94#include "llvm/IR/IntrinsicsPowerPC.h"
112#define DEBUG_TYPE "ppc-loop-instr-form-prep"
118 cl::desc(
"Potential common base number threshold per function "
119 "for PPC loop prep"));
123 cl::desc(
"prefer update form when ds form is also a update form"));
127 cl::desc(
"prepare update form when the load/store increment is a loop "
128 "invariant non-const value."));
132 cl::desc(
"Enable chain commoning in PPC loop prepare pass."));
139 cl::desc(
"Potential PHI threshold per loop for PPC loop prep of update "
144 cl::desc(
"Potential PHI threshold per loop for PPC loop prep of DS form"));
148 cl::desc(
"Potential PHI threshold per loop for PPC loop prep of DQ form"));
159 cl::desc(
"Bucket number per loop for PPC loop chain common"));
167 cl::desc(
"Minimal common base load/store instructions triggering DS/DQ form "
172 cl::desc(
"Minimal common base load/store instructions triggering chain "
173 "commoning preparation. Must be not smaller than 4"));
175STATISTIC(PHINodeAlreadyExistsUpdate,
"PHI node already in pre-increment form");
176STATISTIC(PHINodeAlreadyExistsDS,
"PHI node already in DS form");
177STATISTIC(PHINodeAlreadyExistsDQ,
"PHI node already in DQ form");
178STATISTIC(DSFormChainRewritten,
"Num of DS form chain rewritten");
179STATISTIC(DQFormChainRewritten,
"Num of DQ form chain rewritten");
180STATISTIC(UpdFormChainRewritten,
"Num of update form chain rewritten");
181STATISTIC(ChainCommoningRewritten,
"Num of commoning chains");
184 struct BucketElement {
186 BucketElement(Instruction *
I) : Offset(nullptr), Instr(
I) {}
193 Bucket(
const SCEV *
B, Instruction *
I)
194 : BaseSCEV(
B), Elements(1, BucketElement(
I)) {
199 const SCEV *BaseSCEV;
217 enum PrepForm { UpdateForm = 1, DSForm = 4, DQForm = 16, ChainCommoning };
223 PPCLoopInstrFormPrep(PPCTargetMachine &TM) : FunctionPass(ID), TM(&TM) {}
225 void getAnalysisUsage(AnalysisUsage &AU)
const override {
235 PPCTargetMachine *TM =
nullptr;
236 const PPCSubtarget *ST;
241 bool HasCandidateForPrepare;
247 unsigned SuccPrepCount;
249 bool runOnLoop(Loop *L);
252 bool alreadyPrepared(Loop *L, Instruction *MemI,
253 const SCEV *BasePtrStartSCEV,
254 const SCEV *BasePtrIncSCEV, PrepForm Form);
257 Value *getNodeForInc(Loop *L, Instruction *MemI,
258 const SCEV *BasePtrIncSCEV);
264 bool prepareBasesForCommoningChains(Bucket &BucketChain);
267 bool rewriteLoadStoresForCommoningChains(
268 Loop *L, Bucket &Bucket, SmallPtrSet<BasicBlock *, 16> &BBChanged);
274 std::function<
bool(
const Instruction *,
Value *,
const Type *)>
276 std::function<
bool(
const SCEV *)> isValidDiff,
277 unsigned MaxCandidateNum);
281 void addOneCandidate(Instruction *MemI,
const SCEV *LSCEV,
283 std::function<
bool(
const SCEV *)> isValidDiff,
284 unsigned MaxCandidateNum);
299 bool prepareBaseForDispFormChain(Bucket &BucketChain, PrepForm Form);
306 bool prepareBaseForUpdateFormChain(Bucket &BucketChain);
310 bool rewriteLoadStores(Loop *L, Bucket &BucketChain,
311 SmallPtrSet<BasicBlock *, 16> &BBChanged,
315 std::pair<Instruction *, Instruction *>
316 rewriteForBase(Loop *L,
const SCEVAddRecExpr *BasePtrSCEV,
317 Instruction *BaseMemI,
bool CanPreInc, PrepForm Form,
318 SCEVExpander &SCEVE, SmallPtrSet<Value *, 16> &DeletedPtrs);
323 rewriteForBucketElement(std::pair<Instruction *, Instruction *>
Base,
324 const BucketElement &Element,
Value *OffToBase,
325 SmallPtrSet<Value *, 16> &DeletedPtrs);
330char PPCLoopInstrFormPrep::ID = 0;
331static const char *
name =
"Prepare loop for ppc preferred instruction forms";
343 return new PPCLoopInstrFormPrep(TM);
347 Value *StrippedBasePtr = BasePtr;
349 StrippedBasePtr = BC->getOperand(0);
351 return GEP->isInBounds();
357 assert(
I &&
"Invalid paramater!");
359 return (
I->getName() + Suffix).str();
365 Type **PtrElementType =
nullptr) {
367 Value *PtrValue =
nullptr;
368 Type *PointerElementType =
nullptr;
371 PtrValue = LMemI->getPointerOperand();
372 PointerElementType = LMemI->getType();
374 PtrValue = SMemI->getPointerOperand();
375 PointerElementType = SMemI->getValueOperand()->getType();
378 if (IMemI->getIntrinsicID() == Intrinsic::prefetch ||
379 IMemI->getIntrinsicID() == Intrinsic::ppc_vsx_lxvp) {
380 PtrValue = IMemI->getArgOperand(0);
381 }
else if (IMemI->getIntrinsicID() == Intrinsic::ppc_vsx_stxvp) {
382 PtrValue = IMemI->getArgOperand(1);
387 *PtrElementType = PointerElementType;
392bool PPCLoopInstrFormPrep::runOnFunction(
Function &
F) {
396 LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
397 SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
398 auto *DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>();
399 DT = DTWP ? &DTWP->getDomTree() :
nullptr;
400 PreserveLCSSA = mustPreserveAnalysisID(
LCSSAID);
404 bool MadeChange =
false;
408 MadeChange |= runOnLoop(L);
419bool PPCLoopInstrFormPrep::prepareBasesForCommoningChains(Bucket &CBucket) {
436 "Thredhold can not be smaller than 4!\n");
442 const SCEV *FirstOffset = CBucket.Elements[1].Offset;
447 unsigned FirstOffsetReusedCount = 1;
451 unsigned FirstOffsetReusedCountInFirstChain = 1;
453 unsigned EleNum = CBucket.Elements.size();
454 bool SawChainSeparater =
false;
455 for (
unsigned j = 2;
j != EleNum; ++
j) {
457 CBucket.Elements[j - 1].Offset) == FirstOffset) {
458 if (!SawChainSeparater)
459 FirstOffsetReusedCountInFirstChain++;
460 FirstOffsetReusedCount++;
478 SawChainSeparater =
true;
482 if (FirstOffsetReusedCount == 1)
486 FirstOffsetReusedCount / FirstOffsetReusedCountInFirstChain;
490 if (!SawChainSeparater)
491 ChainNum = (unsigned)sqrt((
double)EleNum);
493 CBucket.ChainSize = (unsigned)(EleNum / ChainNum);
497 if (CBucket.ChainSize * ChainNum != EleNum)
500 if (SawChainSeparater) {
502 for (
unsigned i = 1; i < CBucket.ChainSize; i++)
503 for (
unsigned j = 1;
j < ChainNum;
j++)
504 if (CBucket.Elements[i].Offset !=
505 SE->
getMinusSCEV(CBucket.Elements[i + j * CBucket.ChainSize].Offset,
506 CBucket.Elements[j * CBucket.ChainSize].Offset))
510 for (
unsigned i = 0; i < ChainNum; i++)
511 CBucket.ChainBases.push_back(CBucket.Elements[i * CBucket.ChainSize]);
518bool PPCLoopInstrFormPrep::chainCommoning(Loop *L,
520 bool MadeChange =
false;
525 SmallPtrSet<BasicBlock *, 16> BBChanged;
527 for (
auto &Bucket : Buckets) {
528 if (prepareBasesForCommoningChains(Bucket))
529 MadeChange |= rewriteLoadStoresForCommoningChains(L, Bucket, BBChanged);
533 for (
auto *BB : BBChanged)
538bool PPCLoopInstrFormPrep::rewriteLoadStoresForCommoningChains(
539 Loop *L, Bucket &Bucket, SmallPtrSet<BasicBlock *, 16> &BBChanged) {
540 bool MadeChange =
false;
542 assert(Bucket.Elements.size() ==
543 Bucket.ChainBases.size() * Bucket.ChainSize &&
544 "invalid bucket for chain commoning!\n");
545 SmallPtrSet<Value *, 16> DeletedPtrs;
547 BasicBlock *LoopPredecessor =
L->getLoopPredecessor();
549 SCEVExpander SCEVE(*SE,
"loopprepare-chaincommon");
551 for (
unsigned ChainIdx = 0; ChainIdx < Bucket.ChainBases.size(); ++ChainIdx) {
552 unsigned BaseElemIdx = Bucket.ChainSize * ChainIdx;
553 const SCEV *BaseSCEV =
555 Bucket.Elements[BaseElemIdx].Offset)
560 if (!SCEVE.isSafeToExpand(BasePtrSCEV->
getStart()))
564 "Invalid SCEV type for the base ptr for a candidate chain!\n");
566 std::pair<Instruction *, Instruction *>
Base = rewriteForBase(
567 L, BasePtrSCEV, Bucket.Elements[BaseElemIdx].Instr,
568 false , ChainCommoning, SCEVE, DeletedPtrs);
575 SmallPtrSet<Value *, 16> NewPtrs;
578 for (
unsigned Idx = BaseElemIdx + 1; Idx < BaseElemIdx + Bucket.ChainSize;
580 BucketElement &
I = Bucket.Elements[Idx];
582 assert(Ptr &&
"No pointer operand");
583 if (NewPtrs.
count(Ptr))
586 const SCEV *OffsetSCEV =
587 BaseElemIdx ? SE->
getMinusSCEV(Bucket.Elements[Idx].Offset,
588 Bucket.Elements[BaseElemIdx].Offset)
589 : Bucket.Elements[Idx].Offset;
594 if (!SCEVE.isSafeToExpand(OffsetSCEV))
597 Value *OffsetValue = SCEVE.expandCodeFor(
600 Instruction *NewPtr = rewriteForBucketElement(
Base, Bucket.Elements[Idx],
601 OffsetValue, DeletedPtrs);
603 assert(NewPtr &&
"Wrong rewrite!\n");
607 ++ChainCommoningRewritten;
614 for (
auto *Ptr : DeletedPtrs) {
616 BBChanged.
insert(IDel->getParent());
636std::pair<Instruction *, Instruction *>
637PPCLoopInstrFormPrep::rewriteForBase(Loop *L,
const SCEVAddRecExpr *BasePtrSCEV,
638 Instruction *BaseMemI,
bool CanPreInc,
639 PrepForm Form, SCEVExpander &SCEVE,
640 SmallPtrSet<Value *, 16> &DeletedPtrs) {
642 LLVM_DEBUG(
dbgs() <<
"PIP: Transforming: " << *BasePtrSCEV <<
"\n");
644 assert(BasePtrSCEV->
getLoop() == L &&
"AddRec for the wrong loop?");
647 assert(BasePtr &&
"No pointer operand");
649 Type *I8Ty = Type::getInt8Ty(BaseMemI->
getParent()->getContext());
651 PointerType::get(BaseMemI->
getParent()->getContext(),
652 BasePtr->getType()->getPointerAddressSpace());
654 bool IsConstantInc =
false;
656 Value *IncNode = getNodeForInc(L, BaseMemI, BasePtrIncSCEV);
658 const SCEVConstant *BasePtrIncConstantSCEV =
660 if (BasePtrIncConstantSCEV)
661 IsConstantInc =
true;
665 LLVM_DEBUG(
dbgs() <<
"Loop Increasement can not be represented!\n");
666 return std::make_pair(
nullptr,
nullptr);
672 <<
"Update form prepare for non-const increment is not enabled!\n");
673 return std::make_pair(
nullptr,
nullptr);
676 const SCEV *BasePtrStartSCEV =
nullptr;
679 "Increment is not loop invariant!\n");
681 IsConstantInc ? BasePtrIncConstantSCEV
684 BasePtrStartSCEV = BasePtrSCEV->
getStart();
686 if (alreadyPrepared(L, BaseMemI, BasePtrStartSCEV, BasePtrIncSCEV, Form)) {
688 return std::make_pair(
nullptr,
nullptr);
691 LLVM_DEBUG(
dbgs() <<
"PIP: New start is: " << *BasePtrStartSCEV <<
"\n");
694 unsigned HeaderLoopPredCount =
pred_size(Header);
695 BasicBlock *LoopPredecessor =
L->getLoopPredecessor();
707 if (PI != LoopPredecessor)
710 NewPHI->
addIncoming(BasePtrStart, LoopPredecessor);
722 if (PI == LoopPredecessor)
729 new BitCastInst(PtrInc,
BasePtr->getType(),
737 if (PI == LoopPredecessor)
753 NewBasePtr =
new BitCastInst(NewPHI,
BasePtr->getType(),
755 Header->getFirstInsertionPt());
760 BasePtr->replaceAllUsesWith(NewBasePtr);
762 DeletedPtrs.
insert(BasePtr);
764 return std::make_pair(NewBasePtr, PtrInc);
767Instruction *PPCLoopInstrFormPrep::rewriteForBucketElement(
768 std::pair<Instruction *, Instruction *>
Base,
const BucketElement &Element,
769 Value *OffToBase, SmallPtrSet<Value *, 16> &DeletedPtrs) {
772 assert((NewBasePtr && PtrInc) &&
"base does not exist!\n");
774 Type *I8Ty = Type::getInt8Ty(PtrInc->
getParent()->getContext());
777 assert(Ptr &&
"No pointer operand");
780 if (!Element.Offset ||
783 RealNewPtr = NewBasePtr;
785 std::optional<BasicBlock::iterator> PtrIP = std::nullopt;
787 PtrIP =
I->getIterator();
791 PtrIP = std::nullopt;
793 PtrIP = (*PtrIP)->getParent()->getFirstInsertionPt();
797 assert(OffToBase &&
"There should be an offset for non base element!\n");
799 I8Ty, PtrInc, OffToBase,
811 ReplNewPtr =
new BitCastInst(RealNewPtr, Ptr->
getType(),
815 ReplNewPtr = RealNewPtr;
823void PPCLoopInstrFormPrep::addOneCandidate(
825 std::function<
bool(
const SCEV *)> isValidDiff,
unsigned MaxCandidateNum) {
827 "Candidate should be a memory instruction.");
828 assert(LSCEV &&
"Invalid SCEV for Ptr value.");
830 bool FoundBucket =
false;
831 for (
auto &
B : Buckets) {
836 if (isValidDiff(Diff)) {
837 B.Elements.push_back(BucketElement(Diff, MemI));
844 if (Buckets.size() == MaxCandidateNum) {
845 LLVM_DEBUG(
dbgs() <<
"Can not prepare more chains, reach maximum limit "
846 << MaxCandidateNum <<
"\n");
849 Buckets.push_back(Bucket(LSCEV, MemI));
855 std::function<
bool(
const Instruction *,
Value *,
const Type *)>
857 std::function<
bool(
const SCEV *)> isValidDiff,
unsigned MaxCandidateNum) {
860 for (
const auto &BB :
L->blocks())
861 for (
auto &J : *BB) {
862 Value *PtrValue =
nullptr;
863 Type *PointerElementType =
nullptr;
872 if (
L->isLoopInvariant(PtrValue))
877 if (!LARSCEV || LARSCEV->
getLoop() != L)
881 HasCandidateForPrepare =
true;
883 if (isValidCandidate(&J, PtrValue, PointerElementType))
884 addOneCandidate(&J, LSCEV, Buckets, isValidDiff, MaxCandidateNum);
889bool PPCLoopInstrFormPrep::prepareBaseForDispFormChain(Bucket &BucketChain,
897 DenseMap<unsigned, std::pair<unsigned, unsigned>> RemainderOffsetInfo;
899 for (
unsigned j = 0, je = BucketChain.Elements.size(); j != je; ++j) {
900 if (!BucketChain.Elements[j].Offset)
901 RemainderOffsetInfo[0] = std::make_pair(0, 1);
906 if (!RemainderOffsetInfo.
contains(Remainder))
907 RemainderOffsetInfo[Remainder] = std::make_pair(j, 1);
909 RemainderOffsetInfo[Remainder].second++;
927 unsigned MaxCountRemainder = 0;
928 for (
unsigned j = 0;
j < (unsigned)
Form;
j++)
929 if (
auto It = RemainderOffsetInfo.
find(j);
930 It != RemainderOffsetInfo.
end() &&
931 It->second.second > RemainderOffsetInfo[MaxCountRemainder].second)
932 MaxCountRemainder =
j;
940 if (MaxCountRemainder == 0)
945 BucketChain.Elements[RemainderOffsetInfo[MaxCountRemainder].first].Offset;
947 for (
auto &
E : BucketChain.Elements) {
954 std::swap(BucketChain.Elements[RemainderOffsetInfo[MaxCountRemainder].first],
955 BucketChain.Elements[0]);
965bool PPCLoopInstrFormPrep::prepareBaseForUpdateFormChain(Bucket &BucketChain) {
975 for (
int j = 0, je = BucketChain.Elements.size(); j != je; ++j) {
977 if (
II->getIntrinsicID() == Intrinsic::prefetch)
986 if (!BucketChain.Elements[j].Offset ||
990 const SCEV *
Offset = BucketChain.Elements[
j].Offset;
992 for (
auto &
E : BucketChain.Elements) {
999 std::swap(BucketChain.Elements[j], BucketChain.Elements[0]);
1005bool PPCLoopInstrFormPrep::rewriteLoadStores(
1006 Loop *L, Bucket &BucketChain, SmallPtrSet<BasicBlock *, 16> &BBChanged,
1008 bool MadeChange =
false;
1010 const SCEVAddRecExpr *BasePtrSCEV =
1015 SCEVExpander SCEVE(*SE,
"loopprepare-formrewrite");
1019 SmallPtrSet<Value *, 16> DeletedPtrs;
1024 bool CanPreInc = (
Form == UpdateForm ||
1025 ((
Form == DSForm) &&
1032 std::pair<Instruction *, Instruction *>
Base =
1033 rewriteForBase(L, BasePtrSCEV, BucketChain.Elements.begin()->Instr,
1034 CanPreInc, Form, SCEVE, DeletedPtrs);
1041 SmallPtrSet<Value *, 16> NewPtrs;
1046 assert(Ptr &&
"No pointer operand");
1047 if (NewPtrs.
count(Ptr))
1054 assert(NewPtr &&
"wrong rewrite!\n");
1062 for (
auto *Ptr : DeletedPtrs) {
1064 BBChanged.
insert(IDel->getParent());
1072 if (Form == DSForm && !CanPreInc)
1073 DSFormChainRewritten++;
1074 else if (Form == DQForm)
1075 DQFormChainRewritten++;
1076 else if (Form == UpdateForm || (Form == DSForm && CanPreInc))
1077 UpdFormChainRewritten++;
1082bool PPCLoopInstrFormPrep::updateFormPrep(Loop *L,
1084 bool MadeChange =
false;
1085 if (Buckets.
empty())
1087 SmallPtrSet<BasicBlock *, 16> BBChanged;
1088 for (
auto &Bucket : Buckets)
1091 if (prepareBaseForUpdateFormChain(Bucket))
1092 MadeChange |= rewriteLoadStores(L, Bucket, BBChanged, UpdateForm);
1095 for (
auto *BB : BBChanged)
1100bool PPCLoopInstrFormPrep::dispFormPrep(Loop *L,
1103 bool MadeChange =
false;
1105 if (Buckets.
empty())
1108 SmallPtrSet<BasicBlock *, 16> BBChanged;
1109 for (
auto &Bucket : Buckets) {
1112 if (prepareBaseForDispFormChain(Bucket, Form))
1113 MadeChange |= rewriteLoadStores(L, Bucket, BBChanged, Form);
1117 for (
auto *BB : BBChanged)
1130Value *PPCLoopInstrFormPrep::getNodeForInc(Loop *L, Instruction *MemI,
1131 const SCEV *BasePtrIncSCEV) {
1152 for (
auto &CurrentPHI : PHIIter) {
1154 if (!CurrentPHINode)
1163 if (!PHIBasePtrSCEV)
1168 if (!PHIBasePtrIncSCEV || (PHIBasePtrIncSCEV != BasePtrIncSCEV))
1177 Value *StrippedBaseI =
I;
1179 StrippedBaseI = BC->getOperand(0);
1187 if (StrippedI->
getOpcode() == Instruction::Add ||
1188 (StrippedI->
getOpcode() == Instruction::GetElementPtr &&
1204bool PPCLoopInstrFormPrep::alreadyPrepared(Loop *L, Instruction *MemI,
1205 const SCEV *BasePtrStartSCEV,
1206 const SCEV *BasePtrIncSCEV,
1215 if (!PredBB || !LatchBB)
1220 for (
auto & CurrentPHI : PHIIter) {
1222 if (!CurrentPHINode)
1231 if (!PHIBasePtrSCEV)
1234 const SCEVConstant *PHIBasePtrIncSCEV =
1236 if (!PHIBasePtrIncSCEV)
1244 if (PHIBasePtrIncSCEV == BasePtrIncSCEV) {
1247 if ((Form == UpdateForm || Form == ChainCommoning ) &&
1248 PHIBasePtrSCEV->
getStart() == BasePtrStartSCEV) {
1249 ++PHINodeAlreadyExistsUpdate;
1252 if (Form == DSForm || Form == DQForm) {
1257 ++PHINodeAlreadyExistsDS;
1259 ++PHINodeAlreadyExistsDQ;
1270bool PPCLoopInstrFormPrep::runOnLoop(Loop *L) {
1271 bool MadeChange =
false;
1274 if (!
L->isInnermost())
1283 BasicBlock *LoopPredecessor =
L->getLoopPredecessor();
1287 if (!LoopPredecessor ||
1290 if (LoopPredecessor)
1293 if (!LoopPredecessor) {
1294 LLVM_DEBUG(
dbgs() <<
"PIP fails since no predecessor for current loop.\n");
1300 const Type *PointerElementType) {
1301 assert((PtrValue &&
I) &&
"Invalid parameter!");
1303 if (ST &&
ST->hasAltivec() && PointerElementType->
isVectorTy())
1307 if (
II && ((
II->getIntrinsicID() == Intrinsic::ppc_vsx_lxvp) ||
1308 II->getIntrinsicID() == Intrinsic::ppc_vsx_stxvp))
1318 if (!LARSCEV || LARSCEV->
getLoop() != L)
1320 if (
const SCEVConstant *StepConst =
1322 const APInt &ConstInt = StepConst->getValue()->getValue();
1332 const Type *PointerElementType) {
1333 assert((PtrValue &&
I) &&
"Invalid parameter!");
1341 [](
const User *U) { return isa<SExtInst>(U); }));
1346 const Type *PointerElementType) {
1347 assert((PtrValue &&
I) &&
"Invalid parameter!");
1351 return II->getIntrinsicID() == Intrinsic::ppc_vsx_lxvp ||
1352 II->getIntrinsicID() == Intrinsic::ppc_vsx_stxvp;
1354 return ST &&
ST->hasP9Vector() && (PointerElementType->
isVectorTy());
1361 const Type *PointerElementType) {
1362 const SCEVAddRecExpr *ARSCEV =
1384 bool SawPointer =
false;
1386 if (
Op->getType()->isPointerTy()) {
1390 }
else if (!
Op->getType()->isIntegerTy())
1399 auto isValidConstantDiff = [](
const SCEV *Diff) {
1405 auto isValidChainCommoningDiff = [](
const SCEV *Diff) {
1406 assert(Diff &&
"Invalid Diff!\n");
1421 if (!
Op->getType()->isIntegerTy())
1427 HasCandidateForPrepare =
false;
1436 if (!UpdateFormBuckets.
empty())
1437 MadeChange |= updateFormPrep(L, UpdateFormBuckets);
1438 else if (!HasCandidateForPrepare) {
1441 <<
"No prepare candidates found, stop praparation for current loop!\n");
1453 if (!DSFormBuckets.
empty())
1454 MadeChange |= dispFormPrep(L, DSFormBuckets, DSForm);
1463 if (!DQFormBuckets.
empty())
1464 MadeChange |= dispFormPrep(L, DQFormBuckets, DQForm);
1476 collectCandidates(L, isChainCommoningCandidate, isValidChainCommoningDiff,
1480 if (!Buckets.
empty())
1481 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.
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.