forked from OSchip/llvm-project
Remove getArgumentList() in favor of arg_begin(), args(), etc
Users often call getArgumentList().size(), which is a linear way to get the number of function arguments. arg_size(), on the other hand, is constant time. In general, the fact that arguments are stored in an iplist is an implementation detail, so I've removed it from the Function interface and moved all other users to the argument container APIs (arg_begin(), arg_end(), args(), arg_size()). Reviewed By: chandlerc Differential Revision: https://reviews.llvm.org/D31052 llvm-svn: 298010
This commit is contained in:
parent
c9a392b9dd
commit
45707d4d5a
|
@ -509,22 +509,13 @@ public:
|
||||||
/// Requires that this has no function body.
|
/// Requires that this has no function body.
|
||||||
void stealArgumentListFrom(Function &Src);
|
void stealArgumentListFrom(Function &Src);
|
||||||
|
|
||||||
/// Get the underlying elements of the Function... the basic block list is
|
|
||||||
/// empty for external functions.
|
|
||||||
///
|
|
||||||
const ArgumentListType &getArgumentList() const {
|
|
||||||
CheckLazyArguments();
|
|
||||||
return ArgumentList;
|
|
||||||
}
|
|
||||||
ArgumentListType &getArgumentList() {
|
|
||||||
CheckLazyArguments();
|
|
||||||
return ArgumentList;
|
|
||||||
}
|
|
||||||
|
|
||||||
static ArgumentListType Function::*getSublistAccess(Argument*) {
|
static ArgumentListType Function::*getSublistAccess(Argument*) {
|
||||||
return &Function::ArgumentList;
|
return &Function::ArgumentList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the underlying elements of the Function... the basic block list is
|
||||||
|
/// empty for external functions.
|
||||||
|
///
|
||||||
const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; }
|
const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; }
|
||||||
BasicBlockListType &getBasicBlockList() { return BasicBlocks; }
|
BasicBlockListType &getBasicBlockList() { return BasicBlocks; }
|
||||||
|
|
||||||
|
|
|
@ -8000,7 +8000,7 @@ findArgumentCopyElisionCandidates(const DataLayout &DL,
|
||||||
// entries as we have arguments.
|
// entries as we have arguments.
|
||||||
enum StaticAllocaInfo { Unknown, Clobbered, Elidable };
|
enum StaticAllocaInfo { Unknown, Clobbered, Elidable };
|
||||||
SmallDenseMap<const AllocaInst *, StaticAllocaInfo, 8> StaticAllocas;
|
SmallDenseMap<const AllocaInst *, StaticAllocaInfo, 8> StaticAllocas;
|
||||||
unsigned NumArgs = FuncInfo->Fn->getArgumentList().size();
|
unsigned NumArgs = FuncInfo->Fn->arg_size();
|
||||||
StaticAllocas.reserve(NumArgs * 2);
|
StaticAllocas.reserve(NumArgs * 2);
|
||||||
|
|
||||||
auto GetInfoIfStaticAlloca = [&](const Value *V) -> StaticAllocaInfo * {
|
auto GetInfoIfStaticAlloca = [&](const Value *V) -> StaticAllocaInfo * {
|
||||||
|
|
|
@ -238,7 +238,6 @@ bool AArch64CallLowering::lowerReturn(MachineIRBuilder &MIRBuilder,
|
||||||
bool AArch64CallLowering::lowerFormalArguments(MachineIRBuilder &MIRBuilder,
|
bool AArch64CallLowering::lowerFormalArguments(MachineIRBuilder &MIRBuilder,
|
||||||
const Function &F,
|
const Function &F,
|
||||||
ArrayRef<unsigned> VRegs) const {
|
ArrayRef<unsigned> VRegs) const {
|
||||||
auto &Args = F.getArgumentList();
|
|
||||||
MachineFunction &MF = MIRBuilder.getMF();
|
MachineFunction &MF = MIRBuilder.getMF();
|
||||||
MachineBasicBlock &MBB = MIRBuilder.getMBB();
|
MachineBasicBlock &MBB = MIRBuilder.getMBB();
|
||||||
MachineRegisterInfo &MRI = MF.getRegInfo();
|
MachineRegisterInfo &MRI = MF.getRegInfo();
|
||||||
|
@ -246,7 +245,7 @@ bool AArch64CallLowering::lowerFormalArguments(MachineIRBuilder &MIRBuilder,
|
||||||
|
|
||||||
SmallVector<ArgInfo, 8> SplitArgs;
|
SmallVector<ArgInfo, 8> SplitArgs;
|
||||||
unsigned i = 0;
|
unsigned i = 0;
|
||||||
for (auto &Arg : Args) {
|
for (auto &Arg : F.args()) {
|
||||||
ArgInfo OrigArg{VRegs[i], Arg.getType()};
|
ArgInfo OrigArg{VRegs[i], Arg.getType()};
|
||||||
setArgFlags(OrigArg, i + 1, DL, F);
|
setArgFlags(OrigArg, i + 1, DL, F);
|
||||||
bool Split = false;
|
bool Split = false;
|
||||||
|
|
|
@ -337,8 +337,7 @@ bool ARMCallLowering::lowerFormalArguments(MachineIRBuilder &MIRBuilder,
|
||||||
if (Subtarget->useSoftFloat() || !Subtarget->hasVFP2())
|
if (Subtarget->useSoftFloat() || !Subtarget->hasVFP2())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
auto &Args = F.getArgumentList();
|
for (auto &Arg : F.args())
|
||||||
for (auto &Arg : Args)
|
|
||||||
if (!isSupportedType(DL, TLI, Arg.getType()))
|
if (!isSupportedType(DL, TLI, Arg.getType()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -347,7 +346,7 @@ bool ARMCallLowering::lowerFormalArguments(MachineIRBuilder &MIRBuilder,
|
||||||
|
|
||||||
SmallVector<ArgInfo, 8> ArgInfos;
|
SmallVector<ArgInfo, 8> ArgInfos;
|
||||||
unsigned Idx = 0;
|
unsigned Idx = 0;
|
||||||
for (auto &Arg : Args) {
|
for (auto &Arg : F.args()) {
|
||||||
ArgInfo AInfo(VRegs[Idx], Arg.getType());
|
ArgInfo AInfo(VRegs[Idx], Arg.getType());
|
||||||
setArgFlags(AInfo, Idx + 1, DL, F);
|
setArgFlags(AInfo, Idx + 1, DL, F);
|
||||||
splitToValueTypes(AInfo, ArgInfos, DL, MF.getRegInfo());
|
splitToValueTypes(AInfo, ArgInfos, DL, MF.getRegInfo());
|
||||||
|
|
|
@ -96,7 +96,7 @@ static void BuildSignatureCall(StringRef SymName, BasicBlock &BB, Function &F) {
|
||||||
Value *FunctionName = CreateStringPtr(BB, F.getName());
|
Value *FunctionName = CreateStringPtr(BB, F.getName());
|
||||||
|
|
||||||
Value *Args[] = {FunctionName,
|
Value *Args[] = {FunctionName,
|
||||||
ConstantInt::get(I16, F.getArgumentList().size())};
|
ConstantInt::get(I16, F.arg_size())};
|
||||||
CallInst::Create(Fn, Args, "", &BB);
|
CallInst::Create(Fn, Args, "", &BB);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ static bool needsFPFromSig(Function &F) {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
if (F.arg_size() >=1) {
|
if (F.arg_size() >=1) {
|
||||||
Argument &Arg = F.getArgumentList().front();
|
Argument &Arg = *F.arg_begin();
|
||||||
switch (Arg.getType()->getTypeID()) {
|
switch (Arg.getType()->getTypeID()) {
|
||||||
case Type::FloatTyID:
|
case Type::FloatTyID:
|
||||||
case Type::DoubleTyID:
|
case Type::DoubleTyID:
|
||||||
|
|
|
@ -4111,7 +4111,7 @@ needStackSlotPassParameters(const PPCSubtarget &Subtarget,
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
hasSameArgumentList(const Function *CallerFn, ImmutableCallSite *CS) {
|
hasSameArgumentList(const Function *CallerFn, ImmutableCallSite *CS) {
|
||||||
if (CS->arg_size() != CallerFn->getArgumentList().size())
|
if (CS->arg_size() != CallerFn->arg_size())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ImmutableCallSite::arg_iterator CalleeArgIter = CS->arg_begin();
|
ImmutableCallSite::arg_iterator CalleeArgIter = CS->arg_begin();
|
||||||
|
|
|
@ -179,7 +179,7 @@ bool X86CallLowering::lowerFormalArguments(MachineIRBuilder &MIRBuilder,
|
||||||
|
|
||||||
SmallVector<ArgInfo, 8> SplitArgs;
|
SmallVector<ArgInfo, 8> SplitArgs;
|
||||||
unsigned Idx = 0;
|
unsigned Idx = 0;
|
||||||
for (auto &Arg : F.getArgumentList()) {
|
for (auto &Arg : F.args()) {
|
||||||
ArgInfo OrigArg(VRegs[Idx], Arg.getType());
|
ArgInfo OrigArg(VRegs[Idx], Arg.getType());
|
||||||
setArgFlags(OrigArg, Idx + 1, DL, F);
|
setArgFlags(OrigArg, Idx + 1, DL, F);
|
||||||
LLT Ty = MRI.getType(VRegs[Idx]);
|
LLT Ty = MRI.getType(VRegs[Idx]);
|
||||||
|
|
|
@ -92,7 +92,7 @@ static void removeTailCallAttribute(AllocaInst *Frame, AAResults &AA) {
|
||||||
|
|
||||||
// Given a resume function @f.resume(%f.frame* %frame), returns %f.frame type.
|
// Given a resume function @f.resume(%f.frame* %frame), returns %f.frame type.
|
||||||
static Type *getFrameType(Function *Resume) {
|
static Type *getFrameType(Function *Resume) {
|
||||||
auto *ArgType = Resume->getArgumentList().front().getType();
|
auto *ArgType = Resume->arg_begin()->getType();
|
||||||
return cast<PointerType>(ArgType)->getElementType();
|
return cast<PointerType>(ArgType)->getElementType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -707,7 +707,7 @@ void coro::buildCoroutineFrame(Function &F, Shape &Shape) {
|
||||||
|
|
||||||
// Collect the spills for arguments and other not-materializable values.
|
// Collect the spills for arguments and other not-materializable values.
|
||||||
Spills.clear();
|
Spills.clear();
|
||||||
for (Argument &A : F.getArgumentList())
|
for (Argument &A : F.args())
|
||||||
for (User *U : A.users())
|
for (User *U : A.users())
|
||||||
if (Checker.isDefinitionAcrossSuspend(A, U))
|
if (Checker.isDefinitionAcrossSuspend(A, U))
|
||||||
Spills.emplace_back(&A, U);
|
Spills.emplace_back(&A, U);
|
||||||
|
|
|
@ -223,7 +223,7 @@ static Function *createClone(Function &F, Twine Suffix, coro::Shape &Shape,
|
||||||
// Replace all args with undefs. The buildCoroutineFrame algorithm already
|
// Replace all args with undefs. The buildCoroutineFrame algorithm already
|
||||||
// rewritten access to the args that occurs after suspend points with loads
|
// rewritten access to the args that occurs after suspend points with loads
|
||||||
// and stores to/from the coroutine frame.
|
// and stores to/from the coroutine frame.
|
||||||
for (Argument &A : F.getArgumentList())
|
for (Argument &A : F.args())
|
||||||
VMap[&A] = UndefValue::get(A.getType());
|
VMap[&A] = UndefValue::get(A.getType());
|
||||||
|
|
||||||
SmallVector<ReturnInst *, 4> Returns;
|
SmallVector<ReturnInst *, 4> Returns;
|
||||||
|
@ -264,7 +264,7 @@ static Function *createClone(Function &F, Twine Suffix, coro::Shape &Shape,
|
||||||
IRBuilder<> Builder(&NewF->getEntryBlock().front());
|
IRBuilder<> Builder(&NewF->getEntryBlock().front());
|
||||||
|
|
||||||
// Remap frame pointer.
|
// Remap frame pointer.
|
||||||
Argument *NewFramePtr = &NewF->getArgumentList().front();
|
Argument *NewFramePtr = &*NewF->arg_begin();
|
||||||
Value *OldFramePtr = cast<Value>(VMap[Shape.FramePtr]);
|
Value *OldFramePtr = cast<Value>(VMap[Shape.FramePtr]);
|
||||||
NewFramePtr->takeName(OldFramePtr);
|
NewFramePtr->takeName(OldFramePtr);
|
||||||
OldFramePtr->replaceAllUsesWith(NewFramePtr);
|
OldFramePtr->replaceAllUsesWith(NewFramePtr);
|
||||||
|
|
|
@ -580,8 +580,7 @@ Constant *DataFlowSanitizer::getOrBuildTrampolineFunction(FunctionType *FT,
|
||||||
Function::arg_iterator AI = F->arg_begin(); ++AI;
|
Function::arg_iterator AI = F->arg_begin(); ++AI;
|
||||||
for (unsigned N = FT->getNumParams(); N != 0; ++AI, --N)
|
for (unsigned N = FT->getNumParams(); N != 0; ++AI, --N)
|
||||||
Args.push_back(&*AI);
|
Args.push_back(&*AI);
|
||||||
CallInst *CI =
|
CallInst *CI = CallInst::Create(&*F->arg_begin(), Args, "", BB);
|
||||||
CallInst::Create(&F->getArgumentList().front(), Args, "", BB);
|
|
||||||
ReturnInst *RI;
|
ReturnInst *RI;
|
||||||
if (FT->getReturnType()->isVoidTy())
|
if (FT->getReturnType()->isVoidTy())
|
||||||
RI = ReturnInst::Create(*Ctx, BB);
|
RI = ReturnInst::Create(*Ctx, BB);
|
||||||
|
@ -595,7 +594,7 @@ Constant *DataFlowSanitizer::getOrBuildTrampolineFunction(FunctionType *FT,
|
||||||
DFSanVisitor(DFSF).visitCallInst(*CI);
|
DFSanVisitor(DFSF).visitCallInst(*CI);
|
||||||
if (!FT->getReturnType()->isVoidTy())
|
if (!FT->getReturnType()->isVoidTy())
|
||||||
new StoreInst(DFSF.getShadow(RI->getReturnValue()),
|
new StoreInst(DFSF.getShadow(RI->getReturnValue()),
|
||||||
&F->getArgumentList().back(), RI);
|
&*std::prev(F->arg_end()), RI);
|
||||||
}
|
}
|
||||||
|
|
||||||
return C;
|
return C;
|
||||||
|
@ -906,7 +905,7 @@ Value *DFSanFunction::getShadow(Value *V) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DataFlowSanitizer::IA_Args: {
|
case DataFlowSanitizer::IA_Args: {
|
||||||
unsigned ArgIdx = A->getArgNo() + F->getArgumentList().size() / 2;
|
unsigned ArgIdx = A->getArgNo() + F->arg_size() / 2;
|
||||||
Function::arg_iterator i = F->arg_begin();
|
Function::arg_iterator i = F->arg_begin();
|
||||||
while (ArgIdx--)
|
while (ArgIdx--)
|
||||||
++i;
|
++i;
|
||||||
|
|
|
@ -1603,7 +1603,7 @@ bool llvm::InlineFunction(CallSite CS, InlineFunctionInfo &IFI,
|
||||||
// matches up the formal to the actual argument values.
|
// matches up the formal to the actual argument values.
|
||||||
CallSite::arg_iterator AI = CS.arg_begin();
|
CallSite::arg_iterator AI = CS.arg_begin();
|
||||||
unsigned ArgNo = 0;
|
unsigned ArgNo = 0;
|
||||||
for (Function::const_arg_iterator I = CalledFunc->arg_begin(),
|
for (Function::arg_iterator I = CalledFunc->arg_begin(),
|
||||||
E = CalledFunc->arg_end(); I != E; ++I, ++AI, ++ArgNo) {
|
E = CalledFunc->arg_end(); I != E; ++I, ++AI, ++ArgNo) {
|
||||||
Value *ActualArg = *AI;
|
Value *ActualArg = *AI;
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ TEST(ValueTest, UsedInBasicBlock) {
|
||||||
Function *F = M->getFunction("f");
|
Function *F = M->getFunction("f");
|
||||||
|
|
||||||
EXPECT_FALSE(F->isUsedInBasicBlock(&F->front()));
|
EXPECT_FALSE(F->isUsedInBasicBlock(&F->front()));
|
||||||
EXPECT_TRUE((++F->arg_begin())->isUsedInBasicBlock(&F->front()));
|
EXPECT_TRUE(std::next(F->arg_begin())->isUsedInBasicBlock(&F->front()));
|
||||||
EXPECT_TRUE(F->arg_begin()->isUsedInBasicBlock(&F->front()));
|
EXPECT_TRUE(F->arg_begin()->isUsedInBasicBlock(&F->front()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ TEST(IntegerDivision, SDiv) {
|
||||||
Function *F = Function::Create(FunctionType::get(Builder.getInt32Ty(),
|
Function *F = Function::Create(FunctionType::get(Builder.getInt32Ty(),
|
||||||
ArgTys, false),
|
ArgTys, false),
|
||||||
GlobalValue::ExternalLinkage, "F", &M);
|
GlobalValue::ExternalLinkage, "F", &M);
|
||||||
assert(F->getArgumentList().size() == 2);
|
assert(F->arg_size() == 2);
|
||||||
|
|
||||||
BasicBlock *BB = BasicBlock::Create(C, "", F);
|
BasicBlock *BB = BasicBlock::Create(C, "", F);
|
||||||
Builder.SetInsertPoint(BB);
|
Builder.SetInsertPoint(BB);
|
||||||
|
@ -59,7 +59,7 @@ TEST(IntegerDivision, UDiv) {
|
||||||
Function *F = Function::Create(FunctionType::get(Builder.getInt32Ty(),
|
Function *F = Function::Create(FunctionType::get(Builder.getInt32Ty(),
|
||||||
ArgTys, false),
|
ArgTys, false),
|
||||||
GlobalValue::ExternalLinkage, "F", &M);
|
GlobalValue::ExternalLinkage, "F", &M);
|
||||||
assert(F->getArgumentList().size() == 2);
|
assert(F->arg_size() == 2);
|
||||||
|
|
||||||
BasicBlock *BB = BasicBlock::Create(C, "", F);
|
BasicBlock *BB = BasicBlock::Create(C, "", F);
|
||||||
Builder.SetInsertPoint(BB);
|
Builder.SetInsertPoint(BB);
|
||||||
|
@ -89,7 +89,7 @@ TEST(IntegerDivision, SRem) {
|
||||||
Function *F = Function::Create(FunctionType::get(Builder.getInt32Ty(),
|
Function *F = Function::Create(FunctionType::get(Builder.getInt32Ty(),
|
||||||
ArgTys, false),
|
ArgTys, false),
|
||||||
GlobalValue::ExternalLinkage, "F", &M);
|
GlobalValue::ExternalLinkage, "F", &M);
|
||||||
assert(F->getArgumentList().size() == 2);
|
assert(F->arg_size() == 2);
|
||||||
|
|
||||||
BasicBlock *BB = BasicBlock::Create(C, "", F);
|
BasicBlock *BB = BasicBlock::Create(C, "", F);
|
||||||
Builder.SetInsertPoint(BB);
|
Builder.SetInsertPoint(BB);
|
||||||
|
@ -119,7 +119,7 @@ TEST(IntegerDivision, URem) {
|
||||||
Function *F = Function::Create(FunctionType::get(Builder.getInt32Ty(),
|
Function *F = Function::Create(FunctionType::get(Builder.getInt32Ty(),
|
||||||
ArgTys, false),
|
ArgTys, false),
|
||||||
GlobalValue::ExternalLinkage, "F", &M);
|
GlobalValue::ExternalLinkage, "F", &M);
|
||||||
assert(F->getArgumentList().size() == 2);
|
assert(F->arg_size() == 2);
|
||||||
|
|
||||||
BasicBlock *BB = BasicBlock::Create(C, "", F);
|
BasicBlock *BB = BasicBlock::Create(C, "", F);
|
||||||
Builder.SetInsertPoint(BB);
|
Builder.SetInsertPoint(BB);
|
||||||
|
@ -150,7 +150,7 @@ TEST(IntegerDivision, SDiv64) {
|
||||||
Function *F = Function::Create(FunctionType::get(Builder.getInt64Ty(),
|
Function *F = Function::Create(FunctionType::get(Builder.getInt64Ty(),
|
||||||
ArgTys, false),
|
ArgTys, false),
|
||||||
GlobalValue::ExternalLinkage, "F", &M);
|
GlobalValue::ExternalLinkage, "F", &M);
|
||||||
assert(F->getArgumentList().size() == 2);
|
assert(F->arg_size() == 2);
|
||||||
|
|
||||||
BasicBlock *BB = BasicBlock::Create(C, "", F);
|
BasicBlock *BB = BasicBlock::Create(C, "", F);
|
||||||
Builder.SetInsertPoint(BB);
|
Builder.SetInsertPoint(BB);
|
||||||
|
@ -180,7 +180,7 @@ TEST(IntegerDivision, UDiv64) {
|
||||||
Function *F = Function::Create(FunctionType::get(Builder.getInt64Ty(),
|
Function *F = Function::Create(FunctionType::get(Builder.getInt64Ty(),
|
||||||
ArgTys, false),
|
ArgTys, false),
|
||||||
GlobalValue::ExternalLinkage, "F", &M);
|
GlobalValue::ExternalLinkage, "F", &M);
|
||||||
assert(F->getArgumentList().size() == 2);
|
assert(F->arg_size() == 2);
|
||||||
|
|
||||||
BasicBlock *BB = BasicBlock::Create(C, "", F);
|
BasicBlock *BB = BasicBlock::Create(C, "", F);
|
||||||
Builder.SetInsertPoint(BB);
|
Builder.SetInsertPoint(BB);
|
||||||
|
@ -210,7 +210,7 @@ TEST(IntegerDivision, SRem64) {
|
||||||
Function *F = Function::Create(FunctionType::get(Builder.getInt64Ty(),
|
Function *F = Function::Create(FunctionType::get(Builder.getInt64Ty(),
|
||||||
ArgTys, false),
|
ArgTys, false),
|
||||||
GlobalValue::ExternalLinkage, "F", &M);
|
GlobalValue::ExternalLinkage, "F", &M);
|
||||||
assert(F->getArgumentList().size() == 2);
|
assert(F->arg_size() == 2);
|
||||||
|
|
||||||
BasicBlock *BB = BasicBlock::Create(C, "", F);
|
BasicBlock *BB = BasicBlock::Create(C, "", F);
|
||||||
Builder.SetInsertPoint(BB);
|
Builder.SetInsertPoint(BB);
|
||||||
|
@ -240,7 +240,7 @@ TEST(IntegerDivision, URem64) {
|
||||||
Function *F = Function::Create(FunctionType::get(Builder.getInt64Ty(),
|
Function *F = Function::Create(FunctionType::get(Builder.getInt64Ty(),
|
||||||
ArgTys, false),
|
ArgTys, false),
|
||||||
GlobalValue::ExternalLinkage, "F", &M);
|
GlobalValue::ExternalLinkage, "F", &M);
|
||||||
assert(F->getArgumentList().size() == 2);
|
assert(F->arg_size() == 2);
|
||||||
|
|
||||||
BasicBlock *BB = BasicBlock::Create(C, "", F);
|
BasicBlock *BB = BasicBlock::Create(C, "", F);
|
||||||
Builder.SetInsertPoint(BB);
|
Builder.SetInsertPoint(BB);
|
||||||
|
|
Loading…
Reference in New Issue