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> {

compiler/rustc_codegen_llvm/src/callee.rs

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

1212
use crate::context::CodegenCx;
1313
use crate::llvm;
14-
use crate::value::Value;
14+
use crate::llvm::Value;
1515

1616
/// Codegens a reference to a fn/method item, monomorphizing and
1717
/// inlining as it goes.

compiler/rustc_codegen_llvm/src/common.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ use tracing::debug;
2121
use crate::consts::const_alloc_to_llvm;
2222
pub(crate) use crate::context::CodegenCx;
2323
use crate::context::{GenericCx, SCx};
24-
use crate::llvm::{self, BasicBlock, Bool, ConstantInt, False, Metadata, True};
24+
use crate::llvm::{self, BasicBlock, Bool, ConstantInt, False, Metadata, True, Value};
2525
use crate::type_::Type;
26-
use crate::value::Value;
2726

2827
/*
2928
* A note on nomenclature of linking: "extern", "foreign", and "upcall".

compiler/rustc_codegen_llvm/src/consts.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ use tracing::{debug, instrument, trace};
1919

2020
use crate::common::{AsCCharPtr, CodegenCx};
2121
use crate::errors::SymbolAlreadyDefined;
22-
use crate::llvm::{self, True};
22+
use crate::llvm::{self, True, Value};
2323
use crate::type_::Type;
2424
use crate::type_of::LayoutLlvmExt;
25-
use crate::value::Value;
2625
use crate::{base, debuginfo};
2726

2827
pub(crate) fn const_alloc_to_llvm<'ll>(

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ use rustc_symbol_mangling::mangle_internal_symbol;
3232
use rustc_target::spec::{HasTargetSpec, RelocModel, SmallDataThresholdSupport, Target, TlsModel};
3333
use smallvec::SmallVec;
3434

35+
use crate::abi::CallConvExt as _;
3536
use crate::back::write::to_llvm_code_model;
3637
use crate::callee::get_fn;
3738
use crate::common::AsCCharPtr;
3839
use crate::debuginfo::metadata::apply_vcall_visibility_metadata;
39-
use crate::llvm::Metadata;
40-
use crate::type_::Type;
41-
use crate::value::Value;
40+
use crate::llvm::{Metadata, Value};
41+
use crate::type_::{Type, type_ix_llcx};
4242
use crate::{attributes, common, coverageinfo, debuginfo, llvm, llvm_util};
4343

4444
/// `TyCtxt` (and related cache datastructures) can't be move between threads.
@@ -669,7 +669,7 @@ impl<'ll> SimpleCx<'ll> {
669669
llcx: &'ll llvm::Context,
670670
pointer_size: Size,
671671
) -> Self {
672-
let isize_ty = llvm::Type::ix_llcx(llcx, pointer_size.bits());
672+
let isize_ty = type_ix_llcx(llcx, pointer_size.bits());
673673
Self(SCx { llmod, llcx, isize_ty }, PhantomData)
674674
}
675675
}

compiler/rustc_codegen_llvm/src/coverageinfo/llvm_cov.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
33
use std::ffi::CString;
44

5+
use rustc_llvm::ffi;
6+
57
use crate::common::AsCCharPtr;
6-
use crate::coverageinfo::ffi;
78
use crate::llvm;
89

910
pub(crate) fn covmap_var_name() -> CString {

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/covfun.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::sync::Arc;
99

1010
use rustc_abi::Align;
1111
use rustc_codegen_ssa::traits::{BaseTypeCodegenMethods as _, ConstCodegenMethods};
12+
use rustc_llvm::ffi;
1213
use rustc_middle::mir::coverage::{
1314
BasicCoverageBlock, CovTerm, CoverageIdsInfo, Expression, FunctionCoverageInfo, Mapping,
1415
MappingKind, Op,
@@ -19,8 +20,8 @@ use rustc_target::spec::HasTargetSpec;
1920
use tracing::debug;
2021

2122
use crate::common::CodegenCx;
23+
use crate::coverageinfo::llvm_cov;
2224
use crate::coverageinfo::mapgen::{GlobalFileTable, VirtualFileMapping, spans};
23-
use crate::coverageinfo::{ffi, llvm_cov};
2425
use crate::llvm;
2526

2627
/// Intermediate coverage metadata for a single function, used to help build

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/spans.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
use rustc_llvm::ffi;
12
use rustc_span::source_map::SourceMap;
23
use rustc_span::{BytePos, Pos, SourceFile, Span};
34
use tracing::debug;
45

5-
use crate::coverageinfo::ffi;
66
use crate::coverageinfo::mapgen::LocalFileId;
77

88
/// Line and byte-column coordinates of a source code span within some file.

compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use crate::builder::Builder;
1414
use crate::common::CodegenCx;
1515
use crate::llvm;
1616

17-
pub(crate) mod ffi;
1817
mod llvm_cov;
1918
mod mapgen;
2019

compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_span::sym;
1212
use crate::builder::Builder;
1313
use crate::common::CodegenCx;
1414
use crate::llvm;
15-
use crate::value::Value;
15+
use crate::llvm::Value;
1616

1717
/// Inserts a side-effect free instruction sequence that makes sure that the
1818
/// .debug_gdb_scripts global is referenced, so it isn't removed by the linker.

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::borrow::Cow;
2-
use std::fmt::{self, Write};
3-
use std::hash::{Hash, Hasher};
2+
use std::fmt::Write;
43
use std::path::{Path, PathBuf};
54
use std::sync::Arc;
65
use std::{iter, ptr};
@@ -38,31 +37,11 @@ use crate::debuginfo::dwarf_const;
3837
use crate::debuginfo::metadata::type_map::build_type_with_children;
3938
use crate::debuginfo::utils::{WidePtrKind, wide_pointer_kind};
4039
use crate::llvm;
40+
use crate::llvm::Value;
4141
use crate::llvm::debuginfo::{
4242
DIBasicType, DIBuilder, DICompositeType, DIDescriptor, DIFile, DIFlags, DILexicalBlock,
4343
DIScope, DIType, DebugEmissionKind, DebugNameTableKind,
4444
};
45-
use crate::value::Value;
46-
47-
impl PartialEq for llvm::Metadata {
48-
fn eq(&self, other: &Self) -> bool {
49-
ptr::eq(self, other)
50-
}
51-
}
52-
53-
impl Eq for llvm::Metadata {}
54-
55-
impl Hash for llvm::Metadata {
56-
fn hash<H: Hasher>(&self, hasher: &mut H) {
57-
(self as *const Self).hash(hasher);
58-
}
59-
}
60-
61-
impl fmt::Debug for llvm::Metadata {
62-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
63-
(self as *const Self).fmt(f)
64-
}
65-
}
6645

6746
pub(super) const UNKNOWN_LINE_NUMBER: c_uint = 0;
6847
pub(super) const UNKNOWN_COLUMN_NUMBER: c_uint = 0;

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ use self::utils::{DIB, create_DIArray, is_node_local_to_unit};
3434
use crate::builder::Builder;
3535
use crate::common::{AsCCharPtr, CodegenCx};
3636
use crate::llvm;
37+
use crate::llvm::Value;
3738
use crate::llvm::debuginfo::{
3839
DIArray, DIBuilderBox, DIFile, DIFlags, DILexicalBlock, DILocation, DISPFlags, DIScope,
3940
DITemplateTypeParameter, DIType, DIVariable,
4041
};
41-
use crate::value::Value;
4242

4343
mod create_scope_map;
4444
mod dwarf_const;

compiler/rustc_codegen_llvm/src/declare.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ use crate::abi::FnAbiLlvmExt;
2626
use crate::common::AsCCharPtr;
2727
use crate::context::{CodegenCx, GenericCx, SCx, SimpleCx};
2828
use crate::llvm::AttributePlace::Function;
29-
use crate::llvm::Visibility;
29+
use crate::llvm::{Value, Visibility};
3030
use crate::type_::Type;
31-
use crate::value::Value;
3231
use crate::{attributes, llvm};
3332

3433
/// Declare a function with a SimpleCx.

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ use tracing::debug;
2121
use crate::abi::FnAbiLlvmExt;
2222
use crate::builder::Builder;
2323
use crate::context::CodegenCx;
24-
use crate::llvm::{self, Metadata};
24+
use crate::llvm::{self, Metadata, Value};
2525
use crate::type_::Type;
2626
use crate::type_of::LayoutLlvmExt;
2727
use crate::va_arg::emit_va_arg;
28-
use crate::value::Value;
2928

3029
fn call_simple_intrinsic<'ll, 'tcx>(
3130
bx: &mut Builder<'_, 'll, 'tcx>,

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ mod mono_item;
7575
mod type_;
7676
mod type_of;
7777
mod va_arg;
78-
mod value;
7978

8079
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
8180

compiler/rustc_codegen_llvm/src/llvm/diagnostic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_span::InnerSpan;
66
pub(crate) use self::Diagnostic::*;
77
use self::OptimizationDiagnosticKind::*;
88
use super::{DiagnosticInfo, SMDiagnostic};
9-
use crate::value::Value;
9+
use crate::llvm::Value;
1010

1111
#[derive(Copy, Clone, Debug)]
1212
pub(crate) enum OptimizationDiagnosticKind {

0 commit comments

Comments
 (0)