[Mlir-commits] [mlir] [MLIR][LLVM] Allow importing of nameless globals (PR #101918)

Tobias Gysi llvmlistbot at llvm.org
Mon Aug 5 02:36:31 PDT 2024


================
@@ -884,9 +890,20 @@ LogicalResult ModuleImport::convertGlobal(llvm::GlobalVariable *globalVar) {
     globalExpressionAttr =
         debugImporter->translateGlobalVariableExpression(globalExpressions[0]);
 
+  // Workaround to support LLVM's nameless globals. MLIR, in contrast to LLVM,
+  // always requires a symbol name.
+  std::string globalName = globalVar->getName().str();
+  if (globalName.empty()) {
+    // Make sure the symbol name does not clash with an existing symbol.
+    do {
+      globalName =
+          getNamelessGlobalPrefix().str() + std::to_string(namelessGlobalId++);
+    } while (llvmModule->getNamedValue(globalName));
----------------
gysit wrote:

Works for me. The SymbolTable also has a static function for this `generateSymbolName`. I think I commented before but I don't see the comment now... So I am trying to repost in case it got lost in GitHub somewhere.

The amount of code saved is not too large so feel free to keep this if the exact format of the name is relevant.

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


More information about the Mlir-commits mailing list