summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen
diff options
context:
space:
mode:
authorTim Northover <tnorthover@apple.com>2016-12-07 21:05:38 +0000
committerTim Northover <tnorthover@apple.com>2016-12-07 21:05:38 +0000
commit05cc4859ad289948175382daae0f3ef8c214a8f5 (patch)
treeec252f4fba40a3c82067d11f935e84362315d197 /llvm/lib/CodeGen
parent64a055549a976c5c30c57cbb7ff696e809c79a2e (diff)
downloadbcm5719-llvm-05cc4859ad289948175382daae0f3ef8c214a8f5.tar.gz
bcm5719-llvm-05cc4859ad289948175382daae0f3ef8c214a8f5.zip
GlobalISel: simplify MachineIRBuilder interface.
MachineIRBuilder had weird before/after and beginning/end flags for the insert point. Unfortunately the non-default means that instructions will be inserted in reverse order which is almost never what anyone wants. Really, I think we just want (like IRBuilder has) the ability to insert at any C++ iterator-style point (i.e. before any instruction or before MBB.end()). So this fixes MIRBuilders to behave like IRBuilders in this respect. llvm-svn: 288980
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r--llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp21
-rw-r--r--llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp27
2 files changed, 21 insertions, 27 deletions
diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index c986e65049f..726e89826c5 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -744,13 +744,18 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &MF) {
assert(PendingPHIs.empty() && "stale PHIs");
- // Setup the arguments.
- MachineBasicBlock &MBB = getOrCreateBB(F.front());
- MIRBuilder.setMBB(MBB);
+ // Setup a separate basic-block for the arguments and constants, falling
+ // through to the IR-level Function's entry block.
+ MachineBasicBlock *EntryBB = MF.CreateMachineBasicBlock();
+ MF.push_back(EntryBB);
+ EntryBB->addSuccessor(&getOrCreateBB(F.front()));
+ EntryBuilder.setMBB(*EntryBB);
+
+ // Lower the actual args into this basic block.
SmallVector<unsigned, 8> VRegArgs;
for (const Argument &Arg: F.args())
VRegArgs.push_back(getOrCreateVReg(Arg));
- bool Succeeded = CLI->lowerFormalArguments(MIRBuilder, F, VRegArgs);
+ bool Succeeded = CLI->lowerFormalArguments(EntryBuilder, F, VRegArgs);
if (!Succeeded) {
if (!TPC->isGlobalISelAbortEnabled()) {
MIRBuilder.getMF().getProperties().set(
@@ -761,13 +766,7 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &MF) {
report_fatal_error("Unable to lower arguments");
}
- // Now that we've got the ABI handling code, it's safe to set a location for
- // any Constants we find in the IR.
- if (MBB.empty())
- EntryBuilder.setMBB(MBB, /* Beginning */ true);
- else
- EntryBuilder.setInstr(MBB.back(), /* Before */ false);
-
+ // And translate the function!
for (const BasicBlock &BB: F) {
MachineBasicBlock &MBB = getOrCreateBB(BB);
// Set the insertion point of all the following translations to
diff --git a/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp b/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
index d46dd9f6b8f..c04f6e4ae89 100644
--- a/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
@@ -27,34 +27,29 @@ void MachineIRBuilder::setMF(MachineFunction &MF) {
this->MRI = &MF.getRegInfo();
this->TII = MF.getSubtarget().getInstrInfo();
this->DL = DebugLoc();
- this->MI = nullptr;
+ this->II = MachineBasicBlock::iterator();
this->InsertedInstr = nullptr;
}
-void MachineIRBuilder::setMBB(MachineBasicBlock &MBB, bool Beginning) {
+void MachineIRBuilder::setMBB(MachineBasicBlock &MBB) {
this->MBB = &MBB;
- this->MI = nullptr;
- Before = Beginning;
+ this->II = MBB.end();
assert(&getMF() == MBB.getParent() &&
"Basic block is in a different function");
}
-void MachineIRBuilder::setInstr(MachineInstr &MI, bool Before) {
+void MachineIRBuilder::setInstr(MachineInstr &MI) {
assert(MI.getParent() && "Instruction is not part of a basic block");
setMBB(*MI.getParent());
- this->MI = &MI;
- this->Before = Before;
+ this->II = MI.getIterator();
}
-MachineBasicBlock::iterator MachineIRBuilder::getInsertPt() {
- if (MI) {
- if (Before)
- return MI;
- if (!MI->getNextNode())
- return getMBB().end();
- return MI->getNextNode();
- }
- return Before ? getMBB().begin() : getMBB().end();
+void MachineIRBuilder::setInsertPt(MachineBasicBlock &MBB,
+ MachineBasicBlock::iterator II) {
+ assert(MBB.getParent() == &getMF() &&
+ "Basic block is in a different function");
+ this->MBB = &MBB;
+ this->II = II;
}
void MachineIRBuilder::recordInsertions(
OpenPOWER on IntegriCloud