@@ -54,10 +54,11 @@ data Target = Target { triple :: String, dataLayout :: DataLayout }
54codegenLLVM :: [(TT.Name, SDecl)] ->
54codegenLLVM :: [(TT.Name, SDecl)] ->
55 String -> -- target triple
55 String -> -- target triple
56 String -> -- target CPU
56 String -> -- target CPU
57+ Int -> -- Optimization degree
57 FilePath -> -- output file name
58 FilePath -> -- output file name
58 OutputType ->
59 OutputType ->
60−codegenLLVM defs triple cpu file outty = withContext $ \context -> do
61+codegenLLVM defs triple cpu optimize file outty = withContext $ \context -> do
61 initializeAllTargets
62 initializeAllTargets
62 (target, _) <- failInIO $ lookupTarget Nothing triple
63 (target, _) <- failInIO $ lookupTarget Nothing triple
63 withTargetOptions $ \options ->
64 withTargetOptions $ \options ->
@@ -66,11 +67,11 @@ codegenLLVM defs triple cpu file outty = withContext $ \context -> do
66 let ast = codegen (Target triple layout) (map snd defs)
67 let ast = codegen (Target triple layout) (map snd defs)
67 result <- runErrorT . M.withModuleFromAST context ast $ \m ->
68 result <- runErrorT . M.withModuleFromAST context ast $ \m ->
68 do let opts = defaultCuratedPassSetSpec
69 do let opts = defaultCuratedPassSetSpec
69− { optLevel = Just 3
70+ { optLevel = Just optimize
70 , simplifyLibCalls = Just True
71 , simplifyLibCalls = Just True
71 , useInlinerWithThreshold = Just 225
72 , useInlinerWithThreshold = Just 225
73− withPassManager opts $ \pm -> runPassManager pm m
74+ when (optimize /= 0) $ withPassManager opts $ void . flip runPassManager m
74 outputModule tm file outty m
75 outputModule tm file outty m
75 case result of
76 case result of
76 Right _ -> return ()
77 Right _ -> return ()