[llvm] r256312 - [GC] Make GCStrategy::isGCManagedPointer a type predicate not a value predicate [NFC]

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 22 17:42:15 PST 2015


Author: reames
Date: Tue Dec 22 19:42:15 2015
New Revision: 256312

URL: http://llvm.org/viewvc/llvm-project?rev=256312&view=rev
Log:
[GC] Make GCStrategy::isGCManagedPointer a type predicate not a value predicate [NFC]

Reasons:
1) The existing form was a form of false generality.  None of the implemented GCStrategies use anything other than a type.  Its becoming more and more clear we're going to need some type of strong GC pointer in the type system and we shouldn't pretend otherwise at this point.
2) The API was awkward when applied to vectors-of-pointers.  The old one could have been made to work, but calling isGCManagedPointer(Ty->getScalarType()) is much cleaner than the Value alternatives.  
3) The rewriting implementation effectively assumes the type based predicate as well.  We should be consistent.


Modified:
    llvm/trunk/include/llvm/CodeGen/GCStrategy.h
    llvm/trunk/lib/CodeGen/CoreCLRGC.cpp
    llvm/trunk/lib/CodeGen/SelectionDAG/StatepointLowering.cpp
    llvm/trunk/lib/CodeGen/StatepointExampleGC.cpp
    llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp

Modified: llvm/trunk/include/llvm/CodeGen/GCStrategy.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GCStrategy.h?rev=256312&r1=256311&r2=256312&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GCStrategy.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GCStrategy.h Tue Dec 22 19:42:15 2015
@@ -117,11 +117,11 @@ public:
   /** @name Statepoint Specific Properties */
   ///@{
 
-  /// If the value specified can be reliably distinguished, returns true for
+  /// If the type specified can be reliably distinguished, returns true for
   /// pointers to GC managed locations and false for pointers to non-GC
   /// managed locations.  Note a GCStrategy can always return 'None' (i.e. an
   /// empty optional indicating it can't reliably distinguish.
-  virtual Optional<bool> isGCManagedPointer(const Value *V) const {
+  virtual Optional<bool> isGCManagedPointer(const Type *Ty) const {
     return None;
   }
   ///@}

Modified: llvm/trunk/lib/CodeGen/CoreCLRGC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/CoreCLRGC.cpp?rev=256312&r1=256311&r2=256312&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/CoreCLRGC.cpp (original)
+++ llvm/trunk/lib/CodeGen/CoreCLRGC.cpp Tue Dec 22 19:42:15 2015
@@ -38,9 +38,9 @@ public:
     UsesMetadata = false;
     CustomRoots = false;
   }
-  Optional<bool> isGCManagedPointer(const Value *V) const override {
+  Optional<bool> isGCManagedPointer(const Type *Ty) const override {
     // Method is only valid on pointer typed values.
-    PointerType *PT = cast<PointerType>(V->getType());
+    const PointerType *PT = cast<PointerType>(Ty);
     // We pick addrspace(1) as our GC managed heap.
     return (1 == PT->getAddressSpace());
   }

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/StatepointLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/StatepointLowering.cpp?rev=256312&r1=256311&r2=256312&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/StatepointLowering.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/StatepointLowering.cpp Tue Dec 22 19:42:15 2015
@@ -509,21 +509,21 @@ static void lowerStatepointMetaArgs(Smal
   // to the GCStrategy from there (yet).
   GCStrategy &S = Builder.GFI->getStrategy();
   for (const Value *V : Bases) {
-    auto Opt = S.isGCManagedPointer(V);
+    auto Opt = S.isGCManagedPointer(V->getType());
     if (Opt.hasValue()) {
       assert(Opt.getValue() &&
              "non gc managed base pointer found in statepoint");
     }
   }
   for (const Value *V : Ptrs) {
-    auto Opt = S.isGCManagedPointer(V);
+    auto Opt = S.isGCManagedPointer(V->getType());
     if (Opt.hasValue()) {
       assert(Opt.getValue() &&
              "non gc managed derived pointer found in statepoint");
     }
   }
   for (const Value *V : Relocations) {
-    auto Opt = S.isGCManagedPointer(V);
+    auto Opt = S.isGCManagedPointer(V->getType());
     if (Opt.hasValue()) {
       assert(Opt.getValue() && "non gc managed pointer relocated");
     }

Modified: llvm/trunk/lib/CodeGen/StatepointExampleGC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/StatepointExampleGC.cpp?rev=256312&r1=256311&r2=256312&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/StatepointExampleGC.cpp (original)
+++ llvm/trunk/lib/CodeGen/StatepointExampleGC.cpp Tue Dec 22 19:42:15 2015
@@ -34,9 +34,9 @@ public:
     UsesMetadata = false;
     CustomRoots = false;
   }
-  Optional<bool> isGCManagedPointer(const Value *V) const override {
+  Optional<bool> isGCManagedPointer(const Type *Ty) const override {
     // Method is only valid on pointer typed values.
-    PointerType *PT = cast<PointerType>(V->getType());
+    const PointerType *PT = cast<PointerType>(Ty);
     // For the sake of this example GC, we arbitrarily pick addrspace(1) as our
     // GC managed heap.  We know that a pointer into this heap needs to be
     // updated and that no other pointer does.  Note that addrspace(1) is used

Modified: llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp?rev=256312&r1=256311&r2=256312&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp Tue Dec 22 19:42:15 2015
@@ -215,7 +215,7 @@ static void findLiveSetAtInst(Instructio
                               StatepointLiveSetTy &out);
 
 // TODO: Once we can get to the GCStrategy, this becomes
-// Optional<bool> isGCManagedPointer(const Value *V) const override {
+// Optional<bool> isGCManagedPointer(const Type *Ty) const override {
 
 static bool isGCPointerType(Type *T) {
   if (auto *PT = dyn_cast<PointerType>(T))




More information about the llvm-commits mailing list