diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Basic/Targets.cpp | 12 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGStmt.cpp | 9 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenAction.cpp | 40 | ||||
-rw-r--r-- | clang/lib/CodeGen/TargetInfo.cpp | 22 | ||||
-rw-r--r-- | clang/lib/CodeGen/TargetInfo.h | 9 | ||||
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 5 |
6 files changed, 64 insertions, 33 deletions
diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index b3501a31c80..a8198e4ae79 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -1014,9 +1014,6 @@ public: } virtual bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &info) const; - virtual const llvm::Type* adjustInlineAsmType(std::string& Constraint, - const llvm::Type* Ty, - llvm::LLVMContext& Context) const; virtual std::string convertConstraint(const char Constraint) const; virtual const char *getClobbers() const { return "~{dirflag},~{fpsr},~{flags}"; @@ -1341,15 +1338,6 @@ X86TargetInfo::validateAsmConstraint(const char *&Name, return false; } -const llvm::Type* -X86TargetInfo::adjustInlineAsmType(std::string& Constraint, - const llvm::Type* Ty, - llvm::LLVMContext &Context) const { - if (Constraint=="y" && Ty->isVectorTy()) - return llvm::Type::getX86_MMXTy(Context); - return Ty; -} - std::string X86TargetInfo::convertConstraint(const char Constraint) const { diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp index f809c009ce1..cd238112ed1 100644 --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -14,6 +14,7 @@ #include "CGDebugInfo.h" #include "CodeGenModule.h" #include "CodeGenFunction.h" +#include "TargetInfo.h" #include "clang/AST/StmtVisitor.h" #include "clang/Basic/PrettyStackTrace.h" #include "clang/Basic/TargetInfo.h" @@ -1135,8 +1136,8 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) { } } if (const llvm::Type* AdjTy = - Target.adjustInlineAsmType(OutputConstraint, ResultRegTypes.back(), - getLLVMContext())) + getTargetHooks().adjustInlineAsmType(*this, OutputConstraint, + ResultRegTypes.back())) ResultRegTypes.back() = AdjTy; } else { ArgTypes.push_back(Dest.getAddress()->getType()); @@ -1207,8 +1208,8 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) { } } if (const llvm::Type* AdjTy = - Target.adjustInlineAsmType(InputConstraint, Arg->getType(), - getLLVMContext())) + getTargetHooks().adjustInlineAsmType(*this, InputConstraint, + Arg->getType())) Arg = Builder.CreateBitCast(Arg, AdjTy); ArgTypes.push_back(Arg->getType()); diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index 69ac995a468..a24bbc480c1 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -224,9 +224,15 @@ void BackendConsumer::InlineAsmDiagHandler2(const llvm::SMDiagnostic &D, // -CodeGenAction::CodeGenAction(unsigned _Act) : Act(_Act) {} - -CodeGenAction::~CodeGenAction() {} +CodeGenAction::CodeGenAction(unsigned _Act, LLVMContext *_VMContext) + : Act(_Act), VMContext(_VMContext ? _VMContext : new LLVMContext), + OwnsVMContext(!_VMContext) {} + +CodeGenAction::~CodeGenAction() { + TheModule.reset(); + if (OwnsVMContext) + delete VMContext; +} bool CodeGenAction::hasIRSupport() const { return true; } @@ -243,6 +249,11 @@ llvm::Module *CodeGenAction::takeModule() { return TheModule.take(); } +llvm::LLVMContext *CodeGenAction::takeLLVMContext() { + OwnsVMContext = false; + return VMContext; +} + static raw_ostream *GetOutputStream(CompilerInstance &CI, llvm::StringRef InFile, BackendAction Action) { @@ -275,7 +286,7 @@ ASTConsumer *CodeGenAction::CreateASTConsumer(CompilerInstance &CI, new BackendConsumer(BA, CI.getDiagnostics(), CI.getCodeGenOpts(), CI.getTargetOpts(), CI.getFrontendOpts().ShowTimers, InFile, OS.take(), - CI.getLLVMContext()); + *VMContext); return BEConsumer; } @@ -301,7 +312,7 @@ void CodeGenAction::ExecuteAction() { getCurrentFile().c_str()); llvm::SMDiagnostic Err; - TheModule.reset(ParseIR(MainFileCopy, Err, CI.getLLVMContext())); + TheModule.reset(ParseIR(MainFileCopy, Err, *VMContext)); if (!TheModule) { // Translate from the diagnostic info to the SourceManager location. SourceLocation Loc = SM.getLocation( @@ -332,15 +343,20 @@ void CodeGenAction::ExecuteAction() { // -EmitAssemblyAction::EmitAssemblyAction() - : CodeGenAction(Backend_EmitAssembly) {} +EmitAssemblyAction::EmitAssemblyAction(llvm::LLVMContext *_VMContext) + : CodeGenAction(Backend_EmitAssembly, _VMContext) {} -EmitBCAction::EmitBCAction() : CodeGenAction(Backend_EmitBC) {} +EmitBCAction::EmitBCAction(llvm::LLVMContext *_VMContext) + : CodeGenAction(Backend_EmitBC, _VMContext) {} -EmitLLVMAction::EmitLLVMAction() : CodeGenAction(Backend_EmitLL) {} +EmitLLVMAction::EmitLLVMAction(llvm::LLVMContext *_VMContext) + : CodeGenAction(Backend_EmitLL, _VMContext) {} -EmitLLVMOnlyAction::EmitLLVMOnlyAction() : CodeGenAction(Backend_EmitNothing) {} +EmitLLVMOnlyAction::EmitLLVMOnlyAction(llvm::LLVMContext *_VMContext) + : CodeGenAction(Backend_EmitNothing, _VMContext) {} -EmitCodeGenOnlyAction::EmitCodeGenOnlyAction() : CodeGenAction(Backend_EmitMCNull) {} +EmitCodeGenOnlyAction::EmitCodeGenOnlyAction(llvm::LLVMContext *_VMContext) + : CodeGenAction(Backend_EmitMCNull, _VMContext) {} -EmitObjAction::EmitObjAction() : CodeGenAction(Backend_EmitObj) {} +EmitObjAction::EmitObjAction(llvm::LLVMContext *_VMContext) + : CodeGenAction(Backend_EmitObj, _VMContext) {} diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp index 881a7ee4d04..d74b3f32d95 100644 --- a/clang/lib/CodeGen/TargetInfo.cpp +++ b/clang/lib/CodeGen/TargetInfo.cpp @@ -355,6 +355,14 @@ bool UseX86_MMXType(const llvm::Type *IRType) { IRType->getScalarSizeInBits() != 64; } +static const llvm::Type* X86AdjustInlineAsmType(CodeGen::CodeGenFunction &CGF, + llvm::StringRef Constraint, + const llvm::Type* Ty) { + if (Constraint=="y" && Ty->isVectorTy()) + return llvm::Type::getX86_MMXTy(CGF.getLLVMContext()); + return Ty; +} + //===----------------------------------------------------------------------===// // X86-32 ABI Implementation //===----------------------------------------------------------------------===// @@ -415,6 +423,13 @@ public: bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF, llvm::Value *Address) const; + + const llvm::Type* adjustInlineAsmType(CodeGen::CodeGenFunction &CGF, + llvm::StringRef Constraint, + const llvm::Type* Ty) const { + return X86AdjustInlineAsmType(CGF, Constraint, Ty); + } + }; } @@ -895,6 +910,13 @@ public: return false; } + + const llvm::Type* adjustInlineAsmType(CodeGen::CodeGenFunction &CGF, + llvm::StringRef Constraint, + const llvm::Type* Ty) const { + return X86AdjustInlineAsmType(CGF, Constraint, Ty); + } + }; class WinX86_64TargetCodeGenInfo : public TargetCodeGenInfo { diff --git a/clang/lib/CodeGen/TargetInfo.h b/clang/lib/CodeGen/TargetInfo.h index 9d4cf161030..4f59eb619e9 100644 --- a/clang/lib/CodeGen/TargetInfo.h +++ b/clang/lib/CodeGen/TargetInfo.h @@ -15,8 +15,11 @@ #ifndef CLANG_CODEGEN_TARGETINFO_H #define CLANG_CODEGEN_TARGETINFO_H +#include "llvm/ADT/StringRef.h" + namespace llvm { class GlobalValue; + class Type; class Value; } @@ -102,6 +105,12 @@ namespace clang { llvm::Value *Address) const { return Address; } + + virtual const llvm::Type* adjustInlineAsmType(CodeGen::CodeGenFunction &CGF, + llvm::StringRef Constraint, + const llvm::Type* Ty) const { + return Ty; + } }; } diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 412e7111e48..fd593de560c 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -27,7 +27,6 @@ #include "clang/Frontend/Utils.h" #include "clang/Serialization/ASTReader.h" #include "clang/Sema/CodeCompleteConsumer.h" -#include "llvm/LLVMContext.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" @@ -47,10 +46,6 @@ CompilerInstance::CompilerInstance() CompilerInstance::~CompilerInstance() { } -void CompilerInstance::setLLVMContext(llvm::LLVMContext *Value) { - LLVMContext.reset(Value); -} - void CompilerInstance::setInvocation(CompilerInvocation *Value) { Invocation.reset(Value); } |