Skip to content

[Tablegen] Add more comments for result numbers to DAGISelEmitter.cpp #116533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 29 additions & 10 deletions llvm/utils/TableGen/Common/DAGISelMatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -834,13 +834,16 @@ class EmitIntegerMatcher : public Matcher {
int64_t Val;
MVT::SimpleValueType VT;

unsigned ResultNo;

public:
EmitIntegerMatcher(int64_t val, MVT::SimpleValueType vt)
EmitIntegerMatcher(int64_t val, MVT::SimpleValueType vt, unsigned resultNo)
: Matcher(EmitInteger), Val(SignExtend64(val, MVT(vt).getSizeInBits())),
VT(vt) {}
VT(vt), ResultNo(resultNo) {}

int64_t getValue() const { return Val; }
MVT::SimpleValueType getVT() const { return VT; }
unsigned getResultNo() const { return ResultNo; }

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

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

unsigned ResultNo;

public:
EmitStringIntegerMatcher(const std::string &val, MVT::SimpleValueType vt)
: Matcher(EmitStringInteger), Val(val), VT(vt) {}
EmitStringIntegerMatcher(const std::string &val, MVT::SimpleValueType vt,
unsigned resultNo)
: Matcher(EmitStringInteger), Val(val), VT(vt), ResultNo(resultNo) {}

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

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

unsigned ResultNo;

public:
EmitRegisterMatcher(const CodeGenRegister *reg, MVT::SimpleValueType vt)
: Matcher(EmitRegister), Reg(reg), VT(vt) {}
EmitRegisterMatcher(const CodeGenRegister *reg, MVT::SimpleValueType vt,
unsigned resultNo)
: Matcher(EmitRegister), Reg(reg), VT(vt), ResultNo(resultNo) {}

const CodeGenRegister *getReg() const { return Reg; }
MVT::SimpleValueType getVT() const { return VT; }
unsigned getResultNo() const { return ResultNo; }

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

Expand All @@ -907,11 +918,14 @@ class EmitRegisterMatcher : public Matcher {
class EmitConvertToTargetMatcher : public Matcher {
unsigned Slot;

unsigned ResultNo;

public:
EmitConvertToTargetMatcher(unsigned slot)
: Matcher(EmitConvertToTarget), Slot(slot) {}
EmitConvertToTargetMatcher(unsigned slot, unsigned resultNo)
: Matcher(EmitConvertToTarget), Slot(slot), ResultNo(resultNo) {}

unsigned getSlot() const { return Slot; }
unsigned getResultNo() const { return ResultNo; }

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

unsigned ResultNo;

public:
EmitNodeXFormMatcher(unsigned slot, const Record *nodeXForm)
: Matcher(EmitNodeXForm), Slot(slot), NodeXForm(nodeXForm) {}
EmitNodeXFormMatcher(unsigned slot, const Record *nodeXForm,
unsigned resultNo)
: Matcher(EmitNodeXForm), Slot(slot), NodeXForm(nodeXForm),
ResultNo(resultNo) {}

unsigned getSlot() const { return Slot; }
const Record *getNodeXForm() const { return NodeXForm; }
unsigned getResultNo() const { return ResultNo; }

static bool classof(const Matcher *N) {
return N->getKind() == EmitNodeXForm;
Expand Down
35 changes: 24 additions & 11 deletions llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,8 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
break;
}
unsigned Bytes = OpBytes + EmitSignedVBRValue(Val, OS);
if (!OmitComments)
OS << " // " << Val << " #" << cast<EmitIntegerMatcher>(N)->getResultNo();
OS << '\n';
return Bytes;
}
Expand All @@ -818,7 +820,10 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
OpBytes = EmitVBRValue(VT, OS) + 1;
break;
}
OS << Val << ",\n";
OS << Val << ',';
if (!OmitComments)
OS << " // #" << cast<EmitStringIntegerMatcher>(N)->getResultNo();
OS << '\n';
return OpBytes + 1;
}

Expand Down Expand Up @@ -851,24 +856,31 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
break;
}
if (Reg) {
OS << getQualifiedName(Reg->TheDef) << ",\n";
OS << getQualifiedName(Reg->TheDef);
} else {
OS << "0 ";
if (!OmitComments)
OS << "/*zero_reg*/";
OS << ",\n";
}

OS << ',';
if (!OmitComments)
OS << " // #" << Matcher->getResultNo();
OS << '\n';
return OpBytes + 1;
}

case Matcher::EmitConvertToTarget: {
unsigned Slot = cast<EmitConvertToTargetMatcher>(N)->getSlot();
if (Slot < 8) {
OS << "OPC_EmitConvertToTarget" << Slot << ",\n";
return 1;
}
OS << "OPC_EmitConvertToTarget, " << Slot << ",\n";
return 2;
const auto *CTTM = cast<EmitConvertToTargetMatcher>(N);
unsigned Slot = CTTM->getSlot();
OS << "OPC_EmitConvertToTarget";
if (Slot >= 8)
OS << ", ";
OS << Slot << ',';
if (!OmitComments)
OS << " // #" << CTTM->getResultNo();
OS << '\n';
return 1 + (Slot >= 8);
}

case Matcher::EmitMergeInputChains: {
Expand Down Expand Up @@ -914,7 +926,8 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
OS << "OPC_EmitNodeXForm, " << getNodeXFormID(XF->getNodeXForm()) << ", "
<< XF->getSlot() << ',';
if (!OmitComments)
OS << " // " << XF->getNodeXForm()->getName();
OS << " // " << XF->getNodeXForm()->getName() << " #"
<< XF->getResultNo();
OS << '\n';
return 3;
}
Expand Down
29 changes: 18 additions & 11 deletions llvm/utils/TableGen/DAGISelMatcherGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ void MatcherGen::EmitResultOfNamedOperand(
if (!N.isLeaf()) {
StringRef OperatorName = N.getOperator()->getName();
if (OperatorName == "imm" || OperatorName == "fpimm") {
AddMatcher(new EmitConvertToTargetMatcher(SlotNo));
AddMatcher(new EmitConvertToTargetMatcher(SlotNo, NextRecordedOperandNo));
ResultOps.push_back(NextRecordedOperandNo++);
return;
}
Expand All @@ -666,7 +666,8 @@ void MatcherGen::EmitResultLeafAsOperand(const TreePatternNode &N,
assert(N.isLeaf() && "Must be a leaf");

if (const IntInit *II = dyn_cast<IntInit>(N.getLeafValue())) {
AddMatcher(new EmitIntegerMatcher(II->getValue(), N.getSimpleType(0)));
AddMatcher(new EmitIntegerMatcher(II->getValue(), N.getSimpleType(0),
NextRecordedOperandNo));
ResultOps.push_back(NextRecordedOperandNo++);
return;
}
Expand All @@ -676,13 +677,15 @@ void MatcherGen::EmitResultLeafAsOperand(const TreePatternNode &N,
const Record *Def = DI->getDef();
if (Def->isSubClassOf("Register")) {
const CodeGenRegister *Reg = CGP.getTargetInfo().getRegBank().getReg(Def);
AddMatcher(new EmitRegisterMatcher(Reg, N.getSimpleType(0)));
AddMatcher(new EmitRegisterMatcher(Reg, N.getSimpleType(0),
NextRecordedOperandNo));
ResultOps.push_back(NextRecordedOperandNo++);
return;
}

if (Def->getName() == "zero_reg") {
AddMatcher(new EmitRegisterMatcher(nullptr, N.getSimpleType(0)));
AddMatcher(new EmitRegisterMatcher(nullptr, N.getSimpleType(0),
NextRecordedOperandNo));
ResultOps.push_back(NextRecordedOperandNo++);
return;
}
Expand Down Expand Up @@ -710,12 +713,13 @@ void MatcherGen::EmitResultLeafAsOperand(const TreePatternNode &N,
CGP.getTargetInfo().getRegisterClass(Def);
if (RC.EnumValue <= 127) {
std::string Value = RC.getQualifiedIdName();
AddMatcher(new EmitStringIntegerMatcher(Value, MVT::i32));
ResultOps.push_back(NextRecordedOperandNo++);
AddMatcher(new EmitStringIntegerMatcher(Value, MVT::i32,
NextRecordedOperandNo));
} else {
AddMatcher(new EmitIntegerMatcher(RC.EnumValue, MVT::i32));
ResultOps.push_back(NextRecordedOperandNo++);
AddMatcher(new EmitIntegerMatcher(RC.EnumValue, MVT::i32,
NextRecordedOperandNo));
}
ResultOps.push_back(NextRecordedOperandNo++);
return;
}

Expand All @@ -728,13 +732,15 @@ void MatcherGen::EmitResultLeafAsOperand(const TreePatternNode &N,
const CodeGenSubRegIndex *I = RB.findSubRegIdx(Def);
assert(I && "Cannot find subreg index by name!");
if (I->EnumValue > 127) {
AddMatcher(new EmitIntegerMatcher(I->EnumValue, MVT::i32));
AddMatcher(new EmitIntegerMatcher(I->EnumValue, MVT::i32,
NextRecordedOperandNo));
ResultOps.push_back(NextRecordedOperandNo++);
return;
}
}
std::string Value = getQualifiedName(Def);
AddMatcher(new EmitStringIntegerMatcher(Value, MVT::i32));
AddMatcher(
new EmitStringIntegerMatcher(Value, MVT::i32, NextRecordedOperandNo));
ResultOps.push_back(NextRecordedOperandNo++);
return;
}
Expand Down Expand Up @@ -995,7 +1001,8 @@ void MatcherGen::EmitResultSDNodeXFormAsOperand(
// The input currently must have produced exactly one result.
assert(InputOps.size() == 1 && "Unexpected input to SDNodeXForm");

AddMatcher(new EmitNodeXFormMatcher(InputOps[0], N.getOperator()));
AddMatcher(new EmitNodeXFormMatcher(InputOps[0], N.getOperator(),
NextRecordedOperandNo));
ResultOps.push_back(NextRecordedOperandNo++);
}

Expand Down
Loading