Skip to content

Commit d9517fb

Browse files
committed
[SelectionDAG] Add space-optimized forms of OPC_EmitCopyToReg
These new opcodes implicitly indicate the RecNo. The old `OPC_EmitCopyToReg2` is renamed to `OPC_EmitCopyToRegHalf`. Overall this reduces the llc binary size with all in-tree targets by about 33K (most are from RISCV target).
1 parent 19918ac commit d9517fb

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

llvm/include/llvm/CodeGen/SelectionDAGISel.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,15 @@ class SelectionDAGISel : public MachineFunctionPass {
199199
OPC_EmitMergeInputChains1_1,
200200
OPC_EmitMergeInputChains1_2,
201201
OPC_EmitCopyToReg,
202+
OPC_EmitCopyToReg0,
203+
OPC_EmitCopyToReg1,
202204
OPC_EmitCopyToReg2,
205+
OPC_EmitCopyToReg3,
206+
OPC_EmitCopyToReg4,
207+
OPC_EmitCopyToReg5,
208+
OPC_EmitCopyToReg6,
209+
OPC_EmitCopyToReg7,
210+
OPC_EmitCopyToRegHalf,
203211
OPC_EmitNodeXForm,
204212
OPC_EmitNode,
205213
// Space-optimized forms that implicitly encode number of result VTs.

llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3610,11 +3610,22 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
36103610
}
36113611

36123612
case OPC_EmitCopyToReg:
3613-
case OPC_EmitCopyToReg2: {
3614-
unsigned RecNo = MatcherTable[MatcherIndex++];
3613+
case OPC_EmitCopyToReg0:
3614+
case OPC_EmitCopyToReg1:
3615+
case OPC_EmitCopyToReg2:
3616+
case OPC_EmitCopyToReg3:
3617+
case OPC_EmitCopyToReg4:
3618+
case OPC_EmitCopyToReg5:
3619+
case OPC_EmitCopyToReg6:
3620+
case OPC_EmitCopyToReg7:
3621+
case OPC_EmitCopyToRegHalf: {
3622+
unsigned RecNo =
3623+
Opcode >= OPC_EmitCopyToReg0 && Opcode <= OPC_EmitCopyToReg7
3624+
? Opcode - OPC_EmitCopyToReg0
3625+
: MatcherTable[MatcherIndex++];
36153626
assert(RecNo < RecordedNodes.size() && "Invalid EmitCopyToReg");
36163627
unsigned DestPhysReg = MatcherTable[MatcherIndex++];
3617-
if (Opcode == OPC_EmitCopyToReg2)
3628+
if (Opcode == OPC_EmitCopyToRegHalf)
36183629
DestPhysReg |= MatcherTable[MatcherIndex++] << 8;
36193630

36203631
if (!InputChain.getNode())

llvm/utils/TableGen/DAGISelMatcherEmitter.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -755,14 +755,20 @@ EmitMatcher(const Matcher *N, const unsigned Indent, unsigned CurrentIdx,
755755
const auto *C2RMatcher = cast<EmitCopyToRegMatcher>(N);
756756
int Bytes = 3;
757757
const CodeGenRegister *Reg = C2RMatcher->getDestPhysReg();
758+
unsigned Slot = C2RMatcher->getSrcSlot();
758759
if (Reg->EnumValue > 255) {
759760
assert(isUInt<16>(Reg->EnumValue) && "not handled");
760-
OS << "OPC_EmitCopyToReg2, " << C2RMatcher->getSrcSlot() << ", "
761-
<< "TARGET_VAL(" << getQualifiedName(Reg->TheDef) << "),\n";
761+
OS << "OPC_EmitCopyToRegHalf, " << Slot << ", " << "TARGET_VAL("
762+
<< getQualifiedName(Reg->TheDef) << "),\n";
762763
++Bytes;
763764
} else {
764-
OS << "OPC_EmitCopyToReg, " << C2RMatcher->getSrcSlot() << ", "
765-
<< getQualifiedName(Reg->TheDef) << ",\n";
765+
if (Slot < 8) {
766+
OS << "OPC_EmitCopyToReg" << Slot << ", "
767+
<< getQualifiedName(Reg->TheDef) << ",\n";
768+
--Bytes;
769+
} else
770+
OS << "OPC_EmitCopyToReg, " << Slot << ", "
771+
<< getQualifiedName(Reg->TheDef) << ",\n";
766772
}
767773

768774
return Bytes;

0 commit comments

Comments
 (0)