Skip to content

Commit b3aefc3

Browse files
committed
MachineVerifier: Add parameter to choose if MachineFunction::verify() aborts
The abort on error behaviour is unpractical for debugger and unittest usage. llvm-svn: 260904
1 parent c7b2124 commit b3aefc3

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

llvm/include/llvm/CodeGen/MachineFunction.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,11 @@ class MachineFunction {
332332
///
333333
void dump() const;
334334

335-
/// verify - Run the current MachineFunction through the machine code
336-
/// verifier, useful for debugger use.
337-
void verify(Pass *p = nullptr, const char *Banner = nullptr) const;
335+
/// Run the current MachineFunction through the machine code verifier, useful
336+
/// for debugger use.
337+
/// \returns true if no problems were found.
338+
bool verify(Pass *p = nullptr, const char *Banner = nullptr,
339+
bool AbortOnError = true) const;
338340

339341
// Provide accessors for the MachineBasicBlock list...
340342
typedef BasicBlockListType::iterator iterator;

llvm/lib/CodeGen/MachineVerifier.cpp

+13-10
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ namespace {
5858
Banner(b)
5959
{}
6060

61-
bool runOnMachineFunction(MachineFunction &MF);
61+
unsigned verify(MachineFunction &MF);
6262

6363
Pass *const PASS;
6464
const char *Banner;
@@ -268,7 +268,9 @@ namespace {
268268
}
269269

270270
bool runOnMachineFunction(MachineFunction &MF) override {
271-
MF.verify(this, Banner.c_str());
271+
unsigned FoundErrors = MachineVerifier(this, Banner.c_str()).verify(MF);
272+
if (FoundErrors)
273+
report_fatal_error("Found "+Twine(FoundErrors)+" machine code errors.");
272274
return false;
273275
}
274276
};
@@ -283,9 +285,13 @@ FunctionPass *llvm::createMachineVerifierPass(const std::string &Banner) {
283285
return new MachineVerifierPass(Banner);
284286
}
285287

286-
void MachineFunction::verify(Pass *p, const char *Banner) const {
287-
MachineVerifier(p, Banner)
288-
.runOnMachineFunction(const_cast<MachineFunction&>(*this));
288+
bool MachineFunction::verify(Pass *p, const char *Banner, bool AbortOnErrors)
289+
const {
290+
MachineFunction &MF = const_cast<MachineFunction&>(*this);
291+
unsigned FoundErrors = MachineVerifier(p, Banner).verify(MF);
292+
if (AbortOnErrors && FoundErrors)
293+
report_fatal_error("Found "+Twine(FoundErrors)+" machine code errors.");
294+
return FoundErrors == 0;
289295
}
290296

291297
void MachineVerifier::verifySlotIndexes() const {
@@ -301,7 +307,7 @@ void MachineVerifier::verifySlotIndexes() const {
301307
}
302308
}
303309

304-
bool MachineVerifier::runOnMachineFunction(MachineFunction &MF) {
310+
unsigned MachineVerifier::verify(MachineFunction &MF) {
305311
foundErrors = 0;
306312

307313
this->MF = &MF;
@@ -386,9 +392,6 @@ bool MachineVerifier::runOnMachineFunction(MachineFunction &MF) {
386392
}
387393
visitMachineFunctionAfter();
388394

389-
if (foundErrors)
390-
report_fatal_error("Found "+Twine(foundErrors)+" machine code errors.");
391-
392395
// Clean up.
393396
regsLive.clear();
394397
regsDefined.clear();
@@ -398,7 +401,7 @@ bool MachineVerifier::runOnMachineFunction(MachineFunction &MF) {
398401
regsLiveInButUnused.clear();
399402
MBBInfoMap.clear();
400403

401-
return false; // no changes
404+
return foundErrors;
402405
}
403406

404407
void MachineVerifier::report(const char *msg, const MachineFunction *MF) {

0 commit comments

Comments
 (0)