//===------- X86InsertPrefetch.cpp - Insert cache prefetch hints ----------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This pass applies cache prefetch instructions based on a profile. The pass // assumes DiscriminateMemOps ran immediately before, to ensure debug info // matches the one used at profile generation time. The profile is encoded in // afdo format (text or binary). It contains prefetch hints recommendations. // Each recommendation is made in terms of debug info locations, a type (i.e. // nta, t{0|1|2}) and a delta. The debug info identifies an instruction with a // memory operand (see X86DiscriminateMemOps). The prefetch will be made for // a location at that memory operand + the delta specified in the // recommendation. // //===----------------------------------------------------------------------===// #include "X86.h" #include "X86InstrBuilder.h" #include "X86InstrInfo.h" #include "X86MachineFunctionInfo.h" #include "X86Subtarget.h" #include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/CodeGen/MachineModuleInfo.h" #include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/Module.h" #include "llvm/ProfileData/SampleProf.h" #include "llvm/ProfileData/SampleProfReader.h" #include "llvm/Support/VirtualFileSystem.h" #include "llvm/Transforms/IPO/SampleProfile.h" usingnamespacellvm; usingnamespacesampleprof; static cl::opt<std::string> PrefetchHintsFile("prefetch-hints-file", cl::desc("Path to the prefetch hints profile. See also " "-x86-discriminate-memops"), cl::Hidden); namespace { class X86InsertPrefetch : public MachineFunctionPass { … }; PrefetchHints; // Return any prefetching hints for the specified MachineInstruction. The hints // are returned as pairs (name, delta). ErrorOr<const PrefetchHints &> getPrefetchHints(const FunctionSamples *TopSamples, const MachineInstr &MI) { … } // The prefetch instruction can't take memory operands involving vector // registers. bool IsMemOpCompatibleWithPrefetch(const MachineInstr &MI, int Op) { … } } // end anonymous namespace //===----------------------------------------------------------------------===// // Implementation //===----------------------------------------------------------------------===// char X86InsertPrefetch::ID = …; X86InsertPrefetch::X86InsertPrefetch(const std::string &PrefetchHintsFilename) : … { … } /// Return true if the provided MachineInstruction has cache prefetch hints. In /// that case, the prefetch hints are stored, in order, in the Prefetches /// vector. bool X86InsertPrefetch::findPrefetchInfo(const FunctionSamples *TopSamples, const MachineInstr &MI, Prefetches &Prefetches) const { … } bool X86InsertPrefetch::doInitialization(Module &M) { … } void X86InsertPrefetch::getAnalysisUsage(AnalysisUsage &AU) const { … } bool X86InsertPrefetch::runOnMachineFunction(MachineFunction &MF) { … } FunctionPass *llvm::createX86InsertPrefetchPass() { … }