Skip to content

Commit 41e64e0

Browse files
committed
[pattern-gen] Rais error if an operands is not used in pattern
1 parent 7170b2d commit 41e64e0

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

llvm/lib/CodeGen/GlobalISel/PatternGen.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ STATISTIC(PatternGenNumErrorFormatLoad, "Errors of type: FORMAT_LOAD");
6565
STATISTIC(PatternGenNumErrorFormatImm, "Errors of type: FORMAT_IMM");
6666
STATISTIC(PatternGenNumErrorFormat, "Errors of type: FORMAT");
6767
STATISTIC(PatternGenNumErrorMultipleStores, "Errors of type: MULTIPLE STORES");
68+
STATISTIC(PatternGenNumErrorUnusedOperand, "Errors of type: UNUSED_OPERAND");
6869

6970
#ifdef LLVM_GISEL_COV_PREFIX
7071
static cl::opt<std::string>
@@ -142,7 +143,8 @@ enum PatternErrorT {
142143
FORMAT_LOAD,
143144
FORMAT_IMM,
144145
FORMAT,
145-
MULTIPLE_STORES
146+
MULTIPLE_STORES,
147+
UNUSED_OPERANDS
146148
};
147149
struct PatternError {
148150
PatternErrorT Type;
@@ -163,7 +165,8 @@ llvm::Statistic *ErrorStats[] = {nullptr,
163165
&PatternGenNumErrorFormatLoad,
164166
&PatternGenNumErrorFormatImm,
165167
&PatternGenNumErrorFormat,
166-
&PatternGenNumErrorMultipleStores};
168+
&PatternGenNumErrorMultipleStores,
169+
&PatternGenNumErrorUnusedOperand};
167170

168171
static const std::unordered_map<unsigned, std::string> CmpStr = {
169172
{CmpInst::Predicate::ICMP_EQ, "SETEQ"},
@@ -1366,6 +1369,12 @@ bool PatternGen::runOnMachineFunction(MachineFunction &MF) {
13661369
std::string OutsString;
13671370
std::string InsString;
13681371
for (size_t I = 0; I < CurInstr->fields.size() - 1; I++) {
1372+
if (!PatternArgs[I].In && !PatternArgs[I].Out) {
1373+
llvm::errs() << "Pattern Generation failed for " << MF.getName() << ": "
1374+
<< "Operand '" << CurInstr->fields[I].ident << "' not used in pattern!\n";
1375+
++PatternGenNumErrorUnusedOperand;
1376+
return true;
1377+
}
13691378
if (PatternArgs[I].In) {
13701379
InsString += PatternArgs[I].ArgTypeStr + ":$" +
13711380
std::string(CurInstr->fields[I].ident) + ", ";

0 commit comments

Comments
 (0)