[llvm] r286169 - [OptDiag, opt-viewer] Save callee's location and display as link
Adam Nemet via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 7 14:41:14 PST 2016
Author: anemet
Date: Mon Nov 7 16:41:13 2016
New Revision: 286169
URL: http://llvm.org/viewvc/llvm-project?rev=286169&view=rev
Log:
[OptDiag, opt-viewer] Save callee's location and display as link
With this we get a new field in the YAML record if the value being
streamed out has a debug location. For examples, please see the changes
to the tests.
This is then used in opt-viewer to display a link for the callee
function in the inlining remarks.
Differential Revision: https://reviews.llvm.org/D26366
Modified:
llvm/trunk/include/llvm/IR/DiagnosticInfo.h
llvm/trunk/lib/Analysis/OptimizationDiagnosticInfo.cpp
llvm/trunk/lib/IR/DiagnosticInfo.cpp
llvm/trunk/test/Transforms/Inline/optimization-remarks-passed-yaml.ll
llvm/trunk/test/Transforms/Inline/optimization-remarks-yaml.ll
llvm/trunk/utils/opt-viewer/opt-viewer.py
Modified: llvm/trunk/include/llvm/IR/DiagnosticInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DiagnosticInfo.h?rev=286169&r1=286168&r2=286169&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DiagnosticInfo.h (original)
+++ llvm/trunk/include/llvm/IR/DiagnosticInfo.h Mon Nov 7 16:41:13 2016
@@ -385,6 +385,8 @@ public:
struct Argument {
StringRef Key;
std::string Val;
+ // If set, the debug location corresponding to the value.
+ DebugLoc DLoc;
explicit Argument(StringRef Str = "") : Key("String"), Val(Str) {}
Argument(StringRef Key, Value *V);
Modified: llvm/trunk/lib/Analysis/OptimizationDiagnosticInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/OptimizationDiagnosticInfo.cpp?rev=286169&r1=286168&r2=286169&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/OptimizationDiagnosticInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/OptimizationDiagnosticInfo.cpp Mon Nov 7 16:41:13 2016
@@ -115,6 +115,8 @@ template <> struct MappingTraits<Diagnos
static void mapping(IO &io, DiagnosticInfoOptimizationBase::Argument &A) {
assert(io.outputting() && "input not yet implemented");
io.mapRequired(A.Key.data(), A.Val);
+ if (A.DLoc)
+ io.mapOptional("DebugLoc", A.DLoc);
}
};
Modified: llvm/trunk/lib/IR/DiagnosticInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DiagnosticInfo.cpp?rev=286169&r1=286168&r2=286169&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DiagnosticInfo.cpp (original)
+++ llvm/trunk/lib/IR/DiagnosticInfo.cpp Mon Nov 7 16:41:13 2016
@@ -171,7 +171,14 @@ const std::string DiagnosticInfoWithDebu
return (Filename + ":" + Twine(Line) + ":" + Twine(Column)).str();
}
DiagnosticInfoOptimizationBase::Argument::Argument(StringRef Key, Value *V)
- : Key(Key), Val(GlobalValue::getRealLinkageName(V->getName())) {}
+ : Key(Key), Val(GlobalValue::getRealLinkageName(V->getName())) {
+ if (auto *F = dyn_cast<Function>(V)) {
+ if (DISubprogram *SP = F->getSubprogram())
+ DLoc = DebugLoc::get(SP->getScopeLine(), 0, SP);
+ }
+ else if (auto *I = dyn_cast<Instruction>(V))
+ DLoc = I->getDebugLoc();
+}
DiagnosticInfoOptimizationBase::Argument::Argument(StringRef Key, int N)
: Key(Key), Val(itostr(N)) {}
Modified: llvm/trunk/test/Transforms/Inline/optimization-remarks-passed-yaml.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Inline/optimization-remarks-passed-yaml.ll?rev=286169&r1=286168&r2=286169&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/Inline/optimization-remarks-passed-yaml.ll (original)
+++ llvm/trunk/test/Transforms/Inline/optimization-remarks-passed-yaml.ll Mon Nov 7 16:41:13 2016
@@ -23,8 +23,10 @@
; YAML-NEXT: Hotness: 30
; YAML-NEXT: Args:
; YAML-NEXT: - Callee: foo
+; YAML-NEXT: DebugLoc: { File: /tmp/s.c, Line: 1, Column: 0 }
; YAML-NEXT: - String: ' can be inlined into '
; YAML-NEXT: - Caller: bar
+; YAML-NEXT: DebugLoc: { File: /tmp/s.c, Line: 3, Column: 0 }
; YAML-NEXT: - String: ' with cost='
; YAML-NEXT: - Cost: '{{[0-9]+}}'
; YAML-NEXT: - String: ' (threshold='
@@ -39,8 +41,10 @@
; YAML-NEXT: Hotness: 30
; YAML-NEXT: Args:
; YAML-NEXT: - Callee: foo
+; YAML-NEXT: DebugLoc: { File: /tmp/s.c, Line: 1, Column: 0 }
; YAML-NEXT: - String: ' inlined into '
; YAML-NEXT: - Caller: bar
+; YAML-NEXT: DebugLoc: { File: /tmp/s.c, Line: 3, Column: 0 }
; YAML-NEXT: ...
; ModuleID = '/tmp/s.c'
Modified: llvm/trunk/test/Transforms/Inline/optimization-remarks-yaml.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Inline/optimization-remarks-yaml.ll?rev=286169&r1=286168&r2=286169&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/Inline/optimization-remarks-yaml.ll (original)
+++ llvm/trunk/test/Transforms/Inline/optimization-remarks-yaml.ll Mon Nov 7 16:41:13 2016
@@ -26,6 +26,7 @@
; YAML-NEXT: - Callee: foo
; YAML-NEXT: - String: ' will not be inlined into '
; YAML-NEXT: - Caller: baz
+; YAML-NEXT: DebugLoc: { File: /tmp/s.c, Line: 4, Column: 0 }
; YAML-NEXT: - String: ' because its definition is unavailable'
; YAML-NEXT: ...
; YAML-NEXT: --- !Missed
@@ -38,6 +39,7 @@
; YAML-NEXT: - Callee: bar
; YAML-NEXT: - String: ' will not be inlined into '
; YAML-NEXT: - Caller: baz
+; YAML-NEXT: DebugLoc: { File: /tmp/s.c, Line: 4, Column: 0 }
; YAML-NEXT: - String: ' because its definition is unavailable'
; YAML-NEXT: ...
Modified: llvm/trunk/utils/opt-viewer/opt-viewer.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/opt-viewer/opt-viewer.py?rev=286169&r1=286168&r2=286169&view=diff
==============================================================================
--- llvm/trunk/utils/opt-viewer/opt-viewer.py (original)
+++ llvm/trunk/utils/opt-viewer/opt-viewer.py Mon Nov 7 16:41:13 2016
@@ -46,20 +46,36 @@ class Remark(yaml.YAMLObject):
def DemangledFunctionName(self):
return demangle(self.Function)
+ @classmethod
+ def make_link(cls, File, Line):
+ return "{}#L{}".format(SourceFileRenderer.html_file_name(File), Line)
+
@property
def Link(self):
- return "{}#L{}".format(SourceFileRenderer.html_file_name(self.File), self.Line)
+ return Remark.make_link(self.File, self.Line)
+
+ def getArgString(self, mapping):
+ mapping = mapping.copy()
+ dl = mapping.get('DebugLoc')
+ if dl:
+ del mapping['DebugLoc']
+
+ assert(len(mapping) == 1)
+ (key, value) = mapping.items()[0]
+
+ if key == 'Caller' or key == 'Callee':
+ value = demangle(value)
- def getArgString(self, pair):
- if pair[0] == 'Callee' or pair[0] == 'Caller':
- return demangle(pair[1])
- return pair[1]
+ if dl and key != 'Caller':
+ return "<a href={}>{}</a>".format(
+ Remark.make_link(dl['File'], dl['Line']), value)
+ else:
+ return value
@property
def message(self):
- # Args is a list of mappings (dictionaries) with each dictionary with
- # exactly one key-value pair.
- values = [self.getArgString(mapping.items()[0]) for mapping in self.Args]
+ # Args is a list of mappings (dictionaries)
+ values = [self.getArgString(mapping) for mapping in self.Args]
return "".join(values)
@property
More information about the llvm-commits
mailing list