summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Roeder <tmroeder@google.com>2014-04-25 21:46:51 +0000
committerTom Roeder <tmroeder@google.com>2014-04-25 21:46:51 +0000
commit817f5e2fa137b15b536c952bcc1e75b1dd34b4b1 (patch)
treef514566a78e689fcc0c138b83fde6342a4c26c9a
parentc744a371534456c1bb6557f053705f066ac33b62 (diff)
downloadllvm-817f5e2fa137b15b536c952bcc1e75b1dd34b4b1.tar.gz
llvm-817f5e2fa137b15b536c952bcc1e75b1dd34b4b1.tar.bz2
llvm-817f5e2fa137b15b536c952bcc1e75b1dd34b4b1.tar.xz
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207279 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm-c/lto.h10
-rw-r--r--include/llvm/LTO/LTOCodeGenerator.h2
-rw-r--r--lib/LTO/LTOCodeGenerator.cpp5
-rw-r--r--test/LTO/attrs.ll15
-rw-r--r--tools/llvm-lto/llvm-lto.cpp10
-rw-r--r--tools/lto/lto.cpp22
6 files changed, 61 insertions, 3 deletions
diff --git a/include/llvm-c/lto.h b/include/llvm-c/lto.h
index 808de03318..9c2061acd6 100644
--- a/include/llvm-c/lto.h
+++ b/include/llvm-c/lto.h
@@ -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 cg, lto_codegen_model);
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
diff --git a/include/llvm/LTO/LTOCodeGenerator.h b/include/llvm/LTO/LTOCodeGenerator.h
index 543399157b..7e297c35c9 100644
--- a/include/llvm/LTO/LTOCodeGenerator.h
+++ b/include/llvm/LTO/LTOCodeGenerator.h
@@ -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;
diff --git a/lib/LTO/LTOCodeGenerator.cpp b/lib/LTO/LTOCodeGenerator.cpp
index da74c57c58..105fb6900d 100644
--- a/lib/LTO/LTOCodeGenerator.cpp
+++ b/lib/LTO/LTOCodeGenerator.cpp
@@ -301,8 +301,9 @@ bool LTOCodeGenerator::determineTarget(std::string &errMsg) {
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.
diff --git a/test/LTO/attrs.ll b/test/LTO/attrs.ll
new file mode 100644
index 0000000000..d1967470cd
--- /dev/null
+++ b/test/LTO/attrs.ll
@@ -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
diff --git a/tools/llvm-lto/llvm-lto.cpp b/tools/llvm-lto/llvm-lto.cpp
index 1a92bf4f0e..678e4db08f 100644
--- a/tools/llvm-lto/llvm-lto.cpp
+++ b/tools/llvm-lto/llvm-lto.cpp
@@ -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;
diff --git a/tools/lto/lto.cpp b/tools/lto/lto.cpp
index cc8318a8ba..06b1b05e7e 100644
--- a/tools/lto/lto.cpp
+++ b/tools/lto/lto.cpp
@@ -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 cg, const char *cpu) {
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_symbol(lto_code_gen_t cg,
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(lto_code_gen_t cg, const char *path) {
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_gen_t cg, size_t *length) {
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,