[Statepoint] Clean up Statepoint.h: accessor names.

Use getFoo() as accessors consistently and some other naming changes.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@236564 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Sanjoy Das
2015-05-06 02:36:26 +00:00
parent d77522093e
commit 1df2d64d55
8 changed files with 73 additions and 69 deletions

View File

@@ -69,24 +69,26 @@ class StatepointBase {
} }
/// Return the value actually being called or invoked. /// Return the value actually being called or invoked.
ValueTy *actualCallee() { ValueTy *getActualCallee() { return StatepointCS.getArgument(0); }
return StatepointCS.getArgument(0);
}
/// Return the type of the value returned by the call underlying the /// Return the type of the value returned by the call underlying the
/// statepoint. /// statepoint.
Type *actualReturnType() { Type *getActualReturnType() {
auto *FTy = cast<FunctionType>( auto *FTy = cast<FunctionType>(
cast<PointerType>(actualCallee()->getType())->getElementType()); cast<PointerType>(getActualCallee()->getType())->getElementType());
return FTy->getReturnType(); return FTy->getReturnType();
} }
/// Number of arguments to be passed to the actual callee. /// Number of arguments to be passed to the actual callee.
int numCallArgs() { int getNumCallArgs() {
return cast<ConstantInt>(StatepointCS.getArgument(1))->getZExtValue(); return cast<ConstantInt>(StatepointCS.getArgument(1))->getZExtValue();
} }
/// Number of additional arguments excluding those intended /// Number of additional arguments excluding those intended
/// for garbage collection. /// for garbage collection.
int numTotalVMSArgs() { int getNumTotalVMSArgs() {
return cast<ConstantInt>(StatepointCS.getArgument(3 + numCallArgs()))->getZExtValue(); const Value *NumVMSArgs = StatepointCS.getArgument(3 + getNumCallArgs());
return cast<ConstantInt>(NumVMSArgs)->getZExtValue();
} }
int callArgsBeginOffset() { return 3; } int callArgsBeginOffset() { return 3; }
@@ -98,7 +100,7 @@ class StatepointBase {
return StatepointCS.arg_begin() + Offset; return StatepointCS.arg_begin() + Offset;
} }
typename CallSiteTy::arg_iterator call_args_end() { typename CallSiteTy::arg_iterator call_args_end() {
int Offset = callArgsBeginOffset() + numCallArgs(); int Offset = callArgsBeginOffset() + getNumCallArgs();
assert(Offset <= (int)StatepointCS.arg_size()); assert(Offset <= (int)StatepointCS.arg_size());
return StatepointCS.arg_begin() + Offset; return StatepointCS.arg_begin() + Offset;
} }
@@ -112,7 +114,7 @@ class StatepointBase {
return call_args_end(); return call_args_end();
} }
typename CallSiteTy::arg_iterator vm_state_end() { typename CallSiteTy::arg_iterator vm_state_end() {
int Offset = 3 + numCallArgs() + 1 + numTotalVMSArgs(); int Offset = 3 + getNumCallArgs() + 1 + getNumTotalVMSArgs();
assert(Offset <= (int)StatepointCS.arg_size()); assert(Offset <= (int)StatepointCS.arg_size());
return StatepointCS.arg_begin() + Offset; return StatepointCS.arg_begin() + Offset;
} }
@@ -151,7 +153,7 @@ class StatepointBase {
/// include incorrect length prefixes for variable length sections or /// include incorrect length prefixes for variable length sections or
/// illegal values for parameters. /// illegal values for parameters.
void verify() { void verify() {
assert(numCallArgs() >= 0 && assert(getNumCallArgs() >= 0 &&
"number of arguments to actually callee can't be negative"); "number of arguments to actually callee can't be negative");
// The internal asserts in the iterator accessors do the rest. // The internal asserts in the iterator accessors do the rest.
@@ -220,43 +222,48 @@ class GCRelocateOperands {
} }
/// The statepoint with which this gc.relocate is associated. /// The statepoint with which this gc.relocate is associated.
const Instruction *statepoint() { const Instruction *getStatepoint() {
const Value *token = RelocateCS.getArgument(0); const Value *Token = RelocateCS.getArgument(0);
// This takes care both of relocates for call statepoints and relocates // This takes care both of relocates for call statepoints and relocates
// on normal path of invoke statepoint. // on normal path of invoke statepoint.
if (!isa<ExtractValueInst>(token)) { if (!isa<ExtractValueInst>(Token)) {
return cast<Instruction>(token); return cast<Instruction>(Token);
} }
// This relocate is on exceptional path of an invoke statepoint // This relocate is on exceptional path of an invoke statepoint
const BasicBlock *invokeBB = const BasicBlock *InvokeBB =
cast<Instruction>(token)->getParent()->getUniquePredecessor(); cast<Instruction>(Token)->getParent()->getUniquePredecessor();
assert(invokeBB && "safepoints should have unique landingpads"); assert(InvokeBB && "safepoints should have unique landingpads");
assert(invokeBB->getTerminator() && "safepoint block should be well formed"); assert(InvokeBB->getTerminator() &&
assert(isStatepoint(invokeBB->getTerminator())); "safepoint block should be well formed");
assert(isStatepoint(InvokeBB->getTerminator()));
return invokeBB->getTerminator(); return InvokeBB->getTerminator();
} }
/// The index into the associate statepoint's argument list /// The index into the associate statepoint's argument list
/// which contains the base pointer of the pointer whose /// which contains the base pointer of the pointer whose
/// relocation this gc.relocate describes. /// relocation this gc.relocate describes.
unsigned basePtrIndex() { unsigned getBasePtrIndex() {
return cast<ConstantInt>(RelocateCS.getArgument(1))->getZExtValue(); return cast<ConstantInt>(RelocateCS.getArgument(1))->getZExtValue();
} }
/// The index into the associate statepoint's argument list which /// The index into the associate statepoint's argument list which
/// contains the pointer whose relocation this gc.relocate describes. /// contains the pointer whose relocation this gc.relocate describes.
unsigned derivedPtrIndex() { unsigned getDerivedPtrIndex() {
return cast<ConstantInt>(RelocateCS.getArgument(2))->getZExtValue(); return cast<ConstantInt>(RelocateCS.getArgument(2))->getZExtValue();
} }
Value *basePtr() {
ImmutableCallSite CS(statepoint()); Value *getBasePtr() {
return *(CS.arg_begin() + basePtrIndex()); ImmutableCallSite CS(getStatepoint());
return *(CS.arg_begin() + getBasePtrIndex());
} }
Value *derivedPtr() {
ImmutableCallSite CS(statepoint()); Value *getDerivedPtr() {
return *(CS.arg_begin() + derivedPtrIndex()); ImmutableCallSite CS(getStatepoint());
return *(CS.arg_begin() + getDerivedPtrIndex());
} }
}; };
@@ -265,22 +272,19 @@ std::vector<GCRelocateOperands>
StatepointBase<InstructionTy, ValueTy, CallSiteTy>:: StatepointBase<InstructionTy, ValueTy, CallSiteTy>::
getRelocates(ImmutableStatepoint &IS) { getRelocates(ImmutableStatepoint &IS) {
std::vector<GCRelocateOperands> res; std::vector<GCRelocateOperands> Result;
ImmutableCallSite StatepointCS = IS.getCallSite(); ImmutableCallSite StatepointCS = IS.getCallSite();
// Search for relocated pointers. Note that working backwards from the // Search for relocated pointers. Note that working backwards from the
// gc_relocates ensures that we only get pairs which are actually relocated // gc_relocates ensures that we only get pairs which are actually relocated
// and used after the statepoint. // and used after the statepoint.
for (const User *U : StatepointCS.getInstruction()->users()) { for (const User *U : StatepointCS.getInstruction()->users())
if (isGCRelocate(U)) { if (isGCRelocate(U))
res.push_back(GCRelocateOperands(U)); Result.push_back(GCRelocateOperands(U));
}
}
if (!StatepointCS.isInvoke()) { if (!StatepointCS.isInvoke())
return res; return Result;
}
// We need to scan thorough exceptional relocations if it is invoke statepoint // We need to scan thorough exceptional relocations if it is invoke statepoint
LandingPadInst *LandingPad = LandingPadInst *LandingPad =
@@ -289,19 +293,17 @@ std::vector<GCRelocateOperands>
// Search for extract value from landingpad instruction to which // Search for extract value from landingpad instruction to which
// gc relocates will be attached // gc relocates will be attached
for (const User *LandingPadUser : LandingPad->users()) { for (const User *LandingPadUser : LandingPad->users()) {
if (!isa<ExtractValueInst>(LandingPadUser)) { if (!isa<ExtractValueInst>(LandingPadUser))
continue; continue;
}
// gc relocates should be attached to this extract value // gc relocates should be attached to this extract value
for (const User *U : LandingPadUser->users()) { for (const User *U : LandingPadUser->users())
if (isGCRelocate(U)) { if (isGCRelocate(U))
res.push_back(GCRelocateOperands(U)); Result.push_back(GCRelocateOperands(U));
} }
} return Result;
}
return res;
} }
} }
#endif #endif

View File

@@ -2957,7 +2957,8 @@ static bool isDereferenceablePointer(const Value *V, const DataLayout &DL,
if (const IntrinsicInst *I = dyn_cast<IntrinsicInst>(V)) if (const IntrinsicInst *I = dyn_cast<IntrinsicInst>(V))
if (I->getIntrinsicID() == Intrinsic::experimental_gc_relocate) { if (I->getIntrinsicID() == Intrinsic::experimental_gc_relocate) {
GCRelocateOperands RelocateInst(I); GCRelocateOperands RelocateInst(I);
return isDereferenceablePointer(RelocateInst.derivedPtr(), DL, Visited); return isDereferenceablePointer(RelocateInst.getDerivedPtr(), DL,
Visited);
} }
if (const AddrSpaceCastInst *ASC = dyn_cast<AddrSpaceCastInst>(V)) if (const AddrSpaceCastInst *ASC = dyn_cast<AddrSpaceCastInst>(V))

View File

@@ -531,8 +531,8 @@ static void computeBaseDerivedRelocateMap(
for (auto &U : AllRelocateCalls) { for (auto &U : AllRelocateCalls) {
GCRelocateOperands ThisRelocate(U); GCRelocateOperands ThisRelocate(U);
IntrinsicInst *I = cast<IntrinsicInst>(U); IntrinsicInst *I = cast<IntrinsicInst>(U);
auto K = std::make_pair(ThisRelocate.basePtrIndex(), auto K = std::make_pair(ThisRelocate.getBasePtrIndex(),
ThisRelocate.derivedPtrIndex()); ThisRelocate.getDerivedPtrIndex());
RelocateIdxMap.insert(std::make_pair(K, I)); RelocateIdxMap.insert(std::make_pair(K, I));
} }
for (auto &Item : RelocateIdxMap) { for (auto &Item : RelocateIdxMap) {
@@ -581,15 +581,15 @@ simplifyRelocatesOffABase(IntrinsicInst *RelocatedBase,
GCRelocateOperands MasterRelocate(RelocatedBase); GCRelocateOperands MasterRelocate(RelocatedBase);
GCRelocateOperands ThisRelocate(ToReplace); GCRelocateOperands ThisRelocate(ToReplace);
assert(ThisRelocate.basePtrIndex() == MasterRelocate.basePtrIndex() && assert(ThisRelocate.getBasePtrIndex() == MasterRelocate.getBasePtrIndex() &&
"Not relocating a derived object of the original base object"); "Not relocating a derived object of the original base object");
if (ThisRelocate.basePtrIndex() == ThisRelocate.derivedPtrIndex()) { if (ThisRelocate.getBasePtrIndex() == ThisRelocate.getDerivedPtrIndex()) {
// A duplicate relocate call. TODO: coalesce duplicates. // A duplicate relocate call. TODO: coalesce duplicates.
continue; continue;
} }
Value *Base = ThisRelocate.basePtr(); Value *Base = ThisRelocate.getBasePtr();
auto Derived = dyn_cast<GetElementPtrInst>(ThisRelocate.derivedPtr()); auto Derived = dyn_cast<GetElementPtrInst>(ThisRelocate.getDerivedPtr());
if (!Derived || Derived->getPointerOperand() != Base) if (!Derived || Derived->getPointerOperand() != Base)
continue; continue;

View File

@@ -229,7 +229,7 @@ lowerCallFromStatepoint(ImmutableStatepoint ISP, MachineBasicBlock *LandingPad,
ImmutableCallSite CS(ISP.getCallSite()); ImmutableCallSite CS(ISP.getCallSite());
SDValue ActualCallee = Builder.getValue(ISP.actualCallee()); SDValue ActualCallee = Builder.getValue(ISP.getActualCallee());
// Handle immediate and symbolic callees. // Handle immediate and symbolic callees.
if (auto *ConstCallee = dyn_cast<ConstantSDNode>(ActualCallee.getNode())) if (auto *ConstCallee = dyn_cast<ConstantSDNode>(ActualCallee.getNode()))
@@ -245,12 +245,12 @@ lowerCallFromStatepoint(ImmutableStatepoint ISP, MachineBasicBlock *LandingPad,
assert(CS.getCallingConv() != CallingConv::AnyReg && assert(CS.getCallingConv() != CallingConv::AnyReg &&
"anyregcc is not supported on statepoints!"); "anyregcc is not supported on statepoints!");
Type *DefTy = ISP.actualReturnType(); Type *DefTy = ISP.getActualReturnType();
bool HasDef = !DefTy->isVoidTy(); bool HasDef = !DefTy->isVoidTy();
SDValue ReturnValue, CallEndVal; SDValue ReturnValue, CallEndVal;
std::tie(ReturnValue, CallEndVal) = Builder.lowerCallOperands( std::tie(ReturnValue, CallEndVal) = Builder.lowerCallOperands(
ISP.getCallSite(), ISP.callArgsBeginOffset(), ISP.numCallArgs(), ISP.getCallSite(), ISP.callArgsBeginOffset(), ISP.getNumCallArgs(),
ActualCallee, DefTy, LandingPad, false /* IsPatchPoint */); ActualCallee, DefTy, LandingPad, false /* IsPatchPoint */);
SDNode *CallEnd = CallEndVal.getNode(); SDNode *CallEnd = CallEndVal.getNode();
@@ -286,10 +286,10 @@ lowerCallFromStatepoint(ImmutableStatepoint ISP, MachineBasicBlock *LandingPad,
// register with correct type and save value into it manually. // register with correct type and save value into it manually.
// TODO: To eliminate this problem we can remove gc.result intrinsics // TODO: To eliminate this problem we can remove gc.result intrinsics
// completelly and make statepoint call to return a tuple. // completelly and make statepoint call to return a tuple.
unsigned Reg = Builder.FuncInfo.CreateRegs(ISP.actualReturnType()); unsigned Reg = Builder.FuncInfo.CreateRegs(ISP.getActualReturnType());
RegsForValue RFV(*Builder.DAG.getContext(), RegsForValue RFV(*Builder.DAG.getContext(),
Builder.DAG.getTargetLoweringInfo(), Reg, Builder.DAG.getTargetLoweringInfo(), Reg,
ISP.actualReturnType()); ISP.getActualReturnType());
SDValue Chain = Builder.DAG.getEntryNode(); SDValue Chain = Builder.DAG.getEntryNode();
RFV.getCopyToRegs(ReturnValue, Builder.DAG, Builder.getCurSDLoc(), Chain, RFV.getCopyToRegs(ReturnValue, Builder.DAG, Builder.getCurSDLoc(), Chain,
@@ -325,8 +325,8 @@ static void getIncomingStatepointGCValues(
for (GCRelocateOperands relocateOpers : for (GCRelocateOperands relocateOpers :
StatepointSite.getRelocates(StatepointSite)) { StatepointSite.getRelocates(StatepointSite)) {
Relocs.push_back(relocateOpers.getUnderlyingCallSite().getInstruction()); Relocs.push_back(relocateOpers.getUnderlyingCallSite().getInstruction());
Bases.push_back(relocateOpers.basePtr()); Bases.push_back(relocateOpers.getBasePtr());
Ptrs.push_back(relocateOpers.derivedPtr()); Ptrs.push_back(relocateOpers.getDerivedPtr());
} }
// Remove any redundant llvm::Values which map to the same SDValue as another // Remove any redundant llvm::Values which map to the same SDValue as another
@@ -482,7 +482,7 @@ static void lowerStatepointMetaArgs(SmallVectorImpl<SDValue> &Ops,
// First, prefix the list with the number of unique values to be // First, prefix the list with the number of unique values to be
// lowered. Note that this is the number of *Values* not the // lowered. Note that this is the number of *Values* not the
// number of SDValues required to lower them. // number of SDValues required to lower them.
const int NumVMSArgs = StatepointSite.numTotalVMSArgs(); const int NumVMSArgs = StatepointSite.getNumTotalVMSArgs();
Ops.push_back( Builder.DAG.getTargetConstant(StackMaps::ConstantOp, Ops.push_back( Builder.DAG.getTargetConstant(StackMaps::ConstantOp,
Builder.getCurSDLoc(), Builder.getCurSDLoc(),
MVT::i64)); MVT::i64));
@@ -675,7 +675,7 @@ void SelectionDAGBuilder::visitGCResult(const CallInst &CI) {
// different, and getValue() will use CopyFromReg of the wrong type, // different, and getValue() will use CopyFromReg of the wrong type,
// which is always i32 in our case. // which is always i32 in our case.
PointerType *CalleeType = PointerType *CalleeType =
cast<PointerType>(ImmutableStatepoint(I).actualCallee()->getType()); cast<PointerType>(ImmutableStatepoint(I).getActualCallee()->getType());
Type *RetTy = Type *RetTy =
cast<FunctionType>(CalleeType->getElementType())->getReturnType(); cast<FunctionType>(CalleeType->getElementType())->getReturnType();
SDValue CopyFromReg = getCopyFromRegs(I, RetTy); SDValue CopyFromReg = getCopyFromRegs(I, RetTy);
@@ -694,7 +694,7 @@ void SelectionDAGBuilder::visitGCRelocate(const CallInst &CI) {
#endif #endif
GCRelocateOperands relocateOpers(&CI); GCRelocateOperands relocateOpers(&CI);
SDValue SD = getValue(relocateOpers.derivedPtr()); SDValue SD = getValue(relocateOpers.getDerivedPtr());
if (isa<ConstantSDNode>(SD) || isa<FrameIndexSDNode>(SD)) { if (isa<ConstantSDNode>(SD) || isa<FrameIndexSDNode>(SD)) {
// We didn't need to spill these special cases (constants and allocas). // We didn't need to spill these special cases (constants and allocas).

View File

@@ -2654,9 +2654,9 @@ void AssemblyWriter::printGCRelocateComment(const Value &V) {
GCRelocateOperands GCOps(cast<Instruction>(&V)); GCRelocateOperands GCOps(cast<Instruction>(&V));
Out << " ; ("; Out << " ; (";
writeOperand(GCOps.basePtr(), false); writeOperand(GCOps.getBasePtr(), false);
Out << ", "; Out << ", ";
writeOperand(GCOps.derivedPtr(), false); writeOperand(GCOps.getDerivedPtr(), false);
Out << ")"; Out << ")";
} }

View File

@@ -3315,7 +3315,7 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) {
// Verify rest of the relocate arguments // Verify rest of the relocate arguments
GCRelocateOperands ops(&CI); GCRelocateOperands ops(&CI);
ImmutableCallSite StatepointCS(ops.statepoint()); ImmutableCallSite StatepointCS(ops.getStatepoint());
// Both the base and derived must be piped through the safepoint // Both the base and derived must be piped through the safepoint
Value* Base = CI.getArgOperand(1); Value* Base = CI.getArgOperand(1);
@@ -3362,7 +3362,7 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) {
// Assert that the result type matches the type of the relocated pointer // Assert that the result type matches the type of the relocated pointer
GCRelocateOperands Operands(&CI); GCRelocateOperands Operands(&CI);
Assert(Operands.derivedPtr()->getType() == CI.getType(), Assert(Operands.getDerivedPtr()->getType() == CI.getType(),
"gc.relocate: relocating a pointer shouldn't change its type", &CI); "gc.relocate: relocating a pointer shouldn't change its type", &CI);
break; break;
} }

View File

@@ -1196,7 +1196,7 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
// facts about the relocate value, while being careful to // facts about the relocate value, while being careful to
// preserve relocation semantics. // preserve relocation semantics.
GCRelocateOperands Operands(II); GCRelocateOperands Operands(II);
Value *DerivedPtr = Operands.derivedPtr(); Value *DerivedPtr = Operands.getDerivedPtr();
// Remove the relocation if unused, note that this check is required // Remove the relocation if unused, note that this check is required
// to prevent the cases below from looping forever. // to prevent the cases below from looping forever.

View File

@@ -1336,7 +1336,8 @@ insertRelocationStores(iterator_range<Value::user_iterator> gcRelocs,
} }
GCRelocateOperands relocateOperands(relocatedValue); GCRelocateOperands relocateOperands(relocatedValue);
Value *originalValue = const_cast<Value *>(relocateOperands.derivedPtr()); Value *originalValue =
const_cast<Value *>(relocateOperands.getDerivedPtr());
assert(allocaMap.count(originalValue)); assert(allocaMap.count(originalValue));
Value *alloca = allocaMap[originalValue]; Value *alloca = allocaMap[originalValue];