[Statepoints] Support for "patchable" statepoints.

Summary:
This change adds two new parameters to the statepoint intrinsic, `i64 id`
and `i32 num_patch_bytes`.  `id` gets propagated to the ID field
in the generated StackMap section.  If the `num_patch_bytes` is
non-zero then the statepoint is lowered to `num_patch_bytes` bytes of
nops instead of a call (the spill and reload code remains unchanged).
A non-zero `num_patch_bytes` is useful in situations where a language
runtime requires complete control over how a call is lowered.

This change brings statepoints one step closer to patchpoints.  With
some additional work (that is not part of this patch) it should be
possible to get rid of `TargetOpcode::STATEPOINT` altogether.

PlaceSafepoints generates `statepoint` wrappers with `id` set to
`0xABCDEF00` (the old default value for the ID reported in the stackmap)
and `num_patch_bytes` set to `0`.  This can be made more sophisticated
later.

Reviewers: reames, pgavlin, swaroop.sridhar, AndyAyers

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D9546

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237214 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Sanjoy Das
2015-05-12 23:52:24 +00:00
parent 36cb3ce66a
commit ead2d1fbe0
53 changed files with 504 additions and 368 deletions

View File

@@ -85,8 +85,8 @@ public:
/// MI-level Statepoint operands
///
/// Statepoint operands take the form:
/// <num call arguments>, <call target>, [call arguments],
/// <StackMaps::ConstantOp>, <calling convention>,
/// <id>, <num patch bytes >, <num call arguments>, <call target>,
/// [call arguments], <StackMaps::ConstantOp>, <calling convention>,
/// <StackMaps::ConstantOp>, <statepoint flags>,
/// <StackMaps::ConstantOp>, <num other args>, [other args],
/// [gc values]
@@ -94,10 +94,7 @@ class StatepointOpers {
private:
// These values are aboolute offsets into the operands of the statepoint
// instruction.
enum {
NCallArgsPos = 0,
CallTargetPos = 1
};
enum { IDPos, NBytesPos, NCallArgsPos, CallTargetPos, MetaEnd };
// These values are relative offests from the start of the statepoint meta
// arguments (i.e. the end of the call arguments).
@@ -114,20 +111,15 @@ public:
/// Get starting index of non call related arguments
/// (calling convention, statepoint flags, vm state and gc state).
unsigned getVarIdx() const {
return MI->getOperand(NCallArgsPos).getImm() + 2;
return MI->getOperand(NCallArgsPos).getImm() + MetaEnd;
}
/// Returns the index of the operand containing the number of non-gc non-call
/// arguments.
unsigned getNumVMSArgsIdx() const {
return getVarIdx() + NumVMSArgsOffset;
}
/// Return the ID for the given statepoint.
uint64_t getID() const { return MI->getOperand(IDPos).getImm(); }
/// Returns the number of non-gc non-call arguments attached to the
/// statepoint. Note that this is the number of arguments, not the number of
/// operands required to represent those arguments.
unsigned getNumVMSArgs() const {
return MI->getOperand(getNumVMSArgsIdx()).getImm();
/// Return the number of patchable bytes the given statepoint should emit.
uint32_t getNumPatchBytes() const {
return MI->getOperand(NBytesPos).getImm();
}
/// Returns the target of the underlying call.

View File

@@ -447,7 +447,8 @@ public:
/// \brief Create a call to the experimental.gc.statepoint intrinsic to
/// start a new statepoint sequence.
CallInst *CreateGCStatepointCall(Value *ActualCallee,
CallInst *CreateGCStatepointCall(uint64_t ID, uint32_t NumPatchBytes,
Value *ActualCallee,
ArrayRef<Value *> CallArgs,
ArrayRef<Value *> DeoptArgs,
ArrayRef<Value *> GCArgs,
@@ -456,7 +457,8 @@ public:
// \brief Conveninence function for the common case when CallArgs are filled
// in using makeArrayRef(CS.arg_begin(), CS.arg_end()); Use needs to be
// .get()'ed to get the Value pointer.
CallInst *CreateGCStatepointCall(Value *ActualCallee, ArrayRef<Use> CallArgs,
CallInst *CreateGCStatepointCall(uint64_t ID, uint32_t NumPatchBytes,
Value *ActualCallee, ArrayRef<Use> CallArgs,
ArrayRef<Value *> DeoptArgs,
ArrayRef<Value *> GCArgs,
const Twine &Name = "");
@@ -464,7 +466,8 @@ public:
/// brief Create an invoke to the experimental.gc.statepoint intrinsic to
/// start a new statepoint sequence.
InvokeInst *
CreateGCStatepointInvoke(Value *ActualInvokee, BasicBlock *NormalDest,
CreateGCStatepointInvoke(uint64_t ID, uint32_t NumPatchBytes,
Value *ActualInvokee, BasicBlock *NormalDest,
BasicBlock *UnwindDest, ArrayRef<Value *> InvokeArgs,
ArrayRef<Value *> DeoptArgs,
ArrayRef<Value *> GCArgs, const Twine &Name = "");
@@ -473,7 +476,8 @@ public:
// makeArrayRef(CS.arg_begin(), CS.arg_end()); Use needs to be .get()'ed to
// get the Value *.
InvokeInst *
CreateGCStatepointInvoke(Value *ActualInvokee, BasicBlock *NormalDest,
CreateGCStatepointInvoke(uint64_t ID, uint32_t NumPatchBytes,
Value *ActualInvokee, BasicBlock *NormalDest,
BasicBlock *UnwindDest, ArrayRef<Use> InvokeArgs,
ArrayRef<Value *> DeoptArgs,
ArrayRef<Value *> GCArgs, const Twine &Name = "");

View File

@@ -528,7 +528,8 @@ def int_experimental_patchpoint_i64 : Intrinsic<[llvm_i64_ty],
// These are documented in docs/Statepoint.rst
def int_experimental_gc_statepoint : Intrinsic<[llvm_i32_ty],
[llvm_anyptr_ty, llvm_i32_ty,
[llvm_i64_ty, llvm_i32_ty,
llvm_anyptr_ty, llvm_i32_ty,
llvm_i32_ty, llvm_vararg_ty]>;
def int_experimental_gc_result : Intrinsic<[llvm_any_ty], [llvm_i32_ty]>;

View File

@@ -74,16 +74,35 @@ public:
typedef typename CallSiteTy::arg_iterator arg_iterator;
enum {
ActualCalleePos = 0,
NumCallArgsPos = 1,
CallArgsBeginPos = 3,
IDPos = 0,
NumPatchBytesPos = 1,
ActualCalleePos = 2,
NumCallArgsPos = 3,
FlagsPos = 4,
CallArgsBeginPos = 5,
};
/// Return the underlying CallSite.
CallSiteTy getCallSite() { return StatepointCS; }
uint64_t getFlags() const {
return cast<ConstantInt>(StatepointCS.getArgument(2))->getZExtValue();
return cast<ConstantInt>(StatepointCS.getArgument(FlagsPos))
->getZExtValue();
}
/// Return the ID associated with this statepoint.
uint64_t getID() {
const Value *IDVal = StatepointCS.getArgument(IDPos);
return cast<ConstantInt>(IDVal)->getZExtValue();
}
/// Return the number of patchable bytes associated with this statepoint.
uint32_t getNumPatchBytes() {
const Value *NumPatchBytesVal = StatepointCS.getArgument(NumPatchBytesPos);
uint64_t NumPatchBytes =
cast<ConstantInt>(NumPatchBytesVal)->getZExtValue();
assert(isInt<32>(NumPatchBytes) && "should fit in 32 bits!");
return NumPatchBytes;
}
/// Return the value actually being called or invoked.