mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-12 17:32:19 +00:00
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
This commit is contained in:
parent
c744a37153
commit
817f5e2fa1
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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.
|
||||
|
15
test/LTO/attrs.ll
Normal file
15
test/LTO/attrs.ll
Normal file
@ -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
|
@ -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;
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user