never executed always true always false
1 module GHC.CmmToAsm.CFG.Weight
2 ( Weights (..)
3 , defaultWeights
4 , parseWeights
5 )
6 where
7
8 import GHC.Prelude
9 import GHC.Utils.Panic
10
11 -- | Edge weights to use when generating a CFG from CMM
12 data Weights = Weights
13 { uncondWeight :: Int
14 , condBranchWeight :: Int
15 , switchWeight :: Int
16 , callWeight :: Int
17 , likelyCondWeight :: Int
18 , unlikelyCondWeight :: Int
19 , infoTablePenalty :: Int
20 , backEdgeBonus :: Int
21 }
22
23 -- | Default edge weights
24 defaultWeights :: Weights
25 defaultWeights = Weights
26 { uncondWeight = 1000
27 , condBranchWeight = 800
28 , switchWeight = 1
29 , callWeight = -10
30 , likelyCondWeight = 900
31 , unlikelyCondWeight = 300
32 , infoTablePenalty = 300
33 , backEdgeBonus = 400
34 }
35
36 parseWeights :: String -> Weights -> Weights
37 parseWeights s oldWeights =
38 foldl' (\cfg (n,v) -> update n v cfg) oldWeights assignments
39 where
40 assignments = map assignment $ settings s
41 update "uncondWeight" n w =
42 w {uncondWeight = n}
43 update "condBranchWeight" n w =
44 w {condBranchWeight = n}
45 update "switchWeight" n w =
46 w {switchWeight = n}
47 update "callWeight" n w =
48 w {callWeight = n}
49 update "likelyCondWeight" n w =
50 w {likelyCondWeight = n}
51 update "unlikelyCondWeight" n w =
52 w {unlikelyCondWeight = n}
53 update "infoTablePenalty" n w =
54 w {infoTablePenalty = n}
55 update "backEdgeBonus" n w =
56 w {backEdgeBonus = n}
57 update other _ _
58 = panic $ other ++
59 " is not a CFG weight parameter. " ++
60 exampleString
61 settings s
62 | (s1,rest) <- break (== ',') s
63 , null rest
64 = [s1]
65 | (s1,rest) <- break (== ',') s
66 = s1 : settings (drop 1 rest)
67
68 assignment as
69 | (name, _:val) <- break (== '=') as
70 = (name,read val)
71 | otherwise
72 = panic $ "Invalid CFG weight parameters." ++ exampleString
73
74 exampleString = "Example parameters: uncondWeight=1000," ++
75 "condBranchWeight=800,switchWeight=0,callWeight=300" ++
76 ",likelyCondWeight=900,unlikelyCondWeight=300" ++
77 ",infoTablePenalty=300,backEdgeBonus=400"
78