[llvm] [NVPTX] Fixing debug symbols for ptx target emitting (PR #101891)
Vyom Sharma via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 7 11:00:35 PDT 2024
https://github.com/vyom1611 updated https://github.com/llvm/llvm-project/pull/101891
>From 0c1eb6c9cef13b3d02d0b5617722ce1ebcad1465 Mon Sep 17 00:00:00 2001
From: vyom1611 <sharm843 at umn.edu>
Date: Sun, 4 Aug 2024 20:23:07 +0530
Subject: [PATCH 1/2] [NVPTX] Fixing debug symbols for ptx target emitting
---
.../NVPTX/NVPTXAssignValidGlobalNames.cpp | 47 +++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/llvm/lib/Target/NVPTX/NVPTXAssignValidGlobalNames.cpp b/llvm/lib/Target/NVPTX/NVPTXAssignValidGlobalNames.cpp
index 9f5a217795183..b687e6ceba504 100644
--- a/llvm/lib/Target/NVPTX/NVPTXAssignValidGlobalNames.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXAssignValidGlobalNames.cpp
@@ -18,6 +18,7 @@
#include "NVPTX.h"
#include "llvm/ADT/StringExtras.h"
+#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/LegacyPassManager.h"
@@ -38,6 +39,9 @@ class NVPTXAssignValidGlobalNames : public ModulePass {
/// Clean up the name to remove symbols invalid in PTX.
std::string cleanUpName(StringRef Name);
+
+ /// Clean up the debug symbols.
+ void cleanUpDebugSymbols(Module &M);
};
}
@@ -67,6 +71,9 @@ bool NVPTXAssignValidGlobalNames::runOnModule(Module &M) {
if (F.hasLocalLinkage())
F.setName(cleanUpName(F.getName()));
+ // Clean up the debug symbols.
+ cleanUpDebugSymbols(M);
+
return true;
}
@@ -86,6 +93,46 @@ std::string NVPTXAssignValidGlobalNames::cleanUpName(StringRef Name) {
return ValidNameStream.str();
}
+void NVPTXAssignValidGlobalNames::cleanUpDebugSymbols(Module &M) {
+ LLVMContext &Ctx = M.getContext();
+
+ for (Function &F : M.functions()) {
+ if (DISubprogram *SP = F.getSubprogram()) {
+ auto CleanedName = cleanUpName(SP->getLinkageName());
+ if (!CleanedName.empty()) {
+ SP->replaceLinkageName(MDString::get(Ctx, CleanedName));
+ }
+ }
+ }
+
+ for (GlobalVariable &GV : M.globals()) {
+ SmallVector<DIGlobalVariableExpression *, 1> GVs;
+ GV.getDebugInfo(GVs);
+ for (auto *GVE : GVs) {
+ DIGlobalVariable *GVMD = GVE->getVariable();
+ auto CleanedName = cleanUpName(GVMD->getLinkageName());
+ if (!CleanedName.empty()) {
+ DIGlobalVariable *NewGVMD = DIGlobalVariable::get(
+ Ctx,
+ GVMD->getScope(),
+ GVMD->getName(),
+ CleanedName, // Use the cleaned name as StringRef
+ GVMD->getFile(),
+ GVMD->getLine(),
+ GVMD->getType(),
+ GVMD->isLocalToUnit(),
+ GVMD->isDefinition(),
+ GVMD->getStaticDataMemberDeclaration(),
+ GVMD->getTemplateParams(),
+ GVMD->getAlignInBits(),
+ GVMD->getAnnotations()
+ );
+ GVMD->replaceAllUsesWith(NewGVMD);
+ }
+ }
+ }
+}
+
ModulePass *llvm::createNVPTXAssignValidGlobalNamesPass() {
return new NVPTXAssignValidGlobalNames();
}
>From 64e683ae02d3c601fc7fc3401873eeb8893c8a1d Mon Sep 17 00:00:00 2001
From: vyom1611 <sharm843 at umn.edu>
Date: Wed, 7 Aug 2024 11:12:25 +0530
Subject: [PATCH 2/2] clang-format linting
---
.../NVPTX/NVPTXAssignValidGlobalNames.cpp | 24 +++++++------------
1 file changed, 8 insertions(+), 16 deletions(-)
diff --git a/llvm/lib/Target/NVPTX/NVPTXAssignValidGlobalNames.cpp b/llvm/lib/Target/NVPTX/NVPTXAssignValidGlobalNames.cpp
index b687e6ceba504..06596fab539b5 100644
--- a/llvm/lib/Target/NVPTX/NVPTXAssignValidGlobalNames.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXAssignValidGlobalNames.cpp
@@ -39,7 +39,7 @@ class NVPTXAssignValidGlobalNames : public ModulePass {
/// Clean up the name to remove symbols invalid in PTX.
std::string cleanUpName(StringRef Name);
-
+
/// Clean up the debug symbols.
void cleanUpDebugSymbols(Module &M);
};
@@ -95,7 +95,7 @@ std::string NVPTXAssignValidGlobalNames::cleanUpName(StringRef Name) {
void NVPTXAssignValidGlobalNames::cleanUpDebugSymbols(Module &M) {
LLVMContext &Ctx = M.getContext();
-
+
for (Function &F : M.functions()) {
if (DISubprogram *SP = F.getSubprogram()) {
auto CleanedName = cleanUpName(SP->getLinkageName());
@@ -113,20 +113,12 @@ void NVPTXAssignValidGlobalNames::cleanUpDebugSymbols(Module &M) {
auto CleanedName = cleanUpName(GVMD->getLinkageName());
if (!CleanedName.empty()) {
DIGlobalVariable *NewGVMD = DIGlobalVariable::get(
- Ctx,
- GVMD->getScope(),
- GVMD->getName(),
- CleanedName, // Use the cleaned name as StringRef
- GVMD->getFile(),
- GVMD->getLine(),
- GVMD->getType(),
- GVMD->isLocalToUnit(),
- GVMD->isDefinition(),
- GVMD->getStaticDataMemberDeclaration(),
- GVMD->getTemplateParams(),
- GVMD->getAlignInBits(),
- GVMD->getAnnotations()
- );
+ Ctx, GVMD->getScope(), GVMD->getName(),
+ CleanedName, // Use the cleaned name as StringRef
+ GVMD->getFile(), GVMD->getLine(), GVMD->getType(),
+ GVMD->isLocalToUnit(), GVMD->isDefinition(),
+ GVMD->getStaticDataMemberDeclaration(), GVMD->getTemplateParams(),
+ GVMD->getAlignInBits(), GVMD->getAnnotations());
GVMD->replaceAllUsesWith(NewGVMD);
}
}
More information about the llvm-commits
mailing list