MLIR
23.0.0git
lib
Transforms
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
14
#include "
mlir/Transforms/Passes.h
"
15
16
#include "
mlir/IR/SymbolTable.h
"
17
18
namespace
mlir
{
19
#define GEN_PASS_DEF_SYMBOLPRIVATIZEPASS
20
#include "mlir/Transforms/Passes.h.inc"
21
}
// namespace mlir
22
23
using namespace
mlir
;
24
25
namespace
{
26
struct
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
36
LogicalResult SymbolPrivatize::initialize(
MLIRContext
*context) {
37
for
(
const
std::string &symbol : exclude)
38
excludedSymbols.insert(StringAttr::get(context, symbol));
39
return
success
();
40
}
41
42
void
SymbolPrivatize::runOnOperation() {
43
for
(Region ®ion : 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
}
success
return success()
initialize
LogicalResult initialize(unsigned origNumLoops, ArrayRef< ReassociationIndices > foldedIterationDims)
Definition
ElementwiseOpFusion.cpp:1
SymbolTable.h
Passes.h
mlir::MLIRContext
MLIRContext is the top-level object for a collection of MLIR operations.
Definition
MLIRContext.h:63
mlir::impl::SymbolPrivatizePassBase
Definition
SymbolPrivatize.cpp:1647
mlir
Include the generated interface declarations.
Definition
AliasAnalysis.h:19
mlir::DenseSet
llvm::DenseSet< ValueT, ValueInfoT > DenseSet
Definition
LLVM.h:120
mlir::HoistingKind::Block
@ Block
Definition
AllocationOpInterface.h:24
Generated on
for MLIR by
1.14.0