summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/MIRCanonicalizerPass.cpp
diff options
context:
space:
mode:
authorPuyan Lotfi <puyan@puyan.org>2018-04-16 09:03:03 +0000
committerPuyan Lotfi <puyan@puyan.org>2018-04-16 09:03:03 +0000
commit14b6637edc41125997bf395f1a3504e7288b0e93 (patch)
treeb9a4bff6f5335a446139d74f9dac4ee42b077e95 /llvm/lib/CodeGen/MIRCanonicalizerPass.cpp
parentfab368099010e07ca440c6b3f392686301347067 (diff)
downloadbcm5719-llvm-14b6637edc41125997bf395f1a3504e7288b0e93.tar.gz
bcm5719-llvm-14b6637edc41125997bf395f1a3504e7288b0e93.zip
[MIR-Canon] Adding ISA-Agnostic COPY Folding.
Transforms the following: %vreg1234:gpr32 = COPY %42 %vreg1235:gpr32 = COPY %vreg1234 %vreg1236:gpr32 = COPY %vreg1235 $w0 = COPY %vreg1236 into: $w0 = COPY %42 Assuming %42 is also a gpr32 llvm-svn: 330113
Diffstat (limited to 'llvm/lib/CodeGen/MIRCanonicalizerPass.cpp')
-rw-r--r--llvm/lib/CodeGen/MIRCanonicalizerPass.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/MIRCanonicalizerPass.cpp b/llvm/lib/CodeGen/MIRCanonicalizerPass.cpp
index 298b240b330..3f7e5cf052f 100644
--- a/llvm/lib/CodeGen/MIRCanonicalizerPass.cpp
+++ b/llvm/lib/CodeGen/MIRCanonicalizerPass.cpp
@@ -310,6 +310,45 @@ static bool rescheduleCanonically(unsigned &PseudoIdempotentInstCount,
return Changed;
}
+bool propagateLocalCopies(MachineBasicBlock *MBB) {
+ bool Changed = false;
+ MachineRegisterInfo &MRI = MBB->getParent()->getRegInfo();
+
+ std::vector<MachineInstr *> Copies;
+ for (MachineInstr &MI : MBB->instrs()) {
+ if (MI.isCopy())
+ Copies.push_back(&MI);
+ }
+
+ for (MachineInstr *MI : Copies) {
+
+ if (!MI->getOperand(0).isReg())
+ continue;
+ if (!MI->getOperand(1).isReg())
+ continue;
+
+ const unsigned Dst = MI->getOperand(0).getReg();
+ const unsigned Src = MI->getOperand(1).getReg();
+
+ if (!TargetRegisterInfo::isVirtualRegister(Dst))
+ continue;
+ if (!TargetRegisterInfo::isVirtualRegister(Src))
+ continue;
+ if (MRI.getRegClass(Dst) != MRI.getRegClass(Src))
+ continue;
+
+ for (auto UI = MRI.use_begin(Dst); UI != MRI.use_end(); ++UI) {
+ MachineOperand *MO = &*UI;
+ MO->setReg(Src);
+ Changed = true;
+ }
+
+ MI->eraseFromParent();
+ }
+
+ return Changed;
+}
+
/// Here we find our candidates. What makes an interesting candidate?
/// An candidate for a canonicalization tree root is normally any kind of
/// instruction that causes side effects such as a store to memory or a copy to
@@ -616,6 +655,10 @@ static bool runOnBasicBlock(MachineBasicBlock *MBB,
bbNames.push_back(MBB->getName());
DEBUG(dbgs() << "\n\n NEW BASIC BLOCK: " << MBB->getName() << "\n\n";);
+ DEBUG(dbgs() << "MBB Before Canonical Copy Propagation:\n"; MBB->dump(););
+ Changed |= propagateLocalCopies(MBB);
+ DEBUG(dbgs() << "MBB After Canonical Copy Propagation:\n"; MBB->dump(););
+
DEBUG(dbgs() << "MBB Before Scheduling:\n"; MBB->dump(););
unsigned IdempotentInstCount = 0;
Changed |= rescheduleCanonically(IdempotentInstCount, MBB);
OpenPOWER on IntegriCloud