LLVM  16.0.0git
MemoryOpRemark.h
Go to the documentation of this file.
1 //===- MemoryOpRemark.h - Memory operation remark analysis -*- C++ ------*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Provide more information about instructions that copy, move, or initialize
10 // memory, including those with a "auto-init" !annotation metadata.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_TRANSFORMS_UTILS_MEMORYOPREMARK_H
15 #define LLVM_TRANSFORMS_UTILS_MEMORYOPREMARK_H
16 
17 #include "llvm/ADT/StringRef.h"
19 #include "llvm/IR/DiagnosticInfo.h"
20 #include <optional>
21 
22 namespace llvm {
23 
24 class CallInst;
25 class DataLayout;
26 class DiagnosticInfoIROptimization;
27 class Instruction;
28 class IntrinsicInst;
29 class Value;
30 class OptimizationRemarkEmitter;
31 class StoreInst;
32 
33 // FIXME: Once we get to more remarks like this one, we need to re-evaluate how
34 // much of this logic should actually go into the remark emitter.
38  const DataLayout &DL;
40 
42  const DataLayout &DL, const TargetLibraryInfo &TLI)
43  : ORE(ORE), RemarkPass(RemarkPass), DL(DL), TLI(TLI) {}
44 
45  virtual ~MemoryOpRemark();
46 
47  /// \return true iff the instruction is understood by MemoryOpRemark.
48  static bool canHandle(const Instruction *I, const TargetLibraryInfo &TLI);
49 
50  void visit(const Instruction *I);
51 
52 protected:
53  virtual std::string explainSource(StringRef Type) const;
54 
56  virtual StringRef remarkName(RemarkKind RK) const;
57 
59 
60 private:
61  template<typename ...Ts>
62  std::unique_ptr<DiagnosticInfoIROptimization> makeRemark(Ts... Args);
63 
64  /// Emit a remark using information from the store's destination, size, etc.
65  void visitStore(const StoreInst &SI);
66  /// Emit a generic auto-init remark.
67  void visitUnknown(const Instruction &I);
68  /// Emit a remark using information from known intrinsic calls.
69  void visitIntrinsicCall(const IntrinsicInst &II);
70  /// Emit a remark using information from known function calls.
71  void visitCall(const CallInst &CI);
72 
73  /// Add callee information to a remark: whether it's known, the function name,
74  /// etc.
75  template <typename FTy>
76  void visitCallee(FTy F, bool KnownLibCall, DiagnosticInfoIROptimization &R);
77  /// Add operand information to a remark based on knowledge we have for known
78  /// libcalls.
79  void visitKnownLibCall(const CallInst &CI, LibFunc LF,
81  /// Add the memory operation size to a remark.
82  void visitSizeOperand(Value *V, DiagnosticInfoIROptimization &R);
83 
84  struct VariableInfo {
85  std::optional<StringRef> Name;
86  std::optional<uint64_t> Size;
87  bool isEmpty() const { return !Name && !Size; }
88  };
89  /// Gather more information about \p V as a variable. This can be debug info,
90  /// information from the alloca, etc. Since \p V can represent more than a
91  /// single variable, they will all be added to the remark.
92  void visitPtr(Value *V, bool IsSrc, DiagnosticInfoIROptimization &R);
93  void visitVariable(const Value *V, SmallVectorImpl<VariableInfo> &Result);
94 };
95 
96 /// Special case for -ftrivial-auto-var-init remarks.
97 struct AutoInitRemark : public MemoryOpRemark {
99  const DataLayout &DL, const TargetLibraryInfo &TLI)
101 
102  /// \return true iff the instruction is understood by AutoInitRemark.
103  static bool canHandle(const Instruction *I);
104 
105 protected:
106  std::string explainSource(StringRef Type) const override;
107  StringRef remarkName(RemarkKind RK) const override;
108  DiagnosticKind diagnosticKind() const override {
110  }
111 };
112 
113 } // namespace llvm
114 
115 #endif
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::MemoryOpRemark
Definition: MemoryOpRemark.h:35
llvm::MemoryOpRemark::MemoryOpRemark
MemoryOpRemark(OptimizationRemarkEmitter &ORE, StringRef RemarkPass, const DataLayout &DL, const TargetLibraryInfo &TLI)
Definition: MemoryOpRemark.h:41
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:113
StringRef.h
llvm::MemoryOpRemark::RemarkPass
StringRef RemarkPass
Definition: MemoryOpRemark.h:37
llvm::AutoInitRemark
Special case for -ftrivial-auto-var-init remarks.
Definition: MemoryOpRemark.h:97
llvm::MemoryOpRemark::explainSource
virtual std::string explainSource(StringRef Type) const
Definition: MemoryOpRemark.cpp:109
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::MemoryOpRemark::RK_IntrinsicCall
@ RK_IntrinsicCall
Definition: MemoryOpRemark.h:55
llvm::DiagnosticInfoIROptimization
Common features for diagnostics dealing with optimization remarks that are used by IR passes.
Definition: DiagnosticInfo.h:622
llvm::MemoryOpRemark::TLI
const TargetLibraryInfo & TLI
Definition: MemoryOpRemark.h:39
llvm::DiagnosticKind
DiagnosticKind
Defines the different supported kind of a diagnostic.
Definition: DiagnosticInfo.h:60
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::MemoryOpRemark::DL
const DataLayout & DL
Definition: MemoryOpRemark.h:38
llvm::LibFunc
LibFunc
Definition: TargetLibraryInfo.h:36
llvm::MemoryOpRemark::~MemoryOpRemark
virtual ~MemoryOpRemark()
SI
@ SI
Definition: SIInstrInfo.cpp:7966
llvm::MemoryOpRemark::remarkName
virtual StringRef remarkName(RemarkKind RK) const
Definition: MemoryOpRemark.cpp:113
TargetLibraryInfo.h
llvm::DK_OptimizationRemarkAnalysis
@ DK_OptimizationRemarkAnalysis
Definition: DiagnosticInfo.h:72
llvm::Instruction
Definition: Instruction.h:42
llvm::AutoInitRemark::AutoInitRemark
AutoInitRemark(OptimizationRemarkEmitter &ORE, StringRef RemarkPass, const DataLayout &DL, const TargetLibraryInfo &TLI)
Definition: MemoryOpRemark.h:98
llvm::DK_OptimizationRemarkMissed
@ DK_OptimizationRemarkMissed
Definition: DiagnosticInfo.h:71
llvm::MemoryOpRemark::diagnosticKind
virtual DiagnosticKind diagnosticKind() const
Definition: MemoryOpRemark.h:58
llvm::AutoInitRemark::explainSource
std::string explainSource(StringRef Type) const override
Definition: MemoryOpRemark.cpp:394
llvm::StoreInst
An instruction for storing to memory.
Definition: Instructions.h:298
llvm::AutoInitRemark::canHandle
static bool canHandle(const Instruction *I)
Definition: MemoryOpRemark.cpp:385
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::MemoryOpRemark::visit
void visit(const Instruction *I)
Definition: MemoryOpRemark.cpp:78
llvm::OptimizationRemarkEmitter
The optimization diagnostic interface.
Definition: OptimizationRemarkEmitter.h:33
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::MemoryOpRemark::canHandle
static bool canHandle(const Instruction *I, const TargetLibraryInfo &TLI)
Definition: MemoryOpRemark.cpp:26
llvm::AutoInitRemark::diagnosticKind
DiagnosticKind diagnosticKind() const override
Definition: MemoryOpRemark.h:108
llvm::MemoryOpRemark::RemarkKind
RemarkKind
Definition: MemoryOpRemark.h:55
DiagnosticInfo.h
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::TargetLibraryInfo
Provides information about what library functions are available for the current target.
Definition: TargetLibraryInfo.h:226
llvm::MemoryOpRemark::RK_Store
@ RK_Store
Definition: MemoryOpRemark.h:55
llvm::IntrinsicInst
A wrapper class for inspecting calls to intrinsic functions.
Definition: IntrinsicInst.h:47
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition: Instructions.h:1474
llvm::MemoryOpRemark::ORE
OptimizationRemarkEmitter & ORE
Definition: MemoryOpRemark.h:36
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:394
llvm::MemoryOpRemark::RK_Call
@ RK_Call
Definition: MemoryOpRemark.h:55
llvm::AutoInitRemark::remarkName
StringRef remarkName(RemarkKind RK) const override
Definition: MemoryOpRemark.cpp:398
llvm::MemoryOpRemark::RK_Unknown
@ RK_Unknown
Definition: MemoryOpRemark.h:55
llvm::Value
LLVM Value Representation.
Definition: Value.h:74