Skip to content

Commit 4b9bbd3

Browse files
committed
[X86][NFC] Refine code in X86CompressEVEXTablesEmitter.cpp
1. Simplify getValueFromBitsInit about cast and return type 2. Remove out-of-date comments and allow memory ops in function object `IsMatch` so that we can reuse it for EVEX2Legacy compression. This patch is to extract NFC in llvm#77065 into a separate commit.
1 parent 3fb0d8d commit 4b9bbd3

File tree

1 file changed

+23
-31
lines changed

1 file changed

+23
-31
lines changed

llvm/utils/TableGen/X86CompressEVEXTablesEmitter.cpp

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,14 @@ void X86CompressEVEXTablesEmitter::printTable(const std::vector<Entry> &Table,
7373
OS << "};\n\n";
7474
}
7575

76-
// Return true if the 2 BitsInits are equal
77-
// Calculates the integer value residing BitsInit object
78-
static inline uint64_t getValueFromBitsInit(const BitsInit *B) {
79-
uint64_t Value = 0;
80-
for (unsigned i = 0, e = B->getNumBits(); i != e; ++i) {
81-
if (BitInit *Bit = dyn_cast<BitInit>(B->getBit(i)))
82-
Value |= uint64_t(Bit->getValue()) << i;
83-
else
84-
PrintFatalError("Invalid VectSize bit");
76+
static uint8_t byteFromBitsInit(const BitsInit *B) {
77+
unsigned N = B->getNumBits();
78+
assert(N <= 8 && "Field is too large for uint8_t!");
79+
80+
uint8_t Value = 0;
81+
for (unsigned I = 0; I != N; ++I) {
82+
BitInit *Bit = cast<BitInit>(B->getBit(I));
83+
Value |= Bit->getValue() << I;
8584
}
8685
return Value;
8786
}
@@ -105,30 +104,23 @@ class IsMatch {
105104
NewRI.Form))
106105
return false;
107106

108-
// This is needed for instructions with intrinsic version (_Int).
109-
// Where the only difference is the size of the operands.
110-
// For example: VUCOMISDZrm and Int_VUCOMISDrm
111-
// Also for instructions that their EVEX version was upgraded to work with
112-
// k-registers. For example VPCMPEQBrm (xmm output register) and
113-
// VPCMPEQBZ128rm (k register output register).
114-
for (unsigned i = 0, e = OldInst->Operands.size(); i < e; i++) {
115-
Record *OpRec1 = OldInst->Operands[i].Rec;
116-
Record *OpRec2 = NewInst->Operands[i].Rec;
117-
118-
if (OpRec1 == OpRec2)
107+
for (unsigned I = 0, E = OldInst->Operands.size(); I < E; ++I) {
108+
Record *OldOpRec = OldInst->Operands[I].Rec;
109+
Record *NewOpRec = NewInst->Operands[I].Rec;
110+
111+
if (OldOpRec == NewOpRec)
119112
continue;
120113

121-
if (isRegisterOperand(OpRec1) && isRegisterOperand(OpRec2)) {
122-
if (getRegOperandSize(OpRec1) != getRegOperandSize(OpRec2))
114+
if (isRegisterOperand(OldOpRec) && isRegisterOperand(NewOpRec)) {
115+
if (getRegOperandSize(OldOpRec) != getRegOperandSize(NewOpRec))
116+
return false;
117+
} else if (isMemoryOperand(OldOpRec) && isMemoryOperand(NewOpRec)) {
118+
if (getMemOperandSize(OldOpRec) != getMemOperandSize(NewOpRec))
123119
return false;
124-
} else if (isMemoryOperand(OpRec1) && isMemoryOperand(OpRec2)) {
125-
return false;
126-
} else if (isImmediateOperand(OpRec1) && isImmediateOperand(OpRec2)) {
127-
if (OpRec1->getValueAsDef("Type") != OpRec2->getValueAsDef("Type")) {
120+
} else if (isImmediateOperand(OldOpRec) && isImmediateOperand(NewOpRec)) {
121+
if (OldOpRec->getValueAsDef("Type") != NewOpRec->getValueAsDef("Type"))
128122
return false;
129-
}
130-
} else
131-
return false;
123+
}
132124
}
133125

134126
return true;
@@ -164,8 +156,8 @@ void X86CompressEVEXTablesEmitter::run(raw_ostream &OS) {
164156

165157
for (const CodeGenInstruction *Inst : PreCompressionInsts) {
166158
const Record *Rec = Inst->TheDef;
167-
uint64_t Opcode =
168-
getValueFromBitsInit(Inst->TheDef->getValueAsBitsInit("Opcode"));
159+
uint8_t Opcode =
160+
byteFromBitsInit(Inst->TheDef->getValueAsBitsInit("Opcode"));
169161
const CodeGenInstruction *NewInst = nullptr;
170162
if (ManualMap.find(Rec->getName()) != ManualMap.end()) {
171163
Record *NewRec = Records.getDef(ManualMap.at(Rec->getName()));

0 commit comments

Comments
 (0)