[mlir] Add support for attaching a visibility to symbols.
authorRiver Riddle <riverriddle@google.com>
Mon, 13 Jan 2020 23:54:08 +0000 (15:54 -0800)
committerRiver Riddle <riverriddle@google.com>
Tue, 14 Jan 2020 00:10:13 +0000 (16:10 -0800)
commit9b92e4fbdb5bc4fdd21702e0ce104dfcac6a54a7
tree99f837503aa875da26506b4899e5f0c070988c79
parent53539bb032d162e0147c0e9650a5d1c7ca77dae0
[mlir] Add support for attaching a visibility to symbols.

Summary:
The visibility defines the structural reachability of the symbol within the IR. Symbols can define one of three visibilities:

* Public
The symbol \may be accessed from outside of the visible IR. We cannot assume that we can observe all of the uses of this symbol.

* Private
The symbol may only be referenced from within the operations in the current symbol table, via SymbolRefAttr.

* Nested
The symbol may be referenced by operations in symbol tables above the current symbol table, as long as each symbol table parent also defines a non-private symbol. This allows or referencing the symbol from outside of the defining symbol table, while retaining the ability for the compiler to see all uses.

These properties help to reason about the properties of a symbol, and will be used in a follow up to implement a dce pass on dead symbols.

A few examples of what this would look like in the IR are shown below:

  module @public_module {
    // This function can be accessed by 'live.user'
    func @nested_function() attributes { sym_visibility = "nested" }

    // This function cannot be accessed outside of 'public_module'
   func @private_function() attributes { sym_visibility = "private" }
  }

  // This function can only be accessed from within this module.
  func @private_function() attributes { sym_visibility = "private" }

  // This function may be referenced externally.
  func @public_function()

  "live.user"() {uses = [@public_module::@nested_function,
                                      @private_function,
                                      @public_function]} : () -> ()

Depends On D72043

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D72044
mlir/include/mlir/IR/SymbolTable.h
mlir/lib/IR/Module.cpp
mlir/lib/IR/SymbolTable.cpp
mlir/test/IR/traits.mlir
mlir/test/lib/TestDialect/TestOps.td