summaryrefslogtreecommitdiff
path: root/lib/CodeGen/LiveRangeEdit.cpp
diff options
context:
space:
mode:
authorJakob Stoklund Olesen <stoklund@2pi.dk>2010-10-20 22:00:51 +0000
committerJakob Stoklund Olesen <stoklund@2pi.dk>2010-10-20 22:00:51 +0000
commit080c316ff8a066cd164d9a8f92df509d8cb63110 (patch)
tree43038728caaaec40cd0a1868e5b8d287b304d4f9 /lib/CodeGen/LiveRangeEdit.cpp
parente93d99cf0742eebab859022e4cfdcf03cb9d5dfa (diff)
downloadllvm-080c316ff8a066cd164d9a8f92df509d8cb63110.tar.gz
llvm-080c316ff8a066cd164d9a8f92df509d8cb63110.tar.bz2
llvm-080c316ff8a066cd164d9a8f92df509d8cb63110.tar.xz
Move some of the InlineSpiller rematerialization code into LiveRangeEdit.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@116951 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/LiveRangeEdit.cpp')
-rw-r--r--lib/CodeGen/LiveRangeEdit.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/lib/CodeGen/LiveRangeEdit.cpp b/lib/CodeGen/LiveRangeEdit.cpp
index 463ebcb4ae..cc9c3a3c2f 100644
--- a/lib/CodeGen/LiveRangeEdit.cpp
+++ b/lib/CodeGen/LiveRangeEdit.cpp
@@ -15,6 +15,7 @@
#include "VirtRegMap.h"
#include "llvm/CodeGen/LiveIntervalAnalysis.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
+#include "llvm/Target/TargetInstrInfo.h"
using namespace llvm;
@@ -38,6 +39,31 @@ LiveInterval &LiveRangeEdit::create(MachineRegisterInfo &mri,
return li;
}
+void LiveRangeEdit::scanRemattable(LiveIntervals &lis,
+ const TargetInstrInfo &tii,
+ AliasAnalysis *aa) {
+ for (LiveInterval::vni_iterator I = parent_.vni_begin(),
+ E = parent_.vni_end(); I != E; ++I) {
+ VNInfo *VNI = *I;
+ if (VNI->isUnused())
+ continue;
+ MachineInstr *DefMI = lis.getInstructionFromIndex(VNI->def);
+ if (!DefMI)
+ continue;
+ if (tii.isTriviallyReMaterializable(DefMI, aa))
+ remattable_.insert(VNI);
+ }
+ scannedRemattable_ = true;
+}
+
+bool LiveRangeEdit::anyRematerializable(LiveIntervals &lis,
+ const TargetInstrInfo &tii,
+ AliasAnalysis *aa) {
+ if (!scannedRemattable_)
+ scanRemattable(lis, tii, aa);
+ return !remattable_.empty();
+}
+
/// allUsesAvailableAt - Return true if all registers used by OrigMI at
/// OrigIdx are also available with the same value at UseIdx.
bool LiveRangeEdit::allUsesAvailableAt(const MachineInstr *OrigMI,
@@ -71,3 +97,47 @@ bool LiveRangeEdit::allUsesAvailableAt(const MachineInstr *OrigMI,
return true;
}
+LiveRangeEdit::Remat LiveRangeEdit::canRematerializeAt(VNInfo *ParentVNI,
+ SlotIndex UseIdx,
+ bool cheapAsAMove,
+ LiveIntervals &lis) {
+ assert(scannedRemattable_ && "Call anyRematerializable first");
+ Remat RM = { 0, 0 };
+
+ // We could remat an undefined value as IMPLICIT_DEF, but all that should have
+ // been taken care of earlier.
+ if (!(RM.ParentVNI = parent_.getVNInfoAt(UseIdx)))
+ return RM;
+
+ // Use scanRemattable info.
+ if (!remattable_.count(RM.ParentVNI))
+ return RM;
+
+ // No defining instruction.
+ MachineInstr *OrigMI = lis.getInstructionFromIndex(RM.ParentVNI->def);
+ assert(OrigMI && "Defining instruction for remattable value disappeared");
+
+ // If only cheap remats were requested, bail out early.
+ if (cheapAsAMove && !OrigMI->getDesc().isAsCheapAsAMove())
+ return RM;
+
+ // Verify that all used registers are available with the same values.
+ if (!allUsesAvailableAt(OrigMI, RM.ParentVNI->def, UseIdx, lis))
+ return RM;
+
+ RM.OrigMI = OrigMI;
+ return RM;
+}
+
+SlotIndex LiveRangeEdit::rematerializeAt(MachineBasicBlock &MBB,
+ MachineBasicBlock::iterator MI,
+ unsigned DestReg,
+ const Remat &RM,
+ LiveIntervals &lis,
+ const TargetInstrInfo &tii,
+ const TargetRegisterInfo &tri) {
+ assert(RM.OrigMI && "Invalid remat");
+ tii.reMaterialize(MBB, MI, DestReg, 0, RM.OrigMI, tri);
+ return lis.InsertMachineInstrInMaps(--MI).getDefIndex();
+}
+