summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDiego Novillo <dnovillo@google.com>2014-04-08 16:42:34 +0000
committerDiego Novillo <dnovillo@google.com>2014-04-08 16:42:34 +0000
commitccbf1d2a05a63f18bedbeddffe930cc70d5f5823 (patch)
tree43e244afa7130b9a97233c021c316e00bb659fd9 /include
parent60db02b6feaa7fe08dfeac04a62e3c8ae4298fa1 (diff)
downloadllvm-ccbf1d2a05a63f18bedbeddffe930cc70d5f5823.tar.gz
llvm-ccbf1d2a05a63f18bedbeddffe930cc70d5f5823.tar.bz2
llvm-ccbf1d2a05a63f18bedbeddffe930cc70d5f5823.tar.xz
Add support for optimization reports.
Summary: This patch adds backend support for -Rpass=, which indicates the name of the optimization pass that should emit remarks stating when it made a transformation to the code. Pass names are taken from their DEBUG_NAME definitions. When emitting an optimization report diagnostic, the lack of debug information causes the diagnostic to use "<unknown>:0:0" as the location string. This is the back end counterpart for http://llvm-reviews.chandlerc.com/D3226 Reviewers: qcolombet CC: llvm-commits Differential Revision: http://llvm-reviews.chandlerc.com/D3227 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205774 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/IR/DiagnosticInfo.h59
-rw-r--r--include/llvm/IR/LLVMContext.h11
2 files changed, 70 insertions, 0 deletions
diff --git a/include/llvm/IR/DiagnosticInfo.h b/include/llvm/IR/DiagnosticInfo.h
index 49eb1b0c14..589291a128 100644
--- a/include/llvm/IR/DiagnosticInfo.h
+++ b/include/llvm/IR/DiagnosticInfo.h
@@ -26,6 +26,7 @@ class Function;
class Instruction;
class Twine;
class Value;
+class DebugLoc;
/// \brief Defines the different supported severity of a diagnostic.
enum DiagnosticSeverity {
@@ -44,6 +45,7 @@ enum DiagnosticKind {
DK_StackSize,
DK_DebugMetadataVersion,
DK_SampleProfile,
+ DK_OptimizationRemark,
DK_FirstPluginKind
};
@@ -235,6 +237,63 @@ private:
const Twine &Msg;
};
+/// Diagnostic information for optimization remarks.
+class DiagnosticInfoOptimizationRemark : public DiagnosticInfo {
+public:
+ /// \p PassName is the name of the pass emitting this diagnostic. If
+ /// this name matches the regular expression given in -Rpass=, then the
+ /// diagnostic will be emitted. \p Fn is the function where the diagnostic
+ /// is being emitted. \p DLoc is the location information to use in the
+ /// diagnostic. If line table information is available, the diagnostic
+ /// will include the source code location. \p Msg is the message to show.
+ /// Note that this class does not copy this message, so this reference
+ /// must be valid for the whole life time of the diagnostic.
+ DiagnosticInfoOptimizationRemark(const char *PassName, const Function &Fn,
+ const DebugLoc &DLoc, const Twine &Msg)
+ : DiagnosticInfo(DK_OptimizationRemark, DS_Remark), PassName(PassName),
+ Fn(Fn), DLoc(DLoc), Msg(Msg) {}
+
+ /// \see DiagnosticInfo::print.
+ void print(DiagnosticPrinter &DP) const override;
+
+ /// Hand rolled RTTI.
+ static bool classof(const DiagnosticInfo *DI) {
+ return DI->getKind() == DK_OptimizationRemark;
+ }
+
+ /// Return true if location information is available for this diagnostic.
+ bool isLocationAvailable() const;
+
+ /// Return a string with the location information for this diagnostic
+ /// in the format "file:line:col". If location information is not available,
+ /// it returns "<unknown>:0:0".
+ const StringRef getLocationStr() const;
+
+ /// Return location information for this diagnostic in three parts:
+ /// the source file name, line number and column.
+ void getLocation(StringRef *Filename, unsigned *Line, unsigned *Column) const;
+
+ const char *getPassName() const { return PassName; }
+ const Function &getFunction() const { return Fn; }
+ const DebugLoc &getDebugLoc() const { return DLoc; }
+ const Twine &getMsg() const { return Msg; }
+
+private:
+ /// Name of the pass that triggers this report. If this matches the
+ /// regular expression given in -Rpass=regexp, then the remark will
+ /// be emitted.
+ const char *PassName;
+
+ /// Function where this diagnostic is triggered.
+ const Function &Fn;
+
+ /// Debug location where this diagnostic is triggered.
+ const DebugLoc &DLoc;
+
+ /// Message to report.
+ const Twine &Msg;
+};
+
} // End namespace llvm
#endif
diff --git a/include/llvm/IR/LLVMContext.h b/include/llvm/IR/LLVMContext.h
index ae4859aacc..5c698f81de 100644
--- a/include/llvm/IR/LLVMContext.h
+++ b/include/llvm/IR/LLVMContext.h
@@ -29,6 +29,8 @@ class Module;
class SMDiagnostic;
class DiagnosticInfo;
template <typename T> class SmallVectorImpl;
+class Function;
+class DebugLoc;
/// This is an important class for using LLVM in a threaded context. It
/// (opaquely) owns and manages the core "global" data of LLVM's core
@@ -125,6 +127,15 @@ public:
void emitError(const Instruction *I, const Twine &ErrorStr);
void emitError(const Twine &ErrorStr);
+ /// emitOptimizationRemark - Emit an optimization remark message. \p PassName
+ /// is the name of the pass emitting the message. If -Rpass= is given
+ /// and \p PassName matches the regular expression in -Rpass, then the
+ /// remark will be emitted. \p Fn is the function triggering the remark,
+ /// \p DLoc is the debug location where the diagnostic is generated.
+ /// \p Msg is the message string to use.
+ void emitOptimizationRemark(const char *PassName, const Function &Fn,
+ const DebugLoc &DLoc, const Twine &Msg);
+
private:
LLVMContext(LLVMContext&) LLVM_DELETED_FUNCTION;
void operator=(LLVMContext&) LLVM_DELETED_FUNCTION;