From 906b4995eeab9e6b6fd11a492498c95bba1ce0af Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 19 Feb 2010 07:49:56 +0000 Subject: [PATCH] add emitter support for integer constants and simple physreg references. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96663 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/DAGISelHeader.h | 43 +++++++++++++++++++++++- utils/TableGen/DAGISelMatcher.h | 2 +- utils/TableGen/DAGISelMatcherEmitter.cpp | 17 ++++++++-- 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/include/llvm/CodeGen/DAGISelHeader.h b/include/llvm/CodeGen/DAGISelHeader.h index fd0c4f1f857..1514dbaa702 100644 --- a/include/llvm/CodeGen/DAGISelHeader.h +++ b/include/llvm/CodeGen/DAGISelHeader.h @@ -172,6 +172,11 @@ bool CheckOrImmediate(SDValue V, int64_t Val) { return true; } +void EmitInteger(int64_t Val, MVT::SimpleValueType VT, + SmallVectorImpl &RecordedNodes) { + RecordedNodes.push_back(CurDAG->getTargetConstant(Val, VT)); +} + // These functions are marked always inline so that Idx doesn't get pinned to // the stack. ALWAYS_INLINE static int8_t @@ -218,7 +223,10 @@ enum BuiltinOpcodes { OPC_CheckAndImm1, OPC_CheckAndImm2, OPC_CheckAndImm4, OPC_CheckAndImm8, OPC_CheckOrImm1, OPC_CheckOrImm2, OPC_CheckOrImm4, OPC_CheckOrImm8, OPC_CheckFoldableChainNode, - OPC_CheckChainCompatible + OPC_CheckChainCompatible, + + OPC_EmitInteger1, OPC_EmitInteger2, OPC_EmitInteger4, OPC_EmitInteger8, + OPC_EmitRegister }; struct MatchScope { @@ -417,6 +425,39 @@ SDNode *SelectCodeCommon(SDNode *NodeToMatch, const unsigned char *MatcherTable, break; continue; } + + case OPC_EmitRegister: { + unsigned RegNo = MatcherTable[MatcherIndex++]; + MVT::SimpleValueType VT = + (MVT::SimpleValueType)MatcherTable[MatcherIndex++]; + SDValue Reg = CurDAG->getRegister(RegNo, VT); + RecordedNodes.push_back(N); + continue; + } + case OPC_EmitInteger1: { + MVT::SimpleValueType VT = + (MVT::SimpleValueType)MatcherTable[MatcherIndex++]; + EmitInteger(GetInt1(MatcherTable, MatcherIndex), VT, RecordedNodes); + continue; + } + case OPC_EmitInteger2: { + MVT::SimpleValueType VT = + (MVT::SimpleValueType)MatcherTable[MatcherIndex++]; + EmitInteger(GetInt2(MatcherTable, MatcherIndex), VT, RecordedNodes); + continue; + } + case OPC_EmitInteger4: { + MVT::SimpleValueType VT = + (MVT::SimpleValueType)MatcherTable[MatcherIndex++]; + EmitInteger(GetInt4(MatcherTable, MatcherIndex), VT, RecordedNodes); + continue; + } + case OPC_EmitInteger8: { + MVT::SimpleValueType VT = + (MVT::SimpleValueType)MatcherTable[MatcherIndex++]; + EmitInteger(GetInt8(MatcherTable, MatcherIndex), VT, RecordedNodes); + continue; + } } // If the code reached this point, then the match failed pop out to the next diff --git a/utils/TableGen/DAGISelMatcher.h b/utils/TableGen/DAGISelMatcher.h index 7b6fbdb8bf5..0d5825639d0 100644 --- a/utils/TableGen/DAGISelMatcher.h +++ b/utils/TableGen/DAGISelMatcher.h @@ -386,7 +386,7 @@ public: EmitIntegerMatcherNode(int64_t val, MVT::SimpleValueType vt) : MatcherNode(EmitInteger), Val(val), VT(vt) {} - int64_t getVal() const { return Val; } + int64_t getValue() const { return Val; } MVT::SimpleValueType getVT() const { return VT; } static inline bool classof(const MatcherNode *N) { diff --git a/utils/TableGen/DAGISelMatcherEmitter.cpp b/utils/TableGen/DAGISelMatcherEmitter.cpp index 92b2a55e9b7..4b16db309b2 100644 --- a/utils/TableGen/DAGISelMatcherEmitter.cpp +++ b/utils/TableGen/DAGISelMatcherEmitter.cpp @@ -213,10 +213,21 @@ EmitMatcher(const MatcherNode *N, unsigned Indent) { << cast(N)->getPreviousOp() << ",\n"; return 2; - case MatcherNode::EmitInteger: + case MatcherNode::EmitInteger: { + int64_t Val = cast(N)->getValue(); + OS << "OPC_EmitInteger" << ClassifyInt(Val) << ", " + << getEnumName(cast(N)->getVT()) << ", "; + return EmitInt(Val, OS)+2; + } + case MatcherNode::EmitRegister: - // FIXME: Implement. - return 0; + OS << "OPC_EmitRegister, " + << getEnumName(cast(N)->getVT()) << ", "; + if (Record *R = cast(N)->getReg()) + OS << getQualifiedName(R) << ",\n"; + else + OS << "0 /*zero_reg*/,\n"; + return 3; } assert(0 && "Unreachable"); return 0;