[PATCH] D37016: [GISel]: Allow the MachineIRBuilder to insert instructions after
Aditya Nandakumar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 22 11:24:20 PDT 2017
aditya_nandakumar created this revision.
At times, it's necessary to insert instruction after an iterator.
Allow to specify InsertAfter as a boolean in the setInstr interface.
Repository:
rL LLVM
https://reviews.llvm.org/D37016
Files:
include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
Index: lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
===================================================================
--- lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
+++ lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
@@ -39,18 +39,21 @@
"Basic block is in a different function");
}
-void MachineIRBuilder::setInstr(MachineInstr &MI) {
+void MachineIRBuilder::setInstr(MachineInstr &MI, bool InsertAfter) {
assert(MI.getParent() && "Instruction is not part of a basic block");
setMBB(*MI.getParent());
this->II = MI.getIterator();
+ this->InsertAfter = InsertAfter;
}
void MachineIRBuilder::setInsertPt(MachineBasicBlock &MBB,
- MachineBasicBlock::iterator II) {
+ MachineBasicBlock::iterator II,
+ bool InsertAfter) {
assert(MBB.getParent() == &getMF() &&
"Basic block is in a different function");
this->MBB = &MBB;
this->II = II;
+ this->InsertAfter = InsertAfter;
}
void MachineIRBuilder::recordInsertions(
@@ -77,7 +80,12 @@
MachineInstrBuilder MachineIRBuilder::insertInstr(MachineInstrBuilder MIB) {
- getMBB().insert(getInsertPt(), MIB);
+ auto &MBB = getMBB();
+ if (!InsertAfter)
+ MBB.insert(getInsertPt(), MIB);
+ else
+ MBB.insertAfter(getInsertPt(), MIB);
+
if (InsertedInstr)
InsertedInstr(MIB);
return MIB;
Index: include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
===================================================================
--- include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
+++ include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
@@ -84,13 +84,15 @@
addUseFromArg(MIB, Arg1);
addUsesFromArgs(MIB, std::forward<UseArgsTy>(Args)...);
}
+
+ bool InsertAfter;
public:
/// Some constructors for easy use.
MachineIRBuilder() = default;
MachineIRBuilder(MachineFunction &MF) { setMF(MF); }
- MachineIRBuilder(MachineInstr &MI)
+ MachineIRBuilder(MachineInstr &MI, bool InsertAfter = false)
: MachineIRBuilder(*MI.getParent()->getParent()) {
- setInstr(MI);
+ setInstr(MI, InsertAfter);
}
/// Getter for the function we currently build.
@@ -113,7 +115,7 @@
/// Set the insertion point before the specified position.
/// \pre MBB must be in getMF().
/// \pre II must be a valid iterator in MBB.
- void setInsertPt(MachineBasicBlock &MBB, MachineBasicBlock::iterator II);
+ void setInsertPt(MachineBasicBlock &MBB, MachineBasicBlock::iterator II, bool InsertAfter = false);
/// @}
/// \name Setters for the insertion point.
@@ -127,7 +129,7 @@
/// Set the insertion point to before MI.
/// \pre MI must be in getMF().
- void setInstr(MachineInstr &MI);
+ void setInstr(MachineInstr &MI, bool InsertAfter = false);
/// @}
/// \name Control where instructions we create are recorded (typically for
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37016.112205.patch
Type: text/x-patch
Size: 2875 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170822/6ca1742f/attachment.bin>
More information about the llvm-commits
mailing list