diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2018-08-16 21:30:05 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2018-08-16 21:30:05 +0000 |
commit | c73c0307fe71a4f1a98d99dbc5d7852d44c30fff (patch) | |
tree | fd4bce21f4d2d9e151c95e321832cf4f36695ba6 /llvm/lib/Target/X86/X86InstrInfo.cpp | |
parent | 66cf14d06b1c5d20417e312fabd14ffaf4314ae3 (diff) | |
download | bcm5719-llvm-c73c0307fe71a4f1a98d99dbc5d7852d44c30fff.tar.gz bcm5719-llvm-c73c0307fe71a4f1a98d99dbc5d7852d44c30fff.zip |
[MI] Change the array of `MachineMemOperand` pointers to be
a generically extensible collection of extra info attached to
a `MachineInstr`.
The primary change here is cleaning up the APIs used for setting and
manipulating the `MachineMemOperand` pointer arrays so chat we can
change how they are allocated.
Then we introduce an extra info object that using the trailing object
pattern to attach some number of MMOs but also other extra info. The
design of this is specifically so that this extra info has a fixed
necessary cost (the header tracking what extra info is included) and
everything else can be tail allocated. This pattern works especially
well with a `BumpPtrAllocator` which we use here.
I've also added the basic scaffolding for putting interesting pointers
into this, namely pre- and post-instruction symbols. These aren't used
anywhere yet, they're just there to ensure I've actually gotten the data
structure types correct. I'll flesh out support for these in
a subsequent patch (MIR dumping, parsing, the works).
Finally, I've included an optimization where we store any single pointer
inline in the `MachineInstr` to avoid the allocation overhead. This is
expected to be the overwhelmingly most common case and so should avoid
any memory usage growth due to slightly less clever / dense allocation
when dealing with >1 MMO. This did require several ergonomic
improvements to the `PointerSumType` to reasonably support the various
usage models.
This also has a side effect of freeing up 8 bits within the
`MachineInstr` which could be repurposed for something else.
The suggested direction here came largely from Hal Finkel. I hope it was
worth it. ;] It does hopefully clear a path for subsequent extensions
w/o nearly as much leg work. Lots of thanks to Reid and Justin for
careful reviews and ideas about how to do all of this.
Differential Revision: https://reviews.llvm.org/D50701
llvm-svn: 339940
Diffstat (limited to 'llvm/lib/Target/X86/X86InstrInfo.cpp')
-rw-r--r-- | llvm/lib/Target/X86/X86InstrInfo.cpp | 43 |
1 files changed, 18 insertions, 25 deletions
diff --git a/llvm/lib/Target/X86/X86InstrInfo.cpp b/llvm/lib/Target/X86/X86InstrInfo.cpp index 4073f455a81..513011a1cf6 100644 --- a/llvm/lib/Target/X86/X86InstrInfo.cpp +++ b/llvm/lib/Target/X86/X86InstrInfo.cpp @@ -3308,24 +3308,21 @@ void X86InstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB, .addReg(SrcReg, getKillRegState(isKill)); } -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 { +void X86InstrInfo::storeRegToAddr( + MachineFunction &MF, unsigned SrcReg, bool isKill, + SmallVectorImpl<MachineOperand> &Addr, const TargetRegisterClass *RC, + ArrayRef<MachineMemOperand *> MMOs, + SmallVectorImpl<MachineInstr *> &NewMIs) const { const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo(); unsigned Alignment = std::max<uint32_t>(TRI.getSpillSize(*RC), 16); - bool isAligned = MMOBegin != MMOEnd && - (*MMOBegin)->getAlignment() >= Alignment; + bool isAligned = !MMOs.empty() && MMOs.front()->getAlignment() >= Alignment; unsigned Opc = getStoreRegOpcode(SrcReg, RC, isAligned, Subtarget); DebugLoc DL; MachineInstrBuilder MIB = BuildMI(MF, DL, get(Opc)); for (unsigned i = 0, e = Addr.size(); i != e; ++i) MIB.add(Addr[i]); MIB.addReg(SrcReg, getKillRegState(isKill)); - (*MIB).setMemRefs(MMOBegin, MMOEnd); + MIB.setMemRefs(MMOs); NewMIs.push_back(MIB); } @@ -3345,22 +3342,20 @@ void X86InstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB, addFrameReference(BuildMI(MBB, MI, DL, get(Opc), DestReg), FrameIdx); } -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 { +void X86InstrInfo::loadRegFromAddr( + MachineFunction &MF, unsigned DestReg, + SmallVectorImpl<MachineOperand> &Addr, const TargetRegisterClass *RC, + ArrayRef<MachineMemOperand *> MMOs, + SmallVectorImpl<MachineInstr *> &NewMIs) const { const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo(); unsigned Alignment = std::max<uint32_t>(TRI.getSpillSize(*RC), 16); - bool isAligned = MMOBegin != MMOEnd && - (*MMOBegin)->getAlignment() >= Alignment; + bool isAligned = !MMOs.empty() && MMOs.front()->getAlignment() >= Alignment; unsigned Opc = getLoadRegOpcode(DestReg, RC, isAligned, Subtarget); DebugLoc DL; MachineInstrBuilder MIB = BuildMI(MF, DL, get(Opc), DestReg); for (unsigned i = 0, e = Addr.size(); i != e; ++i) MIB.add(Addr[i]); - (*MIB).setMemRefs(MMOBegin, MMOEnd); + MIB.setMemRefs(MMOs); NewMIs.push_back(MIB); } @@ -5450,9 +5445,8 @@ bool X86InstrInfo::unfoldMemoryOperand( // Emit the load instruction. if (UnfoldLoad) { - 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); + auto MMOs = extractLoadMMOs(MI.memoperands(), MF); + loadRegFromAddr(MF, Reg, AddrOps, RC, MMOs, NewMIs); if (UnfoldStore) { // Address operands cannot be marked isKill. for (unsigned i = 1; i != 1 + X86::AddrNumOperands; ++i) { @@ -5517,9 +5511,8 @@ bool X86InstrInfo::unfoldMemoryOperand( // Emit the store instruction. if (UnfoldStore) { const TargetRegisterClass *DstRC = getRegClass(MCID, 0, &RI, MF); - 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); + auto MMOs = extractStoreMMOs(MI.memoperands(), MF); + storeRegToAddr(MF, Reg, true, AddrOps, DstRC, MMOs, NewMIs); } return true; |