Skip to content

Commit 92ffefe

Browse files
authored
[Tablegen] Add more comments for result numbers to DAGISelEmitter.cpp (#116533)
Print what result number the Emit* nodes are storing their results in. This makes it easy to track the inputs of later opcodes that consume these results.
1 parent 61d1b7c commit 92ffefe

File tree

3 files changed

+71
-32
lines changed

3 files changed

+71
-32
lines changed

llvm/utils/TableGen/Common/DAGISelMatcher.h

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -834,13 +834,16 @@ class EmitIntegerMatcher : public Matcher {
834834
int64_t Val;
835835
MVT::SimpleValueType VT;
836836

837+
unsigned ResultNo;
838+
837839
public:
838-
EmitIntegerMatcher(int64_t val, MVT::SimpleValueType vt)
840+
EmitIntegerMatcher(int64_t val, MVT::SimpleValueType vt, unsigned resultNo)
839841
: Matcher(EmitInteger), Val(SignExtend64(val, MVT(vt).getSizeInBits())),
840-
VT(vt) {}
842+
VT(vt), ResultNo(resultNo) {}
841843

842844
int64_t getValue() const { return Val; }
843845
MVT::SimpleValueType getVT() const { return VT; }
846+
unsigned getResultNo() const { return ResultNo; }
844847

845848
static bool classof(const Matcher *N) { return N->getKind() == EmitInteger; }
846849

@@ -858,12 +861,16 @@ class EmitStringIntegerMatcher : public Matcher {
858861
std::string Val;
859862
MVT::SimpleValueType VT;
860863

864+
unsigned ResultNo;
865+
861866
public:
862-
EmitStringIntegerMatcher(const std::string &val, MVT::SimpleValueType vt)
863-
: Matcher(EmitStringInteger), Val(val), VT(vt) {}
867+
EmitStringIntegerMatcher(const std::string &val, MVT::SimpleValueType vt,
868+
unsigned resultNo)
869+
: Matcher(EmitStringInteger), Val(val), VT(vt), ResultNo(resultNo) {}
864870

865871
const std::string &getValue() const { return Val; }
866872
MVT::SimpleValueType getVT() const { return VT; }
873+
unsigned getResultNo() const { return ResultNo; }
867874

868875
static bool classof(const Matcher *N) {
869876
return N->getKind() == EmitStringInteger;
@@ -884,12 +891,16 @@ class EmitRegisterMatcher : public Matcher {
884891
const CodeGenRegister *Reg;
885892
MVT::SimpleValueType VT;
886893

894+
unsigned ResultNo;
895+
887896
public:
888-
EmitRegisterMatcher(const CodeGenRegister *reg, MVT::SimpleValueType vt)
889-
: Matcher(EmitRegister), Reg(reg), VT(vt) {}
897+
EmitRegisterMatcher(const CodeGenRegister *reg, MVT::SimpleValueType vt,
898+
unsigned resultNo)
899+
: Matcher(EmitRegister), Reg(reg), VT(vt), ResultNo(resultNo) {}
890900

891901
const CodeGenRegister *getReg() const { return Reg; }
892902
MVT::SimpleValueType getVT() const { return VT; }
903+
unsigned getResultNo() const { return ResultNo; }
893904

894905
static bool classof(const Matcher *N) { return N->getKind() == EmitRegister; }
895906

@@ -907,11 +918,14 @@ class EmitRegisterMatcher : public Matcher {
907918
class EmitConvertToTargetMatcher : public Matcher {
908919
unsigned Slot;
909920

921+
unsigned ResultNo;
922+
910923
public:
911-
EmitConvertToTargetMatcher(unsigned slot)
912-
: Matcher(EmitConvertToTarget), Slot(slot) {}
924+
EmitConvertToTargetMatcher(unsigned slot, unsigned resultNo)
925+
: Matcher(EmitConvertToTarget), Slot(slot), ResultNo(resultNo) {}
913926

914927
unsigned getSlot() const { return Slot; }
928+
unsigned getResultNo() const { return ResultNo; }
915929

916930
static bool classof(const Matcher *N) {
917931
return N->getKind() == EmitConvertToTarget;
@@ -985,12 +999,17 @@ class EmitNodeXFormMatcher : public Matcher {
985999
unsigned Slot;
9861000
const Record *NodeXForm;
9871001

1002+
unsigned ResultNo;
1003+
9881004
public:
989-
EmitNodeXFormMatcher(unsigned slot, const Record *nodeXForm)
990-
: Matcher(EmitNodeXForm), Slot(slot), NodeXForm(nodeXForm) {}
1005+
EmitNodeXFormMatcher(unsigned slot, const Record *nodeXForm,
1006+
unsigned resultNo)
1007+
: Matcher(EmitNodeXForm), Slot(slot), NodeXForm(nodeXForm),
1008+
ResultNo(resultNo) {}
9911009

9921010
unsigned getSlot() const { return Slot; }
9931011
const Record *getNodeXForm() const { return NodeXForm; }
1012+
unsigned getResultNo() const { return ResultNo; }
9941013

9951014
static bool classof(const Matcher *N) {
9961015
return N->getKind() == EmitNodeXForm;

llvm/utils/TableGen/DAGISelMatcherEmitter.cpp

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,8 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
798798
break;
799799
}
800800
unsigned Bytes = OpBytes + EmitSignedVBRValue(Val, OS);
801+
if (!OmitComments)
802+
OS << " // " << Val << " #" << cast<EmitIntegerMatcher>(N)->getResultNo();
801803
OS << '\n';
802804
return Bytes;
803805
}
@@ -818,7 +820,10 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
818820
OpBytes = EmitVBRValue(VT, OS) + 1;
819821
break;
820822
}
821-
OS << Val << ",\n";
823+
OS << Val << ',';
824+
if (!OmitComments)
825+
OS << " // #" << cast<EmitStringIntegerMatcher>(N)->getResultNo();
826+
OS << '\n';
822827
return OpBytes + 1;
823828
}
824829

@@ -851,24 +856,31 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
851856
break;
852857
}
853858
if (Reg) {
854-
OS << getQualifiedName(Reg->TheDef) << ",\n";
859+
OS << getQualifiedName(Reg->TheDef);
855860
} else {
856861
OS << "0 ";
857862
if (!OmitComments)
858863
OS << "/*zero_reg*/";
859-
OS << ",\n";
860864
}
865+
866+
OS << ',';
867+
if (!OmitComments)
868+
OS << " // #" << Matcher->getResultNo();
869+
OS << '\n';
861870
return OpBytes + 1;
862871
}
863872

864873
case Matcher::EmitConvertToTarget: {
865-
unsigned Slot = cast<EmitConvertToTargetMatcher>(N)->getSlot();
866-
if (Slot < 8) {
867-
OS << "OPC_EmitConvertToTarget" << Slot << ",\n";
868-
return 1;
869-
}
870-
OS << "OPC_EmitConvertToTarget, " << Slot << ",\n";
871-
return 2;
874+
const auto *CTTM = cast<EmitConvertToTargetMatcher>(N);
875+
unsigned Slot = CTTM->getSlot();
876+
OS << "OPC_EmitConvertToTarget";
877+
if (Slot >= 8)
878+
OS << ", ";
879+
OS << Slot << ',';
880+
if (!OmitComments)
881+
OS << " // #" << CTTM->getResultNo();
882+
OS << '\n';
883+
return 1 + (Slot >= 8);
872884
}
873885

874886
case Matcher::EmitMergeInputChains: {
@@ -914,7 +926,8 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
914926
OS << "OPC_EmitNodeXForm, " << getNodeXFormID(XF->getNodeXForm()) << ", "
915927
<< XF->getSlot() << ',';
916928
if (!OmitComments)
917-
OS << " // " << XF->getNodeXForm()->getName();
929+
OS << " // " << XF->getNodeXForm()->getName() << " #"
930+
<< XF->getResultNo();
918931
OS << '\n';
919932
return 3;
920933
}

llvm/utils/TableGen/DAGISelMatcherGen.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ void MatcherGen::EmitResultOfNamedOperand(
651651
if (!N.isLeaf()) {
652652
StringRef OperatorName = N.getOperator()->getName();
653653
if (OperatorName == "imm" || OperatorName == "fpimm") {
654-
AddMatcher(new EmitConvertToTargetMatcher(SlotNo));
654+
AddMatcher(new EmitConvertToTargetMatcher(SlotNo, NextRecordedOperandNo));
655655
ResultOps.push_back(NextRecordedOperandNo++);
656656
return;
657657
}
@@ -666,7 +666,8 @@ void MatcherGen::EmitResultLeafAsOperand(const TreePatternNode &N,
666666
assert(N.isLeaf() && "Must be a leaf");
667667

668668
if (const IntInit *II = dyn_cast<IntInit>(N.getLeafValue())) {
669-
AddMatcher(new EmitIntegerMatcher(II->getValue(), N.getSimpleType(0)));
669+
AddMatcher(new EmitIntegerMatcher(II->getValue(), N.getSimpleType(0),
670+
NextRecordedOperandNo));
670671
ResultOps.push_back(NextRecordedOperandNo++);
671672
return;
672673
}
@@ -676,13 +677,15 @@ void MatcherGen::EmitResultLeafAsOperand(const TreePatternNode &N,
676677
const Record *Def = DI->getDef();
677678
if (Def->isSubClassOf("Register")) {
678679
const CodeGenRegister *Reg = CGP.getTargetInfo().getRegBank().getReg(Def);
679-
AddMatcher(new EmitRegisterMatcher(Reg, N.getSimpleType(0)));
680+
AddMatcher(new EmitRegisterMatcher(Reg, N.getSimpleType(0),
681+
NextRecordedOperandNo));
680682
ResultOps.push_back(NextRecordedOperandNo++);
681683
return;
682684
}
683685

684686
if (Def->getName() == "zero_reg") {
685-
AddMatcher(new EmitRegisterMatcher(nullptr, N.getSimpleType(0)));
687+
AddMatcher(new EmitRegisterMatcher(nullptr, N.getSimpleType(0),
688+
NextRecordedOperandNo));
686689
ResultOps.push_back(NextRecordedOperandNo++);
687690
return;
688691
}
@@ -710,12 +713,13 @@ void MatcherGen::EmitResultLeafAsOperand(const TreePatternNode &N,
710713
CGP.getTargetInfo().getRegisterClass(Def);
711714
if (RC.EnumValue <= 127) {
712715
std::string Value = RC.getQualifiedIdName();
713-
AddMatcher(new EmitStringIntegerMatcher(Value, MVT::i32));
714-
ResultOps.push_back(NextRecordedOperandNo++);
716+
AddMatcher(new EmitStringIntegerMatcher(Value, MVT::i32,
717+
NextRecordedOperandNo));
715718
} else {
716-
AddMatcher(new EmitIntegerMatcher(RC.EnumValue, MVT::i32));
717-
ResultOps.push_back(NextRecordedOperandNo++);
719+
AddMatcher(new EmitIntegerMatcher(RC.EnumValue, MVT::i32,
720+
NextRecordedOperandNo));
718721
}
722+
ResultOps.push_back(NextRecordedOperandNo++);
719723
return;
720724
}
721725

@@ -728,13 +732,15 @@ void MatcherGen::EmitResultLeafAsOperand(const TreePatternNode &N,
728732
const CodeGenSubRegIndex *I = RB.findSubRegIdx(Def);
729733
assert(I && "Cannot find subreg index by name!");
730734
if (I->EnumValue > 127) {
731-
AddMatcher(new EmitIntegerMatcher(I->EnumValue, MVT::i32));
735+
AddMatcher(new EmitIntegerMatcher(I->EnumValue, MVT::i32,
736+
NextRecordedOperandNo));
732737
ResultOps.push_back(NextRecordedOperandNo++);
733738
return;
734739
}
735740
}
736741
std::string Value = getQualifiedName(Def);
737-
AddMatcher(new EmitStringIntegerMatcher(Value, MVT::i32));
742+
AddMatcher(
743+
new EmitStringIntegerMatcher(Value, MVT::i32, NextRecordedOperandNo));
738744
ResultOps.push_back(NextRecordedOperandNo++);
739745
return;
740746
}
@@ -995,7 +1001,8 @@ void MatcherGen::EmitResultSDNodeXFormAsOperand(
9951001
// The input currently must have produced exactly one result.
9961002
assert(InputOps.size() == 1 && "Unexpected input to SDNodeXForm");
9971003

998-
AddMatcher(new EmitNodeXFormMatcher(InputOps[0], N.getOperator()));
1004+
AddMatcher(new EmitNodeXFormMatcher(InputOps[0], N.getOperator(),
1005+
NextRecordedOperandNo));
9991006
ResultOps.push_back(NextRecordedOperandNo++);
10001007
}
10011008

0 commit comments

Comments
 (0)