94#include "llvm/IR/IntrinsicsPowerPC.h"
111#define DEBUG_TYPE "ppc-loop-instr-form-prep"
117 cl::desc(
"Potential common base number threshold per function "
118 "for PPC loop prep"));
122 cl::desc(
"prefer update form when ds form is also a update form"));
126 cl::desc(
"prepare update form when the load/store increment is a loop "
127 "invariant non-const value."));
131 cl::desc(
"Enable chain commoning in PPC loop prepare pass."));
138 cl::desc(
"Potential PHI threshold per loop for PPC loop prep of update "
143 cl::desc(
"Potential PHI threshold per loop for PPC loop prep of DS form"));
147 cl::desc(
"Potential PHI threshold per loop for PPC loop prep of DQ form"));
158 cl::desc(
"Bucket number per loop for PPC loop chain common"));
166 cl::desc(
"Minimal common base load/store instructions triggering DS/DQ form "
171 cl::desc(
"Minimal common base load/store instructions triggering chain "
172 "commoning preparation. Must be not smaller than 4"));
174STATISTIC(PHINodeAlreadyExistsUpdate,
"PHI node already in pre-increment form");
175STATISTIC(PHINodeAlreadyExistsDS,
"PHI node already in DS form");
176STATISTIC(PHINodeAlreadyExistsDQ,
"PHI node already in DQ form");
177STATISTIC(DSFormChainRewritten,
"Num of DS form chain rewritten");
178STATISTIC(DQFormChainRewritten,
"Num of DQ form chain rewritten");
179STATISTIC(UpdFormChainRewritten,
"Num of update form chain rewritten");
180STATISTIC(ChainCommoningRewritten,
"Num of commoning chains");
183 struct BucketElement {
185 BucketElement(Instruction *
I) : Offset(nullptr), Instr(
I) {}
192 Bucket(
const SCEV *
B, Instruction *
I)
193 : BaseSCEV(
B), Elements(1, BucketElement(
I)) {
198 const SCEV *BaseSCEV;
216 enum PrepForm { UpdateForm = 1, DSForm = 4, DQForm = 16, ChainCommoning };
222 PPCLoopInstrFormPrep(PPCTargetMachine &TM) : FunctionPass(ID), TM(&TM) {}
224 void getAnalysisUsage(AnalysisUsage &AU)
const override {
234 PPCTargetMachine *TM =
nullptr;
235 const PPCSubtarget *ST;
240 bool HasCandidateForPrepare;
246 unsigned SuccPrepCount;
248 bool runOnLoop(Loop *L);
251 bool alreadyPrepared(Loop *L, Instruction *MemI,
252 const SCEV *BasePtrStartSCEV,
253 const SCEV *BasePtrIncSCEV, PrepForm Form);
256 Value *getNodeForInc(Loop *L, Instruction *MemI,
257 const SCEV *BasePtrIncSCEV);
263 bool prepareBasesForCommoningChains(Bucket &BucketChain);
266 bool rewriteLoadStoresForCommoningChains(
267 Loop *L, Bucket &Bucket, SmallPtrSet<BasicBlock *, 16> &BBChanged);
273 std::function<
bool(
const Instruction *,
Value *,
const Type *)>
275 std::function<
bool(
const SCEV *)> isValidDiff,
276 unsigned MaxCandidateNum);
280 void addOneCandidate(Instruction *MemI,
const SCEV *LSCEV,
282 std::function<
bool(
const SCEV *)> isValidDiff,
283 unsigned MaxCandidateNum);
298 bool prepareBaseForDispFormChain(Bucket &BucketChain, PrepForm Form);
305 bool prepareBaseForUpdateFormChain(Bucket &BucketChain);
309 bool rewriteLoadStores(Loop *L, Bucket &BucketChain,
310 SmallPtrSet<BasicBlock *, 16> &BBChanged,
314 std::pair<Instruction *, Instruction *>
315 rewriteForBase(Loop *L,
const SCEVAddRecExpr *BasePtrSCEV,
316 Instruction *BaseMemI,
bool CanPreInc, PrepForm Form,
317 SCEVExpander &SCEVE, SmallPtrSet<Value *, 16> &DeletedPtrs);
322 rewriteForBucketElement(std::pair<Instruction *, Instruction *>
Base,
323 const BucketElement &Element,
Value *OffToBase,
324 SmallPtrSet<Value *, 16> &DeletedPtrs);
329char PPCLoopInstrFormPrep::ID = 0;
330static const char *
name =
"Prepare loop for ppc preferred instruction forms";
342 return new PPCLoopInstrFormPrep(TM);
346 Value *StrippedBasePtr = BasePtr;
348 StrippedBasePtr = BC->getOperand(0);
350 return GEP->isInBounds();
356 assert(
I &&
"Invalid paramater!");
358 return (
I->getName() + Suffix).str();
364 Type **PtrElementType =
nullptr) {
366 Value *PtrValue =
nullptr;
367 Type *PointerElementType =
nullptr;
370 PtrValue = LMemI->getPointerOperand();
371 PointerElementType = LMemI->getType();
373 PtrValue = SMemI->getPointerOperand();
374 PointerElementType = SMemI->getValueOperand()->getType();
377 if (IMemI->getIntrinsicID() == Intrinsic::prefetch ||
378 IMemI->getIntrinsicID() == Intrinsic::ppc_vsx_lxvp) {
379 PtrValue = IMemI->getArgOperand(0);
380 }
else if (IMemI->getIntrinsicID() == Intrinsic::ppc_vsx_stxvp) {
381 PtrValue = IMemI->getArgOperand(1);
386 *PtrElementType = PointerElementType;
391bool PPCLoopInstrFormPrep::runOnFunction(
Function &
F) {
395 LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
396 SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
397 auto *DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>();
398 DT = DTWP ? &DTWP->getDomTree() :
nullptr;
399 PreserveLCSSA = mustPreserveAnalysisID(
LCSSAID);
403 bool MadeChange =
false;
407 MadeChange |= runOnLoop(L);
418bool PPCLoopInstrFormPrep::prepareBasesForCommoningChains(Bucket &CBucket) {
435 "Thredhold can not be smaller than 4!\n");
441 const SCEV *FirstOffset = CBucket.Elements[1].Offset;
446 unsigned FirstOffsetReusedCount = 1;
450 unsigned FirstOffsetReusedCountInFirstChain = 1;
452 unsigned EleNum = CBucket.Elements.size();
453 bool SawChainSeparater =
false;
454 for (
unsigned j = 2;
j != EleNum; ++
j) {
456 CBucket.Elements[j - 1].Offset) == FirstOffset) {
457 if (!SawChainSeparater)
458 FirstOffsetReusedCountInFirstChain++;
459 FirstOffsetReusedCount++;
477 SawChainSeparater =
true;
481 if (FirstOffsetReusedCount == 1)
485 FirstOffsetReusedCount / FirstOffsetReusedCountInFirstChain;
489 if (!SawChainSeparater)
490 ChainNum = (unsigned)sqrt((
double)EleNum);
492 CBucket.ChainSize = (unsigned)(EleNum / ChainNum);
496 if (CBucket.ChainSize * ChainNum != EleNum)
499 if (SawChainSeparater) {
501 for (
unsigned i = 1; i < CBucket.ChainSize; i++)
502 for (
unsigned j = 1;
j < ChainNum;
j++)
503 if (CBucket.Elements[i].Offset !=
504 SE->
getMinusSCEV(CBucket.Elements[i + j * CBucket.ChainSize].Offset,
505 CBucket.Elements[j * CBucket.ChainSize].Offset))
509 for (
unsigned i = 0; i < ChainNum; i++)
510 CBucket.ChainBases.push_back(CBucket.Elements[i * CBucket.ChainSize]);
517bool PPCLoopInstrFormPrep::chainCommoning(Loop *L,
519 bool MadeChange =
false;
524 SmallPtrSet<BasicBlock *, 16> BBChanged;
526 for (
auto &Bucket : Buckets) {
527 if (prepareBasesForCommoningChains(Bucket))
528 MadeChange |= rewriteLoadStoresForCommoningChains(L, Bucket, BBChanged);
532 for (
auto *BB : BBChanged)
537bool PPCLoopInstrFormPrep::rewriteLoadStoresForCommoningChains(
538 Loop *L, Bucket &Bucket, SmallPtrSet<BasicBlock *, 16> &BBChanged) {
539 bool MadeChange =
false;
541 assert(Bucket.Elements.size() ==
542 Bucket.ChainBases.size() * Bucket.ChainSize &&
543 "invalid bucket for chain commoning!\n");
544 SmallPtrSet<Value *, 16> DeletedPtrs;
546 BasicBlock *LoopPredecessor =
L->getLoopPredecessor();
548 SCEVExpander SCEVE(*SE,
"loopprepare-chaincommon");
550 for (
unsigned ChainIdx = 0; ChainIdx < Bucket.ChainBases.size(); ++ChainIdx) {
551 unsigned BaseElemIdx = Bucket.ChainSize * ChainIdx;
552 const SCEV *BaseSCEV =
554 Bucket.Elements[BaseElemIdx].Offset)
559 if (!SCEVE.isSafeToExpand(BasePtrSCEV->
getStart()))
563 "Invalid SCEV type for the base ptr for a candidate chain!\n");
565 std::pair<Instruction *, Instruction *>
Base = rewriteForBase(
566 L, BasePtrSCEV, Bucket.Elements[BaseElemIdx].Instr,
567 false , ChainCommoning, SCEVE, DeletedPtrs);
574 SmallPtrSet<Value *, 16> NewPtrs;
577 for (
unsigned Idx = BaseElemIdx + 1; Idx < BaseElemIdx + Bucket.ChainSize;
579 BucketElement &
I = Bucket.Elements[Idx];
581 assert(Ptr &&
"No pointer operand");
582 if (NewPtrs.
count(Ptr))
585 const SCEV *OffsetSCEV =
586 BaseElemIdx ? SE->
getMinusSCEV(Bucket.Elements[Idx].Offset,
587 Bucket.Elements[BaseElemIdx].Offset)
588 : Bucket.Elements[Idx].Offset;
593 if (!SCEVE.isSafeToExpand(OffsetSCEV))
596 Value *OffsetValue = SCEVE.expandCodeFor(
599 Instruction *NewPtr = rewriteForBucketElement(
Base, Bucket.Elements[Idx],
600 OffsetValue, DeletedPtrs);
602 assert(NewPtr &&
"Wrong rewrite!\n");
606 ++ChainCommoningRewritten;
613 for (
auto *Ptr : DeletedPtrs) {
615 BBChanged.
insert(IDel->getParent());
635std::pair<Instruction *, Instruction *>
636PPCLoopInstrFormPrep::rewriteForBase(Loop *L,
const SCEVAddRecExpr *BasePtrSCEV,
637 Instruction *BaseMemI,
bool CanPreInc,
638 PrepForm Form, SCEVExpander &SCEVE,
639 SmallPtrSet<Value *, 16> &DeletedPtrs) {
641 LLVM_DEBUG(
dbgs() <<
"PIP: Transforming: " << *BasePtrSCEV <<
"\n");
643 assert(BasePtrSCEV->
getLoop() == L &&
"AddRec for the wrong loop?");
646 assert(BasePtr &&
"No pointer operand");
648 Type *I8Ty = Type::getInt8Ty(BaseMemI->
getParent()->getContext());
650 PointerType::get(BaseMemI->
getParent()->getContext(),
651 BasePtr->getType()->getPointerAddressSpace());
653 bool IsConstantInc =
false;
655 Value *IncNode = getNodeForInc(L, BaseMemI, BasePtrIncSCEV);
657 const SCEVConstant *BasePtrIncConstantSCEV =
659 if (BasePtrIncConstantSCEV)
660 IsConstantInc =
true;
664 LLVM_DEBUG(
dbgs() <<
"Loop Increasement can not be represented!\n");
665 return std::make_pair(
nullptr,
nullptr);
671 <<
"Update form prepare for non-const increment is not enabled!\n");
672 return std::make_pair(
nullptr,
nullptr);
675 const SCEV *BasePtrStartSCEV =
nullptr;
678 "Increment is not loop invariant!\n");
680 IsConstantInc ? BasePtrIncConstantSCEV
683 BasePtrStartSCEV = BasePtrSCEV->
getStart();
685 if (alreadyPrepared(L, BaseMemI, BasePtrStartSCEV, BasePtrIncSCEV, Form)) {
687 return std::make_pair(
nullptr,
nullptr);
690 LLVM_DEBUG(
dbgs() <<
"PIP: New start is: " << *BasePtrStartSCEV <<
"\n");
693 unsigned HeaderLoopPredCount =
pred_size(Header);
694 BasicBlock *LoopPredecessor =
L->getLoopPredecessor();
706 if (PI != LoopPredecessor)
709 NewPHI->
addIncoming(BasePtrStart, LoopPredecessor);
721 if (PI == LoopPredecessor)
728 new BitCastInst(PtrInc,
BasePtr->getType(),
736 if (PI == LoopPredecessor)
752 NewBasePtr =
new BitCastInst(NewPHI,
BasePtr->getType(),
754 Header->getFirstInsertionPt());
759 BasePtr->replaceAllUsesWith(NewBasePtr);
761 DeletedPtrs.
insert(BasePtr);
763 return std::make_pair(NewBasePtr, PtrInc);
766Instruction *PPCLoopInstrFormPrep::rewriteForBucketElement(
767 std::pair<Instruction *, Instruction *>
Base,
const BucketElement &Element,
768 Value *OffToBase, SmallPtrSet<Value *, 16> &DeletedPtrs) {
771 assert((NewBasePtr && PtrInc) &&
"base does not exist!\n");
773 Type *I8Ty = Type::getInt8Ty(PtrInc->
getParent()->getContext());
776 assert(Ptr &&
"No pointer operand");
779 if (!Element.Offset ||
782 RealNewPtr = NewBasePtr;
784 std::optional<BasicBlock::iterator> PtrIP = std::nullopt;
786 PtrIP =
I->getIterator();
790 PtrIP = std::nullopt;
792 PtrIP = (*PtrIP)->getParent()->getFirstInsertionPt();
796 assert(OffToBase &&
"There should be an offset for non base element!\n");
798 I8Ty, PtrInc, OffToBase,
810 ReplNewPtr =
new BitCastInst(RealNewPtr, Ptr->
getType(),
814 ReplNewPtr = RealNewPtr;
822void PPCLoopInstrFormPrep::addOneCandidate(
824 std::function<
bool(
const SCEV *)> isValidDiff,
unsigned MaxCandidateNum) {
826 "Candidate should be a memory instruction.");
827 assert(LSCEV &&
"Invalid SCEV for Ptr value.");
829 bool FoundBucket =
false;
830 for (
auto &
B : Buckets) {
835 if (isValidDiff(Diff)) {
836 B.Elements.push_back(BucketElement(Diff, MemI));
843 if (Buckets.size() == MaxCandidateNum) {
844 LLVM_DEBUG(
dbgs() <<
"Can not prepare more chains, reach maximum limit "
845 << MaxCandidateNum <<
"\n");
848 Buckets.push_back(Bucket(LSCEV, MemI));
854 std::function<
bool(
const Instruction *,
Value *,
const Type *)>
856 std::function<
bool(
const SCEV *)> isValidDiff,
unsigned MaxCandidateNum) {
859 for (
const auto &BB :
L->blocks())
860 for (
auto &J : *BB) {
861 Value *PtrValue =
nullptr;
862 Type *PointerElementType =
nullptr;
871 if (
L->isLoopInvariant(PtrValue))
876 if (!LARSCEV || LARSCEV->
getLoop() != L)
880 HasCandidateForPrepare =
true;
882 if (isValidCandidate(&J, PtrValue, PointerElementType))
883 addOneCandidate(&J, LSCEV, Buckets, isValidDiff, MaxCandidateNum);
888bool PPCLoopInstrFormPrep::prepareBaseForDispFormChain(Bucket &BucketChain,
896 DenseMap<unsigned, std::pair<unsigned, unsigned>> RemainderOffsetInfo;
898 for (
unsigned j = 0, je = BucketChain.Elements.size(); j != je; ++j) {
899 if (!BucketChain.Elements[j].Offset)
900 RemainderOffsetInfo[0] = std::make_pair(0, 1);
905 if (!RemainderOffsetInfo.
contains(Remainder))
906 RemainderOffsetInfo[Remainder] = std::make_pair(j, 1);
908 RemainderOffsetInfo[Remainder].second++;
926 unsigned MaxCountRemainder = 0;
927 for (
unsigned j = 0;
j < (unsigned)
Form;
j++)
928 if (
auto It = RemainderOffsetInfo.
find(j);
929 It != RemainderOffsetInfo.
end() &&
930 It->second.second > RemainderOffsetInfo[MaxCountRemainder].second)
931 MaxCountRemainder =
j;
939 if (MaxCountRemainder == 0)
944 BucketChain.Elements[RemainderOffsetInfo[MaxCountRemainder].first].Offset;
946 for (
auto &
E : BucketChain.Elements) {
953 std::swap(BucketChain.Elements[RemainderOffsetInfo[MaxCountRemainder].first],
954 BucketChain.Elements[0]);
964bool PPCLoopInstrFormPrep::prepareBaseForUpdateFormChain(Bucket &BucketChain) {
974 for (
int j = 0, je = BucketChain.Elements.size(); j != je; ++j) {
976 if (
II->getIntrinsicID() == Intrinsic::prefetch)
985 if (!BucketChain.Elements[j].Offset ||
989 const SCEV *
Offset = BucketChain.Elements[
j].Offset;
991 for (
auto &
E : BucketChain.Elements) {
998 std::swap(BucketChain.Elements[j], BucketChain.Elements[0]);
1004bool PPCLoopInstrFormPrep::rewriteLoadStores(
1005 Loop *L, Bucket &BucketChain, SmallPtrSet<BasicBlock *, 16> &BBChanged,
1007 bool MadeChange =
false;
1009 const SCEVAddRecExpr *BasePtrSCEV =
1014 SCEVExpander SCEVE(*SE,
"loopprepare-formrewrite");
1018 SmallPtrSet<Value *, 16> DeletedPtrs;
1023 bool CanPreInc = (
Form == UpdateForm ||
1024 ((
Form == DSForm) &&
1031 std::pair<Instruction *, Instruction *>
Base =
1032 rewriteForBase(L, BasePtrSCEV, BucketChain.Elements.begin()->Instr,
1033 CanPreInc, Form, SCEVE, DeletedPtrs);
1040 SmallPtrSet<Value *, 16> NewPtrs;
1045 assert(Ptr &&
"No pointer operand");
1046 if (NewPtrs.
count(Ptr))
1053 assert(NewPtr &&
"wrong rewrite!\n");
1061 for (
auto *Ptr : DeletedPtrs) {
1063 BBChanged.
insert(IDel->getParent());
1071 if (Form == DSForm && !CanPreInc)
1072 DSFormChainRewritten++;
1073 else if (Form == DQForm)
1074 DQFormChainRewritten++;
1075 else if (Form == UpdateForm || (Form == DSForm && CanPreInc))
1076 UpdFormChainRewritten++;
1081bool PPCLoopInstrFormPrep::updateFormPrep(Loop *L,
1083 bool MadeChange =
false;
1084 if (Buckets.
empty())
1086 SmallPtrSet<BasicBlock *, 16> BBChanged;
1087 for (
auto &Bucket : Buckets)
1090 if (prepareBaseForUpdateFormChain(Bucket))
1091 MadeChange |= rewriteLoadStores(L, Bucket, BBChanged, UpdateForm);
1094 for (
auto *BB : BBChanged)
1099bool PPCLoopInstrFormPrep::dispFormPrep(Loop *L,
1102 bool MadeChange =
false;
1104 if (Buckets.
empty())
1107 SmallPtrSet<BasicBlock *, 16> BBChanged;
1108 for (
auto &Bucket : Buckets) {
1111 if (prepareBaseForDispFormChain(Bucket, Form))
1112 MadeChange |= rewriteLoadStores(L, Bucket, BBChanged, Form);
1116 for (
auto *BB : BBChanged)
1129Value *PPCLoopInstrFormPrep::getNodeForInc(Loop *L, Instruction *MemI,
1130 const SCEV *BasePtrIncSCEV) {
1151 for (
auto &CurrentPHI : PHIIter) {
1153 if (!CurrentPHINode)
1162 if (!PHIBasePtrSCEV)
1167 if (!PHIBasePtrIncSCEV || (PHIBasePtrIncSCEV != BasePtrIncSCEV))
1176 Value *StrippedBaseI =
I;
1178 StrippedBaseI = BC->getOperand(0);
1186 if (StrippedI->
getOpcode() == Instruction::Add ||
1187 (StrippedI->
getOpcode() == Instruction::GetElementPtr &&
1203bool PPCLoopInstrFormPrep::alreadyPrepared(Loop *L, Instruction *MemI,
1204 const SCEV *BasePtrStartSCEV,
1205 const SCEV *BasePtrIncSCEV,
1214 if (!PredBB || !LatchBB)
1219 for (
auto & CurrentPHI : PHIIter) {
1221 if (!CurrentPHINode)
1230 if (!PHIBasePtrSCEV)
1233 const SCEVConstant *PHIBasePtrIncSCEV =
1235 if (!PHIBasePtrIncSCEV)
1243 if (PHIBasePtrIncSCEV == BasePtrIncSCEV) {
1246 if ((Form == UpdateForm || Form == ChainCommoning ) &&
1247 PHIBasePtrSCEV->
getStart() == BasePtrStartSCEV) {
1248 ++PHINodeAlreadyExistsUpdate;
1251 if (Form == DSForm || Form == DQForm) {
1256 ++PHINodeAlreadyExistsDS;
1258 ++PHINodeAlreadyExistsDQ;
1269bool PPCLoopInstrFormPrep::runOnLoop(Loop *L) {
1270 bool MadeChange =
false;
1273 if (!
L->isInnermost())
1282 BasicBlock *LoopPredecessor =
L->getLoopPredecessor();
1286 if (!LoopPredecessor ||
1289 if (LoopPredecessor)
1292 if (!LoopPredecessor) {
1293 LLVM_DEBUG(
dbgs() <<
"PIP fails since no predecessor for current loop.\n");
1299 const Type *PointerElementType) {
1300 assert((PtrValue &&
I) &&
"Invalid parameter!");
1302 if (ST &&
ST->hasAltivec() && PointerElementType->
isVectorTy())
1306 if (
II && ((
II->getIntrinsicID() == Intrinsic::ppc_vsx_lxvp) ||
1307 II->getIntrinsicID() == Intrinsic::ppc_vsx_stxvp))
1317 if (!LARSCEV || LARSCEV->
getLoop() != L)
1319 if (
const SCEVConstant *StepConst =
1321 const APInt &ConstInt = StepConst->getValue()->getValue();
1331 const Type *PointerElementType) {
1332 assert((PtrValue &&
I) &&
"Invalid parameter!");
1340 [](
const User *U) { return isa<SExtInst>(U); }));
1345 const Type *PointerElementType) {
1346 assert((PtrValue &&
I) &&
"Invalid parameter!");
1350 return II->getIntrinsicID() == Intrinsic::ppc_vsx_lxvp ||
1351 II->getIntrinsicID() == Intrinsic::ppc_vsx_stxvp;
1353 return ST &&
ST->hasP9Vector() && (PointerElementType->
isVectorTy());
1360 const Type *PointerElementType) {
1361 const SCEVAddRecExpr *ARSCEV =
1383 bool SawPointer =
false;
1385 if (
Op->getType()->isPointerTy()) {
1389 }
else if (!
Op->getType()->isIntegerTy())
1398 auto isValidConstantDiff = [](
const SCEV *Diff) {
1404 auto isValidChainCommoningDiff = [](
const SCEV *Diff) {
1405 assert(Diff &&
"Invalid Diff!\n");
1420 if (!
Op->getType()->isIntegerTy())
1426 HasCandidateForPrepare =
false;
1435 if (!UpdateFormBuckets.
empty())
1436 MadeChange |= updateFormPrep(L, UpdateFormBuckets);
1437 else if (!HasCandidateForPrepare) {
1440 <<
"No prepare candidates found, stop praparation for current loop!\n");
1452 if (!DSFormBuckets.
empty())
1453 MadeChange |= dispFormPrep(L, DSFormBuckets, DSForm);
1462 if (!DQFormBuckets.
empty())
1463 MadeChange |= dispFormPrep(L, DQFormBuckets, DQForm);
1475 collectCandidates(L, isChainCommoningCandidate, isValidChainCommoningDiff,
1479 if (!Buckets.
empty())
1480 MadeChange |= chainCommoning(L, Buckets);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static const Function * getParent(const Value *V)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file builds on the ADT/GraphTraits.h file to build generic depth first graph iterator.
static bool runOnFunction(Function &F, bool PostInlining)
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
uint64_t IntrinsicInst * II
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
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)
LLVM_ABI APInt urem(const APInt &RHS) const
Unsigned remainder operation.
bool isSignedIntN(unsigned N) const
Check if this APInt has an N-bits signed integer value.
LLVM_ABI APInt srem(const APInt &RHS) const
Function for signed remainder operation.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
InstListType::iterator iterator
Instruction iterators...
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
This class represents a no-op cast from one type to another.
iterator find(const_arg_type_t< KeyT > Val)
bool contains(const_arg_type_t< KeyT > Val) const
Return true if the specified key is in the map, false otherwise.
FunctionPass class - This class is used to implement most global optimizations.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
LLVM_ABI void setIsInBounds(bool b=true)
Set or clear the inbounds flag on this GEP instruction.
Module * getParent()
Get the module that this global value is contained inside of...
LLVM_ABI void insertBefore(InstListType::iterator InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified position.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
LLVM_ABI void insertAfter(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately after the specified instruction.
A wrapper class for inspecting calls to intrinsic functions.
An instruction for reading from memory.
The legacy pass manager's analysis pass to compute loop information.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
Value * getIncomingValueForBlock(const BasicBlock *BB) const
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
int getBasicBlockIndex(const BasicBlock *BB) const
Return the first index of the specified basic block in the value list for this PHI.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
Common code between 32-bit and 64-bit PowerPC targets.
const PPCSubtarget * getSubtargetImpl(const Function &F) const override
Virtual method implemented by subclasses that returns a reference to that target's TargetSubtargetInf...
const SCEV * getStart() const
const SCEV * getStepRecurrence(ScalarEvolution &SE) const
Constructs and returns the recurrence indicating how much this expression steps by.
bool isAffine() const
Return true if this represents an expression A + B*x where A and B are loop invariant values.
const Loop * getLoop() const
const APInt & getAPInt() const
LLVM_ABI bool isSafeToExpand(const SCEV *S) const
Return true if the given expression is safe to expand in the sense that all materialized values are s...
void clear()
Erase the contents of the InsertedExpressions map so that users trying to expand the same expression ...
LLVM_ABI Value * expandCodeFor(const SCEV *SH, Type *Ty, BasicBlock::iterator I)
Insert code to directly compute the specified SCEV expression into the program.
ArrayRef< const SCEV * > operands() const
This class represents an analyzed expression in the program.
LLVM_ABI Type * getType() const
Return the LLVM type of this SCEV expression.
LLVM_ABI const SCEV * getNegativeSCEV(const SCEV *V, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap)
Return the SCEV object corresponding to -V.
LLVM_ABI const SCEV * getSCEVAtScope(const SCEV *S, const Loop *L)
Return a SCEV expression for the specified value at the specified scope in the program.
LLVM_ABI bool isLoopInvariant(const SCEV *S, const Loop *L)
Return true if the value of the given SCEV is unchanging in the specified loop.
LLVM_ABI bool isSCEVable(Type *Ty) const
Test if values of the given type are analyzable within the SCEV framework.
LLVM_ABI const SCEV * getMinusSCEV(const SCEV *LHS, const SCEV *RHS, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
Return LHS-RHS.
LLVM_ABI const SCEV * getAddExpr(SmallVectorImpl< const SCEV * > &Ops, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
Get a canonical add expression, or something simpler if possible.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
An instruction for storing to memory.
StringRef - Represent a constant reference to a string, i.e.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isVectorTy() const
True if this is an instance of VectorType.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
bool isIntegerTy() const
True if this is an instance of IntegerType.
bool isVoidTy() const
Return true if this is 'void'.
Value * getOperand(unsigned i) const
unsigned getNumOperands() const
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
LLVM_ABI LLVMContext & getContext() const
All values hold a context through their type.
const ParentTy * getParent() const
self_iterator getIterator()
@ BasicBlock
Various leaf nodes.
initializer< Ty > init(const Ty &Val)
friend class Instruction
Iterator for Instructions in a `BasicBlock.
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
FunctionAddr VTableAddr Value
LLVM_ABI BasicBlock * InsertPreheaderForLoop(Loop *L, DominatorTree *DT, LoopInfo *LI, MemorySSAUpdater *MSSAU, bool PreserveLCSSA)
InsertPreheaderForLoop - Once we discover that a loop doesn't have a preheader, this method is called...
LLVM_ABI bool RecursivelyDeleteTriviallyDeadInstructions(Value *V, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr, std::function< void(Value *)> AboutToDeleteCallback=std::function< void(Value *)>())
If the specified value is a trivially dead instruction, delete it.
FunctionPass * createPPCLoopInstrFormPrepPass(PPCTargetMachine &TM)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
auto pred_size(const MachineBasicBlock *BB)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI bool DeleteDeadPHIs(BasicBlock *BB, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr)
Examine each PHI in the given block and delete it if it is dead.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
iterator_range(Container &&) -> iterator_range< llvm::detail::IterOfRange< Container > >
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
auto predecessors(const MachineBasicBlock *BB)
iterator_range< df_iterator< T > > depth_first(const T &G)
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.