[llvm] [RISCV][DebugInfo] Maintain CFI information during branch-folder (PR #200767)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 1 02:41:47 PDT 2026
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp,h -- llvm/include/llvm/CodeGen/TargetInstrInfo.h llvm/lib/CodeGen/BranchFolding.cpp llvm/lib/CodeGen/BranchFolding.h llvm/lib/CodeGen/CFIFixup.cpp llvm/lib/CodeGen/MachineVerifier.cpp llvm/lib/CodeGen/TargetInstrInfo.cpp --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/lib/CodeGen/BranchFolding.cpp b/llvm/lib/CodeGen/BranchFolding.cpp
index 371285ae1..f637acfc0 100644
--- a/llvm/lib/CodeGen/BranchFolding.cpp
+++ b/llvm/lib/CodeGen/BranchFolding.cpp
@@ -26,7 +26,6 @@
#include "llvm/CodeGen/Analysis.h"
#include "llvm/CodeGen/BranchFoldingPass.h"
#include "llvm/CodeGen/MBFIWrapper.h"
-#include "llvm/MC/MCDwarf.h"
#include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
#include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
#include "llvm/CodeGen/MachineDominators.h"
@@ -51,6 +50,7 @@
#include "llvm/IR/Function.h"
#include "llvm/InitializePasses.h"
#include "llvm/MC/LaneBitmask.h"
+#include "llvm/MC/MCDwarf.h"
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/Pass.h"
#include "llvm/Support/BlockFrequency.h"
@@ -397,10 +397,10 @@ void BranchFolder::tryFixupCFI(MachineBasicBlock::iterator OldInst) {
if (auto Id = TII->isReloadOfCSR(&*MI))
Restores.insert(*Id);
if (auto Id = TII->isCFIRestoreOfCSR(&*MI)) {
- auto RestoredId = find_if(Restores, [&](auto Id2) {
- return TRI->regsOverlap(*Id, Id2);
- });
- assert(Restores.contains(*RestoredId) && "Must've seen reload of register before CFI restore.");
+ auto RestoredId = find_if(
+ Restores, [&](auto Id2) { return TRI->regsOverlap(*Id, Id2); });
+ assert(Restores.contains(*RestoredId) &&
+ "Must've seen reload of register before CFI restore.");
Restores.erase(*RestoredId);
}
}
diff --git a/llvm/lib/CodeGen/MachineVerifier.cpp b/llvm/lib/CodeGen/MachineVerifier.cpp
index ee8d03072..922938630 100644
--- a/llvm/lib/CodeGen/MachineVerifier.cpp
+++ b/llvm/lib/CodeGen/MachineVerifier.cpp
@@ -4199,12 +4199,13 @@ void MachineVerifier::verifyCFI() {
if (auto Id = TII->isCFIRestoreOfCSR(&MI))
FrameDestroyCFI.push_back(*Id);
}
- if (Restores.size() != FrameDestroyCFI.size() || any_of(FrameDestroyCFI, [&](auto Reg) {
- for (auto Reg2 : Restores)
- if (TRI->regsOverlap(Reg, Reg2))
- return false;
- return true;
- })) {
+ if (Restores.size() != FrameDestroyCFI.size() ||
+ any_of(FrameDestroyCFI, [&](auto Reg) {
+ for (auto Reg2 : Restores)
+ if (TRI->regsOverlap(Reg, Reg2))
+ return false;
+ return true;
+ })) {
report("Invalid CFI informarion", MF);
OS << "\nCFI info does not match restores of CSRs.\n" << MBB << "\n";
}
diff --git a/llvm/lib/CodeGen/TargetInstrInfo.cpp b/llvm/lib/CodeGen/TargetInstrInfo.cpp
index 9fa800893..a9d5df3c9 100644
--- a/llvm/lib/CodeGen/TargetInstrInfo.cpp
+++ b/llvm/lib/CodeGen/TargetInstrInfo.cpp
@@ -31,13 +31,13 @@
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/MC/MCAsmInfo.h"
+#include "llvm/MC/MCDwarf.h"
#include "llvm/MC/MCInstrItineraries.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/InterleavedRange.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
-#include "llvm/MC/MCDwarf.h"
using namespace llvm;
@@ -2234,7 +2234,8 @@ bool TargetInstrInfo::isGlobalMemoryObject(const MachineInstr *MI) const {
(MI->hasOrderedMemoryRef() && !MI->isDereferenceableInvariantLoad());
}
-std::optional<unsigned> TargetInstrInfo::isCFIRestoreOfCSR(const MachineInstr *MI) const {
+std::optional<unsigned>
+TargetInstrInfo::isCFIRestoreOfCSR(const MachineInstr *MI) const {
if (!MI->isCFIInstruction() || !MI->getFlag(MachineInstr::FrameDestroy))
return std::nullopt;
const MachineFunction *MF = MI->getParent()->getParent();
@@ -2249,7 +2250,8 @@ std::optional<unsigned> TargetInstrInfo::isCFIRestoreOfCSR(const MachineInstr *M
return Reg->id();
}
-std::optional<unsigned> TargetInstrInfo::isReloadOfCSR(const MachineInstr *MI) const {
+std::optional<unsigned>
+TargetInstrInfo::isReloadOfCSR(const MachineInstr *MI) const {
if (!MI->mayLoad() || !MI->getFlag(MachineInstr::FrameDestroy))
return std::nullopt;
const MachineOperand &MO = MI->getOperand(0);
``````````
</details>
https://github.com/llvm/llvm-project/pull/200767
More information about the llvm-commits
mailing list