[llvm] 501aa47 - [Statepoint] Sink logic about actual callee into GCStatepointInst

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Thu May 28 10:53:46 PDT 2020


Author: Philip Reames
Date: 2020-05-28T10:53:39-07:00
New Revision: 501aa47ab8fa62f5be1e41bee6d5b8fbd1fa6627

URL: https://github.com/llvm/llvm-project/commit/501aa47ab8fa62f5be1e41bee6d5b8fbd1fa6627
DIFF: https://github.com/llvm/llvm-project/commit/501aa47ab8fa62f5be1e41bee6d5b8fbd1fa6627.diff

LOG: [Statepoint] Sink logic about actual callee into GCStatepointInst

Sinking logic around actual callee from Statepoint to GCStatepointInst.  While doing so, adjust naming to be consistent about refering to "actual" callee and follow precedent on naming from CallBase otherwise.

Use the result to simplify one consumer.  This is mostly just to ensure the new code is exercised, but is also a helpful cleanup on it's own.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/Statepoint.h b/llvm/include/llvm/IR/Statepoint.h
index 34eb1126b373..ce3d5a655df8 100644
--- a/llvm/include/llvm/IR/Statepoint.h
+++ b/llvm/include/llvm/IR/Statepoint.h
@@ -115,6 +115,25 @@ class GCStatepointInst : public CallBase {
   uint64_t getFlags() const {
     return cast<ConstantInt>(getArgOperand(FlagsPos))->getZExtValue();
   }
+
+  /// Return the value actually being called or invoked.
+  Value *getActualCalledOperand() const {
+    return getArgOperand(CalledFunctionPos);
+  }
+
+  /// Returns the function called if this is a wrapping a direct call, and null
+  /// otherwise.
+  Function *getActualCalledFunction() const {
+    return dyn_cast_or_null<Function>(getActualCalledOperand());
+  }
+
+  /// Return the type of the value returned by the call underlying the
+  /// statepoint.
+  Type *getActualReturnType() const {
+    auto *CalleeTy =
+      cast<PointerType>(getActualCalledOperand()->getType())->getElementType();
+    return cast<FunctionType>(CalleeTy)->getReturnType();
+  }
 };
 
 /// A wrapper around a GC intrinsic call, this provides most of the actual
@@ -139,7 +158,6 @@ class StatepointBase {
   using arg_iterator = typename CallTy::const_op_iterator;
 
   enum {
-    CalledFunctionPos = GCStatepointInst::CalledFunctionPos,
     CallArgsBeginPos = GCStatepointInst::CallArgsBeginPos,
   };
 
@@ -162,22 +180,18 @@ class StatepointBase {
   uint64_t getID() const { return getCall()->getID(); }
   uint32_t getNumPatchBytes() const { return getCall()->getNumPatchBytes(); }
   int getNumCallArgs() const { return getCall()->getNumCallArgs(); }
-
-
-  /// Return the value actually being called or invoked.
   ValueTy *getCalledValue() const {
-    return getCall()->getArgOperand(CalledFunctionPos);
+    return getCall()->getActualCalledOperand();
+  }
+  Type *getActualReturnType() const { return getCall()->getActualReturnType(); }
+  FunTy *getCalledFunction() const {
+    return getCall()->getActualCalledFunction();
   }
 
+  
   // FIXME: Migrate users of this to `getCall` and remove it.
   InstructionTy *getInstruction() const { return getCall(); }
 
-  /// Return the function being called if this is a direct call, otherwise
-  /// return null (if it's an indirect call).
-  FunTy *getCalledFunction() const {
-    return dyn_cast<Function>(getCalledValue());
-  }
-
   /// Return the caller function for this statepoint.
   FunTy *getCaller() const { return getCall()->getCaller(); }
 
@@ -187,13 +201,6 @@ class StatepointBase {
     return getCall()->doesNotThrow() || (F ? F->doesNotThrow() : false);
   }
 
-  /// Return the type of the value returned by the call underlying the
-  /// statepoint.
-  Type *getActualReturnType() const {
-    auto *FTy = cast<FunctionType>(
-        cast<PointerType>(getCalledValue()->getType())->getElementType());
-    return FTy->getReturnType();
-  }
 
   size_t arg_size() const { return getNumCallArgs(); }
   arg_iterator arg_begin() const {

diff  --git a/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp
index acb68405470c..664f56523d9b 100644
--- a/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp
@@ -822,7 +822,7 @@ SelectionDAGBuilder::LowerStatepoint(const GCStatepointInst &I,
 #endif
 
   SDValue ActualCallee;
-  SDValue Callee = getValue(ISP.getCalledValue());
+  SDValue Callee = getValue(I.getActualCalledOperand());
 
   if (I.getNumPatchBytes() > 0) {
     // If we've been asked to emit a nop sequence instead of a call instruction
@@ -838,7 +838,7 @@ SelectionDAGBuilder::LowerStatepoint(const GCStatepointInst &I,
   StatepointLoweringInfo SI(DAG);
   populateCallLoweringInfo(SI.CLI, &I, GCStatepointInst::CallArgsBeginPos,
                            I.getNumCallArgs(), ActualCallee,
-                           ISP.getActualReturnType(), false /* IsPatchPoint */);
+                           I.getActualReturnType(), false /* IsPatchPoint */);
 
   // There may be duplication in the gc.relocate list; such as two copies of
   // each relocation on normal and exceptional path for an invoke.  We only
@@ -894,7 +894,7 @@ SelectionDAGBuilder::LowerStatepoint(const GCStatepointInst &I,
 
   // Export the result value if needed
   const GCResultInst *GCResult = ISP.getGCResult();
-  Type *RetTy = ISP.getActualReturnType();
+  Type *RetTy = I.getActualReturnType();
   if (!RetTy->isVoidTy() && GCResult) {
     if (GCResult->getParent() != I.getParent()) {
       // Result value will be used in a 
diff erent basic block so we need to
@@ -979,10 +979,7 @@ void SelectionDAGBuilder::visitGCResult(const GCResultInst &CI) {
     // register because statepoint and actual call return types can be
     // 
diff erent, and getValue() will use CopyFromReg of the wrong type,
     // which is always i32 in our case.
-    PointerType *CalleeType = cast<PointerType>(
-        ImmutableStatepoint(I).getCalledValue()->getType());
-    Type *RetTy =
-        cast<FunctionType>(CalleeType->getElementType())->getReturnType();
+    Type *RetTy = cast<GCStatepointInst>(I)->getActualReturnType();
     SDValue CopyFromReg = getCopyFromRegs(I, RetTy);
 
     assert(CopyFromReg.getNode());


        


More information about the llvm-commits mailing list