aboutsummaryrefslogtreecommitdiffstats
path: root/lib/LTO
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-09-30 16:39:19 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-09-30 16:39:19 +0000
commitc13c9e5a9d288eac494a38f0710d34446167f940 (patch)
tree9963870fcea50321766abe308393c6f996187897 /lib/LTO
parent4b5205d2a3e0df909f29de0bff8ea775ad21fe0f (diff)
downloadexternal_llvm-c13c9e5a9d288eac494a38f0710d34446167f940.zip
external_llvm-c13c9e5a9d288eac494a38f0710d34446167f940.tar.gz
external_llvm-c13c9e5a9d288eac494a38f0710d34446167f940.tar.bz2
Move command line options to the users of libLTO. Fixes --enable-shared build.
Patch by Richard Sandiford. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191680 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/LTO')
-rw-r--r--lib/LTO/LTOCodeGenerator.cpp58
-rw-r--r--lib/LTO/LTOModule.cpp146
2 files changed, 53 insertions, 151 deletions
diff --git a/lib/LTO/LTOCodeGenerator.cpp b/lib/LTO/LTOCodeGenerator.cpp
index 22e9754..faa55bb 100644
--- a/lib/LTO/LTOCodeGenerator.cpp
+++ b/lib/LTO/LTOCodeGenerator.cpp
@@ -40,6 +40,7 @@
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Support/system_error.h"
+#include "llvm/Target/TargetOptions.h"
#include "llvm/Target/TargetRegisterInfo.h"
#include "llvm/Target/Mangler.h"
#include "llvm/Transforms/IPO.h"
@@ -47,18 +48,6 @@
#include "llvm/Transforms/ObjCARC.h"
using namespace llvm;
-static cl::opt<bool>
-DisableOpt("disable-opt", cl::init(false),
- cl::desc("Do not run any optimization passes"));
-
-static cl::opt<bool>
-DisableInline("disable-inlining", cl::init(false),
- cl::desc("Do not run the inliner pass"));
-
-static cl::opt<bool>
-DisableGVNLoadPRE("disable-gvn-loadpre", cl::init(false),
- cl::desc("Do not run the GVN load PRE pass"));
-
const char* LTOCodeGenerator::getVersionString() {
#ifdef LLVM_VERSION_INFO
return PACKAGE_NAME " version " PACKAGE_VERSION ", " LLVM_VERSION_INFO;
@@ -125,6 +114,27 @@ bool LTOCodeGenerator::addModule(LTOModule* mod, std::string& errMsg) {
return !ret;
}
+void LTOCodeGenerator::setTargetOptions(TargetOptions options) {
+ Options.LessPreciseFPMADOption = options.LessPreciseFPMADOption;
+ Options.NoFramePointerElim = options.NoFramePointerElim;
+ Options.AllowFPOpFusion = options.AllowFPOpFusion;
+ Options.UnsafeFPMath = options.UnsafeFPMath;
+ Options.NoInfsFPMath = options.NoInfsFPMath;
+ Options.NoNaNsFPMath = options.NoNaNsFPMath;
+ Options.HonorSignDependentRoundingFPMathOption =
+ options.HonorSignDependentRoundingFPMathOption;
+ Options.UseSoftFloat = options.UseSoftFloat;
+ Options.FloatABIType = options.FloatABIType;
+ Options.NoZerosInBSS = options.NoZerosInBSS;
+ Options.GuaranteedTailCallOpt = options.GuaranteedTailCallOpt;
+ Options.DisableTailCalls = options.DisableTailCalls;
+ Options.StackAlignmentOverride = options.StackAlignmentOverride;
+ Options.TrapFuncName = options.TrapFuncName;
+ Options.PositionIndependentExecutable = options.PositionIndependentExecutable;
+ Options.EnableSegmentedStacks = options.EnableSegmentedStacks;
+ Options.UseInitArray = options.UseInitArray;
+}
+
void LTOCodeGenerator::setDebugInfo(lto_debug_model debug) {
switch (debug) {
case LTO_DEBUG_MODEL_NONE:
@@ -181,7 +191,11 @@ bool LTOCodeGenerator::writeMergedModules(const char *path,
return true;
}
-bool LTOCodeGenerator::compile_to_file(const char** name, std::string& errMsg) {
+bool LTOCodeGenerator::compile_to_file(const char** name,
+ bool disableOpt,
+ bool disableInline,
+ bool disableGVNLoadPRE,
+ std::string& errMsg) {
// make unique temp .o file to put generated object file
SmallString<128> Filename;
int FD;
@@ -194,7 +208,8 @@ bool LTOCodeGenerator::compile_to_file(const char** name, std::string& errMsg) {
// generate object file
tool_output_file objFile(Filename.c_str(), FD);
- bool genResult = generateObjectFile(objFile.os(), errMsg);
+ bool genResult = generateObjectFile(objFile.os(), disableOpt, disableInline,
+ disableGVNLoadPRE, errMsg);
objFile.os().close();
if (objFile.os().has_error()) {
objFile.os().clear_error();
@@ -213,9 +228,14 @@ bool LTOCodeGenerator::compile_to_file(const char** name, std::string& errMsg) {
return true;
}
-const void* LTOCodeGenerator::compile(size_t* length, std::string& errMsg) {
+const void* LTOCodeGenerator::compile(size_t* length,
+ bool disableOpt,
+ bool disableInline,
+ bool disableGVNLoadPRE,
+ std::string& errMsg) {
const char *name;
- if (!compile_to_file(&name, errMsg))
+ if (!compile_to_file(&name, disableOpt, disableInline, disableGVNLoadPRE,
+ errMsg))
return NULL;
// remove old buffer if compile() called twice
@@ -285,8 +305,7 @@ bool LTOCodeGenerator::determineTarget(std::string &errMsg) {
else if (Triple.getArch() == llvm::Triple::x86)
MCpu = "yonah";
}
- TargetOptions Options;
- LTOModule::getTargetOptions(Options);
+
TargetMach = march->createTargetMachine(TripleStr, MCpu, FeatureStr, Options,
RelocModel, CodeModel::Default,
CodeGenOpt::Aggressive);
@@ -382,6 +401,9 @@ void LTOCodeGenerator::applyScopeRestrictions() {
/// Optimize merged modules using various IPO passes
bool LTOCodeGenerator::generateObjectFile(raw_ostream &out,
+ bool DisableOpt,
+ bool DisableInline,
+ bool DisableGVNLoadPRE,
std::string &errMsg) {
if (!this->determineTarget(errMsg))
return false;
diff --git a/lib/LTO/LTOModule.cpp b/lib/LTO/LTOModule.cpp
index 1457f2f..fc8bf0c 100644
--- a/lib/LTO/LTOModule.cpp
+++ b/lib/LTO/LTOModule.cpp
@@ -40,108 +40,6 @@
#include "llvm/Target/TargetRegisterInfo.h"
using namespace llvm;
-static cl::opt<bool>
-EnableFPMAD("enable-fp-mad",
- cl::desc("Enable less precise MAD instructions to be generated"),
- cl::init(false));
-
-static cl::opt<bool>
-DisableFPElim("disable-fp-elim",
- cl::desc("Disable frame pointer elimination optimization"),
- cl::init(false));
-
-static cl::opt<bool>
-EnableUnsafeFPMath("enable-unsafe-fp-math",
- cl::desc("Enable optimizations that may decrease FP precision"),
- cl::init(false));
-
-static cl::opt<bool>
-EnableNoInfsFPMath("enable-no-infs-fp-math",
- cl::desc("Enable FP math optimizations that assume no +-Infs"),
- cl::init(false));
-
-static cl::opt<bool>
-EnableNoNaNsFPMath("enable-no-nans-fp-math",
- cl::desc("Enable FP math optimizations that assume no NaNs"),
- cl::init(false));
-
-static cl::opt<bool>
-EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math",
- cl::Hidden,
- cl::desc("Force codegen to assume rounding mode can change dynamically"),
- cl::init(false));
-
-static cl::opt<bool>
-GenerateSoftFloatCalls("soft-float",
- cl::desc("Generate software floating point library calls"),
- cl::init(false));
-
-static cl::opt<llvm::FloatABI::ABIType>
-FloatABIForCalls("float-abi",
- cl::desc("Choose float ABI type"),
- cl::init(FloatABI::Default),
- cl::values(
- clEnumValN(FloatABI::Default, "default",
- "Target default float ABI type"),
- clEnumValN(FloatABI::Soft, "soft",
- "Soft float ABI (implied by -soft-float)"),
- clEnumValN(FloatABI::Hard, "hard",
- "Hard float ABI (uses FP registers)"),
- clEnumValEnd));
-
-static cl::opt<llvm::FPOpFusion::FPOpFusionMode>
-FuseFPOps("fp-contract",
- cl::desc("Enable aggresive formation of fused FP ops"),
- cl::init(FPOpFusion::Standard),
- cl::values(
- clEnumValN(FPOpFusion::Fast, "fast",
- "Fuse FP ops whenever profitable"),
- clEnumValN(FPOpFusion::Standard, "on",
- "Only fuse 'blessed' FP ops."),
- clEnumValN(FPOpFusion::Strict, "off",
- "Only fuse FP ops when the result won't be effected."),
- clEnumValEnd));
-
-static cl::opt<bool>
-DontPlaceZerosInBSS("nozero-initialized-in-bss",
- cl::desc("Don't place zero-initialized symbols into bss section"),
- cl::init(false));
-
-static cl::opt<bool>
-EnableGuaranteedTailCallOpt("tailcallopt",
- cl::desc("Turn fastcc calls into tail calls by (potentially) changing ABI."),
- cl::init(false));
-
-static cl::opt<bool>
-DisableTailCalls("disable-tail-calls",
- cl::desc("Never emit tail calls"),
- cl::init(false));
-
-static cl::opt<unsigned>
-OverrideStackAlignment("stack-alignment",
- cl::desc("Override default stack alignment"),
- cl::init(0));
-
-static cl::opt<std::string>
-TrapFuncName("trap-func", cl::Hidden,
- cl::desc("Emit a call to trap function rather than a trap instruction"),
- cl::init(""));
-
-static cl::opt<bool>
-EnablePIE("enable-pie",
- cl::desc("Assume the creation of a position independent executable."),
- cl::init(false));
-
-static cl::opt<bool>
-SegmentedStacks("segmented-stacks",
- cl::desc("Use segmented stacks if possible."),
- cl::init(false));
-
-static cl::opt<bool>
-UseInitArray("use-init-array",
- cl::desc("Use .init_array instead of .ctors."),
- cl::init(false));
-
LTOModule::LTOModule(llvm::Module *m, llvm::TargetMachine *t)
: _module(m), _target(t),
_context(_target->getMCAsmInfo(), _target->getRegisterInfo(), NULL),
@@ -189,23 +87,26 @@ bool LTOModule::isTargetMatch(MemoryBuffer *buffer, const char *triplePrefix) {
/// makeLTOModule - Create an LTOModule. N.B. These methods take ownership of
/// the buffer.
-LTOModule *LTOModule::makeLTOModule(const char *path, std::string &errMsg) {
+LTOModule *LTOModule::makeLTOModule(const char *path, TargetOptions options,
+ std::string &errMsg) {
OwningPtr<MemoryBuffer> buffer;
if (error_code ec = MemoryBuffer::getFile(path, buffer)) {
errMsg = ec.message();
return NULL;
}
- return makeLTOModule(buffer.take(), errMsg);
+ return makeLTOModule(buffer.take(), options, errMsg);
}
LTOModule *LTOModule::makeLTOModule(int fd, const char *path,
- size_t size, std::string &errMsg) {
- return makeLTOModule(fd, path, size, 0, errMsg);
+ size_t size, TargetOptions options,
+ std::string &errMsg) {
+ return makeLTOModule(fd, path, size, 0, options, errMsg);
}
LTOModule *LTOModule::makeLTOModule(int fd, const char *path,
size_t map_size,
off_t offset,
+ TargetOptions options,
std::string &errMsg) {
OwningPtr<MemoryBuffer> buffer;
if (error_code ec =
@@ -213,40 +114,20 @@ LTOModule *LTOModule::makeLTOModule(int fd, const char *path,
errMsg = ec.message();
return NULL;
}
- return makeLTOModule(buffer.take(), errMsg);
+ return makeLTOModule(buffer.take(), options, errMsg);
}
LTOModule *LTOModule::makeLTOModule(const void *mem, size_t length,
+ TargetOptions options,
std::string &errMsg) {
OwningPtr<MemoryBuffer> buffer(makeBuffer(mem, length));
if (!buffer)
return NULL;
- return makeLTOModule(buffer.take(), errMsg);
-}
-
-void LTOModule::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 makeLTOModule(buffer.take(), options, errMsg);
}
LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer,
+ TargetOptions options,
std::string &errMsg) {
// parse bitcode buffer
OwningPtr<Module> m(getLazyBitcodeModule(buffer, getGlobalContext(),
@@ -278,10 +159,9 @@ LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer,
else if (Triple.getArch() == llvm::Triple::x86)
CPU = "yonah";
}
- TargetOptions Options;
- getTargetOptions(Options);
+
TargetMachine *target = march->createTargetMachine(TripleStr, CPU, FeatureStr,
- Options);
+ options);
LTOModule *Ret = new LTOModule(m.take(), target);
if (Ret->parseSymbols(errMsg)) {
delete Ret;