Skip to content

[RISCV] Make RISCVIndirectBranchTracking visible in debug output #141623

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

Merged
merged 2 commits into from
May 28, 2025

Conversation

jaidTw
Copy link
Contributor

@jaidTw jaidTw commented May 27, 2025

Fix RISC-V Indirect Branch Tracking pass was not showing in the pass debug output due to not initialized properly.

@jaidTw jaidTw requested review from lenary and topperc May 27, 2025 15:37
@llvmbot
Copy link
Member

llvmbot commented May 27, 2025

@llvm/pr-subscribers-backend-risc-v

Author: Jesse Huang (jaidTw)

Changes

Fix RISC-V Indirect Branch Tracking pass was not showing in the pass debug output due to not initialized properly.


Full diff: https://github.com/llvm/llvm-project/pull/141623.diff

2 Files Affected:

  • (modified) llvm/lib/Target/RISCV/RISCVIndirectBranchTracking.cpp (+12-7)
  • (modified) llvm/lib/Target/RISCV/RISCVTargetMachine.cpp (+1)
diff --git a/llvm/lib/Target/RISCV/RISCVIndirectBranchTracking.cpp b/llvm/lib/Target/RISCV/RISCVIndirectBranchTracking.cpp
index 4660a975b20ae..da89589bee47a 100644
--- a/llvm/lib/Target/RISCV/RISCVIndirectBranchTracking.cpp
+++ b/llvm/lib/Target/RISCV/RISCVIndirectBranchTracking.cpp
@@ -20,6 +20,9 @@
 #include "llvm/CodeGen/MachineInstrBuilder.h"
 #include "llvm/CodeGen/MachineModuleInfo.h"
 
+#define DEBUG_TYPE "riscv-indrect-branch-tracking"
+#define PASS_NAME "RISC-V Indirect Branch Tracking"
+
 using namespace llvm;
 
 cl::opt<uint32_t> PreferredLandingPadLabel(
@@ -27,27 +30,29 @@ cl::opt<uint32_t> PreferredLandingPadLabel(
     cl::desc("Use preferred fixed label for all labels"));
 
 namespace {
-class RISCVIndirectBranchTrackingPass : public MachineFunctionPass {
+class RISCVIndirectBranchTracking : public MachineFunctionPass {
 public:
-  RISCVIndirectBranchTrackingPass() : MachineFunctionPass(ID) {}
+  static char ID;
+  RISCVIndirectBranchTracking() : MachineFunctionPass(ID) {}
 
   StringRef getPassName() const override {
-    return "RISC-V Indirect Branch Tracking";
+    return PASS_NAME;
   }
 
   bool runOnMachineFunction(MachineFunction &MF) override;
 
 private:
-  static char ID;
   const Align LpadAlign = Align(4);
 };
 
 } // end anonymous namespace
 
-char RISCVIndirectBranchTrackingPass::ID = 0;
+INITIALIZE_PASS(RISCVIndirectBranchTracking, DEBUG_TYPE, PASS_NAME, false, false)
+
+char RISCVIndirectBranchTracking::ID = 0;
 
 FunctionPass *llvm::createRISCVIndirectBranchTrackingPass() {
-  return new RISCVIndirectBranchTrackingPass();
+  return new RISCVIndirectBranchTracking();
 }
 
 static void emitLpad(MachineBasicBlock &MBB, const RISCVInstrInfo *TII,
@@ -57,7 +62,7 @@ static void emitLpad(MachineBasicBlock &MBB, const RISCVInstrInfo *TII,
       .addImm(Label);
 }
 
-bool RISCVIndirectBranchTrackingPass::runOnMachineFunction(
+bool RISCVIndirectBranchTracking::runOnMachineFunction(
     MachineFunction &MF) {
   const auto &Subtarget = MF.getSubtarget<RISCVSubtarget>();
   const RISCVInstrInfo *TII = Subtarget.getInstrInfo();
diff --git a/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp b/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
index 15dd4d57727dd..8342845ec6f24 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
+++ b/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
@@ -147,6 +147,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeRISCVTarget() {
   initializeRISCVDAGToDAGISelLegacyPass(*PR);
   initializeRISCVMoveMergePass(*PR);
   initializeRISCVPushPopOptPass(*PR);
+  initializeRISCVIndirectBranchTrackingPass(*PR);
   initializeRISCVLoadStoreOptPass(*PR);
   initializeRISCVExpandAtomicPseudoPass(*PR);
   initializeRISCVRedundantCopyEliminationPass(*PR);

Copy link
Collaborator

@topperc topperc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link

github-actions bot commented May 27, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@jaidTw jaidTw merged commit f2cd146 into llvm:main May 28, 2025
11 checks passed
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Jun 3, 2025
…m#141623)

Fix RISC-V Indirect Branch Tracking pass was not showing in the pass
debug output due to not initialized properly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants