@@ -16,6 +16,7 @@ use rustc_codegen_ssa::MemFlags;
1616use rustc_data_structures:: small_c_str:: SmallCStr ;
1717use rustc_hir:: def_id:: DefId ;
1818use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrs ;
19+ use rustc_middle:: mir:: ExpectKind ;
1920use rustc_middle:: ty:: layout:: {
2021 FnAbiError , FnAbiOfHelpers , FnAbiRequest , LayoutError , LayoutOfHelpers , TyAndLayout ,
2122} ;
@@ -202,42 +203,43 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
202203 cond : & ' ll Value ,
203204 then_llbb : & ' ll BasicBlock ,
204205 else_llbb : & ' ll BasicBlock ,
205- expect : ExpectKind ,
206+ expect : Option < ExpectKind > ,
206207 ) {
207208 // emit the branch instruction
208209 let n = unsafe { llvm:: LLVMBuildCondBr ( self . llbuilder , cond, then_llbb, else_llbb) } ;
209210
210211 // emit expectation metadata
211212 match expect {
212- ExpectKind :: None => { }
213- ExpectKind :: True | ExpectKind :: False => unsafe {
213+ Some ( ExpectKind :: True ) | Some ( ExpectKind :: False ) => unsafe {
214214 // Use weights 2000 and 1, which is what Clang uses
215215 let s = "branch_weights" ;
216+ let e = expect. unwrap ( ) == ExpectKind :: True ;
216217 let v = [
217218 llvm:: LLVMMDStringInContext (
218219 self . cx . llcx ,
219220 s. as_ptr ( ) as * const c_char ,
220221 s. len ( ) as c_uint ,
221222 ) ,
222223 // 'then' branch weight
223- self . cx . const_u32 ( if expect == ExpectKind :: True { 2000 } else { 1 } ) ,
224+ self . cx . const_u32 ( if e { 2000 } else { 1 } ) ,
224225 // 'else' branch weight
225- self . cx . const_u32 ( if expect == ExpectKind :: True { 1 } else { 2000 } ) ,
226+ self . cx . const_u32 ( if e { 1 } else { 2000 } ) ,
226227 ] ;
227228 llvm:: LLVMSetMetadata (
228229 n,
229230 llvm:: MD_prof as c_uint ,
230231 llvm:: LLVMMDNodeInContext ( self . cx . llcx , v. as_ptr ( ) , v. len ( ) as c_uint ) ,
231232 ) ;
232233 } ,
233- ExpectKind :: Unpredictable => unsafe {
234+ Some ( ExpectKind :: Unpredictable ) => unsafe {
234235 let v: [ & Value ; 0 ] = [ ] ;
235236 llvm:: LLVMSetMetadata (
236237 n,
237238 llvm:: MD_unpredictable as c_uint ,
238239 llvm:: LLVMMDNodeInContext ( self . cx . llcx , v. as_ptr ( ) , v. len ( ) as c_uint ) ,
239240 ) ;
240241 } ,
242+ None => { }
241243 }
242244 }
243245
0 commit comments