diff options
author | Sven Tennie <sven.tennie@gmail.com> | 2021-01-24 18:26:27 +0100 |
---|---|---|
committer | Sven Tennie <sven.tennie@gmail.com> | 2021-01-24 18:26:27 +0100 |
commit | 6db2dd78a8488654ea7785621708496e24a6e92e (patch) | |
tree | a1d7108334ec1aa6eae8ca88776bdb5a534f7053 | |
parent | 773e2828fde4d8f640082b6bded9945e7b9584e3 (diff) | |
download | haskell-wip/llvm_musttail_experiment.tar.gz |
LLVM: Use musttail instead of tailwip/llvm_musttail_experiment
This forces LLVM to handle tail calls as tail calls. Otherwise LLVM is
free to ignore the tail and do an ordinary call.
https://llvm.org/docs/LangRef.html#call-instruction
-rw-r--r-- | compiler/GHC/CmmToLlvm/CodeGen.hs | 7 | ||||
-rw-r--r-- | compiler/GHC/Llvm/Ppr.hs | 2 |
2 files changed, 3 insertions, 6 deletions
diff --git a/compiler/GHC/CmmToLlvm/CodeGen.hs b/compiler/GHC/CmmToLlvm/CodeGen.hs index 3ad52b6f79..13e46ae9d5 100644 --- a/compiler/GHC/CmmToLlvm/CodeGen.hs +++ b/compiler/GHC/CmmToLlvm/CodeGen.hs @@ -915,8 +915,7 @@ genJump (CmmLit (CmmLabel lbl)) live = do (vf, stmts, top) <- getHsFunc live lbl (stgRegs, stgStmts) <- funEpilogue live let s1 = Expr $ Call TailCall vf stgRegs llvmStdFunAttrs - let s2 = Return Nothing - return (stmts `appOL` stgStmts `snocOL` s1 `snocOL` s2, top) + return (stmts `appOL` stgStmts `snocOL` s1, top) -- Call to unknown function / address @@ -935,9 +934,7 @@ genJump expr live = do (v1, s1) <- doExpr (pLift fty) $ Cast cast vf (pLift fty) (stgRegs, stgStmts) <- funEpilogue live let s2 = Expr $ Call TailCall v1 stgRegs llvmStdFunAttrs - let s3 = Return Nothing - return (stmts `snocOL` s1 `appOL` stgStmts `snocOL` s2 `snocOL` s3, - top) + return (stmts `snocOL` s1 `appOL` stgStmts `snocOL` s2, top) -- | CmmAssign operation diff --git a/compiler/GHC/Llvm/Ppr.hs b/compiler/GHC/Llvm/Ppr.hs index 3cc4ab5394..6aa2a15e0b 100644 --- a/compiler/GHC/Llvm/Ppr.hs +++ b/compiler/GHC/Llvm/Ppr.hs @@ -283,7 +283,7 @@ ppCall opts ct fptr args attrs = case fptr of where ppCall' (LlvmFunctionDecl _ _ cc ret argTy params _) = - let tc = if ct == TailCall then text "tail " else empty + let tc = if ct == TailCall then text "ret musttail " else empty ppValues = ppCallParams opts (map snd params) args ppArgTy = (ppCommaJoin $ map (ppr . fst) params) <> (case argTy of |