LLVM  12.0.0git
LegalizeTypes.cpp
Go to the documentation of this file.
1 //===-- LegalizeTypes.cpp - Common code for DAG type legalizer ------------===//
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 // This file implements the SelectionDAG::LegalizeTypes method. It transforms
10 // an arbitrary well-formed SelectionDAG to only consist of legal types. This
11 // is common code shared among the LegalizeTypes*.cpp files.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "LegalizeTypes.h"
16 #include "SDNodeDbgValue.h"
17 #include "llvm/ADT/SetVector.h"
19 #include "llvm/IR/CallingConv.h"
20 #include "llvm/IR/DataLayout.h"
24 using namespace llvm;
25 
26 #define DEBUG_TYPE "legalize-types"
27 
28 static cl::opt<bool>
29 EnableExpensiveChecks("enable-legalize-types-checking", cl::Hidden);
30 
31 /// Do extensive, expensive, sanity checking.
32 void DAGTypeLegalizer::PerformExpensiveChecks() {
33  // If a node is not processed, then none of its values should be mapped by any
34  // of PromotedIntegers, ExpandedIntegers, ..., ReplacedValues.
35 
36  // If a node is processed, then each value with an illegal type must be mapped
37  // by exactly one of PromotedIntegers, ExpandedIntegers, ..., ReplacedValues.
38  // Values with a legal type may be mapped by ReplacedValues, but not by any of
39  // the other maps.
40 
41  // Note that these invariants may not hold momentarily when processing a node:
42  // the node being processed may be put in a map before being marked Processed.
43 
44  // Note that it is possible to have nodes marked NewNode in the DAG. This can
45  // occur in two ways. Firstly, a node may be created during legalization but
46  // never passed to the legalization core. This is usually due to the implicit
47  // folding that occurs when using the DAG.getNode operators. Secondly, a new
48  // node may be passed to the legalization core, but when analyzed may morph
49  // into a different node, leaving the original node as a NewNode in the DAG.
50  // A node may morph if one of its operands changes during analysis. Whether
51  // it actually morphs or not depends on whether, after updating its operands,
52  // it is equivalent to an existing node: if so, it morphs into that existing
53  // node (CSE). An operand can change during analysis if the operand is a new
54  // node that morphs, or it is a processed value that was mapped to some other
55  // value (as recorded in ReplacedValues) in which case the operand is turned
56  // into that other value. If a node morphs then the node it morphed into will
57  // be used instead of it for legalization, however the original node continues
58  // to live on in the DAG.
59  // The conclusion is that though there may be nodes marked NewNode in the DAG,
60  // all uses of such nodes are also marked NewNode: the result is a fungus of
61  // NewNodes growing on top of the useful nodes, and perhaps using them, but
62  // not used by them.
63 
64  // If a value is mapped by ReplacedValues, then it must have no uses, except
65  // by nodes marked NewNode (see above).
66 
67  // The final node obtained by mapping by ReplacedValues is not marked NewNode.
68  // Note that ReplacedValues should be applied iteratively.
69 
70  // Note that the ReplacedValues map may also map deleted nodes (by iterating
71  // over the DAG we never dereference deleted nodes). This means that it may
72  // also map nodes marked NewNode if the deallocated memory was reallocated as
73  // another node, and that new node was not seen by the LegalizeTypes machinery
74  // (for example because it was created but not used). In general, we cannot
75  // distinguish between new nodes and deleted nodes.
76  SmallVector<SDNode*, 16> NewNodes;
77  for (SDNode &Node : DAG.allnodes()) {
78  // Remember nodes marked NewNode - they are subject to extra checking below.
79  if (Node.getNodeId() == NewNode)
80  NewNodes.push_back(&Node);
81 
82  for (unsigned i = 0, e = Node.getNumValues(); i != e; ++i) {
83  SDValue Res(&Node, i);
84  bool Failed = false;
85  // Don't create a value in map.
86  auto ResId = (ValueToIdMap.count(Res)) ? ValueToIdMap[Res] : 0;
87 
88  unsigned Mapped = 0;
89  if (ResId && (ReplacedValues.find(ResId) != ReplacedValues.end())) {
90  Mapped |= 1;
91  // Check that remapped values are only used by nodes marked NewNode.
92  for (SDNode::use_iterator UI = Node.use_begin(), UE = Node.use_end();
93  UI != UE; ++UI)
94  if (UI.getUse().getResNo() == i)
95  assert(UI->getNodeId() == NewNode &&
96  "Remapped value has non-trivial use!");
97 
98  // Check that the final result of applying ReplacedValues is not
99  // marked NewNode.
100  auto NewValId = ReplacedValues[ResId];
101  auto I = ReplacedValues.find(NewValId);
102  while (I != ReplacedValues.end()) {
103  NewValId = I->second;
104  I = ReplacedValues.find(NewValId);
105  }
106  SDValue NewVal = getSDValue(NewValId);
107  (void)NewVal;
108  assert(NewVal.getNode()->getNodeId() != NewNode &&
109  "ReplacedValues maps to a new node!");
110  }
111  if (ResId && PromotedIntegers.find(ResId) != PromotedIntegers.end())
112  Mapped |= 2;
113  if (ResId && SoftenedFloats.find(ResId) != SoftenedFloats.end())
114  Mapped |= 4;
115  if (ResId && ScalarizedVectors.find(ResId) != ScalarizedVectors.end())
116  Mapped |= 8;
117  if (ResId && ExpandedIntegers.find(ResId) != ExpandedIntegers.end())
118  Mapped |= 16;
119  if (ResId && ExpandedFloats.find(ResId) != ExpandedFloats.end())
120  Mapped |= 32;
121  if (ResId && SplitVectors.find(ResId) != SplitVectors.end())
122  Mapped |= 64;
123  if (ResId && WidenedVectors.find(ResId) != WidenedVectors.end())
124  Mapped |= 128;
125  if (ResId && PromotedFloats.find(ResId) != PromotedFloats.end())
126  Mapped |= 256;
127  if (ResId && SoftPromotedHalfs.find(ResId) != SoftPromotedHalfs.end())
128  Mapped |= 512;
129 
130  if (Node.getNodeId() != Processed) {
131  // Since we allow ReplacedValues to map deleted nodes, it may map nodes
132  // marked NewNode too, since a deleted node may have been reallocated as
133  // another node that has not been seen by the LegalizeTypes machinery.
134  if ((Node.getNodeId() == NewNode && Mapped > 1) ||
135  (Node.getNodeId() != NewNode && Mapped != 0)) {
136  dbgs() << "Unprocessed value in a map!";
137  Failed = true;
138  }
139  } else if (isTypeLegal(Res.getValueType()) || IgnoreNodeResults(&Node)) {
140  if (Mapped > 1) {
141  dbgs() << "Value with legal type was transformed!";
142  Failed = true;
143  }
144  } else {
145  if (Mapped == 0) {
146  dbgs() << "Processed value not in any map!";
147  Failed = true;
148  } else if (Mapped & (Mapped - 1)) {
149  dbgs() << "Value in multiple maps!";
150  Failed = true;
151  }
152  }
153 
154  if (Failed) {
155  if (Mapped & 1)
156  dbgs() << " ReplacedValues";
157  if (Mapped & 2)
158  dbgs() << " PromotedIntegers";
159  if (Mapped & 4)
160  dbgs() << " SoftenedFloats";
161  if (Mapped & 8)
162  dbgs() << " ScalarizedVectors";
163  if (Mapped & 16)
164  dbgs() << " ExpandedIntegers";
165  if (Mapped & 32)
166  dbgs() << " ExpandedFloats";
167  if (Mapped & 64)
168  dbgs() << " SplitVectors";
169  if (Mapped & 128)
170  dbgs() << " WidenedVectors";
171  if (Mapped & 256)
172  dbgs() << " PromotedFloats";
173  if (Mapped & 512)
174  dbgs() << " SoftPromoteHalfs";
175  dbgs() << "\n";
176  llvm_unreachable(nullptr);
177  }
178  }
179  }
180 
181 #ifndef NDEBUG
182  // Checked that NewNodes are only used by other NewNodes.
183  for (unsigned i = 0, e = NewNodes.size(); i != e; ++i) {
184  SDNode *N = NewNodes[i];
185  for (SDNode::use_iterator UI = N->use_begin(), UE = N->use_end();
186  UI != UE; ++UI)
187  assert(UI->getNodeId() == NewNode && "NewNode used by non-NewNode!");
188  }
189 #endif
190 }
191 
192 /// This is the main entry point for the type legalizer. This does a top-down
193 /// traversal of the dag, legalizing types as it goes. Returns "true" if it made
194 /// any changes.
196  bool Changed = false;
197 
198  // Create a dummy node (which is not added to allnodes), that adds a reference
199  // to the root node, preventing it from being deleted, and tracking any
200  // changes of the root.
201  HandleSDNode Dummy(DAG.getRoot());
202  Dummy.setNodeId(Unanalyzed);
203 
204  // The root of the dag may dangle to deleted nodes until the type legalizer is
205  // done. Set it to null to avoid confusion.
206  DAG.setRoot(SDValue());
207 
208  // Walk all nodes in the graph, assigning them a NodeId of 'ReadyToProcess'
209  // (and remembering them) if they are leaves and assigning 'Unanalyzed' if
210  // non-leaves.
211  for (SDNode &Node : DAG.allnodes()) {
212  if (Node.getNumOperands() == 0) {
213  Node.setNodeId(ReadyToProcess);
214  Worklist.push_back(&Node);
215  } else {
216  Node.setNodeId(Unanalyzed);
217  }
218  }
219 
220  // Now that we have a set of nodes to process, handle them all.
221  while (!Worklist.empty()) {
222 #ifndef EXPENSIVE_CHECKS
224 #endif
225  PerformExpensiveChecks();
226 
227  SDNode *N = Worklist.back();
228  Worklist.pop_back();
229  assert(N->getNodeId() == ReadyToProcess &&
230  "Node should be ready if on worklist!");
231 
232  LLVM_DEBUG(dbgs() << "Legalizing node: "; N->dump(&DAG));
233  if (IgnoreNodeResults(N)) {
234  LLVM_DEBUG(dbgs() << "Ignoring node results\n");
235  goto ScanOperands;
236  }
237 
238  // Scan the values produced by the node, checking to see if any result
239  // types are illegal.
240  for (unsigned i = 0, NumResults = N->getNumValues(); i < NumResults; ++i) {
241  EVT ResultVT = N->getValueType(i);
242  LLVM_DEBUG(dbgs() << "Analyzing result type: " << ResultVT.getEVTString()
243  << "\n");
244  switch (getTypeAction(ResultVT)) {
246  LLVM_DEBUG(dbgs() << "Legal result type\n");
247  break;
250  "Scalarization of scalable vectors is not supported.");
251  // The following calls must take care of *all* of the node's results,
252  // not just the illegal result they were passed (this includes results
253  // with a legal type). Results can be remapped using ReplaceValueWith,
254  // or their promoted/expanded/etc values registered in PromotedIntegers,
255  // ExpandedIntegers etc.
257  PromoteIntegerResult(N, i);
258  Changed = true;
259  goto NodeDone;
261  ExpandIntegerResult(N, i);
262  Changed = true;
263  goto NodeDone;
265  SoftenFloatResult(N, i);
266  Changed = true;
267  goto NodeDone;
269  ExpandFloatResult(N, i);
270  Changed = true;
271  goto NodeDone;
273  ScalarizeVectorResult(N, i);
274  Changed = true;
275  goto NodeDone;
277  SplitVectorResult(N, i);
278  Changed = true;
279  goto NodeDone;
281  WidenVectorResult(N, i);
282  Changed = true;
283  goto NodeDone;
285  PromoteFloatResult(N, i);
286  Changed = true;
287  goto NodeDone;
289  SoftPromoteHalfResult(N, i);
290  Changed = true;
291  goto NodeDone;
292  }
293  }
294 
295 ScanOperands:
296  // Scan the operand list for the node, handling any nodes with operands that
297  // are illegal.
298  {
299  unsigned NumOperands = N->getNumOperands();
300  bool NeedsReanalyzing = false;
301  unsigned i;
302  for (i = 0; i != NumOperands; ++i) {
303  if (IgnoreNodeResults(N->getOperand(i).getNode()))
304  continue;
305 
306  const auto Op = N->getOperand(i);
307  LLVM_DEBUG(dbgs() << "Analyzing operand: "; Op.dump(&DAG));
308  EVT OpVT = Op.getValueType();
309  switch (getTypeAction(OpVT)) {
311  LLVM_DEBUG(dbgs() << "Legal operand\n");
312  continue;
315  "Scalarization of scalable vectors is not supported.");
316  // The following calls must either replace all of the node's results
317  // using ReplaceValueWith, and return "false"; or update the node's
318  // operands in place, and return "true".
320  NeedsReanalyzing = PromoteIntegerOperand(N, i);
321  Changed = true;
322  break;
324  NeedsReanalyzing = ExpandIntegerOperand(N, i);
325  Changed = true;
326  break;
328  NeedsReanalyzing = SoftenFloatOperand(N, i);
329  Changed = true;
330  break;
332  NeedsReanalyzing = ExpandFloatOperand(N, i);
333  Changed = true;
334  break;
336  NeedsReanalyzing = ScalarizeVectorOperand(N, i);
337  Changed = true;
338  break;
340  NeedsReanalyzing = SplitVectorOperand(N, i);
341  Changed = true;
342  break;
344  NeedsReanalyzing = WidenVectorOperand(N, i);
345  Changed = true;
346  break;
348  NeedsReanalyzing = PromoteFloatOperand(N, i);
349  Changed = true;
350  break;
352  NeedsReanalyzing = SoftPromoteHalfOperand(N, i);
353  Changed = true;
354  break;
355  }
356  break;
357  }
358 
359  // The sub-method updated N in place. Check to see if any operands are new,
360  // and if so, mark them. If the node needs revisiting, don't add all users
361  // to the worklist etc.
362  if (NeedsReanalyzing) {
363  assert(N->getNodeId() == ReadyToProcess && "Node ID recalculated?");
364 
365  N->setNodeId(NewNode);
366  // Recompute the NodeId and correct processed operands, adding the node to
367  // the worklist if ready.
368  SDNode *M = AnalyzeNewNode(N);
369  if (M == N)
370  // The node didn't morph - nothing special to do, it will be revisited.
371  continue;
372 
373  // The node morphed - this is equivalent to legalizing by replacing every
374  // value of N with the corresponding value of M. So do that now.
375  assert(N->getNumValues() == M->getNumValues() &&
376  "Node morphing changed the number of results!");
377  for (unsigned i = 0, e = N->getNumValues(); i != e; ++i)
378  // Replacing the value takes care of remapping the new value.
379  ReplaceValueWith(SDValue(N, i), SDValue(M, i));
380  assert(N->getNodeId() == NewNode && "Unexpected node state!");
381  // The node continues to live on as part of the NewNode fungus that
382  // grows on top of the useful nodes. Nothing more needs to be done
383  // with it - move on to the next node.
384  continue;
385  }
386 
387  if (i == NumOperands) {
388  LLVM_DEBUG(dbgs() << "Legally typed node: "; N->dump(&DAG);
389  dbgs() << "\n");
390  }
391  }
392 NodeDone:
393 
394  // If we reach here, the node was processed, potentially creating new nodes.
395  // Mark it as processed and add its users to the worklist as appropriate.
396  assert(N->getNodeId() == ReadyToProcess && "Node ID recalculated?");
397  N->setNodeId(Processed);
398 
399  for (SDNode::use_iterator UI = N->use_begin(), E = N->use_end();
400  UI != E; ++UI) {
401  SDNode *User = *UI;
402  int NodeId = User->getNodeId();
403 
404  // This node has two options: it can either be a new node or its Node ID
405  // may be a count of the number of operands it has that are not ready.
406  if (NodeId > 0) {
407  User->setNodeId(NodeId-1);
408 
409  // If this was the last use it was waiting on, add it to the ready list.
410  if (NodeId-1 == ReadyToProcess)
411  Worklist.push_back(User);
412  continue;
413  }
414 
415  // If this is an unreachable new node, then ignore it. If it ever becomes
416  // reachable by being used by a newly created node then it will be handled
417  // by AnalyzeNewNode.
418  if (NodeId == NewNode)
419  continue;
420 
421  // Otherwise, this node is new: this is the first operand of it that
422  // became ready. Its new NodeId is the number of operands it has minus 1
423  // (as this node is now processed).
424  assert(NodeId == Unanalyzed && "Unknown node ID!");
425  User->setNodeId(User->getNumOperands() - 1);
426 
427  // If the node only has a single operand, it is now ready.
428  if (User->getNumOperands() == 1)
429  Worklist.push_back(User);
430  }
431  }
432 
433 #ifndef EXPENSIVE_CHECKS
435 #endif
436  PerformExpensiveChecks();
437 
438  // If the root changed (e.g. it was a dead load) update the root.
439  DAG.setRoot(Dummy.getValue());
440 
441  // Remove dead nodes. This is important to do for cleanliness but also before
442  // the checking loop below. Implicit folding by the DAG.getNode operators and
443  // node morphing can cause unreachable nodes to be around with their flags set
444  // to new.
445  DAG.RemoveDeadNodes();
446 
447  // In a debug build, scan all the nodes to make sure we found them all. This
448  // ensures that there are no cycles and that everything got processed.
449 #ifndef NDEBUG
450  for (SDNode &Node : DAG.allnodes()) {
451  bool Failed = false;
452 
453  // Check that all result types are legal.
454  if (!IgnoreNodeResults(&Node))
455  for (unsigned i = 0, NumVals = Node.getNumValues(); i < NumVals; ++i)
456  if (!isTypeLegal(Node.getValueType(i))) {
457  dbgs() << "Result type " << i << " illegal: ";
458  Node.dump(&DAG);
459  Failed = true;
460  }
461 
462  // Check that all operand types are legal.
463  for (unsigned i = 0, NumOps = Node.getNumOperands(); i < NumOps; ++i)
464  if (!IgnoreNodeResults(Node.getOperand(i).getNode()) &&
465  !isTypeLegal(Node.getOperand(i).getValueType())) {
466  dbgs() << "Operand type " << i << " illegal: ";
467  Node.getOperand(i).dump(&DAG);
468  Failed = true;
469  }
470 
471  if (Node.getNodeId() != Processed) {
472  if (Node.getNodeId() == NewNode)
473  dbgs() << "New node not analyzed?\n";
474  else if (Node.getNodeId() == Unanalyzed)
475  dbgs() << "Unanalyzed node not noticed?\n";
476  else if (Node.getNodeId() > 0)
477  dbgs() << "Operand not processed?\n";
478  else if (Node.getNodeId() == ReadyToProcess)
479  dbgs() << "Not added to worklist?\n";
480  Failed = true;
481  }
482 
483  if (Failed) {
484  Node.dump(&DAG); dbgs() << "\n";
485  llvm_unreachable(nullptr);
486  }
487  }
488 #endif
489 
490  return Changed;
491 }
492 
493 /// The specified node is the root of a subtree of potentially new nodes.
494 /// Correct any processed operands (this may change the node) and calculate the
495 /// NodeId. If the node itself changes to a processed node, it is not remapped -
496 /// the caller needs to take care of this. Returns the potentially changed node.
497 SDNode *DAGTypeLegalizer::AnalyzeNewNode(SDNode *N) {
498  // If this was an existing node that is already done, we're done.
499  if (N->getNodeId() != NewNode && N->getNodeId() != Unanalyzed)
500  return N;
501 
502  // Okay, we know that this node is new. Recursively walk all of its operands
503  // to see if they are new also. The depth of this walk is bounded by the size
504  // of the new tree that was constructed (usually 2-3 nodes), so we don't worry
505  // about revisiting of nodes.
506  //
507  // As we walk the operands, keep track of the number of nodes that are
508  // processed. If non-zero, this will become the new nodeid of this node.
509  // Operands may morph when they are analyzed. If so, the node will be
510  // updated after all operands have been analyzed. Since this is rare,
511  // the code tries to minimize overhead in the non-morphing case.
512 
513  std::vector<SDValue> NewOps;
514  unsigned NumProcessed = 0;
515  for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
516  SDValue OrigOp = N->getOperand(i);
517  SDValue Op = OrigOp;
518 
519  AnalyzeNewValue(Op); // Op may morph.
520 
521  if (Op.getNode()->getNodeId() == Processed)
522  ++NumProcessed;
523 
524  if (!NewOps.empty()) {
525  // Some previous operand changed. Add this one to the list.
526  NewOps.push_back(Op);
527  } else if (Op != OrigOp) {
528  // This is the first operand to change - add all operands so far.
529  NewOps.insert(NewOps.end(), N->op_begin(), N->op_begin() + i);
530  NewOps.push_back(Op);
531  }
532  }
533 
534  // Some operands changed - update the node.
535  if (!NewOps.empty()) {
536  SDNode *M = DAG.UpdateNodeOperands(N, NewOps);
537  if (M != N) {
538  // The node morphed into a different node. Normally for this to happen
539  // the original node would have to be marked NewNode. However this can
540  // in theory momentarily not be the case while ReplaceValueWith is doing
541  // its stuff. Mark the original node NewNode to help sanity checking.
542  N->setNodeId(NewNode);
543  if (M->getNodeId() != NewNode && M->getNodeId() != Unanalyzed)
544  // It morphed into a previously analyzed node - nothing more to do.
545  return M;
546 
547  // It morphed into a different new node. Do the equivalent of passing
548  // it to AnalyzeNewNode: expunge it and calculate the NodeId. No need
549  // to remap the operands, since they are the same as the operands we
550  // remapped above.
551  N = M;
552  }
553  }
554 
555  // Calculate the NodeId.
556  N->setNodeId(N->getNumOperands() - NumProcessed);
557  if (N->getNodeId() == ReadyToProcess)
558  Worklist.push_back(N);
559 
560  return N;
561 }
562 
563 /// Call AnalyzeNewNode, updating the node in Val if needed.
564 /// If the node changes to a processed node, then remap it.
565 void DAGTypeLegalizer::AnalyzeNewValue(SDValue &Val) {
566  Val.setNode(AnalyzeNewNode(Val.getNode()));
567  if (Val.getNode()->getNodeId() == Processed)
568  // We were passed a processed node, or it morphed into one - remap it.
569  RemapValue(Val);
570 }
571 
572 /// If the specified value was already legalized to another value,
573 /// replace it by that value.
574 void DAGTypeLegalizer::RemapValue(SDValue &V) {
575  auto Id = getTableId(V);
576  V = getSDValue(Id);
577 }
578 
579 void DAGTypeLegalizer::RemapId(TableId &Id) {
580  auto I = ReplacedValues.find(Id);
581  if (I != ReplacedValues.end()) {
582  assert(Id != I->second && "Id is mapped to itself.");
583  // Use path compression to speed up future lookups if values get multiply
584  // replaced with other values.
585  RemapId(I->second);
586  Id = I->second;
587 
588  // Note that N = IdToValueMap[Id] it is possible to have
589  // N.getNode()->getNodeId() == NewNode at this point because it is possible
590  // for a node to be put in the map before being processed.
591  }
592 }
593 
594 namespace {
595  /// This class is a DAGUpdateListener that listens for updates to nodes and
596  /// recomputes their ready state.
597  class NodeUpdateListener : public SelectionDAG::DAGUpdateListener {
598  DAGTypeLegalizer &DTL;
599  SmallSetVector<SDNode*, 16> &NodesToAnalyze;
600  public:
601  explicit NodeUpdateListener(DAGTypeLegalizer &dtl,
603  : SelectionDAG::DAGUpdateListener(dtl.getDAG()),
604  DTL(dtl), NodesToAnalyze(nta) {}
605 
606  void NodeDeleted(SDNode *N, SDNode *E) override {
607  assert(N->getNodeId() != DAGTypeLegalizer::ReadyToProcess &&
608  N->getNodeId() != DAGTypeLegalizer::Processed &&
609  "Invalid node ID for RAUW deletion!");
610  // It is possible, though rare, for the deleted node N to occur as a
611  // target in a map, so note the replacement N -> E in ReplacedValues.
612  assert(E && "Node not replaced?");
613  DTL.NoteDeletion(N, E);
614 
615  // In theory the deleted node could also have been scheduled for analysis.
616  // So remove it from the set of nodes which will be analyzed.
617  NodesToAnalyze.remove(N);
618 
619  // In general nothing needs to be done for E, since it didn't change but
620  // only gained new uses. However N -> E was just added to ReplacedValues,
621  // and the result of a ReplacedValues mapping is not allowed to be marked
622  // NewNode. So if E is marked NewNode, then it needs to be analyzed.
623  if (E->getNodeId() == DAGTypeLegalizer::NewNode)
624  NodesToAnalyze.insert(E);
625  }
626 
627  void NodeUpdated(SDNode *N) override {
628  // Node updates can mean pretty much anything. It is possible that an
629  // operand was set to something already processed (f.e.) in which case
630  // this node could become ready. Recompute its flags.
631  assert(N->getNodeId() != DAGTypeLegalizer::ReadyToProcess &&
632  N->getNodeId() != DAGTypeLegalizer::Processed &&
633  "Invalid node ID for RAUW deletion!");
634  N->setNodeId(DAGTypeLegalizer::NewNode);
635  NodesToAnalyze.insert(N);
636  }
637  };
638 }
639 
640 
641 /// The specified value was legalized to the specified other value.
642 /// Update the DAG and NodeIds replacing any uses of From to use To instead.
643 void DAGTypeLegalizer::ReplaceValueWith(SDValue From, SDValue To) {
644  assert(From.getNode() != To.getNode() && "Potential legalization loop!");
645 
646  // If expansion produced new nodes, make sure they are properly marked.
647  AnalyzeNewValue(To);
648 
649  // Anything that used the old node should now use the new one. Note that this
650  // can potentially cause recursive merging.
651  SmallSetVector<SDNode*, 16> NodesToAnalyze;
652  NodeUpdateListener NUL(*this, NodesToAnalyze);
653  do {
654 
655  // The old node may be present in a map like ExpandedIntegers or
656  // PromotedIntegers. Inform maps about the replacement.
657  auto FromId = getTableId(From);
658  auto ToId = getTableId(To);
659 
660  if (FromId != ToId)
661  ReplacedValues[FromId] = ToId;
663 
664  // Process the list of nodes that need to be reanalyzed.
665  while (!NodesToAnalyze.empty()) {
666  SDNode *N = NodesToAnalyze.back();
667  NodesToAnalyze.pop_back();
668  if (N->getNodeId() != DAGTypeLegalizer::NewNode)
669  // The node was analyzed while reanalyzing an earlier node - it is safe
670  // to skip. Note that this is not a morphing node - otherwise it would
671  // still be marked NewNode.
672  continue;
673 
674  // Analyze the node's operands and recalculate the node ID.
675  SDNode *M = AnalyzeNewNode(N);
676  if (M != N) {
677  // The node morphed into a different node. Make everyone use the new
678  // node instead.
679  assert(M->getNodeId() != NewNode && "Analysis resulted in NewNode!");
680  assert(N->getNumValues() == M->getNumValues() &&
681  "Node morphing changed the number of results!");
682  for (unsigned i = 0, e = N->getNumValues(); i != e; ++i) {
683  SDValue OldVal(N, i);
684  SDValue NewVal(M, i);
685  if (M->getNodeId() == Processed)
686  RemapValue(NewVal);
687  // OldVal may be a target of the ReplacedValues map which was marked
688  // NewNode to force reanalysis because it was updated. Ensure that
689  // anything that ReplacedValues mapped to OldVal will now be mapped
690  // all the way to NewVal.
691  auto OldValId = getTableId(OldVal);
692  auto NewValId = getTableId(NewVal);
693  DAG.ReplaceAllUsesOfValueWith(OldVal, NewVal);
694  if (OldValId != NewValId)
695  ReplacedValues[OldValId] = NewValId;
696  }
697  // The original node continues to exist in the DAG, marked NewNode.
698  }
699  }
700  // When recursively update nodes with new nodes, it is possible to have
701  // new uses of From due to CSE. If this happens, replace the new uses of
702  // From with To.
703  } while (!From.use_empty());
704 }
705 
706 void DAGTypeLegalizer::SetPromotedInteger(SDValue Op, SDValue Result) {
707  assert(Result.getValueType() ==
708  TLI.getTypeToTransformTo(*DAG.getContext(), Op.getValueType()) &&
709  "Invalid type for promoted integer");
710  AnalyzeNewValue(Result);
711 
712  auto &OpIdEntry = PromotedIntegers[getTableId(Op)];
713  assert((OpIdEntry == 0) && "Node is already promoted!");
714  OpIdEntry = getTableId(Result);
715  Result->setFlags(Op->getFlags());
716 
717  DAG.transferDbgValues(Op, Result);
718 }
719 
720 void DAGTypeLegalizer::SetSoftenedFloat(SDValue Op, SDValue Result) {
721  assert(Result.getValueType() ==
722  TLI.getTypeToTransformTo(*DAG.getContext(), Op.getValueType()) &&
723  "Invalid type for softened float");
724  AnalyzeNewValue(Result);
725 
726  auto &OpIdEntry = SoftenedFloats[getTableId(Op)];
727  assert((OpIdEntry == 0) && "Node is already converted to integer!");
728  OpIdEntry = getTableId(Result);
729 }
730 
731 void DAGTypeLegalizer::SetPromotedFloat(SDValue Op, SDValue Result) {
732  assert(Result.getValueType() ==
733  TLI.getTypeToTransformTo(*DAG.getContext(), Op.getValueType()) &&
734  "Invalid type for promoted float");
735  AnalyzeNewValue(Result);
736 
737  auto &OpIdEntry = PromotedFloats[getTableId(Op)];
738  assert((OpIdEntry == 0) && "Node is already promoted!");
739  OpIdEntry = getTableId(Result);
740 }
741 
742 void DAGTypeLegalizer::SetSoftPromotedHalf(SDValue Op, SDValue Result) {
743  assert(Result.getValueType() == MVT::i16 &&
744  "Invalid type for soft-promoted half");
745  AnalyzeNewValue(Result);
746 
747  auto &OpIdEntry = SoftPromotedHalfs[getTableId(Op)];
748  assert((OpIdEntry == 0) && "Node is already promoted!");
749  OpIdEntry = getTableId(Result);
750 }
751 
752 void DAGTypeLegalizer::SetScalarizedVector(SDValue Op, SDValue Result) {
753  // Note that in some cases vector operation operands may be greater than
754  // the vector element type. For example BUILD_VECTOR of type <1 x i1> with
755  // a constant i8 operand.
756 
757  // We don't currently support the scalarization of scalable vector types.
758  assert(Result.getValueSizeInBits().getFixedSize() >=
759  Op.getScalarValueSizeInBits() &&
760  "Invalid type for scalarized vector");
761  AnalyzeNewValue(Result);
762 
763  auto &OpIdEntry = ScalarizedVectors[getTableId(Op)];
764  assert((OpIdEntry == 0) && "Node is already scalarized!");
765  OpIdEntry = getTableId(Result);
766 }
767 
768 void DAGTypeLegalizer::GetExpandedInteger(SDValue Op, SDValue &Lo,
769  SDValue &Hi) {
770  std::pair<TableId, TableId> &Entry = ExpandedIntegers[getTableId(Op)];
771  assert((Entry.first != 0) && "Operand isn't expanded");
772  Lo = getSDValue(Entry.first);
773  Hi = getSDValue(Entry.second);
774 }
775 
776 void DAGTypeLegalizer::SetExpandedInteger(SDValue Op, SDValue Lo,
777  SDValue Hi) {
778  assert(Lo.getValueType() ==
779  TLI.getTypeToTransformTo(*DAG.getContext(), Op.getValueType()) &&
780  Hi.getValueType() == Lo.getValueType() &&
781  "Invalid type for expanded integer");
782  // Lo/Hi may have been newly allocated, if so, add nodeid's as relevant.
783  AnalyzeNewValue(Lo);
784  AnalyzeNewValue(Hi);
785 
786  // Transfer debug values. Don't invalidate the source debug value until it's
787  // been transferred to the high and low bits.
788  if (DAG.getDataLayout().isBigEndian()) {
789  DAG.transferDbgValues(Op, Hi, 0, Hi.getValueSizeInBits(), false);
790  DAG.transferDbgValues(Op, Lo, Hi.getValueSizeInBits(),
791  Lo.getValueSizeInBits());
792  } else {
793  DAG.transferDbgValues(Op, Lo, 0, Lo.getValueSizeInBits(), false);
794  DAG.transferDbgValues(Op, Hi, Lo.getValueSizeInBits(),
795  Hi.getValueSizeInBits());
796  }
797 
798  // Remember that this is the result of the node.
799  std::pair<TableId, TableId> &Entry = ExpandedIntegers[getTableId(Op)];
800  assert((Entry.first == 0) && "Node already expanded");
801  Entry.first = getTableId(Lo);
802  Entry.second = getTableId(Hi);
803 }
804 
805 void DAGTypeLegalizer::GetExpandedFloat(SDValue Op, SDValue &Lo,
806  SDValue &Hi) {
807  std::pair<TableId, TableId> &Entry = ExpandedFloats[getTableId(Op)];
808  assert((Entry.first != 0) && "Operand isn't expanded");
809  Lo = getSDValue(Entry.first);
810  Hi = getSDValue(Entry.second);
811 }
812 
813 void DAGTypeLegalizer::SetExpandedFloat(SDValue Op, SDValue Lo,
814  SDValue Hi) {
815  assert(Lo.getValueType() ==
816  TLI.getTypeToTransformTo(*DAG.getContext(), Op.getValueType()) &&
817  Hi.getValueType() == Lo.getValueType() &&
818  "Invalid type for expanded float");
819  // Lo/Hi may have been newly allocated, if so, add nodeid's as relevant.
820  AnalyzeNewValue(Lo);
821  AnalyzeNewValue(Hi);
822 
823  std::pair<TableId, TableId> &Entry = ExpandedFloats[getTableId(Op)];
824  assert((Entry.first == 0) && "Node already expanded");
825  Entry.first = getTableId(Lo);
826  Entry.second = getTableId(Hi);
827 }
828 
829 void DAGTypeLegalizer::GetSplitVector(SDValue Op, SDValue &Lo,
830  SDValue &Hi) {
831  std::pair<TableId, TableId> &Entry = SplitVectors[getTableId(Op)];
832  Lo = getSDValue(Entry.first);
833  Hi = getSDValue(Entry.second);
834  assert(Lo.getNode() && "Operand isn't split");
835  ;
836 }
837 
838 void DAGTypeLegalizer::SetSplitVector(SDValue Op, SDValue Lo,
839  SDValue Hi) {
840  assert(Lo.getValueType().getVectorElementType() ==
841  Op.getValueType().getVectorElementType() &&
842  Lo.getValueType().getVectorElementCount() * 2 ==
843  Op.getValueType().getVectorElementCount() &&
844  Hi.getValueType() == Lo.getValueType() &&
845  "Invalid type for split vector");
846  // Lo/Hi may have been newly allocated, if so, add nodeid's as relevant.
847  AnalyzeNewValue(Lo);
848  AnalyzeNewValue(Hi);
849 
850  // Remember that this is the result of the node.
851  std::pair<TableId, TableId> &Entry = SplitVectors[getTableId(Op)];
852  assert((Entry.first == 0) && "Node already split");
853  Entry.first = getTableId(Lo);
854  Entry.second = getTableId(Hi);
855 }
856 
857 void DAGTypeLegalizer::SetWidenedVector(SDValue Op, SDValue Result) {
858  assert(Result.getValueType() ==
859  TLI.getTypeToTransformTo(*DAG.getContext(), Op.getValueType()) &&
860  "Invalid type for widened vector");
861  AnalyzeNewValue(Result);
862 
863  auto &OpIdEntry = WidenedVectors[getTableId(Op)];
864  assert((OpIdEntry == 0) && "Node already widened!");
865  OpIdEntry = getTableId(Result);
866 }
867 
868 
869 //===----------------------------------------------------------------------===//
870 // Utilities.
871 //===----------------------------------------------------------------------===//
872 
873 /// Convert to an integer of the same size.
874 SDValue DAGTypeLegalizer::BitConvertToInteger(SDValue Op) {
875  unsigned BitWidth = Op.getValueSizeInBits();
876  return DAG.getNode(ISD::BITCAST, SDLoc(Op),
878 }
879 
880 /// Convert to a vector of integers of the same size.
881 SDValue DAGTypeLegalizer::BitConvertVectorToIntegerVector(SDValue Op) {
882  assert(Op.getValueType().isVector() && "Only applies to vectors!");
883  unsigned EltWidth = Op.getScalarValueSizeInBits();
884  EVT EltNVT = EVT::getIntegerVT(*DAG.getContext(), EltWidth);
885  auto EltCnt = Op.getValueType().getVectorElementCount();
886  return DAG.getNode(ISD::BITCAST, SDLoc(Op),
887  EVT::getVectorVT(*DAG.getContext(), EltNVT, EltCnt), Op);
888 }
889 
890 SDValue DAGTypeLegalizer::CreateStackStoreLoad(SDValue Op,
891  EVT DestVT) {
892  SDLoc dl(Op);
893  // Create the stack frame object. Make sure it is aligned for both
894  // the source and destination types.
895 
896  // In cases where the vector is illegal it will be broken down into parts
897  // and stored in parts - we should use the alignment for the smallest part.
898  Align DestAlign = DAG.getReducedAlign(DestVT, /*UseABI=*/false);
899  Align OpAlign = DAG.getReducedAlign(Op.getValueType(), /*UseABI=*/false);
900  Align Align = std::max(DestAlign, OpAlign);
901  SDValue StackPtr =
902  DAG.CreateStackTemporary(Op.getValueType().getStoreSize(), Align);
903  // Emit a store to the stack slot.
904  SDValue Store = DAG.getStore(DAG.getEntryNode(), dl, Op, StackPtr,
906  // Result is a load from the stack slot.
907  return DAG.getLoad(DestVT, dl, Store, StackPtr, MachinePointerInfo(), Align);
908 }
909 
910 /// Replace the node's results with custom code provided by the target and
911 /// return "true", or do nothing and return "false".
912 /// The last parameter is FALSE if we are dealing with a node with legal
913 /// result types and illegal operand. The second parameter denotes the type of
914 /// illegal OperandNo in that case.
915 /// The last parameter being TRUE means we are dealing with a
916 /// node with illegal result types. The second parameter denotes the type of
917 /// illegal ResNo in that case.
918 bool DAGTypeLegalizer::CustomLowerNode(SDNode *N, EVT VT, bool LegalizeResult) {
919  // See if the target wants to custom lower this node.
920  if (TLI.getOperationAction(N->getOpcode(), VT) != TargetLowering::Custom)
921  return false;
922 
924  if (LegalizeResult)
925  TLI.ReplaceNodeResults(N, Results, DAG);
926  else
927  TLI.LowerOperationWrapper(N, Results, DAG);
928 
929  if (Results.empty())
930  // The target didn't want to custom lower it after all.
931  return false;
932 
933  // Make everything that once used N's values now use those in Results instead.
934  assert(Results.size() == N->getNumValues() &&
935  "Custom lowering returned the wrong number of results!");
936  for (unsigned i = 0, e = Results.size(); i != e; ++i) {
937  ReplaceValueWith(SDValue(N, i), Results[i]);
938  }
939  return true;
940 }
941 
942 
943 /// Widen the node's results with custom code provided by the target and return
944 /// "true", or do nothing and return "false".
945 bool DAGTypeLegalizer::CustomWidenLowerNode(SDNode *N, EVT VT) {
946  // See if the target wants to custom lower this node.
947  if (TLI.getOperationAction(N->getOpcode(), VT) != TargetLowering::Custom)
948  return false;
949 
951  TLI.ReplaceNodeResults(N, Results, DAG);
952 
953  if (Results.empty())
954  // The target didn't want to custom widen lower its result after all.
955  return false;
956 
957  // Update the widening map.
958  assert(Results.size() == N->getNumValues() &&
959  "Custom lowering returned the wrong number of results!");
960  for (unsigned i = 0, e = Results.size(); i != e; ++i) {
961  // If this is a chain output or already widened just replace it.
962  bool WasWidened = SDValue(N, i).getValueType() != Results[i].getValueType();
963  if (WasWidened)
964  SetWidenedVector(SDValue(N, i), Results[i]);
965  else
966  ReplaceValueWith(SDValue(N, i), Results[i]);
967  }
968  return true;
969 }
970 
971 SDValue DAGTypeLegalizer::DisintegrateMERGE_VALUES(SDNode *N, unsigned ResNo) {
972  for (unsigned i = 0, e = N->getNumValues(); i != e; ++i)
973  if (i != ResNo)
974  ReplaceValueWith(SDValue(N, i), SDValue(N->getOperand(i)));
975  return SDValue(N->getOperand(ResNo));
976 }
977 
978 /// Use ISD::EXTRACT_ELEMENT nodes to extract the low and high parts of the
979 /// given value.
980 void DAGTypeLegalizer::GetPairElements(SDValue Pair,
981  SDValue &Lo, SDValue &Hi) {
982  SDLoc dl(Pair);
983  EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), Pair.getValueType());
984  Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, NVT, Pair,
985  DAG.getIntPtrConstant(0, dl));
986  Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, NVT, Pair,
987  DAG.getIntPtrConstant(1, dl));
988 }
989 
990 /// Build an integer with low bits Lo and high bits Hi.
991 SDValue DAGTypeLegalizer::JoinIntegers(SDValue Lo, SDValue Hi) {
992  // Arbitrarily use dlHi for result SDLoc
993  SDLoc dlHi(Hi);
994  SDLoc dlLo(Lo);
995  EVT LVT = Lo.getValueType();
996  EVT HVT = Hi.getValueType();
997  EVT NVT = EVT::getIntegerVT(*DAG.getContext(),
998  LVT.getSizeInBits() + HVT.getSizeInBits());
999 
1000  EVT ShiftAmtVT = TLI.getShiftAmountTy(NVT, DAG.getDataLayout(), false);
1001  Lo = DAG.getNode(ISD::ZERO_EXTEND, dlLo, NVT, Lo);
1002  Hi = DAG.getNode(ISD::ANY_EXTEND, dlHi, NVT, Hi);
1003  Hi = DAG.getNode(ISD::SHL, dlHi, NVT, Hi,
1004  DAG.getConstant(LVT.getSizeInBits(), dlHi, ShiftAmtVT));
1005  return DAG.getNode(ISD::OR, dlHi, NVT, Lo, Hi);
1006 }
1007 
1008 /// Promote the given target boolean to a target boolean of the given type.
1009 /// A target boolean is an integer value, not necessarily of type i1, the bits
1010 /// of which conform to getBooleanContents.
1011 ///
1012 /// ValVT is the type of values that produced the boolean.
1013 SDValue DAGTypeLegalizer::PromoteTargetBoolean(SDValue Bool, EVT ValVT) {
1014  SDLoc dl(Bool);
1015  EVT BoolVT = getSetCCResultType(ValVT);
1016  ISD::NodeType ExtendCode =
1018  return DAG.getNode(ExtendCode, dl, BoolVT, Bool);
1019 }
1020 
1021 /// Return the lower LoVT bits of Op in Lo and the upper HiVT bits in Hi.
1022 void DAGTypeLegalizer::SplitInteger(SDValue Op,
1023  EVT LoVT, EVT HiVT,
1024  SDValue &Lo, SDValue &Hi) {
1025  SDLoc dl(Op);
1026  assert(LoVT.getSizeInBits() + HiVT.getSizeInBits() ==
1027  Op.getValueSizeInBits() && "Invalid integer splitting!");
1028  Lo = DAG.getNode(ISD::TRUNCATE, dl, LoVT, Op);
1029  unsigned ReqShiftAmountInBits =
1030  Log2_32_Ceil(Op.getValueType().getSizeInBits());
1031  MVT ShiftAmountTy =
1032  TLI.getScalarShiftAmountTy(DAG.getDataLayout(), Op.getValueType());
1033  if (ReqShiftAmountInBits > ShiftAmountTy.getSizeInBits())
1034  ShiftAmountTy = MVT::getIntegerVT(NextPowerOf2(ReqShiftAmountInBits));
1035  Hi = DAG.getNode(ISD::SRL, dl, Op.getValueType(), Op,
1036  DAG.getConstant(LoVT.getSizeInBits(), dl, ShiftAmountTy));
1037  Hi = DAG.getNode(ISD::TRUNCATE, dl, HiVT, Hi);
1038 }
1039 
1040 /// Return the lower and upper halves of Op's bits in a value type half the
1041 /// size of Op's.
1042 void DAGTypeLegalizer::SplitInteger(SDValue Op,
1043  SDValue &Lo, SDValue &Hi) {
1044  EVT HalfVT =
1045  EVT::getIntegerVT(*DAG.getContext(), Op.getValueSizeInBits() / 2);
1046  SplitInteger(Op, HalfVT, HalfVT, Lo, Hi);
1047 }
1048 
1049 
1050 //===----------------------------------------------------------------------===//
1051 // Entry Point
1052 //===----------------------------------------------------------------------===//
1053 
1054 /// This transforms the SelectionDAG into a SelectionDAG that only uses types
1055 /// natively supported by the target. Returns "true" if it made any changes.
1056 ///
1057 /// Note that this is an involved process that may invalidate pointers into
1058 /// the graph.
1060  return DAGTypeLegalizer(*this).run();
1061 }
size_t size() const
Definition: Function.h:752
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
Definition: ISDOpcodes.h:790
static MVT getIntegerVT(unsigned BitWidth)
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
Definition: MathExtras.h:610
EVT getValueType() const
Return the ValueType of the referenced return value.
bool empty() const
Definition: Function.h:753
EXTRACT_ELEMENT - This is used to get the lower or upper (determined by a Constant,...
Definition: ISDOpcodes.h:215
bool LegalizeTypes()
This transforms the SelectionDAG into a SelectionDAG that only uses types natively supported by the t...
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:140
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Clients of various APIs that cause global effects on the DAG can optionally implement this interface.
Definition: SelectionDAG.h:295
uint32_t NodeId
Definition: RDFGraph.h:260
static ISD::NodeType getExtendForContent(BooleanContent Content)
Function Alias Analysis Results
This takes an arbitrary SelectionDAG as input and hacks on it until only value types the target machi...
Definition: LegalizeTypes.h:31
BooleanContent getBooleanContents(bool isVec, bool isFloat) const
For targets without i1 registers, this gives the nature of the high-bits of boolean values held in ty...
SDNode * getNode() const
get the SDNode which holds the desired result
SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
const SDValue & setRoot(SDValue N)
Set the current root tag of the SelectionDAG.
Definition: SelectionDAG.h:529
const T & back() const
Return the last element of the SetVector.
Definition: SetVector.h:128
NodeType
ISD::NodeType enum - This enum defines the target-independent operators for a SelectionDAG.
Definition: ISDOpcodes.h:40
void transferDbgValues(SDValue From, SDValue To, unsigned OffsetInBits=0, unsigned SizeInBits=0, bool InvalidateDbg=true)
Transfer debug values from one node to another, while optionally generating fragment expressions for ...
SDValue getIntPtrConstant(uint64_t Val, const SDLoc &DL, bool isTarget=false)
This node's ID needs to be set to the number of its unprocessed operands.
Definition: LegalizeTypes.h:47
Shift and rotation operations.
Definition: ISDOpcodes.h:606
Align getReducedAlign(EVT VT, bool UseABI)
In most cases this function returns the ABI alignment for a given type, except for illegal vector typ...
SDValue getEntryNode() const
Return the token chain corresponding to the entry of the function.
Definition: SelectionDAG.h:523
const DataLayout & getDataLayout() const
Definition: SelectionDAG.h:447
bool remove(const value_type &X)
Remove an item from the set vector.
Definition: SetVector.h:157
void pop_back()
Remove the last element of the SetVector.
Definition: SetVector.h:226
iterator_range< allnodes_iterator > allnodes()
Definition: SelectionDAG.h:512
virtual void ReplaceNodeResults(SDNode *, SmallVectorImpl< SDValue > &, SelectionDAG &) const
This callback is invoked when a node result type is illegal for the target, and the operation was reg...
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition: SetVector.h:141
static cl::opt< bool > EnableExpensiveChecks("enable-legalize-types-checking", cl::Hidden)
bool run()
This is the main entry point for the type legalizer.
Machine Value Type.
This is a new node, not before seen, that was created in the process of legalizing some other node.
Definition: LegalizeTypes.h:43
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
void RemoveDeadNodes()
This method deletes all unreachable nodes in the SelectionDAG.
This class provides iterator support for SDUse operands that use a specific SDNode.
constexpr double e
Definition: MathExtras.h:58
std::string getEVTString() const
This function returns value type as a string, e.g. "i32".
Definition: ValueTypes.cpp:149
constexpr unsigned BitWidth
Definition: BitmaskEnum.h:147
uint64_t Align
Extended Value Type.
Definition: ValueTypes.h:35
uint64_t NextPowerOf2(uint64_t A)
Returns the next power of two (in 64-bits) that is strictly greater than A.
Definition: MathExtras.h:684
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition: ValueTypes.h:333
This class contains a discriminated union of information about pointers in memory operands,...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
void NoteDeletion(SDNode *Old, SDNode *New)
virtual void LowerOperationWrapper(SDNode *N, SmallVectorImpl< SDValue > &Results, SelectionDAG &DAG) const
This callback is invoked by the type legalizer to legalize nodes with an illegal operand type but leg...
SDValue CreateStackTemporary(TypeSize Bytes, Align Alignment)
Create a stack temporary based on the size in bytes and the alignment.
A SetVector that performs no allocations if smaller than a certain size.
Definition: SetVector.h:307
unsigned getNumOperands() const
Definition: User.h:191
BlockVerifier::State From
void setNode(SDNode *N)
set the SDNode
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:350
testing::Matcher< const detail::ErrorHolder & > Failed()
Definition: Error.h:177
SDNode * UpdateNodeOperands(SDNode *N, SDValue Op)
Mutate the specified node in-place to have the specified operands.
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Definition: SelectionDAG.h:223
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1116
virtual MVT getScalarShiftAmountTy(const DataLayout &, EVT) const
EVT is not used in-tree, but is used by out-of-tree target.
LegalizeAction getOperationAction(unsigned Op, EVT VT) const
Return how this operation should be treated: either it is legal, needs to be promoted to a larger siz...
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
This is a node that has already been processed.
Definition: LegalizeTypes.h:50
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements, bool IsScalable=false)
Returns the EVT that represents a vector NumElements in length, where each element is of type VT.
Definition: ValueTypes.h:74
ZERO_EXTEND - Used for integer types, zeroing the new bits.
Definition: ISDOpcodes.h:678
ANY_EXTEND - Used for integer types. The high bits are undefined.
Definition: ISDOpcodes.h:681
int getNodeId() const
Return the unique node id.
SDValue getStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, Align Alignment, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
Helper function to build ISD::STORE nodes.
#define I(x, y, z)
Definition: MD5.cpp:59
#define N
bool empty() const
Determine if the SetVector is empty or not.
Definition: SetVector.h:72
Type * getValueType() const
Definition: GlobalValue.h:273
const SDValue & getRoot() const
Return the root tag of the SelectionDAG.
Definition: SelectionDAG.h:520
SDValue getConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
Create a ConstantSDNode wrapping a constant value.
This class is used to form a handle around another node that is persistent and is updated across invo...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
All operands have been processed, so this node is ready to be handled.
Definition: LegalizeTypes.h:39
void ReplaceAllUsesOfValueWith(SDValue From, SDValue To)
Replace any uses of From with To, leaving uses of other values produced by From.getNode() alone.
bool isBigEndian() const
Definition: DataLayout.h:241
TRUNCATE - Completely drop the high bits.
Definition: ISDOpcodes.h:684
#define LLVM_DEBUG(X)
Definition: Debug.h:122
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
SDValue getLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, MaybeAlign Alignment=MaybeAlign(), MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr)
Loads are not normal binary operators: their result type is not determined by their operands,...
static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth)
Returns the EVT that represents an integer with the given number of bits.
Definition: ValueTypes.h:65
EVT getTypeToTransformTo(LLVMContext &Context, EVT VT) const
For types supported by the target, this is an identity function.
LLVMContext * getContext() const
Definition: SelectionDAG.h:454
EVT getShiftAmountTy(EVT LHSTy, const DataLayout &DL, bool LegalTypes=true) const