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