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 
32 namespace codegen {
33 
34 std::string getMArch();
35 
36 std::string getMCPU();
37 
38 std::vector<std::string> getMAttrs();
39 
40 Reloc::Model getRelocModel();
41 std::optional<Reloc::Model> getExplicitRelocModel();
42 
43 ThreadModel::Model getThreadModel();
44 
45 CodeModel::Model getCodeModel();
46 std::optional<CodeModel::Model> getExplicitCodeModel();
47 
48 llvm::ExceptionHandling getExceptionModel();
49 
50 std::optional<CodeGenFileType> getExplicitFileType();
51 
52 CodeGenFileType getFileType();
53 
54 FramePointerKind getFramePointerUsage();
55 
56 bool getEnableUnsafeFPMath();
57 
58 bool getEnableNoInfsFPMath();
59 
60 bool getEnableNoNaNsFPMath();
61 
62 bool getEnableNoSignedZerosFPMath();
63 
64 bool getEnableApproxFuncFPMath();
65 
66 bool getEnableNoTrappingFPMath();
67 
68 DenormalMode::DenormalModeKind getDenormalFPMath();
69 DenormalMode::DenormalModeKind getDenormalFP32Math();
70 
71 bool getEnableHonorSignDependentRoundingFPMath();
72 
73 llvm::FloatABI::ABIType getFloatABIForCalls();
74 
75 llvm::FPOpFusion::FPOpFusionMode getFuseFPOps();
76 
77 SwiftAsyncFramePointerMode getSwiftAsyncFramePointer();
78 
79 bool getDontPlaceZerosInBSS();
80 
81 bool getEnableGuaranteedTailCallOpt();
82 
83 bool getEnableAIXExtendedAltivecABI();
84 
85 bool getDisableTailCalls();
86 
87 bool getStackSymbolOrdering();
88 
89 unsigned getOverrideStackAlignment();
90 
91 bool getStackRealign();
92 
93 std::string getTrapFuncName();
94 
95 bool getUseCtors();
96 
97 bool getDisableIntegratedAS();
98 
99 bool getRelaxELFRelocations();
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 getUniqueSectionNames();
119 
120 bool getUniqueBasicBlockSectionNames();
121 
122 llvm::EABI getEABIVersion();
123 
124 llvm::DebuggerKind getDebuggerTuningOpt();
125 
126 bool getEnableStackSizeSection();
127 
128 bool getEnableAddrsig();
129 
130 bool getEmitCallSiteInfo();
131 
132 bool getEnableMachineFunctionSplitter();
133 
134 bool getEnableDebugEntryValues();
135 
136 bool getValueTrackingVariableLocations();
137 std::optional<bool> getExplicitValueTrackingVariableLocations();
138 
139 bool getForceDwarfFrameSection();
140 
141 bool getXRayFunctionIndex();
142 
143 bool getDebugStrictDwarf();
144 
145 unsigned getAlignLoops();
146 
147 bool getJMCInstrument();
148 
149 bool getXCOFFReadOnlyPointers();
150 
151 /// Create this object with static storage to register codegen-related command
152 /// line options.
153 struct RegisterCodeGenFlags {
154   RegisterCodeGenFlags();
155 };
156 
157 llvm::BasicBlockSection getBBSectionsMode(llvm::TargetOptions &Options);
158 
159 /// Common utility function tightly tied to the options listed here. Initializes
160 /// a TargetOptions object with CodeGen flags and returns it.
161 /// \p TheTriple is used to determine the default value for options if
162 ///    options are not explicitly specified. If those triple dependant options
163 ///    value do not have effect for your component, a default Triple() could be
164 ///    passed in.
165 TargetOptions InitTargetOptionsFromCodeGenFlags(const llvm::Triple &TheTriple);
166 
167 std::string getCPUStr();
168 
169 std::string getFeaturesStr();
170 
171 std::vector<std::string> getFeatureList();
172 
173 void renderBoolStringAttr(AttrBuilder &B, StringRef Name, bool Val);
174 
175 /// Set function attributes of function \p F based on CPU, Features, and command
176 /// line flags.
177 void setFunctionAttributes(StringRef CPU, StringRef Features, Function &F);
178 
179 /// Set function attributes of functions in Module M based on CPU,
180 /// Features, and command line flags.
181 void setFunctionAttributes(StringRef CPU, StringRef Features, Module &M);
182 
183 /// Should value-tracking variable locations / instruction referencing be
184 /// enabled by default for this triple?
185 bool getDefaultValueTrackingVariableLocations(const llvm::Triple &T);
186 } // namespace codegen
187 } // namespace llvm
188 
189 #endif // LLVM_CODEGEN_COMMANDFLAGS_H
190