[llvm] r207279 - Add an -mattr option to the gold plugin to support subtarget features in LTO

Tom Roeder tmroeder at google.com
Fri Apr 25 14:46:51 PDT 2014


Author: tmroeder
Date: Fri Apr 25 16:46:51 2014
New Revision: 207279

URL: http://llvm.org/viewvc/llvm-project?rev=207279&view=rev
Log:
Add an -mattr option to the gold plugin to support subtarget features in LTO

This adds support for an -mattr option to the gold plugin and to llvm-lto. This
allows the caller to specify details of the subtarget architecture, like +aes,
or +ssse3 on x86.  Note that this requires a change to the include/llvm-c/lto.h
interface: it adds a function lto_codegen_set_attr and it increments the
version of the interface.


Added:
    llvm/trunk/test/LTO/attrs.ll
Modified:
    llvm/trunk/include/llvm-c/lto.h
    llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h
    llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
    llvm/trunk/tools/llvm-lto/llvm-lto.cpp
    llvm/trunk/tools/lto/lto.cpp

Modified: llvm/trunk/include/llvm-c/lto.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/lto.h?rev=207279&r1=207278&r2=207279&view=diff
==============================================================================
--- llvm/trunk/include/llvm-c/lto.h (original)
+++ llvm/trunk/include/llvm-c/lto.h Fri Apr 25 16:46:51 2014
@@ -40,7 +40,7 @@ typedef bool lto_bool_t;
  * @{
  */
 
-#define LTO_API_VERSION 10
+#define LTO_API_VERSION 11
 
 /**
  * \since prior to LTO_API_VERSION=3
@@ -375,6 +375,14 @@ lto_codegen_set_pic_model(lto_code_gen_t
 extern void
 lto_codegen_set_cpu(lto_code_gen_t cg, const char *cpu);
 
+/**
+ * Sets attributes for the cpu to generate code for.
+ *
+ * \since LTO_API_VERSION=11
+ */
+extern void
+lto_codegen_set_attr(lto_code_gen_t cg, const char *attr);
+
 
 /**
  * Sets the location of the assembler tool to run. If not set, libLTO

Modified: llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h?rev=207279&r1=207278&r2=207279&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h (original)
+++ llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h Fri Apr 25 16:46:51 2014
@@ -73,6 +73,7 @@ struct LTOCodeGenerator {
   void setCodePICModel(lto_codegen_model);
 
   void setCpu(const char *mCpu) { MCpu = mCpu; }
+  void setAttr(const char *mAttr) { MAttr = mAttr; }
 
   void addMustPreserveSymbol(const char *sym) { MustPreserveSymbols[sym] = 1; }
 
@@ -150,6 +151,7 @@ private:
   llvm::MemoryBuffer *NativeObjectFile;
   std::vector<char *> CodegenOptions;
   std::string MCpu;
+  std::string MAttr;
   std::string NativeObjectPath;
   llvm::TargetOptions Options;
   lto_diagnostic_handler_t DiagHandler;

Modified: llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOCodeGenerator.cpp?rev=207279&r1=207278&r2=207279&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOCodeGenerator.cpp (original)
+++ llvm/trunk/lib/LTO/LTOCodeGenerator.cpp Fri Apr 25 16:46:51 2014
@@ -301,8 +301,9 @@ bool LTOCodeGenerator::determineTarget(s
     break;
   }
 
-  // construct LTOModule, hand over ownership of module and target
-  SubtargetFeatures Features;
+  // Construct LTOModule, hand over ownership of module and target. Use MAttr as
+  // the default set of features.
+  SubtargetFeatures Features(MAttr);
   Features.getDefaultSubtargetFeatures(Triple);
   std::string FeatureStr = Features.getString();
   // Set a default CPU for Darwin triples.

Added: llvm/trunk/test/LTO/attrs.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LTO/attrs.ll?rev=207279&view=auto
==============================================================================
--- llvm/trunk/test/LTO/attrs.ll (added)
+++ llvm/trunk/test/LTO/attrs.ll Fri Apr 25 16:46:51 2014
@@ -0,0 +1,15 @@
+; RUN: llvm-as < %s >%t1
+; RUN: llvm-lto -exported-symbol=test_x86_aesni_aeskeygenassist -mattr=+aes -o %t2 %t1
+; RUN: llvm-objdump -d %t2 | FileCheck -check-prefix=WITH_AES %s
+; RUN: not llvm-lto -exported-symbol=test_x86_aesni_aeskeygenassist -mattr=-aes -o %t3 %t1 2>&1 | FileCheck -check-prefix=WITHOUT_AES %s
+
+target triple = "x86_64-unknown-linux-gnu"
+declare <2 x i64> @llvm.x86.aesni.aeskeygenassist(<2 x i64>, i8)
+define <2 x i64> @test_x86_aesni_aeskeygenassist(<2 x i64> %a0) {
+  ; WITH_AES: test_x86_aesni_aeskeygenassist
+  ; WITH_AES: aeskeygenassist
+  %res = call <2 x i64> @llvm.x86.aesni.aeskeygenassist(<2 x i64> %a0, i8 7)
+  ret <2 x i64> %res
+}
+
+; WITHOUT_AES: LLVM ERROR: Cannot select: intrinsic %llvm.x86.aesni.aeskeygenassist

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=207279&r1=207278&r2=207279&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-lto/llvm-lto.cpp (original)
+++ llvm/trunk/tools/llvm-lto/llvm-lto.cpp Fri Apr 25 16:46:51 2014
@@ -143,6 +143,16 @@ int main(int argc, char **argv) {
   for (unsigned i = 0; i < KeptDSOSyms.size(); ++i)
     CodeGen.addMustPreserveSymbol(KeptDSOSyms[i].c_str());
 
+  std::string attrs;
+  for (unsigned i = 0; i < MAttrs.size(); ++i) {
+    if (i > 0)
+      attrs.append(",");
+    attrs.append(MAttrs[i]);
+  }
+
+  if (!attrs.empty())
+    CodeGen.setAttr(attrs.c_str());
+
   if (!OutputFilename.empty()) {
     size_t len = 0;
     std::string ErrorInfo;

Modified: llvm/trunk/tools/lto/lto.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/lto.cpp?rev=207279&r1=207278&r2=207279&view=diff
==============================================================================
--- llvm/trunk/tools/lto/lto.cpp (original)
+++ llvm/trunk/tools/lto/lto.cpp Fri Apr 25 16:46:51 2014
@@ -56,6 +56,20 @@ static void lto_initialize() {
   }
 }
 
+// Convert the subtarget features into a string to pass to LTOCodeGenerator.
+static void lto_add_attrs(lto_code_gen_t cg) {
+  if (MAttrs.size()) {
+    std::string attrs;
+    for (unsigned i = 0; i < MAttrs.size(); ++i) {
+      if (i > 0)
+        attrs.append(",");
+      attrs.append(MAttrs[i]);
+    }
+
+    cg->setAttr(attrs.c_str());
+  }
+}
+
 /// lto_get_version - Returns a printable string.
 extern const char* lto_get_version() {
   return LTOCodeGenerator::getVersionString();
@@ -252,6 +266,11 @@ void lto_codegen_set_cpu(lto_code_gen_t
   return cg->setCpu(cpu);
 }
 
+/// lto_codegen_set_attr - Sets the attr to generate code for.
+void lto_codegen_set_attr(lto_code_gen_t cg, const char *attr) {
+  return cg->setAttr(attr);
+}
+
 /// lto_codegen_set_assembler_path - Sets the path to the assembler tool.
 void lto_codegen_set_assembler_path(lto_code_gen_t cg, const char *path) {
   // In here only for backwards compatibility. We use MC now.
@@ -278,6 +297,7 @@ void lto_codegen_add_must_preserve_symbo
 bool lto_codegen_write_merged_modules(lto_code_gen_t cg, const char *path) {
   if (!parsedOptions) {
     cg->parseCodeGenDebugOptions();
+    lto_add_attrs(cg);
     parsedOptions = true;
   }
   return !cg->writeMergedModules(path, sLastErrorString);
@@ -292,6 +312,7 @@ bool lto_codegen_write_merged_modules(lt
 const void *lto_codegen_compile(lto_code_gen_t cg, size_t *length) {
   if (!parsedOptions) {
     cg->parseCodeGenDebugOptions();
+    lto_add_attrs(cg);
     parsedOptions = true;
   }
   return cg->compile(length, DisableOpt, DisableInline, DisableGVNLoadPRE,
@@ -304,6 +325,7 @@ const void *lto_codegen_compile(lto_code
 bool lto_codegen_compile_to_file(lto_code_gen_t cg, const char **name) {
   if (!parsedOptions) {
     cg->parseCodeGenDebugOptions();
+    lto_add_attrs(cg);
     parsedOptions = true;
   }
   return !cg->compile_to_file(name, DisableOpt, DisableInline, DisableGVNLoadPRE,





More information about the llvm-commits mailing list