[llvm] [IR][ARM64EC][NFC] Clean up and document ARM64EC mangling helpers. (PR #107230)

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 4 12:40:40 PDT 2024


================
@@ -291,39 +291,41 @@ void llvm::emitLinkerFlagsForUsedCOFF(raw_ostream &OS, const GlobalValue *GV,
 }
 
 std::optional<std::string> llvm::getArm64ECMangledFunctionName(StringRef Name) {
-  bool IsCppFn = Name[0] == '?';
-  if (IsCppFn && Name.contains("$$h"))
-    return std::nullopt;
-  if (!IsCppFn && Name[0] == '#')
-    return std::nullopt;
+  if (Name[0] != '?') {
+    // For non-C++ symbols, prefix the name with "#" unless it's already
+    // mangled.
+    if (Name[0] == '#')
+      return std::nullopt;
+    return std::optional<std::string>(("#" + Name).str());
+  }
 
-  StringRef Prefix = "$$h";
+  // Insert the ARM64EC "$$h" tag after the mangled function name.
+  if (Name.contains("$$h"))
+    return std::nullopt;
   size_t InsertIdx = 0;
-  if (IsCppFn) {
-    InsertIdx = Name.find("@@");
-    size_t ThreeAtSignsIdx = Name.find("@@@");
-    if (InsertIdx != std::string::npos && InsertIdx != ThreeAtSignsIdx) {
-      InsertIdx += 2;
-    } else {
-      InsertIdx = Name.find("@");
-      if (InsertIdx != std::string::npos)
-        InsertIdx++;
-    }
+  InsertIdx = Name.find("@@");
----------------
mstorsjo wrote:

You can probably merge this with the declaration of `InsertIdx` on the previous line now?

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


More information about the llvm-commits mailing list