diff options
| author | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-10 20:36:50 +0800 |
|---|---|---|
| committer | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-10 20:36:50 +0800 |
| commit | adcf8c9b1bd1b47e00bf859693112cea1f7e8c9f (patch) | |
| tree | 59067aa71befab31678946dbf5e19f57131dd6f2 /backend/tools/MIRTool/MIRToolStageTest.cmake | |
| parent | 3a57627e59ba18b6f9f9aae7bb60c390c0d3575a (diff) | |
| download | rcc-project-adcf8c9b1bd1b47e00bf859693112cea1f7e8c9f.tar.gz rcc-project-adcf8c9b1bd1b47e00bf859693112cea1f7e8c9f.tar.xz | |
[Tooling] Complete backend tooling and validation
Diffstat (limited to 'backend/tools/MIRTool/MIRToolStageTest.cmake')
| -rw-r--r-- | backend/tools/MIRTool/MIRToolStageTest.cmake | 155 |
1 files changed, 155 insertions, 0 deletions
diff --git a/backend/tools/MIRTool/MIRToolStageTest.cmake b/backend/tools/MIRTool/MIRToolStageTest.cmake new file mode 100644 index 0000000..4fefe6e --- /dev/null +++ b/backend/tools/MIRTool/MIRToolStageTest.cmake @@ -0,0 +1,155 @@ +# SPDX-License-Identifier: GPL-3.0-or-later + +if(NOT DEFINED TOOL OR NOT DEFINED INPUT OR NOT DEFINED WORK_DIRECTORY) + message(FATAL_ERROR "MIR tool stage test is missing a required path") +endif() + +file(REMOVE_RECURSE "${WORK_DIRECTORY}") +file(MAKE_DIRECTORY "${WORK_DIRECTORY}") + +set( + Stages + prelegalizer-mir + legalized-mir + regbank-mir + selected-mir + post-ssa-mir + post-ra-mir + final-mir +) +foreach(Stage IN LISTS Stages) + set(StageOutput "${WORK_DIRECTORY}/${Stage}.mir") + set(RepeatedOutput "${WORK_DIRECTORY}/${Stage}.repeat.mir") + set(CanonicalOutput "${WORK_DIRECTORY}/${Stage}.canonical.mir") + execute_process( + COMMAND "${TOOL}" --input "${INPUT}" --emit "${Stage}" --output "${StageOutput}" + RESULT_VARIABLE StageResult + ERROR_VARIABLE StageDiagnostics + ) + if(NOT StageResult EQUAL 0) + message(FATAL_ERROR "${Stage} production failed: ${StageDiagnostics}") + endif() + execute_process( + COMMAND "${TOOL}" --input "${INPUT}" --emit "${Stage}" --output "${RepeatedOutput}" + RESULT_VARIABLE RepeatedResult + ERROR_VARIABLE RepeatedDiagnostics + ) + if(NOT RepeatedResult EQUAL 0) + message(FATAL_ERROR "repeated ${Stage} production failed: ${RepeatedDiagnostics}") + endif() + execute_process( + COMMAND "${CMAKE_COMMAND}" -E compare_files "${StageOutput}" "${RepeatedOutput}" + RESULT_VARIABLE DeterminismResult + ) + if(NOT DeterminismResult EQUAL 0) + message(FATAL_ERROR "${Stage} output is not deterministic") + endif() + execute_process( + COMMAND "${TOOL}" --verify --input "${StageOutput}" --output "${CanonicalOutput}" + RESULT_VARIABLE VerifyResult + ERROR_VARIABLE VerifyDiagnostics + ) + if(NOT VerifyResult EQUAL 0) + message(FATAL_ERROR "${Stage} output failed strict MIR reload: ${VerifyDiagnostics}") + endif() + execute_process( + COMMAND "${CMAKE_COMMAND}" -E compare_files "${StageOutput}" "${CanonicalOutput}" + RESULT_VARIABLE CanonicalResult + ) + if(NOT CanonicalResult EQUAL 0) + message(FATAL_ERROR "${Stage} output is not canonical after strict reload") + endif() +endforeach() + +set(PassList "${WORK_DIRECTORY}/passes.txt") +execute_process( + COMMAND "${TOOL}" --list-passes --input "${INPUT}" --output "${PassList}" + RESULT_VARIABLE ListResult + ERROR_VARIABLE ListDiagnostics +) +if(NOT ListResult EQUAL 0) + message(FATAL_ERROR "pass listing failed: ${ListDiagnostics}") +endif() +file(READ "${PassList}" PassListText) +foreach(RequiredPass IN ITEMS Legalizer RegisterBankSelect InstructionSelect PrologueEpilogueInsertion) + if(NOT PassListText MATCHES "(^|\n)${RequiredPass}(\n|$)") + message(FATAL_ERROR "canonical pass list is missing ${RequiredPass}") + endif() +endforeach() + +set(LegalizedOutput "${WORK_DIRECTORY}/run-pass.mir") +execute_process( + COMMAND + "${TOOL}" --input "${INPUT}" --run-pass Legalizer --emit legalized-mir --output + "${LegalizedOutput}" + RESULT_VARIABLE RunPassResult + ERROR_VARIABLE RunPassDiagnostics +) +if(NOT RunPassResult EQUAL 0) + message(FATAL_ERROR "single-pass execution failed: ${RunPassDiagnostics}") +endif() + +set(RegBankOutput "${WORK_DIRECTORY}/passes.mir") +execute_process( + COMMAND + "${TOOL}" --input "${INPUT}" --passes Legalizer,RegisterBankSelect --emit regbank-mir + --output "${RegBankOutput}" + RESULT_VARIABLE PassesResult + ERROR_VARIABLE PassesDiagnostics +) +if(NOT PassesResult EQUAL 0) + message(FATAL_ERROR "explicit pass pipeline failed: ${PassesDiagnostics}") +endif() + +set(StoppedOutput "${WORK_DIRECTORY}/stopped.mir") +execute_process( + COMMAND + "${TOOL}" --input "${INPUT}" --stop-after Legalizer --emit final-mir --output + "${StoppedOutput}" + RESULT_VARIABLE StopResult + ERROR_VARIABLE StopDiagnostics +) +if(NOT StopResult EQUAL 0) + message(FATAL_ERROR "stop-after control failed: ${StopDiagnostics}") +endif() +execute_process( + COMMAND "${TOOL}" --verify --input "${StoppedOutput}" + RESULT_VARIABLE StopVerifyResult + ERROR_VARIABLE StopVerifyDiagnostics +) +if(NOT StopVerifyResult EQUAL 0) + message(FATAL_ERROR "stop-after output failed strict reload: ${StopVerifyDiagnostics}") +endif() + +execute_process( + COMMAND + "${TOOL}" --input "${INPUT}" --emit legalized-mir --print-before Legalizer --print-after + Legalizer --output "${WORK_DIRECTORY}/printed.mir" + RESULT_VARIABLE PrintResult + ERROR_VARIABLE PrintDiagnostics +) +if(NOT PrintResult EQUAL 0) + message(FATAL_ERROR "pass snapshot controls failed: ${PrintDiagnostics}") +endif() +if(NOT PrintDiagnostics MATCHES "[*][*][*] prelegalizer-mir Legalizer#1" OR + NOT PrintDiagnostics MATCHES "[*][*][*] legalized-mir Legalizer#1") + message(FATAL_ERROR "before/after pass snapshots are incomplete") +endif() + +execute_process( + COMMAND + "${TOOL}" --input "${INPUT}" --emit final-mir --stage-snapshots --output + "${WORK_DIRECTORY}/snapshot-final.mir" + RESULT_VARIABLE SnapshotResult + ERROR_VARIABLE SnapshotDiagnostics +) +if(NOT SnapshotResult EQUAL 0) + message(FATAL_ERROR "stage snapshot execution failed: ${SnapshotDiagnostics}") +endif() +foreach(Stage IN LISTS Stages) + if(NOT SnapshotDiagnostics MATCHES "[*][*][*] ${Stage}") + message(FATAL_ERROR "stage snapshots are missing ${Stage}") + endif() +endforeach() + +file(REMOVE_RECURSE "${WORK_DIRECTORY}") |
