Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to LLVM 12 #81451

Merged
merged 12 commits into from
Mar 4, 2021
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
[submodule "src/llvm-project"]
path = src/llvm-project
url = https://github.com/rust-lang/llvm-project.git
branch = rustc/11.0-2021-01-05
branch = rustc/12.0-2021-02-03
[submodule "src/doc/embedded-book"]
path = src/doc/embedded-book
url = https://github.com/rust-embedded/book.git
Expand Down
17 changes: 14 additions & 3 deletions compiler/rustc_codegen_llvm/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,13 @@ impl<'tcx> FnAbiLlvmExt<'tcx> for FnAbi<'tcx, Ty<'tcx>> {
PassMode::Indirect { ref attrs, extra_attrs: _, on_stack } => {
assert!(!on_stack);
let i = apply(attrs);
llvm::Attribute::StructRet.apply_llfn(llvm::AttributePlace::Argument(i), llfn);
unsafe {
llvm::LLVMRustAddStructRetAttr(
llfn,
llvm::AttributePlace::Argument(i).as_uint(),
self.ret.layout.llvm_type(cx),
);
}
}
_ => {}
}
Expand Down Expand Up @@ -486,8 +492,13 @@ impl<'tcx> FnAbiLlvmExt<'tcx> for FnAbi<'tcx, Ty<'tcx>> {
PassMode::Indirect { ref attrs, extra_attrs: _, on_stack } => {
assert!(!on_stack);
let i = apply(attrs);
llvm::Attribute::StructRet
.apply_callsite(llvm::AttributePlace::Argument(i), callsite);
unsafe {
llvm::LLVMRustAddStructRetCallSiteAttr(
callsite,
llvm::AttributePlace::Argument(i).as_uint(),
self.ret.layout.llvm_type(bx),
);
}
}
_ => {}
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_llvm/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
} else if options.contains(InlineAsmOptions::READONLY) {
llvm::Attribute::ReadOnly.apply_callsite(llvm::AttributePlace::Function, result);
}
llvm::Attribute::WillReturn.apply_callsite(llvm::AttributePlace::Function, result);
nagisa marked this conversation as resolved.
Show resolved Hide resolved
} else if options.contains(InlineAsmOptions::NOMEM) {
llvm::Attribute::InaccessibleMemOnly
.apply_callsite(llvm::AttributePlace::Function, result);
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ fn strip_x86_address_spaces(data_layout: String) -> String {
data_layout.replace("-p270:32:32-p271:32:32-p272:64:64-", "-")
}

fn strip_powerpc64_vectors(data_layout: String) -> String {
data_layout.replace("-v256:256:256-v512:512:512", "")
}

pub unsafe fn create_module(
tcx: TyCtxt<'_>,
llcx: &'ll llvm::Context,
Expand All @@ -119,6 +123,9 @@ pub unsafe fn create_module(
{
target_data_layout = strip_x86_address_spaces(target_data_layout);
}
if llvm_util::get_version() < (12, 0, 0) && sess.target.arch == "powerpc64" {
target_data_layout = strip_powerpc64_vectors(target_data_layout);
}

// Ensure the data-layout values hardcoded remain the defaults.
if sess.target.is_builtin {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ pub(crate) fn write_filenames_section_to_buffer<'a>(
pub(crate) fn write_mapping_to_buffer(
virtual_file_mapping: Vec<u32>,
expressions: Vec<CounterExpression>,
mut mapping_regions: Vec<CounterMappingRegion>,
mapping_regions: Vec<CounterMappingRegion>,
buffer: &RustString,
) {
unsafe {
Expand All @@ -171,7 +171,7 @@ pub(crate) fn write_mapping_to_buffer(
virtual_file_mapping.len() as c_uint,
expressions.as_ptr(),
expressions.len() as c_uint,
mapping_regions.as_mut_ptr(),
mapping_regions.as_ptr(),
mapping_regions.len() as c_uint,
buffer,
);
Expand Down
11 changes: 7 additions & 4 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ pub enum Attribute {
ReadNone = 26,
InaccessibleMemOnly = 27,
SanitizeHWAddress = 28,
WillReturn = 29,
}

/// LLVMIntPredicate
Expand Down Expand Up @@ -239,6 +240,7 @@ pub enum TypeKind {
Token = 16,
ScalableVector = 17,
BFloat = 18,
X86_AMX = 19,
}

impl TypeKind {
Expand All @@ -263,6 +265,7 @@ impl TypeKind {
TypeKind::Token => rustc_codegen_ssa::common::TypeKind::Token,
TypeKind::ScalableVector => rustc_codegen_ssa::common::TypeKind::ScalableVector,
TypeKind::BFloat => rustc_codegen_ssa::common::TypeKind::BFloat,
TypeKind::X86_AMX => rustc_codegen_ssa::common::TypeKind::X86_AMX,
}
}
}
Expand Down Expand Up @@ -674,9 +677,7 @@ pub mod coverageinfo {
/// array", encoded separately), and source location (start and end positions of the represented
/// code region).
///
/// 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)
/// Important: The Rust struct layout (order and types of fields) must match its C++
/// counterpart.
/// Matches LLVMRustCounterMappingRegion.
#[derive(Copy, Clone, Debug)]
#[repr(C)]
pub struct CounterMappingRegion {
Expand Down Expand Up @@ -1073,6 +1074,7 @@ extern "C" {
pub fn LLVMRustAddDereferenceableAttr(Fn: &Value, index: c_uint, bytes: u64);
pub fn LLVMRustAddDereferenceableOrNullAttr(Fn: &Value, index: c_uint, bytes: u64);
pub fn LLVMRustAddByValAttr(Fn: &Value, index: c_uint, ty: &Type);
pub fn LLVMRustAddStructRetAttr(Fn: &Value, index: c_uint, ty: &Type);
pub fn LLVMRustAddFunctionAttribute(Fn: &Value, index: c_uint, attr: Attribute);
pub fn LLVMRustAddFunctionAttrStringValue(
Fn: &Value,
Expand Down Expand Up @@ -1108,6 +1110,7 @@ extern "C" {
pub fn LLVMRustAddDereferenceableCallSiteAttr(Instr: &Value, index: c_uint, bytes: u64);
pub fn LLVMRustAddDereferenceableOrNullCallSiteAttr(Instr: &Value, index: c_uint, bytes: u64);
pub fn LLVMRustAddByValCallSiteAttr(Instr: &Value, index: c_uint, ty: &Type);
pub fn LLVMRustAddStructRetCallSiteAttr(Instr: &Value, index: c_uint, ty: &Type);

// Operations on load/store instructions (only)
pub fn LLVMSetVolatile(MemoryAccessInst: &Value, volatile: Bool);
Expand Down Expand Up @@ -1792,7 +1795,7 @@ extern "C" {
NumVirtualFileMappingIDs: c_uint,
Expressions: *const coverage_map::CounterExpression,
NumExpressions: c_uint,
MappingRegions: *mut coverageinfo::CounterMappingRegion,
MappingRegions: *const coverageinfo::CounterMappingRegion,
NumMappingRegions: c_uint,
BufferOut: &RustString,
);
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_ssa/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pub enum TypeKind {
Token,
ScalableVector,
BFloat,
X86_AMX,
}

// FIXME(mw): Anything that is produced via DepGraph::with_task() must implement
Expand Down
24 changes: 22 additions & 2 deletions compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@

using namespace llvm;

struct LLVMRustCounterMappingRegion {
coverage::Counter Count;
uint32_t FileID;
uint32_t ExpandedFileID;
uint32_t LineStart;
uint32_t ColumnStart;
uint32_t LineEnd;
uint32_t ColumnEnd;
coverage::CounterMappingRegion::RegionKind Kind;
};

extern "C" void LLVMRustCoverageWriteFilenamesSectionToBuffer(
const char* const Filenames[],
size_t FilenamesLen,
Expand All @@ -27,13 +38,22 @@ extern "C" void LLVMRustCoverageWriteMappingToBuffer(
unsigned NumVirtualFileMappingIDs,
const coverage::CounterExpression *Expressions,
unsigned NumExpressions,
coverage::CounterMappingRegion *MappingRegions,
LLVMRustCounterMappingRegion *RustMappingRegions,
unsigned NumMappingRegions,
RustStringRef BufferOut) {
// Convert from FFI representation to LLVM representation.
SmallVector<coverage::CounterMappingRegion, 0> MappingRegions;
MappingRegions.reserve(NumMappingRegions);
for (const auto &Region : makeArrayRef(RustMappingRegions, NumMappingRegions)) {
MappingRegions.emplace_back(
Region.Count, Region.FileID, Region.ExpandedFileID,
Region.LineStart, Region.ColumnStart, Region.LineEnd, Region.ColumnEnd,
Region.Kind);
}
auto CoverageMappingWriter = coverage::CoverageMappingWriter(
makeArrayRef(VirtualFileMappingIDs, NumVirtualFileMappingIDs),
makeArrayRef(Expressions, NumExpressions),
makeMutableArrayRef(MappingRegions, NumMappingRegions));
MappingRegions);
RawRustStringOstream OS(BufferOut);
CoverageMappingWriter.write(OS);
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ enum LLVMRustAttribute {
ReadNone = 26,
InaccessibleMemOnly = 27,
SanitizeHWAddress = 28,
WillReturn = 29,
};

typedef struct OpaqueRustString *RustStringRef;
Expand Down
Loading