change a few opcodes to use VBRs instead of embedding

immediate sizes into the opcode.

llvm-svn: 97423
This commit is contained in:
Chris Lattner 2010-02-28 22:14:32 +00:00
parent 34440d39ab
commit d49712e905
3 changed files with 44 additions and 142 deletions

View File

@ -167,11 +167,6 @@ bool CheckOrImmediate(SDValue V, int64_t Val) {
return true;
}
void EmitInteger(int64_t Val, MVT::SimpleValueType VT,
SmallVectorImpl<SDValue> &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
@ -186,28 +181,14 @@ GetInt2(const unsigned char *MatcherTable, unsigned &Idx) {
return Val;
}
ALWAYS_INLINE static int32_t
GetInt4(const unsigned char *MatcherTable, unsigned &Idx) {
int32_t Val = (uint16_t)GetInt2(MatcherTable, Idx);
Val |= int32_t(GetInt2(MatcherTable, Idx)) << 16;
return Val;
}
ALWAYS_INLINE static int64_t
GetInt8(const unsigned char *MatcherTable, unsigned &Idx) {
int64_t Val = (uint32_t)GetInt4(MatcherTable, Idx);
Val |= int64_t(GetInt4(MatcherTable, Idx)) << 32;
return Val;
}
/// GetVBR - decode a vbr encoding whose top bit is set.
ALWAYS_INLINE static unsigned
GetVBR(unsigned Val, const unsigned char *MatcherTable, unsigned &Idx) {
ALWAYS_INLINE static uint64_t
GetVBR(uint64_t Val, const unsigned char *MatcherTable, unsigned &Idx) {
assert(Val >= 128 && "Not a VBR");
Val &= 127; // Remove first vbr bit.
unsigned Shift = 7;
unsigned NextBits;
uint64_t NextBits;
do {
NextBits = GetInt1(MatcherTable, Idx);
Val |= (NextBits&127) << Shift;
@ -501,44 +482,27 @@ SDNode *SelectCodeCommon(SDNode *NodeToMatch, const unsigned char *MatcherTable,
}
continue;
}
case OPC_CheckInteger1:
if (CheckInteger(N, GetInt1(MatcherTable, MatcherIndex))) break;
case OPC_CheckInteger: {
int64_t Val = MatcherTable[MatcherIndex++];
if (Val & 128)
Val = GetVBR(Val, MatcherTable, MatcherIndex);
if (CheckInteger(N, Val)) break;
continue;
case OPC_CheckInteger2:
if (CheckInteger(N, GetInt2(MatcherTable, MatcherIndex))) break;
}
case OPC_CheckAndImm: {
int64_t Val = MatcherTable[MatcherIndex++];
if (Val & 128)
Val = GetVBR(Val, MatcherTable, MatcherIndex);
if (CheckAndImmediate(N, Val)) break;
continue;
case OPC_CheckInteger4:
if (CheckInteger(N, GetInt4(MatcherTable, MatcherIndex))) break;
continue;
case OPC_CheckInteger8:
if (CheckInteger(N, GetInt8(MatcherTable, MatcherIndex))) break;
continue;
case OPC_CheckAndImm1:
if (CheckAndImmediate(N, GetInt1(MatcherTable, MatcherIndex))) break;
continue;
case OPC_CheckAndImm2:
if (CheckAndImmediate(N, GetInt2(MatcherTable, MatcherIndex))) break;
continue;
case OPC_CheckAndImm4:
if (CheckAndImmediate(N, GetInt4(MatcherTable, MatcherIndex))) break;
continue;
case OPC_CheckAndImm8:
if (CheckAndImmediate(N, GetInt8(MatcherTable, MatcherIndex))) break;
continue;
case OPC_CheckOrImm1:
if (CheckOrImmediate(N, GetInt1(MatcherTable, MatcherIndex))) break;
continue;
case OPC_CheckOrImm2:
if (CheckOrImmediate(N, GetInt2(MatcherTable, MatcherIndex))) break;
continue;
case OPC_CheckOrImm4:
if (CheckOrImmediate(N, GetInt4(MatcherTable, MatcherIndex))) break;
continue;
case OPC_CheckOrImm8:
if (CheckOrImmediate(N, GetInt8(MatcherTable, MatcherIndex))) break;
}
case OPC_CheckOrImm: {
int64_t Val = MatcherTable[MatcherIndex++];
if (Val & 128)
Val = GetVBR(Val, MatcherTable, MatcherIndex);
if (CheckOrImmediate(N, Val)) break;
continue;
}
case OPC_CheckFoldableChainNode: {
assert(NodeStack.size() != 1 && "No parent node");
@ -581,31 +545,15 @@ SDNode *SelectCodeCommon(SDNode *NodeToMatch, const unsigned char *MatcherTable,
continue;
}
case OPC_EmitInteger1: {
case OPC_EmitInteger: {
MVT::SimpleValueType VT =
(MVT::SimpleValueType)MatcherTable[MatcherIndex++];
EmitInteger(GetInt1(MatcherTable, MatcherIndex), VT, RecordedNodes);
int64_t Val = MatcherTable[MatcherIndex++];
if (Val & 128)
Val = GetVBR(Val, MatcherTable, MatcherIndex);
RecordedNodes.push_back(CurDAG->getTargetConstant(Val, VT));
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;
}
case OPC_EmitRegister: {
MVT::SimpleValueType VT =
(MVT::SimpleValueType)MatcherTable[MatcherIndex++];

View File

@ -117,16 +117,15 @@ public:
OPC_CheckChild0Type, OPC_CheckChild1Type, OPC_CheckChild2Type,
OPC_CheckChild3Type, OPC_CheckChild4Type, OPC_CheckChild5Type,
OPC_CheckChild6Type, OPC_CheckChild7Type,
OPC_CheckInteger1, OPC_CheckInteger2, OPC_CheckInteger4, OPC_CheckInteger8,
OPC_CheckInteger,
OPC_CheckCondCode,
OPC_CheckValueType,
OPC_CheckComplexPat,
OPC_CheckAndImm1, OPC_CheckAndImm2, OPC_CheckAndImm4, OPC_CheckAndImm8,
OPC_CheckOrImm1, OPC_CheckOrImm2, OPC_CheckOrImm4, OPC_CheckOrImm8,
OPC_CheckAndImm, OPC_CheckOrImm,
OPC_CheckFoldableChainNode,
OPC_CheckChainCompatible,
OPC_EmitInteger1, OPC_EmitInteger2, OPC_EmitInteger4, OPC_EmitInteger8,
OPC_EmitInteger,
OPC_EmitRegister,
OPC_EmitConvertToTarget,
OPC_EmitMergeInputChains,

View File

@ -24,46 +24,6 @@ enum {
CommentIndent = 30
};
/// ClassifyInt - Classify an integer by size, return '1','2','4','8' if this
/// fits in 1, 2, 4, or 8 sign extended bytes.
static char ClassifyInt(int64_t Val) {
if (Val == int8_t(Val)) return '1';
if (Val == int16_t(Val)) return '2';
if (Val == int32_t(Val)) return '4';
return '8';
}
/// EmitInt - Emit the specified integer, returning the number of bytes emitted.
static unsigned EmitInt(int64_t Val, formatted_raw_ostream &OS) {
unsigned BytesEmitted = 1;
OS << (int)(unsigned char)Val << ", ";
if (Val == int8_t(Val)) {
OS << '\n';
return BytesEmitted;
}
OS << (int)(unsigned char)(Val >> 8) << ", ";
++BytesEmitted;
if (Val != int16_t(Val)) {
OS << (int)(unsigned char)(Val >> 16) << ", "
<< (int)(unsigned char)(Val >> 24) << ", ";
BytesEmitted += 2;
if (Val != int32_t(Val)) {
OS << (int)(unsigned char)(Val >> 32) << ", "
<< (int)(unsigned char)(Val >> 40) << ", "
<< (int)(unsigned char)(Val >> 48) << ", "
<< (int)(unsigned char)(Val >> 56) << ", ";
BytesEmitted += 4;
}
}
OS.PadToColumn(CommentIndent) << "// " << Val << " aka 0x";
OS.write_hex(Val) << '\n';
return BytesEmitted;
}
namespace {
class MatcherTableEmitter {
StringMap<unsigned> NodePredicateMap, PatternPredicateMap;
@ -142,13 +102,13 @@ static unsigned GetVBRSize(unsigned Val) {
/// EmitVBRValue - Emit the specified value as a VBR, returning the number of
/// bytes emitted.
static unsigned EmitVBRValue(unsigned Val, raw_ostream &OS) {
static uint64_t EmitVBRValue(uint64_t Val, raw_ostream &OS) {
if (Val <= 127) {
OS << Val << ", ";
return 1;
}
unsigned InVal = Val;
uint64_t InVal = Val;
unsigned NumBytes = 0;
while (Val >= 128) {
OS << (Val&127) << "|128,";
@ -291,11 +251,9 @@ EmitMatcher(const Matcher *N, unsigned Indent, unsigned CurrentIdx,
<< getEnumName(cast<CheckChildTypeMatcher>(N)->getType()) << ",\n";
return 2;
case Matcher::CheckInteger: {
int64_t Val = cast<CheckIntegerMatcher>(N)->getValue();
OS << "OPC_CheckInteger" << ClassifyInt(Val) << ", ";
return EmitInt(Val, OS)+1;
}
case Matcher::CheckInteger:
OS << "OPC_CheckInteger, ";
return 1+EmitVBRValue(cast<CheckIntegerMatcher>(N)->getValue(), OS);
case Matcher::CheckCondCode:
OS << "OPC_CheckCondCode, ISD::"
<< cast<CheckCondCodeMatcher>(N)->getCondCodeName() << ",\n";
@ -318,17 +276,14 @@ EmitMatcher(const Matcher *N, unsigned Indent, unsigned CurrentIdx,
return 2;
}
case Matcher::CheckAndImm: {
int64_t Val = cast<CheckAndImmMatcher>(N)->getValue();
OS << "OPC_CheckAndImm" << ClassifyInt(Val) << ", ";
return EmitInt(Val, OS)+1;
}
case Matcher::CheckAndImm:
OS << "OPC_CheckAndImm, ";
return 1+EmitVBRValue(cast<CheckAndImmMatcher>(N)->getValue(), OS);
case Matcher::CheckOrImm: {
int64_t Val = cast<CheckOrImmMatcher>(N)->getValue();
OS << "OPC_CheckOrImm" << ClassifyInt(Val) << ", ";
return EmitInt(Val, OS)+1;
}
case Matcher::CheckOrImm:
OS << "OPC_CheckOrImm, ";
return 1+EmitVBRValue(cast<CheckOrImmMatcher>(N)->getValue(), OS);
case Matcher::CheckFoldableChainNode:
OS << "OPC_CheckFoldableChainNode,\n";
return 1;
@ -339,14 +294,14 @@ EmitMatcher(const Matcher *N, unsigned Indent, unsigned CurrentIdx,
case Matcher::EmitInteger: {
int64_t Val = cast<EmitIntegerMatcher>(N)->getValue();
OS << "OPC_EmitInteger" << ClassifyInt(Val) << ", "
OS << "OPC_EmitInteger, "
<< getEnumName(cast<EmitIntegerMatcher>(N)->getVT()) << ", ";
return EmitInt(Val, OS)+2;
return 2+EmitVBRValue(Val, OS);
}
case Matcher::EmitStringInteger: {
const std::string &Val = cast<EmitStringIntegerMatcher>(N)->getValue();
// These should always fit into one byte.
OS << "OPC_EmitInteger1, "
OS << "OPC_EmitInteger, "
<< getEnumName(cast<EmitStringIntegerMatcher>(N)->getVT()) << ", "
<< Val << ",\n";
return 3;