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.

llvm-svn: 97419
This commit is contained in:
Chris Lattner 2010-02-28 21:53:42 +00:00
parent 5610db6923
commit a838264af1
6 changed files with 43 additions and 33 deletions

View File

@ -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<EVT, 4> 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.

View File

@ -246,7 +246,8 @@ bool EmitNodeMatcherCommon::isEqualImpl(const Matcher *m) const {
const EmitNodeMatcherCommon *M = cast<EmitNodeMatcherCommon>(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;
}

View File

@ -876,7 +876,7 @@ class EmitNodeMatcherCommon : public Matcher {
std::string OpcodeName;
const SmallVector<MVT::SimpleValueType, 3> VTs;
const SmallVector<unsigned, 6> 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) {
}

View File

@ -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();

View File

@ -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));

View File

@ -92,7 +92,7 @@ static void ContractNodes(OwningPtr<Matcher> &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<Matcher> &MatcherPtr,
const SmallVectorImpl<MVT::SimpleValueType> &VTs = EN->getVTList();
const SmallVectorImpl<unsigned> &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));