LLVM 17.0.0git
ArgumentPromotion.cpp
Go to the documentation of this file.
1//===- ArgumentPromotion.cpp - Promote by-reference arguments -------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This pass promotes "by reference" arguments to be "by value" arguments. In
10// practice, this means looking for internal functions that have pointer
11// arguments. If it can prove, through the use of alias analysis, that an
12// argument is *only* loaded, then it can pass the value into the function
13// instead of the address of the value. This can cause recursive simplification
14// of code and lead to the elimination of allocas (especially in C++ template
15// code like the STL).
16//
17// This pass also handles aggregate arguments that are passed into a function,
18// scalarizing them if the elements of the aggregate are only loaded. Note that
19// by default it refuses to scalarize aggregates which would require passing in
20// more than three operands to the function, because passing thousands of
21// operands for a large array or structure is unprofitable! This limit can be
22// configured or disabled, however.
23//
24// Note that this transformation could also be done for arguments that are only
25// stored to (returning the value instead), but does not currently. This case
26// would be best handled when and if LLVM begins supporting multiple return
27// values from functions.
28//
29//===----------------------------------------------------------------------===//
30
32
34#include "llvm/ADT/STLExtras.h"
35#include "llvm/ADT/ScopeExit.h"
38#include "llvm/ADT/Statistic.h"
39#include "llvm/ADT/Twine.h"
43#include "llvm/Analysis/Loads.h"
47#include "llvm/IR/Argument.h"
48#include "llvm/IR/Attributes.h"
49#include "llvm/IR/BasicBlock.h"
50#include "llvm/IR/CFG.h"
51#include "llvm/IR/Constants.h"
52#include "llvm/IR/DataLayout.h"
54#include "llvm/IR/Dominators.h"
55#include "llvm/IR/Function.h"
56#include "llvm/IR/IRBuilder.h"
57#include "llvm/IR/InstrTypes.h"
58#include "llvm/IR/Instruction.h"
60#include "llvm/IR/Metadata.h"
61#include "llvm/IR/NoFolder.h"
62#include "llvm/IR/PassManager.h"
63#include "llvm/IR/Type.h"
64#include "llvm/IR/Use.h"
65#include "llvm/IR/User.h"
66#include "llvm/IR/Value.h"
68#include "llvm/Support/Debug.h"
72#include <algorithm>
73#include <cassert>
74#include <cstdint>
75#include <utility>
76#include <vector>
77
78using namespace llvm;
79
80#define DEBUG_TYPE "argpromotion"
81
82STATISTIC(NumArgumentsPromoted, "Number of pointer arguments promoted");
83STATISTIC(NumArgumentsDead, "Number of dead pointer args eliminated");
84
85namespace {
86
87struct ArgPart {
88 Type *Ty;
89 Align Alignment;
90 /// A representative guaranteed-executed load or store instruction for use by
91 /// metadata transfer.
92 Instruction *MustExecInstr;
93};
94
95using OffsetAndArgPart = std::pair<int64_t, ArgPart>;
96
97} // end anonymous namespace
98
100 Value *Ptr, Type *ResElemTy, int64_t Offset) {
101 // For non-opaque pointers, try to create a "nice" GEP if possible, otherwise
102 // fall back to an i8 GEP to a specific offset.
103 unsigned AddrSpace = Ptr->getType()->getPointerAddressSpace();
104 APInt OrigOffset(DL.getIndexTypeSizeInBits(Ptr->getType()), Offset);
105 if (!Ptr->getType()->isOpaquePointerTy()) {
106 Type *OrigElemTy = Ptr->getType()->getNonOpaquePointerElementType();
107 if (OrigOffset == 0 && OrigElemTy == ResElemTy)
108 return Ptr;
109
110 if (OrigElemTy->isSized()) {
111 APInt TmpOffset = OrigOffset;
112 Type *TmpTy = OrigElemTy;
113 SmallVector<APInt> IntIndices =
114 DL.getGEPIndicesForOffset(TmpTy, TmpOffset);
115 if (TmpOffset == 0) {
116 // Try to add trailing zero indices to reach the right type.
117 while (TmpTy != ResElemTy) {
119 if (!NextTy)
120 break;
121
122 IntIndices.push_back(APInt::getZero(
123 isa<StructType>(TmpTy) ? 32 : OrigOffset.getBitWidth()));
124 TmpTy = NextTy;
125 }
126
127 SmallVector<Value *> Indices;
128 for (const APInt &Index : IntIndices)
129 Indices.push_back(IRB.getInt(Index));
130
131 if (OrigOffset != 0 || TmpTy == ResElemTy) {
132 Ptr = IRB.CreateGEP(OrigElemTy, Ptr, Indices);
133 return IRB.CreateBitCast(Ptr, ResElemTy->getPointerTo(AddrSpace));
134 }
135 }
136 }
137 }
138
139 if (OrigOffset != 0) {
140 Ptr = IRB.CreateBitCast(Ptr, IRB.getInt8PtrTy(AddrSpace));
141 Ptr = IRB.CreateGEP(IRB.getInt8Ty(), Ptr, IRB.getInt(OrigOffset));
142 }
143 return IRB.CreateBitCast(Ptr, ResElemTy->getPointerTo(AddrSpace));
144}
145
146/// DoPromotion - This method actually performs the promotion of the specified
147/// arguments, and returns the new function. At this point, we know that it's
148/// safe to do so.
149static Function *
152 &ArgsToPromote) {
153 // Start by computing a new prototype for the function, which is the same as
154 // the old function, but has modified arguments.
155 FunctionType *FTy = F->getFunctionType();
156 std::vector<Type *> Params;
157
158 // Attribute - Keep track of the parameter attributes for the arguments
159 // that we are *not* promoting. For the ones that we do promote, the parameter
160 // attributes are lost
162 AttributeList PAL = F->getAttributes();
163
164 // First, determine the new argument list
165 unsigned ArgNo = 0;
166 for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E;
167 ++I, ++ArgNo) {
168 if (!ArgsToPromote.count(&*I)) {
169 // Unchanged argument
170 Params.push_back(I->getType());
171 ArgAttrVec.push_back(PAL.getParamAttrs(ArgNo));
172 } else if (I->use_empty()) {
173 // Dead argument (which are always marked as promotable)
174 ++NumArgumentsDead;
175 } else {
176 const auto &ArgParts = ArgsToPromote.find(&*I)->second;
177 for (const auto &Pair : ArgParts) {
178 Params.push_back(Pair.second.Ty);
179 ArgAttrVec.push_back(AttributeSet());
180 }
181 ++NumArgumentsPromoted;
182 }
183 }
184
185 Type *RetTy = FTy->getReturnType();
186
187 // Construct the new function type using the new arguments.
188 FunctionType *NFTy = FunctionType::get(RetTy, Params, FTy->isVarArg());
189
190 // Create the new function body and insert it into the module.
191 Function *NF = Function::Create(NFTy, F->getLinkage(), F->getAddressSpace(),
192 F->getName());
194 NF->copyMetadata(F, 0);
195
196 // The new function will have the !dbg metadata copied from the original
197 // function. The original function may not be deleted, and dbg metadata need
198 // to be unique, so we need to drop it.
199 F->setSubprogram(nullptr);
200
201 LLVM_DEBUG(dbgs() << "ARG PROMOTION: Promoting to:" << *NF << "\n"
202 << "From: " << *F);
203
204 uint64_t LargestVectorWidth = 0;
205 for (auto *I : Params)
206 if (auto *VT = dyn_cast<llvm::VectorType>(I))
207 LargestVectorWidth = std::max(
208 LargestVectorWidth, VT->getPrimitiveSizeInBits().getKnownMinValue());
209
210 // Recompute the parameter attributes list based on the new arguments for
211 // the function.
212 NF->setAttributes(AttributeList::get(F->getContext(), PAL.getFnAttrs(),
213 PAL.getRetAttrs(), ArgAttrVec));
214 AttributeFuncs::updateMinLegalVectorWidthAttr(*NF, LargestVectorWidth);
215 ArgAttrVec.clear();
216
217 F->getParent()->getFunctionList().insert(F->getIterator(), NF);
218 NF->takeName(F);
219
220 // Loop over all the callers of the function, transforming the call sites to
221 // pass in the loaded pointers.
223 const DataLayout &DL = F->getParent()->getDataLayout();
225
226 while (!F->use_empty()) {
227 CallBase &CB = cast<CallBase>(*F->user_back());
228 assert(CB.getCalledFunction() == F);
229 const AttributeList &CallPAL = CB.getAttributes();
230 IRBuilder<NoFolder> IRB(&CB);
231
232 // Loop over the operands, inserting GEP and loads in the caller as
233 // appropriate.
234 auto *AI = CB.arg_begin();
235 ArgNo = 0;
236 for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E;
237 ++I, ++AI, ++ArgNo) {
238 if (!ArgsToPromote.count(&*I)) {
239 Args.push_back(*AI); // Unmodified argument
240 ArgAttrVec.push_back(CallPAL.getParamAttrs(ArgNo));
241 } else if (!I->use_empty()) {
242 Value *V = *AI;
243 const auto &ArgParts = ArgsToPromote.find(&*I)->second;
244 for (const auto &Pair : ArgParts) {
245 LoadInst *LI = IRB.CreateAlignedLoad(
246 Pair.second.Ty,
247 createByteGEP(IRB, DL, V, Pair.second.Ty, Pair.first),
248 Pair.second.Alignment, V->getName() + ".val");
249 if (Pair.second.MustExecInstr) {
250 LI->setAAMetadata(Pair.second.MustExecInstr->getAAMetadata());
251 LI->copyMetadata(*Pair.second.MustExecInstr,
252 {LLVMContext::MD_range, LLVMContext::MD_nonnull,
253 LLVMContext::MD_dereferenceable,
254 LLVMContext::MD_dereferenceable_or_null,
255 LLVMContext::MD_align, LLVMContext::MD_noundef,
256 LLVMContext::MD_nontemporal});
257 }
258 Args.push_back(LI);
259 ArgAttrVec.push_back(AttributeSet());
260 }
261 } else {
262 assert(ArgsToPromote.count(&*I) && I->use_empty());
263 DeadArgs.emplace_back(AI->get());
264 }
265 }
266
267 // Push any varargs arguments on the list.
268 for (; AI != CB.arg_end(); ++AI, ++ArgNo) {
269 Args.push_back(*AI);
270 ArgAttrVec.push_back(CallPAL.getParamAttrs(ArgNo));
271 }
272
274 CB.getOperandBundlesAsDefs(OpBundles);
275
276 CallBase *NewCS = nullptr;
277 if (InvokeInst *II = dyn_cast<InvokeInst>(&CB)) {
278 NewCS = InvokeInst::Create(NF, II->getNormalDest(), II->getUnwindDest(),
279 Args, OpBundles, "", &CB);
280 } else {
281 auto *NewCall = CallInst::Create(NF, Args, OpBundles, "", &CB);
282 NewCall->setTailCallKind(cast<CallInst>(&CB)->getTailCallKind());
283 NewCS = NewCall;
284 }
285 NewCS->setCallingConv(CB.getCallingConv());
286 NewCS->setAttributes(AttributeList::get(F->getContext(),
287 CallPAL.getFnAttrs(),
288 CallPAL.getRetAttrs(), ArgAttrVec));
289 NewCS->copyMetadata(CB, {LLVMContext::MD_prof, LLVMContext::MD_dbg});
290 Args.clear();
291 ArgAttrVec.clear();
292
294 LargestVectorWidth);
295
296 if (!CB.use_empty()) {
297 CB.replaceAllUsesWith(NewCS);
298 NewCS->takeName(&CB);
299 }
300
301 // Finally, remove the old call from the program, reducing the use-count of
302 // F.
303 CB.eraseFromParent();
304 }
305
307
308 // Since we have now created the new function, splice the body of the old
309 // function right into the new function, leaving the old rotting hulk of the
310 // function empty.
311 NF->splice(NF->begin(), F);
312
313 // We will collect all the new created allocas to promote them into registers
314 // after the following loop
316
317 // Loop over the argument list, transferring uses of the old arguments over to
318 // the new arguments, also transferring over the names as well.
320 for (Argument &Arg : F->args()) {
321 if (!ArgsToPromote.count(&Arg)) {
322 // If this is an unmodified argument, move the name and users over to the
323 // new version.
324 Arg.replaceAllUsesWith(&*I2);
325 I2->takeName(&Arg);
326 ++I2;
327 continue;
328 }
329
330 // There potentially are metadata uses for things like llvm.dbg.value.
331 // Replace them with undef, after handling the other regular uses.
332 auto RauwUndefMetadata = make_scope_exit(
333 [&]() { Arg.replaceAllUsesWith(UndefValue::get(Arg.getType())); });
334
335 if (Arg.use_empty())
336 continue;
337
338 // Otherwise, if we promoted this argument, we have to create an alloca in
339 // the callee for every promotable part and store each of the new incoming
340 // arguments into the corresponding alloca, what lets the old code (the
341 // store instructions if they are allowed especially) a chance to work as
342 // before.
343 assert(Arg.getType()->isPointerTy() &&
344 "Only arguments with a pointer type are promotable");
345
346 IRBuilder<NoFolder> IRB(&NF->begin()->front());
347
348 // Add only the promoted elements, so parts from ArgsToPromote
350 for (const auto &Pair : ArgsToPromote.find(&Arg)->second) {
351 int64_t Offset = Pair.first;
352 const ArgPart &Part = Pair.second;
353
354 Argument *NewArg = I2++;
355 NewArg->setName(Arg.getName() + "." + Twine(Offset) + ".val");
356
357 AllocaInst *NewAlloca = IRB.CreateAlloca(
358 Part.Ty, nullptr, Arg.getName() + "." + Twine(Offset) + ".allc");
359 NewAlloca->setAlignment(Pair.second.Alignment);
360 IRB.CreateAlignedStore(NewArg, NewAlloca, Pair.second.Alignment);
361
362 // Collect the alloca to retarget the users to
363 OffsetToAlloca.insert({Offset, NewAlloca});
364 }
365
366 auto GetAlloca = [&](Value *Ptr) {
367 APInt Offset(DL.getIndexTypeSizeInBits(Ptr->getType()), 0);
368 Ptr = Ptr->stripAndAccumulateConstantOffsets(DL, Offset,
369 /* AllowNonInbounds */ true);
370 assert(Ptr == &Arg && "Not constant offset from arg?");
371 return OffsetToAlloca.lookup(Offset.getSExtValue());
372 };
373
374 // Cleanup the code from the dead instructions: GEPs and BitCasts in between
375 // the original argument and its users: loads and stores. Retarget every
376 // user to the new created alloca.
379 append_range(Worklist, Arg.users());
380 while (!Worklist.empty()) {
381 Value *V = Worklist.pop_back_val();
382 if (isa<BitCastInst>(V) || isa<GetElementPtrInst>(V)) {
383 DeadInsts.push_back(cast<Instruction>(V));
384 append_range(Worklist, V->users());
385 continue;
386 }
387
388 if (auto *LI = dyn_cast<LoadInst>(V)) {
389 Value *Ptr = LI->getPointerOperand();
390 LI->setOperand(LoadInst::getPointerOperandIndex(), GetAlloca(Ptr));
391 continue;
392 }
393
394 if (auto *SI = dyn_cast<StoreInst>(V)) {
395 assert(!SI->isVolatile() && "Volatile operations can't be promoted.");
396 Value *Ptr = SI->getPointerOperand();
397 SI->setOperand(StoreInst::getPointerOperandIndex(), GetAlloca(Ptr));
398 continue;
399 }
400
401 llvm_unreachable("Unexpected user");
402 }
403
404 for (Instruction *I : DeadInsts) {
405 I->replaceAllUsesWith(PoisonValue::get(I->getType()));
406 I->eraseFromParent();
407 }
408
409 // Collect the allocas for promotion
410 for (const auto &Pair : OffsetToAlloca) {
411 assert(isAllocaPromotable(Pair.second) &&
412 "By design, only promotable allocas should be produced.");
413 Allocas.push_back(Pair.second);
414 }
415 }
416
417 LLVM_DEBUG(dbgs() << "ARG PROMOTION: " << Allocas.size()
418 << " alloca(s) are promotable by Mem2Reg\n");
419
420 if (!Allocas.empty()) {
421 // And we are able to call the `promoteMemoryToRegister()` function.
422 // Our earlier checks have ensured that PromoteMemToReg() will
423 // succeed.
424 auto &DT = FAM.getResult<DominatorTreeAnalysis>(*NF);
425 auto &AC = FAM.getResult<AssumptionAnalysis>(*NF);
426 PromoteMemToReg(Allocas, DT, &AC);
427 }
428
429 return NF;
430}
431
432/// Return true if we can prove that all callees pass in a valid pointer for the
433/// specified function argument.
435 Align NeededAlign,
436 uint64_t NeededDerefBytes) {
437 Function *Callee = Arg->getParent();
438 const DataLayout &DL = Callee->getParent()->getDataLayout();
439 APInt Bytes(64, NeededDerefBytes);
440
441 // Check if the argument itself is marked dereferenceable and aligned.
442 if (isDereferenceableAndAlignedPointer(Arg, NeededAlign, Bytes, DL))
443 return true;
444
445 // Look at all call sites of the function. At this point we know we only have
446 // direct callees.
447 return all_of(Callee->users(), [&](User *U) {
448 CallBase &CB = cast<CallBase>(*U);
449 return isDereferenceableAndAlignedPointer(CB.getArgOperand(Arg->getArgNo()),
450 NeededAlign, Bytes, DL);
451 });
452}
453
454/// Determine that this argument is safe to promote, and find the argument
455/// parts it can be promoted into.
456static bool findArgParts(Argument *Arg, const DataLayout &DL, AAResults &AAR,
457 unsigned MaxElements, bool IsRecursive,
459 // Quick exit for unused arguments
460 if (Arg->use_empty())
461 return true;
462
463 // We can only promote this argument if all the uses are loads at known
464 // offsets.
465 //
466 // Promoting the argument causes it to be loaded in the caller
467 // unconditionally. This is only safe if we can prove that either the load
468 // would have happened in the callee anyway (ie, there is a load in the entry
469 // block) or the pointer passed in at every call site is guaranteed to be
470 // valid.
471 // In the former case, invalid loads can happen, but would have happened
472 // anyway, in the latter case, invalid loads won't happen. This prevents us
473 // from introducing an invalid load that wouldn't have happened in the
474 // original code.
475
477 Align NeededAlign(1);
478 uint64_t NeededDerefBytes = 0;
479
480 // And if this is a byval argument we also allow to have store instructions.
481 // Only handle in such way arguments with specified alignment;
482 // if it's unspecified, the actual alignment of the argument is
483 // target-specific.
484 bool AreStoresAllowed = Arg->getParamByValType() && Arg->getParamAlign();
485
486 // An end user of a pointer argument is a load or store instruction.
487 // Returns std::nullopt if this load or store is not based on the argument.
488 // Return true if we can promote the instruction, false otherwise.
489 auto HandleEndUser = [&](auto *I, Type *Ty,
490 bool GuaranteedToExecute) -> std::optional<bool> {
491 // Don't promote volatile or atomic instructions.
492 if (!I->isSimple())
493 return false;
494
495 Value *Ptr = I->getPointerOperand();
496 APInt Offset(DL.getIndexTypeSizeInBits(Ptr->getType()), 0);
497 Ptr = Ptr->stripAndAccumulateConstantOffsets(DL, Offset,
498 /* AllowNonInbounds */ true);
499 if (Ptr != Arg)
500 return std::nullopt;
501
502 if (Offset.getSignificantBits() >= 64)
503 return false;
504
505 TypeSize Size = DL.getTypeStoreSize(Ty);
506 // Don't try to promote scalable types.
507 if (Size.isScalable())
508 return false;
509
510 // If this is a recursive function and one of the types is a pointer,
511 // then promoting it might lead to recursive promotion.
512 if (IsRecursive && Ty->isPointerTy())
513 return false;
514
515 int64_t Off = Offset.getSExtValue();
516 auto Pair = ArgParts.try_emplace(
517 Off, ArgPart{Ty, I->getAlign(), GuaranteedToExecute ? I : nullptr});
518 ArgPart &Part = Pair.first->second;
519 bool OffsetNotSeenBefore = Pair.second;
520
521 // We limit promotion to only promoting up to a fixed number of elements of
522 // the aggregate.
523 if (MaxElements > 0 && ArgParts.size() > MaxElements) {
524 LLVM_DEBUG(dbgs() << "ArgPromotion of " << *Arg << " failed: "
525 << "more than " << MaxElements << " parts\n");
526 return false;
527 }
528
529 // For now, we only support loading/storing one specific type at a given
530 // offset.
531 if (Part.Ty != Ty) {
532 LLVM_DEBUG(dbgs() << "ArgPromotion of " << *Arg << " failed: "
533 << "accessed as both " << *Part.Ty << " and " << *Ty
534 << " at offset " << Off << "\n");
535 return false;
536 }
537
538 // If this instruction is not guaranteed to execute, and we haven't seen a
539 // load or store at this offset before (or it had lower alignment), then we
540 // need to remember that requirement.
541 // Note that skipping instructions of previously seen offsets is only
542 // correct because we only allow a single type for a given offset, which
543 // also means that the number of accessed bytes will be the same.
544 if (!GuaranteedToExecute &&
545 (OffsetNotSeenBefore || Part.Alignment < I->getAlign())) {
546 // We won't be able to prove dereferenceability for negative offsets.
547 if (Off < 0)
548 return false;
549
550 // If the offset is not aligned, an aligned base pointer won't help.
551 if (!isAligned(I->getAlign(), Off))
552 return false;
553
554 NeededDerefBytes = std::max(NeededDerefBytes, Off + Size.getFixedValue());
555 NeededAlign = std::max(NeededAlign, I->getAlign());
556 }
557
558 Part.Alignment = std::max(Part.Alignment, I->getAlign());
559 return true;
560 };
561
562 // Look for loads and stores that are guaranteed to execute on entry.
563 for (Instruction &I : Arg->getParent()->getEntryBlock()) {
564 std::optional<bool> Res{};
565 if (LoadInst *LI = dyn_cast<LoadInst>(&I))
566 Res = HandleEndUser(LI, LI->getType(), /* GuaranteedToExecute */ true);
567 else if (StoreInst *SI = dyn_cast<StoreInst>(&I))
568 Res = HandleEndUser(SI, SI->getValueOperand()->getType(),
569 /* GuaranteedToExecute */ true);
570 if (Res && !*Res)
571 return false;
572
574 break;
575 }
576
577 // Now look at all loads of the argument. Remember the load instructions
578 // for the aliasing check below.
582 auto AppendUses = [&](const Value *V) {
583 for (const Use &U : V->uses())
584 if (Visited.insert(&U).second)
585 Worklist.push_back(&U);
586 };
587 AppendUses(Arg);
588 while (!Worklist.empty()) {
589 const Use *U = Worklist.pop_back_val();
590 Value *V = U->getUser();
591 if (isa<BitCastInst>(V)) {
592 AppendUses(V);
593 continue;
594 }
595
596 if (auto *GEP = dyn_cast<GetElementPtrInst>(V)) {
597 if (!GEP->hasAllConstantIndices())
598 return false;
599 AppendUses(V);
600 continue;
601 }
602
603 if (auto *LI = dyn_cast<LoadInst>(V)) {
604 if (!*HandleEndUser(LI, LI->getType(), /* GuaranteedToExecute */ false))
605 return false;
606 Loads.push_back(LI);
607 continue;
608 }
609
610 // Stores are allowed for byval arguments
611 auto *SI = dyn_cast<StoreInst>(V);
612 if (AreStoresAllowed && SI &&
613 U->getOperandNo() == StoreInst::getPointerOperandIndex()) {
614 if (!*HandleEndUser(SI, SI->getValueOperand()->getType(),
615 /* GuaranteedToExecute */ false))
616 return false;
617 continue;
618 // Only stores TO the argument is allowed, all the other stores are
619 // unknown users
620 }
621
622 // Unknown user.
623 LLVM_DEBUG(dbgs() << "ArgPromotion of " << *Arg << " failed: "
624 << "unknown user " << *V << "\n");
625 return false;
626 }
627
628 if (NeededDerefBytes || NeededAlign > 1) {
629 // Try to prove a required deref / aligned requirement.
631 NeededDerefBytes)) {
632 LLVM_DEBUG(dbgs() << "ArgPromotion of " << *Arg << " failed: "
633 << "not dereferenceable or aligned\n");
634 return false;
635 }
636 }
637
638 if (ArgParts.empty())
639 return true; // No users, this is a dead argument.
640
641 // Sort parts by offset.
642 append_range(ArgPartsVec, ArgParts);
643 sort(ArgPartsVec, llvm::less_first());
644
645 // Make sure the parts are non-overlapping.
646 int64_t Offset = ArgPartsVec[0].first;
647 for (const auto &Pair : ArgPartsVec) {
648 if (Pair.first < Offset)
649 return false; // Overlap with previous part.
650
651 Offset = Pair.first + DL.getTypeStoreSize(Pair.second.Ty);
652 }
653
654 // If store instructions are allowed, the path from the entry of the function
655 // to each load may be not free of instructions that potentially invalidate
656 // the load, and this is an admissible situation.
657 if (AreStoresAllowed)
658 return true;
659
660 // Okay, now we know that the argument is only used by load instructions, and
661 // it is safe to unconditionally perform all of them. Use alias analysis to
662 // check to see if the pointer is guaranteed to not be modified from entry of
663 // the function to each of the load instructions.
664
665 // Because there could be several/many load instructions, remember which
666 // blocks we know to be transparent to the load.
668
669 for (LoadInst *Load : Loads) {
670 // Check to see if the load is invalidated from the start of the block to
671 // the load itself.
672 BasicBlock *BB = Load->getParent();
673
675 if (AAR.canInstructionRangeModRef(BB->front(), *Load, Loc, ModRefInfo::Mod))
676 return false; // Pointer is invalidated!
677
678 // Now check every path from the entry block to the load for transparency.
679 // To do this, we perform a depth first search on the inverse CFG from the
680 // loading block.
681 for (BasicBlock *P : predecessors(BB)) {
682 for (BasicBlock *TranspBB : inverse_depth_first_ext(P, TranspBlocks))
683 if (AAR.canBasicBlockModify(*TranspBB, Loc))
684 return false;
685 }
686 }
687
688 // If the path from the entry of the function to each load is free of
689 // instructions that potentially invalidate the load, we can make the
690 // transformation!
691 return true;
692}
693
694/// Check if callers and callee agree on how promoted arguments would be
695/// passed.
697 const TargetTransformInfo &TTI) {
698 return all_of(F.uses(), [&](const Use &U) {
699 CallBase *CB = dyn_cast<CallBase>(U.getUser());
700 if (!CB)
701 return false;
702
703 const Function *Caller = CB->getCaller();
704 const Function *Callee = CB->getCalledFunction();
705 return TTI.areTypesABICompatible(Caller, Callee, Types);
706 });
707}
708
709/// PromoteArguments - This method checks the specified function to see if there
710/// are any promotable arguments and if it is safe to promote the function (for
711/// example, all callers are direct). If safe to promote some arguments, it
712/// calls the DoPromotion method.
714 unsigned MaxElements, bool IsRecursive) {
715 // Don't perform argument promotion for naked functions; otherwise we can end
716 // up removing parameters that are seemingly 'not used' as they are referred
717 // to in the assembly.
718 if (F->hasFnAttribute(Attribute::Naked))
719 return nullptr;
720
721 // Make sure that it is local to this module.
722 if (!F->hasLocalLinkage())
723 return nullptr;
724
725 // Don't promote arguments for variadic functions. Adding, removing, or
726 // changing non-pack parameters can change the classification of pack
727 // parameters. Frontends encode that classification at the call site in the
728 // IR, while in the callee the classification is determined dynamically based
729 // on the number of registers consumed so far.
730 if (F->isVarArg())
731 return nullptr;
732
733 // Don't transform functions that receive inallocas, as the transformation may
734 // not be safe depending on calling convention.
735 if (F->getAttributes().hasAttrSomewhere(Attribute::InAlloca))
736 return nullptr;
737
738 // First check: see if there are any pointer arguments! If not, quick exit.
739 SmallVector<Argument *, 16> PointerArgs;
740 for (Argument &I : F->args())
741 if (I.getType()->isPointerTy())
742 PointerArgs.push_back(&I);
743 if (PointerArgs.empty())
744 return nullptr;
745
746 // Second check: make sure that all callers are direct callers. We can't
747 // transform functions that have indirect callers. Also see if the function
748 // is self-recursive.
749 for (Use &U : F->uses()) {
750 CallBase *CB = dyn_cast<CallBase>(U.getUser());
751 // Must be a direct call.
752 if (CB == nullptr || !CB->isCallee(&U) ||
753 CB->getFunctionType() != F->getFunctionType())
754 return nullptr;
755
756 // Can't change signature of musttail callee
757 if (CB->isMustTailCall())
758 return nullptr;
759
760 if (CB->getFunction() == F)
761 IsRecursive = true;
762 }
763
764 // Can't change signature of musttail caller
765 // FIXME: Support promoting whole chain of musttail functions
766 for (BasicBlock &BB : *F)
767 if (BB.getTerminatingMustTailCall())
768 return nullptr;
769
770 const DataLayout &DL = F->getParent()->getDataLayout();
771 auto &AAR = FAM.getResult<AAManager>(*F);
772 const auto &TTI = FAM.getResult<TargetIRAnalysis>(*F);
773
774 // Check to see which arguments are promotable. If an argument is promotable,
775 // add it to ArgsToPromote.
777 for (Argument *PtrArg : PointerArgs) {
778 // Replace sret attribute with noalias. This reduces register pressure by
779 // avoiding a register copy.
780 if (PtrArg->hasStructRetAttr()) {
781 unsigned ArgNo = PtrArg->getArgNo();
782 F->removeParamAttr(ArgNo, Attribute::StructRet);
783 F->addParamAttr(ArgNo, Attribute::NoAlias);
784 for (Use &U : F->uses()) {
785 CallBase &CB = cast<CallBase>(*U.getUser());
786 CB.removeParamAttr(ArgNo, Attribute::StructRet);
787 CB.addParamAttr(ArgNo, Attribute::NoAlias);
788 }
789 }
790
791 // If we can promote the pointer to its value.
793
794 if (findArgParts(PtrArg, DL, AAR, MaxElements, IsRecursive, ArgParts)) {
796 for (const auto &Pair : ArgParts)
797 Types.push_back(Pair.second.Ty);
798
799 if (areTypesABICompatible(Types, *F, TTI)) {
800 ArgsToPromote.insert({PtrArg, std::move(ArgParts)});
801 }
802 }
803 }
804
805 // No promotable pointer arguments.
806 if (ArgsToPromote.empty())
807 return nullptr;
808
809 return doPromotion(F, FAM, ArgsToPromote);
810}
811
814 LazyCallGraph &CG,
815 CGSCCUpdateResult &UR) {
816 bool Changed = false, LocalChange;
817
818 // Iterate until we stop promoting from this SCC.
819 do {
820 LocalChange = false;
821
823 AM.getResult<FunctionAnalysisManagerCGSCCProxy>(C, CG).getManager();
824
825 bool IsRecursive = C.size() > 1;
826 for (LazyCallGraph::Node &N : C) {
827 Function &OldF = N.getFunction();
828 Function *NewF = promoteArguments(&OldF, FAM, MaxElements, IsRecursive);
829 if (!NewF)
830 continue;
831 LocalChange = true;
832
833 // Directly substitute the functions in the call graph. Note that this
834 // requires the old function to be completely dead and completely
835 // replaced by the new function. It does no call graph updates, it merely
836 // swaps out the particular function mapped to a particular node in the
837 // graph.
838 C.getOuterRefSCC().replaceNodeFunction(N, *NewF);
839 FAM.clear(OldF, OldF.getName());
840 OldF.eraseFromParent();
841
842 PreservedAnalyses FuncPA;
843 FuncPA.preserveSet<CFGAnalyses>();
844 for (auto *U : NewF->users()) {
845 auto *UserF = cast<CallBase>(U)->getFunction();
846 FAM.invalidate(*UserF, FuncPA);
847 }
848 }
849
850 Changed |= LocalChange;
851 } while (LocalChange);
852
853 if (!Changed)
854 return PreservedAnalyses::all();
855
857 // We've cleared out analyses for deleted functions.
859 // We've manually invalidated analyses for functions we've modified.
861 return PA;
862}
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
amdgpu Simplify well known AMD library false FunctionCallee Callee
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
static bool areTypesABICompatible(ArrayRef< Type * > Types, const Function &F, const TargetTransformInfo &TTI)
Check if callers and callee agree on how promoted arguments would be passed.
static Function * doPromotion(Function *F, FunctionAnalysisManager &FAM, const DenseMap< Argument *, SmallVector< OffsetAndArgPart, 4 > > &ArgsToPromote)
DoPromotion - This method actually performs the promotion of the specified arguments,...
static Function * promoteArguments(Function *F, FunctionAnalysisManager &FAM, unsigned MaxElements, bool IsRecursive)
PromoteArguments - This method checks the specified function to see if there are any promotable argum...
static bool allCallersPassValidPointerForArgument(Argument *Arg, Align NeededAlign, uint64_t NeededDerefBytes)
Return true if we can prove that all callees pass in a valid pointer for the specified function argum...
static Value * createByteGEP(IRBuilderBase &IRB, const DataLayout &DL, Value *Ptr, Type *ResElemTy, int64_t Offset)
static bool findArgParts(Argument *Arg, const DataLayout &DL, AAResults &AAR, unsigned MaxElements, bool IsRecursive, SmallVectorImpl< OffsetAndArgPart > &ArgPartsVec)
Determine that this argument is safe to promote, and find the argument parts it can be promoted into.
This file contains the simple types necessary to represent the attributes associated with functions a...
This is the interface for LLVM's primary stateless and local alias analysis.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file provides interfaces used to build and manipulate a call graph, which is a very useful tool ...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
return RetTy
#define LLVM_DEBUG(X)
Definition: Debug.h:101
This file builds on the ADT/GraphTraits.h file to build generic depth first graph iterator.
uint64_t Size
Hexagon Common GEP
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
This file provides utility analysis objects describing memory locations.
This file contains the declarations for metadata subclasses.
#define P(N)
FunctionAnalysisManager FAM
This header defines various interfaces for pass management in LLVM.
@ SI
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file contains some templates that are useful if you are working with the STL at all.
This file defines the make_scope_exit function, which executes user-defined cleanup logic at scope ex...
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition: Statistic.h:167
This pass exposes codegen information to IR-level passes.
This defines the Use class.
A manager for alias analyses.
bool canInstructionRangeModRef(const Instruction &I1, const Instruction &I2, const MemoryLocation &Loc, const ModRefInfo Mode)
Check if it is possible for the execution of the specified instructions to mod(according to the mode)...
bool canBasicBlockModify(const BasicBlock &BB, const MemoryLocation &Loc)
Check if it is possible for execution of the specified basic block to modify the location Loc.
Class for arbitrary precision integers.
Definition: APInt.h:75
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition: APInt.h:1439
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
Definition: APInt.h:177
This templated class represents "all analyses that operate over <a particular IR unit>" (e....
Definition: PassManager.h:90
an instruction to allocate memory on the stack
Definition: Instructions.h:58
void setAlignment(Align Align)
Definition: Instructions.h:129
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:620
void clear(IRUnitT &IR, llvm::StringRef Name)
Clear any cached analysis results for a single unit of IR.
void invalidate(IRUnitT &IR, const PreservedAnalyses &PA)
Invalidate cached analyses for an IR unit.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:774
PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM, LazyCallGraph &CG, CGSCCUpdateResult &UR)
This class represents an incoming formal argument to a Function.
Definition: Argument.h:28
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
A function analysis which provides an AssumptionCache.
AttributeSet getFnAttrs() const
The function attributes are returned.
static AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute > > Attrs)
Create an AttributeList with the specified parameters in it.
AttributeSet getRetAttrs() const
The attributes for the ret value are returned.
AttributeSet getParamAttrs(unsigned ArgNo) const
The attributes for the argument or parameter at the given index are returned.
LLVM Basic Block Representation.
Definition: BasicBlock.h:56
const Instruction & front() const
Definition: BasicBlock.h:335
Represents analyses that only rely on functions' control flow.
Definition: PassManager.h:113
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1186
void setCallingConv(CallingConv::ID CC)
Definition: InstrTypes.h:1471
void getOperandBundlesAsDefs(SmallVectorImpl< OperandBundleDef > &Defs) const
Return the list of operand bundles attached to this instruction as a vector of OperandBundleDefs.
void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Removes the attribute from the given argument.
Definition: InstrTypes.h:1580
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
Definition: InstrTypes.h:1408
CallingConv::ID getCallingConv() const
Definition: InstrTypes.h:1467
User::op_iterator arg_begin()
Return the iterator pointing to the beginning of the argument list.
Definition: InstrTypes.h:1328
bool isMustTailCall() const
Tests if this call site must be tail call optimized.
bool isCallee(Value::const_user_iterator UI) const
Determine whether the passed iterator points to the callee operand's Use.
Definition: InstrTypes.h:1419
void setAttributes(AttributeList A)
Set the parameter attributes for this call.
Definition: InstrTypes.h:1490
User::op_iterator arg_end()
Return the iterator pointing to the end of the argument list.
Definition: InstrTypes.h:1334
FunctionType * getFunctionType() const
Definition: InstrTypes.h:1266
AttributeList getAttributes() const
Return the parameter attributes for this call.
Definition: InstrTypes.h:1486
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Adds the attribute to the indicated argument.
Definition: InstrTypes.h:1538
Function * getCaller()
Helper to get the caller (the parent function).
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:110
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: DenseMap.h:202
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&... Args)
Definition: DenseMap.h:235
unsigned size() const
Definition: DenseMap.h:99
bool empty() const
Definition: DenseMap.h:98
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:220
Analysis pass which computes a DominatorTree.
Definition: Dominators.h:279
A proxy from a FunctionAnalysisManager to an SCC.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Definition: Function.h:136
void splice(Function::iterator ToIt, Function *FromF)
Transfer all blocks from FromF to this function at ToIt.
Definition: Function.h:692
iterator begin()
Definition: Function.h:756
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
Definition: Function.cpp:366
arg_iterator arg_begin()
Definition: Function.h:771
void setAttributes(AttributeList Attrs)
Set the attribute list for this Function.
Definition: Function.h:316
void copyAttributesFrom(const Function *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a Function) from the ...
Definition: Function.cpp:743
static Type * getTypeAtIndex(Type *Ty, Value *Idx)
Return the type of the element at the given index of an indexable type.
void copyMetadata(const GlobalObject *Src, unsigned Offset)
Copy metadata from Src, adjusting offsets by Offset.
Definition: Metadata.cpp:1550
Common base class shared among various IRBuilders.
Definition: IRBuilder.h:94
AllocaInst * CreateAlloca(Type *Ty, unsigned AddrSpace, Value *ArraySize=nullptr, const Twine &Name="")
Definition: IRBuilder.h:1702
LoadInst * CreateAlignedLoad(Type *Ty, Value *Ptr, MaybeAlign Align, const char *Name)
Definition: IRBuilder.h:1736
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2022
PointerType * getInt8PtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer to an 8-bit integer value.
Definition: IRBuilder.h:560
StoreInst * CreateAlignedStore(Value *Val, Value *Ptr, MaybeAlign Align, bool isVolatile=false)
Definition: IRBuilder.h:1755
Value * CreateGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="", bool IsInBounds=false)
Definition: IRBuilder.h:1795
IntegerType * getInt8Ty()
Fetch the type representing an 8-bit integer.
Definition: IRBuilder.h:502
ConstantInt * getInt(const APInt &AI)
Get a constant integer value.
Definition: IRBuilder.h:488
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:2564
void setAAMetadata(const AAMDNodes &N)
Sets the AA metadata on this instruction from the AAMDNodes structure.
Definition: Metadata.cpp:1513
const Function * getFunction() const
Return the function this instruction belongs to.
Definition: Instruction.cpp:74
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
Definition: Instruction.cpp:82
void copyMetadata(const Instruction &SrcInst, ArrayRef< unsigned > WL=ArrayRef< unsigned >())
Copy metadata from SrcInst to this instruction.
Invoke instruction.
static InvokeInst * Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, const Twine &NameStr, Instruction *InsertBefore=nullptr)
A node in the call graph.
An SCC of the call graph.
A lazily constructed view of the call graph of a module.
An instruction for reading from memory.
Definition: Instructions.h:177
static unsigned getPointerOperandIndex()
Definition: Instructions.h:266
Representation for a specific memory location.
static MemoryLocation get(const LoadInst *LI)
Return a location with information about the memory reference by the given instruction.
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Definition: Constants.cpp:1750
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:152
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:158
void preserveSet()
Mark an analysis set as preserved.
Definition: PassManager.h:188
void preserve()
Mark an analysis as preserved.
Definition: PassManager.h:173
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:365
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:450
bool empty() const
Definition: SmallVector.h:94
size_t size() const
Definition: SmallVector.h:91
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:577
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:941
void push_back(const T &Elt)
Definition: SmallVector.h:416
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
An instruction for storing to memory.
Definition: Instructions.h:301
static unsigned getPointerOperandIndex()
Definition: Instructions.h:395
Analysis pass providing the TargetTransformInfo.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
PointerType * getPointerTo(unsigned AddrSpace=0) const
Return a pointer to the current type.
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
Definition: Type.h:304
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Definition: Constants.cpp:1731
A Use represents the edge between a Value definition and its users.
Definition: Use.h:43
LLVM Value Representation.
Definition: Value.h:74
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:377
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition: Value.cpp:534
iterator_range< user_iterator > users()
Definition: Value.h:421
bool use_empty() const
Definition: Value.h:344
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:308
void takeName(Value *V)
Transfer the name from V to this value.
Definition: Value.cpp:383
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void updateMinLegalVectorWidthAttr(Function &Fn, uint64_t Width)
Update min-legal-vector-width if it is in Attribute and less than Width.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:406
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1819
void PromoteMemToReg(ArrayRef< AllocaInst * > Allocas, DominatorTree &DT, AssumptionCache *AC=nullptr)
Promote the specified list of alloca instructions into scalar registers, inserting PHI nodes as appro...
detail::scope_exit< std::decay_t< Callable > > make_scope_exit(Callable &&F)
Definition: ScopeExit.h:59
bool isAligned(Align Lhs, uint64_t SizeInBytes)
Checks that SizeInBytes is a multiple of the alignment.
Definition: Alignment.h:145
bool isDereferenceableAndAlignedPointer(const Value *V, Type *Ty, Align Alignment, const DataLayout &DL, const Instruction *CtxI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr, const TargetLibraryInfo *TLI=nullptr)
Returns true if V is always a dereferenceable pointer with alignment greater or equal than requested.
Definition: Loads.cpp:201
void append_range(Container &C, Range &&R)
Wrapper function to append a range to a container.
Definition: STLExtras.h:2129
bool isAllocaPromotable(const AllocaInst *AI)
Return true if this alloca is legal for promotion.
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1744
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
iterator_range< idf_ext_iterator< T, SetTy > > inverse_depth_first_ext(const T &G, SetTy &S)
bool RecursivelyDeleteTriviallyDeadInstructionsPermissive(SmallVectorImpl< WeakTrackingVH > &DeadInsts, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr, std::function< void(Value *)> AboutToDeleteCallback=std::function< void(Value *)>())
Same functionality as RecursivelyDeleteTriviallyDeadInstructions, but allow instructions that are not...
Definition: Local.cpp:552
bool isGuaranteedToTransferExecutionToSuccessor(const Instruction *I)
Return true if this function can prove that the instruction I will always transfer execution to one o...
auto predecessors(const MachineBasicBlock *BB)
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
Support structure for SCC passes to communicate updates the call graph back to the CGSCC pass manager...
Function object to check whether the first component of a container supported by std::get (like std::...
Definition: STLExtras.h:1537