32 cl::desc(
"Threshold for triggering vextract replacement"));
46 return "Hexagon optimize vextract";
61 char HexagonVExtract::ID = 0;
65 "Hexagon optimize vextract",
false,
false)
71 Register ElemR =
MRI.createVirtualRegister(&Hexagon::IntRegsRegClass);
73 Register ExtIdxR = ExtI->getOperand(2).getReg();
74 unsigned ExtIdxS = ExtI->getOperand(2).getSubReg();
79 if (DI->
getOpcode() == Hexagon::A2_tfrsi) {
81 V &= (HST->getVectorLength()-1) & -4u;
83 BuildMI(ExtB, ExtI,
DL, HII->get(Hexagon::L2_loadri_io), ElemR)
90 Register IdxR =
MRI.createVirtualRegister(&Hexagon::IntRegsRegClass);
91 BuildMI(ExtB, ExtI,
DL, HII->get(Hexagon::A2_andir), IdxR)
92 .
add(ExtI->getOperand(2))
94 BuildMI(ExtB, ExtI,
DL, HII->get(Hexagon::L4_loadri_rr), ElemR)
104 const auto &HRI = *HST->getRegisterInfo();
109 std::map<unsigned, SmallVector<MachineInstr *, 4>> VExtractMap;
110 bool Changed =
false;
114 unsigned Opc =
MI.getOpcode();
115 if (Opc != Hexagon::V6_extractw)
118 VExtractMap[VecR].push_back(&
MI);
124 Register AddrR =
MRI.createVirtualRegister(&Hexagon::IntRegsRegClass);
125 unsigned FiOpc = AR != 0 ? Hexagon::PS_fia : Hexagon::PS_fi;
126 auto MIB =
BuildMI(BB, At, dl, HII->get(FiOpc), AddrR);
129 MIB.addFrameIndex(FI).addImm(
Offset);
134 for (
auto &
P : VExtractMap) {
135 unsigned VecR =
P.first;
139 const auto &VecRC = *
MRI.getRegClass(VecR);
140 Align Alignment = HRI.getSpillAlign(VecRC);
141 MaxAlign = std::max(MaxAlign.
valueOrOne(), Alignment);
152 unsigned StoreOpc = VecRC.getID() == Hexagon::HvxVRRegClassID
153 ? Hexagon::V6_vS32b_ai
154 : Hexagon::PS_vstorerw_ai;
161 unsigned VecSize = HRI.getRegSizeInBits(VecRC) / 8;
171 SR == 0 ? 0 : VecSize/2);
173 unsigned ElemR = genElemLoad(ExtI, BaseR,
MRI);
175 MRI.replaceRegWith(ExtR, ElemR);
181 if (AR && MaxAlign) {
186 if (*MaxAlign >
Op.getImm())
187 Op.setImm(MaxAlign->value());
194 return new HexagonVExtract();
unsigned const MachineRegisterInfo * MRI
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
Represent the analysis usage information of a pass.
This class represents an Operation in the Expression.
FunctionPass class - This class is used to implement most global optimizations.
Hexagon target-specific information for each MachineFunction.
const HexagonInstrInfo * getInstrInfo() const override
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
int CreateStackObject(uint64_t Size, Align Alignment, bool isSpillSlot, const AllocaInst *Alloca=nullptr, uint8_t ID=0)
Create a new statically sized stack object, returning a nonnegative identifier to represent it.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & add(const MachineOperand &MO) const
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineBasicBlock * getParent() const
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
const MachineOperand & getOperand(unsigned i) const
MachineOperand class - Representation of each machine instruction operand.
unsigned getSubReg() const
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Wrapper class representing virtual and physical registers.
A global registry used in conjunction with static constructors to make pluggable components (like tar...
StringRef - Represent a constant reference to a string, i.e.
self_iterator getIterator()
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
FunctionPass * createHexagonVExtract()
void initializeHexagonVExtractPass(PassRegistry &)
This struct is a compact representation of a valid (non-zero power of two) alignment.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.