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 getLowerGlobalDtorsViaCxaAtExit();
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 
117 bool getUniqueSectionNames();
118 
119 bool getUniqueBasicBlockSectionNames();
120 
121 llvm::EABI getEABIVersion();
122 
123 llvm::DebuggerKind getDebuggerTuningOpt();
124 
125 bool getEnableStackSizeSection();
126 
127 bool getEnableAddrsig();
128 
129 bool getEmitCallSiteInfo();
130 
131 bool getEnableMachineFunctionSplitter();
132 
133 bool getEnableDebugEntryValues();
134 
135 bool getValueTrackingVariableLocations();
136 std::optional<bool> getExplicitValueTrackingVariableLocations();
137 
138 bool getForceDwarfFrameSection();
139 
140 bool getXRayOmitFunctionIndex();
141 
142 bool getDebugStrictDwarf();
143 
144 unsigned getAlignLoops();
145 
146 bool getJMCInstrument();
147 
148 /// Create this object with static storage to register codegen-related command
149 /// line options.
150 struct RegisterCodeGenFlags {
151   RegisterCodeGenFlags();
152 };
153 
154 llvm::BasicBlockSection getBBSectionsMode(llvm::TargetOptions &Options);
155 
156 /// Common utility function tightly tied to the options listed here. Initializes
157 /// a TargetOptions object with CodeGen flags and returns it.
158 /// \p TheTriple is used to determine the default value for options if
159 ///    options are not explicitly specified. If those triple dependant options
160 ///    value do not have effect for your component, a default Triple() could be
161 ///    passed in.
162 TargetOptions InitTargetOptionsFromCodeGenFlags(const llvm::Triple &TheTriple);
163 
164 std::string getCPUStr();
165 
166 std::string getFeaturesStr();
167 
168 std::vector<std::string> getFeatureList();
169 
170 void renderBoolStringAttr(AttrBuilder &B, StringRef Name, bool Val);
171 
172 /// Set function attributes of function \p F based on CPU, Features, and command
173 /// line flags.
174 void setFunctionAttributes(StringRef CPU, StringRef Features, Function &F);
175 
176 /// Set function attributes of functions in Module M based on CPU,
177 /// Features, and command line flags.
178 void setFunctionAttributes(StringRef CPU, StringRef Features, Module &M);
179 
180 /// Should value-tracking variable locations / instruction referencing be
181 /// enabled by default for this triple?
182 bool getDefaultValueTrackingVariableLocations(const llvm::Triple &T);
183 } // namespace codegen
184 } // namespace llvm
185 
186 #endif // LLVM_CODEGEN_COMMANDFLAGS_H
187