LLVM  14.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 
21 namespace llvm {
22 
23 class CallInst;
24 class DataLayout;
25 class DiagnosticInfoIROptimization;
26 class Instruction;
27 class IntrinsicInst;
28 class Value;
29 class OptimizationRemarkEmitter;
30 class OptimizationRemarkMissed;
31 class OptimizationRemarkAnalysis;
32 class StoreInst;
33 
34 // FIXME: Once we get to more remarks like this one, we need to re-evaluate how
35 // much of this logic should actually go into the remark emitter.
39  const DataLayout &DL;
41 
43  const DataLayout &DL, const TargetLibraryInfo &TLI)
44  : ORE(ORE), RemarkPass(RemarkPass), DL(DL), TLI(TLI) {}
45 
46  virtual ~MemoryOpRemark();
47 
48  /// \return true iff the instruction is understood by MemoryOpRemark.
49  static bool canHandle(const Instruction *I, const TargetLibraryInfo &TLI);
50 
51  void visit(const Instruction *I);
52 
53 protected:
54  virtual std::string explainSource(StringRef Type) const;
55 
57  virtual StringRef remarkName(RemarkKind RK) const;
58 
60 
61 private:
62  template<typename ...Ts>
63  std::unique_ptr<DiagnosticInfoIROptimization> makeRemark(Ts... Args);
64 
65  /// Emit a remark using information from the store's destination, size, etc.
66  void visitStore(const StoreInst &SI);
67  /// Emit a generic auto-init remark.
68  void visitUnknown(const Instruction &I);
69  /// Emit a remark using information from known intrinsic calls.
70  void visitIntrinsicCall(const IntrinsicInst &II);
71  /// Emit a remark using information from known function calls.
72  void visitCall(const CallInst &CI);
73 
74  /// Add callee information to a remark: whether it's known, the function name,
75  /// etc.
76  template <typename FTy>
77  void visitCallee(FTy F, bool KnownLibCall, DiagnosticInfoIROptimization &R);
78  /// Add operand information to a remark based on knowledge we have for known
79  /// libcalls.
80  void visitKnownLibCall(const CallInst &CI, LibFunc LF,
82  /// Add the memory operation size to a remark.
83  void visitSizeOperand(Value *V, DiagnosticInfoIROptimization &R);
84 
85  struct VariableInfo {
88  bool isEmpty() const { return !Name && !Size; }
89  };
90  /// Gather more information about \p V as a variable. This can be debug info,
91  /// information from the alloca, etc. Since \p V can represent more than a
92  /// single variable, they will all be added to the remark.
93  void visitPtr(Value *V, bool IsSrc, DiagnosticInfoIROptimization &R);
94  void visitVariable(const Value *V, SmallVectorImpl<VariableInfo> &Result);
95 };
96 
97 /// Special case for -ftrivial-auto-var-init remarks.
98 struct AutoInitRemark : public MemoryOpRemark {
100  const DataLayout &DL, const TargetLibraryInfo &TLI)
102 
103  /// \return true iff the instruction is understood by AutoInitRemark.
104  static bool canHandle(const Instruction *I);
105 
106 protected:
107  virtual std::string explainSource(StringRef Type) const override;
108  virtual StringRef remarkName(RemarkKind RK) const override;
109  virtual DiagnosticKind diagnosticKind() const override {
111  }
112 };
113 
114 } // namespace llvm
115 
116 #endif
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::MemoryOpRemark
Definition: MemoryOpRemark.h:36
llvm::MemoryOpRemark::MemoryOpRemark
MemoryOpRemark(OptimizationRemarkEmitter &ORE, StringRef RemarkPass, const DataLayout &DL, const TargetLibraryInfo &TLI)
Definition: MemoryOpRemark.h:42
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:112
StringRef.h
llvm::MemoryOpRemark::RemarkPass
StringRef RemarkPass
Definition: MemoryOpRemark.h:38
llvm::AutoInitRemark
Special case for -ftrivial-auto-var-init remarks.
Definition: MemoryOpRemark.h:98
llvm::MemoryOpRemark::explainSource
virtual std::string explainSource(StringRef Type) const
Definition: MemoryOpRemark.cpp:108
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:56
llvm::Optional
Definition: APInt.h:33
llvm::DiagnosticInfoIROptimization
Common features for diagnostics dealing with optimization remarks that are used by IR passes.
Definition: DiagnosticInfo.h:618
llvm::MemoryOpRemark::TLI
const TargetLibraryInfo & TLI
Definition: MemoryOpRemark.h:40
llvm::DiagnosticKind
DiagnosticKind
Defines the different supported kind of a diagnostic.
Definition: DiagnosticInfo.h:55
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::MemoryOpRemark::DL
const DataLayout & DL
Definition: MemoryOpRemark.h:39
llvm::LibFunc
LibFunc
Definition: TargetLibraryInfo.h:34
llvm::MemoryOpRemark::~MemoryOpRemark
virtual ~MemoryOpRemark()
llvm::MemoryOpRemark::remarkName
virtual StringRef remarkName(RemarkKind RK) const
Definition: MemoryOpRemark.cpp:112
TargetLibraryInfo.h
llvm::DK_OptimizationRemarkAnalysis
@ DK_OptimizationRemarkAnalysis
Definition: DiagnosticInfo.h:67
llvm::Instruction
Definition: Instruction.h:45
llvm::AutoInitRemark::AutoInitRemark
AutoInitRemark(OptimizationRemarkEmitter &ORE, StringRef RemarkPass, const DataLayout &DL, const TargetLibraryInfo &TLI)
Definition: MemoryOpRemark.h:99
llvm::DK_OptimizationRemarkMissed
@ DK_OptimizationRemarkMissed
Definition: DiagnosticInfo.h:66
llvm::MemoryOpRemark::diagnosticKind
virtual DiagnosticKind diagnosticKind() const
Definition: MemoryOpRemark.h:59
llvm::AutoInitRemark::explainSource
virtual std::string explainSource(StringRef Type) const override
Definition: MemoryOpRemark.cpp:392
llvm::StoreInst
An instruction for storing to memory.
Definition: Instructions.h:304
llvm::AutoInitRemark::canHandle
static bool canHandle(const Instruction *I)
Definition: MemoryOpRemark.cpp:383
I
#define I(x, y, z)
Definition: MD5.cpp:59
SI
StandardInstrumentations SI(Debug, VerifyEach)
llvm::MemoryOpRemark::visit
void visit(const Instruction *I)
Definition: MemoryOpRemark.cpp:77
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:58
llvm::MemoryOpRemark::canHandle
static bool canHandle(const Instruction *I, const TargetLibraryInfo &TLI)
Definition: MemoryOpRemark.cpp:25
llvm::MemoryOpRemark::RemarkKind
RemarkKind
Definition: MemoryOpRemark.h:56
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
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:219
llvm::MemoryOpRemark::RK_Store
@ RK_Store
Definition: MemoryOpRemark.h:56
llvm::IntrinsicInst
A wrapper class for inspecting calls to intrinsic functions.
Definition: IntrinsicInst.h:45
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition: Instructions.h:1475
llvm::MemoryOpRemark::ORE
OptimizationRemarkEmitter & ORE
Definition: MemoryOpRemark.h:37
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:389
llvm::MemoryOpRemark::RK_Call
@ RK_Call
Definition: MemoryOpRemark.h:56
llvm::AutoInitRemark::remarkName
virtual StringRef remarkName(RemarkKind RK) const override
Definition: MemoryOpRemark.cpp:396
llvm::MemoryOpRemark::RK_Unknown
@ RK_Unknown
Definition: MemoryOpRemark.h:56
llvm::AutoInitRemark::diagnosticKind
virtual DiagnosticKind diagnosticKind() const override
Definition: MemoryOpRemark.h:109
llvm::Value
LLVM Value Representation.
Definition: Value.h:75