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

Remove legacy symbol utils #757

Merged
merged 13 commits into from
Jan 9, 2025
1 change: 0 additions & 1 deletion include/vast/CodeGen/ScopeContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ VAST_UNRELAX_WARNINGS

#include "vast/CodeGen/DefaultSymbolGenerator.hpp"
#include "vast/Util/TypeList.hpp"
#include "vast/Util/Symbols.hpp"

#include "vast/Dialect/Core/Interfaces/SymbolInterface.hpp"

Expand Down
15 changes: 15 additions & 0 deletions include/vast/Dialect/Core/Interfaces/SymbolInterface.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/Dialect/Core/Interfaces/SymbolInterface.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter (19, 22.04)

Run clang-format on include/vast/Dialect/Core/Interfaces/SymbolInterface.hpp

File include/vast/Dialect/Core/Interfaces/SymbolInterface.hpp does not conform to Custom style guidelines. (lines 24, 25, 60)

#pragma once

Expand All @@ -19,10 +19,16 @@
// Use TypeID of Interfaces that defines the symbol
using symbol_kind = mlir::TypeID;

using symbol_use_range = ::mlir::SymbolTable::UseRange;

symbol_use_range get_symbol_uses(
operation symbol, operation from
);

} // namespace vast::core

/// Include the generated interface declarations.
#include "vast/Dialect/Core/Interfaces/SymbolInterface.h.inc"

Check failure on line 31 in include/vast/Dialect/Core/Interfaces/SymbolInterface.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter (19, 22.04)

include/vast/Dialect/Core/Interfaces/SymbolInterface.hpp:31:10 [clang-diagnostic-error]

'vast/Dialect/Core/Interfaces/SymbolInterface.h.inc' file not found

namespace vast::core {

Expand All @@ -49,4 +55,13 @@
return kind == get_symbol_kind< interface >;
}

template< typename symbol_kind >
void symbols(operation scope, auto &&yield) {
scope->walk([&] (operation child) {
if (auto symbol = mlir::dyn_cast< symbol_kind >(child)) {
yield(symbol);
}
});
}

} // namespace vast::core
11 changes: 11 additions & 0 deletions include/vast/Dialect/Core/Interfaces/SymbolInterface.td
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ def Core_Symbol : Core_OpInterface< "SymbolOpInterface" > {
op->setAttr("name", attr);
}
}]
>,
InterfaceMethod< [{
Get all of the uses of the current symbol that are nested within
the given operation 'from'.
Note: See core::symbol_table::get_symbol_uses for more details.
}],
"::mlir::SymbolTable::UseRange", "getSymbolUses",
(ins "::mlir::Operation *":$from), [{}],
/*defaultImplementation=*/[{
return ::vast::core::get_symbol_uses(this->getOperation(), from);
}]
>
];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2024, Trail of Bits, Inc.

Check notice on line 1 in include/vast/Dialect/Core/Interfaces/SymbolTableInterface.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter (19, 22.04)

Run clang-format on include/vast/Dialect/Core/Interfaces/SymbolTableInterface.hpp

File include/vast/Dialect/Core/Interfaces/SymbolTableInterface.hpp does not conform to Custom style guidelines. (lines 28)

#pragma once

Expand All @@ -24,4 +24,12 @@

using symbol_table_op_interface = SymbolTableOpInterface;

void symbol_tables(operation root, auto &&yield) {
root->walk([&] (operation child) {
if (mlir::isa< symbol_table_op_interface >(child)) {
yield(child);
}
});
}

} // namespace vast::core
35 changes: 35 additions & 0 deletions include/vast/Dialect/Core/SymbolTable.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2024, Trail of Bits, Inc.

Check notice on line 1 in include/vast/Dialect/Core/SymbolTable.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter (19, 22.04)

Run clang-format on include/vast/Dialect/Core/SymbolTable.hpp

File include/vast/Dialect/Core/SymbolTable.hpp does not conform to Custom style guidelines. (lines 165, 166)

#pragma once

Expand Down Expand Up @@ -162,6 +162,41 @@

operation get_defining_operation() { return symbol_table_op; }

auto nested_operations() const {
return gmw::operations(symbol_table_op);
}

// Note: These are adapted from mlir::SymbolTable,
// try to keep them consistent when updating, or note the differences.
//
// Get an iterator range for all of the uses, for any symbol, that are
// nested within the given operation 'from'. This does not traverse into
// any nested symbol tables.
static symbol_use_range get_direct_symbol_uses(operation from);
static symbol_use_range get_direct_symbol_uses(region_ptr from);

// Get all of the uses of the given symbol that are nested within the given
// operation 'from'. This does not traverse into any nested symbol tables.
static symbol_use_range get_direct_symbol_uses(operation symbol, operation from);
static symbol_use_range get_direct_symbol_uses(string_attr symbol, operation from);
static symbol_use_range get_direct_symbol_uses(operation symbol, region_ptr from);
static symbol_use_range get_direct_symbol_uses(string_attr symbol, region_ptr from);

// Get an iterator range for all of the uses, for any symbol, that are
// nested within the given operation 'from'. In contrast to
// mlir::SymbolTable::getSymbolUses and `get_direct_symbol_uses` this
// function traverses into nested symbol tables.
static symbol_use_range get_symbol_uses(operation from);
static symbol_use_range get_symbol_uses(region_ptr from);

// Get all of the uses of the given symbol that are nested within the given
// operation 'from'. In contrast to mlir::SymbolTable::getSymbolUses, this
// function traverses into nested symbol tables.
static symbol_use_range get_symbol_uses(operation symbol, operation from);
static symbol_use_range get_symbol_uses(string_attr symbol, operation from);
static symbol_use_range get_symbol_uses(operation symbol, region_ptr from);
static symbol_use_range get_symbol_uses(string_attr symbol, region_ptr from);

protected:

template< util::flat_list symbols_list >
Expand Down
1 change: 0 additions & 1 deletion include/vast/Dialect/HighLevel/HighLevelUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "vast/Dialect/Core/Interfaces/SymbolInterface.hpp"

#include "vast/Util/Common.hpp"
#include <vast/Util/Symbols.hpp>
#include "vast/Util/TypeUtils.hpp"

#include <gap/coro/generator.hpp>
Expand Down
2 changes: 0 additions & 2 deletions include/vast/Dialect/HighLevel/Passes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ VAST_UNRELAX_WARNINGS
namespace vast::hl {
std::unique_ptr< mlir::Pass > createHLLowerTypesPass();

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

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

std::unique_ptr< mlir::Pass > createUDEPass();
Expand Down
19 changes: 0 additions & 19 deletions include/vast/Dialect/HighLevel/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,6 @@

include "mlir/Pass/PassBase.td"

def ExportFnInfo : Pass<"vast-export-fn-info", "core::ModuleOp"> {
let summary = "Create JSON that exports information about function arguments.";
let description = [{
Lowers module into llvm IR and dumps it on stderr.
}];

let dependentDialects = [
"vast::hl::HighLevelDialect",
"vast::core::CoreDialect"
];

let constructor = "vast::hl::createExportFnInfoPass()";

let options = [
Option< "o", "o", "std::string", "",
"Output JSON file to be created." >
];
}

def DCE : Pass<"vast-hl-dce", "core::ModuleOp"> {
let summary = "Trim dead code";
let description = [{
Expand Down
10 changes: 6 additions & 4 deletions include/vast/Dialect/Meta/MetaDialect.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/Dialect/Meta/MetaDialect.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter (19, 22.04)

Run clang-format on include/vast/Dialect/Meta/MetaDialect.hpp

File include/vast/Dialect/Meta/MetaDialect.hpp does not conform to Custom style guidelines. (lines 29, 31)

#pragma once

Expand All @@ -14,18 +14,20 @@


// Pull in the dialect definition.
#include "vast/Dialect/Meta/MetaDialect.h.inc"

Check failure on line 17 in include/vast/Dialect/Meta/MetaDialect.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter (19, 22.04)

include/vast/Dialect/Meta/MetaDialect.hpp:17:10 [clang-diagnostic-error]

'vast/Dialect/Meta/MetaDialect.h.inc' file not found

#include "vast/Util/Common.hpp"

namespace vast::meta
{
using identifier_t = std::uint64_t;

void add_identifier(mlir::Operation *op, identifier_t id);
void add_identifier(operation op, identifier_t id);

void remove_identifier(mlir::Operation *op);
void remove_identifier(operation op);

std::vector< mlir::Operation * > get_with_identifier(mlir::Operation *scope, identifier_t id);
std::vector< operation > get_with_identifier(operation scope, identifier_t id);

std::vector< mlir::Operation * > get_with_meta_location(mlir::Operation *scope, identifier_t id);
std::vector< operation > get_with_meta_location(operation scope, identifier_t id);

} // namespace vast::meta
3 changes: 3 additions & 0 deletions include/vast/Util/Common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ namespace vast {
using string_ref = llvm::StringRef;
using logical_result = mlir::LogicalResult;

using symbol_ref_attr = mlir::SymbolRefAttr;

using mlir_attr = mlir::Attribute;
using maybe_attr_t = std::optional< mlir_attr >;
using named_attr = mlir::NamedAttribute;
using string_attr = mlir::StringAttr;

using integer_attr_t = mlir::IntegerAttr;

Expand Down
121 changes: 0 additions & 121 deletions include/vast/Util/Symbols.hpp

This file was deleted.

1 change: 0 additions & 1 deletion include/vast/repl/command.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ VAST_RELAX_WARNINGS
#include <llvm/ADT/StringExtras.h>
VAST_UNRELAX_WARNINGS

#include "vast/Util/Symbols.hpp"
#include "vast/Util/Tuple.hpp"
#include "vast/Util/TypeList.hpp"

Expand Down
1 change: 0 additions & 1 deletion lib/vast/Conversion/ABI/EmitABI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ VAST_UNRELAX_WARNINGS
#include "vast/Util/Common.hpp"
#include "vast/Util/Functions.hpp"
#include "vast/Util/DialectConversion.hpp"
#include "vast/Util/Symbols.hpp"

#include "vast/Dialect/ABI/ABIOps.hpp"

Expand Down
1 change: 0 additions & 1 deletion lib/vast/Conversion/ABI/LowerABI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ VAST_UNRELAX_WARNINGS
#include "vast/Util/Common.hpp"
#include "vast/Util/Functions.hpp"
#include "vast/Util/DialectConversion.hpp"
#include "vast/Util/Symbols.hpp"
#include "vast/Util/TypeSwitch.hpp"
#include "vast/Util/TypeUtils.hpp"

Expand Down
1 change: 0 additions & 1 deletion lib/vast/Conversion/FromHL/ToLLGEPs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ VAST_UNRELAX_WARNINGS
#include "vast/Dialect/LowLevel/LowLevelOps.hpp"

#include "vast/Util/DialectConversion.hpp"
#include "vast/Util/Symbols.hpp"

namespace vast {
namespace {
Expand Down
1 change: 0 additions & 1 deletion lib/vast/Conversion/ToLLVM/IRsToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ VAST_UNRELAX_WARNINGS
#include "vast/Dialect/Core/TypeTraits.hpp"

#include "vast/Util/Common.hpp"
#include "vast/Util/Symbols.hpp"
#include "vast/Util/Terminator.hpp"
#include "vast/Util/TypeList.hpp"

Expand Down
1 change: 0 additions & 1 deletion lib/vast/Conversion/ToLLVM/LLCFToLLVM.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ VAST_UNRELAX_WARNINGS

#include "vast/Dialect/LowLevel/LowLevelOps.hpp"

#include "vast/Util/Symbols.hpp"
#include "vast/Util/TypeList.hpp"

#include "vast/Conversion/Common/Block.hpp"
Expand Down
1 change: 1 addition & 0 deletions lib/vast/Dialect/Core/Interfaces/SymbolInterface.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) 2022-present, Trail of Bits, Inc.

#include "vast/Dialect/Core/Interfaces/SymbolInterface.hpp"
#include "vast/Dialect/Core/Interfaces/SymbolTableInterface.hpp"

//===----------------------------------------------------------------------===//
// Symbol Interfaces
Expand Down
Loading
Loading