Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obliterate graph regions #728

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion include/vast/Dialect/ABI/ABI.td
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ include "mlir/IR/OpAsmInterface.td"
include "mlir/IR/SymbolInterfaces.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
include "mlir/Interfaces/InferTypeOpInterface.td"
include "mlir/IR/RegionKindInterface.td"

include "vast/Dialect/Core/Interfaces/SymbolInterface.td"

Expand Down
1 change: 0 additions & 1 deletion include/vast/Dialect/Builtin/Builtin.td
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ include "mlir/IR/OpAsmInterface.td"
include "mlir/IR/SymbolInterfaces.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
include "mlir/Interfaces/InferTypeOpInterface.td"
include "mlir/IR/RegionKindInterface.td"
include "mlir/IR/BuiltinAttributeInterfaces.td"

def HLBuiltin_Dialect : Dialect {
Expand Down
4 changes: 1 addition & 3 deletions include/vast/Dialect/Core/CoreOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ include "mlir/IR/OpBase.td"

include "mlir/Dialect/DLTI/DLTIBase.td"
include "mlir/Interfaces/DataLayoutInterfaces.td"
include "mlir/IR/RegionKindInterface.td"

include "vast/Dialect/Core/CoreTraits.td"
include "vast/Dialect/Core/Interfaces/SymbolTableInterface.td"
Expand Down Expand Up @@ -77,8 +76,7 @@ def Core_ScopeOp : Core_Op< "scope", [
NoTerminator, Core_ScopeLikeTrait,
Core_ShadowingSymbolTable< [
[Core_VarSymbol, Core_TypeSymbol], [Core_ElaboratedTypeSymbol]
] >,
DeclareOpInterfaceMethods<RegionKindInterface>
] >
] > {
let summary = "VAST scope declaration";
let description = [{
Expand Down
4 changes: 1 addition & 3 deletions include/vast/Dialect/Core/Func.td
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#define VAST_DIALECT_CORE_FUNC

include "mlir/IR/OpBase.td"
include "mlir/IR/RegionKindInterface.td"

include "mlir/Interfaces/CallInterfaces.td"
include "mlir/Interfaces/FunctionInterfaces.td"
Expand Down Expand Up @@ -38,8 +37,7 @@ class Core_FuncBaseOp< Dialect dialect, string mnemonic, list< Trait > traits =
FunctionOpInterface,
IsolatedFromAbove,
Core_FuncSymbol,
NoTerminator,
DeclareOpInterfaceMethods< RegionKindInterface >
NoTerminator
])
> {
let summary = "VAST function template";
Expand Down
1 change: 0 additions & 1 deletion include/vast/Dialect/HighLevel/HighLevel.td
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ include "mlir/IR/OpAsmInterface.td"
include "mlir/IR/SymbolInterfaces.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
include "mlir/Interfaces/InferTypeOpInterface.td"
include "mlir/IR/RegionKindInterface.td"
include "mlir/IR/BuiltinAttributeInterfaces.td"

include "vast/Dialect/Core/Interfaces/SymbolInterface.td"
Expand Down
4 changes: 2 additions & 2 deletions include/vast/Dialect/HighLevel/HighLevelCF.td
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ include "vast/Dialect/Core/Interfaces/SymbolInterface.td"

class HighLevel_ControlFlowOp< string mnemonic, list< Trait > traits = [] >
: HighLevel_Op< mnemonic, !listconcat(traits,
[NoTerminator, NoRegionArguments, DeclareOpInterfaceMethods<RegionKindInterface>]
[NoTerminator, NoRegionArguments]
) >
{
let summary = "VAST control flow operation";
Expand Down Expand Up @@ -254,7 +254,7 @@ def HighLevel_ChooseExprOp : HighLevel_ControlFlowOp< "choose_expr" >
def HighLevel_BinaryCondOp
: HighLevel_Op<
"binary_cond",
[NoTerminator, DeclareOpInterfaceMethods<RegionKindInterface>]
[NoTerminator]
>
, Results<(outs AnyType:$result)>
{
Expand Down
2 changes: 1 addition & 1 deletion include/vast/Dialect/HighLevel/HighLevelOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -1472,7 +1472,7 @@ def HighLevel_OffsetOfExprOp
}

def HighLevel_StmtExprOp
: HighLevel_Op< "stmt.expr", [SingleBlock, DeclareOpInterfaceMethods<RegionKindInterface>] >
: HighLevel_Op< "stmt.expr", [SingleBlock] >
, Results<(outs AnyType:$result)>
{
let summary = "VAST statement expression";
Expand Down
1 change: 0 additions & 1 deletion include/vast/Dialect/LowLevel/LowLevel.td
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ include "mlir/IR/OpAsmInterface.td"
include "mlir/IR/SymbolInterfaces.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
include "mlir/Interfaces/InferTypeOpInterface.td"
include "mlir/IR/RegionKindInterface.td"

include "vast/Dialect/Core/Interfaces/SymbolInterface.td"

Expand Down
31 changes: 0 additions & 31 deletions include/vast/Dialect/LowLevel/LowLevelOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -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] >
{
Expand Down
1 change: 0 additions & 1 deletion include/vast/Dialect/Meta/Meta.td
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ include "mlir/IR/OpAsmInterface.td"
include "mlir/IR/SymbolInterfaces.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
include "mlir/Interfaces/InferTypeOpInterface.td"
include "mlir/IR/RegionKindInterface.td"

include "vast/Dialect/Core/Interfaces/SymbolInterface.td"

Expand Down
9 changes: 0 additions & 9 deletions include/vast/Util/Dialect.hpp

This file was deleted.

32 changes: 4 additions & 28 deletions lib/vast/Conversion/FromHL/ToLLCF.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021-present, Trail of Bits, Inc.

Check notice on line 1 in lib/vast/Conversion/FromHL/ToLLCF.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter (18, 22.04)

Run clang-format on lib/vast/Conversion/FromHL/ToLLCF.cpp

File lib/vast/Conversion/FromHL/ToLLCF.cpp does not conform to Custom style guidelines. (lines 471)

#include "vast/Conversion/Passes.hpp"

Expand Down Expand Up @@ -313,7 +313,7 @@
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();
Expand Down Expand Up @@ -401,7 +401,7 @@
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 &&reg) {
Expand Down Expand Up @@ -466,33 +466,9 @@
}
};

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
Expand Down Expand Up @@ -522,7 +498,7 @@
}

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());
Expand Down
2 changes: 1 addition & 1 deletion lib/vast/Conversion/ToLLVM/IRsToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 >;

Expand Down
4 changes: 0 additions & 4 deletions lib/vast/Dialect/ABI/ABIOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ VAST_RELAX_WARNINGS
#include <mlir/IR/Builders.h>
VAST_UNRELAX_WARNINGS

#include "vast/Util/Dialect.hpp"

#include "vast/Dialect/Core/Func.hpp"

namespace vast::abi
Expand Down Expand Up @@ -112,8 +110,6 @@ namespace vast::abi
setOperand(0, callee.get< mlir_value >());
}

SSACFG_REGION_OP( FuncOp );

logical_result FuncOp::verify() {
return core::verifyFuncOp(*this);
}
Expand Down
3 changes: 0 additions & 3 deletions lib/vast/Dialect/Core/CoreOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "vast/Dialect/Core/CoreAttributes.hpp"

#include "vast/Util/Common.hpp"
#include "vast/Util/Dialect.hpp"

#include <mlir/Support/LLVM.h>
#include <mlir/Support/LogicalResult.h>
Expand All @@ -25,8 +24,6 @@

namespace vast::core
{
GRAPH_REGION_OP(ScopeOp);

//
// ModuleOp
//
Expand Down
1 change: 0 additions & 1 deletion lib/vast/Dialect/Core/Func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ VAST_UNRELAX_WARNINGS
#include "vast/Dialect/Core/Linkage.hpp"

#include "vast/Util/Common.hpp"
#include "vast/Util/Dialect.hpp"
#include "vast/Util/Region.hpp"

namespace vast::core
Expand Down
18 changes: 0 additions & 18 deletions lib/vast/Dialect/HighLevel/HighLevelOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ VAST_UNRELAX_WARNINGS
#include "vast/Dialect/Core/SymbolTable.hpp"

#include "vast/Util/Common.hpp"
#include "vast/Util/Dialect.hpp"
#include "vast/Util/Region.hpp"
#include "vast/Util/TypeUtils.hpp"
#include "vast/Util/Enum.hpp"
Expand Down Expand Up @@ -846,23 +845,6 @@ namespace vast::hl
st.addTypes(type);
}

GRAPH_REGION_OP(FuncOp);
GRAPH_REGION_OP(StmtExprOp);

GRAPH_REGION_OP(IfOp);
GRAPH_REGION_OP(WhileOp);
GRAPH_REGION_OP(ForOp);
GRAPH_REGION_OP(DoOp);
GRAPH_REGION_OP(SwitchOp);
GRAPH_REGION_OP(CaseOp);
GRAPH_REGION_OP(DefaultOp);
GRAPH_REGION_OP(LabelStmt);
GRAPH_REGION_OP(BreakOp);
GRAPH_REGION_OP(CondOp);
GRAPH_REGION_OP(ChooseExprOp);
GRAPH_REGION_OP(BinaryCondOp);
GRAPH_REGION_OP(ContinueOp);

std::size_t handle_size_of(auto op, mlir_type type) {
auto eval = [op] (mlir_type ty) -> std::size_t {
// sizeof(void), sizeof(function) = 1 as a gcc extension
Expand Down
3 changes: 0 additions & 3 deletions lib/vast/Dialect/LowLevel/LowLevelOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ VAST_RELAX_WARNINGS
#include <mlir/Interfaces/FunctionImplementation.h>
VAST_UNRELAX_WARNINGS

#include "vast/Util/Dialect.hpp"
#include "vast/Util/Region.hpp"

namespace vast::ll
Expand Down Expand Up @@ -49,8 +48,6 @@ namespace vast::ll
return core::printFunctionSignatureAndBodyImpl(printer, op, function_type, dict_attr, body);
}

SSACFG_REGION_OP( FuncOp );

} // namespace vast::ll

#define GET_OP_CLASSES
Expand Down
4 changes: 2 additions & 2 deletions test/vast/Conversion/do-while-a.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

// LL_CF: ll.func @fn external ([[ARG0:%.*]]: !hl.lvalue<si32>) -> 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<si32>
Expand Down
4 changes: 2 additions & 2 deletions test/vast/Conversion/do-while-b.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

// LL_CF: ll.func @fn external ([[ARG0:%.*]]: !hl.lvalue<si32>) -> 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
Expand Down
4 changes: 2 additions & 2 deletions test/vast/Conversion/for-a.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/vast/Conversion/for-b.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions test/vast/Conversion/loops-a.c
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/vast/Conversion/scope-a.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading