]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h
Auto merge of #79697 - rylev:clearer-const-diagnostic, r=oli-obk
[rust.git] / compiler / rustc_llvm / llvm-wrapper / LLVMWrapper.h
1 #include "llvm-c/BitReader.h"
2 #include "llvm-c/Core.h"
3 #include "llvm-c/Object.h"
4 #include "llvm/ADT/ArrayRef.h"
5 #include "llvm/ADT/DenseSet.h"
6 #include "llvm/ADT/SmallVector.h"
7 #include "llvm/ADT/Triple.h"
8 #include "llvm/Analysis/Lint.h"
9 #include "llvm/Analysis/Passes.h"
10 #include "llvm/IR/IRBuilder.h"
11 #include "llvm/IR/InlineAsm.h"
12 #include "llvm/IR/LLVMContext.h"
13 #include "llvm/IR/Module.h"
14 #include "llvm/Support/CommandLine.h"
15 #include "llvm/Support/Debug.h"
16 #include "llvm/Support/DynamicLibrary.h"
17 #include "llvm/Support/FormattedStream.h"
18 #include "llvm/Support/Host.h"
19 #include "llvm/Support/Memory.h"
20 #include "llvm/Support/SourceMgr.h"
21 #include "llvm/Support/TargetRegistry.h"
22 #include "llvm/Support/TargetSelect.h"
23 #include "llvm/Support/Timer.h"
24 #include "llvm/Support/raw_ostream.h"
25 #include "llvm/Target/TargetMachine.h"
26 #include "llvm/Target/TargetOptions.h"
27 #include "llvm/Transforms/IPO.h"
28 #include "llvm/Transforms/Instrumentation.h"
29 #include "llvm/Transforms/Scalar.h"
30 #include "llvm/Transforms/Vectorize.h"
31
32 #define LLVM_VERSION_GE(major, minor)                                          \
33   (LLVM_VERSION_MAJOR > (major) ||                                             \
34    LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR >= (minor))
35
36 #define LLVM_VERSION_EQ(major, minor)                                          \
37   (LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR == (minor))
38
39 #define LLVM_VERSION_LE(major, minor)                                          \
40   (LLVM_VERSION_MAJOR < (major) ||                                             \
41    LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR <= (minor))
42
43 #define LLVM_VERSION_LT(major, minor) (!LLVM_VERSION_GE((major), (minor)))
44
45 #include "llvm/IR/LegacyPassManager.h"
46
47 #include "llvm/Bitcode/BitcodeReader.h"
48 #include "llvm/Bitcode/BitcodeWriter.h"
49
50 #include "llvm/IR/DIBuilder.h"
51 #include "llvm/IR/DebugInfo.h"
52 #include "llvm/IR/IRPrintingPasses.h"
53 #include "llvm/Linker/Linker.h"
54
55 extern "C" void LLVMRustSetLastError(const char *);
56
57 enum class LLVMRustResult { Success, Failure };
58
59 enum LLVMRustAttribute {
60   AlwaysInline = 0,
61   ByVal = 1,
62   Cold = 2,
63   InlineHint = 3,
64   MinSize = 4,
65   Naked = 5,
66   NoAlias = 6,
67   NoCapture = 7,
68   NoInline = 8,
69   NonNull = 9,
70   NoRedZone = 10,
71   NoReturn = 11,
72   NoUnwind = 12,
73   OptimizeForSize = 13,
74   ReadOnly = 14,
75   SExt = 15,
76   StructRet = 16,
77   UWTable = 17,
78   ZExt = 18,
79   InReg = 19,
80   SanitizeThread = 20,
81   SanitizeAddress = 21,
82   SanitizeMemory = 22,
83   NonLazyBind = 23,
84   OptimizeNone = 24,
85   ReturnsTwice = 25,
86   ReadNone = 26,
87   InaccessibleMemOnly = 27,
88 };
89
90 typedef struct OpaqueRustString *RustStringRef;
91 typedef struct LLVMOpaqueTwine *LLVMTwineRef;
92 typedef struct LLVMOpaqueSMDiagnostic *LLVMSMDiagnosticRef;
93
94 extern "C" void LLVMRustStringWriteImpl(RustStringRef Str, const char *Ptr,
95                                         size_t Size);
96
97 class RawRustStringOstream : public llvm::raw_ostream {
98   RustStringRef Str;
99   uint64_t Pos;
100
101   void write_impl(const char *Ptr, size_t Size) override {
102     LLVMRustStringWriteImpl(Str, Ptr, Size);
103     Pos += Size;
104   }
105
106   uint64_t current_pos() const override { return Pos; }
107
108 public:
109   explicit RawRustStringOstream(RustStringRef Str) : Str(Str), Pos(0) {}
110
111   ~RawRustStringOstream() {
112     // LLVM requires this.
113     flush();
114   }
115 };