Skip to content

Commit

Permalink
core: Fix return values of symbol user ranges.
Browse files Browse the repository at this point in the history
  • Loading branch information
xlauko committed Jan 9, 2025
1 parent 6b2fb0d commit c6facd1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 72 deletions.
2 changes: 1 addition & 1 deletion include/vast/Dialect/Core/Interfaces/SymbolInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace vast::core {

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

std::optional< symbol_use_range > get_symbol_uses(
symbol_use_range get_symbol_uses(
operation symbol, operation from
);

Expand Down
65 changes: 17 additions & 48 deletions include/vast/Dialect/Core/SymbolTable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,64 +169,33 @@ namespace vast::core {
// 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. This function returns std::nullopt if there are any unknown
// operations that may potentially be symbol tables.
static std::optional< symbol_use_range > get_direct_symbol_uses(operation from);
static std::optional< symbol_use_range > get_direct_symbol_uses(region_ptr from);
// 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.
// This function returns std::nullopt if there are any unknown operations
// that may potentially be symbol tables.
static std::optional< symbol_use_range > get_direct_symbol_uses(
operation symbol, operation from
);

static std::optional< symbol_use_range > get_direct_symbol_uses(
string_attr symbol, operation from
);

static std::optional< symbol_use_range > get_direct_symbol_uses(
operation symbol, region_ptr from
);

static std::optional< symbol_use_range > get_direct_symbol_uses(
string_attr symbol, region_ptr from
);
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, this function traverses into nested
// symbol tables.
//
// This function returns std::nullopt if there are any unknown operations
// that may potentially be symbol tables.
static std::optional< symbol_use_range > get_symbol_uses(operation from);
static std::optional< symbol_use_range > get_symbol_uses(region_ptr from);
// 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.
//
// This function returns std::nullopt if there are any unknown operations
// that may potentially be symbol tables.
static std::optional< symbol_use_range > get_symbol_uses(
operation symbol, operation from
);

static std::optional< symbol_use_range > get_symbol_uses(
string_attr symbol, operation from
);

static std::optional< symbol_use_range > get_symbol_uses(
operation symbol, region_ptr from
);

static std::optional< symbol_use_range > get_symbol_uses(
string_attr symbol, region_ptr from
);
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:

Expand Down
40 changes: 17 additions & 23 deletions lib/vast/Dialect/Core/SymbolTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ namespace vast::core {

namespace detail {

std::optional< symbol_use_range > get_direct_symbol_uses_impl(
symbol_ref_attr symbol, auto root
) {
symbol_use_range get_direct_symbol_uses_impl(symbol_ref_attr symbol, auto root) {
VAST_ASSERT(symbol);
std::vector< symbol_use > uses;
for (auto use : symbol_uses_in_scope(symbol, root)) {
Expand All @@ -142,47 +140,43 @@ namespace vast::core {
return symbol_use_range(std::move(uses));
}

std::optional< symbol_use_range > get_direct_symbol_uses_impl(
string_attr symbol, auto root
) {
symbol_use_range get_direct_symbol_uses_impl(string_attr symbol, auto root) {
return get_direct_symbol_uses_impl(symbol_ref_attr::get(symbol), root);
}

std::optional< symbol_use_range > get_direct_symbol_uses_impl(
operation symbol, auto root
) {
symbol_use_range get_direct_symbol_uses_impl(operation symbol, auto root) {
return get_direct_symbol_uses_impl(get_symbol_name(symbol), root);
}

} // namespace detail

std::optional< symbol_use_range > symbol_table::get_direct_symbol_uses(operation from) {
symbol_use_range symbol_table::get_direct_symbol_uses(operation from) {
VAST_UNIMPLEMENTED;
}

std::optional< symbol_use_range > symbol_table::get_direct_symbol_uses(region_ptr from) {
symbol_use_range symbol_table::get_direct_symbol_uses(region_ptr from) {
VAST_UNIMPLEMENTED;
}

std::optional< symbol_use_range > symbol_table::get_direct_symbol_uses(
symbol_use_range symbol_table::get_direct_symbol_uses(
operation symbol, operation from
) {
return detail::get_direct_symbol_uses_impl(symbol, from);
}

std::optional< symbol_use_range > symbol_table::get_direct_symbol_uses(
symbol_use_range symbol_table::get_direct_symbol_uses(
string_attr symbol, operation from
) {
return detail::get_direct_symbol_uses_impl(symbol, from);
}

std::optional< symbol_use_range > symbol_table::get_direct_symbol_uses(
symbol_use_range symbol_table::get_direct_symbol_uses(
operation symbol, region_ptr from
) {
return detail::get_direct_symbol_uses_impl(symbol, from);
}

std::optional< symbol_use_range > symbol_table::get_direct_symbol_uses(
symbol_use_range symbol_table::get_direct_symbol_uses(
string_attr symbol, region_ptr from
) {
return detail::get_direct_symbol_uses_impl(symbol, from);
Expand All @@ -193,44 +187,44 @@ namespace vast::core {
//

namespace detail {
std::optional< symbol_use_range > get_symbol_uses_impl(auto symbol, auto scope) {
symbol_use_range get_symbol_uses_impl(auto symbol, auto scope) {
VAST_UNIMPLEMENTED;
}
} // namespace detail

std::optional< symbol_use_range > symbol_table::get_symbol_uses(operation from) {
symbol_use_range symbol_table::get_symbol_uses(operation from) {
VAST_UNIMPLEMENTED;
}

std::optional< symbol_use_range > symbol_table::get_symbol_uses(region_ptr from) {
symbol_use_range symbol_table::get_symbol_uses(region_ptr from) {
VAST_UNIMPLEMENTED;
}

std::optional< symbol_use_range > symbol_table::get_symbol_uses(
symbol_use_range symbol_table::get_symbol_uses(
operation symbol, operation from
) {
return detail::get_symbol_uses_impl(symbol, from);
}

std::optional< symbol_use_range > symbol_table::get_symbol_uses(
symbol_use_range symbol_table::get_symbol_uses(
string_attr symbol, operation from
) {
return detail::get_symbol_uses_impl(symbol, from);
}

std::optional< symbol_use_range > symbol_table::get_symbol_uses(
symbol_use_range symbol_table::get_symbol_uses(
operation symbol, region_ptr from
) {
return detail::get_symbol_uses_impl(symbol, from);
}

std::optional< symbol_use_range > symbol_table::get_symbol_uses(
symbol_use_range symbol_table::get_symbol_uses(
string_attr symbol, region_ptr from
) {
return detail::get_symbol_uses_impl(symbol, from);
}

std::optional< symbol_use_range > get_symbol_uses(
symbol_use_range get_symbol_uses(
operation symbol, operation from
) {
return symbol_table::get_symbol_uses(symbol, from);
Expand Down

0 comments on commit c6facd1

Please sign in to comment.