aboutsummaryrefslogtreecommitdiffstats
path: root/lib/CodeGen/MachineInstr.cpp
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2008-09-24 00:06:15 +0000
committerDan Gohman <gohman@apple.com>2008-09-24 00:06:15 +0000
commit9ffbed86220058f577345dc2de09d3be12cbb96c (patch)
treed572e85f18edc9d97f5b8cbaa5d6395fdd31801d /lib/CodeGen/MachineInstr.cpp
parentdc1611f62dc62d4c9cf5d906ed314e6e2c00969a (diff)
downloadexternal_llvm-9ffbed86220058f577345dc2de09d3be12cbb96c.zip
external_llvm-9ffbed86220058f577345dc2de09d3be12cbb96c.tar.gz
external_llvm-9ffbed86220058f577345dc2de09d3be12cbb96c.tar.bz2
Add a method to MachineInstr for testing whether it makes
any volatile memory references. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56528 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/MachineInstr.cpp')
-rw-r--r--lib/CodeGen/MachineInstr.cpp39
1 files changed, 30 insertions, 9 deletions
diff --git a/lib/CodeGen/MachineInstr.cpp b/lib/CodeGen/MachineInstr.cpp
index a365f20..7d44d4e 100644
--- a/lib/CodeGen/MachineInstr.cpp
+++ b/lib/CodeGen/MachineInstr.cpp
@@ -711,16 +711,11 @@ bool MachineInstr::isSafeToMove(const TargetInstrInfo *TII, bool &SawStore) {
// 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 @@ bool MachineInstr::isSafeToReMat(const TargetInstrInfo *TII, unsigned DstReg) {
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;
}