36 #define DEBUG_TYPE "falkor-hwpf-fix"
38 STATISTIC(NumStridedLoadsMarked,
"Number of strided loads marked");
40 "Number of HW prefetch tag collisions avoided");
42 "Number of HW prefetch tag collisions not avoided due to lack of regsiters");
46 class FalkorMarkStridedAccesses {
54 bool runOnLoop(
Loop &
L);
60 class FalkorMarkStridedAccessesLegacy :
public FunctionPass {
85 "Falkor HW Prefetch Fix",
false,
false)
93 return new FalkorMarkStridedAccessesLegacy();
96 bool FalkorMarkStridedAccessesLegacy::runOnFunction(
Function &
F) {
106 LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
107 ScalarEvolution &SE = getAnalysis<ScalarEvolutionWrapperPass>().getSE();
109 FalkorMarkStridedAccesses LDP(LI, SE);
113 bool FalkorMarkStridedAccesses::run() {
114 bool MadeChange =
false;
118 MadeChange |= runOnLoop(**LIt);
123 bool FalkorMarkStridedAccesses::runOnLoop(
Loop &
L) {
128 bool MadeChange =
false;
142 if (!LSCEVAddRec || !LSCEVAddRec->
isAffine())
147 ++NumStridedLoadsMarked;
148 DEBUG(
dbgs() <<
"Load: " <<
I <<
" marked as strided\n");
168 virtual void getAnalysisUsage(
AnalysisUsage &AU)
const override {
190 : DestReg(0), BaseReg(0), BaseRegIdx(-1), OffsetOpnd(nullptr),
204 "Falkor HW Prefetch Fix Late Phase",
false,
false)
210 return (Dest & 0xf) | ((Base & 0xf) << 4) | ((Offset & 0x3f) << 8);
224 case AArch64::LD1i16:
225 case AArch64::LD1i32:
226 case AArch64::LD1i64:
228 case AArch64::LD2i16:
229 case AArch64::LD2i32:
230 case AArch64::LD2i64:
232 case AArch64::LD3i16:
233 case AArch64::LD3i32:
235 case AArch64::LD4i16:
236 case AArch64::LD4i32:
243 case AArch64::LD3i64:
244 case AArch64::LD4i64:
251 case AArch64::LD1Onev1d:
252 case AArch64::LD1Onev2s:
253 case AArch64::LD1Onev4h:
254 case AArch64::LD1Onev8b:
255 case AArch64::LD1Onev2d:
256 case AArch64::LD1Onev4s:
257 case AArch64::LD1Onev8h:
258 case AArch64::LD1Onev16b:
259 case AArch64::LD1Rv1d:
260 case AArch64::LD1Rv2s:
261 case AArch64::LD1Rv4h:
262 case AArch64::LD1Rv8b:
263 case AArch64::LD1Rv2d:
264 case AArch64::LD1Rv4s:
265 case AArch64::LD1Rv8h:
266 case AArch64::LD1Rv16b:
267 case AArch64::LD1Twov1d:
268 case AArch64::LD1Twov2s:
269 case AArch64::LD1Twov4h:
270 case AArch64::LD1Twov8b:
271 case AArch64::LD2Twov2s:
272 case AArch64::LD2Twov4s:
273 case AArch64::LD2Twov8b:
274 case AArch64::LD2Rv1d:
275 case AArch64::LD2Rv2s:
276 case AArch64::LD2Rv4s:
277 case AArch64::LD2Rv8b:
284 case AArch64::LD1Twov2d:
285 case AArch64::LD1Twov4s:
286 case AArch64::LD1Twov8h:
287 case AArch64::LD1Twov16b:
288 case AArch64::LD1Threev1d:
289 case AArch64::LD1Threev2s:
290 case AArch64::LD1Threev4h:
291 case AArch64::LD1Threev8b:
292 case AArch64::LD1Threev2d:
293 case AArch64::LD1Threev4s:
294 case AArch64::LD1Threev8h:
295 case AArch64::LD1Threev16b:
296 case AArch64::LD1Fourv1d:
297 case AArch64::LD1Fourv2s:
298 case AArch64::LD1Fourv4h:
299 case AArch64::LD1Fourv8b:
300 case AArch64::LD1Fourv2d:
301 case AArch64::LD1Fourv4s:
302 case AArch64::LD1Fourv8h:
303 case AArch64::LD1Fourv16b:
304 case AArch64::LD2Twov2d:
305 case AArch64::LD2Twov4h:
306 case AArch64::LD2Twov8h:
307 case AArch64::LD2Twov16b:
308 case AArch64::LD2Rv2d:
309 case AArch64::LD2Rv4h:
310 case AArch64::LD2Rv8h:
311 case AArch64::LD2Rv16b:
312 case AArch64::LD3Threev2s:
313 case AArch64::LD3Threev4h:
314 case AArch64::LD3Threev8b:
315 case AArch64::LD3Threev2d:
316 case AArch64::LD3Threev4s:
317 case AArch64::LD3Threev8h:
318 case AArch64::LD3Threev16b:
319 case AArch64::LD3Rv1d:
320 case AArch64::LD3Rv2s:
321 case AArch64::LD3Rv4h:
322 case AArch64::LD3Rv8b:
323 case AArch64::LD3Rv2d:
324 case AArch64::LD3Rv4s:
325 case AArch64::LD3Rv8h:
326 case AArch64::LD3Rv16b:
327 case AArch64::LD4Fourv2s:
328 case AArch64::LD4Fourv4h:
329 case AArch64::LD4Fourv8b:
330 case AArch64::LD4Fourv2d:
331 case AArch64::LD4Fourv4s:
332 case AArch64::LD4Fourv8h:
333 case AArch64::LD4Fourv16b:
334 case AArch64::LD4Rv1d:
335 case AArch64::LD4Rv2s:
336 case AArch64::LD4Rv4h:
337 case AArch64::LD4Rv8b:
338 case AArch64::LD4Rv2d:
339 case AArch64::LD4Rv4s:
340 case AArch64::LD4Rv8h:
341 case AArch64::LD4Rv16b:
348 case AArch64::LD1i8_POST:
349 case AArch64::LD1i16_POST:
350 case AArch64::LD1i32_POST:
351 case AArch64::LD1i64_POST:
352 case AArch64::LD2i8_POST:
353 case AArch64::LD2i16_POST:
354 case AArch64::LD2i32_POST:
355 case AArch64::LD2i64_POST:
356 case AArch64::LD3i8_POST:
357 case AArch64::LD3i16_POST:
358 case AArch64::LD3i32_POST:
359 case AArch64::LD4i8_POST:
360 case AArch64::LD4i16_POST:
361 case AArch64::LD4i32_POST:
368 case AArch64::LD3i64_POST:
369 case AArch64::LD4i64_POST:
376 case AArch64::LD1Onev1d_POST:
377 case AArch64::LD1Onev2s_POST:
378 case AArch64::LD1Onev4h_POST:
379 case AArch64::LD1Onev8b_POST:
380 case AArch64::LD1Onev2d_POST:
381 case AArch64::LD1Onev4s_POST:
382 case AArch64::LD1Onev8h_POST:
383 case AArch64::LD1Onev16b_POST:
384 case AArch64::LD1Rv1d_POST:
385 case AArch64::LD1Rv2s_POST:
386 case AArch64::LD1Rv4h_POST:
387 case AArch64::LD1Rv8b_POST:
388 case AArch64::LD1Rv2d_POST:
389 case AArch64::LD1Rv4s_POST:
390 case AArch64::LD1Rv8h_POST:
391 case AArch64::LD1Rv16b_POST:
392 case AArch64::LD1Twov1d_POST:
393 case AArch64::LD1Twov2s_POST:
394 case AArch64::LD1Twov4h_POST:
395 case AArch64::LD1Twov8b_POST:
396 case AArch64::LD2Twov2s_POST:
397 case AArch64::LD2Twov4s_POST:
398 case AArch64::LD2Twov8b_POST:
399 case AArch64::LD2Rv1d_POST:
400 case AArch64::LD2Rv2s_POST:
401 case AArch64::LD2Rv4s_POST:
402 case AArch64::LD2Rv8b_POST:
409 case AArch64::LD1Twov2d_POST:
410 case AArch64::LD1Twov4s_POST:
411 case AArch64::LD1Twov8h_POST:
412 case AArch64::LD1Twov16b_POST:
413 case AArch64::LD1Threev1d_POST:
414 case AArch64::LD1Threev2s_POST:
415 case AArch64::LD1Threev4h_POST:
416 case AArch64::LD1Threev8b_POST:
417 case AArch64::LD1Threev2d_POST:
418 case AArch64::LD1Threev4s_POST:
419 case AArch64::LD1Threev8h_POST:
420 case AArch64::LD1Threev16b_POST:
421 case AArch64::LD1Fourv1d_POST:
422 case AArch64::LD1Fourv2s_POST:
423 case AArch64::LD1Fourv4h_POST:
424 case AArch64::LD1Fourv8b_POST:
425 case AArch64::LD1Fourv2d_POST:
426 case AArch64::LD1Fourv4s_POST:
427 case AArch64::LD1Fourv8h_POST:
428 case AArch64::LD1Fourv16b_POST:
429 case AArch64::LD2Twov2d_POST:
430 case AArch64::LD2Twov4h_POST:
431 case AArch64::LD2Twov8h_POST:
432 case AArch64::LD2Twov16b_POST:
433 case AArch64::LD2Rv2d_POST:
434 case AArch64::LD2Rv4h_POST:
435 case AArch64::LD2Rv8h_POST:
436 case AArch64::LD2Rv16b_POST:
437 case AArch64::LD3Threev2s_POST:
438 case AArch64::LD3Threev4h_POST:
439 case AArch64::LD3Threev8b_POST:
440 case AArch64::LD3Threev2d_POST:
441 case AArch64::LD3Threev4s_POST:
442 case AArch64::LD3Threev8h_POST:
443 case AArch64::LD3Threev16b_POST:
444 case AArch64::LD3Rv1d_POST:
445 case AArch64::LD3Rv2s_POST:
446 case AArch64::LD3Rv4h_POST:
447 case AArch64::LD3Rv8b_POST:
448 case AArch64::LD3Rv2d_POST:
449 case AArch64::LD3Rv4s_POST:
450 case AArch64::LD3Rv8h_POST:
451 case AArch64::LD3Rv16b_POST:
452 case AArch64::LD4Fourv2s_POST:
453 case AArch64::LD4Fourv4h_POST:
454 case AArch64::LD4Fourv8b_POST:
455 case AArch64::LD4Fourv2d_POST:
456 case AArch64::LD4Fourv4s_POST:
457 case AArch64::LD4Fourv8h_POST:
458 case AArch64::LD4Fourv16b_POST:
459 case AArch64::LD4Rv1d_POST:
460 case AArch64::LD4Rv2s_POST:
461 case AArch64::LD4Rv4h_POST:
462 case AArch64::LD4Rv8b_POST:
463 case AArch64::LD4Rv2d_POST:
464 case AArch64::LD4Rv4s_POST:
465 case AArch64::LD4Rv8h_POST:
466 case AArch64::LD4Rv16b_POST:
473 case AArch64::LDRBBroW:
474 case AArch64::LDRBBroX:
475 case AArch64::LDRBBui:
476 case AArch64::LDRBroW:
477 case AArch64::LDRBroX:
478 case AArch64::LDRBui:
480 case AArch64::LDRDroW:
481 case AArch64::LDRDroX:
482 case AArch64::LDRDui:
483 case AArch64::LDRHHroW:
484 case AArch64::LDRHHroX:
485 case AArch64::LDRHHui:
486 case AArch64::LDRHroW:
487 case AArch64::LDRHroX:
488 case AArch64::LDRHui:
490 case AArch64::LDRQroW:
491 case AArch64::LDRQroX:
492 case AArch64::LDRQui:
493 case AArch64::LDRSBWroW:
494 case AArch64::LDRSBWroX:
495 case AArch64::LDRSBWui:
496 case AArch64::LDRSBXroW:
497 case AArch64::LDRSBXroX:
498 case AArch64::LDRSBXui:
499 case AArch64::LDRSHWroW:
500 case AArch64::LDRSHWroX:
501 case AArch64::LDRSHWui:
502 case AArch64::LDRSHXroW:
503 case AArch64::LDRSHXroX:
504 case AArch64::LDRSHXui:
505 case AArch64::LDRSWl:
506 case AArch64::LDRSWroW:
507 case AArch64::LDRSWroX:
508 case AArch64::LDRSWui:
510 case AArch64::LDRSroW:
511 case AArch64::LDRSroX:
512 case AArch64::LDRSui:
514 case AArch64::LDRWroW:
515 case AArch64::LDRWroX:
516 case AArch64::LDRWui:
518 case AArch64::LDRXroW:
519 case AArch64::LDRXroX:
520 case AArch64::LDRXui:
521 case AArch64::LDURBBi:
522 case AArch64::LDURBi:
523 case AArch64::LDURDi:
524 case AArch64::LDURHHi:
525 case AArch64::LDURHi:
526 case AArch64::LDURQi:
527 case AArch64::LDURSBWi:
528 case AArch64::LDURSBXi:
529 case AArch64::LDURSHWi:
530 case AArch64::LDURSHXi:
531 case AArch64::LDURSWi:
532 case AArch64::LDURSi:
533 case AArch64::LDURWi:
534 case AArch64::LDURXi:
541 case AArch64::LDRBBpost:
542 case AArch64::LDRBBpre:
543 case AArch64::LDRBpost:
544 case AArch64::LDRBpre:
545 case AArch64::LDRDpost:
546 case AArch64::LDRDpre:
547 case AArch64::LDRHHpost:
548 case AArch64::LDRHHpre:
549 case AArch64::LDRHpost:
550 case AArch64::LDRHpre:
551 case AArch64::LDRQpost:
552 case AArch64::LDRQpre:
553 case AArch64::LDRSBWpost:
554 case AArch64::LDRSBWpre:
555 case AArch64::LDRSBXpost:
556 case AArch64::LDRSBXpre:
557 case AArch64::LDRSHWpost:
558 case AArch64::LDRSHWpre:
559 case AArch64::LDRSHXpost:
560 case AArch64::LDRSHXpre:
561 case AArch64::LDRSWpost:
562 case AArch64::LDRSWpre:
563 case AArch64::LDRSpost:
564 case AArch64::LDRSpre:
565 case AArch64::LDRWpost:
566 case AArch64::LDRWpre:
567 case AArch64::LDRXpost:
568 case AArch64::LDRXpre:
583 case AArch64::LDPSWi:
593 case AArch64::LDPQpost:
594 case AArch64::LDPQpre:
601 case AArch64::LDPDpost:
602 case AArch64::LDPDpre:
603 case AArch64::LDPSWpost:
604 case AArch64::LDPSWpre:
605 case AArch64::LDPSpost:
606 case AArch64::LDPSpre:
607 case AArch64::LDPWpost:
608 case AArch64::LDPWpre:
609 case AArch64::LDPXpost:
610 case AArch64::LDPXpre:
621 LI.BaseRegIdx = BaseRegIdx;
622 LI.OffsetOpnd = OffsetIdx == -1 ?
nullptr : &MI.
getOperand(OffsetIdx);
623 LI.IsPrePost = IsPrePost;
632 if (LI.OffsetOpnd ==
nullptr)
634 else if (LI.OffsetOpnd->isGlobal() || LI.OffsetOpnd->isSymbol() ||
635 LI.OffsetOpnd->isCPI())
637 else if (LI.OffsetOpnd->isReg())
640 Off = LI.OffsetOpnd->getImm() >> 2;
642 return makeTag(Dest, Base, Off);
656 TagMap[*
Tag].push_back(&
MI);
659 bool AnyCollisions =
false;
660 for (
auto &
P : TagMap) {
661 auto Size =
P.second.size();
663 for (
auto *
MI :
P.second) {
664 if (
TII->isStridedAccess(*
MI)) {
665 AnyCollisions =
true;
684 LR.addLiveOuts(*MBB);
685 for (
auto I = MBB->rbegin();
I != MBB->rend(); LR.stepBackward(*
I), ++
I) {
687 if (!
TII->isStridedAccess(MI))
691 unsigned OldTag = *
getTag(TRI, MI, LdI);
692 auto &OldCollisions = TagMap[OldTag];
693 if (OldCollisions.size() <= 1)
697 DEBUG(
dbgs() <<
"Attempting to fix tag collision: " << MI);
699 for (
unsigned ScratchReg : AArch64::GPR64RegClass) {
700 if (!LR.available(ScratchReg) || MRI.
isReserved(ScratchReg))
704 NewLdI.BaseReg = ScratchReg;
705 unsigned NewTag = *
getTag(TRI, MI, NewLdI);
707 if (TagMap.count(NewTag))
719 BuildMI(*MBB, &MI, DL,
TII->get(AArch64::ORRXrs), ScratchReg)
720 .addReg(AArch64::XZR)
724 BaseOpnd.
setReg(ScratchReg);
729 DEBUG(
dbgs() <<
"Doing post MOV of incremented reg: "
730 <<
PrintReg(ScratchReg, TRI) <<
'\n');
734 TII->get(AArch64::ORRXrs), LdI.BaseReg)
735 .addReg(AArch64::XZR)
740 for (
int I = 0,
E = OldCollisions.size();
I !=
E; ++
I)
741 if (OldCollisions[
I] == &MI) {
743 OldCollisions.pop_back();
751 TagMap[NewTag].push_back(&MI);
752 ++NumCollisionsAvoided;
758 ++NumCollisionsNotAvoided;
774 assert(TRI->trackLivenessAfterRegAlloc(Fn) &&
775 "Register liveness not available!");
const AArch64RegisterInfo & getRegisterInfo() const
getRegisterInfo - TargetInstrInfo is a superset of MRegister info.
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
STATISTIC(NumFunctions,"Total number of functions")
FunctionPass * createFalkorMarkStridedAccessesPass()
The main scalar evolution driver.
static Optional< LoadInfo > getLoadInfo(const MachineInstr &MI)
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
An instruction for reading from memory.
const std::vector< BlockT * > & getBlocks() const
Get a list of the basic blocks which make up this loop.
INITIALIZE_PASS_BEGIN(FalkorMarkStridedAccessesLegacy, DEBUG_TYPE,"Falkor HW Prefetch Fix", false, false) INITIALIZE_PASS_END(FalkorMarkStridedAccessesLegacy
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
TMC & getTM() const
Get the right type of TargetMachine for this target.
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...
const HexagonInstrInfo * TII
falkor hwpf fix Falkor HW Prefetch Fix Late static false unsigned makeTag(unsigned Dest, unsigned Base, unsigned Offset)
bool isLoopInvariant(const Value *V) const
Return true if the specified value is loop invariant.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
Target-Independent Code Generator Pass Configuration Options.
falkor hwpf fix Falkor HW Prefetch Fix Late Phase
This node represents a polynomial recurrence on the trip count of the specified loop.
Printable PrintReg(unsigned Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubRegIdx=0)
Prints virtual and physical registers with or without a TRI instance.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
iterator_range< block_iterator > blocks() const
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
bool isAffine() const
Return true if this represents an expression A + B*x where A and B are loop invariant values...
unsigned const MachineRegisterInfo * MRI
LLVM Basic Block Representation.
df_iterator< T > df_end(const T &G)
bool isReserved(unsigned PhysReg) const
isReserved - Returns true when PhysReg is a reserved register.
const MachineOperand & getOperand(unsigned i) const
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Represent the analysis usage information of a pass.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
FunctionPass class - This class is used to implement most global optimizations.
Value * getPointerOperand()
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
LLVMContext & getContext() const
All values hold a context through their type.
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
void initializeFalkorMarkStridedAccessesLegacyPass(PassRegistry &)
MachineOperand class - Representation of each machine instruction operand.
Module.h This file contains the declarations for the Module class.
void initializeFalkorHWPFFixPass(PassRegistry &)
static Optional< unsigned > getTag(const TargetRegisterInfo *TRI, const MachineInstr &MI, const LoadInfo &LI)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
df_iterator< T > df_begin(const T &G)
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
loop data Loop Data Prefetch
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
MachineFunctionProperties & set(Property P)
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Representation of each machine instruction.
#define FALKOR_STRIDED_ACCESS_MD
This class represents an analyzed expression in the program.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Represents a single loop in the control flow graph.
void setReg(unsigned Reg)
Change the register this operand corresponds to.
FunctionPass * createFalkorHWPFFixPass()
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
A set of register units used to track register liveness.
unsigned getReg() const
getReg - Returns the register number.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
uint16_t getEncodingValue(unsigned RegNo) const
Returns the encoding for RegNo.
LLVM Value Representation.
const SCEV * getSCEV(Value *V)
Return a SCEV expression for the full generality of the specified expression.
The legacy pass manager's analysis pass to compute loop information.
Legacy analysis pass which computes a DominatorTree.
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Properties which a MachineFunction may have at a given point in time.