[llvm] r191680 - Move command line options to the users of libLTO. Fixes --enable-shared build.

Rafael Espindola rafael.espindola at gmail.com
Mon Sep 30 09:39:19 PDT 2013


Author: rafael
Date: Mon Sep 30 11:39:19 2013
New Revision: 191680

URL: http://llvm.org/viewvc/llvm-project?rev=191680&view=rev
Log:
Move command line options to the users of libLTO. Fixes --enable-shared build.

Patch by Richard Sandiford.

Modified:
    llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h
    llvm/trunk/include/llvm/LTO/LTOModule.h
    llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
    llvm/trunk/lib/LTO/LTOModule.cpp
    llvm/trunk/tools/llvm-lto/llvm-lto.cpp
    llvm/trunk/tools/lto/lto.cpp

Modified: llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h?rev=191680&r1=191679&r2=191680&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h (original)
+++ llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h Mon Sep 30 11:39:19 2013
@@ -39,6 +39,7 @@
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/Linker.h"
+#include "llvm/Target/TargetOptions.h"
 #include <string>
 #include <vector>
 
@@ -64,6 +65,7 @@ struct LTOCodeGenerator {
   // Merge given module, return true on success.
   bool addModule(struct LTOModule*, std::string &errMsg);
 
+  void setTargetOptions(llvm::TargetOptions options);
   void setDebugInfo(lto_debug_model);
   void setCodePICModel(lto_codegen_model);
 
@@ -90,7 +92,11 @@ struct LTOCodeGenerator {
   //  Do not try to remove the object file in LTOCodeGenerator's destructor
   //  as we don't who (LTOCodeGenerator or the obj file) will last longer.
   // 
-  bool compile_to_file(const char **name, std::string &errMsg);
+  bool compile_to_file(const char **name,
+                       bool disableOpt,
+                       bool disableInline,
+                       bool disableGVNLoadPRE,
+                       std::string &errMsg);
 
   // As with compile_to_file(), this function compiles the merged module into
   // single object file. Instead of returning the object-file-path to the caller
@@ -98,12 +104,20 @@ struct LTOCodeGenerator {
   // caller. This function should delete intermediate object file once its content
   // is brought to memory. Return NULL if the compilation was not successful. 
   //
-  const void *compile(size_t *length, std::string &errMsg);
+  const void *compile(size_t *length,
+                      bool disableOpt,
+                      bool disableInline,
+                      bool disableGVNLoadPRE,
+                      std::string &errMsg);
 
 private:
   void initializeLTOPasses();
 
-  bool generateObjectFile(llvm::raw_ostream &out, std::string &errMsg);
+  bool generateObjectFile(llvm::raw_ostream &out,
+                          bool disableOpt,
+                          bool disableInline,
+                          bool disableGVNLoadPRE,
+                          std::string &errMsg);
   void applyScopeRestrictions();
   void applyRestriction(llvm::GlobalValue &GV,
                         std::vector<const char*> &MustPreserveList,
@@ -125,6 +139,7 @@ private:
   std::vector<char *> CodegenOptions;
   std::string MCpu;
   std::string NativeObjectPath;
+  llvm::TargetOptions Options;
 };
 
 #endif // LTO_CODE_GENERATOR_H

Modified: llvm/trunk/include/llvm/LTO/LTOModule.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LTO/LTOModule.h?rev=191680&r1=191679&r2=191680&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LTO/LTOModule.h (original)
+++ llvm/trunk/include/llvm/LTO/LTOModule.h Mon Sep 30 11:39:19 2013
@@ -84,14 +84,17 @@ public:
   /// InitializeAllAsmPrinters();
   /// InitializeAllAsmParsers();
   static LTOModule *makeLTOModule(const char* path,
+                                  llvm::TargetOptions options,
                                   std::string &errMsg);
   static LTOModule *makeLTOModule(int fd, const char *path,
-                                  size_t size, std::string &errMsg);
+                                  size_t size, llvm::TargetOptions options,
+                                  std::string &errMsg);
   static LTOModule *makeLTOModule(int fd, const char *path,
                                   size_t map_size,
-                                  off_t offset,
+                                  off_t offset, llvm::TargetOptions options,
                                   std::string& errMsg);
   static LTOModule *makeLTOModule(const void *mem, size_t length,
+                                  llvm::TargetOptions options,
                                   std::string &errMsg);
 
   /// getTargetTriple - Return the Module's target triple.
@@ -132,10 +135,6 @@ public:
     return _asm_undefines;
   }
 
-  /// getTargetOptions - Fill the TargetOptions object with the options
-  /// specified on the command line.
-  static void getTargetOptions(llvm::TargetOptions &Options);
-
 private:
   /// parseSymbols - Parse the symbols from the module and model-level ASM and
   /// add them to either the defined or undefined lists.
@@ -187,6 +186,7 @@ private:
   /// makeLTOModule - Create an LTOModule (private version). N.B. This
   /// method takes ownership of the buffer.
   static LTOModule *makeLTOModule(llvm::MemoryBuffer *buffer,
+                                  llvm::TargetOptions options,
                                   std::string &errMsg);
 
   /// makeBuffer - Create a MemoryBuffer from a memory range.

Modified: llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOCodeGenerator.cpp?rev=191680&r1=191679&r2=191680&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOCodeGenerator.cpp (original)
+++ llvm/trunk/lib/LTO/LTOCodeGenerator.cpp Mon Sep 30 11:39:19 2013
@@ -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(LTOModu
   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::writeMergedModule
   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(c
   // 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(c
   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(s
     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::applyScopeRestric
 
 /// 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;

Modified: llvm/trunk/lib/LTO/LTOModule.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOModule.cpp?rev=191680&r1=191679&r2=191680&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOModule.cpp (original)
+++ llvm/trunk/lib/LTO/LTOModule.cpp Mon Sep 30 11:39:19 2013
@@ -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(MemoryBuff
 
 /// 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
     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(Memo
     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;

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=191680&r1=191679&r2=191680&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-lto/llvm-lto.cpp (original)
+++ llvm/trunk/tools/llvm-lto/llvm-lto.cpp Mon Sep 30 11:39:19 2013
@@ -12,6 +12,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/CodeGen/CommandFlags.h"
 #include "llvm/LTO/LTOCodeGenerator.h"
 #include "llvm/LTO/LTOModule.h"
 #include "llvm/Support/CommandLine.h"
@@ -23,13 +24,26 @@
 
 using namespace llvm;
 
-static cl::list<std::string> InputFilenames(cl::Positional, cl::OneOrMore,
-                                            cl::desc("<input bitcode files>"));
-
-static cl::opt<std::string> OutputFilename("o",
-                                           cl::desc("Override output filename"),
-                                           cl::init(""),
-                                           cl::value_desc("filename"));
+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"));
+
+static cl::list<std::string>
+InputFilenames(cl::Positional, cl::OneOrMore,
+  cl::desc("<input bitcode files>"));
+
+static cl::opt<std::string>
+OutputFilename("o", cl::init(""),
+  cl::desc("Override output filename"),
+  cl::value_desc("filename"));
 
 int main(int argc, char **argv) {
   // Print a stack trace if we signal out.
@@ -45,6 +59,28 @@ int main(int argc, char **argv) {
   InitializeAllAsmPrinters();
   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;
+
   unsigned BaseArg = 0;
   std::string ErrorMessage;
 
@@ -52,11 +88,12 @@ int main(int argc, char **argv) {
 
   CodeGen.setCodePICModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC);
   CodeGen.setDebugInfo(LTO_DEBUG_MODEL_DWARF);
+  CodeGen.setTargetOptions(Options);
 
   for (unsigned i = BaseArg; i < InputFilenames.size(); ++i) {
     std::string error;
     OwningPtr<LTOModule> Module(LTOModule::makeLTOModule(InputFilenames[i].c_str(),
-                                                         error));
+                                                         Options, error));
     if (!error.empty()) {
       errs() << argv[0] << ": error loading file '" << InputFilenames[i]
              << "': " << error << "\n";
@@ -74,7 +111,8 @@ int main(int argc, char **argv) {
   if (!OutputFilename.empty()) {
     size_t len = 0;
     std::string ErrorInfo;
-    const void *Code = CodeGen.compile(&len, ErrorInfo);
+    const void *Code = CodeGen.compile(&len, DisableOpt, DisableInline,
+                                       DisableGVNLoadPRE, ErrorInfo);
     if (Code == NULL) {
       errs() << argv[0]
              << ": error compiling the code: " << ErrorInfo << "\n";
@@ -92,7 +130,8 @@ int main(int argc, char **argv) {
   } else {
     std::string ErrorInfo;
     const char *OutputName = NULL;
-    if (!CodeGen.compile_to_file(&OutputName, ErrorInfo)) {
+    if (!CodeGen.compile_to_file(&OutputName, DisableOpt, DisableInline,
+                                 DisableGVNLoadPRE, ErrorInfo)) {
       errs() << argv[0]
              << ": error compiling the code: " << ErrorInfo
              << "\n";

Modified: llvm/trunk/tools/lto/lto.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/lto.cpp?rev=191680&r1=191679&r2=191680&view=diff
==============================================================================
--- llvm/trunk/tools/lto/lto.cpp (original)
+++ llvm/trunk/tools/lto/lto.cpp Mon Sep 30 11:39:19 2013
@@ -13,11 +13,24 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm-c/lto.h"
+#include "llvm/CodeGen/CommandFlags.h"
 #include "llvm/LTO/LTOCodeGenerator.h"
 #include "llvm/LTO/LTOModule.h"
 #include "llvm-c/Core.h"
 #include "llvm-c/Target.h"
 
+// extra command-line flags needed for LTOCodeGenerator
+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"));
 
 // Holds most recent error string.
 // *** Not thread safe ***
@@ -40,6 +53,28 @@ 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();
@@ -82,14 +117,18 @@ 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();
-  return LTOModule::makeLTOModule(path, sLastErrorString);
+  llvm::TargetOptions Options;
+  lto_set_target_options(Options);
+  return LTOModule::makeLTOModule(path, Options, sLastErrorString);
 }
 
 /// lto_module_create_from_fd - Loads an object file from disk. Returns NULL on
 /// 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();
-  return LTOModule::makeLTOModule(fd, path, size, sLastErrorString);
+  llvm::TargetOptions Options;
+  lto_set_target_options(Options);
+  return LTOModule::makeLTOModule(fd, path, size, Options, sLastErrorString);
 }
 
 /// lto_module_create_from_fd_at_offset - Loads an object file from disk.
@@ -99,14 +138,19 @@ lto_module_t lto_module_create_from_fd_a
                                                  size_t map_size,
                                                  off_t offset) {
   lto_initialize();
-  return LTOModule::makeLTOModule(fd, path, map_size, offset, sLastErrorString);
+  llvm::TargetOptions Options;
+  lto_set_target_options(Options);
+  return LTOModule::makeLTOModule(fd, path, map_size, offset, Options,
+                                  sLastErrorString);
 }
 
 /// lto_module_create_from_memory - Loads an object file from memory. Returns
 /// 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();
-  return LTOModule::makeLTOModule(mem, length, sLastErrorString);
+  llvm::TargetOptions Options;
+  lto_set_target_options(Options);
+  return LTOModule::makeLTOModule(mem, length, Options, sLastErrorString);
 }
 
 /// lto_module_dispose - Frees all memory for a module. Upon return the
@@ -150,7 +194,14 @@ lto_symbol_attributes lto_module_get_sym
 /// is an error.
 lto_code_gen_t lto_codegen_create(void) {
   lto_initialize();
-  return new LTOCodeGenerator();
+
+  TargetOptions Options;
+  lto_set_target_options(Options);
+
+  LTOCodeGenerator *CodeGen = new LTOCodeGenerator();
+  if (CodeGen)
+    CodeGen->setTargetOptions(Options);
+  return CodeGen;
 }
 
 /// lto_codegen_dispose - Frees all memory for a code generator. Upon return the
@@ -220,14 +271,16 @@ bool lto_codegen_write_merged_modules(lt
 /// lto_codegen_compile() is called again. On failure, returns NULL (check
 /// lto_get_error_message() for details).
 const void *lto_codegen_compile(lto_code_gen_t cg, size_t *length) {
-  return cg->compile(length, sLastErrorString);
+  return cg->compile(length, DisableOpt, DisableInline, DisableGVNLoadPRE,
+                     sLastErrorString);
 }
 
 /// lto_codegen_compile_to_file - Generates code for all added modules into one
 /// native object file. The name of the file is written to name. Returns true on
 /// error.
 bool lto_codegen_compile_to_file(lto_code_gen_t cg, const char **name) {
-  return !cg->compile_to_file(name, sLastErrorString);
+  return !cg->compile_to_file(name, DisableOpt, DisableInline, DisableGVNLoadPRE,
+                              sLastErrorString);
 }
 
 /// lto_codegen_debug_options - Used to pass extra options to the code





More information about the llvm-commits mailing list