[llvm] r201699 - Refactor TargetOptions initialization into a single place.
Eli Bendersky
eliben at google.com
Wed Feb 19 09:09:36 PST 2014
Author: eliben
Date: Wed Feb 19 11:09:35 2014
New Revision: 201699
URL: http://llvm.org/viewvc/llvm-project?rev=201699&view=rev
Log:
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.
Modified:
llvm/trunk/include/llvm/CodeGen/CommandFlags.h
llvm/trunk/tools/llc/llc.cpp
llvm/trunk/tools/llvm-lto/llvm-lto.cpp
llvm/trunk/tools/lto/lto.cpp
llvm/trunk/tools/opt/opt.cpp
Modified: llvm/trunk/include/llvm/CodeGen/CommandFlags.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/CommandFlags.h?rev=201699&r1=201698&r2=201699&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/CommandFlags.h (original)
+++ llvm/trunk/include/llvm/CodeGen/CommandFlags.h Wed Feb 19 11:09:35 2014
@@ -19,6 +19,7 @@
#include "llvm/Support/CodeGen.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Target/TargetMachine.h"
+#include "llvm/Target/TargetOptions.h"
#include <string>
using namespace llvm;
@@ -207,4 +208,30 @@ cl::opt<std::string> StartAfter("start-a
cl::value_desc("pass-name"),
cl::init(""));
+// Common utility function tightly tied to the options listed here. Initializes
+// a TargetOptions object with CodeGen flags and returns it.
+static inline TargetOptions InitTargetOptionsFromCodeGenFlags() {
+ TargetOptions Options;
+ Options.LessPreciseFPMADOption = EnableFPMAD;
+ Options.NoFramePointerElim = DisableFPElim;
+ Options.AllowFPOpFusion = FuseFPOps;
+ Options.UnsafeFPMath = EnableUnsafeFPMath;
+ Options.NoInfsFPMath = EnableNoInfsFPMath;
+ Options.NoNaNsFPMath = EnableNoNaNsFPMath;
+ Options.HonorSignDependentRoundingFPMathOption =
+ EnableHonorSignDependentRoundingFPMath;
+ Options.UseSoftFloat = GenerateSoftFloatCalls;
+ if (FloatABIForCalls != FloatABI::Default)
+ Options.FloatABIType = FloatABIForCalls;
+ Options.NoZerosInBSS = DontPlaceZerosInBSS;
+ Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
+ Options.DisableTailCalls = DisableTailCalls;
+ Options.StackAlignmentOverride = OverrideStackAlignment;
+ Options.TrapFuncName = TrapFuncName;
+ Options.PositionIndependentExecutable = EnablePIE;
+ Options.EnableSegmentedStacks = SegmentedStacks;
+ Options.UseInitArray = UseInitArray;
+ return Options;
+}
+
#endif
Modified: llvm/trunk/tools/llc/llc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llc/llc.cpp?rev=201699&r1=201698&r2=201699&view=diff
==============================================================================
--- llvm/trunk/tools/llc/llc.cpp (original)
+++ llvm/trunk/tools/llc/llc.cpp Wed Feb 19 11:09:35 2014
@@ -259,26 +259,7 @@ static int compileModule(char **argv, LL
case '3': OLvl = CodeGenOpt::Aggressive; break;
}
- TargetOptions Options;
- Options.LessPreciseFPMADOption = EnableFPMAD;
- Options.NoFramePointerElim = DisableFPElim;
- Options.AllowFPOpFusion = FuseFPOps;
- Options.UnsafeFPMath = EnableUnsafeFPMath;
- Options.NoInfsFPMath = EnableNoInfsFPMath;
- Options.NoNaNsFPMath = EnableNoNaNsFPMath;
- Options.HonorSignDependentRoundingFPMathOption =
- EnableHonorSignDependentRoundingFPMath;
- Options.UseSoftFloat = GenerateSoftFloatCalls;
- if (FloatABIForCalls != FloatABI::Default)
- Options.FloatABIType = FloatABIForCalls;
- Options.NoZerosInBSS = DontPlaceZerosInBSS;
- Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
- Options.DisableTailCalls = DisableTailCalls;
- Options.StackAlignmentOverride = OverrideStackAlignment;
- Options.TrapFuncName = TrapFuncName;
- Options.PositionIndependentExecutable = EnablePIE;
- Options.EnableSegmentedStacks = SegmentedStacks;
- Options.UseInitArray = UseInitArray;
+ TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
OwningPtr<TargetMachine>
target(TheTarget->createTargetMachine(TheTriple.getTriple(),
Modified: llvm/trunk/tools/llvm-lto/llvm-lto.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-lto/llvm-lto.cpp?rev=201699&r1=201698&r2=201699&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-lto/llvm-lto.cpp (original)
+++ llvm/trunk/tools/llvm-lto/llvm-lto.cpp Wed Feb 19 11:09:35 2014
@@ -77,26 +77,7 @@ int main(int argc, char **argv) {
InitializeAllAsmParsers();
// set up the TargetOptions for the machine
- TargetOptions Options;
- Options.LessPreciseFPMADOption = EnableFPMAD;
- Options.NoFramePointerElim = DisableFPElim;
- Options.AllowFPOpFusion = FuseFPOps;
- Options.UnsafeFPMath = EnableUnsafeFPMath;
- Options.NoInfsFPMath = EnableNoInfsFPMath;
- Options.NoNaNsFPMath = EnableNoNaNsFPMath;
- Options.HonorSignDependentRoundingFPMathOption =
- EnableHonorSignDependentRoundingFPMath;
- Options.UseSoftFloat = GenerateSoftFloatCalls;
- if (FloatABIForCalls != FloatABI::Default)
- Options.FloatABIType = FloatABIForCalls;
- Options.NoZerosInBSS = DontPlaceZerosInBSS;
- Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
- Options.DisableTailCalls = DisableTailCalls;
- Options.StackAlignmentOverride = OverrideStackAlignment;
- Options.TrapFuncName = TrapFuncName;
- Options.PositionIndependentExecutable = EnablePIE;
- Options.EnableSegmentedStacks = SegmentedStacks;
- Options.UseInitArray = UseInitArray;
+ TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
unsigned BaseArg = 0;
Modified: llvm/trunk/tools/lto/lto.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/lto.cpp?rev=201699&r1=201698&r2=201699&view=diff
==============================================================================
--- llvm/trunk/tools/lto/lto.cpp (original)
+++ llvm/trunk/tools/lto/lto.cpp Wed Feb 19 11:09:35 2014
@@ -56,28 +56,6 @@ static void lto_initialize() {
}
}
-static void lto_set_target_options(llvm::TargetOptions &Options) {
- Options.LessPreciseFPMADOption = EnableFPMAD;
- Options.NoFramePointerElim = DisableFPElim;
- Options.AllowFPOpFusion = FuseFPOps;
- Options.UnsafeFPMath = EnableUnsafeFPMath;
- Options.NoInfsFPMath = EnableNoInfsFPMath;
- Options.NoNaNsFPMath = EnableNoNaNsFPMath;
- Options.HonorSignDependentRoundingFPMathOption =
- EnableHonorSignDependentRoundingFPMath;
- Options.UseSoftFloat = GenerateSoftFloatCalls;
- if (FloatABIForCalls != llvm::FloatABI::Default)
- Options.FloatABIType = FloatABIForCalls;
- Options.NoZerosInBSS = DontPlaceZerosInBSS;
- Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
- Options.DisableTailCalls = DisableTailCalls;
- Options.StackAlignmentOverride = OverrideStackAlignment;
- Options.TrapFuncName = TrapFuncName;
- Options.PositionIndependentExecutable = EnablePIE;
- Options.EnableSegmentedStacks = SegmentedStacks;
- Options.UseInitArray = UseInitArray;
-}
-
/// lto_get_version - Returns a printable string.
extern const char* lto_get_version() {
return LTOCodeGenerator::getVersionString();
@@ -120,8 +98,7 @@ lto_module_is_object_file_in_memory_for_
/// (check lto_get_error_message() for details).
lto_module_t lto_module_create(const char* path) {
lto_initialize();
- llvm::TargetOptions Options;
- lto_set_target_options(Options);
+ llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
return LTOModule::makeLTOModule(path, Options, sLastErrorString);
}
@@ -129,8 +106,7 @@ lto_module_t lto_module_create(const cha
/// error (check lto_get_error_message() for details).
lto_module_t lto_module_create_from_fd(int fd, const char *path, size_t size) {
lto_initialize();
- llvm::TargetOptions Options;
- lto_set_target_options(Options);
+ llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
return LTOModule::makeLTOModule(fd, path, size, Options, sLastErrorString);
}
@@ -141,8 +117,7 @@ lto_module_t lto_module_create_from_fd_a
size_t map_size,
off_t offset) {
lto_initialize();
- llvm::TargetOptions Options;
- lto_set_target_options(Options);
+ llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
return LTOModule::makeLTOModule(fd, path, map_size, offset, Options,
sLastErrorString);
}
@@ -151,8 +126,7 @@ lto_module_t lto_module_create_from_fd_a
/// NULL on error (check lto_get_error_message() for details).
lto_module_t lto_module_create_from_memory(const void* mem, size_t length) {
lto_initialize();
- llvm::TargetOptions Options;
- lto_set_target_options(Options);
+ llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
return LTOModule::makeLTOModule(mem, length, Options, sLastErrorString);
}
@@ -162,8 +136,7 @@ lto_module_t lto_module_create_from_memo
size_t length,
const char *path) {
lto_initialize();
- llvm::TargetOptions Options;
- lto_set_target_options(Options);
+ llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
return LTOModule::makeLTOModule(mem, length, Options, sLastErrorString, path);
}
@@ -238,8 +211,7 @@ void lto_codegen_set_diagnostic_handler(
lto_code_gen_t lto_codegen_create(void) {
lto_initialize();
- TargetOptions Options;
- lto_set_target_options(Options);
+ TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
LTOCodeGenerator *CodeGen = new LTOCodeGenerator();
if (CodeGen)
Modified: llvm/trunk/tools/opt/opt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/opt.cpp?rev=201699&r1=201698&r2=201699&view=diff
==============================================================================
--- llvm/trunk/tools/opt/opt.cpp (original)
+++ llvm/trunk/tools/opt/opt.cpp Wed Feb 19 11:09:35 2014
@@ -273,29 +273,6 @@ static void AddStandardLinkPasses(PassMa
//===----------------------------------------------------------------------===//
// CodeGen-related helper functions.
//
-static TargetOptions GetTargetOptions() {
- TargetOptions Options;
- Options.LessPreciseFPMADOption = EnableFPMAD;
- Options.NoFramePointerElim = DisableFPElim;
- Options.AllowFPOpFusion = FuseFPOps;
- Options.UnsafeFPMath = EnableUnsafeFPMath;
- Options.NoInfsFPMath = EnableNoInfsFPMath;
- Options.NoNaNsFPMath = EnableNoNaNsFPMath;
- Options.HonorSignDependentRoundingFPMathOption =
- EnableHonorSignDependentRoundingFPMath;
- Options.UseSoftFloat = GenerateSoftFloatCalls;
- if (FloatABIForCalls != FloatABI::Default)
- Options.FloatABIType = FloatABIForCalls;
- Options.NoZerosInBSS = DontPlaceZerosInBSS;
- Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
- Options.DisableTailCalls = DisableTailCalls;
- Options.StackAlignmentOverride = OverrideStackAlignment;
- Options.TrapFuncName = TrapFuncName;
- Options.PositionIndependentExecutable = EnablePIE;
- Options.EnableSegmentedStacks = SegmentedStacks;
- Options.UseInitArray = UseInitArray;
- return Options;
-}
CodeGenOpt::Level GetCodeGenOptLevel() {
if (OptLevelO1)
@@ -327,7 +304,8 @@ static TargetMachine* GetTargetMachine(T
}
return TheTarget->createTargetMachine(TheTriple.getTriple(),
- MCPU, FeaturesStr, GetTargetOptions(),
+ MCPU, FeaturesStr,
+ InitTargetOptionsFromCodeGenFlags(),
RelocModel, CMModel,
GetCodeGenOptLevel());
}
More information about the llvm-commits
mailing list