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