1 | /* |
---|
2 | * Copyright (c) 2017 International Characters. |
---|
3 | * This software is licensed to the public under the Open Software License 3.0. |
---|
4 | * icgrep is a trademark of International Characters. |
---|
5 | */ |
---|
6 | |
---|
7 | #ifndef TOOLCHAIN_H |
---|
8 | #define TOOLCHAIN_H |
---|
9 | |
---|
10 | #include <llvm/ADT/StringRef.h> |
---|
11 | #include <llvm/Support/CodeGen.h> |
---|
12 | #include <llvm/Target/TargetOptions.h> |
---|
13 | #include <llvm/Target/TargetMachine.h> |
---|
14 | |
---|
15 | // #defines for comparison with LLVM_VERSION_INTEGER |
---|
16 | #define LLVM_3_6_0 30600 |
---|
17 | #define LLVM_3_7_0 30700 |
---|
18 | #define LLVM_3_8_0 30800 |
---|
19 | #define LLVM_3_9_0 30900 |
---|
20 | #define LLVM_4_0_0 40000 |
---|
21 | #define LLVM_5_0_0 50000 |
---|
22 | #define LLVM_6_0_0 60000 |
---|
23 | |
---|
24 | // From LLVM 4.0.0 the clEnumValEnd sentinel is no longer needed. |
---|
25 | // We define a macro to adapt to the CommandLine syntax based on LLVM version. |
---|
26 | #if LLVM_VERSION_INTEGER < LLVM_4_0_0 |
---|
27 | #define CL_ENUM_VAL_SENTINEL , clEnumValEnd |
---|
28 | #else |
---|
29 | #define CL_ENUM_VAL_SENTINEL |
---|
30 | #endif |
---|
31 | |
---|
32 | // FIXME: llvm/CodeGen/CommandFlags.h can only be included once or the various cl::opt causes multiple definition |
---|
33 | // errors. To bypass for now, the relevant options and functions are accessible from here. Re-evaluate with later |
---|
34 | // versions of LLVM. |
---|
35 | |
---|
36 | namespace llvm { namespace cl { class OptionCategory; } } |
---|
37 | |
---|
38 | namespace codegen { |
---|
39 | |
---|
40 | const llvm::cl::OptionCategory * codegen_flags(); |
---|
41 | |
---|
42 | // Command Parameters |
---|
43 | enum DebugFlags { |
---|
44 | VerifyIR, |
---|
45 | SerializeThreads, |
---|
46 | TraceCounts, |
---|
47 | TraceDynamicBuffers, |
---|
48 | EnableAsserts, |
---|
49 | EnableCycleCounter, |
---|
50 | DebugFlagSentinel |
---|
51 | }; |
---|
52 | |
---|
53 | bool DebugOptionIsSet(const DebugFlags flag); |
---|
54 | |
---|
55 | extern bool PipelineParallel; |
---|
56 | extern bool SegmentPipelineParallel; |
---|
57 | |
---|
58 | // Options for generating IR or ASM to files |
---|
59 | const std::string OmittedOption = "."; |
---|
60 | extern std::string ShowUnoptimizedIROption; |
---|
61 | extern std::string ShowIROption; |
---|
62 | #if LLVM_VERSION_INTEGER >= LLVM_3_7_0 |
---|
63 | extern std::string ShowASMOption; |
---|
64 | #endif |
---|
65 | extern const char * ObjectCacheDir; |
---|
66 | extern llvm::CodeGenOpt::Level OptLevel; // set from command line |
---|
67 | extern int BlockSize; // set from command line |
---|
68 | extern int SegmentSize; // set from command line |
---|
69 | extern int BufferSegments; |
---|
70 | extern int ThreadNum; |
---|
71 | extern bool EnableObjectCache; |
---|
72 | extern bool NVPTX; |
---|
73 | extern int GroupNum; |
---|
74 | extern std::string ProgramName; |
---|
75 | extern llvm::TargetOptions Options; |
---|
76 | extern const llvm::Reloc::Model RelocModel; |
---|
77 | extern const llvm::CodeModel::Model CMModel; |
---|
78 | extern const std::string MArch; |
---|
79 | extern const std::string RunPass; |
---|
80 | extern const llvm::TargetMachine::CodeGenFileType FileType; |
---|
81 | extern const std::string StopAfter; |
---|
82 | extern const std::string StartAfter; |
---|
83 | |
---|
84 | std::string getCPUStr(); |
---|
85 | std::string getFeaturesStr(); |
---|
86 | void setFunctionAttributes(llvm::StringRef CPU, llvm::StringRef Features, llvm::Module &M); |
---|
87 | |
---|
88 | void ParseCommandLineOptions(int argc, const char *const *argv, std::initializer_list<const llvm::cl::OptionCategory *> hiding = {}); |
---|
89 | |
---|
90 | } |
---|
91 | |
---|
92 | void AddParabixVersionPrinter(); |
---|
93 | |
---|
94 | bool AVX2_available(); |
---|
95 | |
---|
96 | #endif |
---|