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