Skip to content

Commit e865bbb

Browse files
committed
Move all LLVM externs into the rustc_llvm crate in preparation for ctest
1 parent 111e9bc commit e865bbb

39 files changed

+1060
-1237
lines changed

Cargo.lock

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3434,7 +3434,6 @@ dependencies = [
34343434
name = "rustc_codegen_llvm"
34353435
version = "0.0.0"
34363436
dependencies = [
3437-
"bitflags",
34383437
"gimli",
34393438
"itertools",
34403439
"libc",
@@ -4014,8 +4013,14 @@ dependencies = [
40144013
name = "rustc_llvm"
40154014
version = "0.0.0"
40164015
dependencies = [
4016+
"bitflags",
40174017
"cc",
40184018
"libc",
4019+
"rustc_codegen_ssa",
4020+
"rustc_macros",
4021+
"rustc_middle",
4022+
"rustc_session",
4023+
"rustc_target",
40194024
]
40204025

40214026
[[package]]

compiler/rustc_codegen_llvm/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ test = false
88

99
[dependencies]
1010
# tidy-alphabetical-start
11-
bitflags = "2.4.1"
1211
# To avoid duplicate dependencies, this should match the version of gimli used
1312
# by `rustc_codegen_ssa` via its `thorin-dwp` dependency.
1413
gimli = "0.31"
@@ -38,7 +37,7 @@ rustc_session = { path = "../rustc_session" }
3837
rustc_span = { path = "../rustc_span" }
3938
rustc_symbol_mangling = { path = "../rustc_symbol_mangling" }
4039
rustc_target = { path = "../rustc_target" }
41-
serde = { version = "1", features = [ "derive" ]}
40+
serde = { version = "1", features = ["derive"] }
4241
serde_json = "1"
4342
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
4443
tracing = "0.1"

compiler/rustc_codegen_llvm/src/abi.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ use smallvec::SmallVec;
2323
use crate::attributes::{self, llfn_attrs_from_instance};
2424
use crate::builder::Builder;
2525
use crate::context::CodegenCx;
26-
use crate::llvm::{self, Attribute, AttributePlace};
26+
use crate::llvm::{self, Attribute, AttributeExt as _, AttributePlace, Value};
2727
use crate::type_::Type;
2828
use crate::type_of::LayoutLlvmExt;
29-
use crate::value::Value;
3029

3130
trait ArgAttributesExt {
3231
fn apply_attrs_to_llfn(&self, idx: AttributePlace, cx: &CodegenCx<'_, '_>, llfn: &Value);
@@ -644,8 +643,12 @@ impl AbiBuilderMethods for Builder<'_, '_, '_> {
644643
}
645644
}
646645

647-
impl llvm::CallConv {
648-
pub(crate) fn from_conv(conv: CanonAbi, arch: &str) -> Self {
646+
pub(crate) trait CallConvExt {
647+
fn from_conv(conv: CanonAbi, arch: &str) -> llvm::CallConv;
648+
}
649+
650+
impl CallConvExt for llvm::CallConv {
651+
fn from_conv(conv: CanonAbi, arch: &str) -> Self {
649652
match conv {
650653
CanonAbi::C | CanonAbi::Rust => llvm::CCallConv,
651654
CanonAbi::RustCold => llvm::PreserveMost,

compiler/rustc_codegen_llvm/src/allocator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_symbol_mangling::mangle_internal_symbol;
1111

1212
use crate::builder::SBuilder;
1313
use crate::declare::declare_simple_fn;
14-
use crate::llvm::{self, False, True, Type};
14+
use crate::llvm::{self, AttributeExt as _, False, True, Type};
1515
use crate::{SimpleCx, attributes, debuginfo};
1616

1717
pub(crate) unsafe fn codegen(

compiler/rustc_codegen_llvm/src/asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ use tracing::debug;
1616
use crate::builder::Builder;
1717
use crate::common::Funclet;
1818
use crate::context::CodegenCx;
19+
use crate::llvm::{AttributeExt as _, Value};
1920
use crate::type_::Type;
2021
use crate::type_of::LayoutLlvmExt;
21-
use crate::value::Value;
2222
use crate::{attributes, llvm};
2323

2424
impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ use smallvec::SmallVec;
1212
use crate::context::CodegenCx;
1313
use crate::errors::SanitizerMemtagRequiresMte;
1414
use crate::llvm::AttributePlace::Function;
15-
use crate::llvm::{self, AllocKindFlags, Attribute, AttributeKind, AttributePlace, MemoryEffects};
16-
use crate::value::Value;
15+
use crate::llvm::{
16+
self, AllocKindFlags, Attribute, AttributeExt as _, AttributeKind, AttributePlace,
17+
MemoryEffects, Value,
18+
};
1719
use crate::{attributes, llvm_util};
1820

1921
pub(crate) fn apply_to_llfn(llfn: &Value, idx: AttributePlace, attrs: &[&Attribute]) {

compiler/rustc_codegen_llvm/src/back/archive.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_codegen_ssa::back::archive::{
1111
use rustc_session::Session;
1212

1313
use crate::llvm::archive_ro::{ArchiveRO, Child};
14-
use crate::llvm::{self, ArchiveKind, last_error};
14+
use crate::llvm::{self, LLVMRustResultExt as _, last_error, parse_archive_kind};
1515

1616
/// Helper for adding many files to an archive.
1717
#[must_use = "must call build() to finish building the archive"]
@@ -182,8 +182,7 @@ fn llvm_is_ec_object_file(buf: &[u8]) -> bool {
182182
impl<'a> LlvmArchiveBuilder<'a> {
183183
fn build_with_llvm(&mut self, output: &Path) -> io::Result<bool> {
184184
let kind = &*self.sess.target.archive_format;
185-
let kind = kind
186-
.parse::<ArchiveKind>()
185+
let kind = parse_archive_kind(kind)
187186
.map_err(|_| kind)
188187
.unwrap_or_else(|kind| self.sess.dcx().emit_fatal(UnknownArchiveKind { kind }));
189188

compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::errors::{
2929
DynamicLinkingWithLTO, LlvmError, LtoBitcodeFromRlib, LtoDisallowed, LtoDylib, LtoProcMacro,
3030
};
3131
use crate::llvm::AttributePlace::Function;
32-
use crate::llvm::{self, build_string};
32+
use crate::llvm::{self, AttributeExt as _, build_string};
3333
use crate::{LlvmCodegenBackend, ModuleLlvm, SimpleCx, attributes};
3434

3535
/// We keep track of the computed LTO cache keys from the previous

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ use crate::errors::{
4141
WithLlvmError, WriteBytecode,
4242
};
4343
use crate::llvm::diagnostic::OptimizationDiagnosticKind::*;
44-
use crate::llvm::{self, DiagnosticInfo};
45-
use crate::type_::Type;
44+
use crate::llvm::{self, DiagnosticInfo, LLVMRustResultExt as _};
45+
use crate::type_::type_ptr_llcx;
4646
use crate::{LlvmCodegenBackend, ModuleLlvm, base, common, llvm_util};
4747

4848
pub(crate) fn llvm_err<'a>(dcx: DiagCtxtHandle<'_>, err: LlvmError<'a>) -> FatalError {
@@ -1174,7 +1174,7 @@ fn create_msvc_imps(
11741174
// underscores added in front).
11751175
let prefix = if cgcx.target_arch == "x86" { "\x01__imp__" } else { "\x01__imp_" };
11761176

1177-
let ptr_ty = Type::ptr_llcx(llcx);
1177+
let ptr_ty = type_ptr_llcx(llcx);
11781178
let globals = base::iter_globals(llmod)
11791179
.filter(|&val| {
11801180
llvm::get_linkage(val) == llvm::Linkage::ExternalLinkage && !llvm::is_declaration(val)

compiler/rustc_codegen_llvm/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use rustc_target::spec::SanitizerSet;
2929
use super::ModuleLlvm;
3030
use crate::builder::Builder;
3131
use crate::context::CodegenCx;
32-
use crate::value::Value;
32+
use crate::llvm::Value;
3333
use crate::{attributes, llvm};
3434

3535
pub(crate) struct ValueIter<'ll> {

0 commit comments

Comments
 (0)