Make it possible to set the cpu used for codegen.
authorRafael Espindola <rafael.espindola@gmail.com>
Wed, 11 Aug 2010 00:15:13 +0000 (00:15 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Wed, 11 Aug 2010 00:15:13 +0000 (00:15 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@110759 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm-c/lto.h
tools/gold/gold-plugin.cpp
tools/lto/LTOCodeGenerator.cpp
tools/lto/LTOCodeGenerator.h
tools/lto/lto.cpp

index 34231a22a5799eb00e35453a8ba5983f46b90d1c..67b27a8e66522f0de0b90df143482fc442d87c65 100644 (file)
@@ -205,6 +205,13 @@ extern bool
 lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model);
 
 
+/**
+ * Sets the cpu to generate code for.
+ */
+extern void
+lto_codegen_set_cpu(lto_code_gen_t cg, const char *cpu);
+
+
 /**
  * Sets the location of the "gcc" to run. If not set, libLTO will search for
  * "gcc" on the path.
index d649ccb0485e3a3f0a2e53d7528ec26bac5a6eb4..db0db3b5b2ec1bc81d4227945f72ccd3a421edb4 100644 (file)
@@ -70,6 +70,7 @@ namespace options {
   static std::vector<std::string> pass_through;
   static std::string extra_library_path;
   static std::string triple;
+  static std::string mcpu;
   // Additional options to pass into the code generator.
   // Note: This array will contain all plugin options which are not claimed
   // as plugin exclusive to pass to the code generator.
@@ -85,6 +86,8 @@ namespace options {
 
     if (opt == "generate-api-file") {
       generate_api_file = true;
+    } else if (opt.startswith("mcpu=")) {
+      mcpu = opt.substr(strlen("mcpu="));
     } else if (opt.startswith("as=")) {
       if (!as_path.empty()) {
         (*message)(LDPL_WARNING, "Path to as specified twice. "
@@ -413,6 +416,9 @@ static ld_plugin_status all_symbols_read_hook(void) {
     }
     lto_codegen_set_assembler_args(cg, &as_args_p[0], as_args_p.size());
   }
+  if (!options::mcpu.empty())
+    lto_codegen_set_cpu(cg, options::mcpu.c_str());
+
   // Pass through extra options to the code generator.
   if (!options::extra.empty()) {
     for (std::vector<std::string>::iterator it = options::extra.begin();
index 7850b5d6d27ef6b1e9ca93d097ebc961fccfea36..b69bcc35a71b1948637f6d75895ead196f2891e5 100644 (file)
@@ -119,6 +119,11 @@ bool LTOCodeGenerator::setCodePICModel(lto_codegen_model model,
     return true;
 }
 
+void LTOCodeGenerator::setCpu(const char* mCpu)
+{
+  _mCpu = mCpu;
+}
+
 void LTOCodeGenerator::setAssemblerPath(const char* path)
 {
     if ( _assemblerPath )
@@ -314,7 +319,7 @@ bool LTOCodeGenerator::determineTarget(std::string& errMsg)
 
         // construct LTModule, hand over ownership of module and target
         SubtargetFeatures Features;
-        Features.getDefaultSubtargetFeatures("" /* cpu */, llvm::Triple(Triple));
+        Features.getDefaultSubtargetFeatures(_mCpu, llvm::Triple(Triple));
         std::string FeatureStr = Features.getString();
         _target = march->createTargetMachine(Triple, FeatureStr);
     }
index 9086befc26ddee34a2e26fdbae2ead06a7eda41b..71593a5039bba3643d4d3b5ea8033f886b226b41 100644 (file)
@@ -36,6 +36,7 @@ struct LTOCodeGenerator {
     bool                addModule(struct LTOModule*, std::string& errMsg);
     bool                setDebugInfo(lto_debug_model, std::string& errMsg);
     bool                setCodePICModel(lto_codegen_model, std::string& errMsg);
+    void                setCpu(const char *cpu);
     void                setAssemblerPath(const char* path);
     void                setAssemblerArgs(const char** args, int nargs);
     void                addMustPreserveSymbol(const char* sym);
@@ -63,6 +64,7 @@ private:
     llvm::MemoryBuffer*         _nativeObjectFile;
     std::vector<const char*>    _codegenOptions;
     llvm::sys::Path*            _assemblerPath;
+    std::string                 _mCpu;
     std::vector<std::string>    _assemblerArgs;
 };
 
index 703447b499febbfb8c733ef947dc8c24f545694c..a7ce2a07bbf14d3e3178e9f92b07ac439cb6d5af 100644 (file)
@@ -210,6 +210,14 @@ bool lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model model)
   return cg->setCodePICModel(model, sLastErrorString);
 }
 
+//
+// sets the cpu to generate code for
+//
+void lto_codegen_set_cpu(lto_code_gen_t cg, const char* cpu)
+{
+  return cg->setCpu(cpu);
+}
+
 //
 // sets the path to the assembler tool
 //