55#define DEBUG_TYPE "aarch64-falkor-hwpf-fix"
57STATISTIC(NumStridedLoadsMarked,
"Number of strided loads marked");
59 "Number of HW prefetch tag collisions avoided");
61 "Number of HW prefetch tag collisions not avoided due to lack of registers");
63 "Controls which tag collisions are avoided");
67class FalkorMarkStridedAccesses {
75 bool runOnLoop(
Loop &L);
81class FalkorMarkStridedAccessesLegacy :
public FunctionPass {
104char FalkorMarkStridedAccessesLegacy::ID = 0;
107 "Falkor HW Prefetch Fix",
false,
false)
115 return new FalkorMarkStridedAccessesLegacy();
118bool FalkorMarkStridedAccessesLegacy::runOnFunction(
Function &
F) {
128 LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
129 ScalarEvolution &SE = getAnalysis<ScalarEvolutionWrapperPass>().getSE();
131 FalkorMarkStridedAccesses LDP(LI, SE);
135bool FalkorMarkStridedAccesses::run() {
136 bool MadeChange =
false;
140 MadeChange |= runOnLoop(*LIt);
145bool FalkorMarkStridedAccesses::runOnLoop(
Loop &L) {
147 if (!
L.isInnermost())
150 bool MadeChange =
false;
154 LoadInst *LoadI = dyn_cast<LoadInst>(&
I);
159 if (
L.isLoopInvariant(PtrValue))
163 const SCEVAddRecExpr *LSCEVAddRec = dyn_cast<SCEVAddRecExpr>(LSCEV);
164 if (!LSCEVAddRec || !LSCEVAddRec->
isAffine())
169 ++NumStridedLoadsMarked;
198 MachineFunctionProperties::Property::NoVRegs);
218 bool IsPrePost =
false;
223char FalkorHWPFFix::ID = 0;
226 "Falkor HW Prefetch Fix Late Phase",
false,
false)
232 return (Dest & 0xf) | ((
Base & 0xf) << 4) | ((
Offset & 0x3f) << 8);
241 switch (
MI.getOpcode()) {
245 case AArch64::LD1i64:
246 case AArch64::LD2i64:
254 case AArch64::LD1i16:
255 case AArch64::LD1i32:
257 case AArch64::LD2i16:
258 case AArch64::LD2i32:
260 case AArch64::LD3i16:
261 case AArch64::LD3i32:
262 case AArch64::LD3i64:
264 case AArch64::LD4i16:
265 case AArch64::LD4i32:
266 case AArch64::LD4i64:
273 case AArch64::LD1Onev1d:
274 case AArch64::LD1Onev2s:
275 case AArch64::LD1Onev4h:
276 case AArch64::LD1Onev8b:
277 case AArch64::LD1Onev2d:
278 case AArch64::LD1Onev4s:
279 case AArch64::LD1Onev8h:
280 case AArch64::LD1Onev16b:
281 case AArch64::LD1Rv1d:
282 case AArch64::LD1Rv2s:
283 case AArch64::LD1Rv4h:
284 case AArch64::LD1Rv8b:
285 case AArch64::LD1Rv2d:
286 case AArch64::LD1Rv4s:
287 case AArch64::LD1Rv8h:
288 case AArch64::LD1Rv16b:
295 case AArch64::LD1Twov1d:
296 case AArch64::LD1Twov2s:
297 case AArch64::LD1Twov4h:
298 case AArch64::LD1Twov8b:
299 case AArch64::LD1Twov2d:
300 case AArch64::LD1Twov4s:
301 case AArch64::LD1Twov8h:
302 case AArch64::LD1Twov16b:
303 case AArch64::LD1Threev1d:
304 case AArch64::LD1Threev2s:
305 case AArch64::LD1Threev4h:
306 case AArch64::LD1Threev8b:
307 case AArch64::LD1Threev2d:
308 case AArch64::LD1Threev4s:
309 case AArch64::LD1Threev8h:
310 case AArch64::LD1Threev16b:
311 case AArch64::LD1Fourv1d:
312 case AArch64::LD1Fourv2s:
313 case AArch64::LD1Fourv4h:
314 case AArch64::LD1Fourv8b:
315 case AArch64::LD1Fourv2d:
316 case AArch64::LD1Fourv4s:
317 case AArch64::LD1Fourv8h:
318 case AArch64::LD1Fourv16b:
319 case AArch64::LD2Twov2s:
320 case AArch64::LD2Twov4s:
321 case AArch64::LD2Twov8b:
322 case AArch64::LD2Twov2d:
323 case AArch64::LD2Twov4h:
324 case AArch64::LD2Twov8h:
325 case AArch64::LD2Twov16b:
326 case AArch64::LD2Rv1d:
327 case AArch64::LD2Rv2s:
328 case AArch64::LD2Rv4s:
329 case AArch64::LD2Rv8b:
330 case AArch64::LD2Rv2d:
331 case AArch64::LD2Rv4h:
332 case AArch64::LD2Rv8h:
333 case AArch64::LD2Rv16b:
334 case AArch64::LD3Threev2s:
335 case AArch64::LD3Threev4h:
336 case AArch64::LD3Threev8b:
337 case AArch64::LD3Threev2d:
338 case AArch64::LD3Threev4s:
339 case AArch64::LD3Threev8h:
340 case AArch64::LD3Threev16b:
341 case AArch64::LD3Rv1d:
342 case AArch64::LD3Rv2s:
343 case AArch64::LD3Rv4h:
344 case AArch64::LD3Rv8b:
345 case AArch64::LD3Rv2d:
346 case AArch64::LD3Rv4s:
347 case AArch64::LD3Rv8h:
348 case AArch64::LD3Rv16b:
349 case AArch64::LD4Fourv2s:
350 case AArch64::LD4Fourv4h:
351 case AArch64::LD4Fourv8b:
352 case AArch64::LD4Fourv2d:
353 case AArch64::LD4Fourv4s:
354 case AArch64::LD4Fourv8h:
355 case AArch64::LD4Fourv16b:
356 case AArch64::LD4Rv1d:
357 case AArch64::LD4Rv2s:
358 case AArch64::LD4Rv4h:
359 case AArch64::LD4Rv8b:
360 case AArch64::LD4Rv2d:
361 case AArch64::LD4Rv4s:
362 case AArch64::LD4Rv8h:
363 case AArch64::LD4Rv16b:
370 case AArch64::LD1i64_POST:
371 case AArch64::LD2i64_POST:
378 case AArch64::LD1i8_POST:
379 case AArch64::LD1i16_POST:
380 case AArch64::LD1i32_POST:
381 case AArch64::LD2i8_POST:
382 case AArch64::LD2i16_POST:
383 case AArch64::LD2i32_POST:
384 case AArch64::LD3i8_POST:
385 case AArch64::LD3i16_POST:
386 case AArch64::LD3i32_POST:
387 case AArch64::LD3i64_POST:
388 case AArch64::LD4i8_POST:
389 case AArch64::LD4i16_POST:
390 case AArch64::LD4i32_POST:
391 case AArch64::LD4i64_POST:
398 case AArch64::LD1Onev1d_POST:
399 case AArch64::LD1Onev2s_POST:
400 case AArch64::LD1Onev4h_POST:
401 case AArch64::LD1Onev8b_POST:
402 case AArch64::LD1Onev2d_POST:
403 case AArch64::LD1Onev4s_POST:
404 case AArch64::LD1Onev8h_POST:
405 case AArch64::LD1Onev16b_POST:
406 case AArch64::LD1Rv1d_POST:
407 case AArch64::LD1Rv2s_POST:
408 case AArch64::LD1Rv4h_POST:
409 case AArch64::LD1Rv8b_POST:
410 case AArch64::LD1Rv2d_POST:
411 case AArch64::LD1Rv4s_POST:
412 case AArch64::LD1Rv8h_POST:
413 case AArch64::LD1Rv16b_POST:
420 case AArch64::LD1Twov1d_POST:
421 case AArch64::LD1Twov2s_POST:
422 case AArch64::LD1Twov4h_POST:
423 case AArch64::LD1Twov8b_POST:
424 case AArch64::LD1Twov2d_POST:
425 case AArch64::LD1Twov4s_POST:
426 case AArch64::LD1Twov8h_POST:
427 case AArch64::LD1Twov16b_POST:
428 case AArch64::LD1Threev1d_POST:
429 case AArch64::LD1Threev2s_POST:
430 case AArch64::LD1Threev4h_POST:
431 case AArch64::LD1Threev8b_POST:
432 case AArch64::LD1Threev2d_POST:
433 case AArch64::LD1Threev4s_POST:
434 case AArch64::LD1Threev8h_POST:
435 case AArch64::LD1Threev16b_POST:
436 case AArch64::LD1Fourv1d_POST:
437 case AArch64::LD1Fourv2s_POST:
438 case AArch64::LD1Fourv4h_POST:
439 case AArch64::LD1Fourv8b_POST:
440 case AArch64::LD1Fourv2d_POST:
441 case AArch64::LD1Fourv4s_POST:
442 case AArch64::LD1Fourv8h_POST:
443 case AArch64::LD1Fourv16b_POST:
444 case AArch64::LD2Twov2s_POST:
445 case AArch64::LD2Twov4s_POST:
446 case AArch64::LD2Twov8b_POST:
447 case AArch64::LD2Twov2d_POST:
448 case AArch64::LD2Twov4h_POST:
449 case AArch64::LD2Twov8h_POST:
450 case AArch64::LD2Twov16b_POST:
451 case AArch64::LD2Rv1d_POST:
452 case AArch64::LD2Rv2s_POST:
453 case AArch64::LD2Rv4s_POST:
454 case AArch64::LD2Rv8b_POST:
455 case AArch64::LD2Rv2d_POST:
456 case AArch64::LD2Rv4h_POST:
457 case AArch64::LD2Rv8h_POST:
458 case AArch64::LD2Rv16b_POST:
459 case AArch64::LD3Threev2s_POST:
460 case AArch64::LD3Threev4h_POST:
461 case AArch64::LD3Threev8b_POST:
462 case AArch64::LD3Threev2d_POST:
463 case AArch64::LD3Threev4s_POST:
464 case AArch64::LD3Threev8h_POST:
465 case AArch64::LD3Threev16b_POST:
466 case AArch64::LD3Rv1d_POST:
467 case AArch64::LD3Rv2s_POST:
468 case AArch64::LD3Rv4h_POST:
469 case AArch64::LD3Rv8b_POST:
470 case AArch64::LD3Rv2d_POST:
471 case AArch64::LD3Rv4s_POST:
472 case AArch64::LD3Rv8h_POST:
473 case AArch64::LD3Rv16b_POST:
474 case AArch64::LD4Fourv2s_POST:
475 case AArch64::LD4Fourv4h_POST:
476 case AArch64::LD4Fourv8b_POST:
477 case AArch64::LD4Fourv2d_POST:
478 case AArch64::LD4Fourv4s_POST:
479 case AArch64::LD4Fourv8h_POST:
480 case AArch64::LD4Fourv16b_POST:
481 case AArch64::LD4Rv1d_POST:
482 case AArch64::LD4Rv2s_POST:
483 case AArch64::LD4Rv4h_POST:
484 case AArch64::LD4Rv8b_POST:
485 case AArch64::LD4Rv2d_POST:
486 case AArch64::LD4Rv4s_POST:
487 case AArch64::LD4Rv8h_POST:
488 case AArch64::LD4Rv16b_POST:
495 case AArch64::LDRBBroW:
496 case AArch64::LDRBBroX:
497 case AArch64::LDRBBui:
498 case AArch64::LDRBroW:
499 case AArch64::LDRBroX:
500 case AArch64::LDRBui:
502 case AArch64::LDRDroW:
503 case AArch64::LDRDroX:
504 case AArch64::LDRDui:
505 case AArch64::LDRHHroW:
506 case AArch64::LDRHHroX:
507 case AArch64::LDRHHui:
508 case AArch64::LDRHroW:
509 case AArch64::LDRHroX:
510 case AArch64::LDRHui:
512 case AArch64::LDRQroW:
513 case AArch64::LDRQroX:
514 case AArch64::LDRQui:
515 case AArch64::LDRSBWroW:
516 case AArch64::LDRSBWroX:
517 case AArch64::LDRSBWui:
518 case AArch64::LDRSBXroW:
519 case AArch64::LDRSBXroX:
520 case AArch64::LDRSBXui:
521 case AArch64::LDRSHWroW:
522 case AArch64::LDRSHWroX:
523 case AArch64::LDRSHWui:
524 case AArch64::LDRSHXroW:
525 case AArch64::LDRSHXroX:
526 case AArch64::LDRSHXui:
527 case AArch64::LDRSWl:
528 case AArch64::LDRSWroW:
529 case AArch64::LDRSWroX:
530 case AArch64::LDRSWui:
532 case AArch64::LDRSroW:
533 case AArch64::LDRSroX:
534 case AArch64::LDRSui:
536 case AArch64::LDRWroW:
537 case AArch64::LDRWroX:
538 case AArch64::LDRWui:
540 case AArch64::LDRXroW:
541 case AArch64::LDRXroX:
542 case AArch64::LDRXui:
543 case AArch64::LDURBBi:
544 case AArch64::LDURBi:
545 case AArch64::LDURDi:
546 case AArch64::LDURHHi:
547 case AArch64::LDURHi:
548 case AArch64::LDURQi:
549 case AArch64::LDURSBWi:
550 case AArch64::LDURSBXi:
551 case AArch64::LDURSHWi:
552 case AArch64::LDURSHXi:
553 case AArch64::LDURSWi:
554 case AArch64::LDURSi:
555 case AArch64::LDURWi:
556 case AArch64::LDURXi:
563 case AArch64::LDRBBpost:
564 case AArch64::LDRBBpre:
565 case AArch64::LDRBpost:
566 case AArch64::LDRBpre:
567 case AArch64::LDRDpost:
568 case AArch64::LDRDpre:
569 case AArch64::LDRHHpost:
570 case AArch64::LDRHHpre:
571 case AArch64::LDRHpost:
572 case AArch64::LDRHpre:
573 case AArch64::LDRQpost:
574 case AArch64::LDRQpre:
575 case AArch64::LDRSBWpost:
576 case AArch64::LDRSBWpre:
577 case AArch64::LDRSBXpost:
578 case AArch64::LDRSBXpre:
579 case AArch64::LDRSHWpost:
580 case AArch64::LDRSHWpre:
581 case AArch64::LDRSHXpost:
582 case AArch64::LDRSHXpre:
583 case AArch64::LDRSWpost:
584 case AArch64::LDRSWpre:
585 case AArch64::LDRSpost:
586 case AArch64::LDRSpre:
587 case AArch64::LDRWpost:
588 case AArch64::LDRWpre:
589 case AArch64::LDRXpost:
590 case AArch64::LDRXpre:
597 case AArch64::LDNPDi:
598 case AArch64::LDNPQi:
599 case AArch64::LDNPSi:
609 case AArch64::LDPSWi:
618 case AArch64::LDPQpost:
619 case AArch64::LDPQpre:
620 case AArch64::LDPDpost:
621 case AArch64::LDPDpre:
622 case AArch64::LDPSpost:
623 case AArch64::LDPSpre:
630 case AArch64::LDPSWpost:
631 case AArch64::LDPSWpre:
632 case AArch64::LDPWpost:
633 case AArch64::LDPWpre:
634 case AArch64::LDPXpost:
635 case AArch64::LDPXpre:
644 Register BaseReg =
MI.getOperand(BaseRegIdx).getReg();
645 if (BaseReg == AArch64::SP || BaseReg == AArch64::WSP)
649 LI.DestReg = DestRegIdx == -1 ?
Register() :
MI.getOperand(DestRegIdx).getReg();
650 LI.BaseReg = BaseReg;
651 LI.BaseRegIdx = BaseRegIdx;
652 LI.OffsetOpnd = OffsetIdx == -1 ? nullptr : &
MI.getOperand(OffsetIdx);
653 LI.IsPrePost = IsPrePost;
660 unsigned Dest = LI.DestReg ?
TRI->getEncodingValue(LI.DestReg) : 0;
661 unsigned Base =
TRI->getEncodingValue(LI.BaseReg);
663 if (LI.OffsetOpnd ==
nullptr)
665 else if (LI.OffsetOpnd->isGlobal() || LI.OffsetOpnd->isSymbol() ||
666 LI.OffsetOpnd->isCPI())
668 else if (LI.OffsetOpnd->isReg())
669 Off = (1 << 5) |
TRI->getEncodingValue(LI.OffsetOpnd->getReg());
671 Off = LI.OffsetOpnd->getImm() >> 2;
687 TagMap[*
Tag].push_back(&
MI);
690 bool AnyCollisions =
false;
691 for (
auto &
P : TagMap) {
692 auto Size =
P.second.size();
694 for (
auto *
MI :
P.second) {
695 if (
TII->isStridedAccess(*
MI)) {
696 AnyCollisions =
true;
715 LR.addLiveOuts(*
MBB);
718 if (!
TII->isStridedAccess(
MI))
725 std::optional<unsigned> OptOldTag =
getTag(
TRI,
MI, LdI);
728 auto &OldCollisions = TagMap[*OptOldTag];
729 if (OldCollisions.size() <= 1)
742 for (
unsigned OpI = 0, OpE =
MI.getNumOperands(); OpI < OpE; ++OpI) {
743 if (OpI ==
static_cast<unsigned>(LdI.BaseRegIdx))
750 for (
unsigned ScratchReg : AArch64::GPR64RegClass) {
751 if (!LR.available(ScratchReg) ||
MRI.isReserved(ScratchReg))
755 NewLdI.BaseReg = ScratchReg;
758 if (TagMap.count(NewTag))
775 BaseOpnd.
setReg(ScratchReg);
782 MI.getOperand(0).setReg(
785 TII->get(AArch64::ORRXrs), LdI.BaseReg)
791 for (
int I = 0,
E = OldCollisions.size();
I !=
E; ++
I)
792 if (OldCollisions[
I] == &
MI) {
794 OldCollisions.pop_back();
802 TagMap[NewTag].push_back(&
MI);
803 ++NumCollisionsAvoided;
809 ++NumCollisionsNotAvoided;
823 TRI =
ST.getRegisterInfo();
832 if (
L->isInnermost())
unsigned const MachineRegisterInfo * MRI
aarch64 falkor hwpf fix Falkor HW Prefetch Fix Late static false unsigned makeTag(unsigned Dest, unsigned Base, unsigned Offset)
static std::optional< LoadInfo > getLoadInfo(const MachineInstr &MI)
aarch64 falkor hwpf fix Falkor HW Prefetch Fix Late Phase
static std::optional< unsigned > getTag(const TargetRegisterInfo *TRI, const MachineInstr &MI, const LoadInfo &LI)
aarch64 falkor hwpf fix late
#define FALKOR_STRIDED_ACCESS_MD
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file provides an implementation of debug counters.
#define DEBUG_COUNTER(VARNAME, COUNTERNAME, DESC)
This file defines the DenseMap class.
This file builds on the ADT/GraphTraits.h file to build generic depth first graph iterator.
const HexagonInstrInfo * TII
unsigned const TargetRegisterInfo * TRI
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Target-Independent Code Generator Pass Configuration Options pass.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
void setPreservesCFG()
This function should be called by the pass, iff they do not:
LLVM Basic Block Representation.
static bool shouldExecute(unsigned CounterName)
Legacy analysis pass which computes a DominatorTree.
FunctionPass class - This class is used to implement most global optimizations.
virtual bool runOnFunction(Function &F)=0
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
A set of register units used to track register liveness.
An instruction for reading from memory.
Value * getPointerOperand()
The legacy pass manager's analysis pass to compute loop information.
Represents a single loop in the control flow graph.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
reverse_iterator rbegin()
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...
virtual MachineFunctionProperties getRequiredProperties() const
Properties which a MachineFunction may have at a given point in time.
MachineFunctionProperties & set(Property P)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
bool readsReg() const
readsReg - Returns true if this operand reads the previous value of its register.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
void setReg(Register Reg)
Change the register this operand corresponds to.
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Wrapper class representing virtual and physical registers.
This node represents a polynomial recurrence on the trip count of the specified loop.
bool isAffine() const
Return true if this represents an expression A + B*x where A and B are loop invariant values.
This class represents an analyzed expression in the program.
The main scalar evolution driver.
const SCEV * getSCEV(Value *V)
Return a SCEV expression for the full generality of the specified expression.
Target-Independent Code Generator Pass Configuration Options.
TMC & getTM() const
Get the right type of TargetMachine for this target.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
LLVM Value Representation.
LLVMContext & getContext() const
All values hold a context through their type.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
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 * createFalkorMarkStridedAccessesPass()
FunctionPass * createFalkorHWPFFixPass()
void initializeFalkorMarkStridedAccessesLegacyPass(PassRegistry &)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void initializeFalkorHWPFFixPass(PassRegistry &)
iterator_range< df_iterator< T > > depth_first(const T &G)
Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
A record for a potential prefetch made during the initial scan of the loop.