Symbol table
symbol_table
Helper methods and classes to reason about operations that refer to other operations.
Visibility
Bases: StrEnum
An enumeration detailing the different visibility types that a symbol may have.
Source code in xdsl/utils/symbol_table.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
PUBLIC = 'public'
class-attribute
instance-attribute
The symbol is public and may be referenced anywhere internal or external to the visible references in the IR.
PRIVATE = 'private'
class-attribute
instance-attribute
The symbol is private and may only be referenced by SymbolRefAttrs local to the operations within the current symbol table.
NESTED = 'nested'
class-attribute
instance-attribute
The symbol is visible to the current IR, which may include operations in symbol
tables above the one that owns the current symbol.
nested visibility allows for referencing a symbol outside of its current symbol
table, while retaining the ability to observe all uses.
SymbolUse
Bases: NamedTuple
Source code in xdsl/utils/symbol_table.py
43 44 45 46 47 | |
owner: Operation
instance-attribute
The operation that this access is held by.
symbol_ref: SymbolRefAttr
instance-attribute
The symbol reference that this use represents.
SymbolTable
This class allows for representing and managing the symbol table used by operations with the 'SymbolTable' trait. Inserting into and erasing from this SymbolTable will also insert and erase from the Operation given to it at construction.
Source code in xdsl/utils/symbol_table.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
__init__(symbol_table_op: Operation)
Source code in xdsl/utils/symbol_table.py
68 69 70 71 | |
lookup(name: str | StringAttr) -> Operation | None
Look up a symbol with the specified name, returning None if no such name
exists.
Names never include the @ on them.
Source code in xdsl/utils/symbol_table.py
73 74 75 76 77 78 79 | |
remove(op: Operation) -> None
Remove the given symbol from the table, without deleting it.
Source code in xdsl/utils/symbol_table.py
81 82 83 | |
erase(op: Operation) -> None
Erase the given symbol from the table and delete the operation.
Source code in xdsl/utils/symbol_table.py
85 86 87 | |
insert(symbol: Operation, insertion_point: InsertPoint) -> StringAttr
Insert a new symbol into the table, and rename it as necessary to avoid collisions. Also insert at the specified location in the body of the associated operation if it is not already there. It is asserted that the symbol is not inside another operation. Return the name of the symbol after insertion as attribute.
Source code in xdsl/utils/symbol_table.py
89 90 91 92 93 94 95 96 97 | |
rename(from_op: Operation | StringAttr, to_name: StringAttr | str) -> None
Renames the given op or the op referred to by the given name to the given new name and updates the symbol table and all usages of the symbol accordingly. Fails if the updating of the usages fails.
Source code in xdsl/utils/symbol_table.py
99 100 101 102 103 104 105 106 107 108 | |
rename_to_unique(from_op: Operation | StringAttr, others: Sequence[SymbolTable]) -> StringAttr | None
Renames the given op or the op referred to by the given name to the given new
name that is unique within this and the provided other symbol tables and
updates the symbol table and all usages of the symbol accordingly.
Returns the new name or None if the renaming fails.
Source code in xdsl/utils/symbol_table.py
110 111 112 113 114 115 116 117 118 119 | |
get_symbol_name(symbol: Operation) -> StringAttr | None
staticmethod
Returns the name of the given symbol operation, or None if no symbol is
present.
Source code in xdsl/utils/symbol_table.py
123 124 125 126 127 128 129 | |
set_symbol_name(symbol: Operation, name: StringAttr | str) -> None
staticmethod
Sets the name of the given symbol operation.
Source code in xdsl/utils/symbol_table.py
131 132 133 134 | |
get_symbol_visibility(symbol: Operation) -> Visibility
staticmethod
Returns the visibility of the given symbol operation.
Source code in xdsl/utils/symbol_table.py
136 137 138 139 | |
set_symbol_visibility(symbol: Operation, vis: Visibility) -> None
staticmethod
Sets the visibility of the given symbol operation.
Source code in xdsl/utils/symbol_table.py
141 142 143 144 | |
get_nearest_symbol_table(from_op: Operation) -> Operation | None
staticmethod
Returns the nearest symbol table from a given operation from.
Returns None if no valid parent symbol table could be found.
Source code in xdsl/utils/symbol_table.py
146 147 148 149 150 151 152 | |
walk_symbol_tables(op: Operation, all_sym_uses_visible: bool) -> Iterator[Operation]
staticmethod
Walks all symbol table operations nested within, and including, op.
For each symbol table operation, the provided callback is invoked with the op
and a boolean signifying if the symbols within that symbol table can be
treated as if all uses within the IR are visible to the caller.
all_sym_uses_visible identifies whether all of the symbol uses of symbols
within op are visible.
Source code in xdsl/utils/symbol_table.py
154 155 156 157 158 159 160 161 162 163 164 165 166 | |
lookup_symbol_in(op: Operation, symbol: StringAttr | SymbolRefAttr | str, *, all_symbols: bool = False) -> list[Operation] | Operation | None
staticmethod
lookup_symbol_in(
op: Operation,
symbol: StringAttr | SymbolRefAttr | str,
*,
all_symbols: Literal[True],
) -> list[Operation] | None
lookup_symbol_in(
op: Operation,
symbol: StringAttr | SymbolRefAttr | str,
*,
all_symbols: Literal[False],
) -> Operation | None
Returns the operation registered with the given symbol name with the regions of
op.
op is required to be an operation with the 'xdsl.traits.SymbolTable' trait.
If all_symbols is True, returns all symbols referenced by the symbol.
Source code in xdsl/utils/symbol_table.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
lookup_nearest_symbol_from(from_op: Operation, symbol: StringAttr | SymbolRefAttr) -> Operation | None
staticmethod
Returns the operation registered with the given symbol name within the closest
parent operation of, or including, from_op with the
SymbolTable trait.
Returns None if no valid symbol was found.
Source code in xdsl/utils/symbol_table.py
201 202 203 204 205 206 207 208 209 210 211 | |
get_symbol_uses(from_op: Operation | Region, *, symbol: StringAttr | Operation | None = None) -> Sequence[SymbolUse]
staticmethod
Get the symbol uses nested within from_op for the given symbol, or all the
uses if symbol is None.
This does not traverse into any nested symbol tables.
This function returns None if there are any unknown operations that may
potentially be symbol tables.
Source code in xdsl/utils/symbol_table.py
213 214 215 216 217 218 219 220 221 222 223 224 | |
symbol_known_use_empty(symbol: Operation | StringAttr, from_op: Operation | Region) -> bool
staticmethod
Return if the given symbol is known to have no uses that are nested within the given operation 'from'. This does not traverse into any nested symbol tables. This function will also return false if there are any unknown operations that may potentially be symbol tables. This doesn't necessarily mean that there are no uses, we just can't conservatively prove it.
Source code in xdsl/utils/symbol_table.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
replace_all_symbol_uses(old_symbol: StringAttr | Operation, new_symbol: StringAttr, from_op: Operation | Region) -> bool
staticmethod
Attempt to replace all uses of the given symbol old_symbol with the provided
symbol new_symbol that are nested within the given operation from_op.
This does not traverse into any nested symbol tables.
If there are any unknown operations that may potentially be symbol tables, no
uses are replaced and False is returned.
Source code in xdsl/utils/symbol_table.py
241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
SymbolTableCollection
This class represents a collection of SymbolTables.
It simplifies certain algorithms that run recursively on nested symbol tables.
Symbol tables are constructed lazily to reduce the upfront cost of constructing
unnecessary tables.
Source code in xdsl/utils/symbol_table.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
symbol_tables: Mapping[Operation, SymbolTable]
property
__init__() -> None
Source code in xdsl/utils/symbol_table.py
267 268 | |
lookup_symbol_in(op: Operation, symbol: StringAttr | SymbolRefAttr | str, *, all_symbols: bool = False) -> list[Operation] | Operation | None
staticmethod
lookup_symbol_in(
op: Operation,
symbol: StringAttr | SymbolRefAttr | str,
*,
all_symbols: Literal[True],
) -> list[Operation] | None
lookup_symbol_in(
op: Operation,
symbol: StringAttr | SymbolRefAttr | str,
*,
all_symbols: Literal[False],
) -> Operation | None
Look up a symbol with the specified name within the specified symbol table
operation, returning None if no such name exists.
Accepts either a StringAttr or a SymbolRefAttr.
op is required to be an operation with the 'xdsl.traits.SymbolTable' trait.
If all_symbols is True, returns all symbols referenced by the symbol.
Source code in xdsl/utils/symbol_table.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
lookup_nearest_symbol_from(from_op: Operation, symbol: StringAttr | SymbolRefAttr) -> Operation | None
staticmethod
Returns the operation registered with the given symbol name within the closest
parent operation of, or including, from_op with the
SymbolTable trait.
Returns None if no valid symbol was found.
Source code in xdsl/utils/symbol_table.py
308 309 310 311 312 313 314 315 316 317 318 | |
get_symbol_table(op: Operation) -> SymbolTable
Lookup, or create, a symbol table for an operation.
Source code in xdsl/utils/symbol_table.py
320 321 322 323 324 | |
walk_symbol_table(op: Operation) -> Iterator[Operation]
Walk all of the operations nested under, and including, the given operation, without traversing into any nested symbol tables.
Source code in xdsl/utils/symbol_table.py
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | |