46 #define DEBUG_TYPE "aarch64-vectorbyelement-opt"
49 "Number of vector by element instructions modified");
51 #define AARCH64_VECTOR_BY_ELEMENT_OPT_NAME \
52 "AArch64 vector by element instruction optimization pass"
92 bool reuseDUP(
MachineInstr &
MI,
unsigned DupOpcode,
unsigned SrcReg,
93 unsigned LaneNumber,
unsigned *DestReg)
const;
100 std::map<unsigned, bool> *VecInstElemTable)
const;
113 INITIALIZE_PASS(AArch64VectorByElementOpt,
"aarch64-vectorbyelement-opt",
122 bool AArch64VectorByElementOpt::shouldReplaceInstruction(
128 if (!VecInstElemTable.empty() &&
129 VecInstElemTable.find(InstDesc->getOpcode()) != VecInstElemTable.end())
130 return VecInstElemTable[InstDesc->getOpcode()];
132 unsigned SCIdx = InstDesc->getSchedClass();
136 SchedModel.getMCSchedModel()->getSchedClassDesc(SCIdx);
138 SchedModel.getMCSchedModel()->getSchedClassDesc(SCIdxRep1);
140 SchedModel.getMCSchedModel()->getSchedClassDesc(SCIdxRep2);
147 VecInstElemTable[InstDesc->getOpcode()] =
false;
151 if (SchedModel.computeInstrLatency(InstDesc->getOpcode()) >
152 SchedModel.computeInstrLatency(InstDescRep1->getOpcode()) +
153 SchedModel.computeInstrLatency(InstDescRep2->getOpcode())) {
154 VecInstElemTable[InstDesc->getOpcode()] =
true;
157 VecInstElemTable[InstDesc->getOpcode()] =
false;
170 bool AArch64VectorByElementOpt::earlyExitVectElement(
MachineFunction *MF) {
172 const MCInstrDesc *IndexMulMCID = &
TII->get(AArch64::FMLAv4i32_indexed);
176 if (!shouldReplaceInstruction(MF, IndexMulMCID, DupMCID, MulMCID,
186 bool AArch64VectorByElementOpt::reuseDUP(
MachineInstr &
MI,
unsigned DupOpcode,
187 unsigned SrcReg,
unsigned LaneNumber,
188 unsigned *DestReg)
const {
194 if (CurrentMI->
getOpcode() == DupOpcode &&
218 bool AArch64VectorByElementOpt::optimizeVectElement(
219 MachineInstr &MI, std::map<unsigned, bool> *VecInstElemTable)
const {
228 case AArch64::FMLAv4i32_indexed:
229 DupMCID = &
TII->get(AArch64::DUPv4i32lane);
230 MulMCID = &
TII->get(AArch64::FMLAv4f32);
232 case AArch64::FMLSv4i32_indexed:
233 DupMCID = &
TII->get(AArch64::DUPv4i32lane);
234 MulMCID = &
TII->get(AArch64::FMLSv4f32);
236 case AArch64::FMULXv4i32_indexed:
237 DupMCID = &
TII->get(AArch64::DUPv4i32lane);
238 MulMCID = &
TII->get(AArch64::FMULXv4f32);
240 case AArch64::FMULv4i32_indexed:
241 DupMCID = &
TII->get(AArch64::DUPv4i32lane);
242 MulMCID = &
TII->get(AArch64::FMULv4f32);
246 case AArch64::FMLAv2i64_indexed:
247 DupMCID = &
TII->get(AArch64::DUPv2i64lane);
248 MulMCID = &
TII->get(AArch64::FMLAv2f64);
250 case AArch64::FMLSv2i64_indexed:
251 DupMCID = &
TII->get(AArch64::DUPv2i64lane);
252 MulMCID = &
TII->get(AArch64::FMLSv2f64);
254 case AArch64::FMULXv2i64_indexed:
255 DupMCID = &
TII->get(AArch64::DUPv2i64lane);
256 MulMCID = &
TII->get(AArch64::FMULXv2f64);
258 case AArch64::FMULv2i64_indexed:
259 DupMCID = &
TII->get(AArch64::DUPv2i64lane);
260 MulMCID = &
TII->get(AArch64::FMULv2f64);
264 case AArch64::FMLAv2i32_indexed:
265 RC = &AArch64::FPR64RegClass;
266 DupMCID = &
TII->get(AArch64::DUPv2i32lane);
267 MulMCID = &
TII->get(AArch64::FMLAv2f32);
269 case AArch64::FMLSv2i32_indexed:
270 RC = &AArch64::FPR64RegClass;
271 DupMCID = &
TII->get(AArch64::DUPv2i32lane);
272 MulMCID = &
TII->get(AArch64::FMLSv2f32);
274 case AArch64::FMULXv2i32_indexed:
275 RC = &AArch64::FPR64RegClass;
276 DupMCID = &
TII->get(AArch64::DUPv2i32lane);
277 MulMCID = &
TII->get(AArch64::FMULXv2f32);
279 case AArch64::FMULv2i32_indexed:
280 RC = &AArch64::FPR64RegClass;
281 DupMCID = &
TII->get(AArch64::DUPv2i32lane);
282 MulMCID = &
TII->get(AArch64::FMULv2f32);
312 if (!reuseDUP(MI, DupMCID->
getOpcode(), SrcReg2, LaneNumber, &DupDest)) {
314 BuildMI(MBB, MI, DL, *DupMCID, DupDest)
315 .
addReg(SrcReg2, Src2IsKill)
318 BuildMI(MBB, MI, DL, *MulMCID, MulDest)
319 .
addReg(SrcReg0, Src0IsKill)
320 .
addReg(SrcReg1, Src1IsKill)
321 .
addReg(DupDest, Src2IsKill);
324 if (!reuseDUP(MI, DupMCID->
getOpcode(), SrcReg1, LaneNumber, &DupDest)) {
326 BuildMI(MBB, MI, DL, *DupMCID, DupDest)
327 .
addReg(SrcReg1, Src1IsKill)
330 BuildMI(MBB, MI, DL, *MulMCID, MulDest)
331 .
addReg(SrcReg0, Src0IsKill)
332 .
addReg(DupDest, Src1IsKill);
341 bool AArch64VectorByElementOpt::runOnMachineFunction(
MachineFunction &MF) {
353 if (!SchedModel.hasInstrSchedModel())
357 if (earlyExitVectElement(&MF))
360 bool Changed =
false;
368 if (optimizeVectElement(MI, &VecInstElemTable)) {
387 return new AArch64VectorByElementOpt();
void push_back(const T &Elt)
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
STATISTIC(NumFunctions,"Total number of functions")
unsigned createVirtualRegister(const TargetRegisterClass *RegClass)
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
#define AARCH64_VECTOR_BY_ELEMENT_OPT_NAME
Describe properties that are true of each instruction in the target description file.
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Provide an instruction scheduling machine model to CodeGen passes.
const HexagonInstrInfo * TII
FunctionPass * createAArch64VectorByElementOptPass()
createAArch64VectorByElementOptPass - returns an instance of the vector by element optimization pass...
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
const MCSchedModel & getSchedModel() const
Get the machine model for this subtarget's CPU.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
unsigned getNumOperands() const
Access to explicit operands of the instruction.
INITIALIZE_PASS(AArch64VectorByElementOpt,"aarch64-vectorbyelement-opt", AARCH64_VECTOR_BY_ELEMENT_OPT_NAME, false, false) bool AArch64VectorByElementOpt unsigned SCIdx
Based only on latency of instructions, determine if it is cost efficient to replace the instruction I...
const MCSchedClassDesc * SCDescRep2
unsigned getKillRegState(bool B)
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineBasicBlock * getParent() const
TargetInstrInfo - Interface to description of machine instruction set.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
unsigned const MachineRegisterInfo * MRI
void initializeAArch64VectorByElementOptPass(PassRegistry &)
const MachineOperand & getOperand(unsigned i) const
Summarize the scheduling resources required for an instruction of a particular scheduling class...
FunctionPass class - This class is used to implement most global optimizations.
VecInstElemTable[InstDesc->getOpcode()]
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
unsigned getOpcode() const
Return the opcode number for this descriptor.
const MCSchedClassDesc * SCDescRep1
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
TargetSubtargetInfo - Generic base class for all target subtargets.
Representation of each machine instruction.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
unsigned getReg() const
getReg - Returns the register number.
virtual const TargetInstrInfo * getInstrInfo() const
StringRef - Represent a constant reference to a string, i.e.
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
const MCSchedClassDesc * SCDesc