1 //===-- CommandFlags.h - Command Line Flags Interface -----------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains codegen-specific flags that are shared between different
10 // command line tools. The tools "llc" and "opt" both use this file to prevent
11 // flag duplication.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CODEGEN_COMMANDFLAGS_H
16 #define LLVM_CODEGEN_COMMANDFLAGS_H
17 
18 #include "llvm/ADT/FloatingPointMode.h"
19 #include "llvm/Support/CodeGen.h"
20 #include "llvm/Target/TargetOptions.h"
21 #include <optional>
22 #include <string>
23 #include <vector>
24 
25 namespace llvm {
26 
27 class Module;
28 class AttrBuilder;
29 class Function;
30 class Triple;
31 class TargetMachine;
32 
33 namespace codegen {
34 
35 std::string getMArch();
36 
37 std::string getMCPU();
38 
39 std::vector<std::string> getMAttrs();
40 
41 Reloc::Model getRelocModel();
42 std::optional<Reloc::Model> getExplicitRelocModel();
43 
44 ThreadModel::Model getThreadModel();
45 
46 CodeModel::Model getCodeModel();
47 std::optional<CodeModel::Model> getExplicitCodeModel();
48 
49 uint64_t getLargeDataThreshold();
50 std::optional<uint64_t> getExplicitLargeDataThreshold();
51 
52 llvm::ExceptionHandling getExceptionModel();
53 
54 std::optional<CodeGenFileType> getExplicitFileType();
55 
56 CodeGenFileType getFileType();
57 
58 FramePointerKind getFramePointerUsage();
59 
60 bool getEnableUnsafeFPMath();
61 
62 bool getEnableNoInfsFPMath();
63 
64 bool getEnableNoNaNsFPMath();
65 
66 bool getEnableNoSignedZerosFPMath();
67 
68 bool getEnableApproxFuncFPMath();
69 
70 bool getEnableNoTrappingFPMath();
71 
72 DenormalMode::DenormalModeKind getDenormalFPMath();
73 DenormalMode::DenormalModeKind getDenormalFP32Math();
74 
75 bool getEnableHonorSignDependentRoundingFPMath();
76 
77 llvm::FloatABI::ABIType getFloatABIForCalls();
78 
79 llvm::FPOpFusion::FPOpFusionMode getFuseFPOps();
80 
81 SwiftAsyncFramePointerMode getSwiftAsyncFramePointer();
82 
83 bool getDontPlaceZerosInBSS();
84 
85 bool getEnableGuaranteedTailCallOpt();
86 
87 bool getEnableAIXExtendedAltivecABI();
88 
89 bool getDisableTailCalls();
90 
91 bool getStackSymbolOrdering();
92 
93 bool getStackRealign();
94 
95 std::string getTrapFuncName();
96 
97 bool getUseCtors();
98 
99 bool getDisableIntegratedAS();
100 
101 bool getDataSections();
102 std::optional<bool> getExplicitDataSections();
103 
104 bool getFunctionSections();
105 std::optional<bool> getExplicitFunctionSections();
106 
107 bool getIgnoreXCOFFVisibility();
108 
109 bool getXCOFFTracebackTable();
110 
111 std::string getBBSections();
112 
113 unsigned getTLSSize();
114 
115 bool getEmulatedTLS();
116 std::optional<bool> getExplicitEmulatedTLS();
117 
118 bool getEnableTLSDESC();
119 std::optional<bool> getExplicitEnableTLSDESC();
120 
121 bool getUniqueSectionNames();
122 
123 bool getUniqueBasicBlockSectionNames();
124 
125 bool getSeparateNamedSections();
126 
127 llvm::EABI getEABIVersion();
128 
129 llvm::DebuggerKind getDebuggerTuningOpt();
130 
131 bool getEnableStackSizeSection();
132 
133 bool getEnableAddrsig();
134 
135 bool getEmitCallSiteInfo();
136 
137 bool getEnableMachineFunctionSplitter();
138 
139 bool getEnableDebugEntryValues();
140 
141 bool getValueTrackingVariableLocations();
142 std::optional<bool> getExplicitValueTrackingVariableLocations();
143 
144 bool getForceDwarfFrameSection();
145 
146 bool getXRayFunctionIndex();
147 
148 bool getDebugStrictDwarf();
149 
150 unsigned getAlignLoops();
151 
152 bool getJMCInstrument();
153 
154 bool getXCOFFReadOnlyPointers();
155 
156 /// Create this object with static storage to register codegen-related command
157 /// line options.
158 struct RegisterCodeGenFlags {
159   RegisterCodeGenFlags();
160 };
161 
162 bool getEnableBBAddrMap();
163 
164 llvm::BasicBlockSection getBBSectionsMode(llvm::TargetOptions &Options);
165 
166 /// Common utility function tightly tied to the options listed here. Initializes
167 /// a TargetOptions object with CodeGen flags and returns it.
168 /// \p TheTriple is used to determine the default value for options if
169 ///    options are not explicitly specified. If those triple dependant options
170 ///    value do not have effect for your component, a default Triple() could be
171 ///    passed in.
172 TargetOptions InitTargetOptionsFromCodeGenFlags(const llvm::Triple &TheTriple);
173 
174 std::string getCPUStr();
175 
176 std::string getFeaturesStr();
177 
178 std::vector<std::string> getFeatureList();
179 
180 void renderBoolStringAttr(AttrBuilder &B, StringRef Name, bool Val);
181 
182 /// Set function attributes of function \p F based on CPU, Features, and command
183 /// line flags.
184 void setFunctionAttributes(StringRef CPU, StringRef Features, Function &F);
185 
186 /// Set function attributes of functions in Module M based on CPU,
187 /// Features, and command line flags.
188 void setFunctionAttributes(StringRef CPU, StringRef Features, Module &M);
189 
190 /// Should value-tracking variable locations / instruction referencing be
191 /// enabled by default for this triple?
192 bool getDefaultValueTrackingVariableLocations(const llvm::Triple &T);
193 
194 /// Creates a TargetMachine instance with the options defined on the command
195 /// line. This can be used for tools that do not need further customization of
196 /// the TargetOptions.
197 Expected<std::unique_ptr<TargetMachine>> createTargetMachineForTriple(
198     StringRef TargetTriple,
199     CodeGenOptLevel OptLevel = CodeGenOptLevel::Default);
200 
201 } // namespace codegen
202 } // namespace llvm
203 
204 #endif // LLVM_CODEGEN_COMMANDFLAGS_H
205