Skip to content

Commit bb74561

Browse files
committed
Move all LLVM externs into the rustc_llvm crate in preparation for ctest
1 parent e384365 commit bb74561

37 files changed

+875
-947
lines changed

Cargo.lock

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3509,7 +3509,6 @@ dependencies = [
35093509
name = "rustc_codegen_llvm"
35103510
version = "0.0.0"
35113511
dependencies = [
3512-
"bitflags",
35133512
"gimli 0.31.1",
35143513
"itertools",
35153514
"libc",
@@ -4089,8 +4088,14 @@ dependencies = [
40894088
name = "rustc_llvm"
40904089
version = "0.0.0"
40914090
dependencies = [
4091+
"bitflags",
40924092
"cc",
40934093
"libc",
4094+
"rustc_codegen_ssa",
4095+
"rustc_macros",
4096+
"rustc_middle",
4097+
"rustc_session",
4098+
"rustc_target",
40944099
]
40954100

40964101
[[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/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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@ use crate::attributes;
3333
use crate::common::Funclet;
3434
use crate::context::{CodegenCx, FullCx, GenericCx, SCx};
3535
use crate::llvm::{
36-
self, AtomicOrdering, AtomicRmwBinOp, BasicBlock, False, GEPNoWrapFlags, Metadata, True,
36+
self, AtomicOrdering, AtomicRmwBinOp, BasicBlock, False, GEPNoWrapFlags, Metadata, True, Value,
3737
};
3838
use crate::type_::Type;
3939
use crate::type_of::LayoutLlvmExt;
40-
use crate::value::Value;
4140

4241
#[must_use]
4342
pub(crate) struct GenericBuilder<'a, 'll, CX: Borrow<SCx<'ll>>> {

compiler/rustc_codegen_llvm/src/builder/autodiff.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ use crate::context::SimpleCx;
1515
use crate::declare::declare_simple_fn;
1616
use crate::errors::{AutoDiffWithoutEnable, LlvmError};
1717
use crate::llvm::AttributePlace::Function;
18-
use crate::llvm::{Metadata, True};
19-
use crate::value::Value;
18+
use crate::llvm::{Metadata, True, Value};
2019
use crate::{CodegenContext, LlvmCodegenBackend, ModuleLlvm, attributes, llvm};
2120

2221
fn get_params(fnc: &Value) -> Vec<&Value> {

0 commit comments

Comments
 (0)