File tree Expand file tree Collapse file tree 8 files changed +32
-29
lines changed Expand file tree Collapse file tree 8 files changed +32
-29
lines changed Original file line number Diff line number Diff line change 1
- stack bench --benchmark-arguments ' --output=$benchmark.html'
1
+ stack bench grin --benchmark-arguments ' --output=$benchmark.html'
Original file line number Diff line number Diff line change @@ -68,10 +68,10 @@ main = do
68
68
putStrLn " * HPT *"
69
69
print . pretty $ computer
70
70
71
- putStrLn " * x86 64bit codegen *"
72
- print . CGX64. codeGen $ Program grin
71
+ -- putStrLn "* x86 64bit codegen *"
72
+ -- print . CGX64.codeGen $ Program grin
73
73
74
- putStrLn " * LLVM codegen *"
74
+ -- putStrLn "* LLVM codegen *"
75
75
let mod = CGLLVM. codeGen $ Program grin
76
76
llName = printf " %s.ll" fname
77
77
sName = printf " %s.s" fname
@@ -82,4 +82,4 @@ main = do
82
82
readFile sName >>= putStrLn
83
83
84
84
putStrLn " * LLVM JIT run *"
85
- JITLLVM. eagerJit mod
85
+ JITLLVM. eagerJit mod " grinMain "
Original file line number Diff line number Diff line change 1
1
grinMain =
2
- n13 <- sum 0 1 10000
2
+ n13 <- sum 0 1 100000
3
3
intPrint n13
4
4
5
5
sum n29 n30 n31 =
Original file line number Diff line number Diff line change 1
1
grinMain = t1 <- store (CInt 1)
2
- t2 <- store (CInt 10000)
3
- t3 <- store (Fupto t1 t2)
4
- t4 <- store (Fsum t3)
5
- (CInt r') <- eval t4
6
- intPrint r'
2
+ t2 <- store (CInt 10000)
3
+ t3 <- store (Fupto t1 t2)
4
+ t4 <- store (Fsum t3)
5
+ (CInt r') <- eval t4
6
+ intPrint r'
7
7
8
8
upto m n = (CInt m') <- eval m
9
9
(CInt n') <- eval n
Original file line number Diff line number Diff line change @@ -28,17 +28,11 @@ import LLVM.Module
28
28
import Control.Monad.Except
29
29
import qualified Data.ByteString.Char8 as BS
30
30
31
- toLLVM :: String -> AST. Module -> IO ()
31
+ toLLVM :: String -> AST. Module -> IO BS. ByteString
32
32
toLLVM fname mod = withContext $ \ ctx -> do
33
33
llvm <- withModuleFromAST ctx mod moduleLLVMAssembly
34
- BS. putStrLn llvm
35
34
BS. writeFile fname llvm
36
-
37
- printLLVM :: String -> Exp -> IO ()
38
- printLLVM fname exp = do
39
- let mod = codeGen exp
40
- -- pPrint mod
41
- toLLVM fname mod
35
+ pure llvm
42
36
43
37
tagMap :: Map Tag (Type , Constant )
44
38
tagMap = Map. fromList
Original file line number Diff line number Diff line change @@ -6,22 +6,25 @@ import Grin
6
6
import ParseGrin
7
7
import qualified STReduceGrin
8
8
import qualified ReduceGrin
9
-
9
+ import qualified JITLLVM
10
+ import qualified CodeGenLLVM
10
11
11
12
data Reducer
12
13
= PureReducer
13
14
| STReducer
15
+ | LLVMReducer
14
16
deriving (Eq , Show )
15
17
16
18
eval' :: Reducer -> String -> IO Val
17
19
eval' reducer fname = do
18
20
result <- parseGrin fname
19
21
case result of
20
22
Left err -> error $ show err
21
- Right e -> return $
23
+ Right e ->
22
24
case reducer of
23
- PureReducer -> ReduceGrin. reduceFun e " grinMain"
24
- STReducer -> STReduceGrin. reduceFun e " grinMain"
25
+ PureReducer -> pure $ ReduceGrin. reduceFun e " grinMain"
26
+ STReducer -> pure $ STReduceGrin. reduceFun e " grinMain"
27
+ LLVMReducer -> JITLLVM. eagerJit (CodeGenLLVM. codeGen (Program e)) " grinMain"
25
28
26
29
evalProgram :: Reducer -> Program -> Val
27
30
evalProgram reducer (Program defs) =
Original file line number Diff line number Diff line change 3
3
4
4
module JITLLVM where
5
5
6
+ import Grin
7
+ import Data.String
8
+
6
9
import LLVM.Target
7
10
import LLVM.Context
8
11
import LLVM.Module
@@ -42,8 +45,8 @@ nullResolver s = return (JITSymbol 0 (JITSymbolFlags False False))
42
45
failInIO :: ExceptT String IO a -> IO a
43
46
failInIO = either fail return <=< runExceptT
44
47
45
- eagerJit :: AST. Module -> IO Int64
46
- eagerJit amod =
48
+ eagerJit :: AST. Module -> String -> IO Grin. Val
49
+ eagerJit amod mainName =
47
50
withTestModule amod $ \ mod ->
48
51
withHostTargetMachine $ \ tm ->
49
52
withObjectLinkingLayer $ \ objectLayer ->
@@ -54,7 +57,7 @@ eagerJit amod =
54
57
mod
55
58
(SymbolResolver (resolver intPrint compileLayer) nullResolver) $
56
59
\ moduleSet -> do
57
- mainSymbol <- mangleSymbol compileLayer " grinMain "
60
+ mainSymbol <- mangleSymbol compileLayer (fromString mainName)
58
61
JITSymbol mainFn _ <- findSymbol compileLayer mainSymbol True
59
62
result <- mkMain (castPtrToFunPtr (wordPtrToPtr mainFn))
60
- return result
63
+ return $ Unit
Original file line number Diff line number Diff line change @@ -21,15 +21,15 @@ hs_sum_opt = do
21
21
sum n28 n18 n31
22
22
23
23
hs_sum_pure :: IO Float
24
- hs_sum_pure = pure $ sum 0 1 10000
24
+ hs_sum_pure = pure $ sum 0 1 100000
25
25
where
26
26
sum :: Float -> Float -> Float -> Float
27
27
sum n29 n30 n31
28
28
| n30 > n31 = n29
29
29
| otherwise = sum (n29 + n30) (n30 + 1 ) n31
30
30
31
31
hs_sum_naive :: IO Float
32
- hs_sum_naive = pure $ sum [1 .. 10000 ]
32
+ hs_sum_naive = pure $ sum [1 .. 100000 ]
33
33
34
34
main :: IO ()
35
35
main = do
@@ -43,6 +43,9 @@ main = do
43
43
[ bench " sum_simple" $ nfIO $ eval' STReducer " grin/sum_simple.grin"
44
44
, bench " sum_opt" $ nfIO $ eval' STReducer " grin/sum_opt.grin"
45
45
]
46
+ , bgroup " LLVM"
47
+ [ bench " sum_opt" $ nfIO $ eval' LLVMReducer " grin/sum_opt.grin"
48
+ ]
46
49
, bgroup " GHC"
47
50
[ bench " hs_sum_opt" $ nfIO $ hs_sum_opt
48
51
, bench " hs_sum_pure" $ nfIO $ hs_sum_pure
You can’t perform that action at this time.
0 commit comments