LLVM  5.0.0
RDFLiveness.cpp
Go to the documentation of this file.
1 //===--- RDFLiveness.cpp --------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Computation of the liveness information from the data-flow graph.
11 //
12 // The main functionality of this code is to compute block live-in
13 // information. With the live-in information in place, the placement
14 // of kill flags can also be recalculated.
15 //
16 // The block live-in calculation is based on the ideas from the following
17 // publication:
18 //
19 // Dibyendu Das, Ramakrishna Upadrasta, Benoit Dupont de Dinechin.
20 // "Efficient Liveness Computation Using Merge Sets and DJ-Graphs."
21 // ACM Transactions on Architecture and Code Optimization, Association for
22 // Computing Machinery, 2012, ACM TACO Special Issue on "High-Performance
23 // and Embedded Architectures and Compilers", 8 (4),
24 // <10.1145/2086696.2086706>. <hal-00647369>
25 //
26 #include "RDFLiveness.h"
27 #include "RDFGraph.h"
28 #include "llvm/ADT/SetVector.h"
36 
37 using namespace llvm;
38 using namespace rdf;
39 
40 static cl::opt<unsigned> MaxRecNest("rdf-liveness-max-rec", cl::init(25),
41  cl::Hidden, cl::desc("Maximum recursion level"));
42 
43 namespace llvm {
44 namespace rdf {
45  template<>
46  raw_ostream &operator<< (raw_ostream &OS, const Print<Liveness::RefMap> &P) {
47  OS << '{';
48  for (auto &I : P.Obj) {
49  OS << ' ' << PrintReg(I.first, &P.G.getTRI()) << '{';
50  for (auto J = I.second.begin(), E = I.second.end(); J != E; ) {
51  OS << Print<NodeId>(J->first, P.G) << PrintLaneMaskOpt(J->second);
52  if (++J != E)
53  OS << ',';
54  }
55  OS << '}';
56  }
57  OS << " }";
58  return OS;
59  }
60 } // namespace rdf
61 } // namespace llvm
62 
63 // The order in the returned sequence is the order of reaching defs in the
64 // upward traversal: the first def is the closest to the given reference RefA,
65 // the next one is further up, and so on.
66 // The list ends at a reaching phi def, or when the reference from RefA is
67 // covered by the defs in the list (see FullChain).
68 // This function provides two modes of operation:
69 // (1) Returning the sequence of reaching defs for a particular reference
70 // node. This sequence will terminate at the first phi node [1].
71 // (2) Returning a partial sequence of reaching defs, where the final goal
72 // is to traverse past phi nodes to the actual defs arising from the code
73 // itself.
74 // In mode (2), the register reference for which the search was started
75 // may be different from the reference node RefA, for which this call was
76 // made, hence the argument RefRR, which holds the original register.
77 // Also, some definitions may have already been encountered in a previous
78 // call that will influence register covering. The register references
79 // already defined are passed in through DefRRs.
80 // In mode (1), the "continuation" considerations do not apply, and the
81 // RefRR is the same as the register in RefA, and the set DefRRs is empty.
82 //
83 // [1] It is possible for multiple phi nodes to be included in the returned
84 // sequence:
85 // SubA = phi ...
86 // SubB = phi ...
87 // ... = SuperAB(rdef:SubA), SuperAB"(rdef:SubB)
88 // However, these phi nodes are independent from one another in terms of
89 // the data-flow.
90 
92  NodeAddr<RefNode*> RefA, bool TopShadows, bool FullChain,
93  const RegisterAggr &DefRRs) {
94  NodeList RDefs; // Return value.
95  SetVector<NodeId> DefQ;
96  SetVector<NodeId> Owners;
97 
98  // Dead defs will be treated as if they were live, since they are actually
99  // on the data-flow path. They cannot be ignored because even though they
100  // do not generate meaningful values, they still modify registers.
101 
102  // If the reference is undefined, there is nothing to do.
103  if (RefA.Addr->getFlags() & NodeAttrs::Undef)
104  return RDefs;
105 
106  // The initial queue should not have reaching defs for shadows. The
107  // whole point of a shadow is that it will have a reaching def that
108  // is not aliased to the reaching defs of the related shadows.
109  NodeId Start = RefA.Id;
110  auto SNA = DFG.addr<RefNode*>(Start);
111  if (NodeId RD = SNA.Addr->getReachingDef())
112  DefQ.insert(RD);
113  if (TopShadows) {
114  for (auto S : DFG.getRelatedRefs(RefA.Addr->getOwner(DFG), RefA))
115  if (NodeId RD = NodeAddr<RefNode*>(S).Addr->getReachingDef())
116  DefQ.insert(RD);
117  }
118 
119  // Collect all the reaching defs, going up until a phi node is encountered,
120  // or there are no more reaching defs. From this set, the actual set of
121  // reaching defs will be selected.
122  // The traversal upwards must go on until a covering def is encountered.
123  // It is possible that a collection of non-covering (individually) defs
124  // will be sufficient, but keep going until a covering one is found.
125  for (unsigned i = 0; i < DefQ.size(); ++i) {
126  auto TA = DFG.addr<DefNode*>(DefQ[i]);
127  if (TA.Addr->getFlags() & NodeAttrs::PhiRef)
128  continue;
129  // Stop at the covering/overwriting def of the initial register reference.
130  RegisterRef RR = TA.Addr->getRegRef(DFG);
131  if (!DFG.IsPreservingDef(TA))
132  if (RegisterAggr::isCoverOf(RR, RefRR, PRI))
133  continue;
134  // Get the next level of reaching defs. This will include multiple
135  // reaching defs for shadows.
136  for (auto S : DFG.getRelatedRefs(TA.Addr->getOwner(DFG), TA))
137  if (NodeId RD = NodeAddr<RefNode*>(S).Addr->getReachingDef())
138  DefQ.insert(RD);
139  }
140 
141  // Remove all non-phi defs that are not aliased to RefRR, and collect
142  // the owners of the remaining defs.
143  SetVector<NodeId> Defs;
144  for (NodeId N : DefQ) {
145  auto TA = DFG.addr<DefNode*>(N);
146  bool IsPhi = TA.Addr->getFlags() & NodeAttrs::PhiRef;
147  if (!IsPhi && !PRI.alias(RefRR, TA.Addr->getRegRef(DFG)))
148  continue;
149  Defs.insert(TA.Id);
150  Owners.insert(TA.Addr->getOwner(DFG).Id);
151  }
152 
153  // Return the MachineBasicBlock containing a given instruction.
154  auto Block = [this] (NodeAddr<InstrNode*> IA) -> MachineBasicBlock* {
155  if (IA.Addr->getKind() == NodeAttrs::Stmt)
156  return NodeAddr<StmtNode*>(IA).Addr->getCode()->getParent();
157  assert(IA.Addr->getKind() == NodeAttrs::Phi);
158  NodeAddr<PhiNode*> PA = IA;
159  NodeAddr<BlockNode*> BA = PA.Addr->getOwner(DFG);
160  return BA.Addr->getCode();
161  };
162  // Less(A,B) iff instruction A is further down in the dominator tree than B.
163  auto Less = [&Block,this] (NodeId A, NodeId B) -> bool {
164  if (A == B)
165  return false;
166  auto OA = DFG.addr<InstrNode*>(A), OB = DFG.addr<InstrNode*>(B);
167  MachineBasicBlock *BA = Block(OA), *BB = Block(OB);
168  if (BA != BB)
169  return MDT.dominates(BB, BA);
170  // They are in the same block.
171  bool StmtA = OA.Addr->getKind() == NodeAttrs::Stmt;
172  bool StmtB = OB.Addr->getKind() == NodeAttrs::Stmt;
173  if (StmtA) {
174  if (!StmtB) // OB is a phi and phis dominate statements.
175  return true;
176  MachineInstr *CA = NodeAddr<StmtNode*>(OA).Addr->getCode();
177  MachineInstr *CB = NodeAddr<StmtNode*>(OB).Addr->getCode();
178  // The order must be linear, so tie-break such equalities.
179  if (CA == CB)
180  return A < B;
181  return MDT.dominates(CB, CA);
182  } else {
183  // OA is a phi.
184  if (StmtB)
185  return false;
186  // Both are phis. There is no ordering between phis (in terms of
187  // the data-flow), so tie-break this via node id comparison.
188  return A < B;
189  }
190  };
191 
192  std::vector<NodeId> Tmp(Owners.begin(), Owners.end());
193  std::sort(Tmp.begin(), Tmp.end(), Less);
194 
195  // The vector is a list of instructions, so that defs coming from
196  // the same instruction don't need to be artificially ordered.
197  // Then, when computing the initial segment, and iterating over an
198  // instruction, pick the defs that contribute to the covering (i.e. is
199  // not covered by previously added defs). Check the defs individually,
200  // i.e. first check each def if is covered or not (without adding them
201  // to the tracking set), and then add all the selected ones.
202 
203  // The reason for this is this example:
204  // *d1<A>, *d2<B>, ... Assume A and B are aliased (can happen in phi nodes).
205  // *d3<C> If A \incl BuC, and B \incl AuC, then *d2 would be
206  // covered if we added A first, and A would be covered
207  // if we added B first.
208 
209  RegisterAggr RRs(DefRRs);
210 
211  auto DefInSet = [&Defs] (NodeAddr<RefNode*> TA) -> bool {
212  return TA.Addr->getKind() == NodeAttrs::Def &&
213  Defs.count(TA.Id);
214  };
215  for (NodeId T : Tmp) {
216  if (!FullChain && RRs.hasCoverOf(RefRR))
217  break;
218  auto TA = DFG.addr<InstrNode*>(T);
219  bool IsPhi = DFG.IsCode<NodeAttrs::Phi>(TA);
220  NodeList Ds;
221  for (NodeAddr<DefNode*> DA : TA.Addr->members_if(DefInSet, DFG)) {
222  RegisterRef QR = DA.Addr->getRegRef(DFG);
223  // Add phi defs even if they are covered by subsequent defs. This is
224  // for cases where the reached use is not covered by any of the defs
225  // encountered so far: the phi def is needed to expose the liveness
226  // of that use to the entry of the block.
227  // Example:
228  // phi d1<R3>(,d2,), ... Phi def d1 is covered by d2.
229  // d2<R3>(d1,,u3), ...
230  // ..., u3<D1>(d2) This use needs to be live on entry.
231  if (FullChain || IsPhi || !RRs.hasCoverOf(QR))
232  Ds.push_back(DA);
233  }
234  RDefs.insert(RDefs.end(), Ds.begin(), Ds.end());
235  for (NodeAddr<DefNode*> DA : Ds) {
236  // When collecting a full chain of definitions, do not consider phi
237  // defs to actually define a register.
238  uint16_t Flags = DA.Addr->getFlags();
239  if (!FullChain || !(Flags & NodeAttrs::PhiRef))
240  if (!(Flags & NodeAttrs::Preserving)) // Don't care about Undef here.
241  RRs.insert(DA.Addr->getRegRef(DFG));
242  }
243  }
244 
245  auto DeadP = [](const NodeAddr<DefNode*> DA) -> bool {
246  return DA.Addr->getFlags() & NodeAttrs::Dead;
247  };
248  RDefs.resize(std::distance(RDefs.begin(), remove_if(RDefs, DeadP)));
249 
250  return RDefs;
251 }
252 
253 
254 std::pair<NodeSet,bool>
256  NodeSet &Visited, const NodeSet &Defs) {
257  return getAllReachingDefsRecImpl(RefRR, RefA, Visited, Defs, 0, MaxRecNest);
258 }
259 
260 
261 std::pair<NodeSet,bool>
262 Liveness::getAllReachingDefsRecImpl(RegisterRef RefRR, NodeAddr<RefNode*> RefA,
263  NodeSet &Visited, const NodeSet &Defs, unsigned Nest, unsigned MaxNest) {
264  if (Nest > MaxNest)
265  return { NodeSet(), false };
266  // Collect all defined registers. Do not consider phis to be defining
267  // anything, only collect "real" definitions.
268  RegisterAggr DefRRs(PRI);
269  for (NodeId D : Defs) {
270  const auto DA = DFG.addr<const DefNode*>(D);
271  if (!(DA.Addr->getFlags() & NodeAttrs::PhiRef))
272  DefRRs.insert(DA.Addr->getRegRef(DFG));
273  }
274 
275  NodeList RDs = getAllReachingDefs(RefRR, RefA, false, true, DefRRs);
276  if (RDs.empty())
277  return { Defs, true };
278 
279  // Make a copy of the preexisting definitions and add the newly found ones.
280  NodeSet TmpDefs = Defs;
281  for (NodeAddr<NodeBase*> R : RDs)
282  TmpDefs.insert(R.Id);
283 
284  NodeSet Result = Defs;
285 
286  for (NodeAddr<DefNode*> DA : RDs) {
287  Result.insert(DA.Id);
288  if (!(DA.Addr->getFlags() & NodeAttrs::PhiRef))
289  continue;
290  NodeAddr<PhiNode*> PA = DA.Addr->getOwner(DFG);
291  if (Visited.count(PA.Id))
292  continue;
293  Visited.insert(PA.Id);
294  // Go over all phi uses and get the reaching defs for each use.
295  for (auto U : PA.Addr->members_if(DFG.IsRef<NodeAttrs::Use>, DFG)) {
296  const auto &T = getAllReachingDefsRecImpl(RefRR, U, Visited, TmpDefs,
297  Nest+1, MaxNest);
298  if (!T.second)
299  return { T.first, false };
300  Result.insert(T.first.begin(), T.first.end());
301  }
302  }
303 
304  return { Result, true };
305 }
306 
307 /// Find the nearest ref node aliased to RefRR, going upwards in the data
308 /// flow, starting from the instruction immediately preceding Inst.
311  NodeAddr<BlockNode*> BA = IA.Addr->getOwner(DFG);
312  NodeList Ins = BA.Addr->members(DFG);
313  NodeId FindId = IA.Id;
314  auto E = Ins.rend();
315  auto B = std::find_if(Ins.rbegin(), E,
316  [FindId] (const NodeAddr<InstrNode*> T) {
317  return T.Id == FindId;
318  });
319  // Do not scan IA (which is what B would point to).
320  if (B != E)
321  ++B;
322 
323  do {
324  // Process the range of instructions from B to E.
325  for (NodeAddr<InstrNode*> I : make_range(B, E)) {
326  NodeList Refs = I.Addr->members(DFG);
327  NodeAddr<RefNode*> Clob, Use;
328  // Scan all the refs in I aliased to RefRR, and return the one that
329  // is the closest to the output of I, i.e. def > clobber > use.
330  for (NodeAddr<RefNode*> R : Refs) {
331  if (!PRI.alias(R.Addr->getRegRef(DFG), RefRR))
332  continue;
333  if (DFG.IsDef(R)) {
334  // If it's a non-clobbering def, just return it.
335  if (!(R.Addr->getFlags() & NodeAttrs::Clobbering))
336  return R;
337  Clob = R;
338  } else {
339  Use = R;
340  }
341  }
342  if (Clob.Id != 0)
343  return Clob;
344  if (Use.Id != 0)
345  return Use;
346  }
347 
348  // Go up to the immediate dominator, if any.
349  MachineBasicBlock *BB = BA.Addr->getCode();
350  BA = NodeAddr<BlockNode*>();
351  if (MachineDomTreeNode *N = MDT.getNode(BB)) {
352  if ((N = N->getIDom()))
353  BA = DFG.findBlock(N->getBlock());
354  }
355  if (!BA.Id)
356  break;
357 
358  Ins = BA.Addr->members(DFG);
359  B = Ins.rbegin();
360  E = Ins.rend();
361  } while (true);
362 
363  return NodeAddr<RefNode*>();
364 }
365 
366 
368  NodeAddr<DefNode*> DefA, const RegisterAggr &DefRRs) {
369  NodeSet Uses;
370 
371  // If the original register is already covered by all the intervening
372  // defs, no more uses can be reached.
373  if (DefRRs.hasCoverOf(RefRR))
374  return Uses;
375 
376  // Add all directly reached uses.
377  // If the def is dead, it does not provide a value for any use.
378  bool IsDead = DefA.Addr->getFlags() & NodeAttrs::Dead;
379  NodeId U = !IsDead ? DefA.Addr->getReachedUse() : 0;
380  while (U != 0) {
381  auto UA = DFG.addr<UseNode*>(U);
382  if (!(UA.Addr->getFlags() & NodeAttrs::Undef)) {
383  RegisterRef UR = UA.Addr->getRegRef(DFG);
384  if (PRI.alias(RefRR, UR) && !DefRRs.hasCoverOf(UR))
385  Uses.insert(U);
386  }
387  U = UA.Addr->getSibling();
388  }
389 
390  // Traverse all reached defs. This time dead defs cannot be ignored.
391  for (NodeId D = DefA.Addr->getReachedDef(), NextD; D != 0; D = NextD) {
392  auto DA = DFG.addr<DefNode*>(D);
393  NextD = DA.Addr->getSibling();
394  RegisterRef DR = DA.Addr->getRegRef(DFG);
395  // If this def is already covered, it cannot reach anything new.
396  // Similarly, skip it if it is not aliased to the interesting register.
397  if (DefRRs.hasCoverOf(DR) || !PRI.alias(RefRR, DR))
398  continue;
399  NodeSet T;
400  if (DFG.IsPreservingDef(DA)) {
401  // If it is a preserving def, do not update the set of intervening defs.
402  T = getAllReachedUses(RefRR, DA, DefRRs);
403  } else {
404  RegisterAggr NewDefRRs = DefRRs;
405  NewDefRRs.insert(DR);
406  T = getAllReachedUses(RefRR, DA, NewDefRRs);
407  }
408  Uses.insert(T.begin(), T.end());
409  }
410  return Uses;
411 }
412 
413 
415  RealUseMap.clear();
416 
417  NodeList Phis;
418  NodeAddr<FuncNode*> FA = DFG.getFunc();
419  NodeList Blocks = FA.Addr->members(DFG);
420  for (NodeAddr<BlockNode*> BA : Blocks) {
421  auto Ps = BA.Addr->members_if(DFG.IsCode<NodeAttrs::Phi>, DFG);
422  Phis.insert(Phis.end(), Ps.begin(), Ps.end());
423  }
424 
425  // phi use -> (map: reaching phi -> set of registers defined in between)
426  std::map<NodeId,std::map<NodeId,RegisterAggr>> PhiUp;
427  std::vector<NodeId> PhiUQ; // Work list of phis for upward propagation.
428  std::map<NodeId,RegisterAggr> PhiDRs; // Phi -> registers defined by it.
429 
430  // Go over all phis.
431  for (NodeAddr<PhiNode*> PhiA : Phis) {
432  // Go over all defs and collect the reached uses that are non-phi uses
433  // (i.e. the "real uses").
434  RefMap &RealUses = RealUseMap[PhiA.Id];
435  NodeList PhiRefs = PhiA.Addr->members(DFG);
436 
437  // Have a work queue of defs whose reached uses need to be found.
438  // For each def, add to the queue all reached (non-phi) defs.
439  SetVector<NodeId> DefQ;
440  NodeSet PhiDefs;
441  RegisterAggr DRs(PRI);
442  for (NodeAddr<RefNode*> R : PhiRefs) {
443  if (!DFG.IsRef<NodeAttrs::Def>(R))
444  continue;
445  DRs.insert(R.Addr->getRegRef(DFG));
446  DefQ.insert(R.Id);
447  PhiDefs.insert(R.Id);
448  }
449  PhiDRs.insert(std::make_pair(PhiA.Id, DRs));
450 
451  // Collect the super-set of all possible reached uses. This set will
452  // contain all uses reached from this phi, either directly from the
453  // phi defs, or (recursively) via non-phi defs reached by the phi defs.
454  // This set of uses will later be trimmed to only contain these uses that
455  // are actually reached by the phi defs.
456  for (unsigned i = 0; i < DefQ.size(); ++i) {
457  NodeAddr<DefNode*> DA = DFG.addr<DefNode*>(DefQ[i]);
458  // Visit all reached uses. Phi defs should not really have the "dead"
459  // flag set, but check it anyway for consistency.
460  bool IsDead = DA.Addr->getFlags() & NodeAttrs::Dead;
461  NodeId UN = !IsDead ? DA.Addr->getReachedUse() : 0;
462  while (UN != 0) {
463  NodeAddr<UseNode*> A = DFG.addr<UseNode*>(UN);
464  uint16_t F = A.Addr->getFlags();
465  if ((F & (NodeAttrs::Undef | NodeAttrs::PhiRef)) == 0) {
466  RegisterRef R = PRI.normalize(A.Addr->getRegRef(DFG));
467  RealUses[R.Reg].insert({A.Id,R.Mask});
468  }
469  UN = A.Addr->getSibling();
470  }
471  // Visit all reached defs, and add them to the queue. These defs may
472  // override some of the uses collected here, but that will be handled
473  // later.
474  NodeId DN = DA.Addr->getReachedDef();
475  while (DN != 0) {
476  NodeAddr<DefNode*> A = DFG.addr<DefNode*>(DN);
477  for (auto T : DFG.getRelatedRefs(A.Addr->getOwner(DFG), A)) {
478  uint16_t Flags = NodeAddr<DefNode*>(T).Addr->getFlags();
479  // Must traverse the reached-def chain. Consider:
480  // def(D0) -> def(R0) -> def(R0) -> use(D0)
481  // The reachable use of D0 passes through a def of R0.
482  if (!(Flags & NodeAttrs::PhiRef))
483  DefQ.insert(T.Id);
484  }
485  DN = A.Addr->getSibling();
486  }
487  }
488  // Filter out these uses that appear to be reachable, but really
489  // are not. For example:
490  //
491  // R1:0 = d1
492  // = R1:0 u2 Reached by d1.
493  // R0 = d3
494  // = R1:0 u4 Still reached by d1: indirectly through
495  // the def d3.
496  // R1 = d5
497  // = R1:0 u6 Not reached by d1 (covered collectively
498  // by d3 and d5), but following reached
499  // defs and uses from d1 will lead here.
500  for (auto UI = RealUses.begin(), UE = RealUses.end(); UI != UE; ) {
501  // For each reached register UI->first, there is a set UI->second, of
502  // uses of it. For each such use, check if it is reached by this phi,
503  // i.e. check if the set of its reaching uses intersects the set of
504  // this phi's defs.
505  NodeRefSet Uses = UI->second;
506  UI->second.clear();
507  for (std::pair<NodeId,LaneBitmask> I : Uses) {
508  auto UA = DFG.addr<UseNode*>(I.first);
509  // Undef flag is checked above.
510  assert((UA.Addr->getFlags() & NodeAttrs::Undef) == 0);
511  RegisterRef R(UI->first, I.second);
512  // Calculate the exposed part of the reached use.
513  RegisterAggr Covered(PRI);
514  for (NodeAddr<DefNode*> DA : getAllReachingDefs(R, UA)) {
515  if (PhiDefs.count(DA.Id))
516  break;
517  Covered.insert(DA.Addr->getRegRef(DFG));
518  }
519  if (RegisterRef RC = Covered.clearIn(R)) {
520  // We are updating the map for register UI->first, so we need
521  // to map RC to be expressed in terms of that register.
522  RegisterRef S = PRI.mapTo(RC, UI->first);
523  UI->second.insert({I.first, S.Mask});
524  }
525  }
526  UI = UI->second.empty() ? RealUses.erase(UI) : std::next(UI);
527  }
528 
529  // If this phi reaches some "real" uses, add it to the queue for upward
530  // propagation.
531  if (!RealUses.empty())
532  PhiUQ.push_back(PhiA.Id);
533 
534  // Go over all phi uses and check if the reaching def is another phi.
535  // Collect the phis that are among the reaching defs of these uses.
536  // While traversing the list of reaching defs for each phi use, accumulate
537  // the set of registers defined between this phi (PhiA) and the owner phi
538  // of the reaching def.
539  NodeSet SeenUses;
540 
541  for (auto I : PhiRefs) {
542  if (!DFG.IsRef<NodeAttrs::Use>(I) || SeenUses.count(I.Id))
543  continue;
544  NodeAddr<PhiUseNode*> PUA = I;
545  if (PUA.Addr->getReachingDef() == 0)
546  continue;
547 
548  RegisterRef UR = PUA.Addr->getRegRef(DFG);
549  NodeList Ds = getAllReachingDefs(UR, PUA, true, false, NoRegs);
550  RegisterAggr DefRRs(PRI);
551 
552  for (NodeAddr<DefNode*> D : Ds) {
553  if (D.Addr->getFlags() & NodeAttrs::PhiRef) {
554  NodeId RP = D.Addr->getOwner(DFG).Id;
555  std::map<NodeId,RegisterAggr> &M = PhiUp[PUA.Id];
556  auto F = M.find(RP);
557  if (F == M.end())
558  M.insert(std::make_pair(RP, DefRRs));
559  else
560  F->second.insert(DefRRs);
561  }
562  DefRRs.insert(D.Addr->getRegRef(DFG));
563  }
564 
565  for (NodeAddr<PhiUseNode*> T : DFG.getRelatedRefs(PhiA, PUA))
566  SeenUses.insert(T.Id);
567  }
568  }
569 
570  if (Trace) {
571  dbgs() << "Phi-up-to-phi map with intervening defs:\n";
572  for (auto I : PhiUp) {
573  dbgs() << "phi " << Print<NodeId>(I.first, DFG) << " -> {";
574  for (auto R : I.second)
575  dbgs() << ' ' << Print<NodeId>(R.first, DFG)
576  << Print<RegisterAggr>(R.second, DFG);
577  dbgs() << " }\n";
578  }
579  }
580 
581  // Propagate the reached registers up in the phi chain.
582  //
583  // The following type of situation needs careful handling:
584  //
585  // phi d1<R1:0> (1)
586  // |
587  // ... d2<R1>
588  // |
589  // phi u3<R1:0> (2)
590  // |
591  // ... u4<R1>
592  //
593  // The phi node (2) defines a register pair R1:0, and reaches a "real"
594  // use u4 of just R1. The same phi node is also known to reach (upwards)
595  // the phi node (1). However, the use u4 is not reached by phi (1),
596  // because of the intervening definition d2 of R1. The data flow between
597  // phis (1) and (2) is restricted to R1:0 minus R1, i.e. R0.
598  //
599  // When propagating uses up the phi chains, get the all reaching defs
600  // for a given phi use, and traverse the list until the propagated ref
601  // is covered, or until reaching the final phi. Only assume that the
602  // reference reaches the phi in the latter case.
603 
604  for (unsigned i = 0; i < PhiUQ.size(); ++i) {
605  auto PA = DFG.addr<PhiNode*>(PhiUQ[i]);
606  NodeList PUs = PA.Addr->members_if(DFG.IsRef<NodeAttrs::Use>, DFG);
607  RefMap &RUM = RealUseMap[PA.Id];
608 
609  for (NodeAddr<UseNode*> UA : PUs) {
610  std::map<NodeId,RegisterAggr> &PUM = PhiUp[UA.Id];
611  RegisterRef UR = PRI.normalize(UA.Addr->getRegRef(DFG));
612  for (const std::pair<NodeId,RegisterAggr> &P : PUM) {
613  bool Changed = false;
614  const RegisterAggr &MidDefs = P.second;
615 
616  // Collect the set PropUp of uses that are reached by the current
617  // phi PA, and are not covered by any intervening def between the
618  // currently visited use UA and the the upward phi P.
619 
620  if (MidDefs.hasCoverOf(UR))
621  continue;
622 
623  // General algorithm:
624  // for each (R,U) : U is use node of R, U is reached by PA
625  // if MidDefs does not cover (R,U)
626  // then add (R-MidDefs,U) to RealUseMap[P]
627  //
628  for (const std::pair<RegisterId,NodeRefSet> &T : RUM) {
629  RegisterRef R(T.first);
630  // The current phi (PA) could be a phi for a regmask. It could
631  // reach a whole variety of uses that are not related to the
632  // specific upward phi (P.first).
633  const RegisterAggr &DRs = PhiDRs.at(P.first);
634  if (!DRs.hasAliasOf(R))
635  continue;
636  R = PRI.mapTo(DRs.intersectWith(R), T.first);
637  for (std::pair<NodeId,LaneBitmask> V : T.second) {
638  LaneBitmask M = R.Mask & V.second;
639  if (M.none())
640  continue;
641  if (RegisterRef SS = MidDefs.clearIn(RegisterRef(R.Reg, M))) {
642  NodeRefSet &RS = RealUseMap[P.first][SS.Reg];
643  Changed |= RS.insert({V.first,SS.Mask}).second;
644  }
645  }
646  }
647 
648  if (Changed)
649  PhiUQ.push_back(P.first);
650  }
651  }
652  }
653 
654  if (Trace) {
655  dbgs() << "Real use map:\n";
656  for (auto I : RealUseMap) {
657  dbgs() << "phi " << Print<NodeId>(I.first, DFG);
658  NodeAddr<PhiNode*> PA = DFG.addr<PhiNode*>(I.first);
659  NodeList Ds = PA.Addr->members_if(DFG.IsRef<NodeAttrs::Def>, DFG);
660  if (!Ds.empty()) {
661  RegisterRef RR = NodeAddr<DefNode*>(Ds[0]).Addr->getRegRef(DFG);
662  dbgs() << '<' << Print<RegisterRef>(RR, DFG) << '>';
663  } else {
664  dbgs() << "<noreg>";
665  }
666  dbgs() << " -> " << Print<RefMap>(I.second, DFG) << '\n';
667  }
668  }
669 }
670 
671 
673  // Populate the node-to-block map. This speeds up the calculations
674  // significantly.
675  NBMap.clear();
676  for (NodeAddr<BlockNode*> BA : DFG.getFunc().Addr->members(DFG)) {
677  MachineBasicBlock *BB = BA.Addr->getCode();
678  for (NodeAddr<InstrNode*> IA : BA.Addr->members(DFG)) {
679  for (NodeAddr<RefNode*> RA : IA.Addr->members(DFG))
680  NBMap.insert(std::make_pair(RA.Id, BB));
681  NBMap.insert(std::make_pair(IA.Id, BB));
682  }
683  }
684 
685  MachineFunction &MF = DFG.getMF();
686 
687  // Compute IDF first, then the inverse.
688  decltype(IIDF) IDF;
689  for (MachineBasicBlock &B : MF) {
690  auto F1 = MDF.find(&B);
691  if (F1 == MDF.end())
692  continue;
693  SetVector<MachineBasicBlock*> IDFB(F1->second.begin(), F1->second.end());
694  for (unsigned i = 0; i < IDFB.size(); ++i) {
695  auto F2 = MDF.find(IDFB[i]);
696  if (F2 != MDF.end())
697  IDFB.insert(F2->second.begin(), F2->second.end());
698  }
699  // Add B to the IDF(B). This will put B in the IIDF(B).
700  IDFB.insert(&B);
701  IDF[&B].insert(IDFB.begin(), IDFB.end());
702  }
703 
704  for (auto I : IDF)
705  for (auto S : I.second)
706  IIDF[S].insert(I.first);
707 
708  computePhiInfo();
709 
710  NodeAddr<FuncNode*> FA = DFG.getFunc();
711  NodeList Blocks = FA.Addr->members(DFG);
712 
713  // Build the phi live-on-entry map.
714  for (NodeAddr<BlockNode*> BA : Blocks) {
715  MachineBasicBlock *MB = BA.Addr->getCode();
716  RefMap &LON = PhiLON[MB];
717  for (auto P : BA.Addr->members_if(DFG.IsCode<NodeAttrs::Phi>, DFG))
718  for (const RefMap::value_type &S : RealUseMap[P.Id])
719  LON[S.first].insert(S.second.begin(), S.second.end());
720  }
721 
722  if (Trace) {
723  dbgs() << "Phi live-on-entry map:\n";
724  for (auto &I : PhiLON)
725  dbgs() << "block #" << I.first->getNumber() << " -> "
726  << Print<RefMap>(I.second, DFG) << '\n';
727  }
728 
729  // Build the phi live-on-exit map. Each phi node has some set of reached
730  // "real" uses. Propagate this set backwards into the block predecessors
731  // through the reaching defs of the corresponding phi uses.
732  for (NodeAddr<BlockNode*> BA : Blocks) {
733  NodeList Phis = BA.Addr->members_if(DFG.IsCode<NodeAttrs::Phi>, DFG);
734  for (NodeAddr<PhiNode*> PA : Phis) {
735  RefMap &RUs = RealUseMap[PA.Id];
736  if (RUs.empty())
737  continue;
738 
739  NodeSet SeenUses;
740  for (auto U : PA.Addr->members_if(DFG.IsRef<NodeAttrs::Use>, DFG)) {
741  if (!SeenUses.insert(U.Id).second)
742  continue;
743  NodeAddr<PhiUseNode*> PUA = U;
744  if (PUA.Addr->getReachingDef() == 0)
745  continue;
746 
747  // Each phi has some set (possibly empty) of reached "real" uses,
748  // that is, uses that are part of the compiled program. Such a use
749  // may be located in some farther block, but following a chain of
750  // reaching defs will eventually lead to this phi.
751  // Any chain of reaching defs may fork at a phi node, but there
752  // will be a path upwards that will lead to this phi. Now, this
753  // chain will need to fork at this phi, since some of the reached
754  // uses may have definitions joining in from multiple predecessors.
755  // For each reached "real" use, identify the set of reaching defs
756  // coming from each predecessor P, and add them to PhiLOX[P].
757  //
758  auto PrA = DFG.addr<BlockNode*>(PUA.Addr->getPredecessor());
759  RefMap &LOX = PhiLOX[PrA.Addr->getCode()];
760 
761  for (const std::pair<RegisterId,NodeRefSet> &RS : RUs) {
762  // We need to visit each individual use.
763  for (std::pair<NodeId,LaneBitmask> P : RS.second) {
764  // Create a register ref corresponding to the use, and find
765  // all reaching defs starting from the phi use, and treating
766  // all related shadows as a single use cluster.
767  RegisterRef S(RS.first, P.second);
768  NodeList Ds = getAllReachingDefs(S, PUA, true, false, NoRegs);
769  for (NodeAddr<DefNode*> D : Ds) {
770  // Calculate the mask corresponding to the visited def.
771  RegisterAggr TA(PRI);
772  TA.insert(D.Addr->getRegRef(DFG)).intersect(S);
773  LaneBitmask TM = TA.makeRegRef().Mask;
774  LOX[S.Reg].insert({D.Id, TM});
775  }
776  }
777  }
778 
779  for (NodeAddr<PhiUseNode*> T : DFG.getRelatedRefs(PA, PUA))
780  SeenUses.insert(T.Id);
781  } // for U : phi uses
782  } // for P : Phis
783  } // for B : Blocks
784 
785  if (Trace) {
786  dbgs() << "Phi live-on-exit map:\n";
787  for (auto &I : PhiLOX)
788  dbgs() << "block #" << I.first->getNumber() << " -> "
789  << Print<RefMap>(I.second, DFG) << '\n';
790  }
791 
792  RefMap LiveIn;
793  traverse(&MF.front(), LiveIn);
794 
795  // Add function live-ins to the live-in set of the function entry block.
796  LiveMap[&MF.front()].insert(DFG.getLiveIns());
797 
798  if (Trace) {
799  // Dump the liveness map
800  for (MachineBasicBlock &B : MF) {
801  std::vector<RegisterRef> LV;
802  for (auto I = B.livein_begin(), E = B.livein_end(); I != E; ++I)
803  LV.push_back(RegisterRef(I->PhysReg, I->LaneMask));
804  std::sort(LV.begin(), LV.end());
805  dbgs() << "BB#" << B.getNumber() << "\t rec = {";
806  for (auto I : LV)
807  dbgs() << ' ' << Print<RegisterRef>(I, DFG);
808  dbgs() << " }\n";
809  //dbgs() << "\tcomp = " << Print<RegisterAggr>(LiveMap[&B], DFG) << '\n';
810 
811  LV.clear();
812  const RegisterAggr &LG = LiveMap[&B];
813  for (auto I = LG.rr_begin(), E = LG.rr_end(); I != E; ++I)
814  LV.push_back(*I);
815  std::sort(LV.begin(), LV.end());
816  dbgs() << "\tcomp = {";
817  for (auto I : LV)
818  dbgs() << ' ' << Print<RegisterRef>(I, DFG);
819  dbgs() << " }\n";
820 
821  }
822  }
823 }
824 
825 
827  for (auto &B : DFG.getMF()) {
828  // Remove all live-ins.
829  std::vector<unsigned> T;
830  for (auto I = B.livein_begin(), E = B.livein_end(); I != E; ++I)
831  T.push_back(I->PhysReg);
832  for (auto I : T)
833  B.removeLiveIn(I);
834  // Add the newly computed live-ins.
835  const RegisterAggr &LiveIns = LiveMap[&B];
836  for (auto I = LiveIns.rr_begin(), E = LiveIns.rr_end(); I != E; ++I) {
837  RegisterRef R = *I;
838  B.addLiveIn({MCPhysReg(R.Reg), R.Mask});
839  }
840  }
841 }
842 
843 
845  for (auto &B : DFG.getMF())
846  resetKills(&B);
847 }
848 
849 
851  auto CopyLiveIns = [this] (MachineBasicBlock *B, BitVector &LV) -> void {
852  for (auto I : B->liveins()) {
853  MCSubRegIndexIterator S(I.PhysReg, &TRI);
854  if (!S.isValid()) {
855  LV.set(I.PhysReg);
856  continue;
857  }
858  do {
860  if ((M & I.LaneMask).any())
861  LV.set(S.getSubReg());
862  ++S;
863  } while (S.isValid());
864  }
865  };
866 
867  BitVector LiveIn(TRI.getNumRegs()), Live(TRI.getNumRegs());
868  CopyLiveIns(B, LiveIn);
869  for (auto SI : B->successors())
870  CopyLiveIns(SI, Live);
871 
872  for (auto I = B->rbegin(), E = B->rend(); I != E; ++I) {
873  MachineInstr *MI = &*I;
874  if (MI->isDebugValue())
875  continue;
876 
877  MI->clearKillInfo();
878  for (auto &Op : MI->operands()) {
879  // An implicit def of a super-register may not necessarily start a
880  // live range of it, since an implicit use could be used to keep parts
881  // of it live. Instead of analyzing the implicit operands, ignore
882  // implicit defs.
883  if (!Op.isReg() || !Op.isDef() || Op.isImplicit())
884  continue;
885  unsigned R = Op.getReg();
887  continue;
888  for (MCSubRegIterator SR(R, &TRI, true); SR.isValid(); ++SR)
889  Live.reset(*SR);
890  }
891  for (auto &Op : MI->operands()) {
892  if (!Op.isReg() || !Op.isUse() || Op.isUndef())
893  continue;
894  unsigned R = Op.getReg();
896  continue;
897  bool IsLive = false;
898  for (MCRegAliasIterator AR(R, &TRI, true); AR.isValid(); ++AR) {
899  if (!Live[*AR])
900  continue;
901  IsLive = true;
902  break;
903  }
904  if (!IsLive)
905  Op.setIsKill(true);
906  for (MCSubRegIterator SR(R, &TRI, true); SR.isValid(); ++SR)
907  Live.set(*SR);
908  }
909  }
910 }
911 
912 
913 // Helper function to obtain the basic block containing the reaching def
914 // of the given use.
915 MachineBasicBlock *Liveness::getBlockWithRef(NodeId RN) const {
916  auto F = NBMap.find(RN);
917  if (F != NBMap.end())
918  return F->second;
919  llvm_unreachable("Node id not in map");
920 }
921 
922 
923 void Liveness::traverse(MachineBasicBlock *B, RefMap &LiveIn) {
924  // The LiveIn map, for each (physical) register, contains the set of live
925  // reaching defs of that register that are live on entry to the associated
926  // block.
927 
928  // The summary of the traversal algorithm:
929  //
930  // R is live-in in B, if there exists a U(R), such that rdef(R) dom B
931  // and (U \in IDF(B) or B dom U).
932  //
933  // for (C : children) {
934  // LU = {}
935  // traverse(C, LU)
936  // LiveUses += LU
937  // }
938  //
939  // LiveUses -= Defs(B);
940  // LiveUses += UpwardExposedUses(B);
941  // for (C : IIDF[B])
942  // for (U : LiveUses)
943  // if (Rdef(U) dom C)
944  // C.addLiveIn(U)
945  //
946 
947  // Go up the dominator tree (depth-first).
948  MachineDomTreeNode *N = MDT.getNode(B);
949  for (auto I : *N) {
950  RefMap L;
951  MachineBasicBlock *SB = I->getBlock();
952  traverse(SB, L);
953 
954  for (auto S : L)
955  LiveIn[S.first].insert(S.second.begin(), S.second.end());
956  }
957 
958  if (Trace) {
959  dbgs() << "\n-- BB#" << B->getNumber() << ": " << __func__
960  << " after recursion into: {";
961  for (auto I : *N)
962  dbgs() << ' ' << I->getBlock()->getNumber();
963  dbgs() << " }\n";
964  dbgs() << " LiveIn: " << Print<RefMap>(LiveIn, DFG) << '\n';
965  dbgs() << " Local: " << Print<RegisterAggr>(LiveMap[B], DFG) << '\n';
966  }
967 
968  // Add reaching defs of phi uses that are live on exit from this block.
969  RefMap &PUs = PhiLOX[B];
970  for (auto &S : PUs)
971  LiveIn[S.first].insert(S.second.begin(), S.second.end());
972 
973  if (Trace) {
974  dbgs() << "after LOX\n";
975  dbgs() << " LiveIn: " << Print<RefMap>(LiveIn, DFG) << '\n';
976  dbgs() << " Local: " << Print<RegisterAggr>(LiveMap[B], DFG) << '\n';
977  }
978 
979  // The LiveIn map at this point has all defs that are live-on-exit from B,
980  // as if they were live-on-entry to B. First, we need to filter out all
981  // defs that are present in this block. Then we will add reaching defs of
982  // all upward-exposed uses.
983 
984  // To filter out the defs, first make a copy of LiveIn, and then re-populate
985  // LiveIn with the defs that should remain.
986  RefMap LiveInCopy = LiveIn;
987  LiveIn.clear();
988 
989  for (const std::pair<RegisterId,NodeRefSet> &LE : LiveInCopy) {
990  RegisterRef LRef(LE.first);
991  NodeRefSet &NewDefs = LiveIn[LRef.Reg]; // To be filled.
992  const NodeRefSet &OldDefs = LE.second;
993  for (NodeRef OR : OldDefs) {
994  // R is a def node that was live-on-exit
995  auto DA = DFG.addr<DefNode*>(OR.first);
996  NodeAddr<InstrNode*> IA = DA.Addr->getOwner(DFG);
997  NodeAddr<BlockNode*> BA = IA.Addr->getOwner(DFG);
998  if (B != BA.Addr->getCode()) {
999  // Defs from a different block need to be preserved. Defs from this
1000  // block will need to be processed further, except for phi defs, the
1001  // liveness of which is handled through the PhiLON/PhiLOX maps.
1002  NewDefs.insert(OR);
1003  continue;
1004  }
1005 
1006  // Defs from this block need to stop the liveness from being
1007  // propagated upwards. This only applies to non-preserving defs,
1008  // and to the parts of the register actually covered by those defs.
1009  // (Note that phi defs should always be preserving.)
1010  RegisterAggr RRs(PRI);
1011  LRef.Mask = OR.second;
1012 
1013  if (!DFG.IsPreservingDef(DA)) {
1014  assert(!(IA.Addr->getFlags() & NodeAttrs::Phi));
1015  // DA is a non-phi def that is live-on-exit from this block, and
1016  // that is also located in this block. LRef is a register ref
1017  // whose use this def reaches. If DA covers LRef, then no part
1018  // of LRef is exposed upwards.A
1019  if (RRs.insert(DA.Addr->getRegRef(DFG)).hasCoverOf(LRef))
1020  continue;
1021  }
1022 
1023  // DA itself was not sufficient to cover LRef. In general, it is
1024  // the last in a chain of aliased defs before the exit from this block.
1025  // There could be other defs in this block that are a part of that
1026  // chain. Check that now: accumulate the registers from these defs,
1027  // and if they all together cover LRef, it is not live-on-entry.
1029  // DefNode -> InstrNode -> BlockNode.
1030  NodeAddr<InstrNode*> ITA = TA.Addr->getOwner(DFG);
1031  NodeAddr<BlockNode*> BTA = ITA.Addr->getOwner(DFG);
1032  // Reaching defs are ordered in the upward direction.
1033  if (BTA.Addr->getCode() != B) {
1034  // We have reached past the beginning of B, and the accumulated
1035  // registers are not covering LRef. The first def from the
1036  // upward chain will be live.
1037  // Subtract all accumulated defs (RRs) from LRef.
1038  RegisterRef T = RRs.clearIn(LRef);
1039  assert(T);
1040  NewDefs.insert({TA.Id,T.Mask});
1041  break;
1042  }
1043 
1044  // TA is in B. Only add this def to the accumulated cover if it is
1045  // not preserving.
1046  if (!(TA.Addr->getFlags() & NodeAttrs::Preserving))
1047  RRs.insert(TA.Addr->getRegRef(DFG));
1048  // If this is enough to cover LRef, then stop.
1049  if (RRs.hasCoverOf(LRef))
1050  break;
1051  }
1052  }
1053  }
1054 
1055  emptify(LiveIn);
1056 
1057  if (Trace) {
1058  dbgs() << "after defs in block\n";
1059  dbgs() << " LiveIn: " << Print<RefMap>(LiveIn, DFG) << '\n';
1060  dbgs() << " Local: " << Print<RegisterAggr>(LiveMap[B], DFG) << '\n';
1061  }
1062 
1063  // Scan the block for upward-exposed uses and add them to the tracking set.
1064  for (auto I : DFG.getFunc().Addr->findBlock(B, DFG).Addr->members(DFG)) {
1065  NodeAddr<InstrNode*> IA = I;
1066  if (IA.Addr->getKind() != NodeAttrs::Stmt)
1067  continue;
1068  for (NodeAddr<UseNode*> UA : IA.Addr->members_if(DFG.IsUse, DFG)) {
1069  if (UA.Addr->getFlags() & NodeAttrs::Undef)
1070  continue;
1071  RegisterRef RR = PRI.normalize(UA.Addr->getRegRef(DFG));
1073  if (getBlockWithRef(D.Id) != B)
1074  LiveIn[RR.Reg].insert({D.Id,RR.Mask});
1075  }
1076  }
1077 
1078  if (Trace) {
1079  dbgs() << "after uses in block\n";
1080  dbgs() << " LiveIn: " << Print<RefMap>(LiveIn, DFG) << '\n';
1081  dbgs() << " Local: " << Print<RegisterAggr>(LiveMap[B], DFG) << '\n';
1082  }
1083 
1084  // Phi uses should not be propagated up the dominator tree, since they
1085  // are not dominated by their corresponding reaching defs.
1086  RegisterAggr &Local = LiveMap[B];
1087  RefMap &LON = PhiLON[B];
1088  for (auto &R : LON) {
1089  LaneBitmask M;
1090  for (auto P : R.second)
1091  M |= P.second;
1092  Local.insert(RegisterRef(R.first,M));
1093  }
1094 
1095  if (Trace) {
1096  dbgs() << "after phi uses in block\n";
1097  dbgs() << " LiveIn: " << Print<RefMap>(LiveIn, DFG) << '\n';
1098  dbgs() << " Local: " << Print<RegisterAggr>(Local, DFG) << '\n';
1099  }
1100 
1101  for (auto C : IIDF[B]) {
1102  RegisterAggr &LiveC = LiveMap[C];
1103  for (const std::pair<RegisterId,NodeRefSet> &S : LiveIn)
1104  for (auto R : S.second)
1105  if (MDT.properlyDominates(getBlockWithRef(R.first), C))
1106  LiveC.insert(RegisterRef(S.first, R.second));
1107  }
1108 }
1109 
1110 
1111 void Liveness::emptify(RefMap &M) {
1112  for (auto I = M.begin(), E = M.end(); I != E; )
1113  I = I->second.empty() ? M.erase(I) : std::next(I);
1114 }
1115 
MachineLoop * L
NodeList members(const DataFlowGraph &G) const
Definition: RDFGraph.cpp:541
MachineFunction & getMF() const
Definition: RDFGraph.h:661
iterator_range< livein_iterator > liveins() const
static cl::opt< unsigned > MaxRecNest("rdf-liveness-max-rec", cl::init(25), cl::Hidden, cl::desc("Maximum recursion level"))
bool isValid() const
isValid - returns true if this iterator is not yet at the end.
NodeId getReachedDef() const
Definition: RDFGraph.h:559
uint16_t getFlags() const
Definition: RDFGraph.h:457
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
NodeList getAllReachingDefs(RegisterRef RefRR, NodeAddr< RefNode * > RefA, bool TopShadows, bool FullChain, const RegisterAggr &DefRRs)
Definition: RDFLiveness.cpp:91
auto remove_if(R &&Range, UnaryPredicate P) -> decltype(std::begin(Range))
Provide wrappers to std::remove_if which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:858
rr_iterator rr_end() const
Definition: RDFRegisters.h:198
std::set< NodeRef > NodeRefSet
Definition: RDFLiveness.h:47
static bool IsPreservingDef(const NodeAddr< DefNode * > DA)
Definition: RDFGraph.h:809
bool isValid() const
Returns true if this iterator is not yet at the end.
unsigned second
LaneBitmask getSubRegIndexLaneMask(unsigned SubIdx) const
Return a bitmask representing the parts of a register that are covered by SubIdx. ...
iterator_range< mop_iterator > operands()
Definition: MachineInstr.h:306
iterator end()
Get an iterator to the end of the SetVector.
Definition: SetVector.h:93
size_type size() const
Determine the number of elements in the SetVector.
Definition: SetVector.h:78
iterator_range< succ_iterator > successors()
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:176
void clearKillInfo()
Clears kill flags on all operands.
NodeList getRelatedRefs(NodeAddr< InstrNode * > IA, NodeAddr< RefNode * > RA) const
Definition: RDFGraph.cpp:1139
A Use represents the edge between a Value definition and its users.
Definition: Use.h:56
NodeId getReachedUse() const
Definition: RDFGraph.h:565
static LVILatticeVal intersect(const LVILatticeVal &A, const LVILatticeVal &B)
Combine two sets of facts about the same value into a single set of facts.
RegisterRef mapTo(RegisterRef RR, unsigned R) const
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:60
MachineDomTreeNode * getNode(MachineBasicBlock *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
unsigned getNumRegs() const
Return the number of registers this target has (useful for sizing arrays holding per register informa...
#define F(x, y, z)
Definition: MD5.cpp:55
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition: SetVector.h:142
static bool IsDef(const NodeAddr< NodeBase * > BA)
Definition: RDFGraph.h:794
RegisterRef makeRegRef() const
#define T
std::map< RegisterId, NodeRefSet > RefMap
Definition: RDFLiveness.h:49
iterator begin()
Get an iterator to the beginning of the SetVector.
Definition: SetVector.h:83
Base class for the actual dominator tree node.
NodeAddr< RefNode * > getNearestAliasedRef(RegisterRef RefRR, NodeAddr< InstrNode * > IA)
Find the nearest ref node aliased to RefRR, going upwards in the data flow, starting from the instruc...
Printable PrintReg(unsigned Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubRegIdx=0)
Prints virtual and physical registers with or without a TRI instance.
reverse_iterator rend()
reverse_iterator rbegin()
NodeAddr< NodeBase * > getOwner(const DataFlowGraph &G)
Definition: RDFGraph.cpp:547
NodeList members_if(Predicate P, const DataFlowGraph &G) const
Definition: RDFGraph.h:912
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:131
bool isDebugValue() const
Definition: MachineInstr.h:785
INITIALIZE_PASS(HexagonEarlyIfConversion,"hexagon-eif","Hexagon early if conversion", false, false) bool HexagonEarlyIfConversion MachineBasicBlock * SB
#define P(N)
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:401
static bool IsRef(const NodeAddr< NodeBase * > BA)
Definition: RDFGraph.h:783
bool hasCoverOf(RegisterRef RR) const
constexpr bool none() const
Definition: LaneBitmask.h:52
uint16_t getKind() const
Definition: RDFGraph.h:456
Iterator that enumerates the sub-registers of a Reg and the associated sub-register indices...
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
Definition: SmallVector.h:115
static ManagedStatic< OptionRegistry > OR
Definition: Options.cpp:31
#define A
Definition: LargeTest.cpp:12
MCRegAliasIterator enumerates all registers aliasing Reg.
static bool IsCode(const NodeAddr< NodeBase * > BA)
Definition: RDFGraph.h:789
MCSubRegIterator enumerates all sub-registers of Reg.
RegisterRef intersectWith(RegisterRef RR) const
uint32_t NodeId
Definition: RDFGraph.h:263
NodeId getPredecessor() const
Definition: RDFGraph.h:580
iterator find(MachineBasicBlock *B)
std::pair< NodeId, LaneBitmask > NodeRef
Definition: RDFLiveness.h:46
NodeSet getAllReachedUses(RegisterRef RefRR, NodeAddr< DefNode * > DefA, const RegisterAggr &DefRRs)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
unsigned getSubReg() const
Returns current sub-register.
RegisterAggr & insert(RegisterRef RR)
RegisterRef normalize(RegisterRef RR) const
#define E
Definition: LargeTest.cpp:27
#define B
Definition: LargeTest.cpp:24
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
NodeId getSibling() const
Definition: RDFGraph.h:535
bool alias(RegisterRef RA, RegisterRef RB) const
Definition: RDFRegisters.h:102
const size_t N
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
std::set< NodeId > NodeSet
Definition: RDFGraph.h:513
NodeAddr< FuncNode * > getFunc() const
Definition: RDFGraph.h:660
RegisterRef getRegRef(const DataFlowGraph &G) const
Definition: RDFGraph.cpp:422
static bool IsUse(const NodeAddr< NodeBase * > BA)
Definition: RDFGraph.h:799
iterator insert(iterator I, T &&Elt)
Definition: SmallVector.h:479
unsigned getSubRegIndex() const
Returns sub-register index of the current sub-register.
llvm_unreachable("Unknown RegBank!")
static std::vector< std::string > Flags
Definition: FlagsTest.cpp:8
Representation of each machine instruction.
Definition: MachineInstr.h:59
NodeAddr< NodeBase * > getOwner(const DataFlowGraph &G)
Definition: RDFGraph.cpp:448
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
RegisterRef clearIn(RegisterRef RR) const
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Definition: SmallVector.h:119
size_type count(const key_type &key) const
Count the number of elements of a given key in the SetVector.
Definition: SetVector.h:211
#define C
Definition: LargeTest.cpp:25
#define I(x, y, z)
Definition: MD5.cpp:58
iterator end()
Definition: DenseMap.h:73
MachineBasicBlock * getCode() const
Definition: RDFGraph.h:627
rr_iterator rr_begin() const
Definition: RDFRegisters.h:195
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool isCoverOf(RegisterRef RA, RegisterRef RB, const PhysicalRegisterInfo &PRI)
Definition: RDFRegisters.h:151
const RegisterAggr & getLiveIns() const
Definition: RDFGraph.h:667
A vector that has set insertion semantics.
Definition: SetVector.h:41
NodeAddr< T > addr(NodeId N) const
Definition: RDFGraph.h:656
NodeId getReachingDef() const
Definition: RDFGraph.h:528
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
bool hasAliasOf(RegisterRef RR) const
IRTranslator LLVM IR MI
void sort(Policy policy, RandomAccessIterator Start, RandomAccessIterator End, const Comparator &Comp=Comparator())
Definition: Parallel.h:201
auto find_if(R &&Range, UnaryPredicate P) -> decltype(std::begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:846
bool dominates(const MachineDomTreeNode *A, const MachineDomTreeNode *B) const
NodeAddr< BlockNode * > findBlock(MachineBasicBlock *BB) const
Definition: RDFGraph.h:765
#define D
Definition: LargeTest.cpp:26
std::pair< NodeSet, bool > getAllReachingDefsRec(RegisterRef RefRR, NodeAddr< RefNode * > RefA, NodeSet &Visited, const NodeSet &Defs)
void resize(size_type N)
Definition: SmallVector.h:352