aboutsummaryrefslogtreecommitdiffstats
path: root/lib/CodeGen/MachineInstr.cpp
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2008-08-27 20:33:50 +0000
committerEvan Cheng <evan.cheng@apple.com>2008-08-27 20:33:50 +0000
commit75e2ceec552574757669f41dfbe605a6c0a58097 (patch)
treedf0e7bf0eaeb013305db97d31b7967733baff9e9 /lib/CodeGen/MachineInstr.cpp
parent13610c39931648492be21adc3c64cc2f9fdbe359 (diff)
downloadexternal_llvm-75e2ceec552574757669f41dfbe605a6c0a58097.zip
external_llvm-75e2ceec552574757669f41dfbe605a6c0a58097.tar.gz
external_llvm-75e2ceec552574757669f41dfbe605a6c0a58097.tar.bz2
Refactor isSafeToReMat out of 2addr pass.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55430 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/MachineInstr.cpp')
-rw-r--r--lib/CodeGen/MachineInstr.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/CodeGen/MachineInstr.cpp b/lib/CodeGen/MachineInstr.cpp
index 27e3f66..966d172 100644
--- a/lib/CodeGen/MachineInstr.cpp
+++ b/lib/CodeGen/MachineInstr.cpp
@@ -711,6 +711,31 @@ bool MachineInstr::isSafeToMove(const TargetInstrInfo *TII, bool &SawStore) {
return true;
}
+/// isSafeToReMat - Return true if it's safe to rematerialize the specified
+/// instruction which defined the specified register instead of copying it.
+bool MachineInstr::isSafeToReMat(const TargetInstrInfo *TII, unsigned DstReg) {
+ if (!TID->isAsCheapAsAMove())
+ return false;
+ bool SawStore = false;
+ if (!isSafeToMove(TII, SawStore))
+ return false;
+ for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
+ MachineOperand &MO = getOperand(i);
+ if (!MO.isRegister())
+ continue;
+ // FIXME: For now, do not remat any instruction with register operands.
+ // Later on, we can loosen the restriction is the register operands have
+ // not been modified between the def and use. Note, this is different from
+ // MachineSink because the code in no longer in two-address form (at least
+ // partially).
+ if (MO.isUse())
+ return false;
+ else if (!MO.isDead() && MO.getReg() != DstReg)
+ return false;
+ }
+ return true;
+}
+
void MachineInstr::dump() const {
cerr << " " << *this;
}