forked from OSchip/llvm-project
Pass the target options through to code generation.
The code generation stuff is going to set attributes on the functions it generates. To do that it needs the target options. Pass them through. llvm-svn: 175141
This commit is contained in:
parent
039fa75e4d
commit
c86a2f39a9
|
@ -26,6 +26,7 @@ namespace clang {
|
||||||
class DiagnosticsEngine;
|
class DiagnosticsEngine;
|
||||||
class LangOptions;
|
class LangOptions;
|
||||||
class CodeGenOptions;
|
class CodeGenOptions;
|
||||||
|
class TargetOptions;
|
||||||
|
|
||||||
class CodeGenerator : public ASTConsumer {
|
class CodeGenerator : public ASTConsumer {
|
||||||
virtual void anchor();
|
virtual void anchor();
|
||||||
|
@ -40,6 +41,7 @@ namespace clang {
|
||||||
CodeGenerator *CreateLLVMCodeGen(DiagnosticsEngine &Diags,
|
CodeGenerator *CreateLLVMCodeGen(DiagnosticsEngine &Diags,
|
||||||
const std::string &ModuleName,
|
const std::string &ModuleName,
|
||||||
const CodeGenOptions &CGO,
|
const CodeGenOptions &CGO,
|
||||||
|
const TargetOptions &TO,
|
||||||
llvm::LLVMContext& C);
|
llvm::LLVMContext& C);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "llvm/IR/Attributes.h"
|
#include "llvm/IR/Attributes.h"
|
||||||
#include "llvm/IR/DataLayout.h"
|
#include "llvm/IR/DataLayout.h"
|
||||||
#include "llvm/IR/InlineAsm.h"
|
#include "llvm/IR/InlineAsm.h"
|
||||||
|
#include "llvm/MC/SubtargetFeature.h"
|
||||||
#include "llvm/Support/CallSite.h"
|
#include "llvm/Support/CallSite.h"
|
||||||
#include "llvm/Transforms/Utils/Local.h"
|
#include "llvm/Transforms/Utils/Local.h"
|
||||||
using namespace clang;
|
using namespace clang;
|
||||||
|
@ -1015,6 +1016,18 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI,
|
||||||
if (CodeGenOpts.NoImplicitFloat)
|
if (CodeGenOpts.NoImplicitFloat)
|
||||||
FuncAttrs.addAttribute(llvm::Attribute::NoImplicitFloat);
|
FuncAttrs.addAttribute(llvm::Attribute::NoImplicitFloat);
|
||||||
|
|
||||||
|
if (!TargetOpts.CPU.empty())
|
||||||
|
FuncAttrs.addAttribute("target-cpu", TargetOpts.CPU);
|
||||||
|
|
||||||
|
if (TargetOpts.Features.size()) {
|
||||||
|
llvm::SubtargetFeatures Features;
|
||||||
|
for (std::vector<std::string>::const_iterator
|
||||||
|
it = TargetOpts.Features.begin(),
|
||||||
|
ie = TargetOpts.Features.end(); it != ie; ++it)
|
||||||
|
Features.AddFeature(*it);
|
||||||
|
FuncAttrs.addAttribute("target-features", Features.getString());
|
||||||
|
}
|
||||||
|
|
||||||
QualType RetTy = FI.getReturnType();
|
QualType RetTy = FI.getReturnType();
|
||||||
unsigned Index = 1;
|
unsigned Index = 1;
|
||||||
const ABIArgInfo &RetAI = FI.getReturnInfo();
|
const ABIArgInfo &RetAI = FI.getReturnInfo();
|
||||||
|
|
|
@ -67,7 +67,7 @@ namespace clang {
|
||||||
AsmOutStream(OS),
|
AsmOutStream(OS),
|
||||||
Context(),
|
Context(),
|
||||||
LLVMIRGeneration("LLVM IR Generation Time"),
|
LLVMIRGeneration("LLVM IR Generation Time"),
|
||||||
Gen(CreateLLVMCodeGen(Diags, infile, compopts, C)),
|
Gen(CreateLLVMCodeGen(Diags, infile, compopts, targetopts, C)),
|
||||||
LinkModule(LinkModule)
|
LinkModule(LinkModule)
|
||||||
{
|
{
|
||||||
llvm::TimePassesIsEnabled = TimePasses;
|
llvm::TimePassesIsEnabled = TimePasses;
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#include "clang/Basic/Module.h"
|
#include "clang/Basic/Module.h"
|
||||||
#include "clang/Basic/SourceManager.h"
|
#include "clang/Basic/SourceManager.h"
|
||||||
#include "clang/Basic/TargetInfo.h"
|
#include "clang/Basic/TargetInfo.h"
|
||||||
|
#include "clang/Basic/TargetOptions.h"
|
||||||
#include "clang/Frontend/CodeGenOptions.h"
|
#include "clang/Frontend/CodeGenOptions.h"
|
||||||
#include "llvm/ADT/APSInt.h"
|
#include "llvm/ADT/APSInt.h"
|
||||||
#include "llvm/ADT/Triple.h"
|
#include "llvm/ADT/Triple.h"
|
||||||
|
@ -69,10 +70,11 @@ static CGCXXABI &createCXXABI(CodeGenModule &CGM) {
|
||||||
|
|
||||||
|
|
||||||
CodeGenModule::CodeGenModule(ASTContext &C, const CodeGenOptions &CGO,
|
CodeGenModule::CodeGenModule(ASTContext &C, const CodeGenOptions &CGO,
|
||||||
llvm::Module &M, const llvm::DataLayout &TD,
|
const TargetOptions &TO, llvm::Module &M,
|
||||||
|
const llvm::DataLayout &TD,
|
||||||
DiagnosticsEngine &diags)
|
DiagnosticsEngine &diags)
|
||||||
: Context(C), LangOpts(C.getLangOpts()), CodeGenOpts(CGO), TheModule(M),
|
: Context(C), LangOpts(C.getLangOpts()), CodeGenOpts(CGO), TargetOpts(TO),
|
||||||
TheDataLayout(TD), TheTargetCodeGenInfo(0), Diags(diags),
|
TheModule(M), TheDataLayout(TD), TheTargetCodeGenInfo(0), Diags(diags),
|
||||||
ABI(createCXXABI(*this)),
|
ABI(createCXXABI(*this)),
|
||||||
Types(*this),
|
Types(*this),
|
||||||
TBAA(0),
|
TBAA(0),
|
||||||
|
|
|
@ -65,6 +65,7 @@ namespace clang {
|
||||||
class VarDecl;
|
class VarDecl;
|
||||||
class LangOptions;
|
class LangOptions;
|
||||||
class CodeGenOptions;
|
class CodeGenOptions;
|
||||||
|
class TargetOptions;
|
||||||
class DiagnosticsEngine;
|
class DiagnosticsEngine;
|
||||||
class AnnotateAttr;
|
class AnnotateAttr;
|
||||||
class CXXDestructorDecl;
|
class CXXDestructorDecl;
|
||||||
|
@ -222,6 +223,7 @@ class CodeGenModule : public CodeGenTypeCache {
|
||||||
ASTContext &Context;
|
ASTContext &Context;
|
||||||
const LangOptions &LangOpts;
|
const LangOptions &LangOpts;
|
||||||
const CodeGenOptions &CodeGenOpts;
|
const CodeGenOptions &CodeGenOpts;
|
||||||
|
const TargetOptions &TargetOpts;
|
||||||
llvm::Module &TheModule;
|
llvm::Module &TheModule;
|
||||||
const llvm::DataLayout &TheDataLayout;
|
const llvm::DataLayout &TheDataLayout;
|
||||||
mutable const TargetCodeGenInfo *TheTargetCodeGenInfo;
|
mutable const TargetCodeGenInfo *TheTargetCodeGenInfo;
|
||||||
|
@ -378,8 +380,8 @@ class CodeGenModule : public CodeGenTypeCache {
|
||||||
/// @}
|
/// @}
|
||||||
public:
|
public:
|
||||||
CodeGenModule(ASTContext &C, const CodeGenOptions &CodeGenOpts,
|
CodeGenModule(ASTContext &C, const CodeGenOptions &CodeGenOpts,
|
||||||
llvm::Module &M, const llvm::DataLayout &TD,
|
const TargetOptions &TargetOpts, llvm::Module &M,
|
||||||
DiagnosticsEngine &Diags);
|
const llvm::DataLayout &TD, DiagnosticsEngine &Diags);
|
||||||
|
|
||||||
~CodeGenModule();
|
~CodeGenModule();
|
||||||
|
|
||||||
|
|
|
@ -31,13 +31,16 @@ namespace {
|
||||||
OwningPtr<const llvm::DataLayout> TD;
|
OwningPtr<const llvm::DataLayout> TD;
|
||||||
ASTContext *Ctx;
|
ASTContext *Ctx;
|
||||||
const CodeGenOptions CodeGenOpts; // Intentionally copied in.
|
const CodeGenOptions CodeGenOpts; // Intentionally copied in.
|
||||||
|
const TargetOptions TargetOpts; // Intentionally copied in.
|
||||||
protected:
|
protected:
|
||||||
OwningPtr<llvm::Module> M;
|
OwningPtr<llvm::Module> M;
|
||||||
OwningPtr<CodeGen::CodeGenModule> Builder;
|
OwningPtr<CodeGen::CodeGenModule> Builder;
|
||||||
public:
|
public:
|
||||||
CodeGeneratorImpl(DiagnosticsEngine &diags, const std::string& ModuleName,
|
CodeGeneratorImpl(DiagnosticsEngine &diags, const std::string& ModuleName,
|
||||||
const CodeGenOptions &CGO, llvm::LLVMContext& C)
|
const CodeGenOptions &CGO, const TargetOptions &TO,
|
||||||
: Diags(diags), CodeGenOpts(CGO), M(new llvm::Module(ModuleName, C)) {}
|
llvm::LLVMContext& C)
|
||||||
|
: Diags(diags), CodeGenOpts(CGO), TargetOpts(TO),
|
||||||
|
M(new llvm::Module(ModuleName, C)) {}
|
||||||
|
|
||||||
virtual ~CodeGeneratorImpl() {}
|
virtual ~CodeGeneratorImpl() {}
|
||||||
|
|
||||||
|
@ -55,7 +58,7 @@ namespace {
|
||||||
M->setTargetTriple(Ctx->getTargetInfo().getTriple().getTriple());
|
M->setTargetTriple(Ctx->getTargetInfo().getTriple().getTriple());
|
||||||
M->setDataLayout(Ctx->getTargetInfo().getTargetDescription());
|
M->setDataLayout(Ctx->getTargetInfo().getTargetDescription());
|
||||||
TD.reset(new llvm::DataLayout(Ctx->getTargetInfo().getTargetDescription()));
|
TD.reset(new llvm::DataLayout(Ctx->getTargetInfo().getTargetDescription()));
|
||||||
Builder.reset(new CodeGen::CodeGenModule(Context, CodeGenOpts,
|
Builder.reset(new CodeGen::CodeGenModule(Context, CodeGenOpts, TargetOpts,
|
||||||
*M, *TD, Diags));
|
*M, *TD, Diags));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,6 +125,7 @@ void CodeGenerator::anchor() { }
|
||||||
CodeGenerator *clang::CreateLLVMCodeGen(DiagnosticsEngine &Diags,
|
CodeGenerator *clang::CreateLLVMCodeGen(DiagnosticsEngine &Diags,
|
||||||
const std::string& ModuleName,
|
const std::string& ModuleName,
|
||||||
const CodeGenOptions &CGO,
|
const CodeGenOptions &CGO,
|
||||||
|
const TargetOptions &TO,
|
||||||
llvm::LLVMContext& C) {
|
llvm::LLVMContext& C) {
|
||||||
return new CodeGeneratorImpl(Diags, ModuleName, CGO, C);
|
return new CodeGeneratorImpl(Diags, ModuleName, CGO, TO, C);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue