From 80758084f70dbdaa4ca16661871215bacee0ab18 Mon Sep 17 00:00:00 2001 From: Alp Toker Date: Sun, 6 Jul 2014 05:26:44 +0000 Subject: [PATCH] Use non-intrusive refcounting for TargetOptions llvm-svn: 212388 --- clang/include/clang/Basic/TargetInfo.h | 11 +++--- clang/include/clang/Basic/TargetOptions.h | 4 +-- clang/include/clang/Frontend/ASTUnit.h | 2 +- clang/include/clang/Frontend/CompilerInvocation.h | 2 +- clang/lib/Basic/Targets.cpp | 7 ++-- clang/lib/Frontend/ASTUnit.cpp | 39 ++++++++++------------ clang/lib/Frontend/ChainedIncludesSource.cpp | 4 +-- clang/lib/Frontend/CompilerInstance.cpp | 3 +- clang/unittests/Basic/SourceManagerTest.cpp | 4 +-- clang/unittests/Lex/LexerTest.cpp | 4 +-- clang/unittests/Lex/PPCallbacksTest.cpp | 14 ++++---- .../Lex/PPConditionalDirectiveRecordTest.cpp | 4 +-- 12 files changed, 45 insertions(+), 53 deletions(-) diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index 49fa78a..f4dcc0e 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -47,7 +47,7 @@ namespace Builtin { struct Info; } /// \brief Exposes information about the current target. /// class TargetInfo : public RefCountedBase { - IntrusiveRefCntPtr TargetOpts; + std::shared_ptr TargetOpts; llvm::Triple Triple; protected: // Target values set by the ctor of the actual target implementation. Default @@ -94,8 +94,9 @@ public: /// \param Opts - The options to use to initialize the target. The target may /// modify the options to canonicalize the target feature information to match /// what the backend expects. - static TargetInfo* CreateTargetInfo(DiagnosticsEngine &Diags, - TargetOptions *Opts); + static TargetInfo * + CreateTargetInfo(DiagnosticsEngine &Diags, + const std::shared_ptr &Opts); virtual ~TargetInfo(); @@ -105,10 +106,6 @@ public: return *TargetOpts; } - void setTargetOpts(TargetOptions *TargetOpts) { - this->TargetOpts = TargetOpts; - } - ///===---- Target Data Type Query Methods -------------------------------===// enum IntType { NoInt = 0, diff --git a/clang/include/clang/Basic/TargetOptions.h b/clang/include/clang/Basic/TargetOptions.h index d8a10a5..2c86c31c 100644 --- a/clang/include/clang/Basic/TargetOptions.h +++ b/clang/include/clang/Basic/TargetOptions.h @@ -15,15 +15,13 @@ #ifndef LLVM_CLANG_FRONTEND_TARGETOPTIONS_H #define LLVM_CLANG_FRONTEND_TARGETOPTIONS_H -#include "clang/Basic/LLVM.h" -#include "llvm/ADT/IntrusiveRefCntPtr.h" #include #include namespace clang { /// \brief Options for controlling the target. -class TargetOptions : public RefCountedBase { +class TargetOptions { public: /// If given, the name of the target triple to compile for. If not given the /// target will be selected to match the host. diff --git a/clang/include/clang/Frontend/ASTUnit.h b/clang/include/clang/Frontend/ASTUnit.h index c9ba6d2..42dc69a 100644 --- a/clang/include/clang/Frontend/ASTUnit.h +++ b/clang/include/clang/Frontend/ASTUnit.h @@ -91,7 +91,7 @@ private: IntrusiveRefCntPtr Target; IntrusiveRefCntPtr PP; IntrusiveRefCntPtr Ctx; - IntrusiveRefCntPtr TargetOpts; + std::shared_ptr TargetOpts; IntrusiveRefCntPtr HSOpts; IntrusiveRefCntPtr Reader; bool HadModuleLoaderFatalFailure; diff --git a/clang/include/clang/Frontend/CompilerInvocation.h b/clang/include/clang/Frontend/CompilerInvocation.h index 0305d8a..f05ab80 100644 --- a/clang/include/clang/Frontend/CompilerInvocation.h +++ b/clang/include/clang/Frontend/CompilerInvocation.h @@ -57,7 +57,7 @@ public: std::shared_ptr LangOpts; /// Options controlling the target. - IntrusiveRefCntPtr TargetOpts; + std::shared_ptr TargetOpts; /// Options controlling the diagnostic engine. IntrusiveRefCntPtr DiagnosticOpts; diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index cc20388..a28436c 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -6388,8 +6388,9 @@ static TargetInfo *AllocateTarget(const llvm::Triple &Triple) { /// CreateTargetInfo - Return the target info object for the specified target /// triple. -TargetInfo *TargetInfo::CreateTargetInfo(DiagnosticsEngine &Diags, - TargetOptions *Opts) { +TargetInfo * +TargetInfo::CreateTargetInfo(DiagnosticsEngine &Diags, + const std::shared_ptr &Opts) { llvm::Triple Triple(Opts->Triple); // Construct the target @@ -6398,7 +6399,7 @@ TargetInfo *TargetInfo::CreateTargetInfo(DiagnosticsEngine &Diags, Diags.Report(diag::err_target_unknown_triple) << Triple.str(); return nullptr; } - Target->setTargetOpts(Opts); + Target->TargetOpts = Opts; // Set the target CPU if specified. if (!Opts->CPU.empty() && !Target->setCPU(Opts->CPU)) { diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index 15f4ca4..f8c25ca 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -504,20 +504,17 @@ class ASTInfoCollector : public ASTReaderListener { Preprocessor &PP; ASTContext &Context; LangOptions &LangOpt; - IntrusiveRefCntPtr &TargetOpts; + std::shared_ptr &TargetOpts; IntrusiveRefCntPtr &Target; unsigned &Counter; bool InitializedLanguage; public: - ASTInfoCollector(Preprocessor &PP, ASTContext &Context, LangOptions &LangOpt, - IntrusiveRefCntPtr &TargetOpts, - IntrusiveRefCntPtr &Target, - unsigned &Counter) - : PP(PP), Context(Context), LangOpt(LangOpt), - TargetOpts(TargetOpts), Target(Target), - Counter(Counter), - InitializedLanguage(false) {} + ASTInfoCollector(Preprocessor &PP, ASTContext &Context, LangOptions &LangOpt, + std::shared_ptr &TargetOpts, + IntrusiveRefCntPtr &Target, unsigned &Counter) + : PP(PP), Context(Context), LangOpt(LangOpt), TargetOpts(TargetOpts), + Target(Target), Counter(Counter), InitializedLanguage(false) {} bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain) override { @@ -536,10 +533,10 @@ public: // If we've already initialized the target, don't do it again. if (Target) return false; - - this->TargetOpts = new TargetOptions(TargetOpts); - Target = TargetInfo::CreateTargetInfo(PP.getDiagnostics(), - &*this->TargetOpts); + + this->TargetOpts = std::make_shared(TargetOpts); + Target = + TargetInfo::CreateTargetInfo(PP.getDiagnostics(), this->TargetOpts); updated(); return false; @@ -1066,8 +1063,8 @@ bool ASTUnit::Parse(llvm::MemoryBuffer *OverrideMainBuffer) { Clang->setDiagnostics(&getDiagnostics()); // Create the target instance. - Clang->setTarget(TargetInfo::CreateTargetInfo(Clang->getDiagnostics(), - &Clang->getTargetOpts())); + Clang->setTarget(TargetInfo::CreateTargetInfo( + Clang->getDiagnostics(), Clang->getInvocation().TargetOpts)); if (!Clang->hasTarget()) { delete OverrideMainBuffer; return true; @@ -1565,8 +1562,8 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble( Clang->setDiagnostics(&getDiagnostics()); // Create the target instance. - Clang->setTarget(TargetInfo::CreateTargetInfo(Clang->getDiagnostics(), - &Clang->getTargetOpts())); + Clang->setTarget(TargetInfo::CreateTargetInfo( + Clang->getDiagnostics(), Clang->getInvocation().TargetOpts)); if (!Clang->hasTarget()) { llvm::sys::fs::remove(FrontendOpts.OutputFile); Preamble.clear(); @@ -1832,8 +1829,8 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction( Clang->setDiagnostics(&AST->getDiagnostics()); // Create the target instance. - Clang->setTarget(TargetInfo::CreateTargetInfo(Clang->getDiagnostics(), - &Clang->getTargetOpts())); + Clang->setTarget(TargetInfo::CreateTargetInfo( + Clang->getDiagnostics(), Clang->getInvocation().TargetOpts)); if (!Clang->hasTarget()) return nullptr; @@ -2409,8 +2406,8 @@ void ASTUnit::CodeComplete(StringRef File, unsigned Line, unsigned Column, ProcessWarningOptions(Diag, CCInvocation->getDiagnosticOpts()); // Create the target instance. - Clang->setTarget(TargetInfo::CreateTargetInfo(Clang->getDiagnostics(), - &Clang->getTargetOpts())); + Clang->setTarget(TargetInfo::CreateTargetInfo( + Clang->getDiagnostics(), Clang->getInvocation().TargetOpts)); if (!Clang->hasTarget()) { Clang->setInvocation(nullptr); return; diff --git a/clang/lib/Frontend/ChainedIncludesSource.cpp b/clang/lib/Frontend/ChainedIncludesSource.cpp index 45851a0..01897cb 100644 --- a/clang/lib/Frontend/ChainedIncludesSource.cpp +++ b/clang/lib/Frontend/ChainedIncludesSource.cpp @@ -100,8 +100,8 @@ ChainedIncludesSource::create(CompilerInstance &CI) { std::unique_ptr Clang(new CompilerInstance()); Clang->setInvocation(CInvok.release()); Clang->setDiagnostics(Diags.get()); - Clang->setTarget(TargetInfo::CreateTargetInfo(Clang->getDiagnostics(), - &Clang->getTargetOpts())); + Clang->setTarget(TargetInfo::CreateTargetInfo( + Clang->getDiagnostics(), Clang->getInvocation().TargetOpts)); Clang->createFileManager(); Clang->createSourceManager(Clang->getFileManager()); Clang->createPreprocessor(TU_Prefix); diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index da663fe..93799c8 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -712,7 +712,8 @@ bool CompilerInstance::ExecuteAction(FrontendAction &Act) { raw_ostream &OS = llvm::errs(); // Create the target instance. - setTarget(TargetInfo::CreateTargetInfo(getDiagnostics(), &getTargetOpts())); + setTarget(TargetInfo::CreateTargetInfo(getDiagnostics(), + getInvocation().TargetOpts)); if (!hasTarget()) return false; diff --git a/clang/unittests/Basic/SourceManagerTest.cpp b/clang/unittests/Basic/SourceManagerTest.cpp index 5416ea7..9ea093c 100644 --- a/clang/unittests/Basic/SourceManagerTest.cpp +++ b/clang/unittests/Basic/SourceManagerTest.cpp @@ -38,7 +38,7 @@ protected: SourceMgr(Diags, FileMgr), TargetOpts(new TargetOptions) { TargetOpts->Triple = "x86_64-apple-darwin11.1.0"; - Target = TargetInfo::CreateTargetInfo(Diags, &*TargetOpts); + Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts); } FileSystemOptions FileMgrOpts; @@ -47,7 +47,7 @@ protected: DiagnosticsEngine Diags; SourceManager SourceMgr; LangOptions LangOpts; - IntrusiveRefCntPtr TargetOpts; + std::shared_ptr TargetOpts; IntrusiveRefCntPtr Target; }; diff --git a/clang/unittests/Lex/LexerTest.cpp b/clang/unittests/Lex/LexerTest.cpp index 938ad4d..2d75b52 100644 --- a/clang/unittests/Lex/LexerTest.cpp +++ b/clang/unittests/Lex/LexerTest.cpp @@ -57,7 +57,7 @@ protected: TargetOpts(new TargetOptions) { TargetOpts->Triple = "x86_64-apple-darwin11.1.0"; - Target = TargetInfo::CreateTargetInfo(Diags, &*TargetOpts); + Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts); } std::vector CheckLex(StringRef Source, @@ -108,7 +108,7 @@ protected: DiagnosticsEngine Diags; SourceManager SourceMgr; LangOptions LangOpts; - IntrusiveRefCntPtr TargetOpts; + std::shared_ptr TargetOpts; IntrusiveRefCntPtr Target; }; diff --git a/clang/unittests/Lex/PPCallbacksTest.cpp b/clang/unittests/Lex/PPCallbacksTest.cpp index c5fd570..a1af754 100644 --- a/clang/unittests/Lex/PPCallbacksTest.cpp +++ b/clang/unittests/Lex/PPCallbacksTest.cpp @@ -116,14 +116,12 @@ public: class PPCallbacksTest : public ::testing::Test { protected: PPCallbacksTest() - : FileMgr(FileMgrOpts), - DiagID(new DiagnosticIDs()), - DiagOpts(new DiagnosticOptions()), - Diags(DiagID, DiagOpts.get(), new IgnoringDiagConsumer()), - SourceMgr(Diags, FileMgr) { - TargetOpts = new TargetOptions(); + : FileMgr(FileMgrOpts), DiagID(new DiagnosticIDs()), + DiagOpts(new DiagnosticOptions()), + Diags(DiagID, DiagOpts.get(), new IgnoringDiagConsumer()), + SourceMgr(Diags, FileMgr), TargetOpts(new TargetOptions()) { TargetOpts->Triple = "x86_64-apple-darwin11.1.0"; - Target = TargetInfo::CreateTargetInfo(Diags, &*TargetOpts); + Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts); } FileSystemOptions FileMgrOpts; @@ -133,7 +131,7 @@ protected: DiagnosticsEngine Diags; SourceManager SourceMgr; LangOptions LangOpts; - IntrusiveRefCntPtr TargetOpts; + std::shared_ptr TargetOpts; IntrusiveRefCntPtr Target; // Register a header path as a known file and add its location diff --git a/clang/unittests/Lex/PPConditionalDirectiveRecordTest.cpp b/clang/unittests/Lex/PPConditionalDirectiveRecordTest.cpp index 8659f0f..e63106c 100644 --- a/clang/unittests/Lex/PPConditionalDirectiveRecordTest.cpp +++ b/clang/unittests/Lex/PPConditionalDirectiveRecordTest.cpp @@ -38,7 +38,7 @@ protected: TargetOpts(new TargetOptions) { TargetOpts->Triple = "x86_64-apple-darwin11.1.0"; - Target = TargetInfo::CreateTargetInfo(Diags, &*TargetOpts); + Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts); } FileSystemOptions FileMgrOpts; @@ -47,7 +47,7 @@ protected: DiagnosticsEngine Diags; SourceManager SourceMgr; LangOptions LangOpts; - IntrusiveRefCntPtr TargetOpts; + std::shared_ptr TargetOpts; IntrusiveRefCntPtr Target; }; -- 2.7.4