29 void DAGTypeLegalizer::PerformExpensiveChecks() {
80 for (
unsigned i = 0, e =
I->getNumValues(); i != e; ++i) {
85 if (ReplacedValues.find(Res) != ReplacedValues.end()) {
90 if (UI.getUse().getResNo() == i)
91 assert(UI->getNodeId() ==
NewNode &&
92 "Remapped value has non-trivial use!");
96 SDValue NewVal = ReplacedValues[Res];
98 while (I != ReplacedValues.end()) {
100 I = ReplacedValues.find(NewVal);
103 "ReplacedValues maps to a new node!");
105 if (PromotedIntegers.find(Res) != PromotedIntegers.end())
107 if (SoftenedFloats.find(Res) != SoftenedFloats.end())
109 if (ScalarizedVectors.find(Res) != ScalarizedVectors.end())
111 if (ExpandedIntegers.find(Res) != ExpandedIntegers.end())
113 if (ExpandedFloats.find(Res) != ExpandedFloats.end())
115 if (SplitVectors.find(Res) != SplitVectors.end())
117 if (WidenedVectors.find(Res) != WidenedVectors.end())
124 if ((I->getNodeId() ==
NewNode && Mapped > 1) ||
125 (I->getNodeId() !=
NewNode && Mapped != 0)) {
126 dbgs() <<
"Unprocessed value in a map!";
129 }
else if (isTypeLegal(Res.getValueType()) || IgnoreNodeResults(I)) {
131 dbgs() <<
"Value with legal type was transformed!";
136 dbgs() <<
"Processed value not in any map!";
138 }
else if (Mapped & (Mapped - 1)) {
139 dbgs() <<
"Value in multiple maps!";
146 dbgs() <<
" ReplacedValues";
148 dbgs() <<
" PromotedIntegers";
150 dbgs() <<
" SoftenedFloats";
152 dbgs() <<
" ScalarizedVectors";
154 dbgs() <<
" ExpandedIntegers";
156 dbgs() <<
" ExpandedFloats";
158 dbgs() <<
" SplitVectors";
160 dbgs() <<
" WidenedVectors";
168 for (
unsigned i = 0, e = NewNodes.
size(); i != e; ++i) {
172 assert(UI->getNodeId() ==
NewNode &&
"NewNode used by non-NewNode!");
180 bool Changed =
false;
197 if (I->getNumOperands() == 0) {
199 Worklist.push_back(I);
206 while (!Worklist.empty()) {
210 PerformExpensiveChecks();
212 SDNode *N = Worklist.back();
215 "Node should be ready if on worklist!");
217 if (IgnoreNodeResults(N))
222 for (
unsigned i = 0, NumResults = N->
getNumValues(); i < NumResults; ++i) {
224 switch (getTypeAction(ResultVT)) {
233 PromoteIntegerResult(N, i);
237 ExpandIntegerResult(N, i);
241 SoftenFloatResult(N, i);
245 ExpandFloatResult(N, i);
249 ScalarizeVectorResult(N, i);
253 SplitVectorResult(N, i);
257 WidenVectorResult(N, i);
268 bool NeedsReanalyzing =
false;
270 for (i = 0; i != NumOperands; ++i) {
275 switch (getTypeAction(OpVT)) {
282 NeedsReanalyzing = PromoteIntegerOperand(N, i);
286 NeedsReanalyzing = ExpandIntegerOperand(N, i);
290 NeedsReanalyzing = SoftenFloatOperand(N, i);
294 NeedsReanalyzing = ExpandFloatOperand(N, i);
298 NeedsReanalyzing = ScalarizeVectorOperand(N, i);
302 NeedsReanalyzing = SplitVectorOperand(N, i);
306 NeedsReanalyzing = WidenVectorOperand(N, i);
316 if (NeedsReanalyzing) {
321 SDNode *M = AnalyzeNewNode(N);
329 "Node morphing changed the number of results!");
330 for (
unsigned i = 0, e = N->
getNumValues(); i != e; ++i)
340 if (i == NumOperands) {
363 Worklist.push_back(User);
376 assert(NodeId ==
Unanalyzed &&
"Unknown node ID!");
381 Worklist.push_back(User);
388 PerformExpensiveChecks();
407 if (!IgnoreNodeResults(I))
408 for (
unsigned i = 0, NumVals = I->getNumValues(); i < NumVals; ++i)
409 if (!isTypeLegal(I->getValueType(i))) {
410 dbgs() <<
"Result type " << i <<
" illegal!\n";
415 for (
unsigned i = 0, NumOps = I->getNumOperands(); i < NumOps; ++i)
416 if (!IgnoreNodeResults(I->getOperand(i).getNode()) &&
417 !isTypeLegal(I->getOperand(i).getValueType())) {
418 dbgs() <<
"Operand type " << i <<
" illegal!\n";
424 dbgs() <<
"New node not analyzed?\n";
426 dbgs() <<
"Unanalyzed node not noticed?\n";
427 else if (I->getNodeId() > 0)
428 dbgs() <<
"Operand not processed?\n";
430 dbgs() <<
"Not added to worklist?\n";
435 I->dump(&DAG);
dbgs() <<
"\n";
469 unsigned NumProcessed = 0;
479 if (!NewOps.
empty()) {
482 }
else if (Op != OrigOp) {
490 if (!NewOps.
empty()) {
514 Worklist.push_back(N);
521 void DAGTypeLegalizer::AnalyzeNewValue(
SDValue &Val) {
541 void DAGTypeLegalizer::ExpungeNode(
SDNode *N) {
548 if (ReplacedValues.find(
SDValue(N, i)) != ReplacedValues.end())
557 E = PromotedIntegers.end(); I != E; ++
I) {
558 assert(I->first.getNode() !=
N);
559 RemapValue(I->second);
563 E = SoftenedFloats.end(); I != E; ++
I) {
564 assert(I->first.getNode() !=
N);
565 RemapValue(I->second);
569 E = ScalarizedVectors.end(); I != E; ++
I) {
570 assert(I->first.getNode() !=
N);
571 RemapValue(I->second);
575 E = WidenedVectors.end(); I != E; ++
I) {
576 assert(I->first.getNode() !=
N);
577 RemapValue(I->second);
581 I = ExpandedIntegers.begin(), E = ExpandedIntegers.end(); I != E; ++
I){
582 assert(I->first.getNode() !=
N);
583 RemapValue(I->second.first);
584 RemapValue(I->second.second);
588 I = ExpandedFloats.begin(), E = ExpandedFloats.end(); I != E; ++
I) {
589 assert(I->first.getNode() !=
N);
590 RemapValue(I->second.first);
591 RemapValue(I->second.second);
595 I = SplitVectors.begin(), E = SplitVectors.end(); I != E; ++
I) {
596 assert(I->first.getNode() !=
N);
597 RemapValue(I->second.first);
598 RemapValue(I->second.second);
602 E = ReplacedValues.end(); I != E; ++
I)
603 RemapValue(I->second);
605 for (
unsigned i = 0, e = N->
getNumValues(); i != e; ++i)
606 ReplacedValues.erase(
SDValue(N, i));
611 void DAGTypeLegalizer::RemapValue(
SDValue &N) {
613 if (I != ReplacedValues.end()) {
616 RemapValue(I->second);
635 DTL(dtl), NodesToAnalyze(nta) {}
640 "Invalid node ID for RAUW deletion!");
643 assert(E &&
"Node not replaced?");
644 DTL.NoteDeletion(N, E);
648 NodesToAnalyze.remove(N);
655 NodesToAnalyze.insert(E);
658 virtual void NodeUpdated(
SDNode *N) {
664 "Invalid node ID for RAUW deletion!");
666 NodesToAnalyze.insert(N);
675 void DAGTypeLegalizer::ReplaceValueWith(
SDValue From,
SDValue To) {
676 assert(From.
getNode() != To.
getNode() &&
"Potential legalization loop!");
685 NodeUpdateListener NUL(*
this, NodesToAnalyze);
691 ReplacedValues[From] = To;
694 while (!NodesToAnalyze.
empty()) {
704 SDNode *M = AnalyzeNewNode(N);
710 "Node morphing changed the number of results!");
711 for (
unsigned i = 0, e = N->
getNumValues(); i != e; ++i) {
721 ReplacedValues[OldVal] = NewVal;
732 void DAGTypeLegalizer::SetPromotedInteger(
SDValue Op,
SDValue Result) {
735 "Invalid type for promoted integer");
736 AnalyzeNewValue(Result);
738 SDValue &OpEntry = PromotedIntegers[Op];
739 assert(OpEntry.
getNode() == 0 &&
"Node is already promoted!");
743 void DAGTypeLegalizer::SetSoftenedFloat(
SDValue Op,
SDValue Result) {
746 "Invalid type for softened float");
747 AnalyzeNewValue(Result);
749 SDValue &OpEntry = SoftenedFloats[Op];
750 assert(OpEntry.
getNode() == 0 &&
"Node is already converted to integer!");
754 void DAGTypeLegalizer::SetScalarizedVector(
SDValue Op,
SDValue Result) {
760 "Invalid type for scalarized vector");
761 AnalyzeNewValue(Result);
763 SDValue &OpEntry = ScalarizedVectors[Op];
764 assert(OpEntry.
getNode() == 0 &&
"Node is already scalarized!");
770 std::pair<SDValue, SDValue> &Entry = ExpandedIntegers[Op];
771 RemapValue(Entry.first);
772 RemapValue(Entry.second);
773 assert(Entry.first.getNode() &&
"Operand isn't expanded");
783 "Invalid type for expanded integer");
789 std::pair<SDValue, SDValue> &Entry = ExpandedIntegers[Op];
790 assert(Entry.first.getNode() == 0 &&
"Node already expanded");
797 std::pair<SDValue, SDValue> &Entry = ExpandedFloats[Op];
798 RemapValue(Entry.first);
799 RemapValue(Entry.second);
800 assert(Entry.first.getNode() &&
"Operand isn't expanded");
810 "Invalid type for expanded float");
816 std::pair<SDValue, SDValue> &Entry = ExpandedFloats[Op];
817 assert(Entry.first.getNode() == 0 &&
"Node already expanded");
824 std::pair<SDValue, SDValue> &Entry = SplitVectors[Op];
825 RemapValue(Entry.first);
826 RemapValue(Entry.second);
827 assert(Entry.first.getNode() &&
"Operand isn't split");
839 "Invalid type for split vector");
845 std::pair<SDValue, SDValue> &Entry = SplitVectors[Op];
846 assert(Entry.first.getNode() == 0 &&
"Node already split");
851 void DAGTypeLegalizer::SetWidenedVector(
SDValue Op,
SDValue Result) {
854 "Invalid type for widened vector");
855 AnalyzeNewValue(Result);
857 SDValue &OpEntry = WidenedVectors[Op];
858 assert(OpEntry.
getNode() == 0 &&
"Node already widened!");
876 SDValue DAGTypeLegalizer::BitConvertVectorToIntegerVector(
SDValue Op) {
896 false,
false,
false, 0);
907 bool DAGTypeLegalizer::CustomLowerNode(
SDNode *N,
EVT VT,
bool LegalizeResult) {
924 "Custom lowering returned the wrong number of results!");
925 for (
unsigned i = 0, e = Results.
size(); i != e; ++i) {
926 ReplaceValueWith(
SDValue(N, i), Results[i]);
934 bool DAGTypeLegalizer::CustomWidenLowerNode(
SDNode *N,
EVT VT) {
948 "Custom lowering returned the wrong number of results!");
949 for (
unsigned i = 0, e = Results.
size(); i != e; ++i)
950 SetWidenedVector(
SDValue(N, i), Results[i]);
954 SDValue DAGTypeLegalizer::DisintegrateMERGE_VALUES(
SDNode *N,
unsigned ResNo) {
955 for (
unsigned i = 0, e = N->
getNumValues(); i != e; ++i)
963 void DAGTypeLegalizer::GetPairElements(
SDValue Pair,
1012 }
else if (NumOps == 1) {
1016 }
else if (NumOps == 2) {
1022 for (
unsigned i = 0; i < NumOps; ++i)
1026 &Ops[0], NumOps, isSigned, dl).first;
1031 std::pair<SDValue, SDValue>
1045 Entry.
isZExt = !isSigned;
1046 Args.push_back(Entry);
1056 Callee, Args, DAG,
SDLoc(Node));
1057 std::pair<SDValue, SDValue> CallInfo = TLI.
LowerCallTo(CLI);
1069 return DAG.getNode(ExtendCode, dl, VT, Bool);
1074 void DAGTypeLegalizer::SplitInteger(
SDValue Op,
1088 void DAGTypeLegalizer::SplitInteger(
SDValue Op,
1092 SplitInteger(Op, HalfVT, HalfVT, Lo, Hi);
void push_back(const T &Elt)
SDValue getConstant(uint64_t Val, EVT VT, bool isTarget=false)
CallingConv::ID getLibcallCallingConv(RTLIB::Libcall Call) const
Get the CallingConv that should be used for the specified libcall.
LLVMContext * getContext() const
void dump() const
dump - Dump this node, for debugging.
unsigned getOpcode() const
static ISD::NodeType getExtendForContent(BooleanContent Content)
Type * getTypeForEVT(LLVMContext &Context) const
unsigned getNumOperands() const
const SDValue & getOperand(unsigned Num) const
void setNodeId(int Id)
setNodeId - Set unique node id.
const SDValue & setRoot(SDValue N)
LegalizeAction getOperationAction(unsigned Op, EVT VT) const
SDValue getExternalSymbol(const char *Sym, EVT VT)
SDValue getLoad(EVT VT, SDLoc dl, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, bool isVolatile, bool isNonTemporal, bool isInvariant, unsigned Alignment, const MDNode *TBAAInfo=0, const MDNode *Ranges=0)
bool isVector() const
isVector - Return true if this is a vector value type.
SDValue getStore(SDValue Chain, SDLoc dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, bool isVolatile, bool isNonTemporal, unsigned Alignment, const MDNode *TBAAInfo=0)
#define llvm_unreachable(msg)
EVT getValueType(unsigned ResNo) const
std::pair< SDValue, SDValue > makeLibCall(SelectionDAG &DAG, RTLIB::Libcall LC, EVT RetVT, const SDValue *Ops, unsigned NumOps, bool isSigned, SDLoc dl, bool doesNotReturn=false, bool isReturnValueUsed=true) const
Returns a pair of (return value, chain).
allnodes_const_iterator allnodes_end() const
virtual MVT getPointerTy(uint32_t=0) const
void pop_back()
Remove the last element of the SetVector.
EVT getVectorElementType() const
std::pair< SDValue, SDValue > LowerCallTo(CallLoweringInfo &CLI) const
unsigned getNumValues() const
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
Simple integer binary arithmetic operators.
bool empty() const
Determine if the SetVector is empty or not.
static cl::opt< bool > EnableExpensiveChecks("enable-legalize-types-checking", cl::Hidden)
SDNode * getNode() const
get the SDNode which holds the desired result
use_iterator use_begin() const
void append(in_iter in_start, in_iter in_end)
std::vector< ArgListEntry > ArgListTy
static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements)
const SDValue & getRoot() const
SDValue CreateStackTemporary(EVT VT, unsigned minAlign=1)
virtual void ReplaceNodeResults(SDNode *, SmallVectorImpl< SDValue > &, SelectionDAG &) const
A SetVector that performs no allocations if smaller than a certain size.
allnodes_const_iterator allnodes_begin() const
void setNode(SDNode *N)
set the SDNode
const char * getLibcallName(RTLIB::Libcall Call) const
Get the libcall routine name for the specified libcall.
BooleanContent getBooleanContents(bool isVec) const
SDNode * UpdateNodeOperands(SDNode *N, SDValue Op)
SDValue getIntPtrConstant(uint64_t Val, bool isTarget=false)
Processed - This is a node that has already been processed.
raw_ostream & dbgs()
dbgs - Return a circular-buffered debug stream.
op_iterator op_begin() const
static use_iterator use_end()
ZERO_EXTEND - Used for integer types, zeroing the new bits.
SDValue getNode(unsigned Opcode, SDLoc DL, EVT VT)
ANY_EXTEND - Used for integer types. The high bits are undefined.
unsigned getSizeInBits() const
getSizeInBits - Return the size of the specified value type in bits.
const T & back() const
Return the last element of the SetVector.
SDValue getZExtOrTrunc(SDValue Op, SDLoc DL, EVT VT)
EVT getTypeToTransformTo(LLVMContext &Context, EVT VT) const
void ReplaceAllUsesOfValueWith(SDValue From, SDValue To)
SDValue getEntryNode() const
TRUNCATE - Completely drop the high bits.
static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth)
virtual void LowerOperationWrapper(SDNode *N, SmallVectorImpl< SDValue > &Results, SelectionDAG &DAG) const
unsigned getVectorNumElements() const