[llvm] [GlobalOpt] Update debug info when changing CC to Fast (PR #144303)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 15 23:35:15 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Maurice Heumann (momo5502)
<details>
<summary>Changes</summary>
Changing the CC of local functions to `fastcc` in GlobalOpt causes the PDB to misalign.
Updating the debug info is requried to reflect the change in the PDB.
This fixes #<!-- -->144301
---
Full diff: https://github.com/llvm/llvm-project/pull/144303.diff
1 Files Affected:
- (modified) llvm/lib/Transforms/IPO/GlobalOpt.cpp (+18)
``````````diff
diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
index 7db0586386506..b0f1dee415efd 100644
--- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -1920,6 +1920,14 @@ static void RemovePreallocated(Function *F) {
}
}
+static unsigned char GetDebugInfoFastCC(const Triple &Triple) {
+ if (Triple.isOSWindows() && Triple.isArch32Bit()) {
+ return llvm::dwarf::DW_CC_BORLAND_msfastcall;
+ }
+
+ return llvm::dwarf::DW_CC_normal;
+}
+
static bool
OptimizeFunctions(Module &M,
function_ref<TargetLibraryInfo &(Function &)> GetTLI,
@@ -1938,6 +1946,9 @@ OptimizeFunctions(Module &M,
if (hasOnlyColdCalls(F, GetBFI, ChangeableCCCache))
AllCallsCold.push_back(&F);
+ unsigned char DebugInfoFastCC =
+ GetDebugInfoFastCC(Triple(M.getTargetTriple()));
+
// Optimize functions.
for (Function &F : llvm::make_early_inc_range(M)) {
// Don't perform global opt pass on naked functions; we don't want fast
@@ -2021,6 +2032,13 @@ OptimizeFunctions(Module &M,
// Fast calling convention.
F.setCallingConv(CallingConv::Fast);
ChangeCalleesToFastCall(&F);
+
+ if (F.getSubprogram()) {
+ DISubprogram *SP = F.getSubprogram();
+ auto Temp = SP->getType()->cloneWithCC(DebugInfoFastCC);
+ SP->replaceType(MDNode::replaceWithPermanent(std::move(Temp)));
+ }
+
++NumFastCallFns;
Changed = true;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/144303
More information about the llvm-commits
mailing list