use MorphNodeTo instead of SelectNodeTo. SelectNodeTo

is just a silly wrapper around MorphNodeTo.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97416 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2010-02-28 20:55:18 +00:00
parent c78f2a3994
commit 9a21500edc
5 changed files with 46 additions and 43 deletions

View File

@ -223,7 +223,7 @@ void UpdateChainsAndFlags(SDNode *NodeToMatch, SDValue InputChain,
const SmallVectorImpl<SDNode*> &ChainNodesMatched, const SmallVectorImpl<SDNode*> &ChainNodesMatched,
SDValue InputFlag, SDValue InputFlag,
const SmallVectorImpl<SDNode*>&FlagResultNodesMatched, const SmallVectorImpl<SDNode*>&FlagResultNodesMatched,
bool isSelectNodeTo) { bool isMorphNodeTo) {
// Now that all the normal results are replaced, we replace the chain and // Now that all the normal results are replaced, we replace the chain and
// flag results if present. // flag results if present.
if (!ChainNodesMatched.empty()) { if (!ChainNodesMatched.empty()) {
@ -235,8 +235,8 @@ void UpdateChainsAndFlags(SDNode *NodeToMatch, SDValue InputChain,
SDNode *ChainNode = ChainNodesMatched[i]; SDNode *ChainNode = ChainNodesMatched[i];
// Don't replace the results of the root node if we're doing a // Don't replace the results of the root node if we're doing a
// SelectNodeTo. // MorphNodeTo.
if (ChainNode == NodeToMatch && isSelectNodeTo) if (ChainNode == NodeToMatch && isMorphNodeTo)
continue; continue;
SDValue ChainVal = SDValue(ChainNode, ChainNode->getNumValues()-1); SDValue ChainVal = SDValue(ChainNode, ChainNode->getNumValues()-1);
@ -297,7 +297,7 @@ enum BuiltinOpcodes {
OPC_EmitCopyToReg, OPC_EmitCopyToReg,
OPC_EmitNodeXForm, OPC_EmitNodeXForm,
OPC_EmitNode, OPC_EmitNode,
OPC_SelectNodeTo, OPC_MorphNodeTo,
OPC_MarkFlagResults, OPC_MarkFlagResults,
OPC_CompleteMatch OPC_CompleteMatch
}; };
@ -788,7 +788,7 @@ SDNode *SelectCodeCommon(SDNode *NodeToMatch, const unsigned char *MatcherTable,
} }
case OPC_EmitNode: case OPC_EmitNode:
case OPC_SelectNodeTo: { case OPC_MorphNodeTo: {
uint16_t TargetOpc = GetInt2(MatcherTable, MatcherIndex); uint16_t TargetOpc = GetInt2(MatcherTable, MatcherIndex);
unsigned EmitNodeInfo = MatcherTable[MatcherIndex++]; unsigned EmitNodeInfo = MatcherTable[MatcherIndex++];
// Get the result VT list. // Get the result VT list.
@ -842,13 +842,13 @@ SDNode *SelectCodeCommon(SDNode *NodeToMatch, const unsigned char *MatcherTable,
// Create the node. // Create the node.
SDNode *Res = 0; SDNode *Res = 0;
if (Opcode == OPC_SelectNodeTo) { if (Opcode == OPC_MorphNodeTo) {
// It is possible we're using SelectNodeTo to replace a node with no // It is possible we're using MorphNodeTo to replace a node with no
// normal results with one that has a normal result (or we could be // normal results with one that has a normal result (or we could be
// adding a chain) and the input could have flags and chains as well. // adding a chain) and the input could have flags and chains as well.
// In this case we need to shifting the operands down. // In this case we need to shifting the operands down.
// FIXME: This is a horrible hack and broken in obscure cases, no worse // FIXME: This is a horrible hack and broken in obscure cases, no worse
// than the old isel though. We should sink this into SelectNodeTo. // than the old isel though. We should sink this into MorphNodeTo.
int OldFlagResultNo = -1, OldChainResultNo = -1; int OldFlagResultNo = -1, OldChainResultNo = -1;
unsigned NTMNumResults = NodeToMatch->getNumValues(); unsigned NTMNumResults = NodeToMatch->getNumValues();
@ -860,8 +860,11 @@ SDNode *SelectCodeCommon(SDNode *NodeToMatch, const unsigned char *MatcherTable,
} else if (NodeToMatch->getValueType(NTMNumResults-1) == MVT::Other) } else if (NodeToMatch->getValueType(NTMNumResults-1) == MVT::Other)
OldChainResultNo = NTMNumResults-1; OldChainResultNo = NTMNumResults-1;
Res = CurDAG->SelectNodeTo(NodeToMatch, TargetOpc, VTList, Res = CurDAG->MorphNodeTo(NodeToMatch, ~TargetOpc, VTList,
Ops.data(), Ops.size()); Ops.data(), Ops.size());
// Reset the node ID, to the isel, this should be just like a newly
// allocated machine node.
Res->setNodeId(-1);
// FIXME: Whether the selected node has a flag result should come from // FIXME: Whether the selected node has a flag result should come from
// flags on the node. // flags on the node.
@ -915,11 +918,11 @@ SDNode *SelectCodeCommon(SDNode *NodeToMatch, const unsigned char *MatcherTable,
} }
DEBUG(errs() << " " DEBUG(errs() << " "
<< (Opcode == OPC_SelectNodeTo ? "Selected" : "Created") << (Opcode == OPC_MorphNodeTo ? "Morphed" : "Created")
<< " node: "; Res->dump(CurDAG); errs() << "\n"); << " node: "; Res->dump(CurDAG); errs() << "\n");
// If this was a SelectNodeTo then we're completely done! // If this was a MorphNodeTo then we're completely done!
if (Opcode == OPC_SelectNodeTo) { if (Opcode == OPC_MorphNodeTo) {
// Update chain and flag uses. // Update chain and flag uses.
UpdateChainsAndFlags(NodeToMatch, InputChain, ChainNodesMatched, UpdateChainsAndFlags(NodeToMatch, InputChain, ChainNodesMatched,
InputFlag, FlagResultNodesMatched, true); InputFlag, FlagResultNodesMatched, true);

View File

@ -176,7 +176,7 @@ void EmitNodeXFormMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
void EmitNodeMatcherCommon::printImpl(raw_ostream &OS, unsigned indent) const { void EmitNodeMatcherCommon::printImpl(raw_ostream &OS, unsigned indent) const {
OS.indent(indent); OS.indent(indent);
OS << (isa<SelectNodeToMatcher>(this) ? "SelectNodeTo: " : "EmitNode: ") OS << (isa<MorphNodeToMatcher>(this) ? "MorphNodeTo: " : "EmitNode: ")
<< OpcodeName << ": <todo flags> "; << OpcodeName << ": <todo flags> ";
for (unsigned i = 0, e = VTs.size(); i != e; ++i) for (unsigned i = 0, e = VTs.size(); i != e; ++i)

View File

@ -76,7 +76,7 @@ public:
EmitNodeXForm, // Run a SDNodeXForm EmitNodeXForm, // Run a SDNodeXForm
MarkFlagResults, // Indicate which interior nodes have flag results. MarkFlagResults, // Indicate which interior nodes have flag results.
CompleteMatch, // Finish a match and update the results. CompleteMatch, // Finish a match and update the results.
SelectNodeTo // Build a node, finish a match and update results. MorphNodeTo // Build a node, finish a match and update results.
}; };
const KindTy Kind; const KindTy Kind;
@ -871,7 +871,7 @@ private:
}; };
/// EmitNodeMatcherCommon - Common class shared between EmitNode and /// EmitNodeMatcherCommon - Common class shared between EmitNode and
/// SelectNodeTo. /// MorphNodeTo.
class EmitNodeMatcherCommon : public Matcher { class EmitNodeMatcherCommon : public Matcher {
std::string OpcodeName; std::string OpcodeName;
const SmallVector<MVT::SimpleValueType, 3> VTs; const SmallVector<MVT::SimpleValueType, 3> VTs;
@ -887,8 +887,8 @@ public:
const MVT::SimpleValueType *vts, unsigned numvts, const MVT::SimpleValueType *vts, unsigned numvts,
const unsigned *operands, unsigned numops, const unsigned *operands, unsigned numops,
bool hasChain, bool hasFlag, bool hasmemrefs, bool hasChain, bool hasFlag, bool hasmemrefs,
int numfixedarityoperands, bool isSelectNodeTo) int numfixedarityoperands, bool isMorphNodeTo)
: Matcher(isSelectNodeTo ? SelectNodeTo : EmitNode), OpcodeName(opcodeName), : Matcher(isMorphNodeTo ? MorphNodeTo : EmitNode), OpcodeName(opcodeName),
VTs(vts, vts+numvts), Operands(operands, operands+numops), VTs(vts, vts+numvts), Operands(operands, operands+numops),
HasChain(hasChain), HasFlag(hasFlag), HasMemRefs(hasmemrefs), HasChain(hasChain), HasFlag(hasFlag), HasMemRefs(hasmemrefs),
NumFixedArityOperands(numfixedarityoperands) {} NumFixedArityOperands(numfixedarityoperands) {}
@ -926,7 +926,7 @@ public:
int getNumFixedArityOperands() const { return NumFixedArityOperands; } int getNumFixedArityOperands() const { return NumFixedArityOperands; }
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == EmitNode || N->getKind() == SelectNodeTo; return N->getKind() == EmitNode || N->getKind() == MorphNodeTo;
} }
private: private:
@ -956,14 +956,14 @@ public:
}; };
class SelectNodeToMatcher : public EmitNodeMatcherCommon { class MorphNodeToMatcher : public EmitNodeMatcherCommon {
const PatternToMatch &Pattern; const PatternToMatch &Pattern;
public: public:
SelectNodeToMatcher(const std::string &opcodeName, MorphNodeToMatcher(const std::string &opcodeName,
const MVT::SimpleValueType *vts, unsigned numvts, const MVT::SimpleValueType *vts, unsigned numvts,
const unsigned *operands, unsigned numops, const unsigned *operands, unsigned numops,
bool hasChain, bool hasFlag, bool hasmemrefs, bool hasChain, bool hasFlag, bool hasmemrefs,
int numfixedarityoperands, const PatternToMatch &pattern) int numfixedarityoperands, const PatternToMatch &pattern)
: EmitNodeMatcherCommon(opcodeName, vts, numvts, operands, numops, hasChain, : EmitNodeMatcherCommon(opcodeName, vts, numvts, operands, numops, hasChain,
hasFlag, hasmemrefs, numfixedarityoperands, true), hasFlag, hasmemrefs, numfixedarityoperands, true),
Pattern(pattern) { Pattern(pattern) {
@ -972,7 +972,7 @@ public:
const PatternToMatch &getPattern() const { return Pattern; } const PatternToMatch &getPattern() const { return Pattern; }
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == SelectNodeTo; return N->getKind() == MorphNodeTo;
} }
}; };

View File

@ -390,9 +390,9 @@ EmitMatcher(const Matcher *N, unsigned Indent, unsigned CurrentIdx,
} }
case Matcher::EmitNode: case Matcher::EmitNode:
case Matcher::SelectNodeTo: { case Matcher::MorphNodeTo: {
const EmitNodeMatcherCommon *EN = cast<EmitNodeMatcherCommon>(N); const EmitNodeMatcherCommon *EN = cast<EmitNodeMatcherCommon>(N);
OS << (isa<EmitNodeMatcher>(EN) ? "OPC_EmitNode" : "OPC_SelectNodeTo"); OS << (isa<EmitNodeMatcher>(EN) ? "OPC_EmitNode" : "OPC_MorphNodeTo");
OS << ", TARGET_OPCODE(" << EN->getOpcodeName() << "), 0"; OS << ", TARGET_OPCODE(" << EN->getOpcodeName() << "), 0";
if (EN->hasChain()) OS << "|OPFL_Chain"; if (EN->hasChain()) OS << "|OPFL_Chain";
@ -425,7 +425,7 @@ EmitMatcher(const Matcher *N, unsigned Indent, unsigned CurrentIdx,
} }
OS << '\n'; OS << '\n';
if (const SelectNodeToMatcher *SNT = dyn_cast<SelectNodeToMatcher>(N)) { if (const MorphNodeToMatcher *SNT = dyn_cast<MorphNodeToMatcher>(N)) {
OS.PadToColumn(Indent*2) << "// Src: " OS.PadToColumn(Indent*2) << "// Src: "
<< *SNT->getPattern().getSrcPattern() << '\n'; << *SNT->getPattern().getSrcPattern() << '\n';
OS.PadToColumn(Indent*2) << "// Dst: " OS.PadToColumn(Indent*2) << "// Dst: "
@ -585,7 +585,7 @@ void MatcherTableEmitter::EmitHistogram(formatted_raw_ostream &OS) {
case Matcher::EmitMergeInputChains: OS << "OPC_EmitMergeInputChains"; break; case Matcher::EmitMergeInputChains: OS << "OPC_EmitMergeInputChains"; break;
case Matcher::EmitCopyToReg: OS << "OPC_EmitCopyToReg"; break; case Matcher::EmitCopyToReg: OS << "OPC_EmitCopyToReg"; break;
case Matcher::EmitNode: OS << "OPC_EmitNode"; break; case Matcher::EmitNode: OS << "OPC_EmitNode"; break;
case Matcher::SelectNodeTo: OS << "OPC_SelectNodeTo"; break; case Matcher::MorphNodeTo: OS << "OPC_MorphNodeTo"; break;
case Matcher::EmitNodeXForm: OS << "OPC_EmitNodeXForm"; break; case Matcher::EmitNodeXForm: OS << "OPC_EmitNodeXForm"; break;
case Matcher::MarkFlagResults: OS << "OPC_MarkFlagResults"; break; case Matcher::MarkFlagResults: OS << "OPC_MarkFlagResults"; break;
case Matcher::CompleteMatch: OS << "OPC_CompleteMatch"; break; case Matcher::CompleteMatch: OS << "OPC_CompleteMatch"; break;

View File

@ -66,11 +66,11 @@ static void ContractNodes(OwningPtr<Matcher> &MatcherPtr,
return ContractNodes(MatcherPtr, CGP); return ContractNodes(MatcherPtr, CGP);
} }
// Turn EmitNode->CompleteMatch into SelectNodeTo if we can. // Turn EmitNode->CompleteMatch into MorphNodeTo if we can.
if (EmitNodeMatcher *EN = dyn_cast<EmitNodeMatcher>(N)) if (EmitNodeMatcher *EN = dyn_cast<EmitNodeMatcher>(N))
if (CompleteMatchMatcher *CM = if (CompleteMatchMatcher *CM =
dyn_cast<CompleteMatchMatcher>(EN->getNext())) { dyn_cast<CompleteMatchMatcher>(EN->getNext())) {
// We can only use SelectNodeTo if the result values match up. // We can only use MorphNodeTo if the result values match up.
unsigned RootResultFirst = EN->getFirstResultSlot(); unsigned RootResultFirst = EN->getFirstResultSlot();
bool ResultsMatch = true; bool ResultsMatch = true;
for (unsigned i = 0, e = CM->getNumResults(); i != e; ++i) for (unsigned i = 0, e = CM->getNumResults(); i != e; ++i)
@ -78,7 +78,7 @@ static void ContractNodes(OwningPtr<Matcher> &MatcherPtr,
ResultsMatch = false; ResultsMatch = false;
// If the selected node defines a subset of the flag/chain results, we // If the selected node defines a subset of the flag/chain results, we
// can't use SelectNodeTo. For example, we can't use SelectNodeTo if the // can't use MorphNodeTo. For example, we can't use MorphNodeTo if the
// matched pattern has a chain but the root node doesn't. // matched pattern has a chain but the root node doesn't.
const PatternToMatch &Pattern = CM->getPattern(); const PatternToMatch &Pattern = CM->getPattern();
@ -87,7 +87,7 @@ static void ContractNodes(OwningPtr<Matcher> &MatcherPtr,
ResultsMatch = false; ResultsMatch = false;
// If the matched node has a flag and the output root doesn't, we can't // If the matched node has a flag and the output root doesn't, we can't
// use SelectNodeTo. // use MorphNodeTo.
// //
// NOTE: Strictly speaking, we don't have to check for the flag here // NOTE: Strictly speaking, we don't have to check for the flag here
// because the code in the pattern generator doesn't handle it right. We // because the code in the pattern generator doesn't handle it right. We
@ -109,20 +109,20 @@ static void ContractNodes(OwningPtr<Matcher> &MatcherPtr,
if (ResultsMatch) { if (ResultsMatch) {
const SmallVectorImpl<MVT::SimpleValueType> &VTs = EN->getVTList(); const SmallVectorImpl<MVT::SimpleValueType> &VTs = EN->getVTList();
const SmallVectorImpl<unsigned> &Operands = EN->getOperandList(); const SmallVectorImpl<unsigned> &Operands = EN->getOperandList();
MatcherPtr.reset(new SelectNodeToMatcher(EN->getOpcodeName(), MatcherPtr.reset(new MorphNodeToMatcher(EN->getOpcodeName(),
&VTs[0], VTs.size(), &VTs[0], VTs.size(),
Operands.data(), Operands.size(), Operands.data(),Operands.size(),
EN->hasChain(), EN->hasFlag(), EN->hasChain(), EN->hasFlag(),
EN->hasMemRefs(), EN->hasMemRefs(),
EN->getNumFixedArityOperands(), EN->getNumFixedArityOperands(),
Pattern)); Pattern));
return; return;
} }
// FIXME: Handle OPC_MarkFlagResults. // FIXME: Handle OPC_MarkFlagResults.
// FIXME2: Kill off all the SelectionDAG::SelectNodeTo and getMachineNode // FIXME2: Kill off all the SelectionDAG::MorphNodeTo and getMachineNode
// variants. Call MorphNodeTo instead of SelectNodeTo. // variants.
} }
ContractNodes(N->getNextPtr(), CGP); ContractNodes(N->getNextPtr(), CGP);