summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen
diff options
context:
space:
mode:
authorTim Northover <tnorthover@apple.com>2016-08-25 17:37:32 +0000
committerTim Northover <tnorthover@apple.com>2016-08-25 17:37:32 +0000
commit438c77ca1adf6ea29d25f5c53336dacff5ac5a21 (patch)
tree57bf2922a37cd74ee96e67eb31b9081ff3a7fe61 /llvm/lib/CodeGen
parent2c4a838e241fa078b24811d81bfe87513d40d903 (diff)
downloadbcm5719-llvm-438c77ca1adf6ea29d25f5c53336dacff5ac5a21.tar.gz
bcm5719-llvm-438c77ca1adf6ea29d25f5c53336dacff5ac5a21.zip
GlobalISel: perform multi-step legalization
llvm-svn: 279758
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r--llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp14
-rw-r--r--llvm/lib/CodeGen/GlobalISel/MachineLegalizeHelper.cpp29
2 files changed, 41 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp b/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
index 2cb7e6696e5..50896abbb0e 100644
--- a/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
@@ -26,6 +26,7 @@ void MachineIRBuilder::setMF(MachineFunction &MF) {
this->TII = MF.getSubtarget().getInstrInfo();
this->DL = DebugLoc();
this->MI = nullptr;
+ this->InsertedInstr = nullptr;
}
void MachineIRBuilder::setMBB(MachineBasicBlock &MBB, bool Beginning) {
@@ -53,6 +54,15 @@ MachineBasicBlock::iterator MachineIRBuilder::getInsertPt() {
return Before ? getMBB().begin() : getMBB().end();
}
+void MachineIRBuilder::recordInsertions(
+ std::function<void(MachineInstr *)> Inserted) {
+ InsertedInstr = Inserted;
+}
+
+void MachineIRBuilder::stopRecordingInsertions() {
+ InsertedInstr = nullptr;
+}
+
//------------------------------------------------------------------------------
// Build instruction variants.
//------------------------------------------------------------------------------
@@ -69,6 +79,8 @@ MachineInstrBuilder MachineIRBuilder::buildInstr(unsigned Opcode,
assert(!isPreISelGenericOpcode(Opcode) &&
"Generic instruction must have a type");
getMBB().insert(getInsertPt(), MIB);
+ if (InsertedInstr)
+ InsertedInstr(MIB);
return MIB;
}
@@ -181,6 +193,8 @@ MachineInstrBuilder MachineIRBuilder::buildExtract(ArrayRef<LLT> ResTys,
MIB.addImm(Idx);
getMBB().insert(getInsertPt(), MIB);
+ if (InsertedInstr)
+ InsertedInstr(MIB);
return MIB;
}
diff --git a/llvm/lib/CodeGen/GlobalISel/MachineLegalizeHelper.cpp b/llvm/lib/CodeGen/GlobalISel/MachineLegalizeHelper.cpp
index c7d30cf1f82..66b71668820 100644
--- a/llvm/lib/CodeGen/GlobalISel/MachineLegalizeHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/MachineLegalizeHelper.cpp
@@ -31,8 +31,9 @@ MachineLegalizeHelper::MachineLegalizeHelper(MachineFunction &MF)
MIRBuilder.setMF(MF);
}
-MachineLegalizeHelper::LegalizeResult MachineLegalizeHelper::legalizeInstr(
- MachineInstr &MI, const MachineLegalizer &Legalizer) {
+MachineLegalizeHelper::LegalizeResult
+MachineLegalizeHelper::legalizeInstrStep(MachineInstr &MI,
+ const MachineLegalizer &Legalizer) {
auto Action = Legalizer.getAction(MI);
switch (std::get<0>(Action)) {
case MachineLegalizer::Legal:
@@ -48,6 +49,30 @@ MachineLegalizeHelper::LegalizeResult MachineLegalizeHelper::legalizeInstr(
}
}
+MachineLegalizeHelper::LegalizeResult
+MachineLegalizeHelper::legalizeInstr(MachineInstr &MI,
+ const MachineLegalizer &Legalizer) {
+ std::queue<MachineInstr *> WorkList;
+ MIRBuilder.recordInsertions([&](MachineInstr *MI) { WorkList.push(MI); });
+ WorkList.push(&MI);
+
+ bool Changed = false;
+ LegalizeResult Res;
+ do {
+ Res = legalizeInstrStep(*WorkList.front(), Legalizer);
+ if (Res == UnableToLegalize) {
+ MIRBuilder.stopRecordingInsertions();
+ return UnableToLegalize;
+ }
+ Changed |= Res == Legalized;
+ WorkList.pop();
+ } while (!WorkList.empty());
+
+ MIRBuilder.stopRecordingInsertions();
+
+ return Changed ? Legalized : AlreadyLegal;
+}
+
void MachineLegalizeHelper::extractParts(unsigned Reg, LLT Ty, int NumParts,
SmallVectorImpl<unsigned> &VRegs) {
unsigned Size = Ty.getSizeInBits();
OpenPOWER on IntegriCloud