[Statepoints] Clean up statepoint argument accessors.
authorPat Gavlin <pagavlin@microsoft.com>
Tue, 12 May 2015 21:33:48 +0000 (21:33 +0000)
committerPat Gavlin <pagavlin@microsoft.com>
Tue, 12 May 2015 21:33:48 +0000 (21:33 +0000)
Differential Revision: http://reviews.llvm.org/D9622

llvm-svn: 237191

llvm/include/llvm/IR/Statepoint.h
llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp

index d6b722c..57ae90f 100644 (file)
@@ -110,9 +110,9 @@ public:
     return StatepointCS.arg_begin() + CallArgsBeginPos;
   }
   typename CallSiteTy::arg_iterator call_args_end() {
-    int Offset = CallArgsBeginPos + getNumCallArgs();
-    assert(Offset <= (int)StatepointCS.arg_size());
-    return StatepointCS.arg_begin() + Offset;
+    auto I = call_args_begin() + getNumCallArgs();
+    assert((StatepointCS.arg_end() - I) >= 0);
+    return I;
   }
 
   /// range adapter for call arguments
@@ -122,19 +122,18 @@ public:
 
   /// Number of GC transition args.
   int getNumTotalGCTransitionArgs() {
-    const Value *NumGCTransitionArgs = *gc_transition_args_begin();
+    const Value *NumGCTransitionArgs = *call_args_end();
     return cast<ConstantInt>(NumGCTransitionArgs)->getZExtValue();
   }
   typename CallSiteTy::arg_iterator gc_transition_args_begin() {
-    int Offset = call_args_end() - StatepointCS.arg_begin();
-    assert(Offset <= (int)StatepointCS.arg_size());
-    return StatepointCS.arg_begin() + Offset;
+    auto I = call_args_end() + 1;
+    assert((StatepointCS.arg_end() - I) >= 0);
+    return I;
   }
   typename CallSiteTy::arg_iterator gc_transition_args_end() {
-    int Offset = (gc_transition_args_begin() + 1 +
-                  getNumTotalGCTransitionArgs()) - StatepointCS.arg_begin();
-    assert(Offset <= (int)StatepointCS.arg_size());
-    return StatepointCS.arg_begin() + Offset;
+    auto I = gc_transition_args_begin() + getNumTotalGCTransitionArgs();
+    assert((StatepointCS.arg_end() - I) >= 0);
+    return I;
   }
 
   /// range adapter for GC transition arguments
@@ -146,18 +145,19 @@ public:
   /// Number of additional arguments excluding those intended
   /// for garbage collection.
   int getNumTotalVMSArgs() {
-    Value *NumVMSArgs = *vm_state_begin();
+    const Value *NumVMSArgs = *gc_transition_args_end();
     return cast<ConstantInt>(NumVMSArgs)->getZExtValue();
   }
 
   typename CallSiteTy::arg_iterator vm_state_begin() {
-    return gc_transition_args_end();
+    auto I = gc_transition_args_end() + 1;
+    assert((StatepointCS.arg_end() - I) >= 0);
+    return I;
   }
   typename CallSiteTy::arg_iterator vm_state_end() {
-    int Offset = (gc_transition_args_end() + 1 + getNumTotalVMSArgs()) -
-                 StatepointCS.arg_begin();
-    assert(Offset <= (int)StatepointCS.arg_size());
-    return StatepointCS.arg_begin() + Offset;
+    auto I = vm_state_begin() + getNumTotalVMSArgs();
+    assert((StatepointCS.arg_end() - I) >= 0);
+    return I;
   }
 
   /// range adapter for vm state arguments
index 86fbc63..29f4b0a 100644 (file)
@@ -469,10 +469,7 @@ static void lowerStatepointMetaArgs(SmallVectorImpl<SDValue> &Ops,
   // particular value.  This is purely an optimization over the code below and
   // doesn't change semantics at all.  It is important for performance that we
   // reserve slots for both deopt and gc values before lowering either.
-  for (auto I = StatepointSite.vm_state_begin() + 1,
-            E = StatepointSite.vm_state_end();
-       I != E; ++I) {
-    Value *V = *I;
+  for (const Value *V : StatepointSite.vm_state_args()) {
     SDValue Incoming = Builder.getValue(V);
     reservePreviousStackSlotForValue(Incoming, Builder);
   }
@@ -490,8 +487,8 @@ static void lowerStatepointMetaArgs(SmallVectorImpl<SDValue> &Ops,
   const int NumVMSArgs = StatepointSite.getNumTotalVMSArgs();
   pushStackMapConstant(Ops, Builder, NumVMSArgs);
 
-  assert(NumVMSArgs + 1 == std::distance(StatepointSite.vm_state_begin(),
-                                         StatepointSite.vm_state_end()));
+  assert(NumVMSArgs == std::distance(StatepointSite.vm_state_begin(),
+                                     StatepointSite.vm_state_end()));
 
   // The vm state arguments are lowered in an opaque manner.  We do
   // not know what type of values are contained within.  We skip the
@@ -499,10 +496,7 @@ static void lowerStatepointMetaArgs(SmallVectorImpl<SDValue> &Ops,
   // explicitly just above.  We could have left it in the loop and
   // not done it explicitly, but it's far easier to understand this
   // way.
-  for (auto I = StatepointSite.vm_state_begin() + 1,
-            E = StatepointSite.vm_state_end();
-       I != E; ++I) {
-    const Value *V = *I;
+  for (const Value *V : StatepointSite.vm_state_args()) {
     SDValue Incoming = Builder.getValue(V);
     lowerIncomingStatepointValue(Incoming, Ops, Builder);
   }
@@ -621,12 +615,10 @@ void SelectionDAGBuilder::LowerStatepoint(
     TSOps.push_back(Chain);
 
     // Add GC transition arguments
-    for (auto I = ISP.gc_transition_args_begin() + 1,
-              E = ISP.gc_transition_args_end();
-         I != E; ++I) {
-      TSOps.push_back(getValue(*I));
-      if ((*I)->getType()->isPointerTy())
-        TSOps.push_back(DAG.getSrcValue(*I));
+    for (const Value *V : ISP.gc_transition_args()) {
+      TSOps.push_back(getValue(V));
+      if (V->getType()->isPointerTy())
+        TSOps.push_back(DAG.getSrcValue(V));
     }
 
     // Add glue if necessary
@@ -704,12 +696,10 @@ void SelectionDAGBuilder::LowerStatepoint(
     TEOps.push_back(SDValue(StatepointMCNode, 0));
 
     // Add GC transition arguments
-    for (auto I = ISP.gc_transition_args_begin() + 1,
-              E = ISP.gc_transition_args_end();
-         I != E; ++I) {
-      TEOps.push_back(getValue(*I));
-      if ((*I)->getType()->isPointerTy())
-        TEOps.push_back(DAG.getSrcValue(*I));
+    for (const Value *V : ISP.gc_transition_args()) {
+      TEOps.push_back(getValue(V));
+      if (V->getType()->isPointerTy())
+        TEOps.push_back(DAG.getSrcValue(V));
     }
 
     // Add glue