From 817f5e2fa137b15b536c952bcc1e75b1dd34b4b1 Mon Sep 17 00:00:00 2001 From: Tom Roeder Date: Fri, 25 Apr 2014 21:46:51 +0000 Subject: 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 --- tools/lto/lto.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tools/lto') 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, -- cgit v1.2.3