diff --git a/examples/PrintFunctionNames/CMakeLists.txt b/examples/PrintFunctionNames/CMakeLists.txt index 58b4603e9b6da43301eb36fc32382704e5353191..86793ce7e187ba805ef2d7a171efe0e596858613 100644 --- a/examples/PrintFunctionNames/CMakeLists.txt +++ b/examples/PrintFunctionNames/CMakeLists.txt @@ -1,34 +1,11 @@ set(MODULE TRUE) set( LLVM_USED_LIBS - clangFrontendTool clangFrontend - clangDriver - clangSerialization - clangCodeGen - clangParse - clangSema - clangStaticAnalyzerFrontend - clangStaticAnalyzerCheckers - clangStaticAnalyzerCore - clangAnalysis - clangIndex - clangRewrite clangAST - clangLex - clangBasic ) -# Why do we have to link to all this just to print out function names? -set( LLVM_LINK_COMPONENTS - ${LLVM_TARGETS_TO_BUILD} - asmparser - bitreader - bitwriter - codegen - ipo - selectiondag - ) +set( LLVM_LINK_COMPONENTS support mc) add_clang_library(PrintFunctionNames PrintFunctionNames.cpp) diff --git a/examples/clang-interpreter/main.cpp b/examples/clang-interpreter/main.cpp index 835a5a90ad179123e1a93cbb6e1b11401023f387..a99766f9a31481bc3930b0e8a6bb938679530a75 100644 --- a/examples/clang-interpreter/main.cpp +++ b/examples/clang-interpreter/main.cpp @@ -17,7 +17,6 @@ #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Frontend/TextDiagnosticPrinter.h" -#include "llvm/LLVMContext.h" #include "llvm/Module.h" #include "llvm/Config/config.h" #include "llvm/ADT/OwningPtr.h" @@ -130,7 +129,6 @@ int main(int argc, const char **argv, char * const *envp) { // Create a compiler instance to handle the actual work. CompilerInstance Clang; - Clang.setLLVMContext(new llvm::LLVMContext); Clang.setInvocation(CI.take()); // Create the compilers actual diagnostics engine. diff --git a/include/clang/CodeGen/CodeGenAction.h b/include/clang/CodeGen/CodeGenAction.h index b55effc6be07befb52ef477bb83d18404d13f58a..052c6603f5a7b639750b51adaa2177ce0e0a1ce6 100644 --- a/include/clang/CodeGen/CodeGenAction.h +++ b/include/clang/CodeGen/CodeGenAction.h @@ -14,6 +14,7 @@ #include "llvm/ADT/OwningPtr.h" namespace llvm { + class LLVMContext; class Module; } @@ -24,9 +25,14 @@ class CodeGenAction : public ASTFrontendAction { private: unsigned Act; llvm::OwningPtr<llvm::Module> TheModule; + llvm::LLVMContext *VMContext; + bool OwnsVMContext; protected: - CodeGenAction(unsigned _Act); + /// Create a new code generation action. If the optional \arg _VMContext + /// parameter is supplied, the action uses it without taking ownership, + /// otherwise it creates a fresh LLVM context and takes ownership. + CodeGenAction(unsigned _Act, llvm::LLVMContext *_VMContext = 0); virtual bool hasIRSupport() const; @@ -44,37 +50,40 @@ public: /// been run. The result may be null on failure. llvm::Module *takeModule(); + /// Take the LLVM context used by this action. + llvm::LLVMContext *takeLLVMContext(); + BackendConsumer *BEConsumer; }; class EmitAssemblyAction : public CodeGenAction { public: - EmitAssemblyAction(); + EmitAssemblyAction(llvm::LLVMContext *_VMContext = 0); }; class EmitBCAction : public CodeGenAction { public: - EmitBCAction(); + EmitBCAction(llvm::LLVMContext *_VMContext = 0); }; class EmitLLVMAction : public CodeGenAction { public: - EmitLLVMAction(); + EmitLLVMAction(llvm::LLVMContext *_VMContext = 0); }; class EmitLLVMOnlyAction : public CodeGenAction { public: - EmitLLVMOnlyAction(); + EmitLLVMOnlyAction(llvm::LLVMContext *_VMContext = 0); }; class EmitCodeGenOnlyAction : public CodeGenAction { public: - EmitCodeGenOnlyAction(); + EmitCodeGenOnlyAction(llvm::LLVMContext *_VMContext = 0); }; class EmitObjAction : public CodeGenAction { public: - EmitObjAction(); + EmitObjAction(llvm::LLVMContext *_VMContext = 0); }; } diff --git a/include/clang/Frontend/ASTConsumers.h b/include/clang/Frontend/ASTConsumers.h index e2071df8e32cd10e0e1aa3cb2cd44ef52a8a8ffe..c45bd40706005cbeb8d528f4265cfb27ac679a53 100644 --- a/include/clang/Frontend/ASTConsumers.h +++ b/include/clang/Frontend/ASTConsumers.h @@ -18,8 +18,6 @@ namespace llvm { class raw_ostream; - class Module; - class LLVMContext; namespace sys { class Path; } } namespace clang { diff --git a/include/clang/Frontend/CompilerInstance.h b/include/clang/Frontend/CompilerInstance.h index 430cc603c78f0079315f7d5d0a4aa5cc12544985..7ea79e5599ff9ac4244df8b055d76ec8a928f4a8 100644 --- a/include/clang/Frontend/CompilerInstance.h +++ b/include/clang/Frontend/CompilerInstance.h @@ -19,7 +19,6 @@ #include <string> namespace llvm { -class LLVMContext; class raw_ostream; class raw_fd_ostream; class Timer; @@ -59,9 +58,6 @@ class TargetInfo; /// come in two forms; a short form that reuses the CompilerInstance objects, /// and a long form that takes explicit instances of any required objects. class CompilerInstance { - /// The LLVM context used for this instance. - llvm::OwningPtr<llvm::LLVMContext> LLVMContext; - /// The options used in this compiler instance. llvm::OwningPtr<CompilerInvocation> Invocation; @@ -154,23 +150,6 @@ public: // of the context or else not CompilerInstance specific. bool ExecuteAction(FrontendAction &Act); - /// } - /// @name LLVM Context - /// { - - bool hasLLVMContext() const { return LLVMContext != 0; } - - llvm::LLVMContext &getLLVMContext() const { - assert(LLVMContext && "Compiler instance has no LLVM context!"); - return *LLVMContext; - } - - llvm::LLVMContext *takeLLVMContext() { return LLVMContext.take(); } - - /// setLLVMContext - Replace the current LLVM context and take ownership of - /// \arg Value. - void setLLVMContext(llvm::LLVMContext *Value); - /// } /// @name Compiler Invocation and Options /// { diff --git a/lib/CodeGen/CodeGenAction.cpp b/lib/CodeGen/CodeGenAction.cpp index 69ac995a468b9c0b9a70c74e9fc46dbe6e43e701..a24bbc480c1987d245275fc9f7824a7bf7a54ab5 100644 --- a/lib/CodeGen/CodeGenAction.cpp +++ b/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/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index 412e7111e4801bc8bca1a7da227020487f885f68..fd593de560c02a7231a0fd605f8508c6e9476073 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/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); } diff --git a/tools/c-index-test/CMakeLists.txt b/tools/c-index-test/CMakeLists.txt index 9169fc7422a0d1806efa4223f2aadedfcc95ee9d..45ad9e35c6efb5fc482bdf6ec2f77ea02385bdf5 100644 --- a/tools/c-index-test/CMakeLists.txt +++ b/tools/c-index-test/CMakeLists.txt @@ -1,9 +1,8 @@ set(LLVM_USED_LIBS libclang) set( LLVM_LINK_COMPONENTS - bitreader + support mc - core ) add_clang_executable(c-index-test diff --git a/tools/c-index-test/Makefile b/tools/c-index-test/Makefile index f41aa8098155a7e9f32e4d34264f4be59365e3ee..3d9849a3a4015e348ed819ad422f8134150e9fce 100644 --- a/tools/c-index-test/Makefile +++ b/tools/c-index-test/Makefile @@ -13,7 +13,7 @@ TOOLNAME = c-index-test # No plugins, optimize startup time. TOOL_NO_EXPORTS = 1 -LINK_COMPONENTS := bitreader mc core +LINK_COMPONENTS := support mc USEDLIBS = clang.a clangIndex.a clangFrontend.a clangDriver.a \ clangSerialization.a clangParse.a clangSema.a clangAnalysis.a \ clangAST.a clangLex.a clangBasic.a diff --git a/tools/driver/cc1_main.cpp b/tools/driver/cc1_main.cpp index 1f8d1129dad184f0b35158cd416efb5009b180bb..7fb394fa5b01aed25d5a283c0b4b4aff871d8edf 100644 --- a/tools/driver/cc1_main.cpp +++ b/tools/driver/cc1_main.cpp @@ -24,7 +24,6 @@ #include "clang/Frontend/TextDiagnosticBuffer.h" #include "clang/Frontend/TextDiagnosticPrinter.h" #include "clang/FrontendTool/Utils.h" -#include "llvm/LLVMContext.h" #include "llvm/ADT/Statistic.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ManagedStatic.h" @@ -118,8 +117,6 @@ int cc1_main(const char **ArgBegin, const char **ArgEnd, llvm::OwningPtr<CompilerInstance> Clang(new CompilerInstance()); llvm::IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); - Clang->setLLVMContext(new llvm::LLVMContext()); - // Run clang -cc1 test. if (ArgBegin != ArgEnd && llvm::StringRef(ArgBegin[0]) == "-cc1test") { Diagnostic Diags(DiagID, new TextDiagnosticPrinter(llvm::errs(), diff --git a/tools/libclang/CMakeLists.txt b/tools/libclang/CMakeLists.txt index 661fddd822e0c98564edfc2c7958a6b6fdc01f41..da72f5a02d01a9e683dc4bc90310063e4afd4f1a 100644 --- a/tools/libclang/CMakeLists.txt +++ b/tools/libclang/CMakeLists.txt @@ -11,9 +11,8 @@ set(LLVM_USED_LIBS clangBasic) set( LLVM_LINK_COMPONENTS - bitreader + support mc - core ) add_clang_library(libclang diff --git a/tools/libclang/Makefile b/tools/libclang/Makefile index 6d2a13cfc0b4d2ec67ab198965cc7b33d02a2f66..e684652aa4cad779b7bb691d0eef0a9eb7c8fb44 100644 --- a/tools/libclang/Makefile +++ b/tools/libclang/Makefile @@ -15,7 +15,7 @@ EXPORTED_SYMBOL_FILE = $(PROJ_SRC_DIR)/libclang.exports LINK_LIBS_IN_SHARED = 1 SHARED_LIBRARY = 1 -LINK_COMPONENTS := bitreader mc core +LINK_COMPONENTS := support mc USEDLIBS = clangFrontend.a clangDriver.a clangSerialization.a clangParse.a \ clangSema.a clangAnalysis.a clangAST.a clangLex.a clangBasic.a diff --git a/unittests/Basic/Makefile b/unittests/Basic/Makefile index e7ac57cbe19cc1a7eae23b3a6eab04ad5f964b50..4bac50c12ab300ff062677b11ae49c3ac0b15745 100644 --- a/unittests/Basic/Makefile +++ b/unittests/Basic/Makefile @@ -9,7 +9,7 @@ CLANG_LEVEL = ../.. TESTNAME = Basic -LINK_COMPONENTS := core support mc +LINK_COMPONENTS := support mc USEDLIBS = clangBasic.a include $(CLANG_LEVEL)/unittests/Makefile diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index 0c91450e048f75c1e2d2cb07d548db7b9f0bccee..45358db370b7481e27de7282332e775ba83ded24 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -37,13 +37,13 @@ if(SUPPORTS_NO_VARIADIC_MACROS_FLAG) endif() add_clang_unittest(Basic - "Core" + "support mc" "gtest gtest_main clangBasic" Basic/FileManagerTest.cpp ) add_clang_unittest(Frontend - "Core" + "support mc" "gtest gtest_main clangFrontend" Frontend/FrontendActionTest.cpp ) diff --git a/unittests/Frontend/FrontendActionTest.cpp b/unittests/Frontend/FrontendActionTest.cpp index 49a63983f0527576e8fcdfc66dd9bc384a66c303..a32388a062e96829744ca50bf4caada599ce6bfb 100644 --- a/unittests/Frontend/FrontendActionTest.cpp +++ b/unittests/Frontend/FrontendActionTest.cpp @@ -14,7 +14,6 @@ #include "clang/Frontend/FrontendAction.h" #include "llvm/ADT/Triple.h" -#include "llvm/LLVMContext.h" #include "llvm/Support/MemoryBuffer.h" #include "gtest/gtest.h" @@ -61,7 +60,6 @@ TEST(ASTFrontendAction, Sanity) { invocation->getFrontendOpts().ProgramAction = frontend::ParseSyntaxOnly; invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu"; CompilerInstance compiler; - compiler.setLLVMContext(new LLVMContext); compiler.setInvocation(invocation); compiler.createDiagnostics(0, NULL); diff --git a/unittests/Frontend/Makefile b/unittests/Frontend/Makefile index cdbfb4c57c9861b2e7b4a035bea5866064395fea..4d9937f517cf2dbace11587609986851497c0830 100644 --- a/unittests/Frontend/Makefile +++ b/unittests/Frontend/Makefile @@ -9,7 +9,7 @@ CLANG_LEVEL = ../.. TESTNAME = Frontend -LINK_COMPONENTS := core support mc +LINK_COMPONENTS := support mc USEDLIBS = clangFrontendTool.a clangFrontend.a clangDriver.a \ clangSerialization.a clangCodeGen.a clangParse.a clangSema.a \ clangStaticAnalyzerCheckers.a clangStaticAnalyzerCore.a \