[llvm] r245781 - LTO: Maintain target triple, FeatureStr and CGOptLevel in the module or LTOCodeGenerator.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 21 19:25:53 PDT 2015


Author: pcc
Date: Fri Aug 21 21:25:53 2015
New Revision: 245781

URL: http://llvm.org/viewvc/llvm-project?rev=245781&view=rev
Log:
LTO: Maintain target triple, FeatureStr and CGOptLevel in the module or LTOCodeGenerator.

This makes it easier to create new TargetMachines on demand.

Modified:
    llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h
    llvm/trunk/lib/LTO/LTOCodeGenerator.cpp

Modified: llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h?rev=245781&r1=245780&r2=245781&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h (original)
+++ llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h Fri Aug 21 21:25:53 2015
@@ -77,7 +77,7 @@ struct LTOCodeGenerator {
 
   void setCpu(const char *mCpu) { MCpu = mCpu; }
   void setAttr(const char *mAttr) { MAttr = mAttr; }
-  void setOptLevel(unsigned optLevel) { OptLevel = optLevel; }
+  void setOptLevel(unsigned optLevel);
 
   void setShouldInternalize(bool Value) { ShouldInternalize = Value; }
   void setShouldEmbedUselists(bool Value) { ShouldEmbedUselists = Value; }
@@ -166,10 +166,12 @@ private:
   StringSet MustPreserveSymbols;
   StringSet AsmUndefinedRefs;
   std::vector<std::string> CodegenOptions;
+  std::string FeatureStr;
   std::string MCpu;
   std::string MAttr;
   std::string NativeObjectPath;
   TargetOptions Options;
+  CodeGenOpt::Level CGOptLevel = CodeGenOpt::Default;
   unsigned OptLevel = 2;
   lto_diagnostic_handler_t DiagHandler = nullptr;
   void *DiagContext = nullptr;

Modified: llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOCodeGenerator.cpp?rev=245781&r1=245780&r2=245781&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOCodeGenerator.cpp (original)
+++ llvm/trunk/lib/LTO/LTOCodeGenerator.cpp Fri Aug 21 21:25:53 2015
@@ -164,6 +164,24 @@ void LTOCodeGenerator::setDebugInfo(lto_
   llvm_unreachable("Unknown debug format!");
 }
 
+void LTOCodeGenerator::setOptLevel(unsigned level) {
+  OptLevel = level;
+  switch (OptLevel) {
+  case 0:
+    CGOptLevel = CodeGenOpt::None;
+    break;
+  case 1:
+    CGOptLevel = CodeGenOpt::Less;
+    break;
+  case 2:
+    CGOptLevel = CodeGenOpt::Default;
+    break;
+  case 3:
+    CGOptLevel = CodeGenOpt::Aggressive;
+    break;
+  }
+}
+
 bool LTOCodeGenerator::writeMergedModules(const char *path,
                                           std::string &errMsg) {
   if (!determineTarget(errMsg))
@@ -279,8 +297,10 @@ bool LTOCodeGenerator::determineTarget(s
     return true;
 
   std::string TripleStr = IRLinker.getModule()->getTargetTriple();
-  if (TripleStr.empty())
+  if (TripleStr.empty()) {
     TripleStr = sys::getDefaultTargetTriple();
+    IRLinker.getModule()->setTargetTriple(TripleStr);
+  }
   llvm::Triple Triple(TripleStr);
 
   // create target machine from info for merged modules
@@ -292,7 +312,7 @@ bool LTOCodeGenerator::determineTarget(s
   // the default set of features.
   SubtargetFeatures Features(MAttr);
   Features.getDefaultSubtargetFeatures(Triple);
-  std::string FeatureStr = Features.getString();
+  FeatureStr = Features.getString();
   // Set a default CPU for Darwin triples.
   if (MCpu.empty() && Triple.isOSDarwin()) {
     if (Triple.getArch() == llvm::Triple::x86_64)
@@ -303,22 +323,6 @@ bool LTOCodeGenerator::determineTarget(s
       MCpu = "cyclone";
   }
 
-  CodeGenOpt::Level CGOptLevel;
-  switch (OptLevel) {
-  case 0:
-    CGOptLevel = CodeGenOpt::None;
-    break;
-  case 1:
-    CGOptLevel = CodeGenOpt::Less;
-    break;
-  case 2:
-    CGOptLevel = CodeGenOpt::Default;
-    break;
-  case 3:
-    CGOptLevel = CodeGenOpt::Aggressive;
-    break;
-  }
-
   TargetMach.reset(march->createTargetMachine(TripleStr, MCpu, FeatureStr,
                                               Options, RelocModel,
                                               CodeModel::Default, CGOptLevel));




More information about the llvm-commits mailing list