Skip to content

Commit b18e45c

Browse files
authored
[Codegen][ROCm] Add repro instructions for .rocmasm files (iree-org#21874)
The instructions will be printed inside the `.ll` files we already dump. `.rocmasm` files can be generated using the `llc` command, making bisecting llvm easier, since it doesn't require IREE to be in sync with MLIR and LLVM. Because `llc` is not built by default, you will have to run something like `ninja llc` to use it from within the IREE build.
1 parent 6dc81fd commit b18e45c

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

compiler/plugins/target/ROCM/ROCMTarget.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -711,29 +711,27 @@ class ROCMTargetBackend final : public TargetBackend {
711711
".linked.ll", *llvmModule);
712712
}
713713

714-
// For example 'gfx942'
714+
// For example 'gfx942'.
715715
StringRef targetCPU = targetMachine->getTargetCPU();
716716

717-
// For example 'amdgcn-amd-amdhsa'
717+
// For example 'amdgcn-amd-amdhsa'.
718718
std::string targetTriple = targetMachine->getTargetTriple().str();
719719

720720
// Run LLVM optimization passes.
721721
std::string passesString;
722722
optimizeModule(*llvmModule, *targetMachine, options.slpVectorization,
723723
passesString);
724724
if (!serializationOptions.dumpIntermediatesPath.empty()) {
725-
726725
// Additional context on '-mcpu' flag in PR comments, see for example:
727726
// https://github.com/iree-org/iree/pull/20716#issuecomment-2851650421
728-
std::string header =
729-
llvm::formatv(R"TXT(
730-
; To reproduce the .optimized.ll from the .linked.ll, run:
731-
; opt -S -mtriple={} -mcpu={} --passes='{}'
732-
; The flag '-S' to emit LLVMIR.
733-
; The behavior of some passes depends on '-mtriple' and '-mcpu'
727+
std::string header = llvm::formatv(
728+
R"TXT(; To reproduce the .optimized.ll from the .linked.ll, run:
729+
; opt -S -mtriple={} -mcpu={} --passes='{}' <.linked.ll>
730+
; The flag '-S' is to emit LLVMIR.
731+
; The behavior of some passes depends on '-mtriple' and '-mcpu'.
734732
735733
)TXT",
736-
targetTriple, targetCPU, passesString);
734+
targetTriple, targetCPU, passesString);
737735

738736
dumpModuleToPath(serializationOptions.dumpIntermediatesPath,
739737
serializationOptions.dumpBaseName, variantOp.getName(),
@@ -751,11 +749,18 @@ class ROCMTargetBackend final : public TargetBackend {
751749
llvm::errs() << "Error: cloning LLVM IR failed\n";
752750
return failure();
753751
}
752+
std::string asmHeader = llvm::formatv(
753+
R"TXT(; To reproduce the .rocmasm from .optimized.ll, run:
754+
; llc -mtriple={} -mcpu={} -mattr='{}' -O3 <.optimized.ll> -o <out.rocmasm>
755+
756+
)TXT",
757+
targetTriple, targetCPU, targetMachine->getTargetFeatureString());
758+
754759
std::string targetISA =
755760
translateModuleToISA(*moduleCopy.get(), *targetMachine);
756761
dumpDataToPath(serializationOptions.dumpIntermediatesPath,
757762
serializationOptions.dumpBaseName, variantOp.getName(),
758-
".rocmasm", targetISA);
763+
".rocmasm", asmHeader + targetISA);
759764
}
760765

761766
// Serialize hsaco kernel into the binary that we will embed in the

0 commit comments

Comments
 (0)