Skip to content

Commit

Permalink
Main pass to optimize layout when user annotates function
Browse files Browse the repository at this point in the history
  • Loading branch information
vidsinghal committed Sep 13, 2023
1 parent 583a207 commit c937d0c
Show file tree
Hide file tree
Showing 5 changed files with 478 additions and 63 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Basics
import GenerateLayout1

type Text = Vector Char

emphKeywordInContent :: Text -> Blog -> Blog
{-# ANN emphKeywordInContent Layout1 #-}
emphKeywordInContent keyword blogs =
case blogs of
End -> End
Layout1 header id author date content tags rst -> let newContent = case content of
Content block -> Content (emphasizeKeywordInBlock keyword block)
newRst = emphKeywordInContent keyword rst
in Layout1 header id author date newContent tags newRst

-- main function
gibbon_main =
let blogs = mkBlogs_layout1 2
keyword :: Vector Char
keyword = "a"
newblgs = emphKeywordInContent keyword blogs
in printPacked newblgs
2 changes: 2 additions & 0 deletions gibbon-compiler/src/Gibbon/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ import Gibbon.Passes.Codegen (codegenProg)
import Gibbon.Passes.Fusion2 (fusion2)
import Gibbon.Passes.CalculateBounds (inferRegSize)
import Gibbon.Pretty
import Gibbon.Passes.OptimizeADTLayout (shuffleDataCon)



Expand Down Expand Up @@ -639,6 +640,7 @@ passes config@Config{dynflags} l0 = do
-- branches before InferLocations.

-- Note: L1 -> L2
l1 <- goE1 "optimizeADTLayout" shuffleDataCon l1
l1 <- goE1 "copyOutOfOrderPacked" copyOutOfOrderPacked l1
l1 <- goE1 "simplify_2" simplifyL1 l1
l1 <- go "L1.typecheck" L1.tcProg l1
Expand Down
22 changes: 11 additions & 11 deletions gibbon-compiler/src/Gibbon/Passes/DefinitionUseChains.hs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,7 @@ generateDefUseChainsFunction ::
generateDefUseChainsFunction env f@FunDef {funName, funBody, funTy, funArgs} =
let edgeList = generateDefUseChainsFunBody env funBody
(graph, nodeFromVertex, vertexFromKey) = G.graphFromEdges edgeList
in dbgTraceIt
(sdoc edgeList)
dbgTraceIt
("\n")
M.insert
in M.insert
funName
(graph, nodeFromVertex, vertexFromKey)
M.empty
Expand All @@ -119,7 +115,7 @@ getDefinitionsReachingLetExp :: (FreeVars (e l d), Ord l, Ord d, Ord (e l d), Ou
getDefinitionsReachingLetExp f@FunDef {funName, funBody, funTy, funArgs} =
let edgeList = generateUseDefChainsFunBody M.empty funBody
(graph, nodeFromVertex, vertexFromKey) = G.graphFromEdges edgeList
in dbgTraceIt (sdoc edgeList) dbgTraceIt ("\n") M.insert funName (graph, nodeFromVertex, vertexFromKey) M.empty
in M.insert funName (graph, nodeFromVertex, vertexFromKey) M.empty



Expand All @@ -132,11 +128,7 @@ generateDefUseChainsExp ::
generateDefUseChainsExp env key expr =
let edgeList = generateDefUseChainsFunBody env expr
(graph, nodeFromVertex, vertexFromKey) = G.graphFromEdges edgeList
in dbgTraceIt
(sdoc edgeList)
dbgTraceIt
("\n")
M.insert
in M.insert
key
(graph, nodeFromVertex, vertexFromKey)
M.empty
Expand Down Expand Up @@ -350,3 +342,11 @@ getDefUseChainsVar var exp isReDefined =
MapE {} -> error "getDefUseChainsVar: TODO MapE"
FoldE {} -> error "getDefUseChainsVar: TODO FoldE"
Ext _ -> error "getDefUseChainsVar: TODO Ext"



-- TODO:
-- For UseDefChains, add variables introduced in case expressions.
-- successors are expressions that use those expressions, make this recursive.
-- remove all let binds
-- then release let binds using gFreeVars
Loading

0 comments on commit c937d0c

Please sign in to comment.