16d1237c2363a79c9150da27dc106f9a39cc9113
[ghc.git] / compiler / llvmGen / LlvmCodeGen / Regs.hs
1 --------------------------------------------------------------------------------
2 -- | Deal with Cmm registers
3 --
4
5 module LlvmCodeGen.Regs (
6 lmGlobalRegArg, lmGlobalRegVar, alwaysLive,
7 stgTBAA, baseN, stackN, heapN, rxN, otherN, tbaa, getTBAA
8 ) where
9
10 #include "HsVersions.h"
11
12 import Llvm
13
14 import CmmExpr
15 import DynFlags
16 import FastString
17 import Outputable ( panic )
18 import Unique
19
20 -- | Get the LlvmVar function variable storing the real register
21 lmGlobalRegVar :: DynFlags -> GlobalReg -> LlvmVar
22 lmGlobalRegVar dflags = pVarLift . lmGlobalReg dflags "_Var"
23
24 -- | Get the LlvmVar function argument storing the real register
25 lmGlobalRegArg :: DynFlags -> GlobalReg -> LlvmVar
26 lmGlobalRegArg dflags = lmGlobalReg dflags "_Arg"
27
28 {- Need to make sure the names here can't conflict with the unique generated
29 names. Uniques generated names containing only base62 chars. So using say
30 the '_' char guarantees this.
31 -}
32 lmGlobalReg :: DynFlags -> String -> GlobalReg -> LlvmVar
33 lmGlobalReg dflags suf reg
34 = case reg of
35 BaseReg -> ptrGlobal $ "Base" ++ suf
36 Sp -> ptrGlobal $ "Sp" ++ suf
37 Hp -> ptrGlobal $ "Hp" ++ suf
38 VanillaReg 1 _ -> wordGlobal $ "R1" ++ suf
39 VanillaReg 2 _ -> wordGlobal $ "R2" ++ suf
40 VanillaReg 3 _ -> wordGlobal $ "R3" ++ suf
41 VanillaReg 4 _ -> wordGlobal $ "R4" ++ suf
42 VanillaReg 5 _ -> wordGlobal $ "R5" ++ suf
43 VanillaReg 6 _ -> wordGlobal $ "R6" ++ suf
44 VanillaReg 7 _ -> wordGlobal $ "R7" ++ suf
45 VanillaReg 8 _ -> wordGlobal $ "R8" ++ suf
46 SpLim -> wordGlobal $ "SpLim" ++ suf
47 FloatReg 1 -> floatGlobal $"F1" ++ suf
48 FloatReg 2 -> floatGlobal $"F2" ++ suf
49 FloatReg 3 -> floatGlobal $"F3" ++ suf
50 FloatReg 4 -> floatGlobal $"F4" ++ suf
51 FloatReg 5 -> floatGlobal $"F5" ++ suf
52 FloatReg 6 -> floatGlobal $"F6" ++ suf
53 DoubleReg 1 -> doubleGlobal $ "D1" ++ suf
54 DoubleReg 2 -> doubleGlobal $ "D2" ++ suf
55 DoubleReg 3 -> doubleGlobal $ "D3" ++ suf
56 DoubleReg 4 -> doubleGlobal $ "D4" ++ suf
57 DoubleReg 5 -> doubleGlobal $ "D5" ++ suf
58 DoubleReg 6 -> doubleGlobal $ "D6" ++ suf
59 XmmReg 1 -> xmmGlobal $ "XMM1" ++ suf
60 XmmReg 2 -> xmmGlobal $ "XMM2" ++ suf
61 XmmReg 3 -> xmmGlobal $ "XMM3" ++ suf
62 XmmReg 4 -> xmmGlobal $ "XMM4" ++ suf
63 XmmReg 5 -> xmmGlobal $ "XMM5" ++ suf
64 XmmReg 6 -> xmmGlobal $ "XMM6" ++ suf
65 YmmReg 1 -> ymmGlobal $ "YMM1" ++ suf
66 YmmReg 2 -> ymmGlobal $ "YMM2" ++ suf
67 YmmReg 3 -> ymmGlobal $ "YMM3" ++ suf
68 YmmReg 4 -> ymmGlobal $ "YMM4" ++ suf
69 YmmReg 5 -> ymmGlobal $ "YMM5" ++ suf
70 YmmReg 6 -> ymmGlobal $ "YMM6" ++ suf
71 _other -> panic $ "LlvmCodeGen.Reg: GlobalReg (" ++ (show reg)
72 ++ ") not supported!"
73 -- LongReg, HpLim, CCSS, CurrentTSO, CurrentNusery, HpAlloc
74 -- EagerBlackholeInfo, GCEnter1, GCFun, BaseReg, PicBaseReg
75 where
76 wordGlobal name = LMNLocalVar (fsLit name) (llvmWord dflags)
77 ptrGlobal name = LMNLocalVar (fsLit name) (llvmWordPtr dflags)
78 floatGlobal name = LMNLocalVar (fsLit name) LMFloat
79 doubleGlobal name = LMNLocalVar (fsLit name) LMDouble
80 xmmGlobal name = LMNLocalVar (fsLit name) (LMVector 4 (LMInt 32))
81 ymmGlobal name = LMNLocalVar (fsLit name) (LMVector 8 (LMInt 32))
82
83 -- | A list of STG Registers that should always be considered alive
84 alwaysLive :: [GlobalReg]
85 alwaysLive = [BaseReg, Sp, Hp, SpLim, HpLim, node]
86
87 -- | STG Type Based Alias Analysis hierarchy
88 stgTBAA :: [(Unique, LMString, Maybe Unique)]
89 stgTBAA
90 = [ (topN, fsLit "top", Nothing)
91 , (stackN, fsLit "stack", Just topN)
92 , (heapN, fsLit "heap", Just topN)
93 , (rxN, fsLit "rx", Just heapN)
94 , (baseN, fsLit "base", Just topN)
95 -- FIX: Not 100% sure about 'others' place. Might need to be under 'heap'.
96 -- OR I think the big thing is Sp is never aliased, so might want
97 -- to change the hieracy to have Sp on its own branch that is never
98 -- aliased (e.g never use top as a TBAA node).
99 , (otherN, fsLit "other", Just topN)
100 ]
101
102 -- | Id values
103 topN, stackN, heapN, rxN, baseN, otherN :: Unique
104 topN = getUnique (fsLit "LlvmCodeGen.Regs.topN")
105 stackN = getUnique (fsLit "LlvmCodeGen.Regs.stackN")
106 heapN = getUnique (fsLit "LlvmCodeGen.Regs.heapN")
107 rxN = getUnique (fsLit "LlvmCodeGen.Regs.rxN")
108 baseN = getUnique (fsLit "LlvmCodeGen.Regs.baseN")
109 otherN = getUnique (fsLit "LlvmCodeGen.Regs.otherN")
110
111 -- | The TBAA metadata identifier
112 tbaa :: LMString
113 tbaa = fsLit "tbaa"
114
115 -- | Get the correct TBAA metadata information for this register type
116 getTBAA :: GlobalReg -> Unique
117 getTBAA BaseReg = baseN
118 getTBAA Sp = stackN
119 getTBAA Hp = heapN
120 getTBAA (VanillaReg _ _) = rxN
121 getTBAA _ = topN