diff --git a/include/vast/Dialect/LowLevel/LowLevelOps.td b/include/vast/Dialect/LowLevel/LowLevelOps.td index da339e0b64..522f2ef0db 100644 --- a/include/vast/Dialect/LowLevel/LowLevelOps.td +++ b/include/vast/Dialect/LowLevel/LowLevelOps.td @@ -324,37 +324,6 @@ def LowLevel_ReturnOp let assemblyFormat = "($result^ `:` type($result))? attr-dict"; } -def LowLevel_Scope - : LowLevel_Op< "scope", [ - NoRegionArguments, - NoTerminator, - Core_ScopeLikeTrait, - Core_ShadowingSymbolTable< [ - [Core_VarSymbol, Core_TypeSymbol], [Core_ElaboratedTypeSymbol] - ] > - ] > -{ - let summary = "Scope, holds one region."; - let description = [{ Scope that holds one region, each block should be terminated - with either branch, scope return or their conditional variants. }]; - - let regions = (region AnyRegion:$body); - - let extraClassDeclaration = [{ - mlir::Block *start_block() - { - auto size = std::distance(getBody().begin(), getBody().end()); - if (size < 2) - return nullptr; - return &*std::next(getBody().begin()); - } - }]; - - let assemblyFormat = [{ - $body attr-dict - }]; -} - def LowLevel_InlineScope : LowLevel_Op< "inline_scope", [NoRegionArguments] > { diff --git a/lib/vast/Conversion/FromHL/ToLLCF.cpp b/lib/vast/Conversion/FromHL/ToLLCF.cpp index 4f609a9565..6ee7d805da 100644 --- a/lib/vast/Conversion/FromHL/ToLLCF.cpp +++ b/lib/vast/Conversion/FromHL/ToLLCF.cpp @@ -313,7 +313,7 @@ namespace vast::conv { auto &&finish_control_flow ) const { auto bld = rewriter_wrapper_t(rewriter); - auto scope = rewriter.create< ll::Scope >(op.getLoc()); + auto scope = rewriter.create< core::ScopeOp >(op.getLoc()); auto scope_entry = rewriter.createBlock(&scope.getBody()); auto &cond_region = op.getCondRegion(); @@ -401,7 +401,7 @@ namespace vast::conv { op_t op, typename op_t::Adaptor ops, conversion_rewriter &rewriter ) const override { auto bld = rewriter_wrapper_t(rewriter); - auto scope = rewriter.create< ll::Scope >(op.getLoc()); + auto scope = rewriter.create< core::ScopeOp >(op.getLoc()); auto scope_entry = rewriter.createBlock(&scope.getBody()); auto make_inline_region = [&](auto &®) { @@ -466,33 +466,9 @@ namespace vast::conv { } }; - template< typename op_t, typename trg_t > - struct replace_scope : base_pattern< op_t > - { - using parent_t = base_pattern< op_t >; - using parent_t::parent_t; - - mlir::LogicalResult matchAndRewrite( - op_t op, typename op_t::Adaptor ops, conversion_rewriter &rewriter - ) const override { - auto new_scope = rewriter.create< trg_t >(op.getLoc(), ops.getOperands()); - auto &front_block = new_scope.getBody().emplaceBlock(); - rewriter.inlineRegionBefore(op.getBody(), &front_block); - - rewriter.replaceOp(op, new_scope); - return mlir::success(); - } - - static void legalize(conversion_target &trg) { - trg.addIllegalOp< op_t >(); - trg.addLegalOp< trg_t >(); - } - }; - using cf_patterns = util::make_list< if_op, while_op, for_op, do_op, replace< hl::ReturnOp, ll::ReturnOp >, - replace< core::ImplicitReturnOp, ll::ReturnOp >, - replace_scope< core::ScopeOp, ll::Scope > + replace< core::ImplicitReturnOp, ll::ReturnOp > >; } // namespace pattern @@ -522,7 +498,7 @@ namespace vast::conv { } void run_after_conversion() { - auto clean_scopes = [&](ll::Scope scope) { + auto clean_scopes = [&](core::ScopeOp scope) { mlir::IRRewriter rewriter{ &this->getContext() }; // We really don't care if anything was removed or not. std::ignore = mlir::eraseUnreachableBlocks(rewriter, scope.getBody()); diff --git a/lib/vast/Conversion/ToLLVM/IRsToLLVM.cpp b/lib/vast/Conversion/ToLLVM/IRsToLLVM.cpp index 99141c59b9..a24d6d942f 100644 --- a/lib/vast/Conversion/ToLLVM/IRsToLLVM.cpp +++ b/lib/vast/Conversion/ToLLVM/IRsToLLVM.cpp @@ -291,7 +291,7 @@ namespace vast::conv::irstollvm }; using label_stmt = hl_scopelike< hl::LabelStmt >; - using scope_op = hl_scopelike< ll::Scope >; + using scope_op = hl_scopelike< core::ScopeOp >; using label_patterns = util::type_list< erase_pattern< hl::LabelDeclOp >, label_stmt >; diff --git a/test/vast/Conversion/do-while-a.c b/test/vast/Conversion/do-while-a.c index b6e5b31dd6..4608f31470 100644 --- a/test/vast/Conversion/do-while-a.c +++ b/test/vast/Conversion/do-while-a.c @@ -3,9 +3,9 @@ // LL_CF: ll.func @fn external ([[ARG0:%.*]]: !hl.lvalue) -> none // LL_CF: hl.param @a -// LL_CF: ll.scope { +// LL_CF: core.scope { // LL_CF: hl.var @sum -// LL_CF: ll.scope { +// LL_CF: core.scope { // LL_CF: ll.br ^bb2 // LL_CF: ^bb1: // pred: ^bb2 // LL_CF: [[V8:%[0-9]+]] = hl.ref @a : !hl.lvalue diff --git a/test/vast/Conversion/do-while-b.c b/test/vast/Conversion/do-while-b.c index c633cc4b33..93b7bfc4de 100644 --- a/test/vast/Conversion/do-while-b.c +++ b/test/vast/Conversion/do-while-b.c @@ -3,9 +3,9 @@ // LL_CF: ll.func @fn external ([[ARG0:%.*]]: !hl.lvalue) -> none { // LL_CF: hl.param @a -// LL_CF: ll.scope { +// LL_CF: core.scope { // LL_CF: hl.var @sum -// LL_CF: ll.scope { +// LL_CF: core.scope { // LL_CF: ll.br ^bb2 // LL_CF: ^bb1: // pred: ^bb4 // LL_CF: [[B1V6:%[0-9]+]] = hl.const #core.integer<0> : si32 diff --git a/test/vast/Conversion/for-a.c b/test/vast/Conversion/for-a.c index 38fb08e88f..0929a7743b 100644 --- a/test/vast/Conversion/for-a.c +++ b/test/vast/Conversion/for-a.c @@ -1,7 +1,7 @@ // RUN: %check-hl-to-ll-cf %s | %file-check %s -check-prefix=LL_CF -// LL_CF: ll.scope { -// LL_CF: ll.scope { +// LL_CF: core.scope { +// LL_CF: core.scope { // LL_CF-NEXT: ll.br ^bb1 // LL_CF: ^bb1: // pred: ^bb0 diff --git a/test/vast/Conversion/for-b.c b/test/vast/Conversion/for-b.c index 342ab95529..68cbfbb9d8 100644 --- a/test/vast/Conversion/for-b.c +++ b/test/vast/Conversion/for-b.c @@ -1,6 +1,6 @@ // RUN: %check-hl-to-ll-cf %s | %file-check %s -check-prefix=LL_CF -// LL_CF: ll.scope { +// LL_CF: core.scope { // LL_CF: ll.br ^bb2 // LL_CF: ^bb1: // pred: ^bb4 // LL_CF: ll.br ^bb2 diff --git a/test/vast/Conversion/loops-a.c b/test/vast/Conversion/loops-a.c index 437a8bffa2..ae1398c2ad 100644 --- a/test/vast/Conversion/loops-a.c +++ b/test/vast/Conversion/loops-a.c @@ -1,7 +1,7 @@ // RUN: %check-hl-to-ll-cf %s | %file-check %s -check-prefix=LL_CF // RUN: %check-core-to-llvm %s | %file-check %s -check-prefix=C_LLVM -// LL_CF: ll.scope { +// LL_CF: core.scope { // LL_CF: ll.br ^bb1 // LL_CF: ^bb1: // 2 preds: ^bb0, ^bb2 // LL_CF: [[W1:%[0-9]+]] = hl.const #core.integer<0> : si32 @@ -27,7 +27,7 @@ void fn_while() { while (0) {} } -// LL_CF: ll.scope { +// LL_CF: core.scope { // LL_CF: ll.br ^bb2 // LL_CF: ^bb1: // pred: ^bb2 // LL_CF: [[DW1:%[0-9]+]] = hl.const #core.integer<0> : si32 @@ -53,7 +53,7 @@ void fn_do_while() { do {} while(0); } -// LL_CF: ll.scope { +// LL_CF: core.scope { // LL_CF: ll.br ^bb2 // LL_CF: ^bb1: // pred: ^bb3 // LL_CF: ll.br ^bb2 diff --git a/test/vast/Conversion/scope-a.c b/test/vast/Conversion/scope-a.c index 4e1add0cd8..7011d05353 100644 --- a/test/vast/Conversion/scope-a.c +++ b/test/vast/Conversion/scope-a.c @@ -3,9 +3,9 @@ void fn(int arg) { - // LL_CF: ll.scope { + // LL_CF: core.scope { // LL_CF: hl.var @a - // LL_CF: ll.scope { + // LL_CF: core.scope { // LL_CF: ll.cond_br {{.*}} : i1, ^bb1, ^bb2 // LL_CF: ^bb1: // pred: ^bb0 // LL_CF: hl.ref @a diff --git a/test/vast/Conversion/while-a.c b/test/vast/Conversion/while-a.c index 8a13ed72d6..2034e24be0 100644 --- a/test/vast/Conversion/while-a.c +++ b/test/vast/Conversion/while-a.c @@ -1,6 +1,6 @@ // RUN: %check-hl-to-ll-cf %s | %file-check %s -check-prefix=LL_CF -// LL_CF: ll.scope { +// LL_CF: core.scope { // LL_CF: ll.br ^bb1 // LL_CF: ^bb1: // 2 preds: ^bb0, ^bb2 // LL_CF: ll.cond_scope_ret {{.*}} : i1, ^bb2 diff --git a/test/vast/Conversion/while-b.c b/test/vast/Conversion/while-b.c index 806cb0b66b..9a34c083f2 100644 --- a/test/vast/Conversion/while-b.c +++ b/test/vast/Conversion/while-b.c @@ -1,6 +1,6 @@ // RUN: %check-hl-to-ll-cf %s | %file-check %s -check-prefix=LL_CF -// LL_CF: ll.scope { +// LL_CF: core.scope { // LL_CF: ll.br ^bb1 // LL_CF: ^bb1: // 2 preds: ^bb0, ^bb4 // LL_CF: ll.cond_scope_ret {{.*}} : i1, ^bb2