Auto merge of #43387 - TimNN:rustllvm50, r=alexcrichton

Update Rust LLVM bindings for LLVM 5.0

This is the initial set of changes to update the rust llvm bindings for 5.0. The llvm commits necessitating these changes are linked from the tracking issue, #43370.
This commit is contained in:
bors
2017-07-23 01:57:37 +00:00
7 changed files with 194 additions and 105 deletions

View File

@@ -17,7 +17,6 @@ use libc::c_uint;
use std::ptr; use std::ptr;
use {DiagnosticInfoRef, TwineRef, ValueRef}; use {DiagnosticInfoRef, TwineRef, ValueRef};
use ffi::DebugLocRef;
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub enum OptimizationDiagnosticKind { pub enum OptimizationDiagnosticKind {
@@ -47,7 +46,9 @@ pub struct OptimizationDiagnostic {
pub kind: OptimizationDiagnosticKind, pub kind: OptimizationDiagnosticKind,
pub pass_name: String, pub pass_name: String,
pub function: ValueRef, pub function: ValueRef,
pub debug_loc: DebugLocRef, pub line: c_uint,
pub column: c_uint,
pub filename: String,
pub message: String, pub message: String,
} }
@@ -56,24 +57,37 @@ impl OptimizationDiagnostic {
di: DiagnosticInfoRef) di: DiagnosticInfoRef)
-> OptimizationDiagnostic { -> OptimizationDiagnostic {
let mut function = ptr::null_mut(); let mut function = ptr::null_mut();
let mut debug_loc = ptr::null_mut(); let mut line = 0;
let mut column = 0;
let mut message = None; let mut message = None;
let mut filename = None;
let pass_name = super::build_string(|pass_name| let pass_name = super::build_string(|pass_name|
message = super::build_string(|message| message = super::build_string(|message|
super::LLVMRustUnpackOptimizationDiagnostic(di, filename = super::build_string(|filename|
pass_name, super::LLVMRustUnpackOptimizationDiagnostic(di,
&mut function, pass_name,
&mut debug_loc, &mut function,
message) &mut line,
&mut column,
filename,
message)
)
) )
); );
let mut filename = filename.unwrap_or(String::new());
if filename.is_empty() {
filename.push_str("<unknown file>");
}
OptimizationDiagnostic { OptimizationDiagnostic {
kind: kind, kind: kind,
pass_name: pass_name.expect("got a non-UTF8 pass name from LLVM"), pass_name: pass_name.expect("got a non-UTF8 pass name from LLVM"),
function: function, function: function,
debug_loc: debug_loc, line: line,
column: column,
filename: filename,
message: message.expect("got a non-UTF8 OptimizationDiagnostic message from LLVM") message: message.expect("got a non-UTF8 OptimizationDiagnostic message from LLVM")
} }
} }

View File

@@ -1633,7 +1633,9 @@ extern "C" {
pub fn LLVMRustUnpackOptimizationDiagnostic(DI: DiagnosticInfoRef, pub fn LLVMRustUnpackOptimizationDiagnostic(DI: DiagnosticInfoRef,
pass_name_out: RustStringRef, pass_name_out: RustStringRef,
function_out: *mut ValueRef, function_out: *mut ValueRef,
debugloc_out: *mut DebugLocRef, loc_line_out: *mut c_uint,
loc_column_out: *mut c_uint,
loc_filename_out: RustStringRef,
message_out: RustStringRef); message_out: RustStringRef);
pub fn LLVMRustUnpackInlineAsmDiagnostic(DI: DiagnosticInfoRef, pub fn LLVMRustUnpackInlineAsmDiagnostic(DI: DiagnosticInfoRef,
cookie_out: *mut c_uint, cookie_out: *mut c_uint,

View File

@@ -16,7 +16,7 @@ use rustc::session::config::{self, OutputFilenames, OutputType, OutputTypes, Pas
AllPasses, Sanitizer}; AllPasses, Sanitizer};
use rustc::session::Session; use rustc::session::Session;
use llvm; use llvm;
use llvm::{ModuleRef, TargetMachineRef, PassManagerRef, DiagnosticInfoRef, ContextRef}; use llvm::{ModuleRef, TargetMachineRef, PassManagerRef, DiagnosticInfoRef};
use llvm::SMDiagnosticRef; use llvm::SMDiagnosticRef;
use {CrateTranslation, ModuleLlvm, ModuleSource, ModuleTranslation}; use {CrateTranslation, ModuleLlvm, ModuleSource, ModuleTranslation};
use rustc::hir::def_id::CrateNum; use rustc::hir::def_id::CrateNum;
@@ -307,7 +307,6 @@ pub struct CodegenContext<'a> {
} }
struct HandlerFreeVars<'a> { struct HandlerFreeVars<'a> {
llcx: ContextRef,
cgcx: &'a CodegenContext<'a>, cgcx: &'a CodegenContext<'a>,
} }
@@ -329,7 +328,7 @@ unsafe extern "C" fn inline_asm_handler(diag: SMDiagnosticRef,
} }
unsafe extern "C" fn diagnostic_handler(info: DiagnosticInfoRef, user: *mut c_void) { unsafe extern "C" fn diagnostic_handler(info: DiagnosticInfoRef, user: *mut c_void) {
let HandlerFreeVars { llcx, cgcx } = *(user as *const HandlerFreeVars); let HandlerFreeVars { cgcx, .. } = *(user as *const HandlerFreeVars);
match llvm::diagnostic::Diagnostic::unpack(info) { match llvm::diagnostic::Diagnostic::unpack(info) {
llvm::diagnostic::InlineAsm(inline) => { llvm::diagnostic::InlineAsm(inline) => {
@@ -345,11 +344,12 @@ unsafe extern "C" fn diagnostic_handler(info: DiagnosticInfoRef, user: *mut c_vo
}; };
if enabled { if enabled {
let loc = llvm::debug_loc_to_string(llcx, opt.debug_loc); cgcx.handler.note_without_error(&format!("optimization {} for {} at {}:{}:{}: {}",
cgcx.handler.note_without_error(&format!("optimization {} for {} at {}: {}",
opt.kind.describe(), opt.kind.describe(),
opt.pass_name, opt.pass_name,
if loc.is_empty() { "[unknown]" } else { &*loc }, opt.filename,
opt.line,
opt.column,
opt.message)); opt.message));
} }
} }
@@ -370,9 +370,7 @@ unsafe fn optimize_and_codegen(cgcx: &CodegenContext,
let llcx = mllvm.llcx; let llcx = mllvm.llcx;
let tm = config.tm; let tm = config.tm;
// llcx doesn't outlive this function, so we can put this on the stack.
let fv = HandlerFreeVars { let fv = HandlerFreeVars {
llcx: llcx,
cgcx: cgcx, cgcx: cgcx,
}; };
let fv = &fv as *const HandlerFreeVars as *mut c_void; let fv = &fv as *const HandlerFreeVars as *mut c_void;

View File

@@ -12,6 +12,7 @@
#include "llvm/Object/Archive.h" #include "llvm/Object/Archive.h"
#include "llvm/Object/ArchiveWriter.h" #include "llvm/Object/ArchiveWriter.h"
#include "llvm/Support/Path.h"
using namespace llvm; using namespace llvm;
using namespace llvm::object; using namespace llvm::object;
@@ -256,6 +257,9 @@ LLVMRustWriteArchive(char *Dst, size_t NumMembers,
LLVMRustSetLastError(toString(MOrErr.takeError()).c_str()); LLVMRustSetLastError(toString(MOrErr.takeError()).c_str());
return LLVMRustResult::Failure; return LLVMRustResult::Failure;
} }
#if LLVM_VERSION_GE(5, 0)
MOrErr->MemberName = sys::path::filename(MOrErr->MemberName);
#endif
Members.push_back(std::move(*MOrErr)); Members.push_back(std::move(*MOrErr));
#elif LLVM_VERSION_EQ(3, 8) #elif LLVM_VERSION_EQ(3, 8)
Members.push_back(NewArchiveIterator(Member->Filename)); Members.push_back(NewArchiveIterator(Member->Filename));

View File

@@ -18,6 +18,10 @@
#include "llvm/IR/CallSite.h" #include "llvm/IR/CallSite.h"
#if LLVM_VERSION_GE(5, 0)
#include "llvm/ADT/Optional.h"
#endif
//===----------------------------------------------------------------------=== //===----------------------------------------------------------------------===
// //
// This file defines alternate interfaces to core functions that are more // This file defines alternate interfaces to core functions that are more
@@ -163,10 +167,14 @@ extern "C" void LLVMRustAddCallSiteAttribute(LLVMValueRef Instr, unsigned Index,
LLVMRustAttribute RustAttr) { LLVMRustAttribute RustAttr) {
CallSite Call = CallSite(unwrap<Instruction>(Instr)); CallSite Call = CallSite(unwrap<Instruction>(Instr));
Attribute Attr = Attribute::get(Call->getContext(), fromRust(RustAttr)); Attribute Attr = Attribute::get(Call->getContext(), fromRust(RustAttr));
#if LLVM_VERSION_GE(5, 0)
Call.addAttribute(Index, Attr);
#else
AttrBuilder B(Attr); AttrBuilder B(Attr);
Call.setAttributes(Call.getAttributes().addAttributes( Call.setAttributes(Call.getAttributes().addAttributes(
Call->getContext(), Index, Call->getContext(), Index,
AttributeSet::get(Call->getContext(), Index, B))); AttributeSet::get(Call->getContext(), Index, B)));
#endif
} }
extern "C" void LLVMRustAddDereferenceableCallSiteAttr(LLVMValueRef Instr, extern "C" void LLVMRustAddDereferenceableCallSiteAttr(LLVMValueRef Instr,
@@ -175,9 +183,14 @@ extern "C" void LLVMRustAddDereferenceableCallSiteAttr(LLVMValueRef Instr,
CallSite Call = CallSite(unwrap<Instruction>(Instr)); CallSite Call = CallSite(unwrap<Instruction>(Instr));
AttrBuilder B; AttrBuilder B;
B.addDereferenceableAttr(Bytes); B.addDereferenceableAttr(Bytes);
#if LLVM_VERSION_GE(5, 0)
Call.setAttributes(Call.getAttributes().addAttributes(
Call->getContext(), Index, B));
#else
Call.setAttributes(Call.getAttributes().addAttributes( Call.setAttributes(Call.getAttributes().addAttributes(
Call->getContext(), Index, Call->getContext(), Index,
AttributeSet::get(Call->getContext(), Index, B))); AttributeSet::get(Call->getContext(), Index, B)));
#endif
} }
extern "C" void LLVMRustAddFunctionAttribute(LLVMValueRef Fn, unsigned Index, extern "C" void LLVMRustAddFunctionAttribute(LLVMValueRef Fn, unsigned Index,
@@ -185,7 +198,11 @@ extern "C" void LLVMRustAddFunctionAttribute(LLVMValueRef Fn, unsigned Index,
Function *A = unwrap<Function>(Fn); Function *A = unwrap<Function>(Fn);
Attribute Attr = Attribute::get(A->getContext(), fromRust(RustAttr)); Attribute Attr = Attribute::get(A->getContext(), fromRust(RustAttr));
AttrBuilder B(Attr); AttrBuilder B(Attr);
#if LLVM_VERSION_GE(5, 0)
A->addAttributes(Index, B);
#else
A->addAttributes(Index, AttributeSet::get(A->getContext(), Index, B)); A->addAttributes(Index, AttributeSet::get(A->getContext(), Index, B));
#endif
} }
extern "C" void LLVMRustAddDereferenceableAttr(LLVMValueRef Fn, unsigned Index, extern "C" void LLVMRustAddDereferenceableAttr(LLVMValueRef Fn, unsigned Index,
@@ -193,7 +210,11 @@ extern "C" void LLVMRustAddDereferenceableAttr(LLVMValueRef Fn, unsigned Index,
Function *A = unwrap<Function>(Fn); Function *A = unwrap<Function>(Fn);
AttrBuilder B; AttrBuilder B;
B.addDereferenceableAttr(Bytes); B.addDereferenceableAttr(Bytes);
#if LLVM_VERSION_GE(5, 0)
A->addAttributes(Index, B);
#else
A->addAttributes(Index, AttributeSet::get(A->getContext(), Index, B)); A->addAttributes(Index, AttributeSet::get(A->getContext(), Index, B));
#endif
} }
extern "C" void LLVMRustAddFunctionAttrStringValue(LLVMValueRef Fn, extern "C" void LLVMRustAddFunctionAttrStringValue(LLVMValueRef Fn,
@@ -203,18 +224,26 @@ extern "C" void LLVMRustAddFunctionAttrStringValue(LLVMValueRef Fn,
Function *F = unwrap<Function>(Fn); Function *F = unwrap<Function>(Fn);
AttrBuilder B; AttrBuilder B;
B.addAttribute(Name, Value); B.addAttribute(Name, Value);
#if LLVM_VERSION_GE(5, 0)
F->addAttributes(Index, B);
#else
F->addAttributes(Index, AttributeSet::get(F->getContext(), Index, B)); F->addAttributes(Index, AttributeSet::get(F->getContext(), Index, B));
#endif
} }
extern "C" void LLVMRustRemoveFunctionAttributes(LLVMValueRef Fn, extern "C" void LLVMRustRemoveFunctionAttributes(LLVMValueRef Fn,
unsigned Index, unsigned Index,
LLVMRustAttribute RustAttr) { LLVMRustAttribute RustAttr) {
Function *F = unwrap<Function>(Fn); Function *F = unwrap<Function>(Fn);
const AttributeSet PAL = F->getAttributes();
Attribute Attr = Attribute::get(F->getContext(), fromRust(RustAttr)); Attribute Attr = Attribute::get(F->getContext(), fromRust(RustAttr));
AttrBuilder B(Attr); AttrBuilder B(Attr);
auto PAL = F->getAttributes();
#if LLVM_VERSION_GE(5, 0)
auto PALNew = PAL.removeAttributes(F->getContext(), Index, B);
#else
const AttributeSet PALNew = PAL.removeAttributes( const AttributeSet PALNew = PAL.removeAttributes(
F->getContext(), Index, AttributeSet::get(F->getContext(), Index, B)); F->getContext(), Index, AttributeSet::get(F->getContext(), Index, B));
#endif
F->setAttributes(PALNew); F->setAttributes(PALNew);
} }
@@ -263,6 +292,18 @@ enum class LLVMRustSynchronizationScope {
CrossThread, CrossThread,
}; };
#if LLVM_VERSION_GE(5, 0)
static SyncScope::ID fromRust(LLVMRustSynchronizationScope Scope) {
switch (Scope) {
case LLVMRustSynchronizationScope::SingleThread:
return SyncScope::SingleThread;
case LLVMRustSynchronizationScope::CrossThread:
return SyncScope::System;
default:
llvm_unreachable("bad SynchronizationScope.");
}
}
#else
static SynchronizationScope fromRust(LLVMRustSynchronizationScope Scope) { static SynchronizationScope fromRust(LLVMRustSynchronizationScope Scope) {
switch (Scope) { switch (Scope) {
case LLVMRustSynchronizationScope::SingleThread: case LLVMRustSynchronizationScope::SingleThread:
@@ -273,6 +314,7 @@ static SynchronizationScope fromRust(LLVMRustSynchronizationScope Scope) {
llvm_unreachable("bad SynchronizationScope."); llvm_unreachable("bad SynchronizationScope.");
} }
} }
#endif
extern "C" LLVMValueRef extern "C" LLVMValueRef
LLVMRustBuildAtomicFence(LLVMBuilderRef B, LLVMAtomicOrdering Order, LLVMRustBuildAtomicFence(LLVMBuilderRef B, LLVMAtomicOrdering Order,
@@ -318,17 +360,19 @@ extern "C" void LLVMRustAppendModuleInlineAsm(LLVMModuleRef M, const char *Asm)
typedef DIBuilder *LLVMRustDIBuilderRef; typedef DIBuilder *LLVMRustDIBuilderRef;
typedef struct LLVMOpaqueMetadata *LLVMRustMetadataRef; #if LLVM_VERSION_LT(5, 0)
typedef struct LLVMOpaqueMetadata *LLVMMetadataRef;
namespace llvm { namespace llvm {
DEFINE_ISA_CONVERSION_FUNCTIONS(Metadata, LLVMRustMetadataRef) DEFINE_ISA_CONVERSION_FUNCTIONS(Metadata, LLVMMetadataRef)
inline Metadata **unwrap(LLVMRustMetadataRef *Vals) { inline Metadata **unwrap(LLVMMetadataRef *Vals) {
return reinterpret_cast<Metadata **>(Vals); return reinterpret_cast<Metadata **>(Vals);
} }
} }
#endif
template <typename DIT> DIT *unwrapDIPtr(LLVMRustMetadataRef Ref) { template <typename DIT> DIT *unwrapDIPtr(LLVMMetadataRef Ref) {
return (DIT *)(Ref ? unwrap<MDNode>(Ref) : nullptr); return (DIT *)(Ref ? unwrap<MDNode>(Ref) : nullptr);
} }
@@ -466,7 +510,7 @@ extern "C" void LLVMRustAddModuleFlag(LLVMModuleRef M, const char *Name,
unwrap(M)->addModuleFlag(Module::Warning, Name, Value); unwrap(M)->addModuleFlag(Module::Warning, Name, Value);
} }
extern "C" void LLVMRustMetadataAsValue(LLVMContextRef C, LLVMRustMetadataRef MD) { extern "C" void LLVMRustMetadataAsValue(LLVMContextRef C, LLVMMetadataRef MD) {
wrap(MetadataAsValue::get(*unwrap(C), unwrap(MD))); wrap(MetadataAsValue::get(*unwrap(C), unwrap(MD)));
} }
@@ -482,8 +526,8 @@ extern "C" void LLVMRustDIBuilderFinalize(LLVMRustDIBuilderRef Builder) {
Builder->finalize(); Builder->finalize();
} }
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateCompileUnit( extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateCompileUnit(
LLVMRustDIBuilderRef Builder, unsigned Lang, LLVMRustMetadataRef FileRef, LLVMRustDIBuilderRef Builder, unsigned Lang, LLVMMetadataRef FileRef,
const char *Producer, bool isOptimized, const char *Flags, const char *Producer, bool isOptimized, const char *Flags,
unsigned RuntimeVer, const char *SplitName) { unsigned RuntimeVer, const char *SplitName) {
auto *File = unwrapDI<DIFile>(FileRef); auto *File = unwrapDI<DIFile>(FileRef);
@@ -498,16 +542,16 @@ extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateCompileUnit(
#endif #endif
} }
extern "C" LLVMRustMetadataRef extern "C" LLVMMetadataRef
LLVMRustDIBuilderCreateFile(LLVMRustDIBuilderRef Builder, const char *Filename, LLVMRustDIBuilderCreateFile(LLVMRustDIBuilderRef Builder, const char *Filename,
const char *Directory) { const char *Directory) {
return wrap(Builder->createFile(Filename, Directory)); return wrap(Builder->createFile(Filename, Directory));
} }
extern "C" LLVMRustMetadataRef extern "C" LLVMMetadataRef
LLVMRustDIBuilderCreateSubroutineType(LLVMRustDIBuilderRef Builder, LLVMRustDIBuilderCreateSubroutineType(LLVMRustDIBuilderRef Builder,
LLVMRustMetadataRef File, LLVMMetadataRef File,
LLVMRustMetadataRef ParameterTypes) { LLVMMetadataRef ParameterTypes) {
return wrap(Builder->createSubroutineType( return wrap(Builder->createSubroutineType(
#if LLVM_VERSION_EQ(3, 7) #if LLVM_VERSION_EQ(3, 7)
unwrapDI<DIFile>(File), unwrapDI<DIFile>(File),
@@ -515,12 +559,12 @@ LLVMRustDIBuilderCreateSubroutineType(LLVMRustDIBuilderRef Builder,
DITypeRefArray(unwrap<MDTuple>(ParameterTypes)))); DITypeRefArray(unwrap<MDTuple>(ParameterTypes))));
} }
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateFunction( extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateFunction(
LLVMRustDIBuilderRef Builder, LLVMRustMetadataRef Scope, const char *Name, LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
const char *LinkageName, LLVMRustMetadataRef File, unsigned LineNo, const char *LinkageName, LLVMMetadataRef File, unsigned LineNo,
LLVMRustMetadataRef Ty, bool IsLocalToUnit, bool IsDefinition, LLVMMetadataRef Ty, bool IsLocalToUnit, bool IsDefinition,
unsigned ScopeLine, LLVMRustDIFlags Flags, bool IsOptimized, unsigned ScopeLine, LLVMRustDIFlags Flags, bool IsOptimized,
LLVMValueRef Fn, LLVMRustMetadataRef TParam, LLVMRustMetadataRef Decl) { LLVMValueRef Fn, LLVMMetadataRef TParam, LLVMMetadataRef Decl) {
#if LLVM_VERSION_GE(3, 8) #if LLVM_VERSION_GE(3, 8)
DITemplateParameterArray TParams = DITemplateParameterArray TParams =
DITemplateParameterArray(unwrap<MDTuple>(TParam)); DITemplateParameterArray(unwrap<MDTuple>(TParam));
@@ -540,7 +584,7 @@ extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateFunction(
#endif #endif
} }
extern "C" LLVMRustMetadataRef extern "C" LLVMMetadataRef
LLVMRustDIBuilderCreateBasicType(LLVMRustDIBuilderRef Builder, const char *Name, LLVMRustDIBuilderCreateBasicType(LLVMRustDIBuilderRef Builder, const char *Name,
uint64_t SizeInBits, uint32_t AlignInBits, uint64_t SizeInBits, uint32_t AlignInBits,
unsigned Encoding) { unsigned Encoding) {
@@ -551,19 +595,23 @@ LLVMRustDIBuilderCreateBasicType(LLVMRustDIBuilderRef Builder, const char *Name,
Encoding)); Encoding));
} }
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreatePointerType( extern "C" LLVMMetadataRef LLVMRustDIBuilderCreatePointerType(
LLVMRustDIBuilderRef Builder, LLVMRustMetadataRef PointeeTy, LLVMRustDIBuilderRef Builder, LLVMMetadataRef PointeeTy,
uint64_t SizeInBits, uint32_t AlignInBits, const char *Name) { uint64_t SizeInBits, uint32_t AlignInBits, const char *Name) {
return wrap(Builder->createPointerType(unwrapDI<DIType>(PointeeTy), return wrap(Builder->createPointerType(unwrapDI<DIType>(PointeeTy),
SizeInBits, AlignInBits, Name)); SizeInBits, AlignInBits,
#if LLVM_VERSION_GE(5, 0)
/* DWARFAddressSpace */ None,
#endif
Name));
} }
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateStructType( extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateStructType(
LLVMRustDIBuilderRef Builder, LLVMRustMetadataRef Scope, const char *Name, LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
LLVMRustMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits,
uint32_t AlignInBits, LLVMRustDIFlags Flags, uint32_t AlignInBits, LLVMRustDIFlags Flags,
LLVMRustMetadataRef DerivedFrom, LLVMRustMetadataRef Elements, LLVMMetadataRef DerivedFrom, LLVMMetadataRef Elements,
unsigned RunTimeLang, LLVMRustMetadataRef VTableHolder, unsigned RunTimeLang, LLVMMetadataRef VTableHolder,
const char *UniqueId) { const char *UniqueId) {
return wrap(Builder->createStructType( return wrap(Builder->createStructType(
unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), LineNumber, unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), LineNumber,
@@ -572,37 +620,37 @@ extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateStructType(
unwrapDI<DIType>(VTableHolder), UniqueId)); unwrapDI<DIType>(VTableHolder), UniqueId));
} }
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateMemberType( extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateMemberType(
LLVMRustDIBuilderRef Builder, LLVMRustMetadataRef Scope, const char *Name, LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
LLVMRustMetadataRef File, unsigned LineNo, uint64_t SizeInBits, LLVMMetadataRef File, unsigned LineNo, uint64_t SizeInBits,
uint32_t AlignInBits, uint64_t OffsetInBits, LLVMRustDIFlags Flags, uint32_t AlignInBits, uint64_t OffsetInBits, LLVMRustDIFlags Flags,
LLVMRustMetadataRef Ty) { LLVMMetadataRef Ty) {
return wrap(Builder->createMemberType(unwrapDI<DIDescriptor>(Scope), Name, return wrap(Builder->createMemberType(unwrapDI<DIDescriptor>(Scope), Name,
unwrapDI<DIFile>(File), LineNo, unwrapDI<DIFile>(File), LineNo,
SizeInBits, AlignInBits, OffsetInBits, SizeInBits, AlignInBits, OffsetInBits,
fromRust(Flags), unwrapDI<DIType>(Ty))); fromRust(Flags), unwrapDI<DIType>(Ty)));
} }
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateLexicalBlock( extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateLexicalBlock(
LLVMRustDIBuilderRef Builder, LLVMRustMetadataRef Scope, LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope,
LLVMRustMetadataRef File, unsigned Line, unsigned Col) { LLVMMetadataRef File, unsigned Line, unsigned Col) {
return wrap(Builder->createLexicalBlock(unwrapDI<DIDescriptor>(Scope), return wrap(Builder->createLexicalBlock(unwrapDI<DIDescriptor>(Scope),
unwrapDI<DIFile>(File), Line, Col)); unwrapDI<DIFile>(File), Line, Col));
} }
extern "C" LLVMRustMetadataRef extern "C" LLVMMetadataRef
LLVMRustDIBuilderCreateLexicalBlockFile(LLVMRustDIBuilderRef Builder, LLVMRustDIBuilderCreateLexicalBlockFile(LLVMRustDIBuilderRef Builder,
LLVMRustMetadataRef Scope, LLVMMetadataRef Scope,
LLVMRustMetadataRef File) { LLVMMetadataRef File) {
return wrap(Builder->createLexicalBlockFile(unwrapDI<DIDescriptor>(Scope), return wrap(Builder->createLexicalBlockFile(unwrapDI<DIDescriptor>(Scope),
unwrapDI<DIFile>(File))); unwrapDI<DIFile>(File)));
} }
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateStaticVariable( extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateStaticVariable(
LLVMRustDIBuilderRef Builder, LLVMRustMetadataRef Context, const char *Name, LLVMRustDIBuilderRef Builder, LLVMMetadataRef Context, const char *Name,
const char *LinkageName, LLVMRustMetadataRef File, unsigned LineNo, const char *LinkageName, LLVMMetadataRef File, unsigned LineNo,
LLVMRustMetadataRef Ty, bool IsLocalToUnit, LLVMValueRef V, LLVMMetadataRef Ty, bool IsLocalToUnit, LLVMValueRef V,
LLVMRustMetadataRef Decl = nullptr, uint32_t AlignInBits = 0) { LLVMMetadataRef Decl = nullptr, uint32_t AlignInBits = 0) {
llvm::GlobalVariable *InitVal = cast<llvm::GlobalVariable>(unwrap(V)); llvm::GlobalVariable *InitVal = cast<llvm::GlobalVariable>(unwrap(V));
#if LLVM_VERSION_GE(4, 0) #if LLVM_VERSION_GE(4, 0)
@@ -632,10 +680,10 @@ extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateStaticVariable(
#endif #endif
} }
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateVariable( extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateVariable(
LLVMRustDIBuilderRef Builder, unsigned Tag, LLVMRustMetadataRef Scope, LLVMRustDIBuilderRef Builder, unsigned Tag, LLVMMetadataRef Scope,
const char *Name, LLVMRustMetadataRef File, unsigned LineNo, const char *Name, LLVMMetadataRef File, unsigned LineNo,
LLVMRustMetadataRef Ty, bool AlwaysPreserve, LLVMRustDIFlags Flags, LLVMMetadataRef Ty, bool AlwaysPreserve, LLVMRustDIFlags Flags,
unsigned ArgNo, uint32_t AlignInBits) { unsigned ArgNo, uint32_t AlignInBits) {
#if LLVM_VERSION_GE(3, 8) #if LLVM_VERSION_GE(3, 8)
if (Tag == 0x100) { // DW_TAG_auto_variable if (Tag == 0x100) { // DW_TAG_auto_variable
@@ -659,40 +707,40 @@ extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateVariable(
#endif #endif
} }
extern "C" LLVMRustMetadataRef extern "C" LLVMMetadataRef
LLVMRustDIBuilderCreateArrayType(LLVMRustDIBuilderRef Builder, uint64_t Size, LLVMRustDIBuilderCreateArrayType(LLVMRustDIBuilderRef Builder, uint64_t Size,
uint32_t AlignInBits, LLVMRustMetadataRef Ty, uint32_t AlignInBits, LLVMMetadataRef Ty,
LLVMRustMetadataRef Subscripts) { LLVMMetadataRef Subscripts) {
return wrap( return wrap(
Builder->createArrayType(Size, AlignInBits, unwrapDI<DIType>(Ty), Builder->createArrayType(Size, AlignInBits, unwrapDI<DIType>(Ty),
DINodeArray(unwrapDI<MDTuple>(Subscripts)))); DINodeArray(unwrapDI<MDTuple>(Subscripts))));
} }
extern "C" LLVMRustMetadataRef extern "C" LLVMMetadataRef
LLVMRustDIBuilderCreateVectorType(LLVMRustDIBuilderRef Builder, uint64_t Size, LLVMRustDIBuilderCreateVectorType(LLVMRustDIBuilderRef Builder, uint64_t Size,
uint32_t AlignInBits, LLVMRustMetadataRef Ty, uint32_t AlignInBits, LLVMMetadataRef Ty,
LLVMRustMetadataRef Subscripts) { LLVMMetadataRef Subscripts) {
return wrap( return wrap(
Builder->createVectorType(Size, AlignInBits, unwrapDI<DIType>(Ty), Builder->createVectorType(Size, AlignInBits, unwrapDI<DIType>(Ty),
DINodeArray(unwrapDI<MDTuple>(Subscripts)))); DINodeArray(unwrapDI<MDTuple>(Subscripts))));
} }
extern "C" LLVMRustMetadataRef extern "C" LLVMMetadataRef
LLVMRustDIBuilderGetOrCreateSubrange(LLVMRustDIBuilderRef Builder, int64_t Lo, LLVMRustDIBuilderGetOrCreateSubrange(LLVMRustDIBuilderRef Builder, int64_t Lo,
int64_t Count) { int64_t Count) {
return wrap(Builder->getOrCreateSubrange(Lo, Count)); return wrap(Builder->getOrCreateSubrange(Lo, Count));
} }
extern "C" LLVMRustMetadataRef extern "C" LLVMMetadataRef
LLVMRustDIBuilderGetOrCreateArray(LLVMRustDIBuilderRef Builder, LLVMRustDIBuilderGetOrCreateArray(LLVMRustDIBuilderRef Builder,
LLVMRustMetadataRef *Ptr, unsigned Count) { LLVMMetadataRef *Ptr, unsigned Count) {
Metadata **DataValue = unwrap(Ptr); Metadata **DataValue = unwrap(Ptr);
return wrap( return wrap(
Builder->getOrCreateArray(ArrayRef<Metadata *>(DataValue, Count)).get()); Builder->getOrCreateArray(ArrayRef<Metadata *>(DataValue, Count)).get());
} }
extern "C" LLVMValueRef LLVMRustDIBuilderInsertDeclareAtEnd( extern "C" LLVMValueRef LLVMRustDIBuilderInsertDeclareAtEnd(
LLVMRustDIBuilderRef Builder, LLVMValueRef V, LLVMRustMetadataRef VarInfo, LLVMRustDIBuilderRef Builder, LLVMValueRef V, LLVMMetadataRef VarInfo,
int64_t *AddrOps, unsigned AddrOpsCount, LLVMValueRef DL, int64_t *AddrOps, unsigned AddrOpsCount, LLVMValueRef DL,
LLVMBasicBlockRef InsertAtEnd) { LLVMBasicBlockRef InsertAtEnd) {
return wrap(Builder->insertDeclare( return wrap(Builder->insertDeclare(
@@ -702,27 +750,27 @@ extern "C" LLVMValueRef LLVMRustDIBuilderInsertDeclareAtEnd(
unwrap(InsertAtEnd))); unwrap(InsertAtEnd)));
} }
extern "C" LLVMRustMetadataRef extern "C" LLVMMetadataRef
LLVMRustDIBuilderCreateEnumerator(LLVMRustDIBuilderRef Builder, LLVMRustDIBuilderCreateEnumerator(LLVMRustDIBuilderRef Builder,
const char *Name, uint64_t Val) { const char *Name, uint64_t Val) {
return wrap(Builder->createEnumerator(Name, Val)); return wrap(Builder->createEnumerator(Name, Val));
} }
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateEnumerationType( extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateEnumerationType(
LLVMRustDIBuilderRef Builder, LLVMRustMetadataRef Scope, const char *Name, LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
LLVMRustMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits,
uint32_t AlignInBits, LLVMRustMetadataRef Elements, uint32_t AlignInBits, LLVMMetadataRef Elements,
LLVMRustMetadataRef ClassTy) { LLVMMetadataRef ClassTy) {
return wrap(Builder->createEnumerationType( return wrap(Builder->createEnumerationType(
unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), LineNumber, unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), LineNumber,
SizeInBits, AlignInBits, DINodeArray(unwrapDI<MDTuple>(Elements)), SizeInBits, AlignInBits, DINodeArray(unwrapDI<MDTuple>(Elements)),
unwrapDI<DIType>(ClassTy))); unwrapDI<DIType>(ClassTy)));
} }
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateUnionType( extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateUnionType(
LLVMRustDIBuilderRef Builder, LLVMRustMetadataRef Scope, const char *Name, LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
LLVMRustMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits,
uint32_t AlignInBits, LLVMRustDIFlags Flags, LLVMRustMetadataRef Elements, uint32_t AlignInBits, LLVMRustDIFlags Flags, LLVMMetadataRef Elements,
unsigned RunTimeLang, const char *UniqueId) { unsigned RunTimeLang, const char *UniqueId) {
return wrap(Builder->createUnionType( return wrap(Builder->createUnionType(
unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), LineNumber, unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), LineNumber,
@@ -730,20 +778,24 @@ extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateUnionType(
DINodeArray(unwrapDI<MDTuple>(Elements)), RunTimeLang, UniqueId)); DINodeArray(unwrapDI<MDTuple>(Elements)), RunTimeLang, UniqueId));
} }
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateTemplateTypeParameter( extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateTemplateTypeParameter(
LLVMRustDIBuilderRef Builder, LLVMRustMetadataRef Scope, const char *Name, LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
LLVMRustMetadataRef Ty, LLVMRustMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, LLVMMetadataRef File, unsigned LineNo,
unsigned ColumnNo) { unsigned ColumnNo) {
return wrap(Builder->createTemplateTypeParameter( return wrap(Builder->createTemplateTypeParameter(
unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIType>(Ty))); unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIType>(Ty)));
} }
extern "C" LLVMRustMetadataRef extern "C" LLVMMetadataRef
LLVMRustDIBuilderCreateNameSpace(LLVMRustDIBuilderRef Builder, LLVMRustDIBuilderCreateNameSpace(LLVMRustDIBuilderRef Builder,
LLVMRustMetadataRef Scope, const char *Name, LLVMMetadataRef Scope, const char *Name,
LLVMRustMetadataRef File, unsigned LineNo) { LLVMMetadataRef File, unsigned LineNo) {
return wrap(Builder->createNameSpace( return wrap(Builder->createNameSpace(
unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), LineNo unwrapDI<DIDescriptor>(Scope), Name
#if LLVM_VERSION_LT(5, 0)
,
unwrapDI<DIFile>(File), LineNo
#endif
#if LLVM_VERSION_GE(4, 0) #if LLVM_VERSION_GE(4, 0)
, ,
false // ExportSymbols (only relevant for C++ anonymous namespaces) false // ExportSymbols (only relevant for C++ anonymous namespaces)
@@ -753,16 +805,16 @@ LLVMRustDIBuilderCreateNameSpace(LLVMRustDIBuilderRef Builder,
extern "C" void extern "C" void
LLVMRustDICompositeTypeSetTypeArray(LLVMRustDIBuilderRef Builder, LLVMRustDICompositeTypeSetTypeArray(LLVMRustDIBuilderRef Builder,
LLVMRustMetadataRef CompositeTy, LLVMMetadataRef CompositeTy,
LLVMRustMetadataRef TyArray) { LLVMMetadataRef TyArray) {
DICompositeType *Tmp = unwrapDI<DICompositeType>(CompositeTy); DICompositeType *Tmp = unwrapDI<DICompositeType>(CompositeTy);
Builder->replaceArrays(Tmp, DINodeArray(unwrap<MDTuple>(TyArray))); Builder->replaceArrays(Tmp, DINodeArray(unwrap<MDTuple>(TyArray)));
} }
extern "C" LLVMValueRef extern "C" LLVMValueRef
LLVMRustDIBuilderCreateDebugLocation(LLVMContextRef ContextRef, unsigned Line, LLVMRustDIBuilderCreateDebugLocation(LLVMContextRef ContextRef, unsigned Line,
unsigned Column, LLVMRustMetadataRef Scope, unsigned Column, LLVMMetadataRef Scope,
LLVMRustMetadataRef InlinedAt) { LLVMMetadataRef InlinedAt) {
LLVMContext &Context = *unwrap(ContextRef); LLVMContext &Context = *unwrap(ContextRef);
DebugLoc debug_loc = DebugLoc::get(Line, Column, unwrapDIPtr<MDNode>(Scope), DebugLoc debug_loc = DebugLoc::get(Line, Column, unwrapDIPtr<MDNode>(Scope),
@@ -879,8 +931,8 @@ extern "C" void LLVMRustWriteTwineToString(LLVMTwineRef T, RustStringRef Str) {
extern "C" void LLVMRustUnpackOptimizationDiagnostic( extern "C" void LLVMRustUnpackOptimizationDiagnostic(
LLVMDiagnosticInfoRef DI, RustStringRef PassNameOut, LLVMDiagnosticInfoRef DI, RustStringRef PassNameOut,
LLVMValueRef *FunctionOut, LLVMDebugLocRef *DebugLocOut, LLVMValueRef *FunctionOut, unsigned* Line, unsigned* Column,
RustStringRef MessageOut) { RustStringRef FilenameOut, RustStringRef MessageOut) {
// Undefined to call this not on an optimization diagnostic! // Undefined to call this not on an optimization diagnostic!
llvm::DiagnosticInfoOptimizationBase *Opt = llvm::DiagnosticInfoOptimizationBase *Opt =
static_cast<llvm::DiagnosticInfoOptimizationBase *>(unwrap(DI)); static_cast<llvm::DiagnosticInfoOptimizationBase *>(unwrap(DI));
@@ -888,7 +940,24 @@ extern "C" void LLVMRustUnpackOptimizationDiagnostic(
RawRustStringOstream PassNameOS(PassNameOut); RawRustStringOstream PassNameOS(PassNameOut);
PassNameOS << Opt->getPassName(); PassNameOS << Opt->getPassName();
*FunctionOut = wrap(&Opt->getFunction()); *FunctionOut = wrap(&Opt->getFunction());
*DebugLocOut = wrap(&Opt->getDebugLoc());
RawRustStringOstream FilenameOS(FilenameOut);
#if LLVM_VERSION_GE(5,0)
DiagnosticLocation loc = Opt->getLocation();
if (loc.isValid()) {
*Line = loc.getLine();
*Column = loc.getColumn();
FilenameOS << loc.getFilename();
}
#else
const DebugLoc &loc = Opt->getDebugLoc();
if (loc) {
*Line = loc.getLine();
*Column = loc.getCol();
FilenameOS << cast<DIScope>(loc.getScope())->getFilename();
}
#endif
RawRustStringOstream MessageOS(MessageOut); RawRustStringOstream MessageOS(MessageOut);
MessageOS << Opt->getMsg(); MessageOS << Opt->getMsg();
} }

View File

@@ -55,6 +55,8 @@
(LLVM_VERSION_MAJOR < (major) || \ (LLVM_VERSION_MAJOR < (major) || \
LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR <= (minor)) LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR <= (minor))
#define LLVM_VERSION_LT(major, minor) (!LLVM_VERSION_GE((major), (minor)))
#if LLVM_VERSION_GE(3, 7) #if LLVM_VERSION_GE(3, 7)
#include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/LegacyPassManager.h"
#else #else

View File

@@ -19,34 +19,34 @@ pub fn test() {
&a; // keep variable in an alloca &a; // keep variable in an alloca
// CHECK: [[S_a:%[0-9]+]] = bitcast i32* %a to i8* // CHECK: [[S_a:%[0-9]+]] = bitcast i32* %a to i8*
// CHECK: call void @llvm.lifetime.start(i{{[0-9 ]+}}, i8* [[S_a]]) // CHECK: call void @llvm.lifetime.start{{.*}}(i{{[0-9 ]+}}, i8* [[S_a]])
{ {
let b = &Some(a); let b = &Some(a);
&b; // keep variable in an alloca &b; // keep variable in an alloca
// CHECK: [[S_b:%[0-9]+]] = bitcast %"core::option::Option<i32>"** %b to i8* // CHECK: [[S_b:%[0-9]+]] = bitcast %"core::option::Option<i32>"** %b to i8*
// CHECK: call void @llvm.lifetime.start(i{{[0-9 ]+}}, i8* [[S_b]]) // CHECK: call void @llvm.lifetime.start{{.*}}(i{{[0-9 ]+}}, i8* [[S_b]])
// CHECK: [[S__5:%[0-9]+]] = bitcast %"core::option::Option<i32>"* %_5 to i8* // CHECK: [[S__5:%[0-9]+]] = bitcast %"core::option::Option<i32>"* %_5 to i8*
// CHECK: call void @llvm.lifetime.start(i{{[0-9 ]+}}, i8* [[S__5]]) // CHECK: call void @llvm.lifetime.start{{.*}}(i{{[0-9 ]+}}, i8* [[S__5]])
// CHECK: [[E_b:%[0-9]+]] = bitcast %"core::option::Option<i32>"** %b to i8* // CHECK: [[E_b:%[0-9]+]] = bitcast %"core::option::Option<i32>"** %b to i8*
// CHECK: call void @llvm.lifetime.end(i{{[0-9 ]+}}, i8* [[E_b]]) // CHECK: call void @llvm.lifetime.end{{.*}}(i{{[0-9 ]+}}, i8* [[E_b]])
// CHECK: [[E__5:%[0-9]+]] = bitcast %"core::option::Option<i32>"* %_5 to i8* // CHECK: [[E__5:%[0-9]+]] = bitcast %"core::option::Option<i32>"* %_5 to i8*
// CHECK: call void @llvm.lifetime.end(i{{[0-9 ]+}}, i8* [[E__5]]) // CHECK: call void @llvm.lifetime.end{{.*}}(i{{[0-9 ]+}}, i8* [[E__5]])
} }
let c = 1; let c = 1;
&c; // keep variable in an alloca &c; // keep variable in an alloca
// CHECK: [[S_c:%[0-9]+]] = bitcast i32* %c to i8* // CHECK: [[S_c:%[0-9]+]] = bitcast i32* %c to i8*
// CHECK: call void @llvm.lifetime.start(i{{[0-9 ]+}}, i8* [[S_c]]) // CHECK: call void @llvm.lifetime.start{{.*}}(i{{[0-9 ]+}}, i8* [[S_c]])
// CHECK: [[E_c:%[0-9]+]] = bitcast i32* %c to i8* // CHECK: [[E_c:%[0-9]+]] = bitcast i32* %c to i8*
// CHECK: call void @llvm.lifetime.end(i{{[0-9 ]+}}, i8* [[E_c]]) // CHECK: call void @llvm.lifetime.end{{.*}}(i{{[0-9 ]+}}, i8* [[E_c]])
// CHECK: [[E_a:%[0-9]+]] = bitcast i32* %a to i8* // CHECK: [[E_a:%[0-9]+]] = bitcast i32* %a to i8*
// CHECK: call void @llvm.lifetime.end(i{{[0-9 ]+}}, i8* [[E_a]]) // CHECK: call void @llvm.lifetime.end{{.*}}(i{{[0-9 ]+}}, i8* [[E_a]])
} }