#ifndef LLVM_TRANSFORMS_UTILS_MEMORYOPREMARK_H
#define LLVM_TRANSFORMS_UTILS_MEMORYOPREMARK_H
#include "llvm/ADT/StringRef.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/IR/DiagnosticInfo.h"
namespace llvm {
class CallInst;
class DataLayout;
class DiagnosticInfoIROptimization;
class Instruction;
class IntrinsicInst;
class Value;
class OptimizationRemarkEmitter;
class StoreInst;
struct MemoryOpRemark {
OptimizationRemarkEmitter &ORE;
StringRef RemarkPass;
const DataLayout &DL;
const TargetLibraryInfo &TLI;
MemoryOpRemark(OptimizationRemarkEmitter &ORE, StringRef RemarkPass,
const DataLayout &DL, const TargetLibraryInfo &TLI)
: ORE(ORE), RemarkPass(RemarkPass), DL(DL), TLI(TLI) {}
virtual ~MemoryOpRemark();
static bool canHandle(const Instruction *I, const TargetLibraryInfo &TLI);
void visit(const Instruction *I);
protected:
virtual std::string explainSource(StringRef Type) const;
enum RemarkKind { RK_Store, RK_Unknown, RK_IntrinsicCall, RK_Call };
virtual StringRef remarkName(RemarkKind RK) const;
virtual DiagnosticKind diagnosticKind() const { return DK_OptimizationRemarkAnalysis; }
private:
template<typename ...Ts>
std::unique_ptr<DiagnosticInfoIROptimization> makeRemark(Ts... Args);
void visitStore(const StoreInst &SI);
void visitUnknown(const Instruction &I);
void visitIntrinsicCall(const IntrinsicInst &II);
void visitCall(const CallInst &CI);
template <typename FTy>
void visitCallee(FTy F, bool KnownLibCall, DiagnosticInfoIROptimization &R);
void visitKnownLibCall(const CallInst &CI, LibFunc LF,
DiagnosticInfoIROptimization &R);
void visitSizeOperand(Value *V, DiagnosticInfoIROptimization &R);
struct VariableInfo {
Optional<StringRef> Name;
Optional<uint64_t> Size;
bool isEmpty() const { return !Name && !Size; }
};
void visitPtr(Value *V, bool IsSrc, DiagnosticInfoIROptimization &R);
void visitVariable(const Value *V, SmallVectorImpl<VariableInfo> &Result);
};
struct AutoInitRemark : public MemoryOpRemark {
AutoInitRemark(OptimizationRemarkEmitter &ORE, StringRef RemarkPass,
const DataLayout &DL, const TargetLibraryInfo &TLI)
: MemoryOpRemark(ORE, RemarkPass, DL, TLI) {}
static bool canHandle(const Instruction *I);
protected:
std::string explainSource(StringRef Type) const override;
StringRef remarkName(RemarkKind RK) const override;
DiagnosticKind diagnosticKind() const override {
return DK_OptimizationRemarkMissed;
}
};
}
#endif