Skip to content

Commit 0619292

Browse files
authored
[TableGen] Constify CodeGenInstruction where possible (NFC) (llvm#169193)
1 parent 2d051ad commit 0619292

File tree

9 files changed

+25
-22
lines changed

9 files changed

+25
-22
lines changed

llvm/utils/TableGen/CodeEmitterGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ bool CodeEmitterGen::addCodeToMergeInOperand(const Record *R,
103103
const std::string &VarName,
104104
std::string &Case,
105105
std::string &BitOffsetCase) {
106-
CodeGenInstruction &CGI = Target.getInstruction(R);
106+
const CodeGenInstruction &CGI = Target.getInstruction(R);
107107

108108
// Determine if VarName actually contributes to the Inst encoding.
109109
int Bit = BI->getNumBits() - 1;

llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,7 +1990,8 @@ static unsigned GetNumNodeResults(const Record *Operator,
19901990
}
19911991

19921992
if (Operator->isSubClassOf("Instruction")) {
1993-
CodeGenInstruction &InstInfo = CDP.getTargetInfo().getInstruction(Operator);
1993+
const CodeGenInstruction &InstInfo =
1994+
CDP.getTargetInfo().getInstruction(Operator);
19941995

19951996
unsigned NumDefsToAdd = InstInfo.Operands.NumDefs;
19961997

@@ -2657,7 +2658,7 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) {
26572658

26582659
if (getOperator()->isSubClassOf("Instruction")) {
26592660
const DAGInstruction &Inst = CDP.getInstruction(getOperator());
2660-
CodeGenInstruction &InstInfo =
2661+
const CodeGenInstruction &InstInfo =
26612662
CDP.getTargetInfo().getInstruction(getOperator());
26622663

26632664
bool MadeChange = false;
@@ -3871,7 +3872,7 @@ static void getInstructionsInTree(TreePatternNode &Tree,
38713872

38723873
/// Check the class of a pattern leaf node against the instruction operand it
38733874
/// represents.
3874-
static bool checkOperandClass(CGIOperandList::OperandInfo &OI,
3875+
static bool checkOperandClass(const CGIOperandList::OperandInfo &OI,
38753876
const Record *Leaf) {
38763877
if (OI.Rec == Leaf)
38773878
return true;
@@ -3888,7 +3889,7 @@ static bool checkOperandClass(CGIOperandList::OperandInfo &OI,
38883889
return false;
38893890
}
38903891

3891-
void CodeGenDAGPatterns::parseInstructionPattern(CodeGenInstruction &CGI,
3892+
void CodeGenDAGPatterns::parseInstructionPattern(const CodeGenInstruction &CGI,
38923893
const ListInit *Pat,
38933894
DAGInstMap &DAGInsts) {
38943895

@@ -3987,7 +3988,7 @@ void CodeGenDAGPatterns::parseInstructionPattern(CodeGenInstruction &CGI,
39873988
std::vector<TreePatternNodePtr> ResultNodeOperands;
39883989
std::vector<const Record *> Operands;
39893990
for (unsigned i = NumResults, e = CGI.Operands.size(); i != e; ++i) {
3990-
CGIOperandList::OperandInfo &Op = CGI.Operands[i];
3991+
const CGIOperandList::OperandInfo &Op = CGI.Operands[i];
39913992
StringRef OpName = Op.Name;
39923993
if (OpName.empty()) {
39933994
I.error("Operand #" + Twine(i) + " in operands list has no name!");
@@ -4093,7 +4094,7 @@ void CodeGenDAGPatterns::ParseInstructions() {
40934094
std::vector<const Record *> Results;
40944095
std::vector<const Record *> Operands;
40954096

4096-
CodeGenInstruction &InstInfo = Target.getInstruction(Instr);
4097+
const CodeGenInstruction &InstInfo = Target.getInstruction(Instr);
40974098

40984099
if (InstInfo.Operands.size() != 0) {
40994100
for (unsigned j = 0, e = InstInfo.Operands.NumDefs; j < e; ++j)
@@ -4112,7 +4113,7 @@ void CodeGenDAGPatterns::ParseInstructions() {
41124113
continue; // no pattern.
41134114
}
41144115

4115-
CodeGenInstruction &CGI = Target.getInstruction(Instr);
4116+
const CodeGenInstruction &CGI = Target.getInstruction(Instr);
41164117
parseInstructionPattern(CGI, LI, Instructions);
41174118
}
41184119

llvm/utils/TableGen/Common/CodeGenDAGPatterns.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,8 +1224,8 @@ class CodeGenDAGPatterns {
12241224

12251225
/// Parse the Pattern for an instruction, and insert the result in DAGInsts.
12261226
using DAGInstMap = std::map<const Record *, DAGInstruction, LessRecordByID>;
1227-
void parseInstructionPattern(CodeGenInstruction &CGI, const ListInit *Pattern,
1228-
DAGInstMap &DAGInsts);
1227+
void parseInstructionPattern(const CodeGenInstruction &CGI,
1228+
const ListInit *Pattern, DAGInstMap &DAGInsts);
12291229

12301230
const DAGInstruction &getInstruction(const Record *R) const {
12311231
auto F = Instructions.find(R);

llvm/utils/TableGen/Common/CodeGenInstAlias.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class CodeGenInstAlias {
4141

4242
/// ResultInst - The instruction generated by the alias (decoded from
4343
/// Result).
44-
CodeGenInstruction *ResultInst;
44+
const CodeGenInstruction *ResultInst;
4545

4646
class ResultOperand {
4747
std::string Name;

llvm/utils/TableGen/Common/GlobalISel/PatternParser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ PatternParser::parseInstructionPattern(const Init &Arg, StringRef Name) {
113113

114114
std::unique_ptr<InstructionPattern> Pat;
115115
if (const DagInit *IP = getDagWithOperatorOfSubClass(Arg, "Instruction")) {
116-
auto &Instr = CGT.getInstruction(IP->getOperatorAsDef(DiagLoc));
116+
const CodeGenInstruction &Instr =
117+
CGT.getInstruction(IP->getOperatorAsDef(DiagLoc));
117118
Pat =
118119
std::make_unique<CodeGenInstructionPattern>(Instr, insertStrRef(Name));
119120
} else if (const DagInit *IP =

llvm/utils/TableGen/DAGISelEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static unsigned getResultPatternCost(const TreePatternNode &P,
5151
const Record *Op = P.getOperator();
5252
if (Op->isSubClassOf("Instruction")) {
5353
Cost++;
54-
CodeGenInstruction &II = CGP.getTargetInfo().getInstruction(Op);
54+
const CodeGenInstruction &II = CGP.getTargetInfo().getInstruction(Op);
5555
if (II.usesCustomInserter)
5656
Cost += 10;
5757
}

llvm/utils/TableGen/DAGISelMatcherGen.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ void MatcherGen::EmitResultLeafAsOperand(const TreePatternNode &N,
690690
MVT::SimpleValueType ResultVT = N.getSimpleType(0);
691691
auto IDOperandNo = NextRecordedOperandNo++;
692692
const Record *ImpDef = Def->getRecords().getDef("IMPLICIT_DEF");
693-
CodeGenInstruction &II = CGP.getTargetInfo().getInstruction(ImpDef);
693+
const CodeGenInstruction &II = CGP.getTargetInfo().getInstruction(ImpDef);
694694
AddMatcher(new EmitNodeMatcher(II, ResultVT, {}, false, false, false,
695695
false, -1, IDOperandNo));
696696
ResultOps.push_back(IDOperandNo);
@@ -749,7 +749,7 @@ static bool mayInstNodeLoadOrStore(const TreePatternNode &N,
749749
const CodeGenDAGPatterns &CGP) {
750750
const Record *Op = N.getOperator();
751751
const CodeGenTarget &CGT = CGP.getTargetInfo();
752-
CodeGenInstruction &II = CGT.getInstruction(Op);
752+
const CodeGenInstruction &II = CGT.getInstruction(Op);
753753
return II.mayLoad || II.mayStore;
754754
}
755755

@@ -776,7 +776,7 @@ void MatcherGen::EmitResultInstructionAsOperand(
776776
const TreePatternNode &N, SmallVectorImpl<unsigned> &OutputOps) {
777777
const Record *Op = N.getOperator();
778778
const CodeGenTarget &CGT = CGP.getTargetInfo();
779-
CodeGenInstruction &II = CGT.getInstruction(Op);
779+
const CodeGenInstruction &II = CGT.getInstruction(Op);
780780
const DAGInstruction &Inst = CGP.getInstruction(Op);
781781

782782
bool isRoot = &N == &Pattern.getDstPattern();
@@ -1046,7 +1046,7 @@ void MatcherGen::EmitResultCode() {
10461046
const TreePatternNode &DstPat = Pattern.getDstPattern();
10471047
if (!DstPat.isLeaf() && DstPat.getOperator()->isSubClassOf("Instruction")) {
10481048
const CodeGenTarget &CGT = CGP.getTargetInfo();
1049-
CodeGenInstruction &II = CGT.getInstruction(DstPat.getOperator());
1049+
const CodeGenInstruction &II = CGT.getInstruction(DstPat.getOperator());
10501050

10511051
if (II.HasOneImplicitDefWithKnownVT(CGT) != MVT::Other)
10521052
HandledReg = II.ImplicitDefs[0];

llvm/utils/TableGen/FastISelEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ void FastISelMap::collectPatterns(const CodeGenDAGPatterns &CGP) {
440440
const Record *Op = Dst.getOperator();
441441
if (!Op->isSubClassOf("Instruction"))
442442
continue;
443-
CodeGenInstruction &Inst = CGP.getTargetInfo().getInstruction(Op);
443+
const CodeGenInstruction &Inst = CGP.getTargetInfo().getInstruction(Op);
444444
if (Inst.Operands.empty())
445445
continue;
446446

llvm/utils/TableGen/GlobalISelEmitter.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ static Expected<LLTCodeGen> getInstResultType(const TreePatternNode &Dst,
282282
// While we allow more than one output (both implicit and explicit defs)
283283
// below, we only expect one explicit def here.
284284
assert(Dst.getOperator()->isSubClassOf("Instruction"));
285-
CodeGenInstruction &InstInfo = Target.getInstruction(Dst.getOperator());
285+
const CodeGenInstruction &InstInfo = Target.getInstruction(Dst.getOperator());
286286
if (!InstInfo.Operands.NumDefs)
287287
return failedImport("Dst pattern child needs a def");
288288

@@ -1513,7 +1513,7 @@ GlobalISelEmitter::createInstructionRenderer(action_iterator InsertPt,
15131513
"Pattern operator isn't an instruction (it's a ValueType)");
15141514
return failedImport("Pattern operator isn't an instruction");
15151515
}
1516-
CodeGenInstruction *DstI = &Target.getInstruction(DstOp);
1516+
const CodeGenInstruction *DstI = &Target.getInstruction(DstOp);
15171517

15181518
// COPY_TO_REGCLASS is just a copy with a ConstrainOperandToRegClassAction
15191519
// attached. Similarly for EXTRACT_SUBREG except that's a subregister copy.
@@ -1597,7 +1597,8 @@ Expected<action_iterator> GlobalISelEmitter::importExplicitUseRenderers(
15971597
action_iterator InsertPt, RuleMatcher &M, BuildMIAction &DstMIBuilder,
15981598
const TreePatternNode &Dst) const {
15991599
const CodeGenInstruction *DstI = DstMIBuilder.getCGI();
1600-
CodeGenInstruction *OrigDstI = &Target.getInstruction(Dst.getOperator());
1600+
const CodeGenInstruction *OrigDstI =
1601+
&Target.getInstruction(Dst.getOperator());
16011602

16021603
StringRef Name = OrigDstI->getName();
16031604
unsigned ExpectedDstINumUses = Dst.getNumChildren();
@@ -2140,7 +2141,7 @@ Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
21402141
// We need to replace the def and all its uses with the specified
21412142
// operand. However, we must also insert COPY's wherever needed.
21422143
// For now, emit a copy and let the register allocator clean up.
2143-
auto &DstI = Target.getInstruction(RK.getDef("COPY"));
2144+
const CodeGenInstruction &DstI = Target.getInstruction(RK.getDef("COPY"));
21442145
const auto &DstIOperand = DstI.Operands[0];
21452146

21462147
OperandMatcher &OM0 = InsnMatcher.getOperand(0);

0 commit comments

Comments
 (0)