|
12 | 12 | #include "flang/Optimizer/Dialect/FIROpsSupport.h"
|
13 | 13 | #include "flang/Optimizer/Support/InternalNames.h"
|
14 | 14 | #include "flang/Optimizer/Transforms/Passes.h"
|
| 15 | +#include "mlir/Dialect/GPU/IR/GPUDialect.h" |
15 | 16 | #include "mlir/IR/Attributes.h"
|
16 | 17 | #include "mlir/IR/SymbolTable.h"
|
17 | 18 | #include "mlir/Pass/Pass.h"
|
@@ -58,26 +59,36 @@ void ExternalNameConversionPass::runOnOperation() {
|
58 | 59 | auto *context = &getContext();
|
59 | 60 |
|
60 | 61 | llvm::DenseMap<mlir::StringAttr, mlir::FlatSymbolRefAttr> remappings;
|
61 |
| - // Update names of external Fortran functions and names of Common Block |
62 |
| - // globals. |
63 |
| - for (auto &funcOrGlobal : op->getRegion(0).front()) { |
64 |
| - if (llvm::isa<mlir::func::FuncOp>(funcOrGlobal) || |
65 |
| - llvm::isa<fir::GlobalOp>(funcOrGlobal)) { |
66 |
| - auto symName = funcOrGlobal.getAttrOfType<mlir::StringAttr>( |
67 |
| - mlir::SymbolTable::getSymbolAttrName()); |
68 |
| - auto deconstructedName = fir::NameUniquer::deconstruct(symName); |
69 |
| - if (fir::NameUniquer::isExternalFacingUniquedName(deconstructedName)) { |
70 |
| - auto newName = |
71 |
| - mangleExternalName(deconstructedName, appendUnderscoreOpt); |
72 |
| - auto newAttr = mlir::StringAttr::get(context, newName); |
73 |
| - mlir::SymbolTable::setSymbolName(&funcOrGlobal, newAttr); |
74 |
| - auto newSymRef = mlir::FlatSymbolRefAttr::get(newAttr); |
75 |
| - remappings.try_emplace(symName, newSymRef); |
76 |
| - if (llvm::isa<mlir::func::FuncOp>(funcOrGlobal)) |
77 |
| - funcOrGlobal.setAttr(fir::getInternalFuncNameAttrName(), symName); |
| 62 | + |
| 63 | + auto renameFuncOrGlobalInModule = [&](mlir::Operation *module) { |
| 64 | + for (auto &funcOrGlobal : module->getRegion(0).front()) { |
| 65 | + if (llvm::isa<mlir::func::FuncOp>(funcOrGlobal) || |
| 66 | + llvm::isa<fir::GlobalOp>(funcOrGlobal)) { |
| 67 | + auto symName = funcOrGlobal.getAttrOfType<mlir::StringAttr>( |
| 68 | + mlir::SymbolTable::getSymbolAttrName()); |
| 69 | + auto deconstructedName = fir::NameUniquer::deconstruct(symName); |
| 70 | + if (fir::NameUniquer::isExternalFacingUniquedName(deconstructedName)) { |
| 71 | + auto newName = |
| 72 | + mangleExternalName(deconstructedName, appendUnderscoreOpt); |
| 73 | + auto newAttr = mlir::StringAttr::get(context, newName); |
| 74 | + mlir::SymbolTable::setSymbolName(&funcOrGlobal, newAttr); |
| 75 | + auto newSymRef = mlir::FlatSymbolRefAttr::get(newAttr); |
| 76 | + remappings.try_emplace(symName, newSymRef); |
| 77 | + if (llvm::isa<mlir::func::FuncOp>(funcOrGlobal)) |
| 78 | + funcOrGlobal.setAttr(fir::getInternalFuncNameAttrName(), symName); |
| 79 | + } |
78 | 80 | }
|
79 | 81 | }
|
80 |
| - } |
| 82 | + }; |
| 83 | + |
| 84 | + // Update names of external Fortran functions and names of Common Block |
| 85 | + // globals. |
| 86 | + renameFuncOrGlobalInModule(op); |
| 87 | + |
| 88 | + // Do the same in GPU modules. |
| 89 | + if (auto mod = mlir::dyn_cast_or_null<mlir::ModuleOp>(*op)) |
| 90 | + for (auto gpuMod : mod.getOps<mlir::gpu::GPUModuleOp>()) |
| 91 | + renameFuncOrGlobalInModule(gpuMod); |
81 | 92 |
|
82 | 93 | if (remappings.empty())
|
83 | 94 | return;
|
|
0 commit comments