@@ -54,10 +54,11 @@ data Target = Target { triple :: String, dataLayout :: DataLayout }
5454codegenLLVM :: [(TT.Name, SDecl)] ->
5555 String -> -- target triple
5656 String -> -- target CPU
57+ Int -> -- Optimization degree
5758 FilePath -> -- output file name
5859 OutputType ->
5960 IO ()
60−codegenLLVM defs triple cpu file outty = withContext $ \context -> do
61+codegenLLVM defs triple cpu optimize file outty = withContext $ \context -> do
6162 initializeAllTargets
6263 (target, _) <- failInIO $ lookupTarget Nothing triple
6364 withTargetOptions $ \options ->
@@ -66,11 +67,11 @@ codegenLLVM defs triple cpu file outty = withContext $ \context -> do
6667 let ast = codegen (Target triple layout) (map snd defs)
6768 result <- runErrorT . M.withModuleFromAST context ast $ \m ->
6869 do let opts = defaultCuratedPassSetSpec
69− { optLevel = Just 3
70+ { optLevel = Just optimize
7071 , simplifyLibCalls = Just True
7172 , useInlinerWithThreshold = Just 225
7273 }
73− withPassManager opts $ \pm -> runPassManager pm m
74+ when (optimize /= 0) $ withPassManager opts $ void . flip runPassManager m
7475 outputModule tm file outty m
7576 case result of
7677 Right _ -> return ()