From 683ad0f3bbf5b686f00431a371ec11835a47c85c Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 29 Mar 2009 05:04:26 +0000 Subject: [PATCH] genericize the ActionResult optimization for holding the "ininvalid" bit in the low bit position a little bit (haha). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67982 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Parse/Action.h | 1 + include/clang/Parse/Ownership.h | 37 +++++++++++++++++---------------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h index b7bb8d0afd..b1174672f2 100644 --- a/include/clang/Parse/Action.h +++ b/include/clang/Parse/Action.h @@ -47,6 +47,7 @@ namespace clang { template<> struct IsResultPtrLowBitFree<1> { static const bool value = true;}; template<> struct IsResultPtrLowBitFree<3> { static const bool value = true;}; template<> struct IsResultPtrLowBitFree<4> { static const bool value = true;}; +//template<> struct IsResultPtrLowBitFree<5> { static const bool value = true;}; /// Action - As the parser reads the input file and recognizes the productions /// of the grammar, it invokes methods on this class to turn the parsed input diff --git a/include/clang/Parse/Ownership.h b/include/clang/Parse/Ownership.h index 50bc5aee12..1f5c4f8865 100644 --- a/include/clang/Parse/Ownership.h +++ b/include/clang/Parse/Ownership.h @@ -211,35 +211,36 @@ namespace clang } }; - ///// FIXME: We just lost the ability to bitmangle into DeclPtrTy's and - ///// friends! - // This ActionResult partial specialization places the "invalid" // flag into the low bit of the pointer. - template - class ActionResult { + template + class ActionResult { // A pointer whose low bit is 1 if this result is invalid, 0 // otherwise. uintptr_t PtrWithInvalid; - + typedef llvm::PointerLikeTypeTraits PtrTraits; public: ActionResult(bool Invalid = false) : PtrWithInvalid(static_cast(Invalid)) { } template - ActionResult(ActualExprTy *val) - : PtrWithInvalid(reinterpret_cast(val)) { + ActionResult(ActualExprTy *val) { + PtrTy V(val); + void *VP = PtrTraits::getAsVoidPointer(V); + PtrWithInvalid = reinterpret_cast(VP); assert((PtrWithInvalid & 0x01) == 0 && "Badly aligned pointer"); } ActionResult(const DiagnosticBuilder &) : PtrWithInvalid(0x01) { } - void *get() const { - return reinterpret_cast(PtrWithInvalid & ~0x01); + PtrTy get() const { + void *VP = reinterpret_cast(PtrWithInvalid & ~0x01); + return PtrTraits::getFromVoidPointer(VP); } - void set(void *V) { - PtrWithInvalid = reinterpret_cast(V); + void set(PtrTy V) { + void *VP = PtrTraits::getAsVoidPointer(V); + PtrWithInvalid = reinterpret_cast(VP); assert((PtrWithInvalid & 0x01) == 0 && "Badly aligned pointer"); } @@ -394,7 +395,7 @@ namespace clang } /// Move assignment from another owning result - ASTOwningResult & operator =(moving::ASTResultMover mover) { + ASTOwningResult &operator=(moving::ASTResultMover mover) { destroy(); ActionInv = mover->ActionInv; Ptr = mover->Ptr; @@ -403,7 +404,7 @@ namespace clang } /// Assignment from a raw pointer. Takes ownership - beware! - ASTOwningResult & operator =(void *raw) { + ASTOwningResult &operator=(void *raw) { destroy(); Ptr = raw; ActionInv.setInt(false); @@ -411,7 +412,7 @@ namespace clang } /// Assignment from an ActionResult. Takes ownership - beware! - ASTOwningResult & operator =(const DumbResult &res) { + ASTOwningResult &operator=(const DumbResult &res) { destroy(); Ptr = res.get(); ActionInv.setInt(res.isInvalid()); @@ -419,7 +420,7 @@ namespace clang } /// Access to the raw pointer. - void * get() const { return Ptr; } + void *get() const { return Ptr; } bool isInvalid() const { return ActionInv.getInt(); } @@ -428,7 +429,7 @@ namespace clang bool isUsable() const { return !isInvalid() && get(); } /// Take outside ownership of the raw pointer. - void * take() { + void *take() { if (isInvalid()) return 0; void *tmp = Ptr; @@ -443,7 +444,7 @@ namespace clang } /// Alias for interface familiarity with unique_ptr. - void * release() { return take(); } + void *release() { return take(); } /// Pass ownership to a classical ActionResult. DumbResult result() { -- 2.40.0