forked from OSchip/llvm-project
Use TranslateFromMLIRRegistration for SPIRV roundtrip (NFC)
This is aligning it with the other "translation" which operates on a MLIR input.
This commit is contained in:
parent
3c1b2e338d
commit
12541b5ed5
|
@ -115,23 +115,17 @@ void registerToSPIRVTranslation() {
|
||||||
// Round-trip registration
|
// Round-trip registration
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
static LogicalResult roundTripModule(llvm::SourceMgr &sourceMgr,
|
static LogicalResult roundTripModule(ModuleOp srcModule, bool emitDebugInfo,
|
||||||
bool emitDebugInfo, raw_ostream &output,
|
raw_ostream &output) {
|
||||||
MLIRContext *context) {
|
|
||||||
// Parse an MLIR module from the source manager.
|
|
||||||
auto srcModule = OwningModuleRef(parseSourceFile(sourceMgr, context));
|
|
||||||
if (!srcModule)
|
|
||||||
return failure();
|
|
||||||
|
|
||||||
SmallVector<uint32_t, 0> binary;
|
SmallVector<uint32_t, 0> binary;
|
||||||
|
MLIRContext *context = srcModule.getContext();
|
||||||
auto spirvModules = srcModule->getOps<spirv::ModuleOp>();
|
auto spirvModules = srcModule.getOps<spirv::ModuleOp>();
|
||||||
|
|
||||||
if (spirvModules.begin() == spirvModules.end())
|
if (spirvModules.begin() == spirvModules.end())
|
||||||
return srcModule->emitError("found no 'spv.module' op");
|
return srcModule.emitError("found no 'spv.module' op");
|
||||||
|
|
||||||
if (std::next(spirvModules.begin()) != spirvModules.end())
|
if (std::next(spirvModules.begin()) != spirvModules.end())
|
||||||
return srcModule->emitError("found more than one 'spv.module' op");
|
return srcModule.emitError("found more than one 'spv.module' op");
|
||||||
|
|
||||||
if (failed(spirv::serialize(*spirvModules.begin(), binary, emitDebugInfo)))
|
if (failed(spirv::serialize(*spirvModules.begin(), binary, emitDebugInfo)))
|
||||||
return failure();
|
return failure();
|
||||||
|
@ -152,21 +146,16 @@ static LogicalResult roundTripModule(llvm::SourceMgr &sourceMgr,
|
||||||
|
|
||||||
namespace mlir {
|
namespace mlir {
|
||||||
void registerTestRoundtripSPIRV() {
|
void registerTestRoundtripSPIRV() {
|
||||||
TranslateRegistration roundtrip(
|
TranslateFromMLIRRegistration roundtrip(
|
||||||
"test-spirv-roundtrip", [](llvm::SourceMgr &sourceMgr,
|
"test-spirv-roundtrip", [](ModuleOp module, raw_ostream &output) {
|
||||||
raw_ostream &output, MLIRContext *context) {
|
return roundTripModule(module, /*emitDebugInfo=*/false, output);
|
||||||
return roundTripModule(sourceMgr, /*emitDebugInfo=*/false, output,
|
|
||||||
context);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void registerTestRoundtripDebugSPIRV() {
|
void registerTestRoundtripDebugSPIRV() {
|
||||||
TranslateRegistration roundtrip(
|
TranslateFromMLIRRegistration roundtrip(
|
||||||
"test-spirv-roundtrip-debug",
|
"test-spirv-roundtrip-debug", [](ModuleOp module, raw_ostream &output) {
|
||||||
[](llvm::SourceMgr &sourceMgr, raw_ostream &output,
|
return roundTripModule(module, /*emitDebugInfo=*/true, output);
|
||||||
MLIRContext *context) {
|
|
||||||
return roundTripModule(sourceMgr, /*emitDebugInfo=*/true, output,
|
|
||||||
context);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} // namespace mlir
|
} // namespace mlir
|
||||||
|
|
Loading…
Reference in New Issue