Skip to content

Commit b22c877

Browse files
committed
Move all LLVM externs into the rustc_llvm crate in preparation for ctest
1 parent 915e535 commit b22c877

39 files changed

+1068
-1141
lines changed

Cargo.lock

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3521,7 +3521,6 @@ dependencies = [
35213521
name = "rustc_codegen_llvm"
35223522
version = "0.0.0"
35233523
dependencies = [
3524-
"bitflags",
35253524
"gimli 0.31.1",
35263525
"itertools",
35273526
"libc",
@@ -4101,8 +4100,10 @@ dependencies = [
41014100
name = "rustc_llvm"
41024101
version = "0.0.0"
41034102
dependencies = [
4103+
"bitflags",
41044104
"cc",
41054105
"libc",
4106+
"rustc_macros",
41064107
]
41074108

41084109
[[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, 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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ fn create_const_value_function(
114114
name,
115115
llvm::CallConv::CCallConv,
116116
llvm::UnnamedAddr::Global,
117-
llvm::Visibility::from_generic(tcx.sess.default_visibility()),
117+
llvm::visibility_from_generic(tcx.sess.default_visibility()),
118118
ty,
119119
);
120120

@@ -144,7 +144,7 @@ fn create_wrapper_function(
144144
from_name,
145145
llvm::CallConv::CCallConv,
146146
llvm::UnnamedAddr::Global,
147-
llvm::Visibility::from_generic(tcx.sess.default_visibility()),
147+
llvm::visibility_from_generic(tcx.sess.default_visibility()),
148148
ty,
149149
);
150150
let no_return = if no_return {

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::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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ 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, AttributeKind, AttributePlace, MemoryEffects, Value,
17+
};
1718
use crate::{attributes, llvm_util};
1819

1920
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, 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/write.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use crate::errors::{
4242
};
4343
use crate::llvm::diagnostic::OptimizationDiagnosticKind::*;
4444
use crate::llvm::{self, DiagnosticInfo};
45-
use crate::type_::Type;
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> {

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,9 @@ use crate::abi::FnAbiLlvmExt;
3232
use crate::attributes;
3333
use crate::common::Funclet;
3434
use crate::context::{CodegenCx, FullCx, GenericCx, SCx};
35-
use crate::llvm::{
36-
self, AtomicOrdering, AtomicRmwBinOp, BasicBlock, False, GEPNoWrapFlags, Metadata, True,
37-
};
35+
use crate::llvm::{self, BasicBlock, False, GEPNoWrapFlags, Metadata, True, Value};
3836
use crate::type_::Type;
3937
use crate::type_of::LayoutLlvmExt;
40-
use crate::value::Value;
4138

4239
#[must_use]
4340
pub(crate) struct GenericBuilder<'a, 'll, CX: Borrow<SCx<'ll>>> {
@@ -568,7 +565,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
568565
ty,
569566
ptr,
570567
UNNAMED,
571-
AtomicOrdering::from_generic(order),
568+
llvm::atomic_ordering_from_generic(order),
572569
);
573570
// LLVM requires the alignment of atomic loads to be at least the size of the type.
574571
llvm::LLVMSetAlignment(load, size.bytes() as c_uint);
@@ -808,7 +805,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
808805
self.llbuilder,
809806
val,
810807
ptr,
811-
AtomicOrdering::from_generic(order),
808+
llvm::atomic_ordering_from_generic(order),
812809
);
813810
// LLVM requires the alignment of atomic stores to be at least the size of the type.
814811
llvm::LLVMSetAlignment(store, size.bytes() as c_uint);
@@ -1005,12 +1002,12 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
10051002

10061003
/* Comparisons */
10071004
fn icmp(&mut self, op: IntPredicate, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value {
1008-
let op = llvm::IntPredicate::from_generic(op);
1005+
let op = llvm::int_predicate_from_generic(op);
10091006
unsafe { llvm::LLVMBuildICmp(self.llbuilder, op as c_uint, lhs, rhs, UNNAMED) }
10101007
}
10111008

10121009
fn fcmp(&mut self, op: RealPredicate, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value {
1013-
let op = llvm::RealPredicate::from_generic(op);
1010+
let op = llvm::real_predicate_from_generic(op);
10141011
unsafe { llvm::LLVMBuildFCmp(self.llbuilder, op as c_uint, lhs, rhs, UNNAMED) }
10151012
}
10161013

@@ -1246,8 +1243,8 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
12461243
dst,
12471244
cmp,
12481245
src,
1249-
AtomicOrdering::from_generic(order),
1250-
AtomicOrdering::from_generic(failure_order),
1246+
llvm::atomic_ordering_from_generic(order),
1247+
llvm::atomic_ordering_from_generic(failure_order),
12511248
llvm::False, // SingleThreaded
12521249
);
12531250
llvm::LLVMSetWeak(value, weak);
@@ -1273,10 +1270,10 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
12731270
let mut res = unsafe {
12741271
llvm::LLVMBuildAtomicRMW(
12751272
self.llbuilder,
1276-
AtomicRmwBinOp::from_generic(op),
1273+
llvm::atomic_rmw_bin_op_from_generic(op),
12771274
dst,
12781275
src,
1279-
AtomicOrdering::from_generic(order),
1276+
llvm::atomic_ordering_from_generic(order),
12801277
llvm::False, // SingleThreaded
12811278
)
12821279
};
@@ -1298,7 +1295,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
12981295
unsafe {
12991296
llvm::LLVMBuildFence(
13001297
self.llbuilder,
1301-
AtomicOrdering::from_generic(order),
1298+
llvm::atomic_ordering_from_generic(order),
13021299
single_threaded,
13031300
UNNAMED,
13041301
);

0 commit comments

Comments
 (0)