LLVM 24.0.0git
RDFGraph.cpp
Go to the documentation of this file.
1//===- RDFGraph.cpp -------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Target-independent, SSA-based data flow graph for register data flow (RDF).
10//
12#include "llvm/ADT/BitVector.h"
13#include "llvm/ADT/STLExtras.h"
14#include "llvm/ADT/SetVector.h"
27#include "llvm/IR/Function.h"
28#include "llvm/IR/Module.h"
29#include "llvm/MC/LaneBitmask.h"
30#include "llvm/MC/MCInstrDesc.h"
34#include <cassert>
35#include <cstdint>
36#include <cstring>
37#include <set>
38#include <utility>
39#include <vector>
40
41// Printing functions. Have them here first, so that the rest of the code
42// can use them.
43namespace llvm::rdf {
44
46 P.G.getPRI().print(OS, P.Obj);
47 return OS;
48}
49
51 if (P.Obj == 0)
52 return OS << "null";
53 auto NA = P.G.addr<NodeBase *>(P.Obj);
54 uint16_t Attrs = NA.Addr->getAttrs();
55 uint16_t Kind = NodeAttrs::kind(Attrs);
56 uint16_t Flags = NodeAttrs::flags(Attrs);
57 switch (NodeAttrs::type(Attrs)) {
58 case NodeAttrs::Code:
59 switch (Kind) {
60 case NodeAttrs::Func:
61 OS << 'f';
62 break;
64 OS << 'b';
65 break;
66 case NodeAttrs::Stmt:
67 OS << 's';
68 break;
69 case NodeAttrs::Phi:
70 OS << 'p';
71 break;
72 default:
73 OS << "c?";
74 break;
75 }
76 break;
77 case NodeAttrs::Ref:
78 if (Flags & NodeAttrs::Undef)
79 OS << '/';
80 if (Flags & NodeAttrs::Dead)
81 OS << '\\';
82 if (Flags & NodeAttrs::Preserving)
83 OS << '+';
84 if (Flags & NodeAttrs::Clobbering)
85 OS << '~';
86 switch (Kind) {
87 case NodeAttrs::Use:
88 OS << 'u';
89 break;
90 case NodeAttrs::Def:
91 OS << 'd';
92 break;
94 OS << 'b';
95 break;
96 default:
97 OS << "r?";
98 break;
99 }
100 break;
101 default:
102 OS << '?';
103 break;
104 }
105 OS << P.Obj;
106 if (Flags & NodeAttrs::Shadow)
107 OS << '"';
108 return OS;
109}
110
111static void printRefHeader(raw_ostream &OS, const Ref RA,
112 const DataFlowGraph &G) {
113 OS << Print(RA.Id, G) << '<' << Print(RA.Addr->getRegRef(G), G) << '>';
114 if (RA.Addr->getFlags() & NodeAttrs::Fixed)
115 OS << '!';
116}
117
119 printRefHeader(OS, P.Obj, P.G);
120 OS << '(';
121 if (NodeId N = P.Obj.Addr->getReachingDef())
122 OS << Print(N, P.G);
123 OS << ',';
124 if (NodeId N = P.Obj.Addr->getReachedDef())
125 OS << Print(N, P.G);
126 OS << ',';
127 if (NodeId N = P.Obj.Addr->getReachedUse())
128 OS << Print(N, P.G);
129 OS << "):";
130 if (NodeId N = P.Obj.Addr->getSibling())
131 OS << Print(N, P.G);
132 return OS;
133}
134
136 printRefHeader(OS, P.Obj, P.G);
137 OS << '(';
138 if (NodeId N = P.Obj.Addr->getReachingDef())
139 OS << Print(N, P.G);
140 OS << "):";
141 if (NodeId N = P.Obj.Addr->getSibling())
142 OS << Print(N, P.G);
143 return OS;
144}
145
147 printRefHeader(OS, P.Obj, P.G);
148 OS << '(';
149 if (NodeId N = P.Obj.Addr->getReachingDef())
150 OS << Print(N, P.G);
151 OS << ',';
152 if (NodeId N = P.Obj.Addr->getPredecessor())
153 OS << Print(N, P.G);
154 OS << "):";
155 if (NodeId N = P.Obj.Addr->getSibling())
156 OS << Print(N, P.G);
157 return OS;
158}
159
161 switch (P.Obj.Addr->getKind()) {
162 case NodeAttrs::Def:
163 OS << PrintNode<DefNode *>(P.Obj, P.G);
164 break;
165 case NodeAttrs::Use:
166 if (P.Obj.Addr->getFlags() & NodeAttrs::PhiRef)
167 OS << PrintNode<PhiUseNode *>(P.Obj, P.G);
168 else
169 OS << PrintNode<UseNode *>(P.Obj, P.G);
170 break;
171 }
172 return OS;
173}
174
176 unsigned N = P.Obj.size();
177 for (auto I : P.Obj) {
178 OS << Print(I.Id, P.G);
179 if (--N)
180 OS << ' ';
181 }
182 return OS;
183}
184
186 unsigned N = P.Obj.size();
187 for (auto I : P.Obj) {
188 OS << Print(I, P.G);
189 if (--N)
190 OS << ' ';
191 }
192 return OS;
193}
194
195namespace {
196
197template <typename T> struct PrintListV {
198 PrintListV(const NodeList &L, const DataFlowGraph &G) : List(L), G(G) {}
199
200 using Type = T;
201 const NodeList &List;
202 const DataFlowGraph &G;
203};
204
205template <typename T>
206raw_ostream &operator<<(raw_ostream &OS, const PrintListV<T> &P) {
207 unsigned N = P.List.size();
208 for (NodeAddr<T> A : P.List) {
209 OS << PrintNode<T>(A, P.G);
210 if (--N)
211 OS << ", ";
212 }
213 return OS;
214}
215
216} // end anonymous namespace
217
219 OS << Print(P.Obj.Id, P.G) << ": phi ["
220 << PrintListV<RefNode *>(P.Obj.Addr->members(P.G), P.G) << ']';
221 return OS;
222}
223
225 const MachineInstr &MI = *P.Obj.Addr->getCode();
226 unsigned Opc = MI.getOpcode();
227 OS << Print(P.Obj.Id, P.G) << ": " << P.G.getTII().getName(Opc);
228 // Print the target for calls and branches (for readability).
229 if (MI.isCall() || MI.isBranch()) {
231 llvm::find_if(MI.operands(), [](const MachineOperand &Op) -> bool {
232 return Op.isMBB() || Op.isGlobal() || Op.isSymbol();
233 });
234 if (T != MI.operands_end()) {
235 OS << ' ';
236 if (T->isMBB())
237 OS << printMBBReference(*T->getMBB());
238 else if (T->isGlobal())
239 OS << T->getGlobal()->getName();
240 else if (T->isSymbol())
241 OS << T->getSymbolName();
242 }
243 }
244 OS << " [" << PrintListV<RefNode *>(P.Obj.Addr->members(P.G), P.G) << ']';
245 return OS;
246}
247
249 switch (P.Obj.Addr->getKind()) {
250 case NodeAttrs::Phi:
251 OS << PrintNode<PhiNode *>(P.Obj, P.G);
252 break;
253 case NodeAttrs::Stmt:
254 OS << PrintNode<StmtNode *>(P.Obj, P.G);
255 break;
256 default:
257 OS << "instr? " << Print(P.Obj.Id, P.G);
258 break;
259 }
260 return OS;
261}
262
264 MachineBasicBlock *BB = P.Obj.Addr->getCode();
265 unsigned NP = BB->pred_size();
266 std::vector<int> Ns;
267 auto PrintBBs = [&OS](const std::vector<int> &Ns) -> void {
268 unsigned N = Ns.size();
269 for (int I : Ns) {
270 OS << "%bb." << I;
271 if (--N)
272 OS << ", ";
273 }
274 };
275
276 OS << Print(P.Obj.Id, P.G) << ": --- " << printMBBReference(*BB)
277 << " --- preds(" << NP << "): ";
278 for (MachineBasicBlock *B : BB->predecessors())
279 Ns.push_back(B->getNumber());
280 PrintBBs(Ns);
281
282 unsigned NS = BB->succ_size();
283 OS << " succs(" << NS << "): ";
284 Ns.clear();
285 for (MachineBasicBlock *B : BB->successors())
286 Ns.push_back(B->getNumber());
287 PrintBBs(Ns);
288 OS << '\n';
289
290 for (auto I : P.Obj.Addr->members(P.G))
291 OS << PrintNode<InstrNode *>(I, P.G) << '\n';
292 return OS;
293}
294
296 OS << "DFG dump:[\n"
297 << Print(P.Obj.Id, P.G)
298 << ": Function: " << P.Obj.Addr->getCode()->getName() << '\n';
299 for (auto I : P.Obj.Addr->members(P.G))
300 OS << PrintNode<BlockNode *>(I, P.G) << '\n';
301 OS << "]\n";
302 return OS;
303}
304
306 OS << '{';
307 for (auto I : P.Obj)
308 OS << ' ' << Print(I, P.G);
309 OS << " }";
310 return OS;
311}
312
314 OS << P.Obj;
315 return OS;
316}
317
320 for (auto I = P.Obj.top(), E = P.Obj.bottom(); I != E;) {
321 OS << Print(I->Id, P.G) << '<' << Print(I->Addr->getRegRef(P.G), P.G)
322 << '>';
323 I.down();
324 if (I != E)
325 OS << ' ';
326 }
327 return OS;
328}
329
330// Node allocation functions.
331//
332// Node allocator is like a slab memory allocator: it allocates blocks of
333// memory in sizes that are multiples of the size of a node. Each block has
334// the same size. Nodes are allocated from the currently active block, and
335// when it becomes full, a new one is created.
336// There is a mapping scheme between node id and its location in a block,
337// and within that block is described in the header file.
338//
339void NodeAllocator::startNewBlock() {
340 void *T = MemPool.Allocate(NodesPerBlock * NodeMemSize, NodeMemSize);
341 char *P = static_cast<char *>(T);
342 Blocks.push_back(P);
343 // Check if the block index is still within the allowed range, i.e. less
344 // than 2^N, where N is the number of bits in NodeId for the block index.
345 // BitsPerIndex is the number of bits per node index.
346 assert((Blocks.size() < ((size_t)1 << (8 * sizeof(NodeId) - BitsPerIndex))) &&
347 "Out of bits for block index");
348 ActiveEnd = P;
349}
350
351bool NodeAllocator::needNewBlock() {
352 if (Blocks.empty())
353 return true;
354
355 char *ActiveBegin = Blocks.back();
356 uint32_t Index = (ActiveEnd - ActiveBegin) / NodeMemSize;
357 return Index >= NodesPerBlock;
358}
359
361 if (needNewBlock())
362 startNewBlock();
363
364 uint32_t ActiveB = Blocks.size() - 1;
365 uint32_t Index = (ActiveEnd - Blocks[ActiveB]) / NodeMemSize;
366 Node NA = {reinterpret_cast<NodeBase *>(ActiveEnd), makeId(ActiveB, Index)};
367 ActiveEnd += NodeMemSize;
368 return NA;
369}
370
372 uintptr_t A = reinterpret_cast<uintptr_t>(P);
373 for (unsigned i = 0, n = Blocks.size(); i != n; ++i) {
374 uintptr_t B = reinterpret_cast<uintptr_t>(Blocks[i]);
375 if (A < B || A >= B + NodesPerBlock * NodeMemSize)
376 continue;
377 uint32_t Idx = (A - B) / NodeMemSize;
378 return makeId(i, Idx);
379 }
380 llvm_unreachable("Invalid node address");
381}
382
384 MemPool.Reset();
385 Blocks.clear();
386 ActiveEnd = nullptr;
387}
388
389// Insert node NA after "this" in the circular chain.
391 NodeId Nx = Next;
392 // If NA is already "next", do nothing.
393 if (Next != NA.Id) {
394 Next = NA.Id;
395 NA.Addr->Next = Nx;
396 }
397}
398
399// Fundamental node manipulator functions.
400
401// Obtain the register reference from a reference node.
405 return G.unpack(RefData.PR);
406 assert(RefData.Op != nullptr);
407 return G.makeRegRef(*RefData.Op);
408}
409
410// Set the register reference in the reference node directly (for references
411// in phi nodes).
417
418// Set the register reference in the reference node based on a machine
419// operand (for references in statement nodes).
426
427// Get the owner of a given reference node.
429 Node NA = G.addr<NodeBase *>(getNext());
430
431 while (NA.Addr != this) {
432 if (NA.Addr->getType() == NodeAttrs::Code)
433 return NA;
434 NA = G.addr<NodeBase *>(NA.Addr->getNext());
435 }
436 llvm_unreachable("No owner in circular list");
437}
438
439// Connect the def node to the reaching def node.
441 RefData.RD = DA.Id;
442 RefData.Sib = DA.Addr->getReachedDef();
443 DA.Addr->setReachedDef(Self);
444}
445
446// Connect the use node to the reaching def node.
448 RefData.RD = DA.Id;
449 RefData.Sib = DA.Addr->getReachedUse();
450 DA.Addr->setReachedUse(Self);
451}
452
453// Get the first member of the code node.
455 if (CodeData.FirstM == 0)
456 return Node();
457 return G.addr<NodeBase *>(CodeData.FirstM);
458}
459
460// Get the last member of the code node.
462 if (CodeData.LastM == 0)
463 return Node();
464 return G.addr<NodeBase *>(CodeData.LastM);
465}
466
467// Add node NA at the end of the member list of the given code node.
470 if (ML.Id != 0) {
471 ML.Addr->append(NA);
472 } else {
473 CodeData.FirstM = NA.Id;
474 NodeId Self = G.id(this);
475 NA.Addr->setNext(Self);
476 }
477 CodeData.LastM = NA.Id;
478}
479
480// Add node NA after member node MA in the given code node.
482 MA.Addr->append(NA);
483 if (CodeData.LastM == MA.Id)
484 CodeData.LastM = NA.Id;
485}
486
487// Remove member node NA from the given code node.
489 Node MA = getFirstMember(G);
490 assert(MA.Id != 0);
491
492 // Special handling if the member to remove is the first member.
493 if (MA.Id == NA.Id) {
494 if (CodeData.LastM == MA.Id) {
495 // If it is the only member, set both first and last to 0.
496 CodeData.FirstM = CodeData.LastM = 0;
497 } else {
498 // Otherwise, advance the first member.
499 CodeData.FirstM = MA.Addr->getNext();
500 }
501 return;
502 }
503
504 while (MA.Addr != this) {
505 NodeId MX = MA.Addr->getNext();
506 if (MX == NA.Id) {
507 MA.Addr->setNext(NA.Addr->getNext());
508 // If the member to remove happens to be the last one, update the
509 // LastM indicator.
510 if (CodeData.LastM == NA.Id)
511 CodeData.LastM = MA.Id;
512 return;
513 }
514 MA = G.addr<NodeBase *>(MX);
515 }
516 llvm_unreachable("No such member");
517}
518
519// Return the list of all members of the code node.
521 static auto True = [](Node) -> bool { return true; };
522 return members_if(True, G);
523}
524
525// Return the owner of the given instr node.
527 Node NA = G.addr<NodeBase *>(getNext());
528
529 while (NA.Addr != this) {
531 if (NA.Addr->getKind() == NodeAttrs::Block)
532 return NA;
533 NA = G.addr<NodeBase *>(NA.Addr->getNext());
534 }
535 llvm_unreachable("No owner in circular list");
536}
537
538// Add the phi node PA to the given block node.
540 Node M = getFirstMember(G);
541 if (M.Id == 0) {
542 addMember(PA, G);
543 return;
544 }
545
546 assert(M.Addr->getType() == NodeAttrs::Code);
547 if (M.Addr->getKind() == NodeAttrs::Stmt) {
548 // If the first member of the block is a statement, insert the phi as
549 // the first member.
550 CodeData.FirstM = PA.Id;
551 PA.Addr->setNext(M.Id);
552 } else {
553 // If the first member is a phi, find the last phi, and append PA to it.
554 assert(M.Addr->getKind() == NodeAttrs::Phi);
555 Node MN = M;
556 do {
557 M = MN;
558 MN = G.addr<NodeBase *>(M.Addr->getNext());
560 } while (MN.Addr->getKind() == NodeAttrs::Phi);
561
562 // M is the last phi.
563 addMemberAfter(M, PA, G);
564 }
565}
566
567// Find the block node corresponding to the machine basic block BB in the
568// given func node.
570 const DataFlowGraph &G) const {
571 auto EqBB = [BB](Node NA) -> bool { return Block(NA).Addr->getCode() == BB; };
572 NodeList Ms = members_if(EqBB, G);
573 if (!Ms.empty())
574 return Ms[0];
575 return Block();
576}
577
578// Get the block node for the entry block in the given function.
580 MachineBasicBlock *EntryB = &getCode()->front();
581 return findBlock(EntryB, G);
582}
583
584// Target operand information.
585//
586
587// For a given instruction, check if there are any bits of RR that can remain
588// unchanged across this def.
590 unsigned OpNum) const {
591 return TII.isPredicated(In);
592}
593
594// Check if the definition of RR produces an unspecified value.
596 unsigned OpNum) const {
597 const MachineOperand &Op = In.getOperand(OpNum);
598 if (Op.isRegMask())
599 return true;
600 assert(Op.isReg());
601 if (In.isCall())
602 if (Op.isDef() && Op.isDead())
603 return true;
604 return false;
605}
606
607// Check if the given instruction specifically requires
609 unsigned OpNum) const {
610 if (In.isCall() || In.isReturn() || In.isInlineAsm())
611 return true;
612 // Check for a tail call.
613 if (In.isBranch())
614 for (const MachineOperand &O : In.operands())
615 if (O.isGlobal() || O.isSymbol())
616 return true;
617
618 const MCInstrDesc &D = In.getDesc();
619 if (D.implicit_defs().empty() && D.implicit_uses().empty())
620 return false;
621 const MachineOperand &Op = In.getOperand(OpNum);
622 // If there is a sub-register, treat the operand as non-fixed. Currently,
623 // fixed registers are those that are listed in the descriptor as implicit
624 // uses or defs, and those lists do not allow sub-registers.
625 if (Op.getSubReg() != 0)
626 return false;
627 Register Reg = Op.getReg();
628 ArrayRef<MCPhysReg> ImpOps =
629 Op.isDef() ? D.implicit_defs() : D.implicit_uses();
630 return is_contained(ImpOps, Reg);
631}
632
633//
634// The data flow graph construction.
635//
636
638 const TargetRegisterInfo &tri,
639 const MachineDominatorTree &mdt,
640 const MachineDominanceFrontier &mdf)
641 : DefaultTOI(std::make_unique<TargetOperandInfo>(tii)), MF(mf), TII(tii),
642 TRI(tri), PRI(tri, mf), MDT(mdt), MDF(mdf), TOI(*DefaultTOI),
643 LiveIns(PRI) {}
644
646 const TargetRegisterInfo &tri,
647 const MachineDominatorTree &mdt,
648 const MachineDominanceFrontier &mdf,
649 const TargetOperandInfo &toi)
650 : MF(mf), TII(tii), TRI(tri), PRI(tri, mf), MDT(mdt), MDF(mdf), TOI(toi),
651 LiveIns(PRI) {}
652
653// The implementation of the definition stack.
654// Each register reference has its own definition stack. In particular,
655// for a register references "Reg" and "Reg:subreg" will each have their
656// own definition stacks.
657
658// Construct a stack iterator.
659DataFlowGraph::DefStack::Iterator::Iterator(const DataFlowGraph::DefStack &S,
660 bool Top)
661 : DS(S) {
662 if (!Top) {
663 // Initialize to bottom.
664 Pos = 0;
665 return;
666 }
667 // Initialize to the top, i.e. top-most non-delimiter (or 0, if empty).
668 Pos = DS.Stack.size();
669 while (Pos > 0 && DS.isDelimiter(DS.Stack[Pos - 1]))
670 Pos--;
671}
672
673// Return the size of the stack, including block delimiters.
675 unsigned S = 0;
676 for (auto I = top(), E = bottom(); I != E; I.down())
677 S++;
678 return S;
679}
680
681// Remove the top entry from the stack. Remove all intervening delimiters
682// so that after this, the stack is either empty, or the top of the stack
683// is a non-delimiter.
685 assert(!empty());
686 unsigned P = nextDown(Stack.size());
687 Stack.resize(P);
688}
689
690// Push a delimiter for block node N on the stack.
692 assert(N != 0);
693 Stack.push_back(Def(nullptr, N));
694}
695
696// Remove all nodes from the top of the stack, until the delimited for
697// block node N is encountered. Remove the delimiter as well. In effect,
698// this will remove from the stack all definitions from block N.
700 assert(N != 0);
701 unsigned P = Stack.size();
702 while (P > 0) {
703 bool Found = isDelimiter(Stack[P - 1], N);
704 P--;
705 if (Found)
706 break;
707 }
708 // This will also remove the delimiter, if found.
709 Stack.resize(P);
710}
711
712// Move the stack iterator up by one.
713unsigned DataFlowGraph::DefStack::nextUp(unsigned P) const {
714 // Get the next valid position after P (skipping all delimiters).
715 // The input position P does not have to point to a non-delimiter.
716 unsigned SS = Stack.size();
717 bool IsDelim;
718 assert(P < SS);
719 do {
720 P++;
721 IsDelim = isDelimiter(Stack[P - 1]);
722 } while (P < SS && IsDelim);
723 assert(!IsDelim);
724 return P;
725}
726
727// Move the stack iterator down by one.
728unsigned DataFlowGraph::DefStack::nextDown(unsigned P) const {
729 // Get the preceding valid position before P (skipping all delimiters).
730 // The input position P does not have to point to a non-delimiter.
731 assert(P > 0 && P <= Stack.size());
732 bool IsDelim = isDelimiter(Stack[P - 1]);
733 do {
734 if (--P == 0)
735 break;
736 IsDelim = isDelimiter(Stack[P - 1]);
737 } while (P > 0 && IsDelim);
738 assert(!IsDelim);
739 return P;
740}
741
742// Register information.
743
744RegisterAggr DataFlowGraph::getLandingPadLiveIns() const {
745 RegisterAggr LR(getPRI());
746 const Function &F = MF.getFunction();
747 const Constant *PF = F.hasPersonalityFn() ? F.getPersonalityFn() : nullptr;
748 const TargetLowering &TLI = *MF.getSubtarget().getTargetLowering();
749 ExceptionHandling EH = F.getParent()->getExceptionModel();
750 if (RegisterId R = TLI.getExceptionPointerRegister(EH, PF))
751 LR.insert(RegisterRef(R));
753 if (RegisterId R = TLI.getExceptionSelectorRegister(EH, PF))
754 LR.insert(RegisterRef(R));
755 }
756 return LR;
757}
758
759// Node management functions.
760
761// Get the pointer to the node with the id N.
763 if (N == 0)
764 return nullptr;
765 return Memory.ptr(N);
766}
767
768// Get the id of the node at the address P.
770 if (P == nullptr)
771 return 0;
772 return Memory.id(P);
773}
774
775// Allocate a new node and set the attributes to Attrs.
776Node DataFlowGraph::newNode(uint16_t Attrs) {
777 Node P = Memory.New();
778 P.Addr->init();
779 P.Addr->setAttrs(Attrs);
780 return P;
781}
782
783// Make a copy of the given node B, except for the data-flow links, which
784// are set to 0.
785Node DataFlowGraph::cloneNode(const Node B) {
786 Node NA = newNode(0);
787 memcpy(NA.Addr, B.Addr, sizeof(NodeBase));
788 // Ref nodes need to have the data-flow links reset.
789 if (NA.Addr->getType() == NodeAttrs::Ref) {
790 Ref RA = NA;
791 RA.Addr->setReachingDef(0);
792 RA.Addr->setSibling(0);
793 if (NA.Addr->getKind() == NodeAttrs::Def) {
794 Def DA = NA;
795 DA.Addr->setReachedDef(0);
796 DA.Addr->setReachedUse(0);
797 }
798 }
799 return NA;
800}
801
802// Allocation routines for specific node types/kinds.
803
804Use DataFlowGraph::newUse(Instr Owner, MachineOperand &Op, uint16_t Flags) {
805 Use UA = newNode(NodeAttrs::Ref | NodeAttrs::Use | Flags);
806 UA.Addr->setRegRef(&Op, *this);
807 return UA;
808}
809
810PhiUse DataFlowGraph::newPhiUse(Phi Owner, RegisterRef RR, Block PredB,
811 uint16_t Flags) {
812 PhiUse PUA = newNode(NodeAttrs::Ref | NodeAttrs::Use | Flags);
813 assert(Flags & NodeAttrs::PhiRef);
814 PUA.Addr->setRegRef(RR, *this);
815 PUA.Addr->setPredecessor(PredB.Id);
816 return PUA;
817}
818
819Def DataFlowGraph::newDef(Instr Owner, MachineOperand &Op, uint16_t Flags) {
820 Def DA = newNode(NodeAttrs::Ref | NodeAttrs::Def | Flags);
821 DA.Addr->setRegRef(&Op, *this);
822 return DA;
823}
824
825Def DataFlowGraph::newDef(Instr Owner, RegisterRef RR, uint16_t Flags) {
826 Def DA = newNode(NodeAttrs::Ref | NodeAttrs::Def | Flags);
827 assert(Flags & NodeAttrs::PhiRef);
828 DA.Addr->setRegRef(RR, *this);
829 return DA;
830}
831
832Phi DataFlowGraph::newPhi(Block Owner) {
833 Phi PA = newNode(NodeAttrs::Code | NodeAttrs::Phi);
834 Owner.Addr->addPhi(PA, *this);
835 return PA;
836}
837
838Stmt DataFlowGraph::newStmt(Block Owner, MachineInstr *MI) {
839 Stmt SA = newNode(NodeAttrs::Code | NodeAttrs::Stmt);
840 SA.Addr->setCode(MI);
841 Owner.Addr->addMember(SA, *this);
842 return SA;
843}
844
845Block DataFlowGraph::newBlock(Func Owner, MachineBasicBlock *BB) {
846 Block BA = newNode(NodeAttrs::Code | NodeAttrs::Block);
847 BA.Addr->setCode(BB);
848 Owner.Addr->addMember(BA, *this);
849 return BA;
850}
851
852Func DataFlowGraph::newFunc(MachineFunction *MF) {
853 Func FA = newNode(NodeAttrs::Code | NodeAttrs::Func);
854 FA.Addr->setCode(MF);
855 return FA;
856}
857
858// Build the data flow graph.
859void DataFlowGraph::build(const Config &config) {
860 reset();
861 BuildCfg = config;
862 MachineRegisterInfo &MRI = MF.getRegInfo();
863 ReservedRegs = MRI.getReservedRegs();
864 bool SkipReserved = BuildCfg.Options & BuildOptions::OmitReserved;
865
866 auto Insert = [](auto &Set, auto &&Range) {
867 Set.insert(Range.begin(), Range.end());
868 };
869
870 if (BuildCfg.TrackRegs.empty()) {
871 std::set<RegisterId> BaseSet;
872 if (BuildCfg.Classes.empty()) {
873 // Insert every register.
874 for (unsigned R = 1, E = getPRI().getTRI().getNumRegs(); R != E; ++R)
875 BaseSet.insert(R);
876 } else {
877 for (const TargetRegisterClass *RC : BuildCfg.Classes) {
878 for (MCPhysReg R : *RC)
879 BaseSet.insert(R);
880 }
881 }
882 for (RegisterId R : BaseSet) {
883 if (SkipReserved && ReservedRegs[R])
884 continue;
885 Insert(TrackedUnits, getPRI().getUnits(RegisterRef(R)));
886 }
887 } else {
888 // Track set in Config overrides everything.
889 for (unsigned R : BuildCfg.TrackRegs) {
890 if (SkipReserved && ReservedRegs[R])
891 continue;
892 Insert(TrackedUnits, getPRI().getUnits(RegisterRef(R)));
893 }
894 }
895
896 TheFunc = newFunc(&MF);
897
898 if (MF.empty())
899 return;
900
901 for (MachineBasicBlock &B : MF) {
902 Block BA = newBlock(TheFunc, &B);
903 BlockNodes.insert(std::make_pair(&B, BA));
904 for (MachineInstr &I : B) {
905 if (I.isDebugInstr())
906 continue;
907 buildStmt(BA, I);
908 }
909 }
910
911 Block EA = TheFunc.Addr->getEntryBlock(*this);
912 NodeList Blocks = TheFunc.Addr->members(*this);
913
914 // Collect function live-ins and entry block live-ins.
915 MachineBasicBlock &EntryB = *EA.Addr->getCode();
916 assert(EntryB.pred_empty() && "Function entry block has predecessors");
917 for (std::pair<MCRegister, Register> P : MRI.liveins())
918 LiveIns.insert(RegisterRef(P.first));
919 if (MRI.tracksLiveness()) {
920 for (auto I : EntryB.liveins())
921 LiveIns.insert(RegisterRef(I.PhysReg, I.LaneMask));
922 }
923
924 // Add function-entry phi nodes for the live-in registers.
925 for (RegisterRef RR : LiveIns.refs()) {
926 if (RR.isReg() && !isTracked(RR)) // isReg is likely guaranteed
927 continue;
928 Phi PA = newPhi(EA);
930 Def DA = newDef(PA, RR, PhiFlags);
931 PA.Addr->addMember(DA, *this);
932 }
933
934 // Add phis for landing pads.
935 // Landing pads, unlike usual backs blocks, are not entered through
936 // branches in the program, or fall-throughs from other blocks. They
937 // are entered from the exception handling runtime and target's ABI
938 // may define certain registers as defined on entry to such a block.
939 RegisterAggr EHRegs = getLandingPadLiveIns();
940 if (!EHRegs.empty()) {
941 for (Block BA : Blocks) {
942 const MachineBasicBlock &B = *BA.Addr->getCode();
943 if (!B.isEHPad())
944 continue;
945
946 // Prepare a list of NodeIds of the block's predecessors.
947 NodeList Preds;
948 for (MachineBasicBlock *PB : B.predecessors())
949 Preds.push_back(findBlock(PB));
950
951 // Build phi nodes for each live-in.
952 for (RegisterRef RR : EHRegs.refs()) {
953 if (RR.isReg() && !isTracked(RR))
954 continue;
955 Phi PA = newPhi(BA);
957 // Add def:
958 Def DA = newDef(PA, RR, PhiFlags);
959 PA.Addr->addMember(DA, *this);
960 // Add uses (no reaching defs for phi uses):
961 for (Block PBA : Preds) {
962 PhiUse PUA = newPhiUse(PA, RR, PBA);
963 PA.Addr->addMember(PUA, *this);
964 }
965 }
966 }
967 }
968
969 // Build a map "PhiM" which will contain, for each block, the set
970 // of references that will require phi definitions in that block.
971 // "PhiClobberM" map contains references that require phis for clobbering defs
972 BlockRefsMap PhiM(getPRI());
973 BlockRefsMap PhiClobberM(getPRI());
974 for (Block BA : Blocks)
975 recordDefsForDF(PhiM, PhiClobberM, BA);
976 for (Block BA : Blocks)
977 buildPhis(PhiM, BA);
978
979 // Link all the refs. This will recursively traverse the dominator tree.
980 // Phis for clobbering defs are added here.
982 linkBlockRefs(DM, PhiClobberM, EA);
983
984 // Finally, remove all unused phi nodes.
985 if (!(BuildCfg.Options & BuildOptions::KeepDeadPhis))
986 removeUnusedPhis();
987}
988
989RegisterRef DataFlowGraph::makeRegRef(unsigned Reg, unsigned Sub) const {
991 assert(Reg != 0);
992 if (Sub != 0)
993 Reg = TRI.getSubReg(Reg, Sub);
994 return RegisterRef(Reg);
995}
996
998 assert(Op.isReg() || Op.isRegMask());
999 if (Op.isReg())
1000 return makeRegRef(Op.getReg(), Op.getSubReg());
1001 return RegisterRef(getPRI().getRegMaskId(Op.getRegMask()),
1003}
1004
1005// For each stack in the map DefM, push the delimiter for block B on it.
1007 // Push block delimiters.
1008 for (auto &P : DefM)
1009 P.second.start_block(B);
1010}
1011
1012// Remove all definitions coming from block B from each stack in DefM.
1014 // Pop all defs from this block from the definition stack. Defs that were
1015 // added to the map during the traversal of instructions will not have a
1016 // delimiter, but for those, the whole stack will be emptied.
1017 for (auto &P : DefM)
1018 P.second.clear_block(B);
1019
1020 // Finally, remove empty stacks from the map.
1021 DefM.remove_if([](const auto &P) { return P.second.empty(); });
1022}
1023
1024// Push all definitions from the instruction node IA to an appropriate
1025// stack in DefM.
1027 pushClobbers(IA, DefM);
1028 pushDefs(IA, DefM);
1029}
1030
1031// Push all definitions from the instruction node IA to an appropriate
1032// stack in DefM.
1033void DataFlowGraph::pushClobbers(Instr IA, DefStackMap &DefM) {
1034 NodeSet Visited;
1035 std::set<RegisterId> Defined;
1036
1037 // The important objectives of this function are:
1038 // - to be able to handle instructions both while the graph is being
1039 // constructed, and after the graph has been constructed, and
1040 // - maintain proper ordering of definitions on the stack for each
1041 // register reference:
1042 // - if there are two or more related defs in IA (i.e. coming from
1043 // the same machine operand), then only push one def on the stack,
1044 // - if there are multiple unrelated defs of non-overlapping
1045 // subregisters of S, then the stack for S will have both (in an
1046 // unspecified order), but the order does not matter from the data-
1047 // -flow perspective.
1048
1049 for (Def DA : IA.Addr->members_if(IsDef, *this)) {
1050 if (Visited.count(DA.Id))
1051 continue;
1052 if (!(DA.Addr->getFlags() & NodeAttrs::Clobbering))
1053 continue;
1054
1055 NodeList Rel = getRelatedRefs(IA, DA);
1056 Def PDA = Rel.front();
1057 RegisterRef RR = PDA.Addr->getRegRef(*this);
1058
1059 // Push the definition on the stack for the register and all aliases.
1060 // The def stack traversal in linkNodeUp will check the exact aliasing.
1061 DefM[RR.Id].push(DA);
1062 Defined.insert(RR.Id);
1063 for (RegisterId A : getPRI().getAliasSet(RR)) {
1065 continue;
1066 // Check that we don't push the same def twice.
1067 assert(A != RR.Id);
1068 if (!Defined.count(A))
1069 DefM[A].push(DA);
1070 }
1071 // Mark all the related defs as visited.
1072 for (Node T : Rel)
1073 Visited.insert(T.Id);
1074 }
1075}
1076
1077// Push all definitions from the instruction node IA to an appropriate
1078// stack in DefM.
1079void DataFlowGraph::pushDefs(Instr IA, DefStackMap &DefM) {
1080 NodeSet Visited;
1081#ifndef NDEBUG
1082 std::set<RegisterId> Defined;
1083#endif
1084
1085 // The important objectives of this function are:
1086 // - to be able to handle instructions both while the graph is being
1087 // constructed, and after the graph has been constructed, and
1088 // - maintain proper ordering of definitions on the stack for each
1089 // register reference:
1090 // - if there are two or more related defs in IA (i.e. coming from
1091 // the same machine operand), then only push one def on the stack,
1092 // - if there are multiple unrelated defs of non-overlapping
1093 // subregisters of S, then the stack for S will have both (in an
1094 // unspecified order), but the order does not matter from the data-
1095 // -flow perspective.
1096
1097 for (Def DA : IA.Addr->members_if(IsDef, *this)) {
1098 if (Visited.count(DA.Id))
1099 continue;
1100 if (DA.Addr->getFlags() & NodeAttrs::Clobbering)
1101 continue;
1102
1103 NodeList Rel = getRelatedRefs(IA, DA);
1104 Def PDA = Rel.front();
1105 RegisterRef RR = PDA.Addr->getRegRef(*this);
1106#ifndef NDEBUG
1107 // Assert if the register is defined in two or more unrelated defs.
1108 // This could happen if there are two or more def operands defining it.
1109 if (!Defined.insert(RR.Id).second) {
1110 MachineInstr *MI = Stmt(IA).Addr->getCode();
1111 dbgs() << "Multiple definitions of register: " << Print(RR, *this)
1112 << " in\n " << *MI << "in " << printMBBReference(*MI->getParent())
1113 << '\n';
1114 llvm_unreachable(nullptr);
1115 }
1116#endif
1117 // Push the definition on the stack for the register and all aliases.
1118 // The def stack traversal in linkNodeUp will check the exact aliasing.
1119 DefM[RR.Id].push(DA);
1120 for (RegisterId A : getPRI().getAliasSet(RR)) {
1121 if (RegisterRef::isRegId(A) && !isTracked(RegisterRef(A)))
1122 continue;
1123 // Check that we don't push the same def twice.
1124 assert(A != RR.Id);
1125 DefM[A].push(DA);
1126 }
1127 // Mark all the related defs as visited.
1128 for (Node T : Rel)
1129 Visited.insert(T.Id);
1130 }
1131}
1132
1133// Return the list of all reference nodes related to RA, including RA itself.
1134// See "getNextRelated" for the meaning of a "related reference".
1136 assert(IA.Id != 0 && RA.Id != 0);
1137
1138 NodeList Refs;
1139 NodeId Start = RA.Id;
1140 do {
1141 Refs.push_back(RA);
1142 RA = getNextRelated(IA, RA);
1143 } while (RA.Id != 0 && RA.Id != Start);
1144 return Refs;
1145}
1146
1147// Clear all information in the graph.
1148void DataFlowGraph::reset() {
1149 Memory.clear();
1150 BlockNodes.clear();
1151 TrackedUnits.clear();
1152 ReservedRegs.clear();
1153 TheFunc = Func();
1154}
1155
1156// Return the next reference node in the instruction node IA that is related
1157// to RA. Conceptually, two reference nodes are related if they refer to the
1158// same instance of a register access, but differ in flags or other minor
1159// characteristics. Specific examples of related nodes are shadow reference
1160// nodes.
1161// Return the equivalent of nullptr if there are no more related references.
1163 assert(IA.Id != 0 && RA.Id != 0);
1164
1165 auto IsRelated = [this, RA](Ref TA) -> bool {
1166 if (TA.Addr->getKind() != RA.Addr->getKind())
1167 return false;
1168 if (!getPRI().equal_to(TA.Addr->getRegRef(*this),
1169 RA.Addr->getRegRef(*this))) {
1170 return false;
1171 }
1172 return true;
1173 };
1174
1175 RegisterRef RR = RA.Addr->getRegRef(*this);
1176 if (IA.Addr->getKind() == NodeAttrs::Stmt) {
1177 auto Cond = [&IsRelated, RA](Ref TA) -> bool {
1178 return IsRelated(TA) && &RA.Addr->getOp() == &TA.Addr->getOp();
1179 };
1180 return RA.Addr->getNextRef(RR, Cond, true, *this);
1181 }
1182
1183 assert(IA.Addr->getKind() == NodeAttrs::Phi);
1184 auto Cond = [&IsRelated, RA](Ref TA) -> bool {
1185 if (!IsRelated(TA))
1186 return false;
1187 if (TA.Addr->getKind() != NodeAttrs::Use)
1188 return true;
1189 // For phi uses, compare predecessor blocks.
1190 return PhiUse(TA).Addr->getPredecessor() ==
1192 };
1193 return RA.Addr->getNextRef(RR, Cond, true, *this);
1194}
1195
1196// Find the next node related to RA in IA that satisfies condition P.
1197// If such a node was found, return a pair where the second element is the
1198// located node. If such a node does not exist, return a pair where the
1199// first element is the element after which such a node should be inserted,
1200// and the second element is a null-address.
1201template <typename Predicate>
1202std::pair<Ref, Ref> DataFlowGraph::locateNextRef(Instr IA, Ref RA,
1203 Predicate P) const {
1204 assert(IA.Id != 0 && RA.Id != 0);
1205
1206 Ref NA;
1207 NodeId Start = RA.Id;
1208 while (true) {
1209 NA = getNextRelated(IA, RA);
1210 if (NA.Id == 0 || NA.Id == Start)
1211 break;
1212 if (P(NA))
1213 break;
1214 RA = NA;
1215 }
1216
1217 if (NA.Id != 0 && NA.Id != Start)
1218 return std::make_pair(RA, NA);
1219 return std::make_pair(RA, Ref());
1220}
1221
1222// Get the next shadow node in IA corresponding to RA, and optionally create
1223// such a node if it does not exist.
1225 assert(IA.Id != 0 && RA.Id != 0);
1226
1227 uint16_t Flags = RA.Addr->getFlags() | NodeAttrs::Shadow;
1228 auto IsShadow = [Flags](Ref TA) -> bool {
1229 return TA.Addr->getFlags() == Flags;
1230 };
1231 auto Loc = locateNextRef(IA, RA, IsShadow);
1232 if (Loc.second.Id != 0 || !Create)
1233 return Loc.second;
1234
1235 // Create a copy of RA and mark is as shadow.
1236 Ref NA = cloneNode(RA);
1237 NA.Addr->setFlags(Flags | NodeAttrs::Shadow);
1238 IA.Addr->addMemberAfter(Loc.first, NA, *this);
1239 return NA;
1240}
1241
1242// Create a new statement node in the block node BA that corresponds to
1243// the machine instruction MI.
1244void DataFlowGraph::buildStmt(Block BA, MachineInstr &In) {
1245 Stmt SA = newStmt(BA, &In);
1246
1247 auto isCall = [](const MachineInstr &In) -> bool {
1248 if (In.isCall())
1249 return true;
1250 // Is tail call?
1251 if (In.isBranch()) {
1252 for (const MachineOperand &Op : In.operands())
1253 if (Op.isGlobal() || Op.isSymbol())
1254 return true;
1255 // Assume indirect branches are calls. This is for the purpose of
1256 // keeping implicit operands, and so it won't hurt on intra-function
1257 // indirect branches.
1258 if (In.isIndirectBranch())
1259 return true;
1260 }
1261 return false;
1262 };
1263
1264 auto isDefUndef = [this](const MachineInstr &In, RegisterRef DR) -> bool {
1265 // This instruction defines DR. Check if there is a use operand that
1266 // would make DR live on entry to the instruction.
1267 for (const MachineOperand &Op : In.all_uses()) {
1268 if (Op.getReg() == 0 || Op.isUndef())
1269 continue;
1270 RegisterRef UR = makeRegRef(Op);
1271 if (getPRI().alias(DR, UR))
1272 return false;
1273 }
1274 return true;
1275 };
1276
1277 bool IsCall = isCall(In);
1278 unsigned NumOps = In.getNumOperands();
1279
1280 // Avoid duplicate implicit defs. This will not detect cases of implicit
1281 // defs that define registers that overlap, but it is not clear how to
1282 // interpret that in the absence of explicit defs. Overlapping explicit
1283 // defs are likely illegal already.
1284 BitVector DoneDefs(TRI.getNumRegs());
1285 // Process explicit defs first.
1286 for (unsigned OpN = 0; OpN < NumOps; ++OpN) {
1287 MachineOperand &Op = In.getOperand(OpN);
1288 if (!Op.isReg() || !Op.isDef() || Op.isImplicit())
1289 continue;
1290 Register R = Op.getReg();
1291 if (!R || !R.isPhysical() || !isTracked(RegisterRef(R)))
1292 continue;
1293 uint16_t Flags = NodeAttrs::None;
1294 if (TOI.isPreserving(In, OpN)) {
1296 // If the def is preserving, check if it is also undefined.
1297 if (isDefUndef(In, makeRegRef(Op)))
1299 }
1300 if (TOI.isClobbering(In, OpN))
1302 if (TOI.isFixedReg(In, OpN))
1304 if (IsCall && Op.isDead())
1306 Def DA = newDef(SA, Op, Flags);
1307 SA.Addr->addMember(DA, *this);
1308 assert(!DoneDefs.test(R));
1309 DoneDefs.set(R);
1310 }
1311
1312 // Process reg-masks (as clobbers).
1313 BitVector DoneClobbers(TRI.getNumRegs());
1314 for (unsigned OpN = 0; OpN < NumOps; ++OpN) {
1315 MachineOperand &Op = In.getOperand(OpN);
1316 if (!Op.isRegMask())
1317 continue;
1319 Def DA = newDef(SA, Op, Flags);
1320 SA.Addr->addMember(DA, *this);
1321 // Record all clobbered registers in DoneDefs.
1322 const uint32_t *RM = Op.getRegMask();
1323 for (unsigned i = 1, e = TRI.getNumRegs(); i != e; ++i) {
1324 if (!isTracked(RegisterRef(i)))
1325 continue;
1326 if (!(RM[i / 32] & (1u << (i % 32))))
1327 DoneClobbers.set(i);
1328 }
1329 }
1330
1331 // Process implicit defs, skipping those that have already been added
1332 // as explicit.
1333 for (unsigned OpN = 0; OpN < NumOps; ++OpN) {
1334 MachineOperand &Op = In.getOperand(OpN);
1335 if (!Op.isReg() || !Op.isDef() || !Op.isImplicit())
1336 continue;
1337 Register R = Op.getReg();
1338 if (!R || !R.isPhysical() || !isTracked(RegisterRef(R)) || DoneDefs.test(R))
1339 continue;
1340 RegisterRef RR = makeRegRef(Op);
1341 uint16_t Flags = NodeAttrs::None;
1342 if (TOI.isPreserving(In, OpN)) {
1344 // If the def is preserving, check if it is also undefined.
1345 if (isDefUndef(In, RR))
1347 }
1348 if (TOI.isClobbering(In, OpN))
1350 if (TOI.isFixedReg(In, OpN))
1352 if (IsCall && Op.isDead()) {
1353 if (DoneClobbers.test(R))
1354 continue;
1356 }
1357 Def DA = newDef(SA, Op, Flags);
1358 SA.Addr->addMember(DA, *this);
1359 DoneDefs.set(R);
1360 }
1361
1362 for (unsigned OpN = 0; OpN < NumOps; ++OpN) {
1363 MachineOperand &Op = In.getOperand(OpN);
1364 if (!Op.isReg() || !Op.isUse())
1365 continue;
1366 Register R = Op.getReg();
1367 if (!R || !R.isPhysical() || !isTracked(RegisterRef(R)))
1368 continue;
1369 uint16_t Flags = NodeAttrs::None;
1370 if (Op.isUndef())
1372 if (TOI.isFixedReg(In, OpN))
1374 Use UA = newUse(SA, Op, Flags);
1375 SA.Addr->addMember(UA, *this);
1376 }
1377}
1378
1379// Scan all defs in the block node BA and record in PhiM the locations of
1380// phi nodes corresponding to these defs.
1381// Clobbering defs in BA are recorded in PhiClobberM
1382void DataFlowGraph::recordDefsForDF(BlockRefsMap &PhiM,
1383 BlockRefsMap &PhiClobberM, Block BA) {
1384 // Check all defs from block BA and record them in each block in BA's
1385 // iterated dominance frontier. This information will later be used to
1386 // create phi nodes.
1387 MachineBasicBlock *BB = BA.Addr->getCode();
1388 assert(BB);
1389 auto DFLoc = MDF.find(BB);
1390 if (DFLoc == MDF.end() || DFLoc->second.empty())
1391 return;
1392
1393 // Traverse all instructions in the block and collect the set of all
1394 // defined references. For each reference there will be a phi created
1395 // in the block's iterated dominance frontier.
1396 // This is done to make sure that each defined reference gets only one
1397 // phi node, even if it is defined multiple times.
1398 RegisterAggr Defs(getPRI());
1399 RegisterAggr ClobberDefs(getPRI());
1400 for (Instr IA : BA.Addr->members(*this)) {
1401 for (Ref RA : IA.Addr->members_if(IsDef, *this)) {
1402 RegisterRef RR = RA.Addr->getRegRef(*this);
1403 if (!isTracked(RR))
1404 continue;
1405 if (RR.isReg())
1406 Defs.insert(RR);
1407 // Clobbering def
1408 else if (RR.isMask())
1409 ClobberDefs.insert(RR);
1410 }
1411 }
1412
1413 // Calculate the iterated dominance frontier of BB.
1414 const MachineDominanceFrontier::DomSetType &DF = DFLoc->second;
1415 SetVector<MachineBasicBlock *> IDF(llvm::from_range, DF);
1416 for (unsigned i = 0; i < IDF.size(); ++i) {
1417 auto F = MDF.find(IDF[i]);
1418 if (F != MDF.end())
1419 IDF.insert_range(F->second);
1420 }
1421
1422 // Finally, add the set of defs to each block in the iterated dominance
1423 // frontier.
1424 for (auto *DB : IDF) {
1425 Block DBA = findBlock(DB);
1426 PhiM[DBA.Id].insert(Defs);
1427 PhiClobberM[DBA.Id].insert(ClobberDefs);
1428 }
1429}
1430
1431// Given the locations of phi nodes in the map PhiM, create the phi nodes
1432// that are located in the block node BA.
1433void DataFlowGraph::buildPhis(BlockRefsMap &PhiM, Block BA,
1434 const DefStackMap &DefM) {
1435 // Check if this blocks has any DF defs, i.e. if there are any defs
1436 // that this block is in the iterated dominance frontier of.
1437 auto HasDF = PhiM.find(BA.Id);
1438 if (HasDF == PhiM.end() || HasDF->second.empty())
1439 return;
1440
1441 // Prepare a list of NodeIds of the block's predecessors.
1442 NodeList Preds;
1443 const MachineBasicBlock *MBB = BA.Addr->getCode();
1444 for (MachineBasicBlock *PB : MBB->predecessors())
1445 Preds.push_back(findBlock(PB));
1446
1447 RegisterAggr PhiDefs(getPRI());
1448 // DefM will be non empty when we are building phis
1449 // for clobbering defs
1450 if (!DefM.empty()) {
1451 for (Instr IA : BA.Addr->members_if(IsPhi, *this)) {
1452 for (Def DA : IA.Addr->members_if(IsDef, *this)) {
1453 auto DR = DA.Addr->getRegRef(*this);
1454 PhiDefs.insert(DR);
1455 }
1456 }
1457 }
1458
1459 MachineRegisterInfo &MRI = MF.getRegInfo();
1460 const RegisterAggr &Defs = PhiM[BA.Id];
1461 uint16_t PhiFlags = NodeAttrs::PhiRef | NodeAttrs::Preserving;
1462
1463 for (RegisterRef RR : Defs.refs()) {
1464 if (!DefM.empty()) {
1465 auto F = DefM.find(RR.Id);
1466 // Do not create a phi for unallocatable registers, or for registers
1467 // that are never livein to BA.
1468 // If a phi exists for RR, do not create another.
1469 if (!MRI.isAllocatable(RR.asMCReg()) || PhiDefs.hasCoverOf(RR) ||
1470 F == DefM.end() || F->second.empty())
1471 continue;
1472 // Do not create a phi, if all reaching defs are clobbering
1473 auto RDef = F->second.top();
1474 if (RDef->Addr->getFlags() & NodeAttrs::Clobbering)
1475 continue;
1476 PhiDefs.insert(RR);
1477 }
1478 Phi PA = newPhi(BA);
1479 PA.Addr->addMember(newDef(PA, RR, PhiFlags), *this);
1480
1481 // Add phi uses.
1482 for (Block PBA : Preds) {
1483 PA.Addr->addMember(newPhiUse(PA, RR, PBA), *this);
1484 }
1485 }
1486}
1487
1488// Remove any unneeded phi nodes that were created during the build process.
1489void DataFlowGraph::removeUnusedPhis() {
1490 // This will remove unused phis, i.e. phis where each def does not reach
1491 // any uses or other defs. This will not detect or remove circular phi
1492 // chains that are otherwise dead. Unused/dead phis are created during
1493 // the build process and this function is intended to remove these cases
1494 // that are easily determinable to be unnecessary.
1495
1496 SetVector<NodeId> PhiQ;
1497 for (Block BA : TheFunc.Addr->members(*this)) {
1498 for (auto P : BA.Addr->members_if(IsPhi, *this))
1499 PhiQ.insert(P.Id);
1500 }
1501
1502 static auto HasUsedDef = [](NodeList &Ms) -> bool {
1503 for (Node M : Ms) {
1504 if (M.Addr->getKind() != NodeAttrs::Def)
1505 continue;
1506 Def DA = M;
1507 if (DA.Addr->getReachedDef() != 0 || DA.Addr->getReachedUse() != 0)
1508 return true;
1509 }
1510 return false;
1511 };
1512
1513 // Any phi, if it is removed, may affect other phis (make them dead).
1514 // For each removed phi, collect the potentially affected phis and add
1515 // them back to the queue.
1516 while (!PhiQ.empty()) {
1517 auto PA = addr<PhiNode *>(PhiQ[0]);
1518 PhiQ.remove(PA.Id);
1519 NodeList Refs = PA.Addr->members(*this);
1520 if (HasUsedDef(Refs))
1521 continue;
1522 for (Ref RA : Refs) {
1523 if (NodeId RD = RA.Addr->getReachingDef()) {
1524 auto RDA = addr<DefNode *>(RD);
1525 Instr OA = RDA.Addr->getOwner(*this);
1526 if (IsPhi(OA))
1527 PhiQ.insert(OA.Id);
1528 }
1529 if (RA.Addr->isDef())
1530 unlinkDef(RA, true);
1531 else
1532 unlinkUse(RA, true);
1533 }
1534 Block BA = PA.Addr->getOwner(*this);
1535 BA.Addr->removeMember(PA, *this);
1536 }
1537}
1538
1539// For a given reference node TA in an instruction node IA, connect the
1540// reaching def of TA to the appropriate def node. Create any shadow nodes
1541// as appropriate.
1542template <typename T>
1543void DataFlowGraph::linkRefUp(Instr IA, NodeAddr<T> TA, DefStack &DS) {
1544 if (DS.empty())
1545 return;
1546 RegisterRef RR = TA.Addr->getRegRef(*this);
1547 NodeAddr<T> TAP;
1548
1549 // References from the def stack that have been examined so far.
1550 RegisterAggr Defs(getPRI());
1551
1552 for (auto I = DS.top(), E = DS.bottom(); I != E; I.down()) {
1553 RegisterRef QR = I->Addr->getRegRef(*this);
1554
1555 // Skip all defs that we have already seen.
1556 // If this completes a cover of RR, stop the stack traversal.
1557 bool Seen = Defs.hasCoverOf(QR);
1558 if (Seen)
1559 continue;
1560
1561 bool Cover = Defs.insert(QR).hasCoverOf(RR);
1562
1563 // The reaching def.
1564 Def RDA = *I;
1565
1566 // Pick the reached node.
1567 if (TAP.Id == 0) {
1568 TAP = TA;
1569 } else {
1570 // Mark the existing ref as "shadow" and create a new shadow.
1571 TAP.Addr->setFlags(TAP.Addr->getFlags() | NodeAttrs::Shadow);
1572 TAP = getNextShadow(IA, TAP, true);
1573 }
1574
1575 // Create the link.
1576 TAP.Addr->linkToDef(TAP.Id, RDA);
1577
1578 if (Cover)
1579 break;
1580 }
1581}
1582
1583// Create data-flow links for all reference nodes in the statement node SA.
1584template <typename Predicate>
1585void DataFlowGraph::linkStmtRefs(DefStackMap &DefM, Stmt SA, Predicate P) {
1586#ifndef NDEBUG
1587 RegisterSet Defs(getPRI());
1588#endif
1589
1590 // Link all nodes (upwards in the data-flow) with their reaching defs.
1591 for (Ref RA : SA.Addr->members_if(P, *this)) {
1592 uint16_t Kind = RA.Addr->getKind();
1593 assert(Kind == NodeAttrs::Def || Kind == NodeAttrs::Use);
1594 RegisterRef RR = RA.Addr->getRegRef(*this);
1595#ifndef NDEBUG
1596 // Do not expect multiple defs of the same reference.
1597 assert(Kind != NodeAttrs::Def || !Defs.count(RR));
1598 Defs.insert(RR);
1599#endif
1600
1601 auto F = DefM.find(RR.Id);
1602 if (F == DefM.end())
1603 continue;
1604 DefStack &DS = F->second;
1605 if (Kind == NodeAttrs::Use)
1606 linkRefUp<UseNode *>(SA, RA, DS);
1607 else if (Kind == NodeAttrs::Def)
1608 linkRefUp<DefNode *>(SA, RA, DS);
1609 else
1610 llvm_unreachable("Unexpected node in instruction");
1611 }
1612}
1613
1614// Create data-flow links for all instructions in the block node BA. This
1615// will include updating any phi nodes in BA.
1616void DataFlowGraph::linkBlockRefs(DefStackMap &DefM, BlockRefsMap &PhiClobberM,
1617 Block BA) {
1618 // Create phi nodes for clobbering defs.
1619 // Since a huge number of registers can get clobbered, it would result in many
1620 // phi nodes being created in the graph. Only create phi nodes that have a non
1621 // clobbering reaching def. Use DefM to get not clobbering defs reaching a
1622 // block.
1623 buildPhis(PhiClobberM, BA, DefM);
1624
1625 // Push block delimiters.
1626 markBlock(BA.Id, DefM);
1627
1628 auto IsClobber = [](Ref RA) -> bool {
1629 return IsDef(RA) && (RA.Addr->getFlags() & NodeAttrs::Clobbering);
1630 };
1631 auto IsNoClobber = [](Ref RA) -> bool {
1632 return IsDef(RA) && !(RA.Addr->getFlags() & NodeAttrs::Clobbering);
1633 };
1634
1635 assert(BA.Addr && "block node address is needed to create a data-flow link");
1636 // For each non-phi instruction in the block, link all the defs and uses
1637 // to their reaching defs. For any member of the block (including phis),
1638 // push the defs on the corresponding stacks.
1639 for (Instr IA : BA.Addr->members(*this)) {
1640 // Ignore phi nodes here. They will be linked part by part from the
1641 // predecessors.
1642 if (IA.Addr->getKind() == NodeAttrs::Stmt) {
1643 linkStmtRefs(DefM, IA, IsUse);
1644 linkStmtRefs(DefM, IA, IsClobber);
1645 }
1646
1647 // Push the definitions on the stack.
1648 pushClobbers(IA, DefM);
1649
1650 if (IA.Addr->getKind() == NodeAttrs::Stmt)
1651 linkStmtRefs(DefM, IA, IsNoClobber);
1652
1653 pushDefs(IA, DefM);
1654 }
1655
1656 // Recursively process all children in the dominator tree.
1657 MachineDomTreeNode *N = MDT.getNode(BA.Addr->getCode());
1658 for (auto *I : *N) {
1659 MachineBasicBlock *SB = I->getBlock();
1660 Block SBA = findBlock(SB);
1661 linkBlockRefs(DefM, PhiClobberM, SBA);
1662 }
1663
1664 // Link the phi uses from the successor blocks.
1665 auto IsUseForBA = [BA](Node NA) -> bool {
1666 if (NA.Addr->getKind() != NodeAttrs::Use)
1667 return false;
1669 return PhiUse(NA).Addr->getPredecessor() == BA.Id;
1670 };
1671
1672 RegisterAggr EHLiveIns = getLandingPadLiveIns();
1673 MachineBasicBlock *MBB = BA.Addr->getCode();
1674
1675 for (MachineBasicBlock *SB : MBB->successors()) {
1676 bool IsEHPad = SB->isEHPad();
1677 Block SBA = findBlock(SB);
1678 for (Instr IA : SBA.Addr->members_if(IsPhi, *this)) {
1679 // Do not link phi uses for landing pad live-ins.
1680 if (IsEHPad) {
1681 // Find what register this phi is for.
1682 Ref RA = IA.Addr->getFirstMember(*this);
1683 assert(RA.Id != 0);
1684 if (EHLiveIns.hasCoverOf(RA.Addr->getRegRef(*this)))
1685 continue;
1686 }
1687 // Go over each phi use associated with MBB, and link it.
1688 for (auto U : IA.Addr->members_if(IsUseForBA, *this)) {
1689 PhiUse PUA = U;
1690 RegisterRef RR = PUA.Addr->getRegRef(*this);
1691 linkRefUp<UseNode *>(IA, PUA, DefM[RR.Id]);
1692 }
1693 }
1694 }
1695
1696 // Pop all defs from this block from the definition stacks.
1697 releaseBlock(BA.Id, DefM);
1698}
1699
1700// Remove the use node UA from any data-flow and structural links.
1701void DataFlowGraph::unlinkUseDF(Use UA) {
1702 NodeId RD = UA.Addr->getReachingDef();
1703 NodeId Sib = UA.Addr->getSibling();
1704
1705 if (RD == 0) {
1706 assert(Sib == 0);
1707 return;
1708 }
1709
1710 auto RDA = addr<DefNode *>(RD);
1711 auto TA = addr<UseNode *>(RDA.Addr->getReachedUse());
1712 if (TA.Id == UA.Id) {
1713 RDA.Addr->setReachedUse(Sib);
1714 return;
1715 }
1716
1717 while (TA.Id != 0) {
1718 NodeId S = TA.Addr->getSibling();
1719 if (S == UA.Id) {
1720 TA.Addr->setSibling(UA.Addr->getSibling());
1721 return;
1722 }
1723 TA = addr<UseNode *>(S);
1724 }
1725}
1726
1727// Remove the def node DA from any data-flow and structural links.
1728void DataFlowGraph::unlinkDefDF(Def DA) {
1729 //
1730 // RD
1731 // | reached
1732 // | def
1733 // :
1734 // .
1735 // +----+
1736 // ... -- | DA | -- ... -- 0 : sibling chain of DA
1737 // +----+
1738 // | | reached
1739 // | : def
1740 // | .
1741 // | ... : Siblings (defs)
1742 // |
1743 // : reached
1744 // . use
1745 // ... : sibling chain of reached uses
1746
1747 NodeId RD = DA.Addr->getReachingDef();
1748
1749 // Visit all siblings of the reached def and reset their reaching defs.
1750 // Also, defs reached by DA are now "promoted" to being reached by RD,
1751 // so all of them will need to be spliced into the sibling chain where
1752 // DA belongs.
1753 auto getAllNodes = [this](NodeId N) -> NodeList {
1754 NodeList Res;
1755 while (N) {
1756 auto RA = addr<RefNode *>(N);
1757 // Keep the nodes in the exact sibling order.
1758 Res.push_back(RA);
1759 N = RA.Addr->getSibling();
1760 }
1761 return Res;
1762 };
1763 NodeList ReachedDefs = getAllNodes(DA.Addr->getReachedDef());
1764 NodeList ReachedUses = getAllNodes(DA.Addr->getReachedUse());
1765
1766 if (RD == 0) {
1767 for (Ref I : ReachedDefs)
1768 I.Addr->setSibling(0);
1769 for (Ref I : ReachedUses)
1770 I.Addr->setSibling(0);
1771 }
1772 for (Def I : ReachedDefs)
1773 I.Addr->setReachingDef(RD);
1774 for (Use I : ReachedUses)
1775 I.Addr->setReachingDef(RD);
1776
1777 NodeId Sib = DA.Addr->getSibling();
1778 if (RD == 0) {
1779 assert(Sib == 0);
1780 return;
1781 }
1782
1783 // Update the reaching def node and remove DA from the sibling list.
1784 auto RDA = addr<DefNode *>(RD);
1785 auto TA = addr<DefNode *>(RDA.Addr->getReachedDef());
1786 if (TA.Id == DA.Id) {
1787 // If DA is the first reached def, just update the RD's reached def
1788 // to the DA's sibling.
1789 RDA.Addr->setReachedDef(Sib);
1790 } else {
1791 // Otherwise, traverse the sibling list of the reached defs and remove
1792 // DA from it.
1793 while (TA.Id != 0) {
1794 NodeId S = TA.Addr->getSibling();
1795 if (S == DA.Id) {
1796 TA.Addr->setSibling(Sib);
1797 break;
1798 }
1799 TA = addr<DefNode *>(S);
1800 }
1801 }
1802
1803 // Splice the DA's reached defs into the RDA's reached def chain.
1804 if (!ReachedDefs.empty()) {
1805 auto Last = Def(ReachedDefs.back());
1806 Last.Addr->setSibling(RDA.Addr->getReachedDef());
1807 RDA.Addr->setReachedDef(ReachedDefs.front().Id);
1808 }
1809 // Splice the DA's reached uses into the RDA's reached use chain.
1810 if (!ReachedUses.empty()) {
1811 auto Last = Use(ReachedUses.back());
1812 Last.Addr->setSibling(RDA.Addr->getReachedUse());
1813 RDA.Addr->setReachedUse(ReachedUses.front().Id);
1814 }
1815}
1816
1818 return !disjoint(getPRI().getUnits(RR), TrackedUnits);
1819}
1820
1821bool DataFlowGraph::hasUntrackedRef(Stmt S, bool IgnoreReserved) const {
1823
1824 for (Ref R : S.Addr->members(*this)) {
1825 Ops.push_back(&R.Addr->getOp());
1826 RegisterRef RR = R.Addr->getRegRef(*this);
1827 if (IgnoreReserved && RR.isReg() && ReservedRegs[RR.asMCReg().id()])
1828 continue;
1829 if (!isTracked(RR))
1830 return true;
1831 }
1832 for (const MachineOperand &Op : S.Addr->getCode()->operands()) {
1833 if (!Op.isReg() && !Op.isRegMask())
1834 continue;
1835 if (!llvm::is_contained(Ops, &Op))
1836 return true;
1837 }
1838 return false;
1839}
1840
1841} // end namespace llvm::rdf
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock & MBB
This file implements the BitVector class.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static ManagedStatic< DebugCounterOwner > Owner
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
static RegisterPass< DebugifyModulePass > DM("debugify", "Attach debug info to everything")
IRTranslator LLVM IR MI
Module.h This file contains the declarations for the Module class.
const size_t AbstractManglingParser< Derived, Alloc >::NumOps
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
A common definition of LaneBitmask for use in TableGen and CodeGen.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
#define G(x, y, z)
Definition MD5.cpp:55
Register Reg
Promote Memory to Register
Definition Mem2Reg.cpp:110
#define T
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
#define P(N)
PassBuilder PB(Mod->getContext(), Machine, PassOpts->PTO, std::nullopt, &PIC)
SmallVector< MachineOperand, 4 > Cond
MachineRegisterInfo & MRI
SI optimize exec mask operations pre RA
This file contains some templates that are useful if you are working with the STL at all.
This file implements a set that has insertion order iteration characteristics.
This file describes how to lower LLVM code to machine code.
Kind getKind() const
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
void clear()
Removes all bits from the bitvector.
Definition BitVector.h:349
LLVM_ATTRIBUTE_RETURNS_NONNULL void * Allocate(size_t Size, Align Alignment)
Allocate space at the specified alignment.
Definition Allocator.h:160
bool remove_if(Predicate Pred)
Remove entries that match the given predicate.
Definition DenseMap.h:946
Describe properties that are true of each instruction in the target description file.
constexpr unsigned id() const
Definition MCRegister.h:82
iterator_range< livein_iterator > liveins() const
iterator_range< succ_iterator > successors()
iterator_range< pred_iterator > predecessors()
MachineDominanceFrontier::DomSetType DomSetType
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
const MachineBasicBlock & front() const
Representation of each machine instruction.
const MachineOperand * const_mop_iterator
mop_range operands()
MachineOperand class - Representation of each machine instruction operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Wrapper class representing virtual and physical registers.
Definition Register.h:20
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
TargetInstrInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This class provides various memory handling functions that manipulate MemoryBlock instances.
Definition Memory.h:54
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
NodeAddr< DefNode * > Def
Definition RDFGraph.h:384
NodeAddr< InstrNode * > Instr
Definition RDFGraph.h:389
std::set< RegisterRef, RegisterRefLess > RegisterSet
Definition RDFGraph.h:450
NodeAddr< BlockNode * > Block
Definition RDFGraph.h:392
NodeAddr< PhiNode * > Phi
Definition RDFGraph.h:390
Print(const T &, const DataFlowGraph &) -> Print< T >
NodeAddr< PhiUseNode * > PhiUse
Definition RDFGraph.h:386
NodeAddr< StmtNode * > Stmt
Definition RDFGraph.h:391
uint32_t NodeId
Definition RDFGraph.h:262
NodeAddr< UseNode * > Use
Definition RDFGraph.h:385
static void printRefHeader(raw_ostream &OS, const Ref RA, const DataFlowGraph &G)
Definition RDFGraph.cpp:111
NodeAddr< NodeBase * > Node
Definition RDFGraph.h:381
uint32_t RegisterId
LLVM_ABI raw_ostream & operator<<(raw_ostream &OS, const Print< RegisterRef > &P)
Definition RDFGraph.cpp:45
std::set< NodeId > NodeSet
Definition RDFGraph.h:551
SmallVector< Node, 4 > NodeList
Definition RDFGraph.h:550
NodeAddr< FuncNode * > Func
Definition RDFGraph.h:393
NodeAddr< RefNode * > Ref
Definition RDFGraph.h:383
bool disjoint(const std::set< T > &A, const std::set< T > &B)
constexpr from_range_t from_range
constexpr auto equal_to(T &&Arg)
Functor variant of std::equal_to that can be used as a UnaryPredicate in functional algorithms like a...
Definition STLExtras.h:2189
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
LLVM_ABI EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
DomTreeNodeBase< MachineBasicBlock > MachineDomTreeNode
@ Ref
The access may reference the value stored in memory.
Definition ModRef.h:32
bool isFuncletEHPersonality(EHPersonality Pers)
Returns true if this is a personality function that invokes handler funclets (which must return to it...
@ Sub
Subtraction of integers.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21
DWARFExpression::Operation Op
ExceptionHandling
Definition CodeGen.h:54
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1788
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1963
LLVM_ABI Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:878
#define N
static constexpr LaneBitmask getAll()
Definition LaneBitmask.h:82
MachineBasicBlock * getCode() const
Definition RDFGraph.h:644
LLVM_ABI void addPhi(Phi PA, const DataFlowGraph &G)
Definition RDFGraph.cpp:539
NodeList members_if(Predicate P, const DataFlowGraph &G) const
Definition RDFGraph.h:949
LLVM_ABI void removeMember(Node NA, const DataFlowGraph &G)
Definition RDFGraph.cpp:488
LLVM_ABI NodeList members(const DataFlowGraph &G) const
Definition RDFGraph.cpp:520
LLVM_ABI void addMember(Node NA, const DataFlowGraph &G)
Definition RDFGraph.cpp:468
LLVM_ABI Node getFirstMember(const DataFlowGraph &G) const
Definition RDFGraph.cpp:454
LLVM_ABI void addMemberAfter(Node MA, Node NA, const DataFlowGraph &G)
Definition RDFGraph.cpp:481
LLVM_ABI Node getLastMember(const DataFlowGraph &G) const
Definition RDFGraph.cpp:461
LLVM_ABI void clear_block(NodeId N)
Definition RDFGraph.cpp:699
LLVM_ABI void start_block(NodeId N)
Definition RDFGraph.cpp:691
LLVM_ABI unsigned size() const
Definition RDFGraph.cpp:674
LLVM_ABI NodeId id(const NodeBase *P) const
Definition RDFGraph.cpp:769
void unlinkUse(Use UA, bool RemoveFromOwner)
Definition RDFGraph.h:803
LLVM_ABI void releaseBlock(NodeId B, DefStackMap &DefM)
LLVM_ABI Ref getNextRelated(Instr IA, Ref RA) const
LLVM_ABI bool isTracked(RegisterRef RR) const
LLVM_ABI RegisterRef makeRegRef(unsigned Reg, unsigned Sub) const
Definition RDFGraph.cpp:989
static bool IsDef(const Node BA)
Definition RDFGraph.h:827
LLVM_ABI DataFlowGraph(MachineFunction &mf, const TargetInstrInfo &tii, const TargetRegisterInfo &tri, const MachineDominatorTree &mdt, const MachineDominanceFrontier &mdf)
Definition RDFGraph.cpp:637
LLVM_ABI Ref getNextShadow(Instr IA, Ref RA, bool Create)
static bool IsPhi(const Node BA)
Definition RDFGraph.h:837
LLVM_ABI NodeList getRelatedRefs(Instr IA, Ref RA) const
void unlinkDef(Def DA, bool RemoveFromOwner)
Definition RDFGraph.h:809
static bool IsUse(const Node BA)
Definition RDFGraph.h:832
const PhysicalRegisterInfo & getPRI() const
Definition RDFGraph.h:700
LLVM_ABI void markBlock(NodeId B, DefStackMap &DefM)
LLVM_ABI NodeBase * ptr(NodeId N) const
Definition RDFGraph.cpp:762
Block findBlock(MachineBasicBlock *BB) const
Definition RDFGraph.h:801
LLVM_ABI bool hasUntrackedRef(Stmt S, bool IgnoreReserved=true) const
DenseMap< RegisterId, DefStack > DefStackMap
Definition RDFGraph.h:774
const TargetRegisterInfo & getTRI() const
Definition RDFGraph.h:699
LLVM_ABI void pushAllDefs(Instr IA, DefStackMap &DM)
NodeAddr< T > addr(NodeId N) const
Definition RDFGraph.h:692
LLVM_ABI void linkToDef(NodeId Self, Def DA)
Definition RDFGraph.cpp:440
MachineFunction * getCode() const
Definition RDFGraph.h:652
LLVM_ABI Block findBlock(const MachineBasicBlock *BB, const DataFlowGraph &G) const
Definition RDFGraph.cpp:569
LLVM_ABI Block getEntryBlock(const DataFlowGraph &G)
Definition RDFGraph.cpp:579
LLVM_ABI Node getOwner(const DataFlowGraph &G)
Definition RDFGraph.cpp:526
LLVM_ABI NodeId id(const NodeBase *P) const
Definition RDFGraph.cpp:371
LLVM_ABI void clear()
Definition RDFGraph.cpp:383
LLVM_ABI Node New()
Definition RDFGraph.cpp:360
static uint16_t flags(uint16_t T)
Definition RDFGraph.h:303
static uint16_t kind(uint16_t T)
Definition RDFGraph.h:300
static uint16_t type(uint16_t T)
Definition RDFGraph.h:297
NodeId getNext() const
Definition RDFGraph.h:495
void setFlags(uint16_t F)
Definition RDFGraph.h:499
Ref_struct RefData
Definition RDFGraph.h:540
uint16_t getType() const
Definition RDFGraph.h:492
LLVM_ABI void append(Node NA)
Definition RDFGraph.cpp:390
uint16_t getFlags() const
Definition RDFGraph.h:494
void setNext(NodeId N)
Definition RDFGraph.h:507
Code_struct CodeData
Definition RDFGraph.h:541
uint16_t getKind() const
Definition RDFGraph.h:493
NodeId getPredecessor() const
Definition RDFGraph.h:602
LLVM_ABI void setRegRef(RegisterRef RR, DataFlowGraph &G)
Definition RDFGraph.cpp:412
LLVM_ABI RegisterRef getRegRef(const DataFlowGraph &G) const
Definition RDFGraph.cpp:402
LLVM_ABI Node getOwner(const DataFlowGraph &G)
Definition RDFGraph.cpp:428
iterator_range< ref_iterator > refs() const
constexpr bool isReg() const
static constexpr bool isMaskId(RegisterId Id)
static constexpr bool isRegId(RegisterId Id)
constexpr MCRegister asMCReg() const
MachineInstr * getCode() const
Definition RDFGraph.h:638
virtual bool isFixedReg(const MachineInstr &In, unsigned OpNum) const
Definition RDFGraph.cpp:608
const TargetInstrInfo & TII
Definition RDFGraph.h:460
virtual bool isPreserving(const MachineInstr &In, unsigned OpNum) const
Definition RDFGraph.cpp:589
virtual bool isClobbering(const MachineInstr &In, unsigned OpNum) const
Definition RDFGraph.cpp:595
LLVM_ABI void linkToDef(NodeId Self, Def DA)
Definition RDFGraph.cpp:447