Another predicate routine
authorAnton Korobeynikov <asl@math.spbu.ru>
Thu, 16 Jul 2009 14:33:01 +0000 (14:33 +0000)
committerAnton Korobeynikov <asl@math.spbu.ru>
Thu, 16 Jul 2009 14:33:01 +0000 (14:33 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76057 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/SystemZ/SystemZInstrInfo.cpp
lib/Target/SystemZ/SystemZInstrInfo.h

index 46db94e4c319e2af15ec1501f090103945ad9f44..914d333c34caf5a4b2cb051858e8b573c3ce2c36 100644 (file)
@@ -52,6 +52,12 @@ SystemZInstrInfo::SystemZInstrInfo(SystemZTargetMachine &tm)
     RegSpillOffsets[SpillOffsTab[i][0]] = SpillOffsTab[i][1];
 }
 
+/// isGVStub - Return true if the GV requires an extra load to get the
+/// real address.
+static inline bool isGVStub(GlobalValue *GV, SystemZTargetMachine &TM) {
+  return TM.getSubtarget<SystemZSubtarget>().GVRequiresExtraLoad(GV, TM, false);
+}
+
 void SystemZInstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
                                           MachineBasicBlock::iterator MI,
                                     unsigned SrcReg, bool isKill, int FrameIdx,
@@ -246,6 +252,30 @@ unsigned SystemZInstrInfo::isStoreToStackSlot(const MachineInstr *MI,
   return 0;
 }
 
+bool SystemZInstrInfo::isInvariantLoad(const MachineInstr *MI) const {
+  for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
+    const MachineOperand &MO = MI->getOperand(i);
+    // Loads from constant pools are trivially invariant.
+    if (MO.isCPI())
+      return true;
+
+    if (MO.isGlobal())
+      return isGVStub(MO.getGlobal(), TM);
+
+    // If this is a load from an invariant stack slot, the load is a constant.
+    if (MO.isFI()) {
+      const MachineFrameInfo &MFI =
+        *MI->getParent()->getParent()->getFrameInfo();
+      int Idx = MO.getIndex();
+      return MFI.isFixedObjectIndex(Idx) && MFI.isImmutableObjectIndex(Idx);
+    }
+  }
+
+  // All other instances of these instructions are presumed to have other
+  // issues.
+  return false;
+}
+
 bool
 SystemZInstrInfo::spillCalleeSavedRegisters(MachineBasicBlock &MBB,
                                            MachineBasicBlock::iterator MI,
index 2bcdb2e55c41a3107b5658eebff1b32eaacb1392..0ef3ca93beacf2945cc894025413692e850edacf 100644 (file)
@@ -70,6 +70,7 @@ public:
                    unsigned &SrcSubIdx, unsigned &DstSubIdx) const;
   unsigned isLoadFromStackSlot(const MachineInstr *MI, int &FrameIndex) const;
   unsigned isStoreToStackSlot(const MachineInstr *MI, int &FrameIndex) const;
+  bool isInvariantLoad(const MachineInstr *MI) const;
 
   virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
                                    MachineBasicBlock::iterator MI,