94#include "llvm/IR/IntrinsicsPowerPC.h"
111#define DEBUG_TYPE "ppc-loop-instr-form-prep"
115STATISTIC(PHINodeAlreadyExistsUpdate,
"PHI node already in pre-increment form");
116STATISTIC(PHINodeAlreadyExistsDS,
"PHI node already in DS form");
117STATISTIC(PHINodeAlreadyExistsDQ,
"PHI node already in DQ form");
118STATISTIC(DSFormChainRewritten,
"Num of DS form chain rewritten");
119STATISTIC(DQFormChainRewritten,
"Num of DQ form chain rewritten");
120STATISTIC(UpdFormChainRewritten,
"Num of update form chain rewritten");
121STATISTIC(ChainCommoningRewritten,
"Num of commoning chains");
124 struct BucketElement {
126 BucketElement(Instruction *
I) : Offset(nullptr), Instr(
I) {}
133 Bucket(
const SCEV *
B, Instruction *
I)
134 : BaseSCEV(
B), Elements(1, BucketElement(
I)) {
139 const SCEV *BaseSCEV;
157 enum PrepForm { UpdateForm = 1, DSForm = 4, DQForm = 16, ChainCommoning };
163 PPCLoopInstrFormPrep(PPCTargetMachine &TM)
164 : FunctionPass(ID), CLOpts(TM.
getCLOpts()), TM(&TM) {}
166 void getAnalysisUsage(AnalysisUsage &AU)
const override {
176 const PPCOptions &CLOpts;
177 PPCTargetMachine *TM =
nullptr;
178 const PPCSubtarget *ST;
183 bool HasCandidateForPrepare;
189 unsigned SuccPrepCount;
191 bool runOnLoop(
Loop *L);
194 bool alreadyPrepared(
Loop *L, Instruction *MemI,
195 const SCEV *BasePtrStartSCEV,
196 const SCEV *BasePtrIncSCEV, PrepForm Form);
199 Value *getNodeForInc(
Loop *L, Instruction *MemI,
200 const SCEV *BasePtrIncSCEV);
206 bool prepareBasesForCommoningChains(Bucket &BucketChain);
209 bool rewriteLoadStoresForCommoningChains(
210 Loop *L, Bucket &Bucket, SmallPtrSet<BasicBlock *, 16> &BBChanged);
216 std::function<
bool(
const Instruction *,
Value *,
const Type *)>
218 std::function<
bool(
const SCEV *)> isValidDiff,
219 unsigned MaxCandidateNum);
223 void addOneCandidate(Instruction *MemI,
const SCEV *LSCEV,
225 std::function<
bool(
const SCEV *)> isValidDiff,
226 unsigned MaxCandidateNum);
241 bool prepareBaseForDispFormChain(Bucket &BucketChain, PrepForm Form);
248 bool prepareBaseForUpdateFormChain(Bucket &BucketChain);
252 bool rewriteLoadStores(
Loop *L, Bucket &BucketChain,
253 SmallPtrSet<BasicBlock *, 16> &BBChanged,
257 std::pair<Instruction *, Instruction *>
258 rewriteForBase(
Loop *L,
const SCEVAddRecExpr *BasePtrSCEV,
259 Instruction *BaseMemI,
bool CanPreInc, PrepForm Form,
260 SCEVExpander &SCEVE, SmallPtrSet<Value *, 16> &DeletedPtrs);
265 rewriteForBucketElement(std::pair<Instruction *, Instruction *>
Base,
266 const BucketElement &Element,
Value *OffToBase,
267 SmallPtrSet<Value *, 16> &DeletedPtrs);
272char PPCLoopInstrFormPrep::ID = 0;
273static const char *
name =
"Prepare loop for ppc preferred instruction forms";
285 return new PPCLoopInstrFormPrep(TM);
289 Value *StrippedBasePtr = BasePtr;
291 StrippedBasePtr = BC->getOperand(0);
293 return GEP->isInBounds();
299 assert(
I &&
"Invalid paramater!");
301 return (
I->getName() + Suffix).str();
307 Type **PtrElementType =
nullptr) {
309 Value *PtrValue =
nullptr;
310 Type *PointerElementType =
nullptr;
313 PtrValue = LMemI->getPointerOperand();
314 PointerElementType = LMemI->getType();
316 PtrValue = SMemI->getPointerOperand();
317 PointerElementType = SMemI->getValueOperand()->getType();
320 if (IMemI->getIntrinsicID() == Intrinsic::prefetch ||
321 IMemI->getIntrinsicID() == Intrinsic::ppc_vsx_lxvp) {
322 PtrValue = IMemI->getArgOperand(0);
323 }
else if (IMemI->getIntrinsicID() == Intrinsic::ppc_vsx_stxvp) {
324 PtrValue = IMemI->getArgOperand(1);
329 *PtrElementType = PointerElementType;
334bool PPCLoopInstrFormPrep::runOnFunction(
Function &
F) {
338 LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
339 SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
340 auto *DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>();
341 DT = DTWP ? &DTWP->getDomTree() :
nullptr;
342 PreserveLCSSA = mustPreserveAnalysisID(
LCSSAID);
346 bool MadeChange =
false;
350 MadeChange |= runOnLoop(L);
361bool PPCLoopInstrFormPrep::prepareBasesForCommoningChains(Bucket &CBucket) {
377 assert(CLOpts.chaincommon_min_threshold >= 4 &&
378 "Thredhold can not be smaller than 4!\n");
379 if (CBucket.Elements.size() < CLOpts.chaincommon_min_threshold)
384 const SCEV *FirstOffset = CBucket.Elements[1].Offset;
389 unsigned FirstOffsetReusedCount = 1;
393 unsigned FirstOffsetReusedCountInFirstChain = 1;
395 unsigned EleNum = CBucket.Elements.size();
396 bool SawChainSeparater =
false;
397 for (
unsigned j = 2;
j != EleNum; ++
j) {
399 CBucket.Elements[j - 1].Offset) == FirstOffset) {
400 if (!SawChainSeparater)
401 FirstOffsetReusedCountInFirstChain++;
402 FirstOffsetReusedCount++;
420 SawChainSeparater =
true;
424 if (FirstOffsetReusedCount == 1)
428 FirstOffsetReusedCount / FirstOffsetReusedCountInFirstChain;
432 if (!SawChainSeparater)
433 ChainNum = (unsigned)sqrt((
double)EleNum);
435 CBucket.ChainSize = (unsigned)(EleNum / ChainNum);
439 if (CBucket.ChainSize * ChainNum != EleNum)
442 if (SawChainSeparater) {
444 for (
unsigned i = 1; i < CBucket.ChainSize; i++)
445 for (
unsigned j = 1;
j < ChainNum;
j++)
446 if (CBucket.Elements[i].Offset !=
447 SE->
getMinusSCEV(CBucket.Elements[i + j * CBucket.ChainSize].Offset,
448 CBucket.Elements[j * CBucket.ChainSize].Offset))
452 for (
unsigned i = 0; i < ChainNum; i++)
453 CBucket.ChainBases.push_back(CBucket.Elements[i * CBucket.ChainSize]);
460bool PPCLoopInstrFormPrep::chainCommoning(
Loop *L,
462 bool MadeChange =
false;
467 SmallPtrSet<BasicBlock *, 16> BBChanged;
469 for (
auto &Bucket : Buckets) {
470 if (prepareBasesForCommoningChains(Bucket))
471 MadeChange |= rewriteLoadStoresForCommoningChains(L, Bucket, BBChanged);
475 for (
auto *BB : BBChanged)
480bool PPCLoopInstrFormPrep::rewriteLoadStoresForCommoningChains(
481 Loop *L, Bucket &Bucket, SmallPtrSet<BasicBlock *, 16> &BBChanged) {
482 bool MadeChange =
false;
484 assert(Bucket.Elements.size() ==
485 Bucket.ChainBases.size() * Bucket.ChainSize &&
486 "invalid bucket for chain commoning!\n");
487 SmallPtrSet<Value *, 16> DeletedPtrs;
489 BasicBlock *LoopPredecessor =
L->getLoopPredecessor();
491 SCEVExpander SCEVE(*SE,
"loopprepare-chaincommon");
493 for (
unsigned ChainIdx = 0; ChainIdx < Bucket.ChainBases.size(); ++ChainIdx) {
494 unsigned BaseElemIdx = Bucket.ChainSize * ChainIdx;
495 const SCEV *BaseSCEV =
497 Bucket.Elements[BaseElemIdx].Offset)
503 if (!SCEVE.isSafeToExpand(BasePtrSCEV->
getStart()))
507 "Invalid SCEV type for the base ptr for a candidate chain!\n");
509 std::pair<Instruction *, Instruction *>
Base = rewriteForBase(
510 L, BasePtrSCEV, Bucket.Elements[BaseElemIdx].Instr,
511 false , ChainCommoning, SCEVE, DeletedPtrs);
518 SmallPtrSet<Value *, 16> NewPtrs;
521 for (
unsigned Idx = BaseElemIdx + 1;
Idx < BaseElemIdx + Bucket.ChainSize;
523 BucketElement &
I = Bucket.Elements[
Idx];
525 assert(Ptr &&
"No pointer operand");
526 if (NewPtrs.
count(Ptr))
529 const SCEV *OffsetSCEV =
530 BaseElemIdx ? SE->
getMinusSCEV(Bucket.Elements[Idx].Offset,
531 Bucket.Elements[BaseElemIdx].Offset)
532 : Bucket.Elements[
Idx].Offset;
537 if (!SCEVE.isSafeToExpand(OffsetSCEV))
540 Value *OffsetValue = SCEVE.expandCodeFor(
543 Instruction *NewPtr = rewriteForBucketElement(
Base, Bucket.Elements[Idx],
544 OffsetValue, DeletedPtrs);
546 assert(NewPtr &&
"Wrong rewrite!\n");
550 ++ChainCommoningRewritten;
557 for (
auto *Ptr : DeletedPtrs) {
559 BBChanged.
insert(IDel->getParent());
579std::pair<Instruction *, Instruction *>
580PPCLoopInstrFormPrep::rewriteForBase(
Loop *L,
const SCEVAddRecExpr *BasePtrSCEV,
581 Instruction *BaseMemI,
bool CanPreInc,
582 PrepForm Form, SCEVExpander &SCEVE,
583 SmallPtrSet<Value *, 16> &DeletedPtrs) {
585 LLVM_DEBUG(
dbgs() <<
"PIP: Transforming: " << *BasePtrSCEV <<
"\n");
587 assert(BasePtrSCEV->
getLoop() == L &&
"AddRec for the wrong loop?");
590 assert(BasePtr &&
"No pointer operand");
592 Type *I8Ty = Type::getInt8Ty(BaseMemI->
getParent()->getContext());
594 PointerType::get(BaseMemI->
getParent()->getContext(),
595 BasePtr->getType()->getPointerAddressSpace());
597 bool IsConstantInc =
false;
599 Value *IncNode = getNodeForInc(L, BaseMemI, BasePtrIncSCEV);
601 const SCEVConstant *BasePtrIncConstantSCEV =
603 if (BasePtrIncConstantSCEV)
604 IsConstantInc =
true;
608 LLVM_DEBUG(
dbgs() <<
"Loop Increasement can not be represented!\n");
609 return std::make_pair(
nullptr,
nullptr);
612 if (Form == UpdateForm && !IsConstantInc &&
613 !CLOpts.formprep_update_nonconst_inc) {
616 <<
"Update form prepare for non-const increment is not enabled!\n");
617 return std::make_pair(
nullptr,
nullptr);
620 const SCEV *BasePtrStartSCEV =
nullptr;
623 "Increment is not loop invariant!\n");
625 IsConstantInc ? BasePtrIncConstantSCEV
628 BasePtrStartSCEV = BasePtrSCEV->
getStart();
630 if (alreadyPrepared(L, BaseMemI, BasePtrStartSCEV, BasePtrIncSCEV, Form)) {
632 return std::make_pair(
nullptr,
nullptr);
635 LLVM_DEBUG(
dbgs() <<
"PIP: New start is: " << *BasePtrStartSCEV <<
"\n");
638 unsigned HeaderLoopPredCount =
pred_size(Header);
639 BasicBlock *LoopPredecessor =
L->getLoopPredecessor();
651 if (PI != LoopPredecessor)
654 NewPHI->
addIncoming(BasePtrStart, LoopPredecessor);
666 if (PI == LoopPredecessor)
673 new BitCastInst(PtrInc,
BasePtr->getType(),
681 if (PI == LoopPredecessor)
697 NewBasePtr =
new BitCastInst(NewPHI,
BasePtr->getType(),
699 Header->getFirstInsertionPt());
704 BasePtr->replaceAllUsesWith(NewBasePtr);
706 DeletedPtrs.
insert(BasePtr);
708 return std::make_pair(NewBasePtr, PtrInc);
711Instruction *PPCLoopInstrFormPrep::rewriteForBucketElement(
712 std::pair<Instruction *, Instruction *>
Base,
const BucketElement &Element,
713 Value *OffToBase, SmallPtrSet<Value *, 16> &DeletedPtrs) {
716 assert((NewBasePtr && PtrInc) &&
"base does not exist!\n");
718 Type *I8Ty = Type::getInt8Ty(PtrInc->
getParent()->getContext());
721 assert(Ptr &&
"No pointer operand");
724 if (!Element.Offset ||
727 RealNewPtr = NewBasePtr;
729 std::optional<BasicBlock::iterator> PtrIP = std::nullopt;
731 PtrIP =
I->getIterator();
735 PtrIP = std::nullopt;
737 PtrIP = (*PtrIP)->getParent()->getFirstInsertionPt();
741 assert(OffToBase &&
"There should be an offset for non base element!\n");
743 I8Ty, PtrInc, OffToBase,
755 ReplNewPtr =
new BitCastInst(RealNewPtr, Ptr->
getType(),
759 ReplNewPtr = RealNewPtr;
767void PPCLoopInstrFormPrep::addOneCandidate(
769 std::function<
bool(
const SCEV *)> isValidDiff,
unsigned MaxCandidateNum) {
771 "Candidate should be a memory instruction.");
772 assert(LSCEV &&
"Invalid SCEV for Ptr value.");
774 bool FoundBucket =
false;
775 for (
auto &
B : Buckets) {
780 if (isValidDiff(Diff)) {
781 B.Elements.push_back(BucketElement(Diff, MemI));
788 if (Buckets.size() == MaxCandidateNum) {
789 LLVM_DEBUG(
dbgs() <<
"Can not prepare more chains, reach maximum limit "
790 << MaxCandidateNum <<
"\n");
793 Buckets.push_back(Bucket(LSCEV, MemI));
799 std::function<
bool(
const Instruction *,
Value *,
const Type *)>
801 std::function<
bool(
const SCEV *)> isValidDiff,
unsigned MaxCandidateNum) {
804 for (
const auto &BB :
L->blocks())
805 for (
auto &J : *BB) {
806 Value *PtrValue =
nullptr;
807 Type *PointerElementType =
nullptr;
816 if (
L->isLoopInvariant(PtrValue))
821 if (!LARSCEV || LARSCEV->
getLoop() != L)
825 HasCandidateForPrepare =
true;
827 if (isValidCandidate(&J, PtrValue, PointerElementType))
828 addOneCandidate(&J, LSCEV, Buckets, isValidDiff, MaxCandidateNum);
833bool PPCLoopInstrFormPrep::prepareBaseForDispFormChain(Bucket &BucketChain,
841 DenseMap<unsigned, std::pair<unsigned, unsigned>> RemainderOffsetInfo;
843 for (
unsigned j = 0, je = BucketChain.Elements.size(); j != je; ++j) {
844 if (!BucketChain.Elements[j].Offset)
845 RemainderOffsetInfo[0] = std::make_pair(0, 1);
850 if (!RemainderOffsetInfo.
contains(Remainder))
851 RemainderOffsetInfo[Remainder] = std::make_pair(j, 1);
853 RemainderOffsetInfo[Remainder].second++;
871 unsigned MaxCountRemainder = 0;
872 for (
unsigned j = 0;
j < (unsigned)
Form;
j++)
873 if (
auto It = RemainderOffsetInfo.
find(j);
874 It != RemainderOffsetInfo.
end() &&
875 It->second.second > RemainderOffsetInfo[MaxCountRemainder].second)
876 MaxCountRemainder =
j;
879 if (RemainderOffsetInfo[MaxCountRemainder].second <
880 CLOpts.dispprep_min_threshold)
885 if (MaxCountRemainder == 0)
890 BucketChain.Elements[RemainderOffsetInfo[MaxCountRemainder].first].Offset;
892 for (
auto &
E : BucketChain.Elements) {
899 std::swap(BucketChain.Elements[RemainderOffsetInfo[MaxCountRemainder].first],
900 BucketChain.Elements[0]);
910bool PPCLoopInstrFormPrep::prepareBaseForUpdateFormChain(Bucket &BucketChain) {
920 for (
int j = 0, je = BucketChain.Elements.size(); j != je; ++j) {
922 if (
II->getIntrinsicID() == Intrinsic::prefetch)
931 if (!BucketChain.Elements[j].Offset ||
935 const SCEV *
Offset = BucketChain.Elements[
j].Offset;
937 for (
auto &
E : BucketChain.Elements) {
944 std::swap(BucketChain.Elements[j], BucketChain.Elements[0]);
950bool PPCLoopInstrFormPrep::rewriteLoadStores(
951 Loop *L, Bucket &BucketChain, SmallPtrSet<BasicBlock *, 16> &BBChanged,
953 bool MadeChange =
false;
955 const SCEVAddRecExpr *BasePtrSCEV =
960 SCEVExpander SCEVE(*SE,
"loopprepare-formrewrite");
964 SmallPtrSet<Value *, 16> DeletedPtrs;
969 bool CanPreInc = (
Form == UpdateForm ||
975 CLOpts.formprep_prefer_update));
977 std::pair<Instruction *, Instruction *>
Base =
978 rewriteForBase(L, BasePtrSCEV, BucketChain.Elements.begin()->Instr,
979 CanPreInc, Form, SCEVE, DeletedPtrs);
986 SmallPtrSet<Value *, 16> NewPtrs;
991 assert(Ptr &&
"No pointer operand");
992 if (NewPtrs.
count(Ptr))
999 assert(NewPtr &&
"wrong rewrite!\n");
1007 for (
auto *Ptr : DeletedPtrs) {
1009 BBChanged.
insert(IDel->getParent());
1017 if (Form == DSForm && !CanPreInc)
1018 DSFormChainRewritten++;
1019 else if (Form == DQForm)
1020 DQFormChainRewritten++;
1021 else if (Form == UpdateForm || (Form == DSForm && CanPreInc))
1022 UpdFormChainRewritten++;
1027bool PPCLoopInstrFormPrep::updateFormPrep(
Loop *L,
1029 bool MadeChange =
false;
1030 if (Buckets.
empty())
1032 SmallPtrSet<BasicBlock *, 16> BBChanged;
1033 for (
auto &Bucket : Buckets)
1036 if (prepareBaseForUpdateFormChain(Bucket))
1037 MadeChange |= rewriteLoadStores(L, Bucket, BBChanged, UpdateForm);
1040 for (
auto *BB : BBChanged)
1045bool PPCLoopInstrFormPrep::dispFormPrep(
Loop *L,
1048 bool MadeChange =
false;
1050 if (Buckets.
empty())
1053 SmallPtrSet<BasicBlock *, 16> BBChanged;
1054 for (
auto &Bucket : Buckets) {
1055 if (Bucket.Elements.size() < CLOpts.dispprep_min_threshold)
1057 if (prepareBaseForDispFormChain(Bucket, Form))
1058 MadeChange |= rewriteLoadStores(L, Bucket, BBChanged, Form);
1062 for (
auto *BB : BBChanged)
1075Value *PPCLoopInstrFormPrep::getNodeForInc(
Loop *L, Instruction *MemI,
1076 const SCEV *BasePtrIncSCEV) {
1097 for (
auto &CurrentPHI : PHIIter) {
1099 if (!CurrentPHINode)
1108 if (!PHIBasePtrSCEV)
1113 if (!PHIBasePtrIncSCEV || (PHIBasePtrIncSCEV != BasePtrIncSCEV))
1122 Value *StrippedBaseI =
I;
1124 StrippedBaseI = BC->getOperand(0);
1132 if (StrippedI->
getOpcode() == Instruction::Add ||
1133 (StrippedI->
getOpcode() == Instruction::GetElementPtr &&
1149bool PPCLoopInstrFormPrep::alreadyPrepared(
Loop *L, Instruction *MemI,
1150 const SCEV *BasePtrStartSCEV,
1151 const SCEV *BasePtrIncSCEV,
1160 if (!PredBB || !LatchBB)
1165 for (
auto & CurrentPHI : PHIIter) {
1167 if (!CurrentPHINode)
1176 if (!PHIBasePtrSCEV)
1179 const SCEVConstant *PHIBasePtrIncSCEV =
1181 if (!PHIBasePtrIncSCEV)
1189 if (PHIBasePtrIncSCEV == BasePtrIncSCEV) {
1192 if ((Form == UpdateForm || Form == ChainCommoning ) &&
1193 PHIBasePtrSCEV->
getStart() == BasePtrStartSCEV) {
1194 ++PHINodeAlreadyExistsUpdate;
1197 if (Form == DSForm || Form == DQForm) {
1202 ++PHINodeAlreadyExistsDS;
1204 ++PHINodeAlreadyExistsDQ;
1215bool PPCLoopInstrFormPrep::runOnLoop(
Loop *L) {
1216 bool MadeChange =
false;
1219 if (!
L->isInnermost())
1223 if (SuccPrepCount >= CLOpts.formprep_max_vars)
1228 BasicBlock *LoopPredecessor =
L->getLoopPredecessor();
1232 if (!LoopPredecessor ||
1235 if (LoopPredecessor)
1238 if (!LoopPredecessor) {
1239 LLVM_DEBUG(
dbgs() <<
"PIP fails since no predecessor for current loop.\n");
1245 const Type *PointerElementType) {
1246 assert((PtrValue &&
I) &&
"Invalid parameter!");
1248 if (ST &&
ST->hasAltivec() && PointerElementType->
isVectorTy())
1252 if (
II && ((
II->getIntrinsicID() == Intrinsic::ppc_vsx_lxvp) ||
1253 II->getIntrinsicID() == Intrinsic::ppc_vsx_stxvp))
1263 if (!LARSCEV || LARSCEV->
getLoop() != L)
1265 if (
const SCEVConstant *StepConst =
1267 const APInt &ConstInt = StepConst->getValue()->getValue();
1277 const Type *PointerElementType) {
1278 assert((PtrValue &&
I) &&
"Invalid parameter!");
1286 [](
const User *U) { return isa<SExtInst>(U); }));
1291 const Type *PointerElementType) {
1292 assert((PtrValue &&
I) &&
"Invalid parameter!");
1296 return II->getIntrinsicID() == Intrinsic::ppc_vsx_lxvp ||
1297 II->getIntrinsicID() == Intrinsic::ppc_vsx_stxvp;
1299 return ST &&
ST->hasP9Vector() && (PointerElementType->
isVectorTy());
1306 const Type *PointerElementType) {
1307 const SCEVAddRecExpr *ARSCEV =
1329 bool SawPointer =
false;
1331 if (
Op->getType()->isPointerTy()) {
1335 }
else if (!
Op->getType()->isIntegerTy())
1344 auto isValidConstantDiff = [](
const SCEV *Diff) {
1350 auto isValidChainCommoningDiff = [](
const SCEV *Diff) {
1351 assert(Diff &&
"Invalid Diff!\n");
1366 if (!
Op->getType()->isIntegerTy())
1372 HasCandidateForPrepare =
false;
1378 collectCandidates(L, isUpdateFormCandidate, isValidConstantDiff,
1379 CLOpts.preinc_prep_max_vars);
1382 if (!UpdateFormBuckets.
empty())
1383 MadeChange |= updateFormPrep(L, UpdateFormBuckets);
1384 else if (!HasCandidateForPrepare) {
1387 <<
"No prepare candidates found, stop praparation for current loop!\n");
1396 L, isDSFormCandidate, isValidConstantDiff, CLOpts.dsprep_max_vars);
1399 if (!DSFormBuckets.
empty())
1400 MadeChange |= dispFormPrep(L, DSFormBuckets, DSForm);
1406 L, isDQFormCandidate, isValidConstantDiff, CLOpts.dqprep_max_vars);
1409 if (!DQFormBuckets.
empty())
1410 MadeChange |= dispFormPrep(L, DQFormBuckets, DQForm);
1415 if (!CLOpts.formprep_chain_commoning) {
1422 collectCandidates(L, isChainCommoningCandidate, isValidChainCommoningDiff,
1423 CLOpts.chaincommon_max_vars);
1426 if (!Buckets.
empty())
1427 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; assumes that the block is well-formed.
This class represents a no-op cast from one type to another.
bool contains(const_arg_type_t< KeyT > Val) const
Return true if the specified key is in the map, false otherwise.
iterator find(const_arg_type_t< KeyT > Val)
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...
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
SCEVUse getStepRecurrence(ScalarEvolution &SE) const
Constructs and returns the recurrence indicating how much this expression steps by.
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(SCEVUse SH, Type *Ty, BasicBlock::iterator I)
Insert code to directly compute the specified SCEV expression into the program.
ArrayRef< SCEVUse > operands() const
This class represents an analyzed expression in the program.
Type * getType() const
Return the LLVM type of this SCEV expression.
LLVM_ABI const SCEV * getMinusSCEV(SCEVUse LHS, SCEVUse RHS, SCEVFlags Flags=SCEV::FlagNone, unsigned Depth=0)
Return LHS-RHS.
LLVM_ABI SCEVUse 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 SCEVUse getAddExpr(SmallVectorImpl< SCEVUse > &Ops, SCEVFlagsPair Flags={}, unsigned Depth=0)
Get a canonical add expression, or something simpler if possible.
LLVM_ABI bool isSCEVable(Type *Ty) const
Test if values of the given type are analyzable within the SCEV framework.
LLVM_ABI const SCEV * getNegativeSCEV(const SCEV *V, SCEVFlags Flags=SCEV::FlagNone)
Return the SCEV object corresponding to -V.
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.
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()
const AArch64MCOptions & getCLOpts(const MCTargetOptions &Options)
@ BasicBlock
Various leaf nodes.
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.
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.
LLVM_ABI bool DeleteDeadPHIs(BasicBlock *BB, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr, SmallPtrSetImpl< PHINode * > *KnownNonDeadPHIs=nullptr)
Examine each PHI in the given block and delete it if it is dead.
auto pred_size(const MachineBasicBlock *BB)
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
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 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.
SCEVPtrT getPointer() const