Files
clang-p2996/mlir/test/Target/LLVMIR/Import/metadata-profiling.ll
Tobias Gysi 10fa27704b [mlir][llvm] Add branch weight op interface
This revision adds a branch weight op interface for the call / branch
operations that support branch weights. It can be used in the LLVM IR
import and export to simplify the branch weight conversion. An
additional mapping between call operations and instructions ensures
the actual conversion can be done in the module translation itself,
rather than in the dialect translation interface. It also has the
benefit that downstream users can amend custom metadata to the call
operation during the export to LLVM IR.

Reviewed By: zero9178, definelicht

Differential Revision: https://reviews.llvm.org/D155702
2023-07-20 10:46:04 +00:00

69 lines
1.4 KiB
LLVM

; RUN: mlir-translate -import-llvm -split-input-file %s | FileCheck %s
; CHECK-LABEL: @cond_br
define i64 @cond_br(i1 %arg1, i64 %arg2) {
entry:
; CHECK: llvm.cond_br
; CHECK-SAME: weights([0, 3])
br i1 %arg1, label %bb1, label %bb2, !prof !0
bb1:
ret i64 %arg2
bb2:
ret i64 %arg2
}
!0 = !{!"branch_weights", i32 0, i32 3}
; // -----
; CHECK-LABEL: @simple_switch(
define i32 @simple_switch(i32 %arg1) {
; CHECK: llvm.switch
; CHECK: {branch_weights = array<i32: 42, 3, 5>}
switch i32 %arg1, label %bbd [
i32 0, label %bb1
i32 9, label %bb2
], !prof !0
bb1:
ret i32 %arg1
bb2:
ret i32 %arg1
bbd:
ret i32 %arg1
}
!0 = !{!"branch_weights", i32 42, i32 3, i32 5}
; // -----
; CHECK: llvm.func @fn()
declare void @fn()
; CHECK-LABEL: @call_branch_weights
define void @call_branch_weights() {
; CHECK: llvm.call @fn() {branch_weights = array<i32: 42>}
call void @fn(), !prof !0
ret void
}
!0 = !{!"branch_weights", i32 42}
; // -----
declare void @foo()
declare i32 @__gxx_personality_v0(...)
; CHECK-LABEL: @invoke_branch_weights
define i32 @invoke_branch_weights() personality ptr @__gxx_personality_v0 {
; CHECK: llvm.invoke @foo() to ^bb2 unwind ^bb1 {branch_weights = array<i32: 42, 99>} : () -> ()
invoke void @foo() to label %bb2 unwind label %bb1, !prof !0
bb1:
%1 = landingpad { ptr, i32 } cleanup
br label %bb2
bb2:
ret i32 1
}
!0 = !{!"branch_weights", i32 42, i32 99}