From: Matthijs Kooijman Date: Mon, 17 Aug 2009 12:29:57 +0000 (+0200) Subject: Add top level inliner normalization pass. X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=cda7d41d556f8cc179cf29579b213dc480ab5dba;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git Add top level inliner normalization pass. This pass does not actually do anything yet, it just provides the plumbing for inlining later on. --- diff --git "a/c\316\273ash/CLasH/Normalize.hs" "b/c\316\273ash/CLasH/Normalize.hs" index 5d2b3a6..4366949 100644 --- "a/c\316\273ash/CLasH/Normalize.hs" +++ "b/c\316\273ash/CLasH/Normalize.hs" @@ -23,6 +23,7 @@ import qualified UniqSupply import qualified CoreUtils import qualified Type import qualified TcType +import qualified Name import qualified Id import qualified Var import qualified VarSet @@ -319,6 +320,33 @@ letmergetop = everywhere ("letmerge", letmerge) inlinenonreptop :: Transform inlinenonreptop = everywhere ("inlinenonrep", inlinebind ((Monad.liftM not) . isRepr . snd)) +inlinetoplevel, inlinetopleveltop :: Transform +-- Any system name is candidate for inlining. Never inline user-defined +-- functions, to preserver structure. +inlinetoplevel expr@(Var f) | (Name.isSystemName . Id.idName) f = do + -- See if this is a top level binding for which we have a body + body_maybe <- Trans.lift $ getGlobalBind f + case body_maybe of + Just body -> do + -- Get the normalized version + norm <- Trans.lift $ getNormalized f + if needsInline norm + then + change norm + else + return expr + -- No body, this is probably a local variable or builtin or external + -- function. + Nothing -> return expr +-- Leave all other expressions unchanged +inlinetoplevel expr = return expr +inlinetopleveltop = everywhere ("inlinetoplevel", inlinetoplevel) + +needsInline :: CoreExpr -> Bool +-- Any function that just evaluates to another function, can be inlined +--needsInline (Var f) = True +needsInline _ = False + -------------------------------- -- Scrutinee simplification -------------------------------- @@ -617,7 +645,7 @@ funextracttop = everywhere ("funextract", funextract) -- What transforms to run? -transforms = [argproptop, funextracttop, etatop, betatop, castproptop, letremovesimpletop, letderectop, letremovetop, letsimpltop, letflattop, scrutsimpltop, casesimpltop, caseremovetop, inlinenonreptop, appsimpltop, letremoveunusedtop, castsimpltop, lambdasimpltop] +transforms = [inlinetopleveltop, argproptop, funextracttop, etatop, betatop, castproptop, letremovesimpletop, letderectop, letremovetop, letsimpltop, letflattop, scrutsimpltop, casesimpltop, caseremovetop, inlinenonreptop, appsimpltop, letremoveunusedtop, castsimpltop, lambdasimpltop] -- | Returns the normalized version of the given function. getNormalized ::