From 939a7d6367501d43be73f4e41db7395af1194989 Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Mon, 21 Sep 2015 09:14:33 +0100 Subject: Annotate CmmBranch with an optional likely target Summary: This allows the code generator to give hints to later code generation steps about which branch is most likely to be taken. Right now it is only taken into account in one place: a special case in CmmContFlowOpt that swapped branches over to maximise the chance of fallthrough, which is now disabled when there is a likelihood setting. Test Plan: validate Reviewers: austin, simonpj, bgamari, ezyang, tibbe Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1273 --- compiler/codeGen/StgCmmExpr.hs | 3 ++- compiler/codeGen/StgCmmLayout.hs | 5 +++-- compiler/codeGen/StgCmmMonad.hs | 6 +++--- compiler/codeGen/StgCmmUtils.hs | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) (limited to 'compiler/codeGen') diff --git a/compiler/codeGen/StgCmmExpr.hs b/compiler/codeGen/StgCmmExpr.hs index 747f71a630..29db20a765 100644 --- a/compiler/codeGen/StgCmmExpr.hs +++ b/compiler/codeGen/StgCmmExpr.hs @@ -876,7 +876,8 @@ emitEnter fun = do ; tscope <- getTickScope ; emit $ copyout <*> - mkCbranch (cmmIsTagged dflags (CmmReg nodeReg)) lret lcall <*> + mkCbranch (cmmIsTagged dflags (CmmReg nodeReg)) + lret lcall Nothing <*> outOfLine lcall (the_call,tscope) <*> mkLabel lret tscope <*> copyin diff --git a/compiler/codeGen/StgCmmLayout.hs b/compiler/codeGen/StgCmmLayout.hs index c3d8873cfb..593dd6cc18 100644 --- a/compiler/codeGen/StgCmmLayout.hs +++ b/compiler/codeGen/StgCmmLayout.hs @@ -226,9 +226,10 @@ slowCall fun stg_args (mkIntExpr dflags n_args) tscope <- getTickScope - emit (mkCbranch (cmmIsTagged dflags funv) is_tagged_lbl slow_lbl + emit (mkCbranch (cmmIsTagged dflags funv) + is_tagged_lbl slow_lbl (Just True) <*> mkLabel is_tagged_lbl tscope - <*> mkCbranch correct_arity fast_lbl slow_lbl + <*> mkCbranch correct_arity fast_lbl slow_lbl (Just True) <*> mkLabel fast_lbl tscope <*> fast_code <*> mkBranch end_lbl diff --git a/compiler/codeGen/StgCmmMonad.hs b/compiler/codeGen/StgCmmMonad.hs index f7a13f9c98..1acf31b327 100644 --- a/compiler/codeGen/StgCmmMonad.hs +++ b/compiler/codeGen/StgCmmMonad.hs @@ -831,7 +831,7 @@ mkCmmIfThenElse e tbranch fbranch = do endif <- newLabelC tid <- newLabelC fid <- newLabelC - return $ catAGraphs [ mkCbranch e tid fid + return $ catAGraphs [ mkCbranch e tid fid Nothing , mkLabel tid tscp, tbranch, mkBranch endif , mkLabel fid tscp, fbranch, mkLabel endif tscp ] @@ -839,14 +839,14 @@ mkCmmIfGoto :: CmmExpr -> BlockId -> FCode CmmAGraph mkCmmIfGoto e tid = do endif <- newLabelC tscp <- getTickScope - return $ catAGraphs [ mkCbranch e tid endif, mkLabel endif tscp ] + return $ catAGraphs [ mkCbranch e tid endif Nothing, mkLabel endif tscp ] mkCmmIfThen :: CmmExpr -> CmmAGraph -> FCode CmmAGraph mkCmmIfThen e tbranch = do endif <- newLabelC tid <- newLabelC tscp <- getTickScope - return $ catAGraphs [ mkCbranch e tid endif + return $ catAGraphs [ mkCbranch e tid endif Nothing , mkLabel tid tscp, tbranch, mkLabel endif tscp ] diff --git a/compiler/codeGen/StgCmmUtils.hs b/compiler/codeGen/StgCmmUtils.hs index db771c2f9a..a03625262c 100644 --- a/compiler/codeGen/StgCmmUtils.hs +++ b/compiler/codeGen/StgCmmUtils.hs @@ -558,7 +558,7 @@ mk_float_switch :: Width -> CmmExpr -> BlockId -> FCode CmmAGraph mk_float_switch rep scrut deflt _bounds [(lit,blk)] = do dflags <- getDynFlags - return $ mkCbranch (cond dflags) deflt blk + return $ mkCbranch (cond dflags) deflt blk Nothing where cond dflags = CmmMachOp ne [scrut, CmmLit cmm_lit] where -- cgit v1.2.1