xref: /netbsd-src/external/apache2/llvm/dist/llvm/include/llvm/Transforms/Utils/AutoInitRemark.h (revision 82d56013d7b633d116a93943de88e08335357a7c)
1 //===- AutoInitRemark.h - Auto-init remark analysis -*- C++ -------------*-===//
2 //
3 //                      The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Provide more information about instructions with a "auto-init"
11 // !annotation metadata.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_TRANSFORMS_UTILS_AUTOINITREMARK_H
16 #define LLVM_TRANSFORMS_UTILS_AUTOINITREMARK_H
17 
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/Analysis/TargetLibraryInfo.h"
20 
21 namespace llvm {
22 
23 class CallInst;
24 class DataLayout;
25 class Instruction;
26 class IntrinsicInst;
27 class Value;
28 class OptimizationRemarkEmitter;
29 class OptimizationRemarkMissed;
30 class StoreInst;
31 
32 // FIXME: Once we get to more remarks like this one, we need to re-evaluate how
33 // much of this logic should actually go into the remark emitter.
34 struct AutoInitRemark {
35   OptimizationRemarkEmitter &ORE;
36   StringRef RemarkPass;
37   const DataLayout &DL;
38   const TargetLibraryInfo &TLI;
39 
AutoInitRemarkAutoInitRemark40   AutoInitRemark(OptimizationRemarkEmitter &ORE, StringRef RemarkPass,
41                  const DataLayout &DL, const TargetLibraryInfo &TLI)
42       : ORE(ORE), RemarkPass(RemarkPass), DL(DL), TLI(TLI) {}
43 
44   /// Emit a remark using information from the store's destination, size, etc.
45   void inspectStore(StoreInst &SI);
46   /// Emit a generic auto-init remark.
47   void inspectUnknown(Instruction &I);
48   /// Emit a remark using information from known intrinsic calls.
49   void inspectIntrinsicCall(IntrinsicInst &II);
50   /// Emit a remark using information from known function calls.
51   void inspectCall(CallInst &CI);
52 
53 private:
54   /// Add callee information to a remark: whether it's known, the function name,
55   /// etc.
56   template <typename FTy>
57   void inspectCallee(FTy F, bool KnownLibCall, OptimizationRemarkMissed &R);
58   /// Add operand information to a remark based on knowledge we have for known
59   /// libcalls.
60   void inspectKnownLibCall(CallInst &CI, LibFunc LF,
61                            OptimizationRemarkMissed &R);
62   /// Add the memory operation size to a remark.
63   void inspectSizeOperand(Value *V, OptimizationRemarkMissed &R);
64 
65   struct VariableInfo {
66     Optional<StringRef> Name;
67     Optional<uint64_t> Size;
isEmptyAutoInitRemark::VariableInfo68     bool isEmpty() const { return !Name && !Size; }
69   };
70   /// Gather more information about \p V as a variable. This can be debug info,
71   /// information from the alloca, etc. Since \p V can represent more than a
72   /// single variable, they will all be added to the remark.
73   void inspectDst(Value *Dst, OptimizationRemarkMissed &R);
74   void inspectVariable(const Value *V, SmallVectorImpl<VariableInfo> &Result);
75 };
76 
77 } // namespace llvm
78 
79 #endif
80