Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MemProf] Basic metadata support and verification
Add basic support for the MemProf metadata (!memprof and !callsite) which was initially described in "RFC: IR metadata format for MemProf" (https://discourse.llvm.org/t/rfc-ir-metadata-format-for-memprof/59165). The bulk of the patch is verification support, along with some tests. There are a couple of changes to the format described in the original RFC: Initial measurements suggested that a tree format for the stack ids in the contexts would be more efficient, but subsequent evaluation with large applications showed that in fact the cost of the additional metadata nodes required by this deduplication scheme overwhelmed the benefit from sharing stack id nodes. Therefore, the implementation here and in follow on patches utilizes a simpler scheme of lists of stack id integers in the memprof profile contexts and callsite metadata. The follow on matching patch employs context trimming optimizations to reduce the cost. Secondly, instead of verbosely listing all profiled fields in each profiled context (memory info block or MIB), and deferring the interpretation of the profile data, the profile data is evaluated and converted into string tags specifying the behavior (e.g. "cold") during profile matching. This reduces the verbosity of the profile metadata, and allows additional context trimming optimizations. As a result, the named metadata schema description is also no longer needed. Differential Revision: https://reviews.llvm.org/D128141
- Loading branch information
1 parent
3040272
commit 0174f55
Showing
4 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
; Test that incorrect memprof and callsite metadata fail verification. | ||
; RUN: not llvm-as -disable-output < %s 2>&1 | FileCheck %s | ||
|
||
define i32* @test1() { | ||
entry: | ||
%call1 = call noalias dereferenceable_or_null(40) i8* @malloc(i64 noundef 40), !memprof !0 | ||
%call2 = call noalias dereferenceable_or_null(40) i8* @malloc(i64 noundef 40), !memprof !1 | ||
%call3 = call noalias dereferenceable_or_null(40) i8* @malloc(i64 noundef 40), !memprof !3 | ||
%call4 = call noalias dereferenceable_or_null(40) i8* @malloc(i64 noundef 40), !memprof !5 | ||
%call5 = call noalias dereferenceable_or_null(40) i8* @malloc(i64 noundef 40), !memprof !7, !callsite !9 | ||
%0 = bitcast i8* %call5 to i32* | ||
ret i32* %0 | ||
} | ||
|
||
define i32* @test2() { | ||
entry: | ||
%call = call noundef i32* @test1(), !callsite !10 | ||
ret i32* %call | ||
} | ||
|
||
define i32* @test3() { | ||
entry: | ||
%call = call noundef i32* @test2(), !callsite !11 | ||
ret i32* %call | ||
} | ||
|
||
define void @wronginsttype() { | ||
%1 = add i32 0, 1, !memprof !0, !callsite !9 | ||
ret void | ||
} | ||
|
||
declare dso_local noalias noundef i8* @malloc(i64 noundef) | ||
|
||
; CHECK: !memprof annotations should have at least 1 metadata operand (MemInfoBlock) | ||
!0 = !{} | ||
!1 = !{!2} | ||
; CHECK: !memprof MemInfoBlock first operand should not be null | ||
!2 = !{null, !"cold"} | ||
!3 = !{!4} | ||
; CHECK: !memprof MemInfoBlock first operand should be an MDNode | ||
!4 = !{i64 0, !"cold"} | ||
!5 = !{!6} | ||
; CHECK: Each !memprof MemInfoBlock should have at least 2 operands | ||
!6 = !{i64 0} | ||
!7 = !{!8} | ||
; CHECK: call stack metadata should have at least 1 operand | ||
; CHECK: Not all !memprof MemInfoBlock operands 1 to N are MDString | ||
!8 = !{!0, !"default", i64 0} | ||
!9 = !{i64 123} | ||
; CHECK: call stack metadata operand should be constant integer | ||
!10 = !{!"wrongtype"} | ||
!11 = !{i64 789, i64 678} | ||
|
||
; Errors from annotating incorrect instruction type in @wronginsttype. | ||
; CHECK: !memprof metadata should only exist on calls | ||
; CHECK: !callsite metadata should only exist on calls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
; Test that well-formed memprof and callsite metadata pass verification. | ||
; RUN: llvm-as -disable-output < %s 2>&1 | ||
|
||
define i32* @test1() { | ||
entry: | ||
%call = call noalias dereferenceable_or_null(40) i8* @malloc(i64 noundef 40), !memprof !0, !callsite !5 | ||
%0 = bitcast i8* %call to i32* | ||
ret i32* %0 | ||
} | ||
|
||
define i32* @test2() { | ||
entry: | ||
%call = call noundef i32* @test1(), !callsite !6 | ||
ret i32* %call | ||
} | ||
|
||
define i32* @test3() { | ||
entry: | ||
%call = call noundef i32* @test1(), !callsite !7 | ||
ret i32* %call | ||
} | ||
|
||
declare dso_local noalias noundef i8* @malloc(i64 noundef) | ||
|
||
!0 = !{!1, !3} | ||
; !memprof metadata should be able to support an arbitrary list of string tags. | ||
!1 = !{!2, !"default", !"tag2"} | ||
!2 = !{i64 123, i64 456} | ||
!3 = !{!4, !"cold", !"tag3", !"tag4"} | ||
!4 = !{i64 123, i64 789, i64 678} | ||
!5 = !{i64 123} | ||
!6 = !{i64 456} | ||
; Inlined callsites will have more than one call stack id. | ||
!7 = !{i64 789, i64 678} |