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

Unify symbol reference handling #727

Merged
merged 50 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
e89fd8d
hl: Obliterate SSA value frm VarDecl.
xlauko Sep 11, 2024
0024721
hl: Let DeclRef take symbol name instead of SSA value.
xlauko Sep 11, 2024
089ae64
cg: Declare function param names using ParmVarDeclOp.
xlauko Sep 11, 2024
ce91cc1
test: Update references of ssa values to symbols.
xlauko Sep 13, 2024
7aa1c34
conv:tollvars: Remove obsolete var initilization section fix.
xlauko Sep 13, 2024
d49a452
conv: Introduce VarsToCells pass and ToMem pipeline step.
xlauko Sep 13, 2024
f567a81
ll: Introduce memory cells to represent variables storage.
xlauko Sep 13, 2024
e1620b8
conv:tomem: Implement VarsToCellsPass.
xlauko Sep 13, 2024
e2b8d5c
ll: Clean up `Cell` assembly format.
xlauko Sep 13, 2024
998635a
ll: Add prefix to LowLevel operations.
xlauko Sep 13, 2024
9b2d7fc
ll: Make ll::scope a shadowing symbol table.
xlauko Sep 13, 2024
c8e9788
ll: Make ll::Cell to define variable symbol.
xlauko Sep 13, 2024
dc95487
conv:tomem: Create RefsToSSAPass.
xlauko Sep 13, 2024
05cf352
hl: Rename `DeclRefOp` parameter `decl` to `name`.
xlauko Sep 13, 2024
c11d123
conv: Remove obsolete `hl-to-ll-vars` pass.
xlauko Sep 13, 2024
9d55d78
ll: Remove obsolete ArgAlloca as it is replaced by Cell now.
xlauko Sep 13, 2024
c7c7a36
conv: Remove obsolete FnArgsToAllocaPass.
xlauko Sep 13, 2024
8d2cb5e
conv:tomem: Add `hl::ParmVarDeclOp` to `ll::Cell` pattern.
xlauko Sep 13, 2024
0fa5c04
conv: Remove obsolete Param to Alloca conversion.
xlauko Sep 13, 2024
1f2ac1b
conv: Update ll::Var to ll::Cell patterns.
xlauko Sep 13, 2024
af15221
conv:tollvm: Remove obsolete ll::Var conversions.
xlauko Sep 13, 2024
be1de8c
treewide: Rename ModuleConversionPassMixin to more generic Conversion…
xlauko Sep 16, 2024
6f4a69b
conv: Refactor function conversion utilities.
xlauko Sep 16, 2024
ad2bdaf
conv:tomem: Implement StripParamLValuesPass.
xlauko Sep 16, 2024
6b8eda1
conv: Add type_converting_conversion_config.
xlauko Sep 16, 2024
b382ccd
test: Remove obsolete tool substitutions.
xlauko Sep 16, 2024
246c4d0
test: Update ll.var to ll.cell tests.
xlauko Sep 16, 2024
7d6d395
abi: Add FuncOp traits to define its symbol table.
xlauko Sep 16, 2024
11538e2
abi: Add FuncOp traits to define its symbol table.
xlauko Sep 16, 2024
eb91084
conv:tomem: Fix variable symbol lookup.
xlauko Sep 16, 2024
5351a8a
hl: Fix function type name resolution.
xlauko Sep 16, 2024
8b534a3
core: Introduce `ScopeLikeTrait`.
xlauko Sep 17, 2024
b37ebc6
core: Allow to access SymbolTable defining operation.
xlauko Sep 17, 2024
aeba589
core: Let ScopeOp to have ScopeLikeTrait.
xlauko Sep 17, 2024
305af46
ll: core: Let Scope to have ScopeLikeTrait.
xlauko Sep 17, 2024
ef5620a
hl: Fix variable storage classes.
xlauko Sep 17, 2024
403cde9
conv:tomem: Convert to cells only local variables.
xlauko Sep 17, 2024
4442a2c
conv: Remove obsolete lvalue type conversion.
xlauko Sep 17, 2024
a2ff6db
conv: Make hl.var with lvalue illegal in LowerValueCategoriesPass.
xlauko Sep 17, 2024
48e6057
test: Fix filecheck output parameters.
xlauko Sep 17, 2024
c7bf438
conv:tomem: Make StripParamLValuesPass work on external function with…
xlauko Sep 18, 2024
0fd639d
conv: Remove now obsolete lvalue function type conversion.
xlauko Sep 18, 2024
3e9b913
test: Update conversion checks to adhere new results.
xlauko Sep 18, 2024
6baf878
conv:tomem: Replace invalid uses of replaceOp with eraseOp.
Jezurko Sep 18, 2024
1fd72ed
conv:tollvm: Add missing include.
Jezurko Sep 18, 2024
961fe46
util: Make trailing scope detection skip vast-specific ops.
Jezurko Sep 18, 2024
89d9c17
hl:splicescopes: Use mlir walk method instead of custom functions.
Jezurko Sep 18, 2024
2056292
conv:tomem: Add LowLevel as legal dialect to avoid legalizer issues.
Jezurko Sep 18, 2024
38dac20
conv:tc: Resolve UB by moving methods requiring downcast out of crtp …
Jezurko Sep 19, 2024
ab0782a
treewide: Fix formatting.
xlauko Sep 20, 2024
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
15 changes: 5 additions & 10 deletions include/vast/CodeGen/ScopeContext.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023, Trail of Bits, Inc.

Check notice on line 1 in include/vast/CodeGen/ScopeContext.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter (18, 22.04)

Run clang-format on include/vast/CodeGen/ScopeContext.hpp

File include/vast/CodeGen/ScopeContext.hpp does not conform to Custom style guidelines. (lines 93)

#pragma once

Expand Down Expand Up @@ -32,7 +32,7 @@
};

using funs_scope_table = scoped_table< string_ref, operation >;
using vars_scope_table = scoped_table< string_ref, mlir_value >;
using vars_scope_table = scoped_table< string_ref, operation >;
using types_scope_table = scoped_table< string_ref, operation >;
using members_scope_table = scoped_table< string_ref, operation >;
using labels_scope_table = scoped_table< string_ref, operation >;
Expand All @@ -57,7 +57,7 @@
operation declare(operation op) {
llvm::TypeSwitch< operation >(op)
.Case< core::VarSymbolOpInterface >([&] (auto &op) {
symbols.vars.insert(op.getSymbolName(), op->getResult(0));
symbols.vars.insert(op.getSymbolName(), op);
})
.Case< core::TypeSymbolOpInterface >([&] (auto &op) {
symbols.types.insert(op.getSymbolName(), op);
Expand Down Expand Up @@ -90,11 +90,7 @@
}
}

auto declare_function_param(string_ref name, mlir_value value) {
return symbols.vars.insert(name, value), value;
}

mlir_value lookup_var(string_ref name) const {
operation lookup_var(string_ref name) const {
return symbols.vars.lookup(name);
}

Expand Down Expand Up @@ -190,8 +186,7 @@

virtual ~block_scope() = default;

symbol_table_scope< string_ref, mlir_value > vars;

symbol_table_scope< string_ref, operation > vars;
symbol_table_scope< string_ref, operation > types;
symbol_table_scope< string_ref, operation > enum_constants;
};
Expand Down Expand Up @@ -239,7 +234,7 @@

symbol_table_scope< string_ref, operation > functions;
symbol_table_scope< string_ref, operation > types;
symbol_table_scope< string_ref, mlir_value > globals;
symbol_table_scope< string_ref, operation > globals;
xlauko marked this conversation as resolved.
Show resolved Hide resolved
symbol_table_scope< string_ref, operation > enum_constants;
};

Expand Down
47 changes: 39 additions & 8 deletions include/vast/Conversion/Common/Mixins.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022-present, Trail of Bits, Inc.

Check notice on line 1 in include/vast/Conversion/Common/Mixins.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter (18, 22.04)

Run clang-format on include/vast/Conversion/Common/Mixins.hpp

File include/vast/Conversion/Common/Mixins.hpp does not conform to Custom style guidelines. (lines 87, 91, 92, 95, 219, 247)

#pragma once

Expand Down Expand Up @@ -82,6 +82,25 @@
}
};


template< typename type_converter >
struct type_converting_conversion_config : base_conversion_config {
type_converter &tc;

type_converting_conversion_config(
rewrite_pattern_set patterns,
conversion_target target,
type_converter &tc
)
: base_conversion_config{std::move(patterns), std::move(target)}, tc(tc)
{}

template< typename pattern >
void add_pattern() {
patterns.template add< pattern >(tc, patterns.getContext());
}
};

// Configuration class for LLVM conversion
using llvm_type_converter = conv::tc::FullLLVMTypeConverter;

Expand Down Expand Up @@ -110,7 +129,7 @@
// base class for module conversion passes providing common functionality
//
template< typename derived, template< typename > typename base >
struct ModuleConversionPassMixinBase
struct ConversionPassMixinBase
: base< derived >
, populate_patterns< derived >
{
Expand Down Expand Up @@ -165,8 +184,8 @@
//
// Example usage:
//
// struct ExamplePass : ModuleConversionPassMixin<ExamplePass, ExamplePassBase> {
// using base = ModuleConversionPassMixin<ExamplePass, ExamplePassBase>;
// struct ExamplePass : ConversionPassMixin<ExamplePass, ExamplePassBase> {
// using base = ConversionPassMixin<ExamplePass, ExamplePassBase>;
//
// static conversion_target create_conversion_target(mcontext_t &context) {
// conversion_target target(context);
Expand All @@ -182,22 +201,34 @@
// }
//
template< typename derived, template< typename > typename base >
struct ModuleConversionPassMixin : ModuleConversionPassMixinBase< derived, base >
struct ConversionPassMixin : ConversionPassMixinBase< derived, base >
{
base_conversion_config make_config() {
auto &ctx = this->getContext();
return { rewrite_pattern_set(&ctx), derived::create_conversion_target(ctx) };
}
};

template< typename derived, template< typename > typename base, typename type_converter >
struct TypeConvertingConversionPassMixin : ConversionPassMixinBase< derived, base >
{
std::shared_ptr< type_converter > tc;

type_converting_conversion_config< type_converter > make_config() {
auto &ctx = this->getContext();
tc = std::make_shared< type_converter >(ctx);
return { rewrite_pattern_set(&ctx), derived::create_conversion_target(ctx), *tc };
}
};

//
// Mixin for conversion passes that target the LLVM dialect.
// Requires the derived pass to specify LLVM-specific conversion logic.
//
// Example usage:
//
// struct ExamplePass : ModuleLLVMConversionPassMixin<ExamplePass, ExamplePassBase> {
// using base = ModuleLLVMConversionPassMixin<ExamplePass, ExamplePassBase>;
// struct ExamplePass : LLVMConversionPassMixin<ExamplePass, ExamplePassBase> {
// using base = LLVMConversionPassMixin<ExamplePass, ExamplePassBase>;
//
// static conversion_target create_conversion_target(mcontest_t &context) {
// conversion_target target(context);
Expand All @@ -213,8 +244,8 @@
// }
//
template< typename derived, template< typename > typename base >
struct ModuleLLVMConversionPassMixin
: ModuleConversionPassMixinBase< derived, base >
struct LLVMConversionPassMixin
: ConversionPassMixinBase< derived, base >
{
std::shared_ptr< llvm_type_converter > tc;

Expand Down
3 changes: 3 additions & 0 deletions include/vast/Conversion/Common/Patterns.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ namespace vast {

generic_conversion_pattern(mlir::TypeConverter &tc, mcontext_t &mctx)
: base(tc, mlir::Pattern::MatchAnyOpTypeTag{}, 1, &mctx) {}

generic_conversion_pattern(mlir::TypeConverter &tc, mcontext_t *mctx)
: base(tc, mlir::Pattern::MatchAnyOpTypeTag{}, 1, mctx) {}
};

template< typename op_t >
Expand Down
13 changes: 9 additions & 4 deletions include/vast/Conversion/Passes.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022-present, Trail of Bits, Inc.

Check notice on line 1 in include/vast/Conversion/Passes.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter (18, 22.04)

Run clang-format on include/vast/Conversion/Passes.hpp

File include/vast/Conversion/Passes.hpp does not conform to Custom style guidelines. (lines 67)

#pragma once

Expand Down Expand Up @@ -51,18 +51,21 @@

std::unique_ptr< mlir::Pass > createHLToLLGEPsPass();

std::unique_ptr< mlir::Pass > createHLToLLVarsPass();

std::unique_ptr< mlir::Pass > createHLEmitLazyRegionsPass();

std::unique_ptr< mlir::Pass > createHLToLLFuncPass();

std::unique_ptr< mlir::Pass > createHLToHLBI();

std::unique_ptr< mlir::Pass > createFnArgsToAllocaPass();

std::unique_ptr< mlir::Pass > createLowerValueCategoriesPass();

// ToMem
std::unique_ptr< mlir::Pass > createRefsToSSAPass();

std::unique_ptr< mlir::Pass > createStripParamLValuesPass();

std::unique_ptr< mlir::Pass > createVarsToCellsPass();

// Generate the code for registering passes.
#define GEN_PASS_REGISTRATION
#include "vast/Conversion/Passes.h.inc"
Expand All @@ -76,6 +79,8 @@

pipeline_step_ptr to_ll();

pipeline_step_ptr to_mem();

pipeline_step_ptr to_llvm();

pipeline_step_ptr canonicalize();
Expand Down
49 changes: 27 additions & 22 deletions include/vast/Conversion/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,39 @@ def IRsToLLVM : Pass<"vast-irs-to-llvm", "mlir::ModuleOp"> {
];
}

def FnArgsToAlloca : Pass<"vast-fn-args-to-alloca", "core::ModuleOp"> {
let summary = "VAST to LLVM Dialect conversion";
let description = [{
For each function emit its prologue - for each argument make an alloca
and store the corresponding argument in it.
}];
def RefsToSSA : Pass<"vast-refs-to-ssa", "core::ModuleOp"> {
let summary = "Lower `hl.ref` into ssa-based `ll.cell`.";
let description = [{ TBD }];
xlauko marked this conversation as resolved.
Show resolved Hide resolved

let constructor = "vast::createFnArgsToAllocaPass()";
let constructor = "vast::createRefsToSSAPass()";
let dependentDialects = [
"vast::ll::LowLevelDialect",
"vast::core::CoreDialect"
"vast::hl::HighLevelDialect",
];
}

def StripParamLValues : Pass<"vast-strip-param-lvalues", "core::ModuleOp"> {
let summary = "Strip `hl.lvalue` from types in the module.";
let description = [{ TBD }];
xlauko marked this conversation as resolved.
Show resolved Hide resolved

let constructor = "vast::createStripParamLValuesPass()";
let dependentDialects = [
"vast::hl::HighLevelDialect",
];
}

def VarsToCells : Pass<"vast-vars-to-cells", "core::ModuleOp"> {
let summary = "Lower `hl.var` into ssa-based `ll.cell`.";
let description = [{ TBD }];

xlauko marked this conversation as resolved.
Show resolved Hide resolved
let constructor = "vast::createVarsToCellsPass()";
let dependentDialects = [
"vast::ll::LowLevelDialect",
"vast::hl::HighLevelDialect",
];
}


def LowerValueCategories : Pass<"vast-lower-value-categories", "core::ModuleOp"> {
let summary = "Lower `hl.lvalue` into explicit pointers and loads.";
let description = [{
Expand Down Expand Up @@ -146,20 +165,6 @@ def HLToLLGEPs : Pass<"vast-hl-to-ll-geps", "core::ModuleOp"> {
];
}

def HLToLLVars : Pass<"vast-hl-to-ll-vars", "core::ModuleOp"> {
let summary = "Convert hl variables into ll versions.";
let description = [{
This pass is still a work in progress.
}];

let constructor = "vast::createHLToLLVarsPass()";
let dependentDialects = [
"mlir::LLVM::LLVMDialect",
"vast::ll::LowLevelDialect",
"vast::core::CoreDialect"
];
}

def HLToLLFunc : Pass<"vast-hl-to-ll-func", "core::ModuleOp"> {
let summary = "Convert hl functions into ll versions.";
let description = [{
Expand Down
Loading