10 #define DEBUG_TYPE "commgep"
69 typedef std::set<GepNode*>
NodeSet;
70 typedef std::map<GepNode*,Value*> NodeToValueMap;
71 typedef std::vector<GepNode*> NodeVect;
72 typedef std::map<GepNode*,NodeVect> NodeChildrenMap;
73 typedef std::set<Use*> UseSet;
74 typedef std::map<GepNode*,UseSet> NodeToUsesMap;
79 NodeOrdering() =
default;
81 void insert(
const GepNode *
N) { Map.insert(std::make_pair(N, ++LastNum)); }
82 void clear() { Map.clear(); }
84 bool operator()(
const GepNode *N1,
const GepNode *N2)
const {
85 auto F1 = Map.find(N1), F2 = Map.find(N2);
86 assert(F1 != Map.end() && F2 != Map.end());
87 return F1->second < F2->second;
91 std::map<const GepNode *, unsigned> Map;
103 bool runOnFunction(
Function &
F)
override;
104 StringRef getPassName()
const override {
return "Hexagon Common GEP"; }
117 typedef std::map<Value*,GepNode*> ValueToNodeMap;
118 typedef std::vector<Value*> ValueVect;
119 typedef std::map<GepNode*,ValueVect> NodeToValuesMap;
121 void getBlockTraversalOrder(
BasicBlock *Root, ValueVect &Order);
127 BasicBlock *recalculatePlacement(GepNode *Node, NodeChildrenMap &NCM,
128 NodeToValueMap &Loc);
129 BasicBlock *recalculatePlacementRec(GepNode *Node, NodeChildrenMap &NCM,
130 NodeToValueMap &Loc);
132 bool isInvariantIn(GepNode *Node,
Loop *
L);
134 BasicBlock *adjustForInvariance(GepNode *Node, NodeChildrenMap &NCM,
135 NodeToValueMap &Loc);
136 void separateChainForNode(GepNode *Node,
Use *U, NodeToValueMap &Loc);
137 void separateConstantChains(GepNode *Node, NodeChildrenMap &NCM,
138 NodeToValueMap &Loc);
139 void computeNodePlacement(NodeToValueMap &Loc);
143 void getAllUsersForNode(GepNode *Node, ValueVect &Values,
144 NodeChildrenMap &NCM);
145 void materialize(NodeToValueMap &Loc);
147 void removeDeadCode();
202 if (
auto *PTy = dyn_cast<PointerType>(Ty))
203 return PTy->getElementType();
206 Type *NexTy = cast<SequentialType>(Ty)->getElementType();
211 assert(CI &&
"Struct type with non-constant index");
213 Type *NextTy = cast<StructType>(Ty)->getElementType(i);
220 if (GN.
Flags & GepNode::Root) {
224 if (GN.
Flags & GepNode::Internal) {
230 if (GN.
Flags & GepNode::Used) {
235 if (GN.
Flags & GepNode::InBounds) {
241 if (GN.
Flags & GepNode::Root)
244 OS <<
"Parent:" << GN.
Parent;
248 OS << CI->getValue().getSExtValue();
252 OS <<
"<anon> =" << *GN.
Idx;
260 OS <<
"<anon-struct>:" << *STy;
268 template <
typename NodeContainer>
270 typedef typename NodeContainer::const_iterator const_iterator;
271 for (const_iterator
I = S.begin(),
E = S.end();
I !=
E; ++
I)
272 OS << *
I <<
' ' << **
I <<
'\n';
285 typedef NodeToUsesMap::const_iterator const_iterator;
286 for (const_iterator
I = M.begin(),
E = M.end();
I !=
E; ++
I) {
287 const UseSet &Us =
I->second;
288 OS <<
I->first <<
" -> #" << Us.size() <<
'{';
289 for (UseSet::const_iterator J = Us.begin(),
F = Us.end(); J !=
F; ++J) {
290 User *R = (*J)->getUser();
294 OS <<
" <?>(" << *R <<
')';
304 return NS.find(N) != NS.end();
317 void HexagonCommonGEP::getBlockTraversalOrder(
BasicBlock *Root,
323 Order.push_back(Root);
324 for (
auto *DTN : children<DomTreeNode*>(DT->getNode(Root)))
325 getBlockTraversalOrder(DTN->getBlock(), Order);
339 ValueToNodeMap &NM) {
340 DEBUG(
dbgs() <<
"Visiting GEP: " << *GepI <<
'\n');
341 GepNode *N =
new (*Mem) GepNode;
344 ValueToNodeMap::iterator
F = NM.find(PtrOp);
347 N->Flags |= GepNode::Root | InBounds;
352 N->Parent = F->second;
364 if (isa<GetElementPtrInst>(*UI)) {
366 if (isHandledGepForm(UserG))
369 Us.insert(&UI.getUse());
377 Type *PtrTy = cast<PointerType>(PtrOp->
getType())->getElementType();
381 GepNode *Nx =
new (*Mem) GepNode;
383 Nx->Flags |= GepNode::Internal | InBounds;
395 PN->Flags |= GepNode::Used;
396 Uses[PN].insert(Us.begin(), Us.end());
401 NM.insert(std::make_pair(GepI, PN));
404 void HexagonCommonGEP::collect() {
407 getBlockTraversalOrder(&Fn->front(), BO);
413 for (ValueVect::iterator
I = BO.begin(),
E = BO.end();
I !=
E; ++
I) {
416 if (!isa<GetElementPtrInst>(J))
419 if (isHandledGepForm(GepI))
420 processGepInst(GepI, NM);
424 DEBUG(
dbgs() <<
"Gep nodes after initial collection:\n" << Nodes);
429 typedef NodeVect::const_iterator const_iterator;
430 for (const_iterator I = Nodes.begin(),
E = Nodes.end(); I !=
E; ++
I) {
432 if (N->Flags & GepNode::Root) {
436 GepNode *PN = N->Parent;
437 NCM[PN].push_back(N);
444 Work.push_back(Root);
447 while (!Work.empty()) {
448 NodeVect::iterator First = Work.begin();
451 NodeChildrenMap::iterator CF = NCM.find(N);
452 if (CF != NCM.end()) {
453 Work.insert(Work.end(), CF->second.begin(), CF->second.end());
454 Nodes.insert(CF->second.begin(), CF->second.end());
461 typedef std::set<NodeSet> NodeSymRel;
462 typedef std::pair<GepNode*,GepNode*> NodePair;
463 typedef std::set<NodePair> NodePairSet;
467 static const NodeSet *
node_class(GepNode *N, NodeSymRel &Rel) {
468 for (NodeSymRel::iterator I = Rel.begin(),
E = Rel.end(); I !=
E; ++
I)
478 uintptr_t P1 = uintptr_t(N1), P2 = uintptr_t(N2);
480 return std::make_pair(N1, N2);
481 return std::make_pair(N2, N1);
492 static bool node_eq(GepNode *N1, GepNode *N2, NodePairSet &
Eq,
500 NodePairSet::iterator FEq = Eq.find(NP);
503 NodePairSet::iterator FNe = Ne.find(NP);
507 bool Root1 = N1->Flags & GepNode::Root;
508 bool Root2 = N2->Flags & GepNode::Root;
513 if (Root1 != Root2 || (Root1 && N1->BaseVal != N2->BaseVal)) {
520 if (Root1 ||
node_eq(N1->Parent, N2->Parent, Eq, Ne)) {
527 void HexagonCommonGEP::common() {
532 typedef std::map<unsigned,NodeSet> NodeSetMap;
535 for (NodeVect::iterator I = Nodes.begin(),
E = Nodes.end(); I !=
E; ++
I) {
538 MaybeEq[
H].insert(N);
545 for (NodeSetMap::iterator I = MaybeEq.begin(),
E = MaybeEq.end();
547 NodeSet &S = I->second;
548 for (NodeSet::iterator NI = S.begin(),
NE = S.end(); NI !=
NE; ++NI) {
558 for (NodeSet::iterator NJ = std::next(NI); NJ !=
NE; ++NJ)
565 std::pair<NodeSymRel::iterator, bool>
Ins = EqRel.insert(C);
567 assert(Ins.second &&
"Cannot add a class");
573 dbgs() <<
"Gep node equality:\n";
574 for (NodePairSet::iterator I = Eq.begin(),
E = Eq.end(); I !=
E; ++
I)
575 dbgs() <<
"{ " << I->first <<
", " << I->second <<
" }\n";
577 dbgs() <<
"Gep equivalence classes:\n";
578 for (NodeSymRel::iterator I = EqRel.begin(),
E = EqRel.end(); I !=
E; ++
I) {
580 const NodeSet &S = *
I;
581 for (NodeSet::const_iterator J = S.begin(), F = S.end(); J !=
F; ++J) {
591 typedef std::map<const NodeSet*,GepNode*> ProjMap;
593 for (NodeSymRel::iterator I = EqRel.begin(),
E = EqRel.end(); I !=
E; ++
I) {
594 const NodeSet &S = *
I;
595 GepNode *
Min = *std::min_element(S.begin(), S.end(),
NodeOrder);
596 std::pair<ProjMap::iterator,bool>
Ins = PM.insert(std::make_pair(&S, Min));
598 assert(Ins.second &&
"Cannot add minimal element");
602 UseSet &MinUs = Uses[
Min];
603 for (NodeSet::iterator J = S.begin(), F = S.end(); J !=
F; ++J) {
608 if (NF & GepNode::Used)
609 MinUs.insert(Uses[N].
begin(), Uses[N].
end());
616 assert((Min->Flags & Flags) == Min->Flags);
624 for (NodeVect::iterator I = Nodes.begin(),
E = Nodes.end(); I !=
E; ++
I) {
626 if (N->Flags & GepNode::Root)
628 const NodeSet *PC =
node_class(N->Parent, EqRel);
631 ProjMap::iterator F = PM.find(PC);
635 GepNode *Rep = F->second;
639 DEBUG(
dbgs() <<
"Gep nodes after commoning:\n" << Nodes);
643 for (NodeVect::iterator I = Nodes.begin(),
E = Nodes.end(); I !=
E; ++
I) {
648 ProjMap::iterator F = PM.find(PC);
656 NodeVect::iterator NewE =
remove_if(Nodes, in_set(Erase));
657 Nodes.resize(std::distance(Nodes.begin(), NewE));
659 DEBUG(
dbgs() <<
"Gep nodes after post-commoning cleanup:\n" << Nodes);
662 template <
typename T>
665 dbgs() <<
"NCD of {";
666 for (
typename T::iterator I = Blocks.begin(),
E = Blocks.end();
677 typename T::iterator I = Blocks.begin(),
E = Blocks.end();
691 template <
typename T>
695 typename T::iterator I = Blocks.begin(),
E = Blocks.end();
697 while (I !=
E && !*I)
717 template <
typename T>
720 typedef typename T::iterator iterator;
721 for (iterator I = Values.begin(),
E = Values.end(); I !=
E; ++
I) {
730 if (!isa<Instruction>(V))
736 if (std::distance(FirstUse, BEnd) < std::distance(It, BEnd))
746 BasicBlock *HexagonCommonGEP::recalculatePlacement(GepNode *Node,
747 NodeChildrenMap &NCM, NodeToValueMap &Loc) {
748 DEBUG(
dbgs() <<
"Loc for node:" << Node <<
'\n');
759 if (Node->Flags & GepNode::Used) {
762 NodeToUsesMap::iterator UF = Uses.find(Node);
763 assert(UF != Uses.end() &&
"Used node with no use information");
764 UseSet &Us = UF->second;
765 for (UseSet::iterator I = Us.begin(),
E = Us.end(); I !=
E; ++
I) {
767 User *R = U->getUser();
768 if (!isa<Instruction>(R))
771 ? cast<PHINode>(R)->getIncomingBlock(*U)
777 NodeChildrenMap::iterator CF = NCM.find(Node);
778 if (CF != NCM.end()) {
779 NodeVect &Cs = CF->second;
780 for (NodeVect::iterator I = Cs.begin(),
E = Cs.end(); I !=
E; ++
I) {
782 NodeToValueMap::iterator LF = Loc.find(CN);
788 Bs.push_back(LF->second);
797 if (IdxI && !DT->dominates(IdxI->
getParent(), DomB))
813 BasicBlock *HexagonCommonGEP::recalculatePlacementRec(GepNode *Node,
814 NodeChildrenMap &NCM, NodeToValueMap &Loc) {
815 DEBUG(
dbgs() <<
"LocRec begin for node:" << Node <<
'\n');
818 NodeChildrenMap::iterator CF = NCM.find(Node);
819 if (CF != NCM.end()) {
820 NodeVect &Cs = CF->second;
821 for (NodeVect::iterator I = Cs.begin(),
E = Cs.end(); I !=
E; ++
I)
822 recalculatePlacementRec(*I, NCM, Loc);
824 BasicBlock *LB = recalculatePlacement(Node, NCM, Loc);
825 DEBUG(
dbgs() <<
"LocRec end for node:" << Node <<
'\n');
829 bool HexagonCommonGEP::isInvariantIn(
Value *Val,
Loop *
L) {
830 if (isa<Constant>(Val) || isa<Argument>(Val))
836 return DT->properlyDominates(DefB, HdrB);
839 bool HexagonCommonGEP::isInvariantIn(GepNode *Node,
Loop *L) {
840 if (Node->Flags & GepNode::Root)
841 if (!isInvariantIn(Node->BaseVal, L))
843 return isInvariantIn(Node->Idx, L);
850 if (PDT->dominates(B, HB))
852 if (LB && DT->dominates(B, LB))
868 BasicBlock *HexagonCommonGEP::adjustForInvariance(GepNode *Node,
869 NodeChildrenMap &NCM, NodeToValueMap &Loc) {
874 if (Node->Flags & GepNode::Root) {
875 if (
Instruction *PIn = dyn_cast<Instruction>(Node->BaseVal))
876 Bs.push_back(PIn->getParent());
878 Bs.push_back(Loc[Node->Parent]);
880 if (
Instruction *IIn = dyn_cast<Instruction>(Node->Idx))
881 Bs.push_back(IIn->getParent());
892 BasicBlock *LocB = cast_or_null<BasicBlock>(Loc[Node]);
894 Loop *Lp = LI->getLoopFor(LocB);
896 if (!isInvariantIn(Node, Lp) || !isInMainPath(LocB, Lp))
899 if (!NewLoc || !DT->dominates(TopB, NewLoc))
908 NodeChildrenMap::iterator CF = NCM.find(Node);
909 if (CF != NCM.end()) {
910 NodeVect &Cs = CF->second;
911 for (NodeVect::iterator I = Cs.begin(),
E = Cs.end(); I !=
E; ++
I)
912 adjustForInvariance(*I, NCM, Loc);
919 struct LocationAsBlock {
920 LocationAsBlock(
const NodeToValueMap &L) : Map(L) {}
922 const NodeToValueMap ⤅
928 for (NodeToValueMap::const_iterator I = Loc.Map.begin(),
E = Loc.Map.end();
930 OS << I->first <<
" -> ";
932 OS << B->
getName() <<
'(' << B <<
')';
938 inline bool is_constant(GepNode *N) {
939 return isa<ConstantInt>(N->Idx);
944 void HexagonCommonGEP::separateChainForNode(GepNode *Node,
Use *U,
945 NodeToValueMap &Loc) {
946 User *R = U->getUser();
947 DEBUG(
dbgs() <<
"Separating chain for node (" << Node <<
") user: "
952 GepNode *C =
nullptr, *NewNode =
nullptr;
953 while (is_constant(N) && !(N->Flags & GepNode::Root)) {
955 GepNode *NewN =
new (*Mem) GepNode(N);
956 Nodes.push_back(NewN);
961 NewN->Flags &= ~GepNode::Used;
971 NodeToUsesMap::iterator UF = Uses.find(Node);
973 UseSet &Us = UF->second;
975 for (UseSet::iterator I = Us.begin(); I != Us.end(); ) {
976 User *S = (*I)->getUser();
977 UseSet::iterator Nx = std::next(I);
985 Node->Flags &= ~GepNode::Used;
990 NewNode->Flags |= GepNode::Used;
991 DEBUG(
dbgs() <<
"new node: " << NewNode <<
" " << *NewNode <<
'\n');
993 Uses[NewNode] = NewUs;
996 void HexagonCommonGEP::separateConstantChains(GepNode *Node,
997 NodeChildrenMap &NCM, NodeToValueMap &Loc) {
1002 DEBUG(
dbgs() <<
"Separating constant chains for node: " << Node <<
'\n');
1006 for (NodeSet::iterator I = Ns.begin(),
E = Ns.end(); I !=
E; ++
I) {
1008 if (!(N->Flags & GepNode::Used))
1010 NodeToUsesMap::iterator UF = Uses.find(N);
1011 assert(UF != Uses.end());
1012 UseSet &Us = UF->second;
1015 for (UseSet::iterator J = Us.begin(), F = Us.end(); J !=
F; ++J) {
1017 User *R = U->getUser();
1021 if (
LoadInst *Ld = dyn_cast<LoadInst>(R)) {
1023 if (&Ld->getOperandUse(PtrX) == U)
1025 }
else if (
StoreInst *St = dyn_cast<StoreInst>(R)) {
1027 if (&St->getOperandUse(PtrX) == U)
1036 FNs.insert(std::make_pair(N, LSs));
1039 DEBUG(
dbgs() <<
"Nodes with foldable users:\n" << FNs);
1041 for (NodeToUsesMap::iterator I = FNs.begin(),
E = FNs.end(); I !=
E; ++
I) {
1042 GepNode *N = I->first;
1043 UseSet &Us = I->second;
1044 for (UseSet::iterator J = Us.begin(), F = Us.end(); J !=
F; ++J)
1045 separateChainForNode(N, *J, Loc);
1049 void HexagonCommonGEP::computeNodePlacement(NodeToValueMap &Loc) {
1052 NodeChildrenMap NCM;
1058 for (NodeVect::iterator I = Roots.begin(),
E = Roots.end(); I !=
E; ++
I)
1059 recalculatePlacementRec(*I, NCM, Loc);
1061 DEBUG(
dbgs() <<
"Initial node placement:\n" << LocationAsBlock(Loc));
1064 for (NodeVect::iterator I = Roots.begin(),
E = Roots.end(); I !=
E; ++
I)
1065 adjustForInvariance(*I, NCM, Loc);
1067 DEBUG(
dbgs() <<
"Node placement after adjustment for invariance:\n"
1068 << LocationAsBlock(Loc));
1071 for (NodeVect::iterator I = Roots.begin(),
E = Roots.end(); I !=
E; ++
I)
1072 separateConstantChains(*I, NCM, Loc);
1074 DEBUG(
dbgs() <<
"Node use information:\n" << Uses);
1080 DEBUG(
dbgs() <<
"Final node placement:\n" << LocationAsBlock(Loc));
1086 <<
" for nodes:\n" << NA);
1087 unsigned Num = NA.size();
1088 GepNode *
RN = NA[0];
1089 assert((RN->Flags & GepNode::Root) &&
"Creating GEP for non-root");
1092 Value *Input = RN->BaseVal;
1100 if (!NA[nax]->PTy->isPointerTy()) {
1107 while (++nax <= Num) {
1108 GepNode *N = NA[nax-1];
1109 IdxList[IdxC++] = N->Idx;
1114 if (NextTy != NA[nax]->PTy)
1123 DEBUG(
dbgs() <<
"new GEP: " << *NewInst <<
'\n');
1125 }
while (nax <= Num);
1131 void HexagonCommonGEP::getAllUsersForNode(GepNode *Node, ValueVect &Values,
1132 NodeChildrenMap &NCM) {
1134 Work.push_back(Node);
1136 while (!Work.empty()) {
1137 NodeVect::iterator First = Work.begin();
1138 GepNode *N = *First;
1140 if (N->Flags & GepNode::Used) {
1141 NodeToUsesMap::iterator UF = Uses.find(N);
1142 assert(UF != Uses.end() &&
"No use information for used node");
1143 UseSet &Us = UF->second;
1144 for (UseSet::iterator I = Us.begin(),
E = Us.end(); I !=
E; ++
I)
1145 Values.push_back((*I)->getUser());
1147 NodeChildrenMap::iterator CF = NCM.find(N);
1148 if (CF != NCM.end()) {
1149 NodeVect &Cs = CF->second;
1150 Work.insert(Work.end(), Cs.begin(), Cs.end());
1155 void HexagonCommonGEP::materialize(NodeToValueMap &Loc) {
1156 DEBUG(
dbgs() <<
"Nodes before materialization:\n" << Nodes <<
'\n');
1157 NodeChildrenMap NCM;
1163 while (!Roots.empty()) {
1164 NodeVect::iterator First = Roots.begin();
1165 GepNode *Root = *First, *
Last = *First;
1174 bool LastUsed =
false;
1175 unsigned LastCN = 0;
1178 Value *LocV = Loc[Last];
1184 LastUsed = (Last->Flags & GepNode::Used);
1187 NodeChildrenMap::iterator CF = NCM.find(Last);
1188 LastCN = (CF != NCM.end()) ? CF->second.size() : 0;
1191 GepNode *Child = CF->second.front();
1192 BasicBlock *ChildB = cast_or_null<BasicBlock>(Loc[Child]);
1193 if (ChildB !=
nullptr && LastB != ChildB)
1199 if (LastUsed || LastCN > 0) {
1201 getAllUsersForNode(Root, Urs, NCM);
1203 if (FirstUse != LastB->
end())
1204 InsertAt = FirstUse;
1208 Value *NewInst = fabricateGEP(NA, InsertAt, LastB);
1213 NodeVect &Cs = NCM[Last];
1214 for (NodeVect::iterator I = Cs.begin(),
E = Cs.end(); I !=
E; ++
I) {
1216 CN->Flags &= ~GepNode::Internal;
1217 CN->Flags |= GepNode::Root;
1218 CN->BaseVal = NewInst;
1219 Roots.push_back(CN);
1226 NodeToUsesMap::iterator UF = Uses.find(Last);
1227 assert(UF != Uses.end() &&
"No use information found");
1228 UseSet &Us = UF->second;
1229 for (UseSet::iterator I = Us.begin(),
E = Us.end(); I !=
E; ++
I) {
1237 void HexagonCommonGEP::removeDeadCode() {
1239 BO.push_back(&Fn->front());
1241 for (
unsigned i = 0; i < BO.size(); ++i) {
1243 for (
auto DTN : children<DomTreeNode*>(DT->getNode(B)))
1244 BO.push_back(DTN->getBlock());
1247 for (
unsigned i = BO.size(); i > 0; --i) {
1252 for (reverse_iterator I = IL.rbegin(),
E = IL.rend(); I !=
E; ++
I)
1254 for (ValueVect::iterator I = Ins.begin(),
E = Ins.end(); I !=
E; ++
I) {
1262 bool HexagonCommonGEP::runOnFunction(
Function &F) {
1263 if (skipFunction(F))
1269 if (isa<InvokeInst>(I) || isa<LandingPadInst>(
I))
1273 DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
1274 PDT = &getAnalysis<PostDominatorTreeWrapperPass>().getPostDomTree();
1275 LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
1289 computeNodePlacement(Loc);
1293 #ifdef EXPENSIVE_CHECKS
1303 return new HexagonCommonGEP();
void AddPointer(const void *Ptr)
Add* - Add various data types to Bit data.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
const_iterator end(StringRef path)
Get end iterator over path.
Value * getPointerOperand()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
auto remove_if(R &&Range, UnaryPredicate P) -> decltype(std::begin(Range))
Provide wrappers to std::remove_if which take ranges instead of having to pass begin/end explicitly...
static BasicBlock::iterator first_use_of_in_block(T &Values, BasicBlock *B)
static void nodes_for_root(GepNode *Root, NodeChildrenMap &NCM, NodeSet &Nodes)
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
static bool is_empty(const BasicBlock *B)
static cl::opt< bool > OptEnableInv("commgep-inv", cl::init(true), cl::Hidden, cl::ZeroOrMore)
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
LoopT * getParentLoop() const
An instruction for reading from memory.
This defines the Use class.
BlockT * getHeader() const
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
static void invert_find_roots(const NodeVect &Nodes, NodeChildrenMap &NCM, NodeVect &Roots)
StringRef getName() const
Return a constant reference to the value's name.
BlockT * getLoopLatch() const
If there is a single latch block for this loop, return it.
iterator begin()
Instruction iterator methods.
FunctionPass * createHexagonCommonGEP()
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
const APInt & getValue() const
Return the constant as an APInt value reference.
Class to represent struct types.
A Use represents the edge between a Value definition and its users.
void setIsInBounds(bool b=true)
Set or clear the inbounds flag on this GEP instruction.
bool Eq(const uint8_t *Data, size_t Size, const char *Str)
bool isLiteral() const
Return true if this type is uniqued by structural equivalence, false if it is a struct definition...
zlib-gnu style compression
DomTreeNodeBase * getIDom() const
Base class for the actual dominator tree node.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
An instruction for storing to memory.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
bool isInBounds() const
Determine whether the GEP has the inbounds flag.
static cl::opt< bool > OptEnableConst("commgep-const", cl::init(true), cl::Hidden, cl::ZeroOrMore)
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
initializer< Ty > init(const Ty &Val)
Type * next_type(Type *Ty, Value *Idx)
BlockT * getLoopPreheader() const
If there is a preheader for this loop, return it.
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
static unsigned getPointerOperandIndex()
This is an important class for using LLVM in a threaded context.
int64_t getSExtValue() const
Get sign extended value.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static unsigned node_hash(GepNode *N)
Represent the analysis usage information of a pass.
const InstListType & getInstList() const
Return the underlying instruction list container.
#define LLVM_ATTRIBUTE_UNUSED
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
FunctionPass class - This class is used to implement most global optimizations.
self_iterator getIterator()
static BasicBlock * preheader(DominatorTree *DT, Loop *L)
static cl::opt< bool > OptSpeculate("commgep-speculate", cl::init(true), cl::Hidden, cl::ZeroOrMore)
bool isPointerTy() const
True if this is an instance of PointerType.
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
bool dominates(const Instruction *Def, const Use &U) const
Return true if Def dominates a use in User.
Iterator for intrusive lists based on ilist_node.
GepNode(const GepNode *N)
This is the shared class of boolean and integer constants.
void initializeHexagonCommonGEPPass(PassRegistry &)
Type * getType() const
All values are typed, get the type of this value.
StringRef getStructName() const
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
A BumpPtrAllocator that allows only elements of a specific type to be allocated.
static BasicBlock * nearest_common_dominator(DominatorTree *DT, T &Blocks)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static NodePair node_pair(GepNode *N1, GepNode *N2)
std::set< NodeId > NodeSet
DomTreeNodeBase< NodeT > * getNode(NodeT *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
static void clear(coro::Shape &Shape)
bool isStructTy() const
True if this is an instance of StructType.
static std::vector< std::string > Flags
static bool node_eq(GepNode *N1, GepNode *N2, NodePairSet &Eq, NodePairSet &Ne)
static IntegerType * getInt32Ty(LLVMContext &C)
unsigned ComputeHash() const
ComputeHash - Compute a strong hash value for this FoldingSetNodeID, used to lookup the node in the F...
Represents a single loop in the control flow graph.
user_iterator_impl< User > user_iterator
bool verifyFunction(const Function &F, raw_ostream *OS=nullptr)
Check a function for errors, useful for use when debugging a pass.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
INITIALIZE_PASS_BEGIN(HexagonCommonGEP,"hcommgep","Hexagon Common GEP", false, false) INITIALIZE_PASS_END(HexagonCommonGEP
static unsigned getPointerOperandIndex()
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
user_iterator user_begin()
bool isInstructionTriviallyDead(Instruction *I, const TargetLibraryInfo *TLI=nullptr)
Return true if the result produced by the instruction is not used, and the instruction has no side ef...
LLVM Value Representation.
static const Function * getParent(const Value *V)
This class implements an extremely fast bulk output stream that can only output to a stream...
The legacy pass manager's analysis pass to compute loop information.
StringRef - Represent a constant reference to a string, i.e.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Legacy analysis pass which computes a DominatorTree.
const TerminatorInst * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
NodeT * findNearestCommonDominator(NodeT *A, NodeT *B) const
findNearestCommonDominator - Find nearest common dominator basic block for basic block A and B...
static BasicBlock * nearest_common_dominatee(DominatorTree *DT, T &Blocks)
base_list_type::reverse_iterator reverse_iterator
const BasicBlock * getParent() const
void dump_node_container(raw_ostream &OS, const NodeContainer &S)
static const NodeSet * node_class(GepNode *N, NodeSymRel &Rel)