diff options
Diffstat (limited to 'lib/Target/AArch64/AArch64FalkorHWPFFix.cpp')
| -rw-r--r-- | lib/Target/AArch64/AArch64FalkorHWPFFix.cpp | 67 |
1 files changed, 46 insertions, 21 deletions
diff --git a/lib/Target/AArch64/AArch64FalkorHWPFFix.cpp b/lib/Target/AArch64/AArch64FalkorHWPFFix.cpp index 2c887a9ca5db..d1ddb2e3ef70 100644 --- a/lib/Target/AArch64/AArch64FalkorHWPFFix.cpp +++ b/lib/Target/AArch64/AArch64FalkorHWPFFix.cpp @@ -1,4 +1,4 @@ -//===-- AArch64FalkorHWPFFix.cpp - Avoid HW prefetcher pitfalls on Falkor--===// +//===- AArch64FalkorHWPFFix.cpp - Avoid HW prefetcher pitfalls on Falkor --===// // // The LLVM Compiler Infrastructure // @@ -15,21 +15,41 @@ #include "AArch64.h" #include "AArch64InstrInfo.h" +#include "AArch64Subtarget.h" #include "AArch64TargetMachine.h" +#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DepthFirstIterator.h" +#include "llvm/ADT/None.h" +#include "llvm/ADT/Optional.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/ScalarEvolution.h" #include "llvm/Analysis/ScalarEvolutionExpressions.h" #include "llvm/CodeGen/LiveRegUnits.h" +#include "llvm/CodeGen/MachineBasicBlock.h" +#include "llvm/CodeGen/MachineFunction.h" +#include "llvm/CodeGen/MachineFunctionPass.h" +#include "llvm/CodeGen/MachineInstr.h" #include "llvm/CodeGen/MachineInstrBuilder.h" +#include "llvm/CodeGen/MachineLoopInfo.h" +#include "llvm/CodeGen/MachineOperand.h" #include "llvm/CodeGen/MachineRegisterInfo.h" #include "llvm/CodeGen/TargetPassConfig.h" +#include "llvm/CodeGen/TargetRegisterInfo.h" +#include "llvm/IR/DebugLoc.h" #include "llvm/IR/Dominators.h" #include "llvm/IR/Function.h" -#include "llvm/IR/Module.h" -#include "llvm/Support/CommandLine.h" +#include "llvm/IR/Instruction.h" +#include "llvm/IR/Instructions.h" +#include "llvm/IR/Metadata.h" +#include "llvm/Pass.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/Debug.h" +#include "llvm/Support/raw_ostream.h" +#include <cassert> +#include <iterator> +#include <utility> using namespace llvm; @@ -60,6 +80,7 @@ private: class FalkorMarkStridedAccessesLegacy : public FunctionPass { public: static char ID; // Pass ID, replacement for typeid + FalkorMarkStridedAccessesLegacy() : FunctionPass(ID) { initializeFalkorMarkStridedAccessesLegacyPass( *PassRegistry::getPassRegistry()); @@ -71,16 +92,16 @@ public: AU.addRequired<LoopInfoWrapperPass>(); AU.addPreserved<LoopInfoWrapperPass>(); AU.addRequired<ScalarEvolutionWrapperPass>(); - // FIXME: For some reason, preserving SE here breaks LSR (even if - // this pass changes nothing). - // AU.addPreserved<ScalarEvolutionWrapperPass>(); + AU.addPreserved<ScalarEvolutionWrapperPass>(); } bool runOnFunction(Function &F) override; }; -} // namespace + +} // end anonymous namespace char FalkorMarkStridedAccessesLegacy::ID = 0; + INITIALIZE_PASS_BEGIN(FalkorMarkStridedAccessesLegacy, DEBUG_TYPE, "Falkor HW Prefetch Fix", false, false) INITIALIZE_PASS_DEPENDENCY(TargetPassConfig) @@ -165,7 +186,7 @@ public: bool runOnMachineFunction(MachineFunction &Fn) override; - virtual void getAnalysisUsage(AnalysisUsage &AU) const override { + void getAnalysisUsage(AnalysisUsage &AU) const override { AU.addRequired<MachineLoopInfo>(); MachineFunctionPass::getAnalysisUsage(AU); } @@ -186,17 +207,16 @@ private: /// Bits from load opcodes used to compute HW prefetcher instruction tags. struct LoadInfo { - LoadInfo() - : DestReg(0), BaseReg(0), BaseRegIdx(-1), OffsetOpnd(nullptr), - IsPrePost(false) {} - unsigned DestReg; - unsigned BaseReg; - int BaseRegIdx; - const MachineOperand *OffsetOpnd; - bool IsPrePost; + LoadInfo() = default; + + unsigned DestReg = 0; + unsigned BaseReg = 0; + int BaseRegIdx = -1; + const MachineOperand *OffsetOpnd = nullptr; + bool IsPrePost = false; }; -} // namespace +} // end anonymous namespace char FalkorHWPFFix::ID = 0; @@ -618,9 +638,14 @@ static Optional<LoadInfo> getLoadInfo(const MachineInstr &MI) { break; } + // Loads from the stack pointer don't get prefetched. + unsigned BaseReg = MI.getOperand(BaseRegIdx).getReg(); + if (BaseReg == AArch64::SP || BaseReg == AArch64::WSP) + return None; + LoadInfo LI; LI.DestReg = DestRegIdx == -1 ? 0 : MI.getOperand(DestRegIdx).getReg(); - LI.BaseReg = MI.getOperand(BaseRegIdx).getReg(); + LI.BaseReg = BaseReg; LI.BaseRegIdx = BaseRegIdx; LI.OffsetOpnd = OffsetIdx == -1 ? nullptr : &MI.getOperand(OffsetIdx); LI.IsPrePost = IsPrePost; @@ -715,7 +740,7 @@ void FalkorHWPFFix::runOnLoop(MachineLoop &L, MachineFunction &Fn) { if (TagMap.count(NewTag)) continue; - DEBUG(dbgs() << "Changing base reg to: " << PrintReg(ScratchReg, TRI) + DEBUG(dbgs() << "Changing base reg to: " << printReg(ScratchReg, TRI) << '\n'); // Rewrite: @@ -735,7 +760,7 @@ void FalkorHWPFFix::runOnLoop(MachineLoop &L, MachineFunction &Fn) { // well to update the real base register. if (LdI.IsPrePost) { DEBUG(dbgs() << "Doing post MOV of incremented reg: " - << PrintReg(ScratchReg, TRI) << '\n'); + << printReg(ScratchReg, TRI) << '\n'); MI.getOperand(0).setReg( ScratchReg); // Change tied operand pre/post update dest. BuildMI(*MBB, std::next(MachineBasicBlock::iterator(MI)), DL, @@ -773,7 +798,7 @@ bool FalkorHWPFFix::runOnMachineFunction(MachineFunction &Fn) { if (ST.getProcFamily() != AArch64Subtarget::Falkor) return false; - if (skipFunction(*Fn.getFunction())) + if (skipFunction(Fn.getFunction())) return false; TII = static_cast<const AArch64InstrInfo *>(ST.getInstrInfo()); |
