[llvm] r249779 - [RS4GC] Refactoring to make a later change easier, NFCI
Sanjoy Das via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 8 16:18:38 PDT 2015
Author: sanjoy
Date: Thu Oct 8 18:18:38 2015
New Revision: 249779
URL: http://llvm.org/viewvc/llvm-project?rev=249779&view=rev
Log:
[RS4GC] Refactoring to make a later change easier, NFCI
Summary:
These non-semantic changes will help make a later change adding
support for deopt operand bundles more streamlined.
Reviewers: reames, swaroop.sridhar
Subscribers: sanjoy, llvm-commits
Differential Revision: http://reviews.llvm.org/D13491
Modified:
llvm/trunk/include/llvm/IR/Statepoint.h
llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
llvm/trunk/test/Transforms/RewriteStatepointsForGC/relocation.ll
Modified: llvm/trunk/include/llvm/IR/Statepoint.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Statepoint.h?rev=249779&r1=249778&r2=249779&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Statepoint.h (original)
+++ llvm/trunk/include/llvm/IR/Statepoint.h Thu Oct 8 18:18:38 2015
@@ -235,6 +235,10 @@ public:
return getCallSite().arg_end();
}
+ unsigned gcArgsStartIdx() const {
+ return gc_args_begin() - getInstruction()->op_begin();
+ }
+
/// range adapter for gc arguments
iterator_range<arg_iterator> gc_args() const {
return iterator_range<arg_iterator>(gc_args_begin(), gc_args_end());
Modified: llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp?rev=249779&r1=249778&r2=249779&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp Thu Oct 8 18:18:38 2015
@@ -1339,10 +1339,6 @@ makeStatepointExplicitImpl(const CallSit
assert(isStatepoint(CS) &&
"This method expects to be rewriting a statepoint");
- // We're not changing the function signature of the statepoint since the gc
- // arguments go into the var args section.
- Function *GCStatepointDecl = CS.getCalledFunction();
-
// Then go ahead and use the builder do actually do the inserts. We insert
// immediately before the previous instruction under the assumption that all
// arguments will be available here. We can't insert afterwards since we may
@@ -1350,24 +1346,28 @@ makeStatepointExplicitImpl(const CallSit
Instruction *InsertBefore = CS.getInstruction();
IRBuilder<> Builder(InsertBefore);
- // Copy all of the arguments from the original statepoint - this includes the
- // target, call args, and deopt args
- SmallVector<llvm::Value *, 64> Args;
- Args.insert(Args.end(), CS.arg_begin(), CS.arg_end());
- // TODO: Clear the 'needs rewrite' flag
-
- // Add all the pointers to be relocated (gc arguments) and capture the start
- // of the live variable list for use in the gc_relocates
- const int LiveStartIdx = Args.size();
- Args.insert(Args.end(), LiveVariables.begin(), LiveVariables.end());
+ Statepoint OldSP(CS);
+
+ ArrayRef<Value *> GCArgs(LiveVariables);
+ uint64_t StatepointID = OldSP.getID();
+ uint32_t NumPatchBytes = OldSP.getNumPatchBytes();
+ uint32_t Flags = OldSP.getFlags();
+
+ ArrayRef<Use> CallArgs(OldSP.arg_begin(), OldSP.arg_end());
+ ArrayRef<Use> DeoptArgs(OldSP.vm_state_begin(), OldSP.vm_state_end());
+ ArrayRef<Use> TransitionArgs(OldSP.gc_transition_args_begin(),
+ OldSP.gc_transition_args_end());
+ Value *CallTarget = OldSP.getCalledValue();
// Create the statepoint given all the arguments
Instruction *Token = nullptr;
AttributeSet ReturnAttrs;
if (CS.isCall()) {
CallInst *ToReplace = cast<CallInst>(CS.getInstruction());
- CallInst *Call =
- Builder.CreateCall(GCStatepointDecl, Args, "safepoint_token");
+ CallInst *Call = Builder.CreateGCStatepointCall(
+ StatepointID, NumPatchBytes, CallTarget, Flags, CallArgs,
+ TransitionArgs, DeoptArgs, GCArgs, "safepoint_token");
+
Call->setTailCall(ToReplace->isTailCall());
Call->setCallingConv(ToReplace->getCallingConv());
@@ -1392,10 +1392,11 @@ makeStatepointExplicitImpl(const CallSit
// Insert the new invoke into the old block. We'll remove the old one in a
// moment at which point this will become the new terminator for the
// original block.
- InvokeInst *Invoke =
- InvokeInst::Create(GCStatepointDecl, ToReplace->getNormalDest(),
- ToReplace->getUnwindDest(), Args, "statepoint_token",
- ToReplace->getParent());
+ InvokeInst *Invoke = Builder.CreateGCStatepointInvoke(
+ StatepointID, NumPatchBytes, CallTarget, ToReplace->getNormalDest(),
+ ToReplace->getUnwindDest(), Flags, CallArgs, TransitionArgs, DeoptArgs,
+ GCArgs, "statepoint_token");
+
Invoke->setCallingConv(ToReplace->getCallingConv());
// Currently we will fail on parameter attributes and on certain
@@ -1424,6 +1425,7 @@ makeStatepointExplicitImpl(const CallSit
UnwindBlock->getLandingPadInst(), 1, "relocate_token"));
Result.UnwindToken = ExceptionalToken;
+ const unsigned LiveStartIdx = Statepoint(Token).gcArgsStartIdx();
CreateGCRelocates(LiveVariables, LiveStartIdx, BasePtrs, ExceptionalToken,
Builder);
@@ -1460,6 +1462,7 @@ makeStatepointExplicitImpl(const CallSit
Result.StatepointToken = Token;
// Second, create a gc.relocate for every live variable
+ const unsigned LiveStartIdx = Statepoint(Token).gcArgsStartIdx();
CreateGCRelocates(LiveVariables, LiveStartIdx, BasePtrs, Token, Builder);
}
Modified: llvm/trunk/test/Transforms/RewriteStatepointsForGC/relocation.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/RewriteStatepointsForGC/relocation.ll?rev=249779&r1=249778&r2=249779&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/RewriteStatepointsForGC/relocation.ll (original)
+++ llvm/trunk/test/Transforms/RewriteStatepointsForGC/relocation.ll Thu Oct 8 18:18:38 2015
@@ -94,7 +94,7 @@ join:
; CHECK-LABEL: join:
; CHECK: phi i8 addrspace(1)*
; CHECK-DAG: [ %arg.relocated, %if_branch ]
-; CHECK-DAG: [ %arg.relocated4, %else_branch ]
+; CHECK-DAG: [ %arg.relocated3, %else_branch ]
; CHECK-NOT: phi
call void (i8 addrspace(1)*) @some_call(i8 addrspace(1)* %arg)
ret void
More information about the llvm-commits
mailing list