2016-12-30 11:22:11 +00:00
|
|
|
#include "llvm-c/BitReader.h"
|
|
|
|
#include "llvm-c/Core.h"
|
|
|
|
#include "llvm-c/Object.h"
|
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
|
|
|
#include "llvm/ADT/DenseSet.h"
|
|
|
|
#include "llvm/ADT/Triple.h"
|
|
|
|
#include "llvm/Analysis/Lint.h"
|
|
|
|
#include "llvm/Analysis/Passes.h"
|
2013-05-25 22:23:12 +00:00
|
|
|
#include "llvm/IR/IRBuilder.h"
|
2013-05-27 23:15:31 +00:00
|
|
|
#include "llvm/IR/InlineAsm.h"
|
2016-12-30 11:22:11 +00:00
|
|
|
#include "llvm/IR/LLVMContext.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
2013-05-27 23:15:31 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/DynamicLibrary.h"
|
2016-12-30 11:22:11 +00:00
|
|
|
#include "llvm/Support/FormattedStream.h"
|
|
|
|
#include "llvm/Support/Host.h"
|
2013-05-27 23:15:31 +00:00
|
|
|
#include "llvm/Support/Memory.h"
|
2016-12-30 11:22:11 +00:00
|
|
|
#include "llvm/Support/SourceMgr.h"
|
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
|
|
|
#include "llvm/Support/TargetSelect.h"
|
|
|
|
#include "llvm/Support/Timer.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2013-05-27 23:15:31 +00:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include "llvm/Target/TargetOptions.h"
|
|
|
|
#include "llvm/Transforms/IPO.h"
|
|
|
|
#include "llvm/Transforms/Instrumentation.h"
|
2016-12-30 11:22:11 +00:00
|
|
|
#include "llvm/Transforms/Scalar.h"
|
2013-05-27 23:15:31 +00:00
|
|
|
#include "llvm/Transforms/Vectorize.h"
|
|
|
|
|
2016-12-30 11:22:11 +00:00
|
|
|
#define LLVM_VERSION_GE(major, minor) \
|
|
|
|
(LLVM_VERSION_MAJOR > (major) || \
|
|
|
|
LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR >= (minor))
|
2016-09-24 14:44:21 +00:00
|
|
|
|
2016-12-30 11:22:11 +00:00
|
|
|
#define LLVM_VERSION_EQ(major, minor) \
|
2016-09-24 14:44:21 +00:00
|
|
|
(LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR == (minor))
|
|
|
|
|
2016-12-30 11:22:11 +00:00
|
|
|
#define LLVM_VERSION_LE(major, minor) \
|
|
|
|
(LLVM_VERSION_MAJOR < (major) || \
|
|
|
|
LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR <= (minor))
|
2016-09-24 14:44:21 +00:00
|
|
|
|
2017-07-21 11:13:37 +00:00
|
|
|
#define LLVM_VERSION_LT(major, minor) (!LLVM_VERSION_GE((major), (minor)))
|
|
|
|
|
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`.
2015-05-14 19:10:43 +00:00
|
|
|
#include "llvm/IR/LegacyPassManager.h"
|
|
|
|
|
2016-11-17 14:10:19 +00:00
|
|
|
#include "llvm/Bitcode/BitcodeReader.h"
|
|
|
|
#include "llvm/Bitcode/BitcodeWriter.h"
|
|
|
|
|
2014-03-31 21:43:19 +00:00
|
|
|
#include "llvm/IR/DIBuilder.h"
|
2016-12-30 11:22:11 +00:00
|
|
|
#include "llvm/IR/DebugInfo.h"
|
|
|
|
#include "llvm/IR/IRPrintingPasses.h"
|
2014-03-31 21:43:19 +00:00
|
|
|
#include "llvm/Linker/Linker.h"
|
2014-02-26 22:06:27 +00:00
|
|
|
|
2018-01-04 20:19:23 +00:00
|
|
|
extern "C" void LLVMRustSetLastError(const char *);
|
2014-09-10 06:12:09 +00:00
|
|
|
|
2016-12-30 11:22:11 +00:00
|
|
|
enum class LLVMRustResult { Success, Failure };
|
2016-08-01 21:16:16 +00:00
|
|
|
|
2016-11-16 22:36:08 +00:00
|
|
|
enum LLVMRustAttribute {
|
2016-12-30 11:22:11 +00:00
|
|
|
AlwaysInline = 0,
|
|
|
|
ByVal = 1,
|
|
|
|
Cold = 2,
|
|
|
|
InlineHint = 3,
|
|
|
|
MinSize = 4,
|
|
|
|
Naked = 5,
|
|
|
|
NoAlias = 6,
|
|
|
|
NoCapture = 7,
|
|
|
|
NoInline = 8,
|
|
|
|
NonNull = 9,
|
|
|
|
NoRedZone = 10,
|
|
|
|
NoReturn = 11,
|
|
|
|
NoUnwind = 12,
|
|
|
|
OptimizeForSize = 13,
|
|
|
|
ReadOnly = 14,
|
|
|
|
SExt = 15,
|
|
|
|
StructRet = 16,
|
|
|
|
UWTable = 17,
|
|
|
|
ZExt = 18,
|
|
|
|
InReg = 19,
|
2016-12-30 04:28:11 +00:00
|
|
|
SanitizeThread = 20,
|
|
|
|
SanitizeAddress = 21,
|
|
|
|
SanitizeMemory = 22,
|
2018-09-26 16:19:55 +00:00
|
|
|
NonLazyBind = 23,
|
2018-10-27 12:29:06 +00:00
|
|
|
OptimizeNone = 24,
|
2019-02-09 14:55:30 +00:00
|
|
|
ReturnsTwice = 25,
|
2020-02-17 21:36:01 +00:00
|
|
|
ReadNone = 26,
|
|
|
|
InaccessibleMemOnly = 27,
|
2016-11-16 22:36:08 +00:00
|
|
|
};
|
|
|
|
|
2014-09-10 06:12:09 +00:00
|
|
|
typedef struct OpaqueRustString *RustStringRef;
|
2014-09-12 15:17:58 +00:00
|
|
|
typedef struct LLVMOpaqueTwine *LLVMTwineRef;
|
2014-09-27 08:33:36 +00:00
|
|
|
typedef struct LLVMOpaqueSMDiagnostic *LLVMSMDiagnosticRef;
|
2014-09-10 06:12:09 +00:00
|
|
|
|
2016-12-31 17:01:23 +00:00
|
|
|
extern "C" void LLVMRustStringWriteImpl(RustStringRef Str, const char *Ptr,
|
|
|
|
size_t Size);
|
2014-09-10 06:12:09 +00:00
|
|
|
|
2016-12-31 17:01:23 +00:00
|
|
|
class RawRustStringOstream : public llvm::raw_ostream {
|
|
|
|
RustStringRef Str;
|
|
|
|
uint64_t Pos;
|
2014-09-10 06:12:09 +00:00
|
|
|
|
2016-12-31 17:01:23 +00:00
|
|
|
void write_impl(const char *Ptr, size_t Size) override {
|
|
|
|
LLVMRustStringWriteImpl(Str, Ptr, Size);
|
|
|
|
Pos += Size;
|
2016-12-30 11:22:11 +00:00
|
|
|
}
|
2014-09-10 06:12:09 +00:00
|
|
|
|
2016-12-31 17:01:23 +00:00
|
|
|
uint64_t current_pos() const override { return Pos; }
|
2014-09-10 06:12:09 +00:00
|
|
|
|
|
|
|
public:
|
2016-12-31 17:01:23 +00:00
|
|
|
explicit RawRustStringOstream(RustStringRef Str) : Str(Str), Pos(0) {}
|
2014-09-10 06:12:09 +00:00
|
|
|
|
2016-12-31 17:01:23 +00:00
|
|
|
~RawRustStringOstream() {
|
2016-12-30 11:22:11 +00:00
|
|
|
// LLVM requires this.
|
|
|
|
flush();
|
|
|
|
}
|
2014-09-10 06:12:09 +00:00
|
|
|
};
|