Skip to content

Commit 14d64be

Browse files
committed
[GISel] Print better error messages for missing Combiner Observer calls
Differential revision: https://reviews.llvm.org/D105290
1 parent 6bbbd7b commit 14d64be

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,17 @@ void GISelCSEInfo::releaseMemory() {
260260
#endif
261261
}
262262

263+
#ifndef NDEBUG
264+
static const char *stringify(const MachineInstr *MI, std::string &S) {
265+
raw_string_ostream OS(S);
266+
OS << *MI;
267+
return OS.str().c_str();
268+
}
269+
#endif
270+
263271
Error GISelCSEInfo::verify() {
264272
#ifndef NDEBUG
273+
std::string S1, S2;
265274
handleRecordedInsts();
266275
// For each instruction in map from MI -> UMI,
267276
// Profile(MI) and make sure UMI is found for that profile.
@@ -274,19 +283,23 @@ Error GISelCSEInfo::verify() {
274283
if (FoundNode != It.second)
275284
return createStringError(std::errc::not_supported,
276285
"CSEMap mismatch, InstrMapping has MIs without "
277-
"corresponding Nodes in CSEMap");
286+
"corresponding Nodes in CSEMap:\n%s",
287+
stringify(It.second->MI, S1));
278288
}
279289

280290
// For every node in the CSEMap, make sure that the InstrMapping
281291
// points to it.
282292
for (const UniqueMachineInstr &UMI : CSEMap) {
283293
if (!InstrMapping.count(UMI.MI))
284294
return createStringError(std::errc::not_supported,
285-
"Node in CSE without InstrMapping", UMI.MI);
295+
"Node in CSE without InstrMapping:\n%s",
296+
stringify(UMI.MI, S1));
286297

287298
if (InstrMapping[UMI.MI] != &UMI)
288299
return createStringError(std::make_error_code(std::errc::not_supported),
289-
"Mismatch in CSE mapping");
300+
"Mismatch in CSE mapping:\n%s\n%s",
301+
stringify(InstrMapping[UMI.MI]->MI, S1),
302+
stringify(UMI.MI, S2));
290303
}
291304
#endif
292305
return Error::success();

llvm/lib/CodeGen/GlobalISel/Combiner.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,14 @@ bool Combiner::combineMachineInstrs(MachineFunction &MF,
153153
MFChanged |= Changed;
154154
} while (Changed);
155155

156-
assert(!CSEInfo || (!errorToBool(CSEInfo->verify()) &&
157-
"CSEInfo is not consistent. Likely missing calls to "
158-
"observer on mutations"));
156+
#ifndef NDEBUG
157+
if (CSEInfo) {
158+
if (auto E = CSEInfo->verify()) {
159+
errs() << E << '\n';
160+
assert(false && "CSEInfo is not consistent. Likely missing calls to "
161+
"observer on mutations.");
162+
}
163+
}
164+
#endif
159165
return MFChanged;
160166
}

0 commit comments

Comments
 (0)