-
Notifications
You must be signed in to change notification settings - Fork 14k
[GlobalOpt] Update debug info when changing CC to Fast #144303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-debuginfo @llvm/pr-subscribers-llvm-transforms Author: Maurice Heumann (momo5502) ChangesChanging the CC of local functions to This fixes #144301 Full diff: https://github.com/llvm/llvm-project/pull/144303.diff 1 Files Affected:
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;
}
|
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; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a bit brittle, if other targets had other calling convention choices - perhaps this logic should go wherever the CC is determined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. However, I think the mapping for fastcc is determined by a table definition for each architecture. I feel like integrating this there is not easily feasible.
Do you have a recommendation on how this could be done better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you point to the table definition, we/someone could take a look to see how practical it is.
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