llvm.org GIT mirror llvm / cf42174
Refactor TargetOptions initialization into a single place. The same code (~20 lines) for initializing a TargetOptions object from CodeGen cmdline flags is duplicated 4 times in 4 different tools. This patch moves it into a utility function. Since the CodeGen/CommandFlags.h file defines cl::opt flags in a header, it's a bit of a touchy situation because we should only link them into tools. So this patch puts the init function in the header. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201699 91177308-0d34-0410-b5e6-96231b3b80d8 Eli Bendersky 5 years ago
5 changed file(s) with 37 addition(s) and 98 deletion(s). Raw diff Collapse all Expand all
1818 #include "llvm/Support/CodeGen.h"
1919 #include "llvm/Support/CommandLine.h"
2020 #include "llvm/Target/TargetMachine.h"
21 #include "llvm/Target/TargetOptions.h"
2122 #include
2223 using namespace llvm;
2324
206207 cl::value_desc("pass-name"),
207208 cl::init(""));
208209
210 // Common utility function tightly tied to the options listed here. Initializes
211 // a TargetOptions object with CodeGen flags and returns it.
212 static inline TargetOptions InitTargetOptionsFromCodeGenFlags() {
213 TargetOptions Options;
214 Options.LessPreciseFPMADOption = EnableFPMAD;
215 Options.NoFramePointerElim = DisableFPElim;
216 Options.AllowFPOpFusion = FuseFPOps;
217 Options.UnsafeFPMath = EnableUnsafeFPMath;
218 Options.NoInfsFPMath = EnableNoInfsFPMath;
219 Options.NoNaNsFPMath = EnableNoNaNsFPMath;
220 Options.HonorSignDependentRoundingFPMathOption =
221 EnableHonorSignDependentRoundingFPMath;
222 Options.UseSoftFloat = GenerateSoftFloatCalls;
223 if (FloatABIForCalls != FloatABI::Default)
224 Options.FloatABIType = FloatABIForCalls;
225 Options.NoZerosInBSS = DontPlaceZerosInBSS;
226 Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
227 Options.DisableTailCalls = DisableTailCalls;
228 Options.StackAlignmentOverride = OverrideStackAlignment;
229 Options.TrapFuncName = TrapFuncName;
230 Options.PositionIndependentExecutable = EnablePIE;
231 Options.EnableSegmentedStacks = SegmentedStacks;
232 Options.UseInitArray = UseInitArray;
233 return Options;
234 }
235
209236 #endif
258258 case '3': OLvl = CodeGenOpt::Aggressive; break;
259259 }
260260
261 TargetOptions Options;
262 Options.LessPreciseFPMADOption = EnableFPMAD;
263 Options.NoFramePointerElim = DisableFPElim;
264 Options.AllowFPOpFusion = FuseFPOps;
265 Options.UnsafeFPMath = EnableUnsafeFPMath;
266 Options.NoInfsFPMath = EnableNoInfsFPMath;
267 Options.NoNaNsFPMath = EnableNoNaNsFPMath;
268 Options.HonorSignDependentRoundingFPMathOption =
269 EnableHonorSignDependentRoundingFPMath;
270 Options.UseSoftFloat = GenerateSoftFloatCalls;
271 if (FloatABIForCalls != FloatABI::Default)
272 Options.FloatABIType = FloatABIForCalls;
273 Options.NoZerosInBSS = DontPlaceZerosInBSS;
274 Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
275 Options.DisableTailCalls = DisableTailCalls;
276 Options.StackAlignmentOverride = OverrideStackAlignment;
277 Options.TrapFuncName = TrapFuncName;
278 Options.PositionIndependentExecutable = EnablePIE;
279 Options.EnableSegmentedStacks = SegmentedStacks;
280 Options.UseInitArray = UseInitArray;
261 TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
281262
282263 OwningPtr
283264 target(TheTarget->createTargetMachine(TheTriple.getTriple(),
7676 InitializeAllAsmParsers();
7777
7878 // set up the TargetOptions for the machine
79 TargetOptions Options;
80 Options.LessPreciseFPMADOption = EnableFPMAD;
81 Options.NoFramePointerElim = DisableFPElim;
82 Options.AllowFPOpFusion = FuseFPOps;
83 Options.UnsafeFPMath = EnableUnsafeFPMath;
84 Options.NoInfsFPMath = EnableNoInfsFPMath;
85 Options.NoNaNsFPMath = EnableNoNaNsFPMath;
86 Options.HonorSignDependentRoundingFPMathOption =
87 EnableHonorSignDependentRoundingFPMath;
88 Options.UseSoftFloat = GenerateSoftFloatCalls;
89 if (FloatABIForCalls != FloatABI::Default)
90 Options.FloatABIType = FloatABIForCalls;
91 Options.NoZerosInBSS = DontPlaceZerosInBSS;
92 Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
93 Options.DisableTailCalls = DisableTailCalls;
94 Options.StackAlignmentOverride = OverrideStackAlignment;
95 Options.TrapFuncName = TrapFuncName;
96 Options.PositionIndependentExecutable = EnablePIE;
97 Options.EnableSegmentedStacks = SegmentedStacks;
98 Options.UseInitArray = UseInitArray;
79 TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
9980
10081 unsigned BaseArg = 0;
10182
5555 }
5656 }
5757
58 static void lto_set_target_options(llvm::TargetOptions &Options) {
59 Options.LessPreciseFPMADOption = EnableFPMAD;
60 Options.NoFramePointerElim = DisableFPElim;
61 Options.AllowFPOpFusion = FuseFPOps;
62 Options.UnsafeFPMath = EnableUnsafeFPMath;
63 Options.NoInfsFPMath = EnableNoInfsFPMath;
64 Options.NoNaNsFPMath = EnableNoNaNsFPMath;
65 Options.HonorSignDependentRoundingFPMathOption =
66 EnableHonorSignDependentRoundingFPMath;
67 Options.UseSoftFloat = GenerateSoftFloatCalls;
68 if (FloatABIForCalls != llvm::FloatABI::Default)
69 Options.FloatABIType = FloatABIForCalls;
70 Options.NoZerosInBSS = DontPlaceZerosInBSS;
71 Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
72 Options.DisableTailCalls = DisableTailCalls;
73 Options.StackAlignmentOverride = OverrideStackAlignment;
74 Options.TrapFuncName = TrapFuncName;
75 Options.PositionIndependentExecutable = EnablePIE;
76 Options.EnableSegmentedStacks = SegmentedStacks;
77 Options.UseInitArray = UseInitArray;
78 }
79
8058 /// lto_get_version - Returns a printable string.
8159 extern const char* lto_get_version() {
8260 return LTOCodeGenerator::getVersionString();
11997 /// (check lto_get_error_message() for details).
12098 lto_module_t lto_module_create(const char* path) {
12199 lto_initialize();
122 llvm::TargetOptions Options;
123 lto_set_target_options(Options);
100 llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
124101 return LTOModule::makeLTOModule(path, Options, sLastErrorString);
125102 }
126103
128105 /// error (check lto_get_error_message() for details).
129106 lto_module_t lto_module_create_from_fd(int fd, const char *path, size_t size) {
130107 lto_initialize();
131 llvm::TargetOptions Options;
132 lto_set_target_options(Options);
108 llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
133109 return LTOModule::makeLTOModule(fd, path, size, Options, sLastErrorString);
134110 }
135111
140116 size_t map_size,
141117 off_t offset) {
142118 lto_initialize();
143 llvm::TargetOptions Options;
144 lto_set_target_options(Options);
119 llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
145120 return LTOModule::makeLTOModule(fd, path, map_size, offset, Options,
146121 sLastErrorString);
147122 }
150125 /// NULL on error (check lto_get_error_message() for details).
151126 lto_module_t lto_module_create_from_memory(const void* mem, size_t length) {
152127 lto_initialize();
153 llvm::TargetOptions Options;
154 lto_set_target_options(Options);
128 llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
155129 return LTOModule::makeLTOModule(mem, length, Options, sLastErrorString);
156130 }
157131
161135 size_t length,
162136 const char *path) {
163137 lto_initialize();
164 llvm::TargetOptions Options;
165 lto_set_target_options(Options);
138 llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
166139 return LTOModule::makeLTOModule(mem, length, Options, sLastErrorString, path);
167140 }
168141
237210 lto_code_gen_t lto_codegen_create(void) {
238211 lto_initialize();
239212
240 TargetOptions Options;
241 lto_set_target_options(Options);
213 TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
242214
243215 LTOCodeGenerator *CodeGen = new LTOCodeGenerator();
244216 if (CodeGen)
272272 //===----------------------------------------------------------------------===//
273273 // CodeGen-related helper functions.
274274 //
275 static TargetOptions GetTargetOptions() {
276 TargetOptions Options;
277 Options.LessPreciseFPMADOption = EnableFPMAD;
278 Options.NoFramePointerElim = DisableFPElim;
279 Options.AllowFPOpFusion = FuseFPOps;
280 Options.UnsafeFPMath = EnableUnsafeFPMath;
281 Options.NoInfsFPMath = EnableNoInfsFPMath;
282 Options.NoNaNsFPMath = EnableNoNaNsFPMath;
283 Options.HonorSignDependentRoundingFPMathOption =
284 EnableHonorSignDependentRoundingFPMath;
285 Options.UseSoftFloat = GenerateSoftFloatCalls;
286 if (FloatABIForCalls != FloatABI::Default)
287 Options.FloatABIType = FloatABIForCalls;
288 Options.NoZerosInBSS = DontPlaceZerosInBSS;
289 Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
290 Options.DisableTailCalls = DisableTailCalls;
291 Options.StackAlignmentOverride = OverrideStackAlignment;
292 Options.TrapFuncName = TrapFuncName;
293 Options.PositionIndependentExecutable = EnablePIE;
294 Options.EnableSegmentedStacks = SegmentedStacks;
295 Options.UseInitArray = UseInitArray;
296 return Options;
297 }
298275
299276 CodeGenOpt::Level GetCodeGenOptLevel() {
300277 if (OptLevelO1)
326303 }
327304
328305 return TheTarget->createTargetMachine(TheTriple.getTriple(),
329 MCPU, FeaturesStr, GetTargetOptions(),
306 MCPU, FeaturesStr,
307 InitTargetOptionsFromCodeGenFlags(),
330308 RelocModel, CMModel,
331309 GetCodeGenOptLevel());
332310 }