{-# LANGUAGE CPP #-}
module LlvmCodeGen.Regs (
lmGlobalRegArg, lmGlobalRegVar, alwaysLive,
stgTBAA, baseN, stackN, heapN, rxN, topN, tbaa, getTBAA
) where
#include "HsVersions.h"
import GhcPrelude
import Llvm
import CmmExpr
import DynFlags
import FastString
import Outputable ( panic )
import Unique
lmGlobalRegVar :: DynFlags -> GlobalReg -> LlvmVar
lmGlobalRegVar :: DynFlags -> GlobalReg -> LlvmVar
lmGlobalRegVar DynFlags
dflags = LlvmVar -> LlvmVar
pVarLift (LlvmVar -> LlvmVar)
-> (GlobalReg -> LlvmVar) -> GlobalReg -> LlvmVar
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DynFlags -> String -> GlobalReg -> LlvmVar
lmGlobalReg DynFlags
dflags String
"_Var"
lmGlobalRegArg :: DynFlags -> GlobalReg -> LlvmVar
lmGlobalRegArg :: DynFlags -> GlobalReg -> LlvmVar
lmGlobalRegArg DynFlags
dflags = DynFlags -> String -> GlobalReg -> LlvmVar
lmGlobalReg DynFlags
dflags String
"_Arg"
lmGlobalReg :: DynFlags -> String -> GlobalReg -> LlvmVar
lmGlobalReg :: DynFlags -> String -> GlobalReg -> LlvmVar
lmGlobalReg DynFlags
dflags String
suf GlobalReg
reg
= case GlobalReg
reg of
GlobalReg
BaseReg -> String -> LlvmVar
ptrGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"Base" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
GlobalReg
Sp -> String -> LlvmVar
ptrGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"Sp" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
GlobalReg
Hp -> String -> LlvmVar
ptrGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"Hp" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
VanillaReg Int
1 VGcPtr
_ -> String -> LlvmVar
wordGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"R1" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
VanillaReg Int
2 VGcPtr
_ -> String -> LlvmVar
wordGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"R2" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
VanillaReg Int
3 VGcPtr
_ -> String -> LlvmVar
wordGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"R3" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
VanillaReg Int
4 VGcPtr
_ -> String -> LlvmVar
wordGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"R4" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
VanillaReg Int
5 VGcPtr
_ -> String -> LlvmVar
wordGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"R5" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
VanillaReg Int
6 VGcPtr
_ -> String -> LlvmVar
wordGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"R6" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
VanillaReg Int
7 VGcPtr
_ -> String -> LlvmVar
wordGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"R7" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
VanillaReg Int
8 VGcPtr
_ -> String -> LlvmVar
wordGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"R8" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
GlobalReg
SpLim -> String -> LlvmVar
wordGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"SpLim" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
FloatReg Int
1 -> String -> LlvmVar
floatGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$String
"F1" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
FloatReg Int
2 -> String -> LlvmVar
floatGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$String
"F2" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
FloatReg Int
3 -> String -> LlvmVar
floatGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$String
"F3" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
FloatReg Int
4 -> String -> LlvmVar
floatGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$String
"F4" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
FloatReg Int
5 -> String -> LlvmVar
floatGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$String
"F5" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
FloatReg Int
6 -> String -> LlvmVar
floatGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$String
"F6" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
DoubleReg Int
1 -> String -> LlvmVar
doubleGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"D1" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
DoubleReg Int
2 -> String -> LlvmVar
doubleGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"D2" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
DoubleReg Int
3 -> String -> LlvmVar
doubleGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"D3" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
DoubleReg Int
4 -> String -> LlvmVar
doubleGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"D4" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
DoubleReg Int
5 -> String -> LlvmVar
doubleGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"D5" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
DoubleReg Int
6 -> String -> LlvmVar
doubleGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"D6" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
XmmReg Int
1 -> String -> LlvmVar
xmmGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"XMM1" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
XmmReg Int
2 -> String -> LlvmVar
xmmGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"XMM2" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
XmmReg Int
3 -> String -> LlvmVar
xmmGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"XMM3" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
XmmReg Int
4 -> String -> LlvmVar
xmmGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"XMM4" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
XmmReg Int
5 -> String -> LlvmVar
xmmGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"XMM5" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
XmmReg Int
6 -> String -> LlvmVar
xmmGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"XMM6" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
YmmReg Int
1 -> String -> LlvmVar
ymmGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"YMM1" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
YmmReg Int
2 -> String -> LlvmVar
ymmGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"YMM2" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
YmmReg Int
3 -> String -> LlvmVar
ymmGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"YMM3" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
YmmReg Int
4 -> String -> LlvmVar
ymmGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"YMM4" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
YmmReg Int
5 -> String -> LlvmVar
ymmGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"YMM5" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
YmmReg Int
6 -> String -> LlvmVar
ymmGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"YMM6" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
ZmmReg Int
1 -> String -> LlvmVar
zmmGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"ZMM1" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
ZmmReg Int
2 -> String -> LlvmVar
zmmGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"ZMM2" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
ZmmReg Int
3 -> String -> LlvmVar
zmmGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"ZMM3" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
ZmmReg Int
4 -> String -> LlvmVar
zmmGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"ZMM4" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
ZmmReg Int
5 -> String -> LlvmVar
zmmGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"ZMM5" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
ZmmReg Int
6 -> String -> LlvmVar
zmmGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"ZMM6" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
GlobalReg
MachSp -> String -> LlvmVar
wordGlobal (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"MachSp" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suf
GlobalReg
_other -> String -> LlvmVar
forall a. String -> a
panic (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"LlvmCodeGen.Reg: GlobalReg (" String -> String -> String
forall a. [a] -> [a] -> [a]
++ (GlobalReg -> String
forall a. Show a => a -> String
show GlobalReg
reg)
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
") not supported!"
where
wordGlobal :: String -> LlvmVar
wordGlobal String
name = LMString -> LlvmType -> LlvmVar
LMNLocalVar (String -> LMString
fsLit String
name) (DynFlags -> LlvmType
llvmWord DynFlags
dflags)
ptrGlobal :: String -> LlvmVar
ptrGlobal String
name = LMString -> LlvmType -> LlvmVar
LMNLocalVar (String -> LMString
fsLit String
name) (DynFlags -> LlvmType
llvmWordPtr DynFlags
dflags)
floatGlobal :: String -> LlvmVar
floatGlobal String
name = LMString -> LlvmType -> LlvmVar
LMNLocalVar (String -> LMString
fsLit String
name) LlvmType
LMFloat
doubleGlobal :: String -> LlvmVar
doubleGlobal String
name = LMString -> LlvmType -> LlvmVar
LMNLocalVar (String -> LMString
fsLit String
name) LlvmType
LMDouble
xmmGlobal :: String -> LlvmVar
xmmGlobal String
name = LMString -> LlvmType -> LlvmVar
LMNLocalVar (String -> LMString
fsLit String
name) (Int -> LlvmType -> LlvmType
LMVector Int
4 (Int -> LlvmType
LMInt Int
32))
ymmGlobal :: String -> LlvmVar
ymmGlobal String
name = LMString -> LlvmType -> LlvmVar
LMNLocalVar (String -> LMString
fsLit String
name) (Int -> LlvmType -> LlvmType
LMVector Int
8 (Int -> LlvmType
LMInt Int
32))
zmmGlobal :: String -> LlvmVar
zmmGlobal String
name = LMString -> LlvmType -> LlvmVar
LMNLocalVar (String -> LMString
fsLit String
name) (Int -> LlvmType -> LlvmType
LMVector Int
16 (Int -> LlvmType
LMInt Int
32))
alwaysLive :: [GlobalReg]
alwaysLive :: [GlobalReg]
alwaysLive = [GlobalReg
BaseReg, GlobalReg
Sp, GlobalReg
Hp, GlobalReg
SpLim, GlobalReg
HpLim, GlobalReg
node]
stgTBAA :: [(Unique, LMString, Maybe Unique)]
stgTBAA :: [(Unique, LMString, Maybe Unique)]
stgTBAA
= [ (Unique
rootN, String -> LMString
fsLit String
"root", Maybe Unique
forall a. Maybe a
Nothing)
, (Unique
topN, String -> LMString
fsLit String
"top", Unique -> Maybe Unique
forall a. a -> Maybe a
Just Unique
rootN)
, (Unique
stackN, String -> LMString
fsLit String
"stack", Unique -> Maybe Unique
forall a. a -> Maybe a
Just Unique
topN)
, (Unique
heapN, String -> LMString
fsLit String
"heap", Unique -> Maybe Unique
forall a. a -> Maybe a
Just Unique
topN)
, (Unique
rxN, String -> LMString
fsLit String
"rx", Unique -> Maybe Unique
forall a. a -> Maybe a
Just Unique
heapN)
, (Unique
baseN, String -> LMString
fsLit String
"base", Unique -> Maybe Unique
forall a. a -> Maybe a
Just Unique
topN)
]
rootN, topN, stackN, heapN, rxN, baseN :: Unique
rootN :: Unique
rootN = LMString -> Unique
forall a. Uniquable a => a -> Unique
getUnique (String -> LMString
fsLit String
"LlvmCodeGen.Regs.rootN")
topN :: Unique
topN = LMString -> Unique
forall a. Uniquable a => a -> Unique
getUnique (String -> LMString
fsLit String
"LlvmCodeGen.Regs.topN")
stackN :: Unique
stackN = LMString -> Unique
forall a. Uniquable a => a -> Unique
getUnique (String -> LMString
fsLit String
"LlvmCodeGen.Regs.stackN")
heapN :: Unique
heapN = LMString -> Unique
forall a. Uniquable a => a -> Unique
getUnique (String -> LMString
fsLit String
"LlvmCodeGen.Regs.heapN")
rxN :: Unique
rxN = LMString -> Unique
forall a. Uniquable a => a -> Unique
getUnique (String -> LMString
fsLit String
"LlvmCodeGen.Regs.rxN")
baseN :: Unique
baseN = LMString -> Unique
forall a. Uniquable a => a -> Unique
getUnique (String -> LMString
fsLit String
"LlvmCodeGen.Regs.baseN")
tbaa :: LMString
tbaa :: LMString
tbaa = String -> LMString
fsLit String
"tbaa"
getTBAA :: GlobalReg -> Unique
getTBAA :: GlobalReg -> Unique
getTBAA GlobalReg
BaseReg = Unique
baseN
getTBAA GlobalReg
Sp = Unique
stackN
getTBAA GlobalReg
Hp = Unique
heapN
getTBAA (VanillaReg Int
_ VGcPtr
_) = Unique
rxN
getTBAA GlobalReg
_ = Unique
topN