diff options
author | Igor Breger <igor.breger@intel.com> | 2017-03-28 09:35:06 +0000 |
---|---|---|
committer | Igor Breger <igor.breger@intel.com> | 2017-03-28 09:35:06 +0000 |
commit | f580fce2c34461433e404b5dacad87a483d1164e (patch) | |
tree | 5c533c1f5f9e146363ca5289e657ce8be4ae3cb9 /llvm/lib/Target | |
parent | 923e574bff006ea6a6888e1900ecc4d4a2a4ef41 (diff) | |
download | bcm5719-llvm-f580fce2c34461433e404b5dacad87a483d1164e.tar.gz bcm5719-llvm-f580fce2c34461433e404b5dacad87a483d1164e.zip |
[GlobalISel][X86] support G_FRAME_INDEX instruction selection.
Summary:
G_LOAD/G_STORE, add alternative RegisterBank mapping.
For G_LOAD, Fast and Greedy mode choose the same RegisterBank mapping (GprRegBank ) for the G_GLOAD + G_FADD , can't get rid of cross register bank copy GprRegBank->VecRegBank.
Reviewers: zvi, rovka, qcolombet, ab
Reviewed By: zvi
Subscribers: llvm-commits, dberris, kristof.beyls, eladcohen, guyblank
Differential Revision: https://reviews.llvm.org/D30979
llvm-svn: 298907
Diffstat (limited to 'llvm/lib/Target')
-rw-r--r-- | llvm/lib/Target/X86/X86RegisterBankInfo.cpp | 104 | ||||
-rw-r--r-- | llvm/lib/Target/X86/X86RegisterBankInfo.h | 20 |
2 files changed, 102 insertions, 22 deletions
diff --git a/llvm/lib/Target/X86/X86RegisterBankInfo.cpp b/llvm/lib/Target/X86/X86RegisterBankInfo.cpp index ad9e5f6bef9..d395c826e6b 100644 --- a/llvm/lib/Target/X86/X86RegisterBankInfo.cpp +++ b/llvm/lib/Target/X86/X86RegisterBankInfo.cpp @@ -105,6 +105,39 @@ X86GenRegisterBankInfo::getPartialMappingIdx(const LLT &Ty, bool isFP) { return PMI_None; } +void X86RegisterBankInfo::getInstrPartialMappingIdxs( + const MachineInstr &MI, const MachineRegisterInfo &MRI, const bool isFP, + SmallVectorImpl<PartialMappingIdx> &OpRegBankIdx) { + + unsigned NumOperands = MI.getNumOperands(); + for (unsigned Idx = 0; Idx < NumOperands; ++Idx) { + auto &MO = MI.getOperand(Idx); + if (!MO.isReg()) + OpRegBankIdx[Idx] = PMI_None; + else + OpRegBankIdx[Idx] = getPartialMappingIdx(MRI.getType(MO.getReg()), isFP); + } +} + +bool X86RegisterBankInfo::getInstrValueMapping( + const MachineInstr &MI, + const SmallVectorImpl<PartialMappingIdx> &OpRegBankIdx, + SmallVectorImpl<const ValueMapping *> &OpdsMapping) { + + unsigned NumOperands = MI.getNumOperands(); + for (unsigned Idx = 0; Idx < NumOperands; ++Idx) { + if (!MI.getOperand(Idx).isReg()) + continue; + + auto Mapping = getValueMapping(OpRegBankIdx[Idx], 1); + if (!Mapping->isValid()) + return false; + + OpdsMapping[Idx] = Mapping; + } + return true; +} + RegisterBankInfo::InstructionMapping X86RegisterBankInfo::getSameOperandsMapping(const MachineInstr &MI, bool isFP) { const MachineFunction &MF = *MI.getParent()->getParent(); @@ -151,33 +184,60 @@ X86RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const { } unsigned NumOperands = MI.getNumOperands(); - unsigned Cost = 1; // set dafault cost - // Track the bank of each register. + // Track the bank of each register, use NotFP mapping (all scalars in GPRs) SmallVector<PartialMappingIdx, 4> OpRegBankIdx(NumOperands); - for (unsigned Idx = 0; Idx < NumOperands; ++Idx) { - auto &MO = MI.getOperand(Idx); - if (!MO.isReg()) - continue; - - // As a top-level guess, use NotFP mapping (all scalars in GPRs) - OpRegBankIdx[Idx] = getPartialMappingIdx(MRI.getType(MO.getReg()), false); - } + getInstrPartialMappingIdxs(MI, MRI, /* isFP */ false, OpRegBankIdx); // Finally construct the computed mapping. - RegisterBankInfo::InstructionMapping Mapping = - InstructionMapping{DefaultMappingID, Cost, nullptr, NumOperands}; SmallVector<const ValueMapping *, 8> OpdsMapping(NumOperands); - for (unsigned Idx = 0; Idx < NumOperands; ++Idx) { - if (MI.getOperand(Idx).isReg()) { - auto Mapping = getValueMapping(OpRegBankIdx[Idx], 1); - if (!Mapping->isValid()) - return InstructionMapping(); + if (!getInstrValueMapping(MI, OpRegBankIdx, OpdsMapping)) + return InstructionMapping(); - OpdsMapping[Idx] = Mapping; - } - } + return InstructionMapping{DefaultMappingID, /* Cost */ 1, + getOperandsMapping(OpdsMapping), NumOperands}; +} + +void X86RegisterBankInfo::applyMappingImpl( + const OperandsMapper &OpdMapper) const { + return applyDefaultMapping(OpdMapper); +} + +RegisterBankInfo::InstructionMappings +X86RegisterBankInfo::getInstrAlternativeMappings(const MachineInstr &MI) const { + + const MachineFunction &MF = *MI.getParent()->getParent(); + const TargetSubtargetInfo &STI = MF.getSubtarget(); + const TargetRegisterInfo &TRI = *STI.getRegisterInfo(); + const MachineRegisterInfo &MRI = MF.getRegInfo(); - Mapping.setOperandsMapping(getOperandsMapping(OpdsMapping)); - return Mapping; + switch (MI.getOpcode()) { + case TargetOpcode::G_LOAD: + case TargetOpcode::G_STORE: { + // we going to try to map 32/64 bit to PMI_FP32/PMI_FP64 + unsigned Size = getSizeInBits(MI.getOperand(0).getReg(), MRI, TRI); + if (Size != 32 && Size != 64) + break; + + unsigned NumOperands = MI.getNumOperands(); + + // Track the bank of each register, use FP mapping (all scalars in VEC) + SmallVector<PartialMappingIdx, 4> OpRegBankIdx(NumOperands); + getInstrPartialMappingIdxs(MI, MRI, /* isFP */ true, OpRegBankIdx); + + // Finally construct the computed mapping. + SmallVector<const ValueMapping *, 8> OpdsMapping(NumOperands); + if (!getInstrValueMapping(MI, OpRegBankIdx, OpdsMapping)) + break; + + RegisterBankInfo::InstructionMapping Mapping = InstructionMapping{ + /*ID*/ 1, /*Cost*/ 1, getOperandsMapping(OpdsMapping), NumOperands}; + InstructionMappings AltMappings; + AltMappings.emplace_back(std::move(Mapping)); + return AltMappings; + } + default: + break; + } + return RegisterBankInfo::getInstrAlternativeMappings(MI); } diff --git a/llvm/lib/Target/X86/X86RegisterBankInfo.h b/llvm/lib/Target/X86/X86RegisterBankInfo.h index 5fcce87a71e..aaa83920b6b 100644 --- a/llvm/lib/Target/X86/X86RegisterBankInfo.h +++ b/llvm/lib/Target/X86/X86RegisterBankInfo.h @@ -49,12 +49,32 @@ private: static InstructionMapping getSameOperandsMapping(const MachineInstr &MI, bool isFP); + /// Track the bank of each instruction operand(register) + /// \return An instruction PartialMappingIdxs. + static void + getInstrPartialMappingIdxs(const MachineInstr &MI, + const MachineRegisterInfo &MRI, const bool isFP, + SmallVectorImpl<PartialMappingIdx> &OpRegBankIdx); + + /// Construct the instruction ValueMapping from PartialMappingIdxs + /// \return true if mapping succeeded. + static bool + getInstrValueMapping(const MachineInstr &MI, + const SmallVectorImpl<PartialMappingIdx> &OpRegBankIdx, + SmallVectorImpl<const ValueMapping *> &OpdsMapping); + public: X86RegisterBankInfo(const TargetRegisterInfo &TRI); const RegisterBank & getRegBankFromRegClass(const TargetRegisterClass &RC) const override; + InstructionMappings + getInstrAlternativeMappings(const MachineInstr &MI) const override; + + /// See RegisterBankInfo::applyMapping. + void applyMappingImpl(const OperandsMapper &OpdMapper) const override; + InstructionMapping getInstrMapping(const MachineInstr &MI) const override; }; |