From ff7fb60f2a7e2f3efd54df6480aadcb4adf5cab7 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 28 Feb 2010 21:53:42 +0000 Subject: [PATCH] enhance the EmitNode/MorphNodeTo operands to take a bit that specifies whether there is an output flag or not. Use this instead of redundantly encoding the chain/flag results in the output vtlist. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97419 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/DAGISelHeader.h | 33 ++++++++++++++---------- utils/TableGen/DAGISelMatcher.cpp | 3 ++- utils/TableGen/DAGISelMatcher.h | 24 ++++++++++------- utils/TableGen/DAGISelMatcherEmitter.cpp | 3 ++- utils/TableGen/DAGISelMatcherGen.cpp | 6 +---- utils/TableGen/DAGISelMatcherOpt.cpp | 7 ++--- 6 files changed, 43 insertions(+), 33 deletions(-) diff --git a/include/llvm/CodeGen/DAGISelHeader.h b/include/llvm/CodeGen/DAGISelHeader.h index 3ffc6e942cd..9aec982229a 100644 --- a/include/llvm/CodeGen/DAGISelHeader.h +++ b/include/llvm/CodeGen/DAGISelHeader.h @@ -303,17 +303,18 @@ enum BuiltinOpcodes { }; enum { - OPFL_None = 0, // Node has no chain or flag input and isn't variadic. - OPFL_Chain = 1, // Node has a chain input. - OPFL_Flag = 2, // Node has a flag input. - OPFL_MemRefs = 4, // Node gets accumulated MemRefs. - OPFL_Variadic0 = 1<<3, // Node is variadic, root has 0 fixed inputs. - OPFL_Variadic1 = 2<<3, // Node is variadic, root has 1 fixed inputs. - OPFL_Variadic2 = 3<<3, // Node is variadic, root has 2 fixed inputs. - OPFL_Variadic3 = 4<<3, // Node is variadic, root has 3 fixed inputs. - OPFL_Variadic4 = 5<<3, // Node is variadic, root has 4 fixed inputs. - OPFL_Variadic5 = 6<<3, // Node is variadic, root has 5 fixed inputs. - OPFL_Variadic6 = 7<<3, // Node is variadic, root has 6 fixed inputs. + OPFL_None = 0, // Node has no chain or flag input and isn't variadic. + OPFL_Chain = 1, // Node has a chain input. + OPFL_FlagInput = 2, // Node has a flag input. + OPFL_FlagOutput = 4, // Node has a flag output. + OPFL_MemRefs = 8, // Node gets accumulated MemRefs. + OPFL_Variadic0 = 1<<4, // Node is variadic, root has 0 fixed inputs. + OPFL_Variadic1 = 2<<4, // Node is variadic, root has 1 fixed inputs. + OPFL_Variadic2 = 3<<4, // Node is variadic, root has 2 fixed inputs. + OPFL_Variadic3 = 4<<4, // Node is variadic, root has 3 fixed inputs. + OPFL_Variadic4 = 5<<4, // Node is variadic, root has 4 fixed inputs. + OPFL_Variadic5 = 6<<4, // Node is variadic, root has 5 fixed inputs. + OPFL_Variadic6 = 7<<4, // Node is variadic, root has 6 fixed inputs. OPFL_VariadicInfo = OPFL_Variadic6 }; @@ -322,7 +323,7 @@ enum { /// number of fixed arity values that should be skipped when copying from the /// root. static inline int getNumFixedFromVariadicInfo(unsigned Flags) { - return ((Flags&OPFL_VariadicInfo) >> 3)-1; + return ((Flags&OPFL_VariadicInfo) >> 4)-1; } struct MatchScope { @@ -793,7 +794,6 @@ SDNode *SelectCodeCommon(SDNode *NodeToMatch, const unsigned char *MatcherTable, unsigned EmitNodeInfo = MatcherTable[MatcherIndex++]; // Get the result VT list. unsigned NumVTs = MatcherTable[MatcherIndex++]; - assert(NumVTs != 0 && "Invalid node result"); SmallVector VTs; for (unsigned i = 0; i != NumVTs; ++i) { MVT::SimpleValueType VT = @@ -802,6 +802,11 @@ SDNode *SelectCodeCommon(SDNode *NodeToMatch, const unsigned char *MatcherTable, VTs.push_back(VT); } + if (EmitNodeInfo & OPFL_Chain) + VTs.push_back(MVT::Other); + if (EmitNodeInfo & OPFL_FlagOutput) + VTs.push_back(MVT::Flag); + // FIXME: Use faster version for the common 'one VT' case? SDVTList VTList = CurDAG->getVTList(VTs.data(), VTs.size()); @@ -837,7 +842,7 @@ SDNode *SelectCodeCommon(SDNode *NodeToMatch, const unsigned char *MatcherTable, // If this has chain/flag inputs, add them. if (EmitNodeInfo & OPFL_Chain) Ops.push_back(InputChain); - if ((EmitNodeInfo & OPFL_Flag) && InputFlag.getNode() != 0) + if ((EmitNodeInfo & OPFL_FlagInput) && InputFlag.getNode() != 0) Ops.push_back(InputFlag); // Create the node. diff --git a/utils/TableGen/DAGISelMatcher.cpp b/utils/TableGen/DAGISelMatcher.cpp index 1f1bb60c37c..f1bfec0fc3e 100644 --- a/utils/TableGen/DAGISelMatcher.cpp +++ b/utils/TableGen/DAGISelMatcher.cpp @@ -246,7 +246,8 @@ bool EmitNodeMatcherCommon::isEqualImpl(const Matcher *m) const { const EmitNodeMatcherCommon *M = cast(m); return M->OpcodeName == OpcodeName && M->VTs == VTs && M->Operands == Operands && M->HasChain == HasChain && - M->HasFlag == HasFlag && M->HasMemRefs == HasMemRefs && + M->HasInFlag == HasInFlag && M->HasOutFlag == HasOutFlag && + M->HasMemRefs == HasMemRefs && M->NumFixedArityOperands == NumFixedArityOperands; } diff --git a/utils/TableGen/DAGISelMatcher.h b/utils/TableGen/DAGISelMatcher.h index 46652d912ec..d9c8b292212 100644 --- a/utils/TableGen/DAGISelMatcher.h +++ b/utils/TableGen/DAGISelMatcher.h @@ -876,7 +876,7 @@ class EmitNodeMatcherCommon : public Matcher { std::string OpcodeName; const SmallVector VTs; const SmallVector Operands; - bool HasChain, HasFlag, HasMemRefs; + bool HasChain, HasInFlag, HasOutFlag, HasMemRefs; /// NumFixedArityOperands - If this is a fixed arity node, this is set to -1. /// If this is a varidic node, this is set to the number of fixed arity @@ -886,12 +886,13 @@ public: EmitNodeMatcherCommon(const std::string &opcodeName, const MVT::SimpleValueType *vts, unsigned numvts, const unsigned *operands, unsigned numops, - bool hasChain, bool hasFlag, bool hasmemrefs, + bool hasChain, bool hasInFlag, bool hasOutFlag, + bool hasmemrefs, int numfixedarityoperands, bool isMorphNodeTo) : Matcher(isMorphNodeTo ? MorphNodeTo : EmitNode), OpcodeName(opcodeName), VTs(vts, vts+numvts), Operands(operands, operands+numops), - HasChain(hasChain), HasFlag(hasFlag), HasMemRefs(hasmemrefs), - NumFixedArityOperands(numfixedarityoperands) {} + HasChain(hasChain), HasInFlag(hasInFlag), HasOutFlag(hasOutFlag), + HasMemRefs(hasmemrefs), NumFixedArityOperands(numfixedarityoperands) {} const std::string &getOpcodeName() const { return OpcodeName; } @@ -921,7 +922,8 @@ public: bool hasChain() const { return HasChain; } - bool hasFlag() const { return HasFlag; } + bool hasInFlag() const { return HasInFlag; } + bool hasOutFlag() const { return HasOutFlag; } bool hasMemRefs() const { return HasMemRefs; } int getNumFixedArityOperands() const { return NumFixedArityOperands; } @@ -942,10 +944,12 @@ public: EmitNodeMatcher(const std::string &opcodeName, const MVT::SimpleValueType *vts, unsigned numvts, const unsigned *operands, unsigned numops, - bool hasChain, bool hasFlag, bool hasmemrefs, + bool hasChain, bool hasInFlag, bool hasOutFlag, + bool hasmemrefs, int numfixedarityoperands, unsigned firstresultslot) : EmitNodeMatcherCommon(opcodeName, vts, numvts, operands, numops, hasChain, - hasFlag, hasmemrefs, numfixedarityoperands, false), + hasInFlag, hasOutFlag, hasmemrefs, + numfixedarityoperands, false), FirstResultSlot(firstresultslot) {} unsigned getFirstResultSlot() const { return FirstResultSlot; } @@ -962,10 +966,12 @@ public: MorphNodeToMatcher(const std::string &opcodeName, const MVT::SimpleValueType *vts, unsigned numvts, const unsigned *operands, unsigned numops, - bool hasChain, bool hasFlag, bool hasmemrefs, + bool hasChain, bool hasInFlag, bool hasOutFlag, + bool hasmemrefs, int numfixedarityoperands, const PatternToMatch &pattern) : EmitNodeMatcherCommon(opcodeName, vts, numvts, operands, numops, hasChain, - hasFlag, hasmemrefs, numfixedarityoperands, true), + hasInFlag, hasOutFlag, hasmemrefs, + numfixedarityoperands, true), Pattern(pattern) { } diff --git a/utils/TableGen/DAGISelMatcherEmitter.cpp b/utils/TableGen/DAGISelMatcherEmitter.cpp index c4c005cb1d0..c6addd8b0db 100644 --- a/utils/TableGen/DAGISelMatcherEmitter.cpp +++ b/utils/TableGen/DAGISelMatcherEmitter.cpp @@ -396,7 +396,8 @@ EmitMatcher(const Matcher *N, unsigned Indent, unsigned CurrentIdx, OS << ", TARGET_OPCODE(" << EN->getOpcodeName() << "), 0"; if (EN->hasChain()) OS << "|OPFL_Chain"; - if (EN->hasFlag()) OS << "|OPFL_Flag"; + if (EN->hasInFlag()) OS << "|OPFL_FlagInput"; + if (EN->hasOutFlag()) OS << "|OPFL_FlagOutput"; if (EN->hasMemRefs()) OS << "|OPFL_MemRefs"; if (EN->getNumFixedArityOperands() != -1) OS << "|OPFL_Variadic" << EN->getNumFixedArityOperands(); diff --git a/utils/TableGen/DAGISelMatcherGen.cpp b/utils/TableGen/DAGISelMatcherGen.cpp index c558eba9fd5..8f8fcf7cfb9 100644 --- a/utils/TableGen/DAGISelMatcherGen.cpp +++ b/utils/TableGen/DAGISelMatcherGen.cpp @@ -713,10 +713,6 @@ EmitResultInstructionAsOperand(const TreePatternNode *N, if (Pattern.getDstRegs()[i]->isSubClassOf("Register")) ResultVTs.push_back(getRegisterValueType(Pattern.getDstRegs()[i], CGT)); } - if (NodeHasChain) - ResultVTs.push_back(MVT::Other); - if (TreeHasOutFlag) - ResultVTs.push_back(MVT::Flag); // FIXME2: Instead of using the isVariadic flag on the instruction, we should // have an SDNP that indicates variadicism. The TargetInstrInfo isVariadic @@ -744,7 +740,7 @@ EmitResultInstructionAsOperand(const TreePatternNode *N, AddMatcher(new EmitNodeMatcher(II.Namespace+"::"+II.TheDef->getName(), ResultVTs.data(), ResultVTs.size(), InstOps.data(), InstOps.size(), - NodeHasChain, TreeHasInFlag, + NodeHasChain, TreeHasInFlag, TreeHasOutFlag, NodeHasMemRefs, NumFixedArityOperands, NextRecordedOperandNo)); diff --git a/utils/TableGen/DAGISelMatcherOpt.cpp b/utils/TableGen/DAGISelMatcherOpt.cpp index 65a01fa6b9a..01723d3ec84 100644 --- a/utils/TableGen/DAGISelMatcherOpt.cpp +++ b/utils/TableGen/DAGISelMatcherOpt.cpp @@ -92,7 +92,7 @@ static void ContractNodes(OwningPtr &MatcherPtr, // 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 // do it anyway for thoroughness. - if (!EN->hasFlag() && + if (!EN->hasOutFlag() && Pattern.getSrcPattern()->NodeHasProperty(SDNPOutFlag, CGP)) ResultsMatch = false; @@ -110,9 +110,10 @@ static void ContractNodes(OwningPtr &MatcherPtr, const SmallVectorImpl &VTs = EN->getVTList(); const SmallVectorImpl &Operands = EN->getOperandList(); MatcherPtr.reset(new MorphNodeToMatcher(EN->getOpcodeName(), - &VTs[0], VTs.size(), + VTs.data(), VTs.size(), Operands.data(),Operands.size(), - EN->hasChain(), EN->hasFlag(), + EN->hasChain(), EN->hasInFlag(), + EN->hasOutFlag(), EN->hasMemRefs(), EN->getNumFixedArityOperands(), Pattern)); -- 2.34.1