X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2FcoreSyn%2FCoreUnfold.lhs;h=95a05d0b07eba13a097cd675400305ebdd77da7d;hp=d57f1886fc0377e7b7d91397a2c169374a9915a2;hb=17b297d97d327620ed6bfab942f8992b2446f1bf;hpb=0065d5ab628975892cea1ec7303f968c3338cbe1 diff --git a/compiler/coreSyn/CoreUnfold.lhs b/compiler/coreSyn/CoreUnfold.lhs index d57f188..95a05d0 100644 --- a/compiler/coreSyn/CoreUnfold.lhs +++ b/compiler/coreSyn/CoreUnfold.lhs @@ -1,7 +1,9 @@ % +% (c) The University of Glasgow 2006 % (c) The AQUA Project, Glasgow University, 1994-1998 % -\section[CoreUnfold]{Core-syntax unfoldings} + +Core-syntax unfoldings Unfoldings (which can travel across module boundaries) are in Core syntax (namely @CoreExpr@s). @@ -13,6 +15,13 @@ literal''). In the corner of a @CoreUnfolding@ unfolding, you will find, unsurprisingly, a Core expression. \begin{code} +{-# OPTIONS_GHC -w #-} +-- The above warning supression flag is a temporary kludge. +-- While working on this module you are encouraged to remove it and fix +-- any warnings in the module. See +-- http://hackage.haskell.org/trac/ghc/wiki/WorkingConventions#Warnings +-- for details + module CoreUnfold ( Unfolding, UnfoldingGuidance, -- Abstract types @@ -30,31 +39,24 @@ module CoreUnfold ( #include "HsVersions.h" -import StaticFlags ( opt_UF_CreationThreshold, opt_UF_UseThreshold, - opt_UF_FunAppDiscount, opt_UF_KeenessFactor, - opt_UF_DearOp, - ) -import DynFlags ( DynFlags, DynFlag(..), dopt ) +import StaticFlags +import DynFlags import CoreSyn -import PprCore ( pprCoreExpr ) -import OccurAnal ( occurAnalyseExpr ) -import CoreUtils ( exprIsHNF, exprIsCheap, exprIsTrivial ) -import Id ( Id, idType, isId, - idUnfolding, globalIdDetails - ) -import DataCon ( isUnboxedTupleCon ) -import Literal ( litSize ) -import PrimOp ( primOpIsDupable, primOpOutOfLine ) -import IdInfo ( OccInfo(..), GlobalIdDetails(..) ) -import Type ( isUnLiftedType ) -import PrelNames ( hasKey, buildIdKey, augmentIdKey ) +import PprCore () -- Instances +import OccurAnal +import CoreUtils +import Id +import DataCon +import Literal +import PrimOp +import IdInfo +import Type +import PrelNames import Bag import FastTypes import Outputable -#if __GLASGOW_HASKELL__ >= 404 -import GLAEXTS ( Int# ) -#endif +import GHC.Exts ( Int# ) \end{code} @@ -87,6 +89,14 @@ mkUnfolding top_lvl expr -- This can occasionally mean that the guidance is very pessimistic; -- it gets fixed up next round +instance Outputable Unfolding where + ppr NoUnfolding = ptext SLIT("No unfolding") + ppr (OtherCon cs) = ptext SLIT("OtherCon") <+> ppr cs + ppr (CompulsoryUnfolding e) = ptext SLIT("Compulsory") <+> ppr e + ppr (CoreUnfolding e top hnf cheap g) + = ptext SLIT("Unf") <+> sep [ppr top <+> ppr hnf <+> ppr cheap <+> ppr g, + ppr e] + mkCompulsoryUnfolding expr -- Used for things that absolutely must be unfolded = CompulsoryUnfolding (occurAnalyseExpr expr) \end{code} @@ -192,6 +202,8 @@ sizeExpr bOMB_OUT_SIZE top_args expr -- then we'll get a dfun which is a pair of two INLINE lambdas size_up (Note _ body) = size_up body -- Other notes cost nothing + + size_up (Cast e _) = size_up e size_up (App fun (Type t)) = size_up fun size_up (App fun arg) = size_up_app fun [arg] @@ -263,7 +275,6 @@ sizeExpr bOMB_OUT_SIZE top_args expr -- The 1+ is a little discount for reduced allocation in the caller alts_size tot_size _ = tot_size --- gaw 2004 size_up (Case e _ _ alts) = nukeScrutDiscount (size_up e) `addSize` foldr (addSize . size_up_alt) sizeZero alts -- We don't charge for the case itself @@ -492,15 +503,13 @@ StrictAnal.addStrictnessInfoToTopId \begin{code} callSiteInline :: DynFlags -> Bool -- True <=> the Id can be inlined - -> Bool -- 'inline' note at call site - -> OccInfo -> Id -- The Id -> [Bool] -- One for each value arg; True if it is interesting -> Bool -- True <=> continuation is interesting -> Maybe CoreExpr -- Unfolding, if any -callSiteInline dflags active_inline inline_call occ id arg_infos interesting_cont +callSiteInline dflags active_inline id arg_infos interesting_cont = case idUnfolding id of { NoUnfolding -> Nothing ; OtherCon cs -> Nothing ; @@ -522,12 +531,8 @@ callSiteInline dflags active_inline inline_call occ id arg_infos interesting_con yes_or_no | not active_inline = False - | otherwise = case occ of - IAmDead -> pprTrace "callSiteInline: dead" (ppr id) False - IAmALoopBreaker -> False - --OneOcc in_lam _ _ -> (not in_lam || is_cheap) && consider_safe True - other -> is_cheap && consider_safe False - -- we consider even the once-in-one-branch + | otherwise = is_cheap && consider_safe False + -- We consider even the once-in-one-branch -- occurrences, because they won't all have been -- caught by preInlineUnconditionally. In particular, -- if the occurrence is once inside a lambda, and the @@ -539,9 +544,6 @@ callSiteInline dflags active_inline inline_call occ id arg_infos interesting_con -- consider_safe decides whether it's a good idea to -- inline something, given that there's no -- work-duplication issue (the caller checks that). - | inline_call = True - - | otherwise = case guidance of UnfoldNever -> False UnfoldIfGoodArgs n_vals_wanted arg_discounts size res_discount @@ -590,7 +592,6 @@ callSiteInline dflags active_inline inline_call occ id arg_infos interesting_con if dopt Opt_D_dump_inlinings dflags then pprTrace "Considering inlining" (ppr id <+> vcat [text "active:" <+> ppr active_inline, - text "occ info:" <+> ppr occ, text "arg infos" <+> ppr arg_infos, text "interesting continuation" <+> ppr interesting_cont, text "is value:" <+> ppr is_value,