[Modules] Sink the DEBUG_TYPE macro out of LegalizeTypes.h and into the
[oota-llvm.git] / lib / CodeGen / SelectionDAG / LegalizeTypes.cpp
1 //===-- LegalizeTypes.cpp - Common code for DAG type legalizer ------------===//
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 // This file implements the SelectionDAG::LegalizeTypes method.  It transforms
11 // an arbitrary well-formed SelectionDAG to only consist of legal types.  This
12 // is common code shared among the LegalizeTypes*.cpp files.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #define DEBUG_TYPE "legalize-types"
17 #include "LegalizeTypes.h"
18 #include "llvm/ADT/SetVector.h"
19 #include "llvm/IR/CallingConv.h"
20 #include "llvm/IR/DataLayout.h"
21 #include "llvm/Support/CommandLine.h"
22 #include "llvm/Support/ErrorHandling.h"
23 #include "llvm/Support/raw_ostream.h"
24 using namespace llvm;
25
26 static cl::opt<bool>
27 EnableExpensiveChecks("enable-legalize-types-checking", cl::Hidden);
28
29 /// PerformExpensiveChecks - Do extensive, expensive, sanity checking.
30 void DAGTypeLegalizer::PerformExpensiveChecks() {
31   // If a node is not processed, then none of its values should be mapped by any
32   // of PromotedIntegers, ExpandedIntegers, ..., ReplacedValues.
33
34   // If a node is processed, then each value with an illegal type must be mapped
35   // by exactly one of PromotedIntegers, ExpandedIntegers, ..., ReplacedValues.
36   // Values with a legal type may be mapped by ReplacedValues, but not by any of
37   // the other maps.
38
39   // Note that these invariants may not hold momentarily when processing a node:
40   // the node being processed may be put in a map before being marked Processed.
41
42   // Note that it is possible to have nodes marked NewNode in the DAG.  This can
43   // occur in two ways.  Firstly, a node may be created during legalization but
44   // never passed to the legalization core.  This is usually due to the implicit
45   // folding that occurs when using the DAG.getNode operators.  Secondly, a new
46   // node may be passed to the legalization core, but when analyzed may morph
47   // into a different node, leaving the original node as a NewNode in the DAG.
48   // A node may morph if one of its operands changes during analysis.  Whether
49   // it actually morphs or not depends on whether, after updating its operands,
50   // it is equivalent to an existing node: if so, it morphs into that existing
51   // node (CSE).  An operand can change during analysis if the operand is a new
52   // node that morphs, or it is a processed value that was mapped to some other
53   // value (as recorded in ReplacedValues) in which case the operand is turned
54   // into that other value.  If a node morphs then the node it morphed into will
55   // be used instead of it for legalization, however the original node continues
56   // to live on in the DAG.
57   // The conclusion is that though there may be nodes marked NewNode in the DAG,
58   // all uses of such nodes are also marked NewNode: the result is a fungus of
59   // NewNodes growing on top of the useful nodes, and perhaps using them, but
60   // not used by them.
61
62   // If a value is mapped by ReplacedValues, then it must have no uses, except
63   // by nodes marked NewNode (see above).
64
65   // The final node obtained by mapping by ReplacedValues is not marked NewNode.
66   // Note that ReplacedValues should be applied iteratively.
67
68   // Note that the ReplacedValues map may also map deleted nodes (by iterating
69   // over the DAG we never dereference deleted nodes).  This means that it may
70   // also map nodes marked NewNode if the deallocated memory was reallocated as
71   // another node, and that new node was not seen by the LegalizeTypes machinery
72   // (for example because it was created but not used).  In general, we cannot
73   // distinguish between new nodes and deleted nodes.
74   SmallVector<SDNode*, 16> NewNodes;
75   for (SelectionDAG::allnodes_iterator I = DAG.allnodes_begin(),
76        E = DAG.allnodes_end(); I != E; ++I) {
77     // Remember nodes marked NewNode - they are subject to extra checking below.
78     if (I->getNodeId() == NewNode)
79       NewNodes.push_back(I);
80
81     for (unsigned i = 0, e = I->getNumValues(); i != e; ++i) {
82       SDValue Res(I, i);
83       bool Failed = false;
84
85       unsigned Mapped = 0;
86       if (ReplacedValues.find(Res) != ReplacedValues.end()) {
87         Mapped |= 1;
88         // Check that remapped values are only used by nodes marked NewNode.
89         for (SDNode::use_iterator UI = I->use_begin(), UE = I->use_end();
90              UI != UE; ++UI)
91           if (UI.getUse().getResNo() == i)
92             assert(UI->getNodeId() == NewNode &&
93                    "Remapped value has non-trivial use!");
94
95         // Check that the final result of applying ReplacedValues is not
96         // marked NewNode.
97         SDValue NewVal = ReplacedValues[Res];
98         DenseMap<SDValue, SDValue>::iterator I = ReplacedValues.find(NewVal);
99         while (I != ReplacedValues.end()) {
100           NewVal = I->second;
101           I = ReplacedValues.find(NewVal);
102         }
103         assert(NewVal.getNode()->getNodeId() != NewNode &&
104                "ReplacedValues maps to a new node!");
105       }
106       if (PromotedIntegers.find(Res) != PromotedIntegers.end())
107         Mapped |= 2;
108       if (SoftenedFloats.find(Res) != SoftenedFloats.end())
109         Mapped |= 4;
110       if (ScalarizedVectors.find(Res) != ScalarizedVectors.end())
111         Mapped |= 8;
112       if (ExpandedIntegers.find(Res) != ExpandedIntegers.end())
113         Mapped |= 16;
114       if (ExpandedFloats.find(Res) != ExpandedFloats.end())
115         Mapped |= 32;
116       if (SplitVectors.find(Res) != SplitVectors.end())
117         Mapped |= 64;
118       if (WidenedVectors.find(Res) != WidenedVectors.end())
119         Mapped |= 128;
120
121       if (I->getNodeId() != Processed) {
122         // Since we allow ReplacedValues to map deleted nodes, it may map nodes
123         // marked NewNode too, since a deleted node may have been reallocated as
124         // another node that has not been seen by the LegalizeTypes machinery.
125         if ((I->getNodeId() == NewNode && Mapped > 1) ||
126             (I->getNodeId() != NewNode && Mapped != 0)) {
127           dbgs() << "Unprocessed value in a map!";
128           Failed = true;
129         }
130       } else if (isTypeLegal(Res.getValueType()) || IgnoreNodeResults(I)) {
131         if (Mapped > 1) {
132           dbgs() << "Value with legal type was transformed!";
133           Failed = true;
134         }
135       } else {
136         if (Mapped == 0) {
137           dbgs() << "Processed value not in any map!";
138           Failed = true;
139         } else if (Mapped & (Mapped - 1)) {
140           dbgs() << "Value in multiple maps!";
141           Failed = true;
142         }
143       }
144
145       if (Failed) {
146         if (Mapped & 1)
147           dbgs() << " ReplacedValues";
148         if (Mapped & 2)
149           dbgs() << " PromotedIntegers";
150         if (Mapped & 4)
151           dbgs() << " SoftenedFloats";
152         if (Mapped & 8)
153           dbgs() << " ScalarizedVectors";
154         if (Mapped & 16)
155           dbgs() << " ExpandedIntegers";
156         if (Mapped & 32)
157           dbgs() << " ExpandedFloats";
158         if (Mapped & 64)
159           dbgs() << " SplitVectors";
160         if (Mapped & 128)
161           dbgs() << " WidenedVectors";
162         dbgs() << "\n";
163         llvm_unreachable(nullptr);
164       }
165     }
166   }
167
168   // Checked that NewNodes are only used by other NewNodes.
169   for (unsigned i = 0, e = NewNodes.size(); i != e; ++i) {
170     SDNode *N = NewNodes[i];
171     for (SDNode::use_iterator UI = N->use_begin(), UE = N->use_end();
172          UI != UE; ++UI)
173       assert(UI->getNodeId() == NewNode && "NewNode used by non-NewNode!");
174   }
175 }
176
177 /// run - This is the main entry point for the type legalizer.  This does a
178 /// top-down traversal of the dag, legalizing types as it goes.  Returns "true"
179 /// if it made any changes.
180 bool DAGTypeLegalizer::run() {
181   bool Changed = false;
182
183   // Create a dummy node (which is not added to allnodes), that adds a reference
184   // to the root node, preventing it from being deleted, and tracking any
185   // changes of the root.
186   HandleSDNode Dummy(DAG.getRoot());
187   Dummy.setNodeId(Unanalyzed);
188
189   // The root of the dag may dangle to deleted nodes until the type legalizer is
190   // done.  Set it to null to avoid confusion.
191   DAG.setRoot(SDValue());
192
193   // Walk all nodes in the graph, assigning them a NodeId of 'ReadyToProcess'
194   // (and remembering them) if they are leaves and assigning 'Unanalyzed' if
195   // non-leaves.
196   for (SelectionDAG::allnodes_iterator I = DAG.allnodes_begin(),
197        E = DAG.allnodes_end(); I != E; ++I) {
198     if (I->getNumOperands() == 0) {
199       I->setNodeId(ReadyToProcess);
200       Worklist.push_back(I);
201     } else {
202       I->setNodeId(Unanalyzed);
203     }
204   }
205
206   // Now that we have a set of nodes to process, handle them all.
207   while (!Worklist.empty()) {
208 #ifndef XDEBUG
209     if (EnableExpensiveChecks)
210 #endif
211       PerformExpensiveChecks();
212
213     SDNode *N = Worklist.back();
214     Worklist.pop_back();
215     assert(N->getNodeId() == ReadyToProcess &&
216            "Node should be ready if on worklist!");
217
218     if (IgnoreNodeResults(N))
219       goto ScanOperands;
220
221     // Scan the values produced by the node, checking to see if any result
222     // types are illegal.
223     for (unsigned i = 0, NumResults = N->getNumValues(); i < NumResults; ++i) {
224       EVT ResultVT = N->getValueType(i);
225       switch (getTypeAction(ResultVT)) {
226       case TargetLowering::TypeLegal:
227         break;
228       // The following calls must take care of *all* of the node's results,
229       // not just the illegal result they were passed (this includes results
230       // with a legal type).  Results can be remapped using ReplaceValueWith,
231       // or their promoted/expanded/etc values registered in PromotedIntegers,
232       // ExpandedIntegers etc.
233       case TargetLowering::TypePromoteInteger:
234         PromoteIntegerResult(N, i);
235         Changed = true;
236         goto NodeDone;
237       case TargetLowering::TypeExpandInteger:
238         ExpandIntegerResult(N, i);
239         Changed = true;
240         goto NodeDone;
241       case TargetLowering::TypeSoftenFloat:
242         SoftenFloatResult(N, i);
243         Changed = true;
244         goto NodeDone;
245       case TargetLowering::TypeExpandFloat:
246         ExpandFloatResult(N, i);
247         Changed = true;
248         goto NodeDone;
249       case TargetLowering::TypeScalarizeVector:
250         ScalarizeVectorResult(N, i);
251         Changed = true;
252         goto NodeDone;
253       case TargetLowering::TypeSplitVector:
254         SplitVectorResult(N, i);
255         Changed = true;
256         goto NodeDone;
257       case TargetLowering::TypeWidenVector:
258         WidenVectorResult(N, i);
259         Changed = true;
260         goto NodeDone;
261       }
262     }
263
264 ScanOperands:
265     // Scan the operand list for the node, handling any nodes with operands that
266     // are illegal.
267     {
268     unsigned NumOperands = N->getNumOperands();
269     bool NeedsReanalyzing = false;
270     unsigned i;
271     for (i = 0; i != NumOperands; ++i) {
272       if (IgnoreNodeResults(N->getOperand(i).getNode()))
273         continue;
274
275       EVT OpVT = N->getOperand(i).getValueType();
276       switch (getTypeAction(OpVT)) {
277       case TargetLowering::TypeLegal:
278         continue;
279       // The following calls must either replace all of the node's results
280       // using ReplaceValueWith, and return "false"; or update the node's
281       // operands in place, and return "true".
282       case TargetLowering::TypePromoteInteger:
283         NeedsReanalyzing = PromoteIntegerOperand(N, i);
284         Changed = true;
285         break;
286       case TargetLowering::TypeExpandInteger:
287         NeedsReanalyzing = ExpandIntegerOperand(N, i);
288         Changed = true;
289         break;
290       case TargetLowering::TypeSoftenFloat:
291         NeedsReanalyzing = SoftenFloatOperand(N, i);
292         Changed = true;
293         break;
294       case TargetLowering::TypeExpandFloat:
295         NeedsReanalyzing = ExpandFloatOperand(N, i);
296         Changed = true;
297         break;
298       case TargetLowering::TypeScalarizeVector:
299         NeedsReanalyzing = ScalarizeVectorOperand(N, i);
300         Changed = true;
301         break;
302       case TargetLowering::TypeSplitVector:
303         NeedsReanalyzing = SplitVectorOperand(N, i);
304         Changed = true;
305         break;
306       case TargetLowering::TypeWidenVector:
307         NeedsReanalyzing = WidenVectorOperand(N, i);
308         Changed = true;
309         break;
310       }
311       break;
312     }
313
314     // The sub-method updated N in place.  Check to see if any operands are new,
315     // and if so, mark them.  If the node needs revisiting, don't add all users
316     // to the worklist etc.
317     if (NeedsReanalyzing) {
318       assert(N->getNodeId() == ReadyToProcess && "Node ID recalculated?");
319       N->setNodeId(NewNode);
320       // Recompute the NodeId and correct processed operands, adding the node to
321       // the worklist if ready.
322       SDNode *M = AnalyzeNewNode(N);
323       if (M == N)
324         // The node didn't morph - nothing special to do, it will be revisited.
325         continue;
326
327       // The node morphed - this is equivalent to legalizing by replacing every
328       // value of N with the corresponding value of M.  So do that now.
329       assert(N->getNumValues() == M->getNumValues() &&
330              "Node morphing changed the number of results!");
331       for (unsigned i = 0, e = N->getNumValues(); i != e; ++i)
332         // Replacing the value takes care of remapping the new value.
333         ReplaceValueWith(SDValue(N, i), SDValue(M, i));
334       assert(N->getNodeId() == NewNode && "Unexpected node state!");
335       // The node continues to live on as part of the NewNode fungus that
336       // grows on top of the useful nodes.  Nothing more needs to be done
337       // with it - move on to the next node.
338       continue;
339     }
340
341     if (i == NumOperands) {
342       DEBUG(dbgs() << "Legally typed node: "; N->dump(&DAG); dbgs() << "\n");
343     }
344     }
345 NodeDone:
346
347     // If we reach here, the node was processed, potentially creating new nodes.
348     // Mark it as processed and add its users to the worklist as appropriate.
349     assert(N->getNodeId() == ReadyToProcess && "Node ID recalculated?");
350     N->setNodeId(Processed);
351
352     for (SDNode::use_iterator UI = N->use_begin(), E = N->use_end();
353          UI != E; ++UI) {
354       SDNode *User = *UI;
355       int NodeId = User->getNodeId();
356
357       // This node has two options: it can either be a new node or its Node ID
358       // may be a count of the number of operands it has that are not ready.
359       if (NodeId > 0) {
360         User->setNodeId(NodeId-1);
361
362         // If this was the last use it was waiting on, add it to the ready list.
363         if (NodeId-1 == ReadyToProcess)
364           Worklist.push_back(User);
365         continue;
366       }
367
368       // If this is an unreachable new node, then ignore it.  If it ever becomes
369       // reachable by being used by a newly created node then it will be handled
370       // by AnalyzeNewNode.
371       if (NodeId == NewNode)
372         continue;
373
374       // Otherwise, this node is new: this is the first operand of it that
375       // became ready.  Its new NodeId is the number of operands it has minus 1
376       // (as this node is now processed).
377       assert(NodeId == Unanalyzed && "Unknown node ID!");
378       User->setNodeId(User->getNumOperands() - 1);
379
380       // If the node only has a single operand, it is now ready.
381       if (User->getNumOperands() == 1)
382         Worklist.push_back(User);
383     }
384   }
385
386 #ifndef XDEBUG
387   if (EnableExpensiveChecks)
388 #endif
389     PerformExpensiveChecks();
390
391   // If the root changed (e.g. it was a dead load) update the root.
392   DAG.setRoot(Dummy.getValue());
393
394   // Remove dead nodes.  This is important to do for cleanliness but also before
395   // the checking loop below.  Implicit folding by the DAG.getNode operators and
396   // node morphing can cause unreachable nodes to be around with their flags set
397   // to new.
398   DAG.RemoveDeadNodes();
399
400   // In a debug build, scan all the nodes to make sure we found them all.  This
401   // ensures that there are no cycles and that everything got processed.
402 #ifndef NDEBUG
403   for (SelectionDAG::allnodes_iterator I = DAG.allnodes_begin(),
404        E = DAG.allnodes_end(); I != E; ++I) {
405     bool Failed = false;
406
407     // Check that all result types are legal.
408     if (!IgnoreNodeResults(I))
409       for (unsigned i = 0, NumVals = I->getNumValues(); i < NumVals; ++i)
410         if (!isTypeLegal(I->getValueType(i))) {
411           dbgs() << "Result type " << i << " illegal!\n";
412           Failed = true;
413         }
414
415     // Check that all operand types are legal.
416     for (unsigned i = 0, NumOps = I->getNumOperands(); i < NumOps; ++i)
417       if (!IgnoreNodeResults(I->getOperand(i).getNode()) &&
418           !isTypeLegal(I->getOperand(i).getValueType())) {
419         dbgs() << "Operand type " << i << " illegal!\n";
420         Failed = true;
421       }
422
423     if (I->getNodeId() != Processed) {
424        if (I->getNodeId() == NewNode)
425          dbgs() << "New node not analyzed?\n";
426        else if (I->getNodeId() == Unanalyzed)
427          dbgs() << "Unanalyzed node not noticed?\n";
428        else if (I->getNodeId() > 0)
429          dbgs() << "Operand not processed?\n";
430        else if (I->getNodeId() == ReadyToProcess)
431          dbgs() << "Not added to worklist?\n";
432        Failed = true;
433     }
434
435     if (Failed) {
436       I->dump(&DAG); dbgs() << "\n";
437       llvm_unreachable(nullptr);
438     }
439   }
440 #endif
441
442   return Changed;
443 }
444
445 /// AnalyzeNewNode - The specified node is the root of a subtree of potentially
446 /// new nodes.  Correct any processed operands (this may change the node) and
447 /// calculate the NodeId.  If the node itself changes to a processed node, it
448 /// is not remapped - the caller needs to take care of this.
449 /// Returns the potentially changed node.
450 SDNode *DAGTypeLegalizer::AnalyzeNewNode(SDNode *N) {
451   // If this was an existing node that is already done, we're done.
452   if (N->getNodeId() != NewNode && N->getNodeId() != Unanalyzed)
453     return N;
454
455   // Remove any stale map entries.
456   ExpungeNode(N);
457
458   // Okay, we know that this node is new.  Recursively walk all of its operands
459   // to see if they are new also.  The depth of this walk is bounded by the size
460   // of the new tree that was constructed (usually 2-3 nodes), so we don't worry
461   // about revisiting of nodes.
462   //
463   // As we walk the operands, keep track of the number of nodes that are
464   // processed.  If non-zero, this will become the new nodeid of this node.
465   // Operands may morph when they are analyzed.  If so, the node will be
466   // updated after all operands have been analyzed.  Since this is rare,
467   // the code tries to minimize overhead in the non-morphing case.
468
469   SmallVector<SDValue, 8> NewOps;
470   unsigned NumProcessed = 0;
471   for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
472     SDValue OrigOp = N->getOperand(i);
473     SDValue Op = OrigOp;
474
475     AnalyzeNewValue(Op); // Op may morph.
476
477     if (Op.getNode()->getNodeId() == Processed)
478       ++NumProcessed;
479
480     if (!NewOps.empty()) {
481       // Some previous operand changed.  Add this one to the list.
482       NewOps.push_back(Op);
483     } else if (Op != OrigOp) {
484       // This is the first operand to change - add all operands so far.
485       NewOps.append(N->op_begin(), N->op_begin() + i);
486       NewOps.push_back(Op);
487     }
488   }
489
490   // Some operands changed - update the node.
491   if (!NewOps.empty()) {
492     SDNode *M = DAG.UpdateNodeOperands(N, &NewOps[0], NewOps.size());
493     if (M != N) {
494       // The node morphed into a different node.  Normally for this to happen
495       // the original node would have to be marked NewNode.  However this can
496       // in theory momentarily not be the case while ReplaceValueWith is doing
497       // its stuff.  Mark the original node NewNode to help sanity checking.
498       N->setNodeId(NewNode);
499       if (M->getNodeId() != NewNode && M->getNodeId() != Unanalyzed)
500         // It morphed into a previously analyzed node - nothing more to do.
501         return M;
502
503       // It morphed into a different new node.  Do the equivalent of passing
504       // it to AnalyzeNewNode: expunge it and calculate the NodeId.  No need
505       // to remap the operands, since they are the same as the operands we
506       // remapped above.
507       N = M;
508       ExpungeNode(N);
509     }
510   }
511
512   // Calculate the NodeId.
513   N->setNodeId(N->getNumOperands() - NumProcessed);
514   if (N->getNodeId() == ReadyToProcess)
515     Worklist.push_back(N);
516
517   return N;
518 }
519
520 /// AnalyzeNewValue - Call AnalyzeNewNode, updating the node in Val if needed.
521 /// If the node changes to a processed node, then remap it.
522 void DAGTypeLegalizer::AnalyzeNewValue(SDValue &Val) {
523   Val.setNode(AnalyzeNewNode(Val.getNode()));
524   if (Val.getNode()->getNodeId() == Processed)
525     // We were passed a processed node, or it morphed into one - remap it.
526     RemapValue(Val);
527 }
528
529 /// ExpungeNode - If N has a bogus mapping in ReplacedValues, eliminate it.
530 /// This can occur when a node is deleted then reallocated as a new node -
531 /// the mapping in ReplacedValues applies to the deleted node, not the new
532 /// one.
533 /// The only map that can have a deleted node as a source is ReplacedValues.
534 /// Other maps can have deleted nodes as targets, but since their looked-up
535 /// values are always immediately remapped using RemapValue, resulting in a
536 /// not-deleted node, this is harmless as long as ReplacedValues/RemapValue
537 /// always performs correct mappings.  In order to keep the mapping correct,
538 /// ExpungeNode should be called on any new nodes *before* adding them as
539 /// either source or target to ReplacedValues (which typically means calling
540 /// Expunge when a new node is first seen, since it may no longer be marked
541 /// NewNode by the time it is added to ReplacedValues).
542 void DAGTypeLegalizer::ExpungeNode(SDNode *N) {
543   if (N->getNodeId() != NewNode)
544     return;
545
546   // If N is not remapped by ReplacedValues then there is nothing to do.
547   unsigned i, e;
548   for (i = 0, e = N->getNumValues(); i != e; ++i)
549     if (ReplacedValues.find(SDValue(N, i)) != ReplacedValues.end())
550       break;
551
552   if (i == e)
553     return;
554
555   // Remove N from all maps - this is expensive but rare.
556
557   for (DenseMap<SDValue, SDValue>::iterator I = PromotedIntegers.begin(),
558        E = PromotedIntegers.end(); I != E; ++I) {
559     assert(I->first.getNode() != N);
560     RemapValue(I->second);
561   }
562
563   for (DenseMap<SDValue, SDValue>::iterator I = SoftenedFloats.begin(),
564        E = SoftenedFloats.end(); I != E; ++I) {
565     assert(I->first.getNode() != N);
566     RemapValue(I->second);
567   }
568
569   for (DenseMap<SDValue, SDValue>::iterator I = ScalarizedVectors.begin(),
570        E = ScalarizedVectors.end(); I != E; ++I) {
571     assert(I->first.getNode() != N);
572     RemapValue(I->second);
573   }
574
575   for (DenseMap<SDValue, SDValue>::iterator I = WidenedVectors.begin(),
576        E = WidenedVectors.end(); I != E; ++I) {
577     assert(I->first.getNode() != N);
578     RemapValue(I->second);
579   }
580
581   for (DenseMap<SDValue, std::pair<SDValue, SDValue> >::iterator
582        I = ExpandedIntegers.begin(), E = ExpandedIntegers.end(); I != E; ++I){
583     assert(I->first.getNode() != N);
584     RemapValue(I->second.first);
585     RemapValue(I->second.second);
586   }
587
588   for (DenseMap<SDValue, std::pair<SDValue, SDValue> >::iterator
589        I = ExpandedFloats.begin(), E = ExpandedFloats.end(); I != E; ++I) {
590     assert(I->first.getNode() != N);
591     RemapValue(I->second.first);
592     RemapValue(I->second.second);
593   }
594
595   for (DenseMap<SDValue, std::pair<SDValue, SDValue> >::iterator
596        I = SplitVectors.begin(), E = SplitVectors.end(); I != E; ++I) {
597     assert(I->first.getNode() != N);
598     RemapValue(I->second.first);
599     RemapValue(I->second.second);
600   }
601
602   for (DenseMap<SDValue, SDValue>::iterator I = ReplacedValues.begin(),
603        E = ReplacedValues.end(); I != E; ++I)
604     RemapValue(I->second);
605
606   for (unsigned i = 0, e = N->getNumValues(); i != e; ++i)
607     ReplacedValues.erase(SDValue(N, i));
608 }
609
610 /// RemapValue - If the specified value was already legalized to another value,
611 /// replace it by that value.
612 void DAGTypeLegalizer::RemapValue(SDValue &N) {
613   DenseMap<SDValue, SDValue>::iterator I = ReplacedValues.find(N);
614   if (I != ReplacedValues.end()) {
615     // Use path compression to speed up future lookups if values get multiply
616     // replaced with other values.
617     RemapValue(I->second);
618     N = I->second;
619
620     // Note that it is possible to have N.getNode()->getNodeId() == NewNode at
621     // this point because it is possible for a node to be put in the map before
622     // being processed.
623   }
624 }
625
626 namespace {
627   /// NodeUpdateListener - This class is a DAGUpdateListener that listens for
628   /// updates to nodes and recomputes their ready state.
629   class NodeUpdateListener : public SelectionDAG::DAGUpdateListener {
630     DAGTypeLegalizer &DTL;
631     SmallSetVector<SDNode*, 16> &NodesToAnalyze;
632   public:
633     explicit NodeUpdateListener(DAGTypeLegalizer &dtl,
634                                 SmallSetVector<SDNode*, 16> &nta)
635       : SelectionDAG::DAGUpdateListener(dtl.getDAG()),
636         DTL(dtl), NodesToAnalyze(nta) {}
637
638     void NodeDeleted(SDNode *N, SDNode *E) override {
639       assert(N->getNodeId() != DAGTypeLegalizer::ReadyToProcess &&
640              N->getNodeId() != DAGTypeLegalizer::Processed &&
641              "Invalid node ID for RAUW deletion!");
642       // It is possible, though rare, for the deleted node N to occur as a
643       // target in a map, so note the replacement N -> E in ReplacedValues.
644       assert(E && "Node not replaced?");
645       DTL.NoteDeletion(N, E);
646
647       // In theory the deleted node could also have been scheduled for analysis.
648       // So remove it from the set of nodes which will be analyzed.
649       NodesToAnalyze.remove(N);
650
651       // In general nothing needs to be done for E, since it didn't change but
652       // only gained new uses.  However N -> E was just added to ReplacedValues,
653       // and the result of a ReplacedValues mapping is not allowed to be marked
654       // NewNode.  So if E is marked NewNode, then it needs to be analyzed.
655       if (E->getNodeId() == DAGTypeLegalizer::NewNode)
656         NodesToAnalyze.insert(E);
657     }
658
659     void NodeUpdated(SDNode *N) override {
660       // Node updates can mean pretty much anything.  It is possible that an
661       // operand was set to something already processed (f.e.) in which case
662       // this node could become ready.  Recompute its flags.
663       assert(N->getNodeId() != DAGTypeLegalizer::ReadyToProcess &&
664              N->getNodeId() != DAGTypeLegalizer::Processed &&
665              "Invalid node ID for RAUW deletion!");
666       N->setNodeId(DAGTypeLegalizer::NewNode);
667       NodesToAnalyze.insert(N);
668     }
669   };
670 }
671
672
673 /// ReplaceValueWith - The specified value was legalized to the specified other
674 /// value.  Update the DAG and NodeIds replacing any uses of From to use To
675 /// instead.
676 void DAGTypeLegalizer::ReplaceValueWith(SDValue From, SDValue To) {
677   assert(From.getNode() != To.getNode() && "Potential legalization loop!");
678
679   // If expansion produced new nodes, make sure they are properly marked.
680   ExpungeNode(From.getNode());
681   AnalyzeNewValue(To); // Expunges To.
682
683   // Anything that used the old node should now use the new one.  Note that this
684   // can potentially cause recursive merging.
685   SmallSetVector<SDNode*, 16> NodesToAnalyze;
686   NodeUpdateListener NUL(*this, NodesToAnalyze);
687   do {
688     DAG.ReplaceAllUsesOfValueWith(From, To);
689
690     // The old node may still be present in a map like ExpandedIntegers or
691     // PromotedIntegers.  Inform maps about the replacement.
692     ReplacedValues[From] = To;
693
694     // Process the list of nodes that need to be reanalyzed.
695     while (!NodesToAnalyze.empty()) {
696       SDNode *N = NodesToAnalyze.back();
697       NodesToAnalyze.pop_back();
698       if (N->getNodeId() != DAGTypeLegalizer::NewNode)
699         // The node was analyzed while reanalyzing an earlier node - it is safe
700         // to skip.  Note that this is not a morphing node - otherwise it would
701         // still be marked NewNode.
702         continue;
703
704       // Analyze the node's operands and recalculate the node ID.
705       SDNode *M = AnalyzeNewNode(N);
706       if (M != N) {
707         // The node morphed into a different node.  Make everyone use the new
708         // node instead.
709         assert(M->getNodeId() != NewNode && "Analysis resulted in NewNode!");
710         assert(N->getNumValues() == M->getNumValues() &&
711                "Node morphing changed the number of results!");
712         for (unsigned i = 0, e = N->getNumValues(); i != e; ++i) {
713           SDValue OldVal(N, i);
714           SDValue NewVal(M, i);
715           if (M->getNodeId() == Processed)
716             RemapValue(NewVal);
717           DAG.ReplaceAllUsesOfValueWith(OldVal, NewVal);
718           // OldVal may be a target of the ReplacedValues map which was marked
719           // NewNode to force reanalysis because it was updated.  Ensure that
720           // anything that ReplacedValues mapped to OldVal will now be mapped
721           // all the way to NewVal.
722           ReplacedValues[OldVal] = NewVal;
723         }
724         // The original node continues to exist in the DAG, marked NewNode.
725       }
726     }
727     // When recursively update nodes with new nodes, it is possible to have
728     // new uses of From due to CSE. If this happens, replace the new uses of
729     // From with To.
730   } while (!From.use_empty());
731 }
732
733 void DAGTypeLegalizer::SetPromotedInteger(SDValue Op, SDValue Result) {
734   assert(Result.getValueType() ==
735          TLI.getTypeToTransformTo(*DAG.getContext(), Op.getValueType()) &&
736          "Invalid type for promoted integer");
737   AnalyzeNewValue(Result);
738
739   SDValue &OpEntry = PromotedIntegers[Op];
740   assert(!OpEntry.getNode() && "Node is already promoted!");
741   OpEntry = Result;
742 }
743
744 void DAGTypeLegalizer::SetSoftenedFloat(SDValue Op, SDValue Result) {
745   assert(Result.getValueType() ==
746          TLI.getTypeToTransformTo(*DAG.getContext(), Op.getValueType()) &&
747          "Invalid type for softened float");
748   AnalyzeNewValue(Result);
749
750   SDValue &OpEntry = SoftenedFloats[Op];
751   assert(!OpEntry.getNode() && "Node is already converted to integer!");
752   OpEntry = Result;
753 }
754
755 void DAGTypeLegalizer::SetScalarizedVector(SDValue Op, SDValue Result) {
756   // Note that in some cases vector operation operands may be greater than
757   // the vector element type. For example BUILD_VECTOR of type <1 x i1> with
758   // a constant i8 operand.
759   assert(Result.getValueType().getSizeInBits() >=
760          Op.getValueType().getVectorElementType().getSizeInBits() &&
761          "Invalid type for scalarized vector");
762   AnalyzeNewValue(Result);
763
764   SDValue &OpEntry = ScalarizedVectors[Op];
765   assert(!OpEntry.getNode() && "Node is already scalarized!");
766   OpEntry = Result;
767 }
768
769 void DAGTypeLegalizer::GetExpandedInteger(SDValue Op, SDValue &Lo,
770                                           SDValue &Hi) {
771   std::pair<SDValue, SDValue> &Entry = ExpandedIntegers[Op];
772   RemapValue(Entry.first);
773   RemapValue(Entry.second);
774   assert(Entry.first.getNode() && "Operand isn't expanded");
775   Lo = Entry.first;
776   Hi = Entry.second;
777 }
778
779 void DAGTypeLegalizer::SetExpandedInteger(SDValue Op, SDValue Lo,
780                                           SDValue Hi) {
781   assert(Lo.getValueType() ==
782          TLI.getTypeToTransformTo(*DAG.getContext(), Op.getValueType()) &&
783          Hi.getValueType() == Lo.getValueType() &&
784          "Invalid type for expanded integer");
785   // Lo/Hi may have been newly allocated, if so, add nodeid's as relevant.
786   AnalyzeNewValue(Lo);
787   AnalyzeNewValue(Hi);
788
789   // Remember that this is the result of the node.
790   std::pair<SDValue, SDValue> &Entry = ExpandedIntegers[Op];
791   assert(!Entry.first.getNode() && "Node already expanded");
792   Entry.first = Lo;
793   Entry.second = Hi;
794 }
795
796 void DAGTypeLegalizer::GetExpandedFloat(SDValue Op, SDValue &Lo,
797                                         SDValue &Hi) {
798   std::pair<SDValue, SDValue> &Entry = ExpandedFloats[Op];
799   RemapValue(Entry.first);
800   RemapValue(Entry.second);
801   assert(Entry.first.getNode() && "Operand isn't expanded");
802   Lo = Entry.first;
803   Hi = Entry.second;
804 }
805
806 void DAGTypeLegalizer::SetExpandedFloat(SDValue Op, SDValue Lo,
807                                         SDValue Hi) {
808   assert(Lo.getValueType() ==
809          TLI.getTypeToTransformTo(*DAG.getContext(), Op.getValueType()) &&
810          Hi.getValueType() == Lo.getValueType() &&
811          "Invalid type for expanded float");
812   // Lo/Hi may have been newly allocated, if so, add nodeid's as relevant.
813   AnalyzeNewValue(Lo);
814   AnalyzeNewValue(Hi);
815
816   // Remember that this is the result of the node.
817   std::pair<SDValue, SDValue> &Entry = ExpandedFloats[Op];
818   assert(!Entry.first.getNode() && "Node already expanded");
819   Entry.first = Lo;
820   Entry.second = Hi;
821 }
822
823 void DAGTypeLegalizer::GetSplitVector(SDValue Op, SDValue &Lo,
824                                       SDValue &Hi) {
825   std::pair<SDValue, SDValue> &Entry = SplitVectors[Op];
826   RemapValue(Entry.first);
827   RemapValue(Entry.second);
828   assert(Entry.first.getNode() && "Operand isn't split");
829   Lo = Entry.first;
830   Hi = Entry.second;
831 }
832
833 void DAGTypeLegalizer::SetSplitVector(SDValue Op, SDValue Lo,
834                                       SDValue Hi) {
835   assert(Lo.getValueType().getVectorElementType() ==
836          Op.getValueType().getVectorElementType() &&
837          2*Lo.getValueType().getVectorNumElements() ==
838          Op.getValueType().getVectorNumElements() &&
839          Hi.getValueType() == Lo.getValueType() &&
840          "Invalid type for split vector");
841   // Lo/Hi may have been newly allocated, if so, add nodeid's as relevant.
842   AnalyzeNewValue(Lo);
843   AnalyzeNewValue(Hi);
844
845   // Remember that this is the result of the node.
846   std::pair<SDValue, SDValue> &Entry = SplitVectors[Op];
847   assert(!Entry.first.getNode() && "Node already split");
848   Entry.first = Lo;
849   Entry.second = Hi;
850 }
851
852 void DAGTypeLegalizer::SetWidenedVector(SDValue Op, SDValue Result) {
853   assert(Result.getValueType() ==
854          TLI.getTypeToTransformTo(*DAG.getContext(), Op.getValueType()) &&
855          "Invalid type for widened vector");
856   AnalyzeNewValue(Result);
857
858   SDValue &OpEntry = WidenedVectors[Op];
859   assert(!OpEntry.getNode() && "Node already widened!");
860   OpEntry = Result;
861 }
862
863
864 //===----------------------------------------------------------------------===//
865 // Utilities.
866 //===----------------------------------------------------------------------===//
867
868 /// BitConvertToInteger - Convert to an integer of the same size.
869 SDValue DAGTypeLegalizer::BitConvertToInteger(SDValue Op) {
870   unsigned BitWidth = Op.getValueType().getSizeInBits();
871   return DAG.getNode(ISD::BITCAST, SDLoc(Op),
872                      EVT::getIntegerVT(*DAG.getContext(), BitWidth), Op);
873 }
874
875 /// BitConvertVectorToIntegerVector - Convert to a vector of integers of the
876 /// same size.
877 SDValue DAGTypeLegalizer::BitConvertVectorToIntegerVector(SDValue Op) {
878   assert(Op.getValueType().isVector() && "Only applies to vectors!");
879   unsigned EltWidth = Op.getValueType().getVectorElementType().getSizeInBits();
880   EVT EltNVT = EVT::getIntegerVT(*DAG.getContext(), EltWidth);
881   unsigned NumElts = Op.getValueType().getVectorNumElements();
882   return DAG.getNode(ISD::BITCAST, SDLoc(Op),
883                      EVT::getVectorVT(*DAG.getContext(), EltNVT, NumElts), Op);
884 }
885
886 SDValue DAGTypeLegalizer::CreateStackStoreLoad(SDValue Op,
887                                                EVT DestVT) {
888   SDLoc dl(Op);
889   // Create the stack frame object.  Make sure it is aligned for both
890   // the source and destination types.
891   SDValue StackPtr = DAG.CreateStackTemporary(Op.getValueType(), DestVT);
892   // Emit a store to the stack slot.
893   SDValue Store = DAG.getStore(DAG.getEntryNode(), dl, Op, StackPtr,
894                                MachinePointerInfo(), false, false, 0);
895   // Result is a load from the stack slot.
896   return DAG.getLoad(DestVT, dl, Store, StackPtr, MachinePointerInfo(),
897                      false, false, false, 0);
898 }
899
900 /// CustomLowerNode - Replace the node's results with custom code provided
901 /// by the target and return "true", or do nothing and return "false".
902 /// The last parameter is FALSE if we are dealing with a node with legal
903 /// result types and illegal operand. The second parameter denotes the type of
904 /// illegal OperandNo in that case.
905 /// The last parameter being TRUE means we are dealing with a
906 /// node with illegal result types. The second parameter denotes the type of
907 /// illegal ResNo in that case.
908 bool DAGTypeLegalizer::CustomLowerNode(SDNode *N, EVT VT, bool LegalizeResult) {
909   // See if the target wants to custom lower this node.
910   if (TLI.getOperationAction(N->getOpcode(), VT) != TargetLowering::Custom)
911     return false;
912
913   SmallVector<SDValue, 8> Results;
914   if (LegalizeResult)
915     TLI.ReplaceNodeResults(N, Results, DAG);
916   else
917     TLI.LowerOperationWrapper(N, Results, DAG);
918
919   if (Results.empty())
920     // The target didn't want to custom lower it after all.
921     return false;
922
923   // Make everything that once used N's values now use those in Results instead.
924   assert(Results.size() == N->getNumValues() &&
925          "Custom lowering returned the wrong number of results!");
926   for (unsigned i = 0, e = Results.size(); i != e; ++i) {
927     ReplaceValueWith(SDValue(N, i), Results[i]);
928   }
929   return true;
930 }
931
932
933 /// CustomWidenLowerNode - Widen the node's results with custom code provided
934 /// by the target and return "true", or do nothing and return "false".
935 bool DAGTypeLegalizer::CustomWidenLowerNode(SDNode *N, EVT VT) {
936   // See if the target wants to custom lower this node.
937   if (TLI.getOperationAction(N->getOpcode(), VT) != TargetLowering::Custom)
938     return false;
939
940   SmallVector<SDValue, 8> Results;
941   TLI.ReplaceNodeResults(N, Results, DAG);
942
943   if (Results.empty())
944     // The target didn't want to custom widen lower its result  after all.
945     return false;
946
947   // Update the widening map.
948   assert(Results.size() == N->getNumValues() &&
949          "Custom lowering returned the wrong number of results!");
950   for (unsigned i = 0, e = Results.size(); i != e; ++i)
951     SetWidenedVector(SDValue(N, i), Results[i]);
952   return true;
953 }
954
955 SDValue DAGTypeLegalizer::DisintegrateMERGE_VALUES(SDNode *N, unsigned ResNo) {
956   for (unsigned i = 0, e = N->getNumValues(); i != e; ++i)
957     if (i != ResNo)
958       ReplaceValueWith(SDValue(N, i), SDValue(N->getOperand(i)));
959   return SDValue(N->getOperand(ResNo));
960 }
961
962 /// GetPairElements - Use ISD::EXTRACT_ELEMENT nodes to extract the low and
963 /// high parts of the given value.
964 void DAGTypeLegalizer::GetPairElements(SDValue Pair,
965                                        SDValue &Lo, SDValue &Hi) {
966   SDLoc dl(Pair);
967   EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), Pair.getValueType());
968   Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, NVT, Pair,
969                    DAG.getIntPtrConstant(0));
970   Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, NVT, Pair,
971                    DAG.getIntPtrConstant(1));
972 }
973
974 SDValue DAGTypeLegalizer::GetVectorElementPointer(SDValue VecPtr, EVT EltVT,
975                                                   SDValue Index) {
976   SDLoc dl(Index);
977   // Make sure the index type is big enough to compute in.
978   Index = DAG.getZExtOrTrunc(Index, dl, TLI.getPointerTy());
979
980   // Calculate the element offset and add it to the pointer.
981   unsigned EltSize = EltVT.getSizeInBits() / 8; // FIXME: should be ABI size.
982
983   Index = DAG.getNode(ISD::MUL, dl, Index.getValueType(), Index,
984                       DAG.getConstant(EltSize, Index.getValueType()));
985   return DAG.getNode(ISD::ADD, dl, Index.getValueType(), Index, VecPtr);
986 }
987
988 /// JoinIntegers - Build an integer with low bits Lo and high bits Hi.
989 SDValue DAGTypeLegalizer::JoinIntegers(SDValue Lo, SDValue Hi) {
990   // Arbitrarily use dlHi for result SDLoc
991   SDLoc dlHi(Hi);
992   SDLoc dlLo(Lo);
993   EVT LVT = Lo.getValueType();
994   EVT HVT = Hi.getValueType();
995   EVT NVT = EVT::getIntegerVT(*DAG.getContext(),
996                               LVT.getSizeInBits() + HVT.getSizeInBits());
997
998   Lo = DAG.getNode(ISD::ZERO_EXTEND, dlLo, NVT, Lo);
999   Hi = DAG.getNode(ISD::ANY_EXTEND, dlHi, NVT, Hi);
1000   Hi = DAG.getNode(ISD::SHL, dlHi, NVT, Hi,
1001                    DAG.getConstant(LVT.getSizeInBits(), TLI.getPointerTy()));
1002   return DAG.getNode(ISD::OR, dlHi, NVT, Lo, Hi);
1003 }
1004
1005 /// LibCallify - Convert the node into a libcall with the same prototype.
1006 SDValue DAGTypeLegalizer::LibCallify(RTLIB::Libcall LC, SDNode *N,
1007                                      bool isSigned) {
1008   unsigned NumOps = N->getNumOperands();
1009   SDLoc dl(N);
1010   if (NumOps == 0) {
1011     return TLI.makeLibCall(DAG, LC, N->getValueType(0), nullptr, 0, isSigned,
1012                            dl).first;
1013   } else if (NumOps == 1) {
1014     SDValue Op = N->getOperand(0);
1015     return TLI.makeLibCall(DAG, LC, N->getValueType(0), &Op, 1, isSigned,
1016                            dl).first;
1017   } else if (NumOps == 2) {
1018     SDValue Ops[2] = { N->getOperand(0), N->getOperand(1) };
1019     return TLI.makeLibCall(DAG, LC, N->getValueType(0), Ops, 2, isSigned,
1020                            dl).first;
1021   }
1022   SmallVector<SDValue, 8> Ops(NumOps);
1023   for (unsigned i = 0; i < NumOps; ++i)
1024     Ops[i] = N->getOperand(i);
1025
1026   return TLI.makeLibCall(DAG, LC, N->getValueType(0),
1027                          &Ops[0], NumOps, isSigned, dl).first;
1028 }
1029
1030 // ExpandChainLibCall - Expand a node into a call to a libcall. Similar to
1031 // ExpandLibCall except that the first operand is the in-chain.
1032 std::pair<SDValue, SDValue>
1033 DAGTypeLegalizer::ExpandChainLibCall(RTLIB::Libcall LC,
1034                                          SDNode *Node,
1035                                          bool isSigned) {
1036   SDValue InChain = Node->getOperand(0);
1037
1038   TargetLowering::ArgListTy Args;
1039   TargetLowering::ArgListEntry Entry;
1040   for (unsigned i = 1, e = Node->getNumOperands(); i != e; ++i) {
1041     EVT ArgVT = Node->getOperand(i).getValueType();
1042     Type *ArgTy = ArgVT.getTypeForEVT(*DAG.getContext());
1043     Entry.Node = Node->getOperand(i);
1044     Entry.Ty = ArgTy;
1045     Entry.isSExt = isSigned;
1046     Entry.isZExt = !isSigned;
1047     Args.push_back(Entry);
1048   }
1049   SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC),
1050                                          TLI.getPointerTy());
1051
1052   Type *RetTy = Node->getValueType(0).getTypeForEVT(*DAG.getContext());
1053   TargetLowering::
1054   CallLoweringInfo CLI(InChain, RetTy, isSigned, !isSigned, false, false,
1055                     0, TLI.getLibcallCallingConv(LC), /*isTailCall=*/false,
1056                     /*doesNotReturn=*/false, /*isReturnValueUsed=*/true,
1057                     Callee, Args, DAG, SDLoc(Node));
1058   std::pair<SDValue, SDValue> CallInfo = TLI.LowerCallTo(CLI);
1059
1060   return CallInfo;
1061 }
1062
1063 /// PromoteTargetBoolean - Promote the given target boolean to a target boolean
1064 /// of the given type.  A target boolean is an integer value, not necessarily of
1065 /// type i1, the bits of which conform to getBooleanContents.
1066 SDValue DAGTypeLegalizer::PromoteTargetBoolean(SDValue Bool, EVT VT) {
1067   SDLoc dl(Bool);
1068   ISD::NodeType ExtendCode =
1069     TargetLowering::getExtendForContent(TLI.getBooleanContents(VT.isVector()));
1070   return DAG.getNode(ExtendCode, dl, VT, Bool);
1071 }
1072
1073 /// SplitInteger - Return the lower LoVT bits of Op in Lo and the upper HiVT
1074 /// bits in Hi.
1075 void DAGTypeLegalizer::SplitInteger(SDValue Op,
1076                                     EVT LoVT, EVT HiVT,
1077                                     SDValue &Lo, SDValue &Hi) {
1078   SDLoc dl(Op);
1079   assert(LoVT.getSizeInBits() + HiVT.getSizeInBits() ==
1080          Op.getValueType().getSizeInBits() && "Invalid integer splitting!");
1081   Lo = DAG.getNode(ISD::TRUNCATE, dl, LoVT, Op);
1082   Hi = DAG.getNode(ISD::SRL, dl, Op.getValueType(), Op,
1083                    DAG.getConstant(LoVT.getSizeInBits(), TLI.getPointerTy()));
1084   Hi = DAG.getNode(ISD::TRUNCATE, dl, HiVT, Hi);
1085 }
1086
1087 /// SplitInteger - Return the lower and upper halves of Op's bits in a value
1088 /// type half the size of Op's.
1089 void DAGTypeLegalizer::SplitInteger(SDValue Op,
1090                                     SDValue &Lo, SDValue &Hi) {
1091   EVT HalfVT = EVT::getIntegerVT(*DAG.getContext(),
1092                                  Op.getValueType().getSizeInBits()/2);
1093   SplitInteger(Op, HalfVT, HalfVT, Lo, Hi);
1094 }
1095
1096
1097 //===----------------------------------------------------------------------===//
1098 //  Entry Point
1099 //===----------------------------------------------------------------------===//
1100
1101 /// LegalizeTypes - This transforms the SelectionDAG into a SelectionDAG that
1102 /// only uses types natively supported by the target.  Returns "true" if it made
1103 /// any changes.
1104 ///
1105 /// Note that this is an involved process that may invalidate pointers into
1106 /// the graph.
1107 bool SelectionDAG::LegalizeTypes() {
1108   return DAGTypeLegalizer(*this).run();
1109 }