diff options
| author | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-12 04:21:14 +0800 |
|---|---|---|
| committer | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-12 04:21:14 +0800 |
| commit | 1775d50ba02dab033c639f5c8fedd46cb6613bef (patch) | |
| tree | b4ca387ff0015862cdf90a8652ad35402fa9af69 /backend | |
| parent | 64c0360a6646dd1d3f75b8d1ed11ec4da825256b (diff) | |
| download | rcc-project-1775d50ba02dab033c639f5c8fedd46cb6613bef.tar.gz rcc-project-1775d50ba02dab033c639f5c8fedd46cb6613bef.tar.xz | |
[Tooling] Adopt LLVM MIR command-line spellings
Diffstat (limited to 'backend')
| -rw-r--r-- | backend/include/rcc/CodeGen/MachineCombinerPattern.h | 1 | ||||
| -rw-r--r-- | backend/include/rcc/Tooling/PipelineDriver.h | 1 | ||||
| -rw-r--r-- | backend/lib/CodeGen/MachineCombiner.cpp | 18 | ||||
| -rw-r--r-- | backend/lib/CodeGen/MachinePipelinePasses.cpp | 18 | ||||
| -rw-r--r-- | backend/lib/Target/RISCV/RISCVPipeline.cpp | 13 | ||||
| -rw-r--r-- | backend/lib/Tooling/BackendDriver.cpp | 9 | ||||
| -rw-r--r-- | backend/lib/Tooling/PipelineDriver.cpp | 6 | ||||
| -rw-r--r-- | backend/tools/MIRTool/MIRToolMain.cpp | 92 | ||||
| -rw-r--r-- | backend/tools/MIRTool/MIRToolOperationsTest.cmake | 46 | ||||
| -rw-r--r-- | backend/tools/MIRTool/MIRToolOutputTest.cmake | 4 | ||||
| -rw-r--r-- | backend/tools/MIRTool/MIRToolStageTest.cmake | 70 | ||||
| -rw-r--r-- | backend/unittests/Tooling/BackendManifestTest.cpp | 2 | ||||
| -rw-r--r-- | backend/unittests/Tooling/MIRReducerFuzzerTest.cpp | 4 | ||||
| -rw-r--r-- | backend/unittests/Tooling/PipelineDriverTest.cpp | 18 |
14 files changed, 202 insertions, 100 deletions
diff --git a/backend/include/rcc/CodeGen/MachineCombinerPattern.h b/backend/include/rcc/CodeGen/MachineCombinerPattern.h index 69df70a..0701250 100644 --- a/backend/include/rcc/CodeGen/MachineCombinerPattern.h +++ b/backend/include/rcc/CodeGen/MachineCombinerPattern.h @@ -16,6 +16,7 @@ namespace rcc { enum class MachineCombinerStage : std::uint8_t { + PreLegalizer, SelectedSSA, PreRegisterAllocation, PostRegisterAllocation, diff --git a/backend/include/rcc/Tooling/PipelineDriver.h b/backend/include/rcc/Tooling/PipelineDriver.h index 2de341c..d6c9f58 100644 --- a/backend/include/rcc/Tooling/PipelineDriver.h +++ b/backend/include/rcc/Tooling/PipelineDriver.h @@ -44,6 +44,7 @@ struct PipelineControls final { bool CaptureStageSnapshots = false; bool VerifyEach = true; bool DetectUnreportedChanges = true; + bool SimplifyMIR = false; }; struct PipelineSnapshot final { diff --git a/backend/lib/CodeGen/MachineCombiner.cpp b/backend/lib/CodeGen/MachineCombiner.cpp index 54915ab..9a87b6f 100644 --- a/backend/lib/CodeGen/MachineCombiner.cpp +++ b/backend/lib/CodeGen/MachineCombiner.cpp @@ -25,6 +25,20 @@ namespace rcc { namespace { [[nodiscard]] const MachinePassContract &combinerContract(MachineCombinerStage Stage) { + static const MachinePassContract PreLegalizer = [] { + MachinePassContract Value{ + .Name = "riscv-prelegalizer-combiner", + .Requires = {MachineFunctionProperty::IsSSA}, + .Sets = {}, + .Clears = {}, + .RequiredAnalyses = {}, + .VerificationStage = PipelineStage::MachineIRInput, + }; + Value.ThreadSafety = PassThreadSafety::ThreadSafe; + Value.DeclaredChanges = {MachinePassChange::Instructions, MachinePassChange::Operands, + MachinePassChange::Registers}; + return Value; + }(); static const MachinePassContract SelectedSSA = [] { MachinePassContract Value{ .Name = "machine-combiner-selected-ssa", @@ -85,6 +99,8 @@ namespace { return Value; }(); switch (Stage) { + case MachineCombinerStage::PreLegalizer: + return PreLegalizer; case MachineCombinerStage::SelectedSSA: return SelectedSSA; case MachineCombinerStage::PreRegisterAllocation: @@ -94,7 +110,7 @@ namespace { case MachineCombinerStage::PostFrame: return PostFrame; } - return SelectedSSA; + return PreLegalizer; } [[nodiscard]] Error prefixedError(const Error &Failure, std::string Prefix) { diff --git a/backend/lib/CodeGen/MachinePipelinePasses.cpp b/backend/lib/CodeGen/MachinePipelinePasses.cpp index 9bde291..3dae07e 100644 --- a/backend/lib/CodeGen/MachinePipelinePasses.cpp +++ b/backend/lib/CodeGen/MachinePipelinePasses.cpp @@ -24,7 +24,7 @@ namespace { [[nodiscard]] const MachinePassContract &legalizerContract() { static const MachinePassContract Contract{ - .Name = "Legalizer", + .Name = "legalizer", // LLVM's GlobalISel legalizer operates on SSA form and does not require // the optional register-liveness tracking property. .Requires = {MachineFunctionProperty::IsSSA}, @@ -38,7 +38,7 @@ namespace { [[nodiscard]] const MachinePassContract &bankSelectContract() { static const MachinePassContract Contract{ - .Name = "RegisterBankSelect", + .Name = "regbankselect", .Requires = {MachineFunctionProperty::Legalized}, .Sets = {MachineFunctionProperty::RegBankSelected}, .Clears = {}, @@ -50,7 +50,7 @@ namespace { [[nodiscard]] const MachinePassContract &instructionSelectContract() { static const MachinePassContract Contract{ - .Name = "InstructionSelect", + .Name = "instruction-select", .Requires = {MachineFunctionProperty::Legalized, MachineFunctionProperty::RegBankSelected}, .Sets = {MachineFunctionProperty::Selected}, .Clears = {}, @@ -281,8 +281,7 @@ registerConfigurationFingerprint(const MachineRegisterInfo &RegInfo) noexcept { [[nodiscard]] Expected<void> clearTrackedLivenessFlags(MachineFunction &Function, MachinePassResult &Result) { - if (!Result.Changed || - !Function.properties().has(MachineFunctionProperty::TracksLiveness)) + if (!Result.Changed || !Function.properties().has(MachineFunctionProperty::TracksLiveness)) return {}; bool Changed = false; for (MachineInstr *Instruction : layoutInstructions(Function)) { @@ -291,8 +290,7 @@ registerConfigurationFingerprint(const MachineRegisterInfo &RegInfo) noexcept { if (!Operand.isRegister()) continue; RegisterOperandFlags Flags = Operand.registerFlags(); - if (!Flags.has(RegisterOperandFlag::Kill) && - !Flags.has(RegisterOperandFlag::Dead)) + if (!Flags.has(RegisterOperandFlag::Kill) && !Flags.has(RegisterOperandFlag::Dead)) continue; Flags.clear(RegisterOperandFlag::Kill); Flags.clear(RegisterOperandFlag::Dead); @@ -413,9 +411,9 @@ Expected<MachinePassResult> LegalizerPass::runImplementation(MachineFunction &Fu if (!InstructionWasErased) { const OpcodeState After = stateOf(*Instruction); if (After == Before) - return std::unexpected(passFailure( - "target legalizer made no observable progress for '" + Descriptor->Name + "'", - ErrorCode::InternalError)); + return std::unexpected(passFailure("target legalizer made no observable progress for '" + + Descriptor->Name + "'", + ErrorCode::InternalError)); } Result.Changed = true; Result.Changes.add(MachinePassChange::Instructions); diff --git a/backend/lib/Target/RISCV/RISCVPipeline.cpp b/backend/lib/Target/RISCV/RISCVPipeline.cpp index 05d26b3..d995060 100644 --- a/backend/lib/Target/RISCV/RISCVPipeline.cpp +++ b/backend/lib/Target/RISCV/RISCVPipeline.cpp @@ -2,6 +2,7 @@ #include "rcc/Target/RISCV/RISCVPipeline.h" +#include "rcc/CodeGen/MachineCombiner.h" #include "rcc/CodeGen/MachineFunction.h" #include "rcc/CodeGen/MachineOptimizationPipeline.h" #include "rcc/CodeGen/MachinePipelinePasses.h" @@ -27,7 +28,11 @@ template <typename PassT, typename... ArgumentT> [[nodiscard]] Expected<void> addInitialPipeline(MachinePassManager &Pipeline, RISCVSubtargetFeatures Features) { - auto Added = addPass<LegalizerPass>(Pipeline, createLegalizerInfo(Features)); + auto Added = addPass<MachineCombinerPass>(Pipeline, machineCombinerInfo(), + MachineCombinerStage::PreLegalizer); + if (!Added) + return std::unexpected(Added.error()); + Added = addPass<LegalizerPass>(Pipeline, createLegalizerInfo(Features)); if (!Added) return std::unexpected(Added.error()); Added = addPass<RegisterBankSelectPass>(Pipeline, registerBankInfo()); @@ -76,7 +81,11 @@ Expected<void> addCanonicalPipeline(MachinePassManager &Pipeline, const MachineF Expected<void> addCanonicalPipeline(MachinePassManager &Pipeline, const MachineFunction &Function, RISCVSubtargetFeatures Features) { if (!Function.properties().has(MachineFunctionProperty::Legalized)) { - auto Added = addPass<LegalizerPass>(Pipeline, createLegalizerInfo(Features)); + auto Added = addPass<MachineCombinerPass>(Pipeline, machineCombinerInfo(), + MachineCombinerStage::PreLegalizer); + if (!Added) + return std::unexpected(Added.error()); + Added = addPass<LegalizerPass>(Pipeline, createLegalizerInfo(Features)); if (!Added) return std::unexpected(Added.error()); } diff --git a/backend/lib/Tooling/BackendDriver.cpp b/backend/lib/Tooling/BackendDriver.cpp index 2a2a500..fff58c5 100644 --- a/backend/lib/Tooling/BackendDriver.cpp +++ b/backend/lib/Tooling/BackendDriver.cpp @@ -49,9 +49,10 @@ namespace { [[nodiscard]] Expected<std::vector<std::uint8_t>> printMIR(const mir::MIRDocument &Document, const TargetDescription &Target, - const BackendInvocation &Invocation) { + const BackendInvocation &Invocation, + bool Simplify) { mir::MIRDocumentPrinterOptions Options; - Options.Mode = mir::MIPrintMode::Complete; + Options.Mode = Simplify ? mir::MIPrintMode::Readable : mir::MIPrintMode::Complete; Options.EmitEmbeddedIR = true; Options.DataLayout = Invocation.DataLayout; auto Printed = mir::printMIRDocument(Document, Target, std::move(Options)); @@ -103,6 +104,8 @@ Expected<BackendRunResult> runBackend(CanonicalMIR Input, const TargetDescriptio Controls.StopAtStage = RequiredStage; } + const bool SimplifyMIR = Controls.SimplifyMIR; + MachinePassInstrumentation LocalInstrumentation; MachinePassInstrumentation *ActiveInstrumentation = Instrumentation == nullptr ? &LocalInstrumentation : Instrumentation; @@ -113,7 +116,7 @@ Expected<BackendRunResult> runBackend(CanonicalMIR Input, const TargetDescriptio std::vector<std::uint8_t> Bytes; if (isMIR(Output)) { - auto Printed = printMIR(Input.Document, Target, Invocation); + auto Printed = printMIR(Input.Document, Target, Invocation, SimplifyMIR); if (!Printed) return std::unexpected(Printed.error()); Bytes = std::move(*Printed); diff --git a/backend/lib/Tooling/PipelineDriver.cpp b/backend/lib/Tooling/PipelineDriver.cpp index 4dab499..620367f 100644 --- a/backend/lib/Tooling/PipelineDriver.cpp +++ b/backend/lib/Tooling/PipelineDriver.cpp @@ -55,11 +55,11 @@ struct FunctionRunResult final { } [[nodiscard]] std::optional<BackendStage> stageAfterPass(std::string_view Pass) noexcept { - if (Pass == "Legalizer") + if (Pass == "legalizer") return BackendStage::LegalizedMIR; - if (Pass == "RegisterBankSelect") + if (Pass == "regbankselect") return BackendStage::RegisterBankMIR; - if (Pass == "InstructionSelect") + if (Pass == "instruction-select") return BackendStage::SelectedMIR; if (Pass == "TwoAddressRewrite") return BackendStage::PostSSAMIR; diff --git a/backend/tools/MIRTool/MIRToolMain.cpp b/backend/tools/MIRTool/MIRToolMain.cpp index f764cf0..ea180d6 100644 --- a/backend/tools/MIRTool/MIRToolMain.cpp +++ b/backend/tools/MIRTool/MIRToolMain.cpp @@ -81,15 +81,17 @@ void printUsage(std::ostream &Output) { " --fuzz <layer,...|all> Run deterministic layered fuzzing\n" " --list-passes List the canonical pipeline suffix\n" "pipeline/output:\n" - " --run-pass <name> Run one named pass\n" - " --passes <name,...> Run an explicit pass sequence\n" - " --stop-before <pass[#N]> Stop before a pass occurrence\n" - " --stop-after <pass[#N]> Stop after a pass occurrence\n" - " --print-before <pass[#N],...> Print snapshots before passes\n" - " --print-after <pass[#N],...> Print snapshots after passes\n" + " -run-pass <name> Run one named pass\n" + " -passes <name,...> Run an explicit pass sequence\n" + " -stop-before <pass[#N]> Stop before a pass occurrence\n" + " -stop-after <pass[#N]> Stop after a pass occurrence\n" + " -print-before <pass[#N],...> Print snapshots before passes\n" + " -print-after <pass[#N],...> Print snapshots after passes\n" + " -simplify-mir Omit default-valued MIR fields\n" + " -verify-machineinstrs Verify each machine pass result\n" " --stage-snapshots Print every stage boundary\n" " --emit <stage|assembly|object> Select the output artifact\n" - " -o, --output <file|-> Select the output path\n" + " -o <file|-> Select the output path\n" "reproduction/cache/fuzz:\n" " --crash-reproducer <path> Save input and manifest before execution\n" " --cache-dir <path> Select the content-addressed cache root\n" @@ -102,10 +104,11 @@ void printUsage(std::ostream &Output) { " --enable-action <name> Enable an Action ID component\n" " --print-actions Print stable Action decisions\n" " -O0|-O1|-O2|-O3|-Os|-Oz Optimization level identity\n" - " --relocation-model <static|pic>\n" - " --code-model <small|medium|large>\n" + " -relocation-model <static|pic>\n" + " -code-model <small|medium|large>\n" " --layout <native-object|compiler-final-layout|external-relaxation>\n" - " --cpu/--tune-cpu/--features/--abi/--data-layout <value>\n" + " -mtriple/-mcpu/-mtune/-mattr/-target-abi <value>\n" + " --data-layout <value> Override the MIR data layout\n" " --target-option <name=value> Explicit target option\n" " --assembler-option <name=value>\n" " --assembler-flavor/--assembler-version <value>\n"; @@ -160,6 +163,24 @@ template <typename IntegerT> return Result; } +void applyFeatureOverrides(std::vector<std::string> Overrides, std::vector<std::string> &Features) { + for (std::string &Override : Overrides) { + if (!Override.empty() && Override.front() != '+' && Override.front() != '-') + Override.insert(Override.begin(), '+'); + const std::string_view Name = std::string_view(Override).substr(1); + std::erase_if(Features, [Name](const std::string &Feature) { + return Feature.size() > 1 && std::string_view(Feature).substr(1) == Name; + }); + Features.push_back(std::move(Override)); + } +} + +[[nodiscard]] std::string normalizeRV64Triple(std::string_view Triple) { + if (Triple == "riscv64" || Triple == "riscv64-linux-gnu") + return "riscv64-unknown-linux-gnu"; + return std::string(Triple); +} + [[nodiscard]] Expected<rcc::tooling::BackendOption> parseBackendOption(std::string_view Text, std::string_view Category) { const std::size_t Equal = Text.find('='); @@ -238,6 +259,14 @@ template <typename IntegerT> Command.Controls.CaptureStageSnapshots = true; continue; } + if (Argument == "-simplify-mir") { + Command.Controls.SimplifyMIR = true; + continue; + } + if (Argument == "-verify-machineinstrs") { + Command.Controls.VerifyEach = true; + continue; + } if (Argument == "--no-verify-each") { Command.Controls.VerifyEach = false; continue; @@ -268,11 +297,7 @@ template <typename IntegerT> Command.InputPath = std::string(**Input); continue; } - auto Output = takeOption(Argument, "--output", Index, ArgumentCount, Arguments); - if (!Output) - return std::unexpected(Output.error()); - if (!*Output && Argument == "-o") - Output = takeOption(Argument, "-o", Index, ArgumentCount, Arguments); + auto Output = takeOption(Argument, "-o", Index, ArgumentCount, Arguments); if (!Output) return std::unexpected(Output.error()); if (*Output) { @@ -291,24 +316,24 @@ template <typename IntegerT> Command.OutputWasSpecified = true; continue; } - auto RunPass = takeOption(Argument, "--run-pass", Index, ArgumentCount, Arguments); + auto RunPass = takeOption(Argument, "-run-pass", Index, ArgumentCount, Arguments); if (!RunPass) return std::unexpected(RunPass.error()); if (*RunPass) { if (ExplicitPipeline) return rcc::makeUnexpected(ErrorCode::InvalidInvocation, - "--run-pass and --passes cannot be combined"); + "-run-pass and -passes cannot be combined"); Command.Invocation.PassPipeline = {std::string(**RunPass)}; ExplicitPipeline = true; continue; } - auto Passes = takeOption(Argument, "--passes", Index, ArgumentCount, Arguments); + auto Passes = takeOption(Argument, "-passes", Index, ArgumentCount, Arguments); if (!Passes) return std::unexpected(Passes.error()); if (*Passes) { if (ExplicitPipeline) return rcc::makeUnexpected(ErrorCode::InvalidInvocation, - "--run-pass and --passes cannot be combined"); + "-run-pass and -passes cannot be combined"); auto Names = splitList(**Passes, "pass pipeline"); if (!Names) return std::unexpected(Names.error()); @@ -327,12 +352,12 @@ template <typename IntegerT> Destination = std::string(**Value); return true; }; - auto StopBefore = ParseSelector("--stop-before", Command.Controls.StopBefore); + auto StopBefore = ParseSelector("-stop-before", Command.Controls.StopBefore); if (!StopBefore) return std::unexpected(StopBefore.error()); if (*StopBefore) continue; - auto StopAfter = ParseSelector("--stop-after", Command.Controls.StopAfter); + auto StopAfter = ParseSelector("-stop-after", Command.Controls.StopAfter); if (!StopAfter) return std::unexpected(StopAfter.error()); if (*StopAfter) @@ -352,12 +377,12 @@ template <typename IntegerT> std::make_move_iterator(Selectors->end())); return true; }; - auto PrintBefore = ParseSelectorList("--print-before", Command.Controls.PrintBefore); + auto PrintBefore = ParseSelectorList("-print-before", Command.Controls.PrintBefore); if (!PrintBefore) return std::unexpected(PrintBefore.error()); if (*PrintBefore) continue; - auto PrintAfter = ParseSelectorList("--print-after", Command.Controls.PrintAfter); + auto PrintAfter = ParseSelectorList("-print-after", Command.Controls.PrintAfter); if (!PrintAfter) return std::unexpected(PrintAfter.error()); if (*PrintAfter) @@ -490,17 +515,24 @@ template <typename IntegerT> Destination = std::string(**Value); return true; }; - auto CPU = ParseString("--cpu", Command.Invocation.CPU); + auto Triple = takeOption(Argument, "-mtriple", Index, ArgumentCount, Arguments); + if (!Triple) + return std::unexpected(Triple.error()); + if (*Triple) { + Command.Invocation.Triple = normalizeRV64Triple(**Triple); + continue; + } + auto CPU = ParseString("-mcpu", Command.Invocation.CPU); if (!CPU) return std::unexpected(CPU.error()); if (*CPU) continue; - auto TuneCPU = ParseString("--tune-cpu", Command.Invocation.TuneCPU); + auto TuneCPU = ParseString("-mtune", Command.Invocation.TuneCPU); if (!TuneCPU) return std::unexpected(TuneCPU.error()); if (*TuneCPU) continue; - auto ABI = ParseString("--abi", Command.Invocation.ABI); + auto ABI = ParseString("-target-abi", Command.Invocation.ABI); if (!ABI) return std::unexpected(ABI.error()); if (*ABI) @@ -520,17 +552,17 @@ template <typename IntegerT> return std::unexpected(AssemblerVersion.error()); if (*AssemblerVersion) continue; - auto Features = takeOption(Argument, "--features", Index, ArgumentCount, Arguments); + auto Features = takeOption(Argument, "-mattr", Index, ArgumentCount, Arguments); if (!Features) return std::unexpected(Features.error()); if (*Features) { auto Values = splitList(**Features, "target feature list"); if (!Values) return std::unexpected(Values.error()); - Command.Invocation.Features = std::move(*Values); + applyFeatureOverrides(std::move(*Values), Command.Invocation.Features); continue; } - auto Relocation = takeOption(Argument, "--relocation-model", Index, ArgumentCount, Arguments); + auto Relocation = takeOption(Argument, "-relocation-model", Index, ArgumentCount, Arguments); if (!Relocation) return std::unexpected(Relocation.error()); if (*Relocation) { @@ -540,7 +572,7 @@ template <typename IntegerT> Command.Invocation.Relocation = *Value; continue; } - auto Code = takeOption(Argument, "--code-model", Index, ArgumentCount, Arguments); + auto Code = takeOption(Argument, "-code-model", Index, ArgumentCount, Arguments); if (!Code) return std::unexpected(Code.error()); if (*Code) { diff --git a/backend/tools/MIRTool/MIRToolOperationsTest.cmake b/backend/tools/MIRTool/MIRToolOperationsTest.cmake index 003e868..8dee32f 100644 --- a/backend/tools/MIRTool/MIRToolOperationsTest.cmake +++ b/backend/tools/MIRTool/MIRToolOperationsTest.cmake @@ -9,7 +9,7 @@ file(MAKE_DIRECTORY "${WORK_DIRECTORY}") set(StandardInputMIR "${WORK_DIRECTORY}/stdin.mir") execute_process( - COMMAND "${TOOL}" --verify - --output "${StandardInputMIR}" + COMMAND "${TOOL}" --verify - -o "${StandardInputMIR}" INPUT_FILE "${INPUT}" RESULT_VARIABLE StandardInputResult ERROR_VARIABLE StandardInputDiagnostics @@ -28,7 +28,7 @@ set(ReloadedAssembly "${WORK_DIRECTORY}/reloaded.s") execute_process( COMMAND "${TOOL}" --input "${INPUT}" --emit assembly --cache-dir "${CacheDirectory}" - --cache-policy write --output "${CachedAssembly}" + --cache-policy write -o "${CachedAssembly}" RESULT_VARIABLE CacheWriteResult ERROR_VARIABLE CacheWriteDiagnostics ) @@ -38,7 +38,7 @@ endif() execute_process( COMMAND "${TOOL}" --input "${INPUT}" --emit assembly --cache-dir "${CacheDirectory}" - --cache-policy read --output "${ReloadedAssembly}" + --cache-policy read -o "${ReloadedAssembly}" RESULT_VARIABLE CacheReadResult ERROR_VARIABLE CacheReadDiagnostics ) @@ -56,7 +56,7 @@ endif() execute_process( COMMAND "${TOOL}" --input "${INPUT}" --emit assembly --cache-dir - "${WORK_DIRECTORY}/empty-cache" --cache-policy read --output "${WORK_DIRECTORY}/miss.s" + "${WORK_DIRECTORY}/empty-cache" --cache-policy read -o "${WORK_DIRECTORY}/miss.s" RESULT_VARIABLE CacheMissResult ERROR_VARIABLE CacheMissDiagnostics ) @@ -74,7 +74,7 @@ file(WRITE "${CachedArtifact}" "corrupt") execute_process( COMMAND "${TOOL}" --input "${INPUT}" --emit assembly --cache-dir "${CacheDirectory}" - --cache-policy read --output "${WORK_DIRECTORY}/corrupt.s" + --cache-policy read -o "${WORK_DIRECTORY}/corrupt.s" RESULT_VARIABLE CorruptCacheResult ERROR_VARIABLE CorruptCacheDiagnostics ) @@ -88,7 +88,7 @@ set(ReplayedAssembly "${WORK_DIRECTORY}/success-replayed.s") execute_process( COMMAND "${TOOL}" --input "${INPUT}" --emit assembly --crash-reproducer "${SuccessReproducer}" - --output "${SuccessAssembly}" + -o "${SuccessAssembly}" RESULT_VARIABLE ReproducerWriteResult ERROR_VARIABLE ReproducerWriteDiagnostics ) @@ -96,7 +96,7 @@ if(NOT ReproducerWriteResult EQUAL 0) message(FATAL_ERROR "successful reproducer publication failed: ${ReproducerWriteDiagnostics}") endif() execute_process( - COMMAND "${TOOL}" --reproduce "${SuccessReproducer}" --output "${ReplayedAssembly}" + COMMAND "${TOOL}" --reproduce "${SuccessReproducer}" -o "${ReplayedAssembly}" RESULT_VARIABLE ReproducerReplayResult ERROR_VARIABLE ReproducerReplayDiagnostics ) @@ -113,7 +113,7 @@ endif() set(RegBankInput "${WORK_DIRECTORY}/regbank.mir") execute_process( - COMMAND "${TOOL}" --input "${INPUT}" --emit regbank-mir --output "${RegBankInput}" + COMMAND "${TOOL}" --input "${INPUT}" --emit regbank-mir -o "${RegBankInput}" RESULT_VARIABLE RegBankResult ERROR_VARIABLE RegBankDiagnostics ) @@ -124,8 +124,8 @@ endif() set(FailureReproducer "${WORK_DIRECTORY}/failure-reproducer") execute_process( COMMAND - "${TOOL}" --input "${RegBankInput}" --run-pass InstructionSelect --emit selected-mir - --fuel 0 --crash-reproducer "${FailureReproducer}" --output "${WORK_DIRECTORY}/failure.mir" + "${TOOL}" --input "${RegBankInput}" -run-pass instruction-select --emit selected-mir + --fuel 0 --crash-reproducer "${FailureReproducer}" -o "${WORK_DIRECTORY}/failure.mir" RESULT_VARIABLE FailureResult ERROR_VARIABLE FailureDiagnostics ) @@ -134,12 +134,12 @@ if(FailureResult EQUAL 0 OR message(FATAL_ERROR "zero Action fuel did not produce the expected failure") endif() file(READ "${FailureReproducer}/manifest.yaml" FailureManifest) -if(NOT FailureManifest MATCHES "InstructionSelect" OR +if(NOT FailureManifest MATCHES "instruction-select" OR NOT FailureManifest MATCHES "required selection action was rejected") message(FATAL_ERROR "failure reproducer did not record structured pass diagnostics") endif() execute_process( - COMMAND "${TOOL}" --reproduce "${FailureReproducer}" --output "${WORK_DIRECTORY}/replay.mir" + COMMAND "${TOOL}" --reproduce "${FailureReproducer}" -o "${WORK_DIRECTORY}/replay.mir" RESULT_VARIABLE FailureReplayResult ERROR_VARIABLE FailureReplayDiagnostics ) @@ -151,12 +151,12 @@ endif() set(ActionOutput "${WORK_DIRECTORY}/selected.mir") execute_process( COMMAND - "${TOOL}" --input "${RegBankInput}" --run-pass InstructionSelect --emit selected-mir - --print-actions --output "${ActionOutput}" + "${TOOL}" --input "${RegBankInput}" -run-pass instruction-select --emit selected-mir + --print-actions -o "${ActionOutput}" RESULT_VARIABLE ActionResult ERROR_VARIABLE ActionDiagnostics ) -if(NOT ActionResult EQUAL 0 OR NOT ActionDiagnostics MATCHES "accepted InstructionSelect") +if(NOT ActionResult EQUAL 0 OR NOT ActionDiagnostics MATCHES "accepted instruction-select") message(FATAL_ERROR "successful Action execution did not report stable decisions") endif() @@ -172,7 +172,7 @@ set(CanonicalReducerSeed "${WORK_DIRECTORY}/reducer-seed.canonical.mir") set(ReducedMIR "${WORK_DIRECTORY}/reduced.mir") file(WRITE "${ReducerSeed}" "${ReducerSeedText}") execute_process( - COMMAND "${TOOL}" --verify --input "${ReducerSeed}" --output "${CanonicalReducerSeed}" + COMMAND "${TOOL}" --verify --input "${ReducerSeed}" -o "${CanonicalReducerSeed}" RESULT_VARIABLE ReducerSeedResult ERROR_VARIABLE ReducerSeedDiagnostics ) @@ -180,7 +180,7 @@ if(NOT ReducerSeedResult EQUAL 0) message(FATAL_ERROR "reducer seed failed canonicalization: ${ReducerSeedDiagnostics}") endif() execute_process( - COMMAND "${TOOL}" --reduce validity --input "${ReducerSeed}" --output "${ReducedMIR}" + COMMAND "${TOOL}" --reduce validity --input "${ReducerSeed}" -o "${ReducedMIR}" RESULT_VARIABLE ValidityReducerResult ERROR_VARIABLE ValidityReducerDiagnostics ) @@ -204,8 +204,8 @@ endif() set(FailureReducedMIR "${WORK_DIRECTORY}/failure-reduced.mir") execute_process( COMMAND - "${TOOL}" --reduce failure --input "${RegBankInput}" --run-pass InstructionSelect - --emit selected-mir --fuel 0 --output "${FailureReducedMIR}" + "${TOOL}" --reduce failure --input "${RegBankInput}" -run-pass instruction-select + --emit selected-mir --fuel 0 -o "${FailureReducedMIR}" RESULT_VARIABLE FailureReducerResult ERROR_VARIABLE FailureReducerDiagnostics ) @@ -214,8 +214,8 @@ if(NOT FailureReducerResult EQUAL 0) endif() execute_process( COMMAND - "${TOOL}" --input "${FailureReducedMIR}" --run-pass InstructionSelect --emit selected-mir - --fuel 0 --output "${WORK_DIRECTORY}/failure-reduced-output.mir" + "${TOOL}" --input "${FailureReducedMIR}" -run-pass instruction-select --emit selected-mir + --fuel 0 -o "${WORK_DIRECTORY}/failure-reduced-output.mir" RESULT_VARIABLE ReducedFailureResult ERROR_VARIABLE ReducedFailureDiagnostics ) @@ -228,7 +228,7 @@ set(FirstFuzz "${WORK_DIRECTORY}/fuzz-1.txt") set(SecondFuzz "${WORK_DIRECTORY}/fuzz-2.txt") execute_process( COMMAND - "${TOOL}" --fuzz all --fuzz-iterations 2 --seed 123 --input "${INPUT}" --output + "${TOOL}" --fuzz all --fuzz-iterations 2 --seed 123 --input "${INPUT}" -o "${FirstFuzz}" RESULT_VARIABLE FirstFuzzResult ERROR_VARIABLE FirstFuzzDiagnostics @@ -238,7 +238,7 @@ if(NOT FirstFuzzResult EQUAL 0) endif() execute_process( COMMAND - "${TOOL}" --fuzz all --fuzz-iterations 2 --seed 123 --input "${INPUT}" --output + "${TOOL}" --fuzz all --fuzz-iterations 2 --seed 123 --input "${INPUT}" -o "${SecondFuzz}" RESULT_VARIABLE SecondFuzzResult ERROR_VARIABLE SecondFuzzDiagnostics diff --git a/backend/tools/MIRTool/MIRToolOutputTest.cmake b/backend/tools/MIRTool/MIRToolOutputTest.cmake index f8e4499..13159b8 100644 --- a/backend/tools/MIRTool/MIRToolOutputTest.cmake +++ b/backend/tools/MIRTool/MIRToolOutputTest.cmake @@ -10,7 +10,7 @@ file(MAKE_DIRECTORY "${OutputDirectory}") set(RepeatedOutput "${OUTPUT}.repeat") execute_process( - COMMAND "${TOOL}" --input "${INPUT}" --emit "${OUTPUT_KIND}" --output "${OUTPUT}" + COMMAND "${TOOL}" --input "${INPUT}" --emit "${OUTPUT_KIND}" -o "${OUTPUT}" RESULT_VARIABLE FirstResult ERROR_VARIABLE FirstDiagnostics ) @@ -18,7 +18,7 @@ if(NOT FirstResult EQUAL 0) message(FATAL_ERROR "${OUTPUT_KIND} production failed: ${FirstDiagnostics}") endif() execute_process( - COMMAND "${TOOL}" --input "${INPUT}" --emit "${OUTPUT_KIND}" --output "${RepeatedOutput}" + COMMAND "${TOOL}" --input "${INPUT}" --emit "${OUTPUT_KIND}" -o "${RepeatedOutput}" RESULT_VARIABLE SecondResult ERROR_VARIABLE SecondDiagnostics ) diff --git a/backend/tools/MIRTool/MIRToolStageTest.cmake b/backend/tools/MIRTool/MIRToolStageTest.cmake index 8247363..25c55c3 100644 --- a/backend/tools/MIRTool/MIRToolStageTest.cmake +++ b/backend/tools/MIRTool/MIRToolStageTest.cmake @@ -22,7 +22,7 @@ foreach(Stage IN LISTS Stages) set(RepeatedOutput "${WORK_DIRECTORY}/${Stage}.repeat.mir") set(CanonicalOutput "${WORK_DIRECTORY}/${Stage}.canonical.mir") execute_process( - COMMAND "${TOOL}" --input "${INPUT}" --emit "${Stage}" --output "${StageOutput}" + COMMAND "${TOOL}" --input "${INPUT}" --emit "${Stage}" -o "${StageOutput}" RESULT_VARIABLE StageResult ERROR_VARIABLE StageDiagnostics ) @@ -30,7 +30,7 @@ foreach(Stage IN LISTS Stages) message(FATAL_ERROR "${Stage} production failed: ${StageDiagnostics}") endif() execute_process( - COMMAND "${TOOL}" --input "${INPUT}" --emit "${Stage}" --output "${RepeatedOutput}" + COMMAND "${TOOL}" --input "${INPUT}" --emit "${Stage}" -o "${RepeatedOutput}" RESULT_VARIABLE RepeatedResult ERROR_VARIABLE RepeatedDiagnostics ) @@ -45,7 +45,7 @@ foreach(Stage IN LISTS Stages) message(FATAL_ERROR "${Stage} output is not deterministic") endif() execute_process( - COMMAND "${TOOL}" --verify --input "${StageOutput}" --output "${CanonicalOutput}" + COMMAND "${TOOL}" --verify --input "${StageOutput}" -o "${CanonicalOutput}" RESULT_VARIABLE VerifyResult ERROR_VARIABLE VerifyDiagnostics ) @@ -64,7 +64,7 @@ endforeach() set(NoPassOutput "${WORK_DIRECTORY}/none.mir") execute_process( COMMAND - "${TOOL}" --input "${INPUT}" --run-pass=none --emit final-mir --output "${NoPassOutput}" + "${TOOL}" --input "${INPUT}" -run-pass=none --emit final-mir -o "${NoPassOutput}" RESULT_VARIABLE NoPassResult ERROR_VARIABLE NoPassDiagnostics ) @@ -80,9 +80,49 @@ if(NOT NoPassComparisonResult EQUAL 0) message(FATAL_ERROR "LLVM-compatible none pass changed canonical MIR") endif() +set(LLVMContractOutput "${WORK_DIRECTORY}/llvm-contract.mir") +execute_process( + COMMAND + "${TOOL}" "${INPUT}" -run-pass=none -mtriple=riscv64 + -mattr=+m,+a,+f,+d,+c -relocation-model=pic -code-model=small -simplify-mir + -verify-machineinstrs -o "${LLVMContractOutput}" + RESULT_VARIABLE LLVMContractResult + ERROR_VARIABLE LLVMContractDiagnostics +) +if(NOT LLVMContractResult EQUAL 0) + message(FATAL_ERROR "LLVM llc-compatible invocation failed: ${LLVMContractDiagnostics}") +endif() +file(SIZE "${LLVMContractOutput}" LLVMContractOutputSize) +if(LLVMContractOutputSize EQUAL 0) + message(FATAL_ERROR "LLVM llc-compatible invocation produced no MIR") +endif() + +foreach( + RemovedOption + IN ITEMS + --run-pass=none + --passes=none + --stop-after=legalizer + --print-before=legalizer + --features=+m + --relocation-model=pic + --code-model=small + --output=- +) + execute_process( + COMMAND "${TOOL}" "${INPUT}" "${RemovedOption}" + RESULT_VARIABLE RemovedOptionResult + ERROR_VARIABLE RemovedOptionDiagnostics + ) + if(RemovedOptionResult EQUAL 0 OR + NOT RemovedOptionDiagnostics MATCHES "unknown command-line option") + message(FATAL_ERROR "removed option ${RemovedOption} remains accepted") + endif() +endforeach() + set(PassList "${WORK_DIRECTORY}/passes.txt") execute_process( - COMMAND "${TOOL}" --list-passes --input "${INPUT}" --output "${PassList}" + COMMAND "${TOOL}" --list-passes --input "${INPUT}" -o "${PassList}" RESULT_VARIABLE ListResult ERROR_VARIABLE ListDiagnostics ) @@ -90,7 +130,7 @@ 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) +foreach(RequiredPass IN ITEMS legalizer regbankselect instruction-select PrologueEpilogueInsertion) if(NOT PassListText MATCHES "(^|\n)${RequiredPass}(\n|$)") message(FATAL_ERROR "canonical pass list is missing ${RequiredPass}") endif() @@ -99,7 +139,7 @@ endforeach() set(LegalizedOutput "${WORK_DIRECTORY}/run-pass.mir") execute_process( COMMAND - "${TOOL}" --input "${INPUT}" --run-pass Legalizer --emit legalized-mir --output + "${TOOL}" --input "${INPUT}" -run-pass legalizer --emit legalized-mir -o "${LegalizedOutput}" RESULT_VARIABLE RunPassResult ERROR_VARIABLE RunPassDiagnostics @@ -111,8 +151,8 @@ endif() set(RegBankOutput "${WORK_DIRECTORY}/passes.mir") execute_process( COMMAND - "${TOOL}" --input "${INPUT}" --passes Legalizer,RegisterBankSelect --emit regbank-mir - --output "${RegBankOutput}" + "${TOOL}" --input "${INPUT}" -passes legalizer,regbankselect --emit regbank-mir -o + "${RegBankOutput}" RESULT_VARIABLE PassesResult ERROR_VARIABLE PassesDiagnostics ) @@ -123,7 +163,7 @@ endif() set(StoppedOutput "${WORK_DIRECTORY}/stopped.mir") execute_process( COMMAND - "${TOOL}" --input "${INPUT}" --stop-after Legalizer --emit final-mir --output + "${TOOL}" --input "${INPUT}" -stop-after legalizer --emit final-mir -o "${StoppedOutput}" RESULT_VARIABLE StopResult ERROR_VARIABLE StopDiagnostics @@ -142,22 +182,22 @@ endif() execute_process( COMMAND - "${TOOL}" --input "${INPUT}" --emit legalized-mir --print-before Legalizer --print-after - Legalizer --output "${WORK_DIRECTORY}/printed.mir" + "${TOOL}" --input "${INPUT}" --emit legalized-mir -print-before legalizer -print-after + legalizer -o "${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") +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 + "${TOOL}" --input "${INPUT}" --emit final-mir --stage-snapshots -o "${WORK_DIRECTORY}/snapshot-final.mir" RESULT_VARIABLE SnapshotResult ERROR_VARIABLE SnapshotDiagnostics diff --git a/backend/unittests/Tooling/BackendManifestTest.cpp b/backend/unittests/Tooling/BackendManifestTest.cpp index 5a6a0e9..36a023c 100644 --- a/backend/unittests/Tooling/BackendManifestTest.cpp +++ b/backend/unittests/Tooling/BackendManifestTest.cpp @@ -125,7 +125,7 @@ int main() { if (!keyDiffers(Base, Changed, Input, *Fingerprint)) return tooling_test::fail("cache key must include the optimization level"); Changed = Base; - Changed.PassPipeline = {"Legalizer"}; + Changed.PassPipeline = {"legalizer"}; if (!keyDiffers(Base, Changed, Input, *Fingerprint)) return tooling_test::fail("cache key must include the pass pipeline"); Changed = Base; diff --git a/backend/unittests/Tooling/MIRReducerFuzzerTest.cpp b/backend/unittests/Tooling/MIRReducerFuzzerTest.cpp index 9c95d75..9526a9f 100644 --- a/backend/unittests/Tooling/MIRReducerFuzzerTest.cpp +++ b/backend/unittests/Tooling/MIRReducerFuzzerTest.cpp @@ -90,7 +90,7 @@ int main() { } rcc::tooling::BackendInvocation PassInvocation = Invocation; - PassInvocation.PassPipeline = {"Legalizer", "RegisterBankSelect", "InstructionSelect"}; + PassInvocation.PassPipeline = {"legalizer", "regbankselect", "instruction-select"}; rcc::tooling::MIRReducerOptions PassOptions; PassOptions.Mode = rcc::tooling::ReductionMode::PreserveFailure; PassOptions.MaximumAttempts = 32; @@ -114,7 +114,7 @@ int main() { if (!RegBank) return tooling_test::fail(RegBank.error().message()); rcc::tooling::BackendInvocation FailureInvocation = Invocation; - FailureInvocation.PassPipeline = {"InstructionSelect"}; + FailureInvocation.PassPipeline = {"instruction-select"}; FailureInvocation.ActionFuel = 0; const auto PreservesActionFailure = [&](std::string_view MIR, const rcc::tooling::BackendInvocation &Candidate) { diff --git a/backend/unittests/Tooling/PipelineDriverTest.cpp b/backend/unittests/Tooling/PipelineDriverTest.cpp index 618bf33..273de52 100644 --- a/backend/unittests/Tooling/PipelineDriverTest.cpp +++ b/backend/unittests/Tooling/PipelineDriverTest.cpp @@ -103,7 +103,7 @@ int main() { rcc::tooling::BackendInvocation AtomicOnlyInvocation = Invocation; AtomicOnlyInvocation.Features = {"+a", "+zacas", "+zabha"}; - AtomicOnlyInvocation.PassPipeline = {"Legalizer"}; + AtomicOnlyInvocation.PassPipeline = {"legalizer"}; auto CanonicalAtomicOnly = AtomicOnlyInvocation.canonicalizeAndVerify(); if (!CanonicalAtomicOnly) return tooling_test::fail(CanonicalAtomicOnly.error().message()); @@ -194,8 +194,8 @@ int main() { if (!PrintInput) return tooling_test::fail(PrintInput.error().message()); rcc::tooling::PipelineControls PrintControls; - PrintControls.PrintBefore = {"Legalizer"}; - PrintControls.PrintAfter = {"Legalizer#1"}; + PrintControls.PrintBefore = {"legalizer"}; + PrintControls.PrintAfter = {"legalizer#1"}; auto PrintPoints = rcc::tooling::runRV64GCPipeline(PrintInput->Document, *Target, Invocation, PrintControls); if (!PrintPoints || PrintPoints->Snapshots.size() != 2 || @@ -209,22 +209,24 @@ int main() { if (!StopInput) return tooling_test::fail(StopInput.error().message()); rcc::tooling::PipelineControls StopControls; - StopControls.StopAfter = "Legalizer#1"; + StopControls.StopAfter = "legalizer#1"; auto Stopped = rcc::tooling::runRV64GCPipeline(StopInput->Document, *Target, Invocation, StopControls); const rcc::MachineFunction *StoppedFunction = StopInput->Document.unit().functionAt(0); if (!Stopped || StoppedFunction == nullptr || rcc::tooling::stageForFunction(*StoppedFunction) != rcc::tooling::BackendStage::LegalizedMIR || - Stopped->ExecutedPasses.size() != 1) { + Stopped->ExecutedPasses.size() != 2 || + Stopped->ExecutedPasses[0].Pass != "riscv-prelegalizer-combiner" || + Stopped->ExecutedPasses[1].Pass != "legalizer") { return tooling_test::fail("stop-after must stop at the selected pass occurrence"); } - StopControls.StopAfter = "Legalizer#0"; + StopControls.StopAfter = "legalizer#0"; if (rcc::tooling::runRV64GCPipeline(StopInput->Document, *Target, Invocation, StopControls)) return tooling_test::fail("pipeline controls must reject occurrence zero"); rcc::tooling::BackendInvocation MixedPipeline = Invocation; - MixedPipeline.PassPipeline = {"default", "Legalizer"}; + MixedPipeline.PassPipeline = {"default", "legalizer"}; auto MixedInput = rcc::tooling::parseAndCanonicalizeMIR("mixed-pipeline.mir", *Source, *Target, MixedPipeline); if (!MixedInput) @@ -263,7 +265,7 @@ int main() { if (!RegBankRun) return tooling_test::fail(RegBankRun.error().message()); rcc::tooling::BackendInvocation InstructionSelectInvocation = Invocation; - InstructionSelectInvocation.PassPipeline = {"InstructionSelect"}; + InstructionSelectInvocation.PassPipeline = {"instruction-select"}; InstructionSelectInvocation.ActionFuel = 0; auto RejectedInput = rcc::tooling::parseAndCanonicalizeMIR( "action-rejected.mir", std::string(RegBankRun->text()), *Target, InstructionSelectInvocation); |
