llvm.org GIT mirror llvm / 817f5e2
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 Tom Roeder 5 years ago
6 changed file(s) with 61 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
7272 void setCodePICModel(lto_codegen_model);
7373
7474 void setCpu(const char *mCpu) { MCpu = mCpu; }
75 void setAttr(const char *mAttr) { MAttr = mAttr; }
7576
7677 void addMustPreserveSymbol(const char *sym) { MustPreserveSymbols[sym] = 1; }
7778
149150 llvm::MemoryBuffer *NativeObjectFile;
150151 std::vector CodegenOptions;
151152 std::string MCpu;
153 std::string MAttr;
152154 std::string NativeObjectPath;
153155 llvm::TargetOptions Options;
154156 lto_diagnostic_handler_t DiagHandler;
3939 * @{
4040 */
4141
42 #define LTO_API_VERSION 10
42 #define LTO_API_VERSION 11
4343
4444 /**
4545 * \since prior to LTO_API_VERSION=3
374374 extern void
375375 lto_codegen_set_cpu(lto_code_gen_t cg, const char *cpu);
376376
377 /**
378 * Sets attributes for the cpu to generate code for.
379 *
380 * \since LTO_API_VERSION=11
381 */
382 extern void
383 lto_codegen_set_attr(lto_code_gen_t cg, const char *attr);
384
377385
378386 /**
379387 * Sets the location of the assembler tool to run. If not set, libLTO
300300 break;
301301 }
302302
303 // construct LTOModule, hand over ownership of module and target
304 SubtargetFeatures Features;
303 // Construct LTOModule, hand over ownership of module and target. Use MAttr as
304 // the default set of features.
305 SubtargetFeatures Features(MAttr);
305306 Features.getDefaultSubtargetFeatures(Triple);
306307 std::string FeatureStr = Features.getString();
307308 // Set a default CPU for Darwin triples.
0 ; RUN: llvm-as < %s >%t1
1 ; RUN: llvm-lto -exported-symbol=test_x86_aesni_aeskeygenassist -mattr=+aes -o %t2 %t1
2 ; RUN: llvm-objdump -d %t2 | FileCheck -check-prefix=WITH_AES %s
3 ; RUN: not llvm-lto -exported-symbol=test_x86_aesni_aeskeygenassist -mattr=-aes -o %t3 %t1 2>&1 | FileCheck -check-prefix=WITHOUT_AES %s
4
5 target triple = "x86_64-unknown-linux-gnu"
6 declare <2 x i64> @llvm.x86.aesni.aeskeygenassist(<2 x i64>, i8)
7 define <2 x i64> @test_x86_aesni_aeskeygenassist(<2 x i64> %a0) {
8 ; WITH_AES: test_x86_aesni_aeskeygenassist
9 ; WITH_AES: aeskeygenassist
10 %res = call <2 x i64> @llvm.x86.aesni.aeskeygenassist(<2 x i64> %a0, i8 7)
11 ret <2 x i64> %res
12 }
13
14 ; WITHOUT_AES: LLVM ERROR: Cannot select: intrinsic %llvm.x86.aesni.aeskeygenassist
142142 for (unsigned i = 0; i < KeptDSOSyms.size(); ++i)
143143 CodeGen.addMustPreserveSymbol(KeptDSOSyms[i].c_str());
144144
145 std::string attrs;
146 for (unsigned i = 0; i < MAttrs.size(); ++i) {
147 if (i > 0)
148 attrs.append(",");
149 attrs.append(MAttrs[i]);
150 }
151
152 if (!attrs.empty())
153 CodeGen.setAttr(attrs.c_str());
154
145155 if (!OutputFilename.empty()) {
146156 size_t len = 0;
147157 std::string ErrorInfo;
5555 }
5656 }
5757
58 // Convert the subtarget features into a string to pass to LTOCodeGenerator.
59 static void lto_add_attrs(lto_code_gen_t cg) {
60 if (MAttrs.size()) {
61 std::string attrs;
62 for (unsigned i = 0; i < MAttrs.size(); ++i) {
63 if (i > 0)
64 attrs.append(",");
65 attrs.append(MAttrs[i]);
66 }
67
68 cg->setAttr(attrs.c_str());
69 }
70 }
71
5872 /// lto_get_version - Returns a printable string.
5973 extern const char* lto_get_version() {
6074 return LTOCodeGenerator::getVersionString();
251265 return cg->setCpu(cpu);
252266 }
253267
268 /// lto_codegen_set_attr - Sets the attr to generate code for.
269 void lto_codegen_set_attr(lto_code_gen_t cg, const char *attr) {
270 return cg->setAttr(attr);
271 }
272
254273 /// lto_codegen_set_assembler_path - Sets the path to the assembler tool.
255274 void lto_codegen_set_assembler_path(lto_code_gen_t cg, const char *path) {
256275 // In here only for backwards compatibility. We use MC now.
277296 bool lto_codegen_write_merged_modules(lto_code_gen_t cg, const char *path) {
278297 if (!parsedOptions) {
279298 cg->parseCodeGenDebugOptions();
299 lto_add_attrs(cg);
280300 parsedOptions = true;
281301 }
282302 return !cg->writeMergedModules(path, sLastErrorString);
291311 const void *lto_codegen_compile(lto_code_gen_t cg, size_t *length) {
292312 if (!parsedOptions) {
293313 cg->parseCodeGenDebugOptions();
314 lto_add_attrs(cg);
294315 parsedOptions = true;
295316 }
296317 return cg->compile(length, DisableOpt, DisableInline, DisableGVNLoadPRE,
303324 bool lto_codegen_compile_to_file(lto_code_gen_t cg, const char **name) {
304325 if (!parsedOptions) {
305326 cg->parseCodeGenDebugOptions();
327 lto_add_attrs(cg);
306328 parsedOptions = true;
307329 }
308330 return !cg->compile_to_file(name, DisableOpt, DisableInline, DisableGVNLoadPRE,