include "mlir/SPIRV/SPIRVBase.td"
#endif // SPIRV_BASE
-def SPV_ModuleOp : SPV_Op<"module", []> {
+def SPV_ModuleOp : SPV_Op<"module",
+ [SingleBlockImplicitTerminator<"ModuleEndOp">]> {
let summary = "The top-level op that defines a SPIR-V module";
let description = [{
// spv.module
//===----------------------------------------------------------------------===//
-static void ensureModuleEnd(Region *region, Builder builder, Location loc) {
- impl::ensureRegionTerminator<spirv::ModuleEndOp>(*region, builder, loc);
-}
-
void spirv::ModuleOp::build(Builder *builder, OperationState *state) {
- ensureModuleEnd(state->addRegion(), *builder, state->location);
+ ensureTerminator(*state->addRegion(), *builder, state->location);
}
void spirv::ModuleOp::build(Builder *builder, OperationState *state,
state->addAttribute("extensions", extensions);
if (extended_instruction_sets)
state->addAttribute("extended_instruction_sets", extended_instruction_sets);
- ensureModuleEnd(state->addRegion(), *builder, state->location);
+ ensureTerminator(*state->addRegion(), *builder, state->location);
}
static ParseResult parseModuleOp(OpAsmParser *parser, OperationState *state) {
return failure();
}
- ensureModuleEnd(body, parser->getBuilder(), state->location);
-
+ spirv::ModuleOp::ensureTerminator(*body, parser->getBuilder(),
+ state->location);
return success();
}
// -----
-// Module_with_multiple_blocks
-// expected-error @+1 {{failed to verify constraint: region with 1 blocks}}
+// Module with multiple blocks
+// expected-error @+1 {{expects region #0 to have 0 or 1 blocks}}
spv.module "Logical" "VulkanKHR" {
^first:
spv.Return
// -----
+// Module with wrong terminator
+// expected-error@+2 {{expects regions to end with 'spv._module_end'}}
+// expected-note@+1 {{in custom textual format, the absence of terminator implies 'spv._module_end'}}
+"spv.module"() ({
+ %0 = spv.constant true
+}) {addressing_model = 0 : i32, memory_model = 1 : i32} : () -> ()
+
+// -----
+
// Use non SPIR-V op inside.module
spv.module "Logical" "VulkanKHR" {
// expected-error @+1 {{'spv.module' can only contain func and spv.* ops}}