[flang-commits] [flang] [RFC][flang] Replace special symbols in uniqued global names. (PR #104859)

Slava Zakharin via flang-commits flang-commits at lists.llvm.org
Tue Aug 20 09:55:23 PDT 2024


================
@@ -0,0 +1,80 @@
+//=== CompilerGeneratedNames.cpp - convert special symbols in global names ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "flang/Optimizer/Dialect/FIRDialect.h"
+#include "flang/Optimizer/Dialect/FIROps.h"
+#include "flang/Optimizer/Dialect/FIROpsSupport.h"
+#include "flang/Optimizer/Support/InternalNames.h"
+#include "flang/Optimizer/Transforms/Passes.h"
+#include "mlir/IR/Attributes.h"
+#include "mlir/IR/SymbolTable.h"
+#include "mlir/Pass/Pass.h"
+
+namespace fir {
+#define GEN_PASS_DEF_COMPILERGENERATEDNAMESCONVERSION
+#include "flang/Optimizer/Transforms/Passes.h.inc"
+} // namespace fir
+
+using namespace mlir;
+
+namespace {
+
+class CompilerGeneratedNamesConversionPass
+    : public fir::impl::CompilerGeneratedNamesConversionBase<
+          CompilerGeneratedNamesConversionPass> {
+public:
+  using CompilerGeneratedNamesConversionBase<
+      CompilerGeneratedNamesConversionPass>::
+      CompilerGeneratedNamesConversionBase;
+
+  mlir::ModuleOp getModule() { return getOperation(); }
+  void runOnOperation() override;
+};
+} // namespace
+
+void CompilerGeneratedNamesConversionPass::runOnOperation() {
+  auto op = getOperation();
+  auto *context = &getContext();
+
+  llvm::DenseMap<mlir::StringAttr, mlir::FlatSymbolRefAttr> remappings;
+  for (auto &funcOrGlobal : op->getRegion(0).front()) {
+    if (llvm::isa<mlir::func::FuncOp>(funcOrGlobal) ||
+        llvm::isa<fir::GlobalOp>(funcOrGlobal)) {
+      auto symName = funcOrGlobal.getAttrOfType<mlir::StringAttr>(
+          mlir::SymbolTable::getSymbolAttrName());
+      auto deconstructedName = fir::NameUniquer::deconstruct(symName);
+      if (deconstructedName.first != fir::NameUniquer::NameKind::NOT_UNIQUED &&
----------------
vzakhari wrote:

Thank you for the pointers, Jean and Val!  I would like to address these cases separately.

These names do not look quite from the reserved name space to me, so I guess they may conflict with the user space if I try to replace `.` with `X` in them (e.g. when linking with an object file created from a C module).  I think I can try to put them into the "Flang's name space", e.g. `@_QEdefault.nonTbpDefinedIoTable` or `@_QECdefault.nonTbpDefinedIoTable`, then the new pass should work for them and we will be safe from the name conflicts (given that `_Q` is reserved).

https://github.com/llvm/llvm-project/pull/104859


More information about the flang-commits mailing list