MLIR 23.0.0git
SymbolPrivatize.cpp
Go to the documentation of this file.
1//===- SymbolPrivatize.cpp - Pass to mark symbols private -----------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements an pass that marks all symbols as private unless
10// excluded.
11//
12//===----------------------------------------------------------------------===//
13
15
16#include "mlir/IR/SymbolTable.h"
17
18namespace mlir {
19#define GEN_PASS_DEF_SYMBOLPRIVATIZEPASS
20#include "mlir/Transforms/Passes.h.inc"
21} // namespace mlir
22
23using namespace mlir;
24
25namespace {
26struct SymbolPrivatize : public impl::SymbolPrivatizePassBase<SymbolPrivatize> {
27 using impl::SymbolPrivatizePassBase<SymbolPrivatize>::SymbolPrivatizePassBase;
28 LogicalResult initialize(MLIRContext *context) override;
29 void runOnOperation() override;
30
31 /// Symbols whose visibility won't be changed.
32 DenseSet<StringAttr> excludedSymbols;
33};
34} // namespace
35
36LogicalResult SymbolPrivatize::initialize(MLIRContext *context) {
37 for (const std::string &symbol : exclude)
38 excludedSymbols.insert(StringAttr::get(context, symbol));
39 return success();
40}
41
42void SymbolPrivatize::runOnOperation() {
43 for (Region &region : getOperation()->getRegions()) {
44 for (Block &block : region) {
45 for (Operation &op : block) {
46 auto symbol = dyn_cast<SymbolOpInterface>(op);
47 if (!symbol)
48 continue;
49 if (!excludedSymbols.contains(symbol.getNameAttr()))
50 symbol.setVisibility(SymbolTable::Visibility::Private);
51 }
52 }
53 }
54}
return success()
LogicalResult initialize(unsigned origNumLoops, ArrayRef< ReassociationIndices > foldedIterationDims)
MLIRContext is the top-level object for a collection of MLIR operations.
Definition MLIRContext.h:63
Include the generated interface declarations.
llvm::DenseSet< ValueT, ValueInfoT > DenseSet
Definition LLVM.h:120