llvm.org GIT mirror llvm / 1c19be8
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298010 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 3 years ago
15 changed file(s) with 29 addition(s) and 41 deletion(s). Raw diff Collapse all Expand all
508508 /// Requires that this has no function body.
509509 void stealArgumentListFrom(Function &Src);
510510
511 static ArgumentListType Function::*getSublistAccess(Argument*) {
512 return &Function::ArgumentList;
513 }
514
511515 /// Get the underlying elements of the Function... the basic block list is
512516 /// empty for external functions.
513517 ///
514 const ArgumentListType &getArgumentList() const {
515 CheckLazyArguments();
516 return ArgumentList;
517 }
518 ArgumentListType &getArgumentList() {
519 CheckLazyArguments();
520 return ArgumentList;
521 }
522
523 static ArgumentListType Function::*getSublistAccess(Argument*) {
524 return &Function::ArgumentList;
525 }
526
527518 const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; }
528519 BasicBlockListType &getBasicBlockList() { return BasicBlocks; }
529520
79997999 // entries as we have arguments.
80008000 enum StaticAllocaInfo { Unknown, Clobbered, Elidable };
80018001 SmallDenseMap StaticAllocas;
8002 unsigned NumArgs = FuncInfo->Fn->getArgumentList().size();
8002 unsigned NumArgs = FuncInfo->Fn->arg_size();
80038003 StaticAllocas.reserve(NumArgs * 2);
80048004
80058005 auto GetInfoIfStaticAlloca = [&](const Value *V) -> StaticAllocaInfo * {
237237 bool AArch64CallLowering::lowerFormalArguments(MachineIRBuilder &MIRBuilder,
238238 const Function &F,
239239 ArrayRef VRegs) const {
240 auto &Args = F.getArgumentList();
241240 MachineFunction &MF = MIRBuilder.getMF();
242241 MachineBasicBlock &MBB = MIRBuilder.getMBB();
243242 MachineRegisterInfo &MRI = MF.getRegInfo();
245244
246245 SmallVector SplitArgs;
247246 unsigned i = 0;
248 for (auto &Arg : Args) {
247 for (auto &Arg : F.args()) {
249248 ArgInfo OrigArg{VRegs[i], Arg.getType()};
250249 setArgFlags(OrigArg, i + 1, DL, F);
251250 bool Split = false;
336336 if (Subtarget->useSoftFloat() || !Subtarget->hasVFP2())
337337 return false;
338338
339 auto &Args = F.getArgumentList();
340 for (auto &Arg : Args)
339 for (auto &Arg : F.args())
341340 if (!isSupportedType(DL, TLI, Arg.getType()))
342341 return false;
343342
346345
347346 SmallVector ArgInfos;
348347 unsigned Idx = 0;
349 for (auto &Arg : Args) {
348 for (auto &Arg : F.args()) {
350349 ArgInfo AInfo(VRegs[Idx], Arg.getType());
351350 setArgFlags(AInfo, Idx + 1, DL, F);
352351 splitToValueTypes(AInfo, ArgInfos, DL, MF.getRegInfo());
9595 Value *FunctionName = CreateStringPtr(BB, F.getName());
9696
9797 Value *Args[] = {FunctionName,
98 ConstantInt::get(I16, F.getArgumentList().size())};
98 ConstantInt::get(I16, F.arg_size())};
9999 CallInst::Create(Fn, Args, "", &BB);
100100 }
101101
5656 ;
5757 }
5858 if (F.arg_size() >=1) {
59 Argument &Arg = F.getArgumentList().front();
59 Argument &Arg = *F.arg_begin();
6060 switch (Arg.getType()->getTypeID()) {
6161 case Type::FloatTyID:
6262 case Type::DoubleTyID:
41104110
41114111 static bool
41124112 hasSameArgumentList(const Function *CallerFn, ImmutableCallSite *CS) {
4113 if (CS->arg_size() != CallerFn->getArgumentList().size())
4113 if (CS->arg_size() != CallerFn->arg_size())
41144114 return false;
41154115
41164116 ImmutableCallSite::arg_iterator CalleeArgIter = CS->arg_begin();
178178
179179 SmallVector SplitArgs;
180180 unsigned Idx = 0;
181 for (auto &Arg : F.getArgumentList()) {
181 for (auto &Arg : F.args()) {
182182 ArgInfo OrigArg(VRegs[Idx], Arg.getType());
183183 setArgFlags(OrigArg, Idx + 1, DL, F);
184184 LLT Ty = MRI.getType(VRegs[Idx]);
9191
9292 // Given a resume function @f.resume(%f.frame* %frame), returns %f.frame type.
9393 static Type *getFrameType(Function *Resume) {
94 auto *ArgType = Resume->getArgumentList().front().getType();
94 auto *ArgType = Resume->arg_begin()->getType();
9595 return cast(ArgType)->getElementType();
9696 }
9797
706706
707707 // Collect the spills for arguments and other not-materializable values.
708708 Spills.clear();
709 for (Argument &A : F.getArgumentList())
709 for (Argument &A : F.args())
710710 for (User *U : A.users())
711711 if (Checker.isDefinitionAcrossSuspend(A, U))
712712 Spills.emplace_back(&A, U);
222222 // Replace all args with undefs. The buildCoroutineFrame algorithm already
223223 // rewritten access to the args that occurs after suspend points with loads
224224 // and stores to/from the coroutine frame.
225 for (Argument &A : F.getArgumentList())
225 for (Argument &A : F.args())
226226 VMap[&A] = UndefValue::get(A.getType());
227227
228228 SmallVector Returns;
263263 IRBuilder<> Builder(&NewF->getEntryBlock().front());
264264
265265 // Remap frame pointer.
266 Argument *NewFramePtr = &NewF->getArgumentList().front();
266 Argument *NewFramePtr = &*NewF->arg_begin();
267267 Value *OldFramePtr = cast(VMap[Shape.FramePtr]);
268268 NewFramePtr->takeName(OldFramePtr);
269269 OldFramePtr->replaceAllUsesWith(NewFramePtr);
579579 Function::arg_iterator AI = F->arg_begin(); ++AI;
580580 for (unsigned N = FT->getNumParams(); N != 0; ++AI, --N)
581581 Args.push_back(&*AI);
582 CallInst *CI =
583 CallInst::Create(&F->getArgumentList().front(), Args, "", BB);
582 CallInst *CI = CallInst::Create(&*F->arg_begin(), Args, "", BB);
584583 ReturnInst *RI;
585584 if (FT->getReturnType()->isVoidTy())
586585 RI = ReturnInst::Create(*Ctx, BB);
594593 DFSanVisitor(DFSF).visitCallInst(*CI);
595594 if (!FT->getReturnType()->isVoidTy())
596595 new StoreInst(DFSF.getShadow(RI->getReturnValue()),
597 &F->getArgumentList().back(), RI);
596 &*std::prev(F->arg_end()), RI);
598597 }
599598
600599 return C;
905904 break;
906905 }
907906 case DataFlowSanitizer::IA_Args: {
908 unsigned ArgIdx = A->getArgNo() + F->getArgumentList().size() / 2;
907 unsigned ArgIdx = A->getArgNo() + F->arg_size() / 2;
909908 Function::arg_iterator i = F->arg_begin();
910909 while (ArgIdx--)
911910 ++i;
16021602 // matches up the formal to the actual argument values.
16031603 CallSite::arg_iterator AI = CS.arg_begin();
16041604 unsigned ArgNo = 0;
1605 for (Function::const_arg_iterator I = CalledFunc->arg_begin(),
1605 for (Function::arg_iterator I = CalledFunc->arg_begin(),
16061606 E = CalledFunc->arg_end(); I != E; ++I, ++AI, ++ArgNo) {
16071607 Value *ActualArg = *AI;
16081608
3939 Function *F = M->getFunction("f");
4040
4141 EXPECT_FALSE(F->isUsedInBasicBlock(&F->front()));
42 EXPECT_TRUE((++F->arg_begin())->isUsedInBasicBlock(&F->front()));
42 EXPECT_TRUE(std::next(F->arg_begin())->isUsedInBasicBlock(&F->front()));
4343 EXPECT_TRUE(F->arg_begin()->isUsedInBasicBlock(&F->front()));
4444 }
4545
2828 Function *F = Function::Create(FunctionType::get(Builder.getInt32Ty(),
2929 ArgTys, false),
3030 GlobalValue::ExternalLinkage, "F", &M);
31 assert(F->getArgumentList().size() == 2);
31 assert(F->arg_size() == 2);
3232
3333 BasicBlock *BB = BasicBlock::Create(C, "", F);
3434 Builder.SetInsertPoint(BB);
5858 Function *F = Function::Create(FunctionType::get(Builder.getInt32Ty(),
5959 ArgTys, false),
6060 GlobalValue::ExternalLinkage, "F", &M);
61 assert(F->getArgumentList().size() == 2);
61 assert(F->arg_size() == 2);
6262
6363 BasicBlock *BB = BasicBlock::Create(C, "", F);
6464 Builder.SetInsertPoint(BB);
8888 Function *F = Function::Create(FunctionType::get(Builder.getInt32Ty(),
8989 ArgTys, false),
9090 GlobalValue::ExternalLinkage, "F", &M);
91 assert(F->getArgumentList().size() == 2);
91 assert(F->arg_size() == 2);
9292
9393 BasicBlock *BB = BasicBlock::Create(C, "", F);
9494 Builder.SetInsertPoint(BB);
118118 Function *F = Function::Create(FunctionType::get(Builder.getInt32Ty(),
119119 ArgTys, false),
120120 GlobalValue::ExternalLinkage, "F", &M);
121 assert(F->getArgumentList().size() == 2);
121 assert(F->arg_size() == 2);
122122
123123 BasicBlock *BB = BasicBlock::Create(C, "", F);
124124 Builder.SetInsertPoint(BB);
149149 Function *F = Function::Create(FunctionType::get(Builder.getInt64Ty(),
150150 ArgTys, false),
151151 GlobalValue::ExternalLinkage, "F", &M);
152 assert(F->getArgumentList().size() == 2);
152 assert(F->arg_size() == 2);
153153
154154 BasicBlock *BB = BasicBlock::Create(C, "", F);
155155 Builder.SetInsertPoint(BB);
179179 Function *F = Function::Create(FunctionType::get(Builder.getInt64Ty(),
180180 ArgTys, false),
181181 GlobalValue::ExternalLinkage, "F", &M);
182 assert(F->getArgumentList().size() == 2);
182 assert(F->arg_size() == 2);
183183
184184 BasicBlock *BB = BasicBlock::Create(C, "", F);
185185 Builder.SetInsertPoint(BB);
209209 Function *F = Function::Create(FunctionType::get(Builder.getInt64Ty(),
210210 ArgTys, false),
211211 GlobalValue::ExternalLinkage, "F", &M);
212 assert(F->getArgumentList().size() == 2);
212 assert(F->arg_size() == 2);
213213
214214 BasicBlock *BB = BasicBlock::Create(C, "", F);
215215 Builder.SetInsertPoint(BB);
239239 Function *F = Function::Create(FunctionType::get(Builder.getInt64Ty(),
240240 ArgTys, false),
241241 GlobalValue::ExternalLinkage, "F", &M);
242 assert(F->getArgumentList().size() == 2);
242 assert(F->arg_size() == 2);
243243
244244 BasicBlock *BB = BasicBlock::Create(C, "", F);
245245 Builder.SetInsertPoint(BB);