[llvm-commits] [llvm] r56528 - in /llvm/trunk: include/llvm/CodeGen/MachineInstr.h lib/CodeGen/MachineInstr.cpp

Dan Gohman gohman at apple.com
Tue Sep 23 17:06:16 PDT 2008


Author: djg
Date: Tue Sep 23 19:06:15 2008
New Revision: 56528

URL: http://llvm.org/viewvc/llvm-project?rev=56528&view=rev
Log:
Add a method to MachineInstr for testing whether it makes
any volatile memory references.

Modified:
    llvm/trunk/include/llvm/CodeGen/MachineInstr.h
    llvm/trunk/lib/CodeGen/MachineInstr.cpp

Modified: llvm/trunk/include/llvm/CodeGen/MachineInstr.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineInstr.h?rev=56528&r1=56527&r2=56528&view=diff

==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineInstr.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineInstr.h Tue Sep 23 19:06:15 2008
@@ -250,8 +250,16 @@
   /// the instruction's location and its intended destination.
   bool isSafeToMove(const TargetInstrInfo *TII, bool &SawStore);
 
+  /// isSafeToReMat - Return true if it's safe to rematerialize the specified
+  /// instruction which defined the specified register instead of copying it.
   bool isSafeToReMat(const TargetInstrInfo *TII, unsigned DstReg);
 
+  /// hasVolatileMemoryRef - Return true if this instruction may have a
+  /// volatile memory reference, or if the information describing the
+  /// memory reference is not available. Return false if it is known to
+  /// have no volatile memory references.
+  bool hasVolatileMemoryRef() const;
+
   //
   // Debugging support
   //

Modified: llvm/trunk/lib/CodeGen/MachineInstr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineInstr.cpp?rev=56528&r1=56527&r2=56528&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/MachineInstr.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineInstr.cpp Tue Sep 23 19:06:15 2008
@@ -711,16 +711,11 @@
   // destination. The check for isInvariantLoad gives the targe the chance to
   // classify the load as always returning a constant, e.g. a constant pool
   // load.
-  if (TID->mayLoad() && !TII->isInvariantLoad(this)) {
+  if (TID->mayLoad() && !TII->isInvariantLoad(this))
     // Otherwise, this is a real load.  If there is a store between the load and
-    // end of block, we can't sink the load.
-    //
-    // FIXME: we can't do this transformation until we know that the load is
-    // not volatile, and machineinstrs don't keep this info. :(
-    //
-    //if (SawStore) 
-    return false;
-  }
+    // end of block, or if the laod is volatile, we can't move it.
+    return SawStore || hasVolatileMemoryRef();
+
   return true;
 }
 
@@ -749,6 +744,32 @@
   return true;
 }
 
+/// hasVolatileMemoryRef - Return true if this instruction may have a
+/// volatile memory reference, or if the information describing the
+/// memory reference is not available. Return false if it is known to
+/// have no volatile memory references.
+bool MachineInstr::hasVolatileMemoryRef() const {
+  // An instruction known never to access memory won't have a volatile access.
+  if (!TID->mayStore() &&
+      !TID->mayLoad() &&
+      !TID->isCall() &&
+      !TID->hasUnmodeledSideEffects())
+    return false;
+
+  // Otherwise, if the instruction has no memory reference information,
+  // conservatively assume it wasn't preserved.
+  if (memoperands_empty())
+    return true;
+  
+  // Check the memory reference information for volatile references.
+  for (std::list<MachineMemOperand>::const_iterator I = memoperands_begin(),
+       E = memoperands_end(); I != E; ++I)
+    if (I->isVolatile())
+      return true;
+
+  return false;
+}
+
 void MachineInstr::dump() const {
   cerr << "  " << *this;
 }





More information about the llvm-commits mailing list