#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"
#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;
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:
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;
// 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();
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
if (TargetMach != NULL)
return true;
- // if options were requested, set them
- if (!CodegenOptions.empty())
- cl::ParseCommandLineOptions(CodegenOptions.size(),
- const_cast<char **>(&CodegenOptions[0]));
-
std::string TripleStr = Linker.getModule()->getTargetTriple();
if (TripleStr.empty())
TripleStr = sys::getDefaultTargetTriple();
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);
void LTOCodeGenerator::
applyRestriction(GlobalValue &GV,
std::vector<const char*> &MustPreserveList,
+ std::vector<const char*> &DSOList,
SmallPtrSet<GlobalValue*, 8> &AsmUsed,
Mangler &Mangler) {
SmallString<64> Buffer;
return;
if (MustPreserveSymbols.count(Buffer))
MustPreserveList.push_back(GV.getName().data());
+ if (DSOSymbols.count(Buffer))
+ DSOList.push_back(GV.getName().data());
if (AsmUndefinedRefs.count(Buffer))
AsmUsed.insert(&GV);
}
NULL);
Mangler Mangler(MContext, TargetMach);
std::vector<const char*> MustPreserveList;
+ std::vector<const char*> DSOList;
SmallPtrSet<GlobalValue*, 8> AsmUsed;
for (Module::iterator f = mergedModule->begin(),
e = mergedModule->end(); f != e; ++f)
- applyRestriction(*f, MustPreserveList, AsmUsed, Mangler);
+ applyRestriction(*f, MustPreserveList, DSOList, AsmUsed, Mangler);
for (Module::global_iterator v = mergedModule->global_begin(),
e = mergedModule->global_end(); v != e; ++v)
- applyRestriction(*v, MustPreserveList, AsmUsed, Mangler);
+ applyRestriction(*v, MustPreserveList, DSOList, AsmUsed, Mangler);
for (Module::alias_iterator a = mergedModule->alias_begin(),
e = mergedModule->alias_end(); a != e; ++a)
- applyRestriction(*a, MustPreserveList, AsmUsed, Mangler);
+ applyRestriction(*a, MustPreserveList, DSOList, AsmUsed, Mangler);
GlobalVariable *LLVMCompilerUsed =
mergedModule->getGlobalVariable("llvm.compiler.used");
LLVMCompilerUsed->setSection("llvm.metadata");
}
- passes.add(createInternalizePass(MustPreserveList));
+ passes.add(createInternalizePass(MustPreserveList, DSOList));
// apply scope restrictions
passes.run(*mergedModule);
/// 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;
CodegenOptions.push_back(strdup(o.first.str().c_str()));
}
}
+
+void LTOCodeGenerator::parseCodeGenDebugOptions() {
+ // if options were requested, set them
+ if (!CodegenOptions.empty())
+ cl::ParseCommandLineOptions(CodegenOptions.size(),
+ const_cast<char **>(&CodegenOptions[0]));
+}