[llvm] [LLVM][CodeGen] Let eraseFromParent return iterator (PR #109849)
Yida Zhang via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 25 09:17:05 PDT 2024
https://github.com/zyd2001 updated https://github.com/llvm/llvm-project/pull/109849
>From f42963a7a5a1327fa396bb6c1f9f23809c5d6c15 Mon Sep 17 00:00:00 2001
From: Yida Zhang <zhan3339 at purdue.edu>
Date: Tue, 24 Sep 2024 15:21:21 -0400
Subject: [PATCH 1/2] let eraseFromParent return iterator
---
llvm/include/llvm/CodeGen/MachineBasicBlock.h | 18 +++++++++++++++++-
llvm/include/llvm/CodeGen/MachineFunction.h | 18 ++----------------
llvm/include/llvm/CodeGen/MachineInstr.h | 3 ++-
llvm/lib/CodeGen/MachineBasicBlock.cpp | 4 ++--
llvm/lib/CodeGen/MachineInstr.cpp | 5 +++--
5 files changed, 26 insertions(+), 22 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/MachineBasicBlock.h b/llvm/include/llvm/CodeGen/MachineBasicBlock.h
index 6cf151c951b19f..fd7160c75cf21e 100644
--- a/llvm/include/llvm/CodeGen/MachineBasicBlock.h
+++ b/llvm/include/llvm/CodeGen/MachineBasicBlock.h
@@ -43,6 +43,22 @@ class raw_ostream;
class LiveIntervals;
class TargetRegisterClass;
class TargetRegisterInfo;
+
+template <> struct ilist_alloc_traits<MachineBasicBlock> {
+ void deleteNode(MachineBasicBlock *MBB);
+};
+
+template <> struct ilist_callback_traits<MachineBasicBlock> {
+ void addNodeToList(MachineBasicBlock* N);
+ void removeNodeFromList(MachineBasicBlock* N);
+
+ template <class Iterator>
+ void transferNodesFromList(ilist_callback_traits &OldList, Iterator, Iterator) {
+ assert(this == &OldList && "never transfer MBBs between functions");
+ }
+};
+
+
template <typename IRUnitT, typename... ExtraArgTs> class AnalysisManager;
using MachineFunctionAnalysisManager = AnalysisManager<MachineFunction>;
@@ -1126,7 +1142,7 @@ class MachineBasicBlock
MachineBasicBlock *removeFromParent();
/// This method unlinks 'this' from the containing function and deletes it.
- void eraseFromParent();
+ ilist<MachineBasicBlock>::iterator eraseFromParent();
/// Given a machine basic block that branched to 'Old', change the code and
/// CFG so that it branches to 'New' instead.
diff --git a/llvm/include/llvm/CodeGen/MachineFunction.h b/llvm/include/llvm/CodeGen/MachineFunction.h
index aeb72ca24d79b8..3e59fdc5c7791e 100644
--- a/llvm/include/llvm/CodeGen/MachineFunction.h
+++ b/llvm/include/llvm/CodeGen/MachineFunction.h
@@ -74,20 +74,6 @@ class TargetSubtargetInfo;
struct WasmEHFuncInfo;
struct WinEHFuncInfo;
-template <> struct ilist_alloc_traits<MachineBasicBlock> {
- void deleteNode(MachineBasicBlock *MBB);
-};
-
-template <> struct ilist_callback_traits<MachineBasicBlock> {
- void addNodeToList(MachineBasicBlock* N);
- void removeNodeFromList(MachineBasicBlock* N);
-
- template <class Iterator>
- void transferNodesFromList(ilist_callback_traits &OldList, Iterator, Iterator) {
- assert(this == &OldList && "never transfer MBBs between functions");
- }
-};
-
/// MachineFunctionInfo - This class can be derived from and used by targets to
/// hold private target-specific information for each MachineFunction. Objects
/// of type are accessed/created with MF::getInfo and destroyed when the
@@ -958,8 +944,8 @@ class LLVM_ABI MachineFunction {
void remove(iterator MBBI) { BasicBlocks.remove(MBBI); }
void remove(MachineBasicBlock *MBBI) { BasicBlocks.remove(MBBI); }
- void erase(iterator MBBI) { BasicBlocks.erase(MBBI); }
- void erase(MachineBasicBlock *MBBI) { BasicBlocks.erase(MBBI); }
+ iterator erase(iterator MBBI) { return BasicBlocks.erase(MBBI); }
+ iterator erase(MachineBasicBlock *MBBI) { return BasicBlocks.erase(MBBI); }
template <typename Comp>
void sort(Comp comp) {
diff --git a/llvm/include/llvm/CodeGen/MachineInstr.h b/llvm/include/llvm/CodeGen/MachineInstr.h
index 76a7b8662bae66..4eaf9698ad3e7d 100644
--- a/llvm/include/llvm/CodeGen/MachineInstr.h
+++ b/llvm/include/llvm/CodeGen/MachineInstr.h
@@ -21,6 +21,7 @@
#include "llvm/ADT/ilist_node.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/Analysis/MemoryLocation.h"
+#include "llvm/CodeGen/MachineInstrBundleIterator.h"
#include "llvm/CodeGen/MachineMemOperand.h"
#include "llvm/CodeGen/MachineOperand.h"
#include "llvm/CodeGen/TargetOpcodes.h"
@@ -1309,7 +1310,7 @@ class MachineInstr
/// If this instruction is the header of a bundle, the whole bundle is erased.
/// This function can not be used for instructions inside a bundle, use
/// eraseFromBundle() to erase individual bundled instructions.
- void eraseFromParent();
+ MachineInstrBundleIterator<MachineInstr> eraseFromParent();
/// Unlink 'this' from its basic block and delete it.
///
diff --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp b/llvm/lib/CodeGen/MachineBasicBlock.cpp
index 5d06af3ebf3360..3602fa5141b38a 100644
--- a/llvm/lib/CodeGen/MachineBasicBlock.cpp
+++ b/llvm/lib/CodeGen/MachineBasicBlock.cpp
@@ -1471,9 +1471,9 @@ MachineBasicBlock *MachineBasicBlock::removeFromParent() {
}
/// This method unlinks 'this' from the containing function, and deletes it.
-void MachineBasicBlock::eraseFromParent() {
+ilist<MachineBasicBlock>::iterator MachineBasicBlock::eraseFromParent() {
assert(getParent() && "Not embedded in a function!");
- getParent()->erase(this);
+ return getParent()->erase(this);
}
/// Given a machine basic block that branched to 'Old', change the code and CFG
diff --git a/llvm/lib/CodeGen/MachineInstr.cpp b/llvm/lib/CodeGen/MachineInstr.cpp
index 0d78c2cafbaf63..a3b0c6895667b7 100644
--- a/llvm/lib/CodeGen/MachineInstr.cpp
+++ b/llvm/lib/CodeGen/MachineInstr.cpp
@@ -23,6 +23,7 @@
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineInstrBundle.h"
+#include "llvm/CodeGen/MachineInstrBundleIterator.h"
#include "llvm/CodeGen/MachineMemOperand.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/CodeGen/MachineOperand.h"
@@ -758,9 +759,9 @@ MachineInstr *MachineInstr::removeFromBundle() {
return getParent()->remove_instr(this);
}
-void MachineInstr::eraseFromParent() {
+MachineInstrBundleIterator<MachineInstr> MachineInstr::eraseFromParent() {
assert(getParent() && "Not embedded in a basic block!");
- getParent()->erase(this);
+ return getParent()->erase(this);
}
void MachineInstr::eraseFromBundle() {
>From 0cb111918e9b0d7b076e25ff8088b50413b386de Mon Sep 17 00:00:00 2001
From: Yida Zhang <zhan3339 at purdue.edu>
Date: Wed, 25 Sep 2024 12:16:37 -0400
Subject: [PATCH 2/2] fix format
---
llvm/include/llvm/CodeGen/MachineBasicBlock.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/MachineBasicBlock.h b/llvm/include/llvm/CodeGen/MachineBasicBlock.h
index fd7160c75cf21e..db1e19336cdb59 100644
--- a/llvm/include/llvm/CodeGen/MachineBasicBlock.h
+++ b/llvm/include/llvm/CodeGen/MachineBasicBlock.h
@@ -49,16 +49,16 @@ template <> struct ilist_alloc_traits<MachineBasicBlock> {
};
template <> struct ilist_callback_traits<MachineBasicBlock> {
- void addNodeToList(MachineBasicBlock* N);
- void removeNodeFromList(MachineBasicBlock* N);
+ void addNodeToList(MachineBasicBlock *N);
+ void removeNodeFromList(MachineBasicBlock *N);
template <class Iterator>
- void transferNodesFromList(ilist_callback_traits &OldList, Iterator, Iterator) {
+ void transferNodesFromList(ilist_callback_traits &OldList, Iterator,
+ Iterator) {
assert(this == &OldList && "never transfer MBBs between functions");
}
};
-
template <typename IRUnitT, typename... ExtraArgTs> class AnalysisManager;
using MachineFunctionAnalysisManager = AnalysisManager<MachineFunction>;
More information about the llvm-commits
mailing list