LLVM 20.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"
20#include <optional>
21
22namespace llvm {
23
24class CallInst;
25class DataLayout;
26class DiagnosticInfoIROptimization;
27class Instruction;
28class IntrinsicInst;
29class Value;
30class OptimizationRemarkEmitter;
31class 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)
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
52protected:
53 virtual std::string explainSource(StringRef Type) const;
54
56 virtual StringRef remarkName(RemarkKind RK) const;
57
59
60private:
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.
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
105protected:
106 std::string explainSource(StringRef Type) const override;
107 StringRef remarkName(RemarkKind RK) const override;
110 }
111};
112
113} // namespace llvm
114
115#endif
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
uint64_t IntrinsicInst * II
This class represents a function call, abstracting a target machine's calling convention.
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
Common features for diagnostics dealing with optimization remarks that are used by IR passes.
A wrapper class for inspecting calls to intrinsic functions.
Definition: IntrinsicInst.h:48
The optimization diagnostic interface.
An instruction for storing to memory.
Definition: Instructions.h:290
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Provides information about what library functions are available for the current target.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:74
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
DiagnosticKind
Defines the different supported kind of a diagnostic.
@ DK_OptimizationRemarkAnalysis
@ DK_OptimizationRemarkMissed
Special case for -ftrivial-auto-var-init remarks.
static bool canHandle(const Instruction *I)
DiagnosticKind diagnosticKind() const override
StringRef remarkName(RemarkKind RK) const override
std::string explainSource(StringRef Type) const override
AutoInitRemark(OptimizationRemarkEmitter &ORE, StringRef RemarkPass, const DataLayout &DL, const TargetLibraryInfo &TLI)
virtual std::string explainSource(StringRef Type) const
virtual DiagnosticKind diagnosticKind() const
const TargetLibraryInfo & TLI
virtual StringRef remarkName(RemarkKind RK) const
void visit(const Instruction *I)
const DataLayout & DL
static bool canHandle(const Instruction *I, const TargetLibraryInfo &TLI)
virtual ~MemoryOpRemark()
MemoryOpRemark(OptimizationRemarkEmitter &ORE, StringRef RemarkPass, const DataLayout &DL, const TargetLibraryInfo &TLI)
OptimizationRemarkEmitter & ORE