MLIR 22.0.0git
UseDefaultVisibilityPass.cpp
Go to the documentation of this file.
1//===- UseDefaultVisibilityPass.cpp - Update default visibility -----------===//
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
12#include "mlir/Pass/Pass.h"
13#include "llvm/ADT/TypeSwitch.h"
14
15namespace mlir {
16namespace LLVM {
17#define GEN_PASS_DEF_LLVMUSEDEFAULTVISIBILITYPASS
18#include "mlir/Dialect/LLVMIR/Transforms/Passes.h.inc"
19} // namespace LLVM
20} // namespace mlir
21
22using namespace mlir;
23
24namespace {
25class UseDefaultVisibilityPass
26 : public LLVM::impl::LLVMUseDefaultVisibilityPassBase<
27 UseDefaultVisibilityPass> {
28 using Base::Base;
29
30public:
31 void runOnOperation() override {
32 LLVM::Visibility useDefaultVisibility = useVisibility.getValue();
33 if (useDefaultVisibility == LLVM::Visibility::Default)
34 return;
35 Operation *op = getOperation();
36 op->walk([&](Operation *op) {
37 llvm::TypeSwitch<Operation *, void>(op)
38 .Case<LLVM::LLVMFuncOp, LLVM::GlobalOp, LLVM::IFuncOp, LLVM::AliasOp>(
39 [&](auto op) {
40 if (op.getVisibility_() == LLVM::Visibility::Default)
41 op.setVisibility_(useDefaultVisibility);
42 });
43 });
44 }
45};
46} // namespace
std::enable_if_t< llvm::function_traits< std::decay_t< FnT > >::num_args==1, RetT > walk(FnT &&callback)
Walk the operation by calling the callback for each nested operation (including this one),...
Definition Operation.h:797
Include the generated interface declarations.