[spirv] Dump spirv.module with dump-executable-intermediates-to= (#14058)
This would make debugging easier when we would like to inspect the
generated `spirv.module` contents.
diff --git a/compiler/src/iree/compiler/Dialect/HAL/Target/VulkanSPIRV/VulkanSPIRVTarget.cpp b/compiler/src/iree/compiler/Dialect/HAL/Target/VulkanSPIRV/VulkanSPIRVTarget.cpp
index 8f160d7..c82c283 100644
--- a/compiler/src/iree/compiler/Dialect/HAL/Target/VulkanSPIRV/VulkanSPIRVTarget.cpp
+++ b/compiler/src/iree/compiler/Dialect/HAL/Target/VulkanSPIRV/VulkanSPIRVTarget.cpp
@@ -22,6 +22,7 @@
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/ToolOutputFile.h"
+#include "llvm/Support/raw_ostream.h"
#include "mlir/AsmParser/AsmParser.h"
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h"
@@ -141,6 +142,13 @@
<< "should only contain exactly one spirv.module op";
}
auto spvModuleOp = *spirvModuleOps.begin();
+ if (!options.dumpIntermediatesPath.empty()) {
+ std::string assembly;
+ llvm::raw_string_ostream os(assembly);
+ spvModuleOp.print(os, OpPrintingFlags().useLocalScope());
+ dumpDataToPath(options.dumpIntermediatesPath, options.dumpBaseName,
+ variantOp.getName(), ".mlir", assembly);
+ }
FlatbufferBuilder builder;
iree_hal_spirv_ExecutableDef_start_as_root(builder);