Add basic infrastructure and x86 support for preserving MachineMemOperand
information when unfolding memory references. llvm-svn: 83656
This commit is contained in:
@@ -235,6 +235,70 @@ MachineFunction::allocateMemRefsArray(unsigned long Num) {
|
||||
return Allocator.Allocate<MachineMemOperand *>(Num);
|
||||
}
|
||||
|
||||
std::pair<MachineInstr::mmo_iterator, MachineInstr::mmo_iterator>
|
||||
MachineFunction::extractLoadMemRefs(MachineInstr::mmo_iterator Begin,
|
||||
MachineInstr::mmo_iterator End) {
|
||||
// Count the number of load mem refs.
|
||||
unsigned Num = 0;
|
||||
for (MachineInstr::mmo_iterator I = Begin; I != End; ++I)
|
||||
if ((*I)->isLoad())
|
||||
++Num;
|
||||
|
||||
// Allocate a new array and populate it with the load information.
|
||||
MachineInstr::mmo_iterator Result = allocateMemRefsArray(Num);
|
||||
unsigned Index = 0;
|
||||
for (MachineInstr::mmo_iterator I = Begin; I != End; ++I) {
|
||||
if ((*I)->isLoad()) {
|
||||
if (!(*I)->isStore())
|
||||
// Reuse the MMO.
|
||||
Result[Index] = *I;
|
||||
else {
|
||||
// Clone the MMO and unset the store flag.
|
||||
MachineMemOperand *JustLoad =
|
||||
getMachineMemOperand((*I)->getValue(),
|
||||
(*I)->getFlags() & ~MachineMemOperand::MOStore,
|
||||
(*I)->getOffset(), (*I)->getSize(),
|
||||
(*I)->getBaseAlignment());
|
||||
Result[Index] = JustLoad;
|
||||
}
|
||||
++Index;
|
||||
}
|
||||
}
|
||||
return std::make_pair(Result, Result + Num);
|
||||
}
|
||||
|
||||
std::pair<MachineInstr::mmo_iterator, MachineInstr::mmo_iterator>
|
||||
MachineFunction::extractStoreMemRefs(MachineInstr::mmo_iterator Begin,
|
||||
MachineInstr::mmo_iterator End) {
|
||||
// Count the number of load mem refs.
|
||||
unsigned Num = 0;
|
||||
for (MachineInstr::mmo_iterator I = Begin; I != End; ++I)
|
||||
if ((*I)->isStore())
|
||||
++Num;
|
||||
|
||||
// Allocate a new array and populate it with the store information.
|
||||
MachineInstr::mmo_iterator Result = allocateMemRefsArray(Num);
|
||||
unsigned Index = 0;
|
||||
for (MachineInstr::mmo_iterator I = Begin; I != End; ++I) {
|
||||
if ((*I)->isStore()) {
|
||||
if (!(*I)->isLoad())
|
||||
// Reuse the MMO.
|
||||
Result[Index] = *I;
|
||||
else {
|
||||
// Clone the MMO and unset the load flag.
|
||||
MachineMemOperand *JustStore =
|
||||
getMachineMemOperand((*I)->getValue(),
|
||||
(*I)->getFlags() & ~MachineMemOperand::MOLoad,
|
||||
(*I)->getOffset(), (*I)->getSize(),
|
||||
(*I)->getBaseAlignment());
|
||||
Result[Index] = JustStore;
|
||||
}
|
||||
++Index;
|
||||
}
|
||||
}
|
||||
return std::make_pair(Result, Result + Num);
|
||||
}
|
||||
|
||||
void MachineFunction::dump() const {
|
||||
print(errs());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user