mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-11-02 07:11:49 +00:00
Add basic infrastructure and x86 support for preserving MachineMemOperand
information when unfolding memory references. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@83656 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
c525472828
commit
91e69c3715
@ -329,7 +329,7 @@ public:
|
||||
unsigned base_alignment);
|
||||
|
||||
/// getMachineMemOperand - Allocate a new MachineMemOperand by copying
|
||||
/// an existing one, adjusting by an offset and using the given EVT.
|
||||
/// an existing one, adjusting by an offset and using the given size.
|
||||
/// MachineMemOperands are owned by the MachineFunction and need not be
|
||||
/// explicitly deallocated.
|
||||
MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO,
|
||||
@ -339,6 +339,20 @@ public:
|
||||
/// pointers. This array is owned by the MachineFunction.
|
||||
MachineInstr::mmo_iterator allocateMemRefsArray(unsigned long Num);
|
||||
|
||||
/// extractLoadMemRefs - Allocate an array and populate it with just the
|
||||
/// load information from the given MachineMemOperand sequence.
|
||||
std::pair<MachineInstr::mmo_iterator,
|
||||
MachineInstr::mmo_iterator>
|
||||
extractLoadMemRefs(MachineInstr::mmo_iterator Begin,
|
||||
MachineInstr::mmo_iterator End);
|
||||
|
||||
/// extractStoreMemRefs - Allocate an array and populate it with just the
|
||||
/// store information from the given MachineMemOperand sequence.
|
||||
std::pair<MachineInstr::mmo_iterator,
|
||||
MachineInstr::mmo_iterator>
|
||||
extractStoreMemRefs(MachineInstr::mmo_iterator Begin,
|
||||
MachineInstr::mmo_iterator End);
|
||||
|
||||
//===--------------------------------------------------------------------===//
|
||||
// Debug location.
|
||||
//
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -1886,6 +1886,8 @@ void X86InstrInfo::storeRegToAddr(MachineFunction &MF, unsigned SrcReg,
|
||||
bool isKill,
|
||||
SmallVectorImpl<MachineOperand> &Addr,
|
||||
const TargetRegisterClass *RC,
|
||||
MachineInstr::mmo_iterator MMOBegin,
|
||||
MachineInstr::mmo_iterator MMOEnd,
|
||||
SmallVectorImpl<MachineInstr*> &NewMIs) const {
|
||||
bool isAligned = (RI.getStackAlignment() >= 16) ||
|
||||
RI.needsStackRealignment(MF);
|
||||
@ -1895,6 +1897,7 @@ void X86InstrInfo::storeRegToAddr(MachineFunction &MF, unsigned SrcReg,
|
||||
for (unsigned i = 0, e = Addr.size(); i != e; ++i)
|
||||
MIB.addOperand(Addr[i]);
|
||||
MIB.addReg(SrcReg, getKillRegState(isKill));
|
||||
(*MIB).setMemRefs(MMOBegin, MMOEnd);
|
||||
NewMIs.push_back(MIB);
|
||||
}
|
||||
|
||||
@ -1977,6 +1980,8 @@ void X86InstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
|
||||
void X86InstrInfo::loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
|
||||
SmallVectorImpl<MachineOperand> &Addr,
|
||||
const TargetRegisterClass *RC,
|
||||
MachineInstr::mmo_iterator MMOBegin,
|
||||
MachineInstr::mmo_iterator MMOEnd,
|
||||
SmallVectorImpl<MachineInstr*> &NewMIs) const {
|
||||
bool isAligned = (RI.getStackAlignment() >= 16) ||
|
||||
RI.needsStackRealignment(MF);
|
||||
@ -1985,6 +1990,7 @@ void X86InstrInfo::loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
|
||||
MachineInstrBuilder MIB = BuildMI(MF, DL, get(Opc), DestReg);
|
||||
for (unsigned i = 0, e = Addr.size(); i != e; ++i)
|
||||
MIB.addOperand(Addr[i]);
|
||||
(*MIB).setMemRefs(MMOBegin, MMOEnd);
|
||||
NewMIs.push_back(MIB);
|
||||
}
|
||||
|
||||
@ -2442,7 +2448,11 @@ bool X86InstrInfo::unfoldMemoryOperand(MachineFunction &MF, MachineInstr *MI,
|
||||
|
||||
// Emit the load instruction.
|
||||
if (UnfoldLoad) {
|
||||
loadRegFromAddr(MF, Reg, AddrOps, RC, NewMIs);
|
||||
std::pair<MachineInstr::mmo_iterator,
|
||||
MachineInstr::mmo_iterator> MMOs =
|
||||
MF.extractLoadMemRefs(MI->memoperands_begin(),
|
||||
MI->memoperands_end());
|
||||
loadRegFromAddr(MF, Reg, AddrOps, RC, MMOs.first, MMOs.second, NewMIs);
|
||||
if (UnfoldStore) {
|
||||
// Address operands cannot be marked isKill.
|
||||
for (unsigned i = 1; i != 1 + X86AddrNumOperands; ++i) {
|
||||
@ -2502,7 +2512,11 @@ bool X86InstrInfo::unfoldMemoryOperand(MachineFunction &MF, MachineInstr *MI,
|
||||
// Emit the store instruction.
|
||||
if (UnfoldStore) {
|
||||
const TargetRegisterClass *DstRC = TID.OpInfo[0].getRegClass(&RI);
|
||||
storeRegToAddr(MF, Reg, true, AddrOps, DstRC, NewMIs);
|
||||
std::pair<MachineInstr::mmo_iterator,
|
||||
MachineInstr::mmo_iterator> MMOs =
|
||||
MF.extractStoreMemRefs(MI->memoperands_begin(),
|
||||
MI->memoperands_end());
|
||||
storeRegToAddr(MF, Reg, true, AddrOps, DstRC, MMOs.first, MMOs.second, NewMIs);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -2544,7 +2558,7 @@ X86InstrInfo::unfoldMemoryOperand(SelectionDAG &DAG, SDNode *N,
|
||||
|
||||
// Emit the load instruction.
|
||||
SDNode *Load = 0;
|
||||
const MachineFunction &MF = DAG.getMachineFunction();
|
||||
MachineFunction &MF = DAG.getMachineFunction();
|
||||
if (FoldedLoad) {
|
||||
EVT VT = *RC->vt_begin();
|
||||
bool isAligned = (RI.getStackAlignment() >= 16) ||
|
||||
@ -2552,6 +2566,13 @@ X86InstrInfo::unfoldMemoryOperand(SelectionDAG &DAG, SDNode *N,
|
||||
Load = DAG.getMachineNode(getLoadRegOpcode(0, RC, isAligned, TM), dl,
|
||||
VT, MVT::Other, &AddrOps[0], AddrOps.size());
|
||||
NewNodes.push_back(Load);
|
||||
|
||||
// Preserve memory reference information.
|
||||
std::pair<MachineInstr::mmo_iterator,
|
||||
MachineInstr::mmo_iterator> MMOs =
|
||||
MF.extractLoadMemRefs(cast<MachineSDNode>(N)->memoperands_begin(),
|
||||
cast<MachineSDNode>(N)->memoperands_end());
|
||||
cast<MachineSDNode>(Load)->setMemRefs(MMOs.first, MMOs.second);
|
||||
}
|
||||
|
||||
// Emit the data processing instruction.
|
||||
@ -2585,6 +2606,13 @@ X86InstrInfo::unfoldMemoryOperand(SelectionDAG &DAG, SDNode *N,
|
||||
dl, MVT::Other,
|
||||
&AddrOps[0], AddrOps.size());
|
||||
NewNodes.push_back(Store);
|
||||
|
||||
// Preserve memory reference information.
|
||||
std::pair<MachineInstr::mmo_iterator,
|
||||
MachineInstr::mmo_iterator> MMOs =
|
||||
MF.extractStoreMemRefs(cast<MachineSDNode>(N)->memoperands_begin(),
|
||||
cast<MachineSDNode>(N)->memoperands_end());
|
||||
cast<MachineSDNode>(Load)->setMemRefs(MMOs.first, MMOs.second);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -498,6 +498,8 @@ public:
|
||||
virtual void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill,
|
||||
SmallVectorImpl<MachineOperand> &Addr,
|
||||
const TargetRegisterClass *RC,
|
||||
MachineInstr::mmo_iterator MMOBegin,
|
||||
MachineInstr::mmo_iterator MMOEnd,
|
||||
SmallVectorImpl<MachineInstr*> &NewMIs) const;
|
||||
|
||||
virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
|
||||
@ -508,6 +510,8 @@ public:
|
||||
virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
|
||||
SmallVectorImpl<MachineOperand> &Addr,
|
||||
const TargetRegisterClass *RC,
|
||||
MachineInstr::mmo_iterator MMOBegin,
|
||||
MachineInstr::mmo_iterator MMOEnd,
|
||||
SmallVectorImpl<MachineInstr*> &NewMIs) const;
|
||||
|
||||
virtual bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
|
||||
|
Loading…
Reference in New Issue
Block a user