1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00

[Guards] Add branch metadata when lowering

Guards are expected to basically never fail.  Reflect this in the branch
probabilities in their lowered form.

llvm-svn: 269791
This commit is contained in:
Sanjoy Das 2016-05-17 17:51:19 +00:00
parent 92221742de
commit 6c603c44d6
2 changed files with 17 additions and 5 deletions

View File

@ -21,12 +21,18 @@
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/MDBuilder.h"
#include "llvm/IR/Module.h"
#include "llvm/Pass.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
using namespace llvm;
static cl::opt<uint32_t> LikelyBranchWeight(
"guards-likely-branch-weight", cl::Hidden, cl::init(1 << 20),
cl::desc("The probability of a guard failing is assumed to be the "
"reciprocal of this value (default = 1 << 20)"));
namespace {
struct LowerGuardIntrinsic : public FunctionPass {
static char ID;
@ -59,6 +65,10 @@ static void MakeGuardControlFlowExplicit(Function *DeoptIntrinsic,
if (auto *MD = CI->getMetadata(LLVMContext::MD_make_implicit))
CheckBI->setMetadata(LLVMContext::MD_make_implicit, MD);
MDBuilder MDB(CI->getContext());
CheckBI->setMetadata(LLVMContext::MD_prof,
MDB.createBranchWeights(LikelyBranchWeight, 1));
IRBuilder<> B(DeoptBlockTerm);
auto *DeoptCall = B.CreateCall(DeoptIntrinsic, Args, {DeoptOB}, "");

View File

@ -9,7 +9,7 @@ define i8 @f_basic(i1* %c_ptr) {
call void(i1, ...) @llvm.experimental.guard(i1 %c, i32 1) [ "deopt"(i32 1) ]
ret i8 5
; CHECK: br i1 %c, label %guarded, label %deopt
; CHECK: br i1 %c, label %guarded, label %deopt, !prof !0
; CHECK: deopt:
; CHECK-NEXT: %deoptcall = call i8 (...) @llvm.experimental.deoptimize.i8(i32 1) [ "deopt"(i32 1) ]
; CHECK-NEXT: ret i8 %deoptcall
@ -24,7 +24,7 @@ define void @f_void_return_ty(i1* %c_ptr) {
call void(i1, ...) @llvm.experimental.guard(i1 %c, i32 1) [ "deopt"() ]
ret void
; CHECK: br i1 %c, label %guarded, label %deopt
; CHECK: br i1 %c, label %guarded, label %deopt, !prof !0
; CHECK: deopt:
; CHECK-NEXT: call void (...) @llvm.experimental.deoptimize.isVoid(i32 1) [ "deopt"() ]
; CHECK-NEXT: ret void
@ -39,7 +39,7 @@ define void @f_multiple_args(i1* %c_ptr) {
call void(i1, ...) @llvm.experimental.guard(i1 %c, i32 1, i32 2, double 500.0) [ "deopt"(i32 2, i32 3) ]
ret void
; CHECK: br i1 %c, label %guarded, label %deopt
; CHECK: br i1 %c, label %guarded, label %deopt, !prof !0
; CHECK: deopt:
; CHECK-NEXT: call void (...) @llvm.experimental.deoptimize.isVoid(i32 1, i32 2, double 5.000000e+02) [ "deopt"(i32 2, i32 3) ]
; CHECK-NEXT: ret void
@ -53,7 +53,7 @@ define i32 @f_zero_args(i1* %c_ptr) {
call void(i1, ...) @llvm.experimental.guard(i1 %c) [ "deopt"(i32 2, i32 3) ]
ret i32 500
; CHECK: br i1 %c, label %guarded, label %deopt
; CHECK: br i1 %c, label %guarded, label %deopt, !prof !0
; CHECK: deopt:
; CHECK-NEXT: %deoptcall = call i32 (...) @llvm.experimental.deoptimize.i32() [ "deopt"(i32 2, i32 3) ]
; CHECK-NEXT: ret i32 %deoptcall
@ -63,7 +63,7 @@ define i32 @f_zero_args(i1* %c_ptr) {
define i8 @f_with_make_implicit_md(i32* %ptr) {
; CHECK-LABEL: @f_with_make_implicit_md(
; CHECK: br i1 %notNull, label %guarded, label %deopt, !make.implicit !0
; CHECK: br i1 %notNull, label %guarded, label %deopt, !prof !0, !make.implicit !1
; CHECK: deopt:
; CHECK-NEXT: %deoptcall = call i8 (...) @llvm.experimental.deoptimize.i8(i32 1) [ "deopt"(i32 1) ]
; CHECK-NEXT: ret i8 %deoptcall
@ -72,3 +72,5 @@ define i8 @f_with_make_implicit_md(i32* %ptr) {
call void(i1, ...) @llvm.experimental.guard(i1 %notNull, i32 1) [ "deopt"(i32 1) ], !make.implicit !{}
ret i8 5
}
!0 = !{!"branch_weights", i32 1048576, i32 1}