rustc: Update LLVM
This commit updates the LLVM submodule in use to the current HEAD of the LLVM repository. This is primarily being done to start picking up unwinding support for MSVC, which is currently unimplemented in the revision of LLVM we are using. Along the way a few changes had to be made: * As usual, lots of C++ debuginfo bindings in LLVM changed, so there were some significant changes to our RustWrapper.cpp * As usual, some pass management changed in LLVM, so clang was re-scrutinized to ensure that we're doing the same thing as clang. * Some optimization options are now passed directly into the `PassManagerBuilder` instead of through CLI switches to LLVM. * The `NoFramePointerElim` option was removed from LLVM, favoring instead the `no-frame-pointer-elim` function attribute instead. Additionally, LLVM has picked up some new optimizations which required fixing an existing soundness hole in the IR we generate. It appears that the current LLVM we use does not expose this hole. When an enum is moved, the previous slot in memory is overwritten with a bit pattern corresponding to "dropped". When the drop glue for this slot is run, however, the switch on the discriminant can often start executing the `unreachable` block of the switch due to the discriminant now being outside the normal range. This was patched over locally for now by having the `unreachable` block just change to a `ret void`.
This commit is contained in:
@@ -15,12 +15,19 @@
|
||||
#include "llvm/Support/CBindingWrapping.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/Host.h"
|
||||
#if LLVM_VERSION_MINOR >= 7
|
||||
#include "llvm/Analysis/TargetLibraryInfo.h"
|
||||
#include "llvm/Analysis/TargetTransformInfo.h"
|
||||
#else
|
||||
#include "llvm/Target/TargetLibraryInfo.h"
|
||||
#endif
|
||||
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
|
||||
|
||||
|
||||
#include "llvm-c/Transforms/PassManagerBuilder.h"
|
||||
|
||||
using namespace llvm;
|
||||
using namespace llvm::legacy;
|
||||
|
||||
extern cl::opt<bool> EnableARMEHABI;
|
||||
|
||||
@@ -71,7 +78,6 @@ LLVMRustCreateTargetMachine(const char *triple,
|
||||
CodeGenOpt::Level OptLevel,
|
||||
bool EnableSegmentedStacks,
|
||||
bool UseSoftFloat,
|
||||
bool NoFramePointerElim,
|
||||
bool PositionIndependentExecutable,
|
||||
bool FunctionSections,
|
||||
bool DataSections) {
|
||||
@@ -91,12 +97,12 @@ LLVMRustCreateTargetMachine(const char *triple,
|
||||
|
||||
TargetOptions Options;
|
||||
Options.PositionIndependentExecutable = PositionIndependentExecutable;
|
||||
Options.NoFramePointerElim = NoFramePointerElim;
|
||||
Options.FloatABIType = FloatABI::Default;
|
||||
Options.UseSoftFloat = UseSoftFloat;
|
||||
if (UseSoftFloat) {
|
||||
Options.FloatABIType = FloatABI::Soft;
|
||||
}
|
||||
Options.DataSections = DataSections;
|
||||
Options.FunctionSections = FunctionSections;
|
||||
|
||||
TargetMachine *TM = TheTarget->createTargetMachine(Trip.getTriple(),
|
||||
real_cpu,
|
||||
@@ -105,8 +111,6 @@ LLVMRustCreateTargetMachine(const char *triple,
|
||||
RM,
|
||||
CM,
|
||||
OptLevel);
|
||||
TM->setDataSections(DataSections);
|
||||
TM->setFunctionSections(FunctionSections);
|
||||
return wrap(TM);
|
||||
}
|
||||
|
||||
@@ -123,12 +127,32 @@ LLVMRustAddAnalysisPasses(LLVMTargetMachineRef TM,
|
||||
LLVMPassManagerRef PMR,
|
||||
LLVMModuleRef M) {
|
||||
PassManagerBase *PM = unwrap(PMR);
|
||||
#if LLVM_VERSION_MINOR >= 6
|
||||
#if LLVM_VERSION_MINOR >= 7
|
||||
PM->add(createTargetTransformInfoWrapperPass(
|
||||
unwrap(TM)->getTargetIRAnalysis()));
|
||||
#else
|
||||
#if LLVM_VERSION_MINOR == 6
|
||||
PM->add(new DataLayoutPass());
|
||||
#else
|
||||
PM->add(new DataLayoutPass(unwrap(M)));
|
||||
#endif
|
||||
unwrap(TM)->addAnalysisPasses(*PM);
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustConfigurePassManagerBuilder(LLVMPassManagerBuilderRef PMB,
|
||||
CodeGenOpt::Level OptLevel,
|
||||
bool MergeFunctions,
|
||||
bool SLPVectorize,
|
||||
bool LoopVectorize) {
|
||||
#if LLVM_VERSION_MINOR >= 6
|
||||
// Ignore mergefunc for now as enabling it causes crashes.
|
||||
//unwrap(PMB)->MergeFunctions = MergeFunctions;
|
||||
#endif
|
||||
unwrap(PMB)->SLPVectorize = SLPVectorize;
|
||||
unwrap(PMB)->OptLevel = OptLevel;
|
||||
unwrap(PMB)->LoopVectorize = LoopVectorize;
|
||||
}
|
||||
|
||||
// Unfortunately, the LLVM C API doesn't provide a way to set the `LibraryInfo`
|
||||
@@ -138,7 +162,11 @@ LLVMRustAddBuilderLibraryInfo(LLVMPassManagerBuilderRef PMB,
|
||||
LLVMModuleRef M,
|
||||
bool DisableSimplifyLibCalls) {
|
||||
Triple TargetTriple(unwrap(M)->getTargetTriple());
|
||||
#if LLVM_VERSION_MINOR >= 7
|
||||
TargetLibraryInfoImpl *TLI = new TargetLibraryInfoImpl(TargetTriple);
|
||||
#else
|
||||
TargetLibraryInfo *TLI = new TargetLibraryInfo(TargetTriple);
|
||||
#endif
|
||||
if (DisableSimplifyLibCalls)
|
||||
TLI->disableAllFunctions();
|
||||
unwrap(PMB)->LibraryInfo = TLI;
|
||||
@@ -151,10 +179,17 @@ LLVMRustAddLibraryInfo(LLVMPassManagerRef PMB,
|
||||
LLVMModuleRef M,
|
||||
bool DisableSimplifyLibCalls) {
|
||||
Triple TargetTriple(unwrap(M)->getTargetTriple());
|
||||
#if LLVM_VERSION_MINOR >= 7
|
||||
TargetLibraryInfoImpl TLII(TargetTriple);
|
||||
if (DisableSimplifyLibCalls)
|
||||
TLII.disableAllFunctions();
|
||||
unwrap(PMB)->add(new TargetLibraryInfoWrapperPass(TLII));
|
||||
#else
|
||||
TargetLibraryInfo *TLI = new TargetLibraryInfo(TargetTriple);
|
||||
if (DisableSimplifyLibCalls)
|
||||
TLI->disableAllFunctions();
|
||||
unwrap(PMB)->add(TLI);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Unfortunately, the LLVM C API doesn't provide an easy way of iterating over
|
||||
@@ -204,10 +239,19 @@ LLVMRustWriteOutputFile(LLVMTargetMachineRef Target,
|
||||
LLVMRustSetLastError(ErrorInfo.c_str());
|
||||
return false;
|
||||
}
|
||||
formatted_raw_ostream FOS(OS);
|
||||
|
||||
#if LLVM_VERSION_MINOR >= 7
|
||||
unwrap(Target)->addPassesToEmitFile(*PM, OS, FileType, false);
|
||||
#else
|
||||
formatted_raw_ostream FOS(OS);
|
||||
unwrap(Target)->addPassesToEmitFile(*PM, FOS, FileType, false);
|
||||
#endif
|
||||
PM->run(*unwrap(M));
|
||||
|
||||
// Apparently `addPassesToEmitFile` adds an pointer to our on-the-stack output
|
||||
// stream (OS), so the only real safe place to delete this is here? Don't we
|
||||
// wish this was written in Rust?
|
||||
delete PM;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user