Skip to content

[Instrumentation] Support verifying machine function #90931

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 4 commits into from
May 4, 2024

Conversation

paperchalice
Copy link
Contributor

@paperchalice paperchalice commented May 3, 2024

We need it to test isel related passes. Currently verifyMachineFunction is incomplete (no LiveIntervals support), but is enough for testing isel pass, will migrate to complete MachineVerifierPass in future.

@paperchalice paperchalice requested review from aeubanks and arsenm May 3, 2024 02:06
@paperchalice paperchalice changed the title [Instrumentation] Support verify machine function [Instrumentation] Support verifying machine function May 3, 2024
@paperchalice paperchalice force-pushed the verify-instrumentation branch from 5db6744 to 4c847d2 Compare May 3, 2024 02:12
@@ -115,7 +115,7 @@ int llvm::compileModuleWithNewPM(
MachineModuleInfo MMI(&LLVMTM);

PassInstrumentationCallbacks PIC;
StandardInstrumentations SI(Context, Opt.DebugPM);
StandardInstrumentations SI(Context, Opt.DebugPM, !NoVerify);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Command line option verify-machineinstrs is overlapped with --disable-verify when we use new pass manager.


// TODO: Use complete MachineVerifierPass.
if (auto *MF = unwrapIR<MachineFunction>(IR)) {
dbgs() << "Verifying machine function " << MF->getName() << '\n';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logging should be under DebugLogging

// TODO: Use complete MachineVerifierPass.
if (auto *MF = unwrapIR<MachineFunction>(IR)) {
dbgs() << "Verifying machine function " << MF->getName() << '\n';
verifyMachineFunction("", *MF);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add something for Banner, like the "Broke module found after pass ..." above? and we have a pass that breaks MIR to test this IIRC?

Copy link
Contributor Author

@paperchalice paperchalice May 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MIRs are verified immediately after parsing and there is no trivial pass that convert valid mir to invalid mir.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I was thinking of RequireAllMachineFunctionPropertiesPass. could you add something like that pass which creates invalid MIR, then use that for testing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extended TriggerVerifierErrorPass now.

@@ -0,0 +1,10 @@
# RUN: llc -mtriple=x86_64-pc-linux-gnu -x mir -passes=no-op-machine-function -filetype=null < %s 2>&1 | FileCheck %s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to enable DebugLogging right?

Copy link

github-actions bot commented May 3, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@paperchalice paperchalice force-pushed the verify-instrumentation branch from 453676a to 0260bdb Compare May 3, 2024 06:38
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &) {
// Intentionally create a virtual register and set NoVRegs property.
auto &MRI = MF.getRegInfo();
MRI.createGenericVirtualRegister(LLT::scalar(8));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be safe, it would be best to introduce an actual instruction with the register. IIRC we permit virtual registers that have no uses in the MIR

@paperchalice paperchalice force-pushed the verify-instrumentation branch from 0260bdb to 237b57f Compare May 3, 2024 07:04
Copy link
Contributor

@aeubanks aeubanks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks!

# RUN: not --crash llc -mtriple=x86_64-pc-linux-gnu -debug-pass-manager -passes='module(function(machine-function(trigger-verifier-error)))' -filetype=null %s 2>&1 | FileCheck %s

# CHECK: Verifying machine function f
# CHECK: Broken machine function found after pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: CHECK: ... after pass "TriggerVerifierErrorPass"

@paperchalice paperchalice merged commit e7939d0 into llvm:main May 4, 2024
3 of 4 checks passed
AZero13 pushed a commit to AZero13/llvm-project that referenced this pull request May 4, 2024
We need it to test isel related passes. Currently
`verifyMachineFunction` is incomplete (no LiveIntervals support), but is
enough for testing isel pass, will migrate to complete
`MachineVerifierPass` in future.
@paperchalice paperchalice deleted the verify-instrumentation branch May 4, 2024 02:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants