Skip to content

Commit 4099208

Browse files
committed
Auto merge of #81451 - nikic:llvm-12, r=nagisa
Upgrade to LLVM 12 This implements the necessary adjustments to make rustc work with LLVM 12. I didn't encounter any major issues so far. r? `@cuviper`
2 parents ec7f258 + ab03c56 commit 4099208

File tree

57 files changed

+402
-101
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+402
-101
lines changed

.gitmodules

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
[submodule "src/llvm-project"]
3838
path = src/llvm-project
3939
url = https://github.com/rust-lang/llvm-project.git
40-
branch = rustc/11.0-2021-01-05
40+
branch = rustc/12.0-2021-02-03
4141
[submodule "src/doc/embedded-book"]
4242
path = src/doc/embedded-book
4343
url = https://github.com/rust-embedded/book.git

compiler/rustc_codegen_llvm/src/abi.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,13 @@ impl<'tcx> FnAbiLlvmExt<'tcx> for FnAbi<'tcx, Ty<'tcx>> {
430430
PassMode::Indirect { ref attrs, extra_attrs: _, on_stack } => {
431431
assert!(!on_stack);
432432
let i = apply(attrs);
433-
llvm::Attribute::StructRet.apply_llfn(llvm::AttributePlace::Argument(i), llfn);
433+
unsafe {
434+
llvm::LLVMRustAddStructRetAttr(
435+
llfn,
436+
llvm::AttributePlace::Argument(i).as_uint(),
437+
self.ret.layout.llvm_type(cx),
438+
);
439+
}
434440
}
435441
_ => {}
436442
}
@@ -486,8 +492,13 @@ impl<'tcx> FnAbiLlvmExt<'tcx> for FnAbi<'tcx, Ty<'tcx>> {
486492
PassMode::Indirect { ref attrs, extra_attrs: _, on_stack } => {
487493
assert!(!on_stack);
488494
let i = apply(attrs);
489-
llvm::Attribute::StructRet
490-
.apply_callsite(llvm::AttributePlace::Argument(i), callsite);
495+
unsafe {
496+
llvm::LLVMRustAddStructRetCallSiteAttr(
497+
callsite,
498+
llvm::AttributePlace::Argument(i).as_uint(),
499+
self.ret.layout.llvm_type(bx),
500+
);
501+
}
491502
}
492503
_ => {}
493504
}

compiler/rustc_codegen_llvm/src/asm.rs

+1
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
304304
} else if options.contains(InlineAsmOptions::READONLY) {
305305
llvm::Attribute::ReadOnly.apply_callsite(llvm::AttributePlace::Function, result);
306306
}
307+
llvm::Attribute::WillReturn.apply_callsite(llvm::AttributePlace::Function, result);
307308
} else if options.contains(InlineAsmOptions::NOMEM) {
308309
llvm::Attribute::InaccessibleMemOnly
309310
.apply_callsite(llvm::AttributePlace::Function, result);

compiler/rustc_codegen_llvm/src/context.rs

+7
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ fn strip_x86_address_spaces(data_layout: String) -> String {
104104
data_layout.replace("-p270:32:32-p271:32:32-p272:64:64-", "-")
105105
}
106106

107+
fn strip_powerpc64_vectors(data_layout: String) -> String {
108+
data_layout.replace("-v256:256:256-v512:512:512", "")
109+
}
110+
107111
pub unsafe fn create_module(
108112
tcx: TyCtxt<'_>,
109113
llcx: &'ll llvm::Context,
@@ -119,6 +123,9 @@ pub unsafe fn create_module(
119123
{
120124
target_data_layout = strip_x86_address_spaces(target_data_layout);
121125
}
126+
if llvm_util::get_version() < (12, 0, 0) && sess.target.arch == "powerpc64" {
127+
target_data_layout = strip_powerpc64_vectors(target_data_layout);
128+
}
122129

123130
// Ensure the data-layout values hardcoded remain the defaults.
124131
if sess.target.is_builtin {

compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ pub(crate) fn write_filenames_section_to_buffer<'a>(
162162
pub(crate) fn write_mapping_to_buffer(
163163
virtual_file_mapping: Vec<u32>,
164164
expressions: Vec<CounterExpression>,
165-
mut mapping_regions: Vec<CounterMappingRegion>,
165+
mapping_regions: Vec<CounterMappingRegion>,
166166
buffer: &RustString,
167167
) {
168168
unsafe {
@@ -171,7 +171,7 @@ pub(crate) fn write_mapping_to_buffer(
171171
virtual_file_mapping.len() as c_uint,
172172
expressions.as_ptr(),
173173
expressions.len() as c_uint,
174-
mapping_regions.as_mut_ptr(),
174+
mapping_regions.as_ptr(),
175175
mapping_regions.len() as c_uint,
176176
buffer,
177177
);

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ pub enum Attribute {
132132
ReadNone = 26,
133133
InaccessibleMemOnly = 27,
134134
SanitizeHWAddress = 28,
135+
WillReturn = 29,
135136
}
136137

137138
/// LLVMIntPredicate
@@ -239,6 +240,7 @@ pub enum TypeKind {
239240
Token = 16,
240241
ScalableVector = 17,
241242
BFloat = 18,
243+
X86_AMX = 19,
242244
}
243245

244246
impl TypeKind {
@@ -263,6 +265,7 @@ impl TypeKind {
263265
TypeKind::Token => rustc_codegen_ssa::common::TypeKind::Token,
264266
TypeKind::ScalableVector => rustc_codegen_ssa::common::TypeKind::ScalableVector,
265267
TypeKind::BFloat => rustc_codegen_ssa::common::TypeKind::BFloat,
268+
TypeKind::X86_AMX => rustc_codegen_ssa::common::TypeKind::X86_AMX,
266269
}
267270
}
268271
}
@@ -674,9 +677,7 @@ pub mod coverageinfo {
674677
/// array", encoded separately), and source location (start and end positions of the represented
675678
/// code region).
676679
///
677-
/// Aligns with [llvm::coverage::CounterMappingRegion](https://github.com/rust-lang/llvm-project/blob/rustc/11.0-2020-10-12/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h#L224-L227)
678-
/// Important: The Rust struct layout (order and types of fields) must match its C++
679-
/// counterpart.
680+
/// Matches LLVMRustCounterMappingRegion.
680681
#[derive(Copy, Clone, Debug)]
681682
#[repr(C)]
682683
pub struct CounterMappingRegion {
@@ -1073,6 +1074,7 @@ extern "C" {
10731074
pub fn LLVMRustAddDereferenceableAttr(Fn: &Value, index: c_uint, bytes: u64);
10741075
pub fn LLVMRustAddDereferenceableOrNullAttr(Fn: &Value, index: c_uint, bytes: u64);
10751076
pub fn LLVMRustAddByValAttr(Fn: &Value, index: c_uint, ty: &Type);
1077+
pub fn LLVMRustAddStructRetAttr(Fn: &Value, index: c_uint, ty: &Type);
10761078
pub fn LLVMRustAddFunctionAttribute(Fn: &Value, index: c_uint, attr: Attribute);
10771079
pub fn LLVMRustAddFunctionAttrStringValue(
10781080
Fn: &Value,
@@ -1108,6 +1110,7 @@ extern "C" {
11081110
pub fn LLVMRustAddDereferenceableCallSiteAttr(Instr: &Value, index: c_uint, bytes: u64);
11091111
pub fn LLVMRustAddDereferenceableOrNullCallSiteAttr(Instr: &Value, index: c_uint, bytes: u64);
11101112
pub fn LLVMRustAddByValCallSiteAttr(Instr: &Value, index: c_uint, ty: &Type);
1113+
pub fn LLVMRustAddStructRetCallSiteAttr(Instr: &Value, index: c_uint, ty: &Type);
11111114

11121115
// Operations on load/store instructions (only)
11131116
pub fn LLVMSetVolatile(MemoryAccessInst: &Value, volatile: Bool);
@@ -1792,7 +1795,7 @@ extern "C" {
17921795
NumVirtualFileMappingIDs: c_uint,
17931796
Expressions: *const coverage_map::CounterExpression,
17941797
NumExpressions: c_uint,
1795-
MappingRegions: *mut coverageinfo::CounterMappingRegion,
1798+
MappingRegions: *const coverageinfo::CounterMappingRegion,
17961799
NumMappingRegions: c_uint,
17971800
BufferOut: &RustString,
17981801
);

compiler/rustc_codegen_ssa/src/common.rs

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ pub enum TypeKind {
9595
Token,
9696
ScalableVector,
9797
BFloat,
98+
X86_AMX,
9899
}
99100

100101
// FIXME(mw): Anything that is produced via DepGraph::with_task() must implement

compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp

+22-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@
88

99
using namespace llvm;
1010

11+
struct LLVMRustCounterMappingRegion {
12+
coverage::Counter Count;
13+
uint32_t FileID;
14+
uint32_t ExpandedFileID;
15+
uint32_t LineStart;
16+
uint32_t ColumnStart;
17+
uint32_t LineEnd;
18+
uint32_t ColumnEnd;
19+
coverage::CounterMappingRegion::RegionKind Kind;
20+
};
21+
1122
extern "C" void LLVMRustCoverageWriteFilenamesSectionToBuffer(
1223
const char* const Filenames[],
1324
size_t FilenamesLen,
@@ -27,13 +38,22 @@ extern "C" void LLVMRustCoverageWriteMappingToBuffer(
2738
unsigned NumVirtualFileMappingIDs,
2839
const coverage::CounterExpression *Expressions,
2940
unsigned NumExpressions,
30-
coverage::CounterMappingRegion *MappingRegions,
41+
LLVMRustCounterMappingRegion *RustMappingRegions,
3142
unsigned NumMappingRegions,
3243
RustStringRef BufferOut) {
44+
// Convert from FFI representation to LLVM representation.
45+
SmallVector<coverage::CounterMappingRegion, 0> MappingRegions;
46+
MappingRegions.reserve(NumMappingRegions);
47+
for (const auto &Region : makeArrayRef(RustMappingRegions, NumMappingRegions)) {
48+
MappingRegions.emplace_back(
49+
Region.Count, Region.FileID, Region.ExpandedFileID,
50+
Region.LineStart, Region.ColumnStart, Region.LineEnd, Region.ColumnEnd,
51+
Region.Kind);
52+
}
3353
auto CoverageMappingWriter = coverage::CoverageMappingWriter(
3454
makeArrayRef(VirtualFileMappingIDs, NumVirtualFileMappingIDs),
3555
makeArrayRef(Expressions, NumExpressions),
36-
makeMutableArrayRef(MappingRegions, NumMappingRegions));
56+
MappingRegions);
3757
RawRustStringOstream OS(BufferOut);
3858
CoverageMappingWriter.write(OS);
3959
}

compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ enum LLVMRustAttribute {
8686
ReadNone = 26,
8787
InaccessibleMemOnly = 27,
8888
SanitizeHWAddress = 28,
89+
WillReturn = 29,
8990
};
9091

9192
typedef struct OpaqueRustString *RustStringRef;

0 commit comments

Comments
 (0)