Averest


Compiler Module

This module implements the core of a simple compiler for translating MiniC programs to CmdType programs and control dataflow graphs.

Types

Type Description

BasicBlock

BasicBlock is a record to hold the data of a basic block of the CDFG of a cmd program. rdVars and wrVars hold the sets of variables that were read and written by that basic block, cmdProg is the program of that basic block, and actDepGraph is its action dependency graph. nextBBs is the set of successor basic blocks (either one or two). Finally, lineBegin and lineEnd are the first and last lines of the cmd program that belong to this basic block.

Functions and values

Function or value Description

CompileStmtC decl funcArr S

Full Usage: CompileStmtC decl funcArr S

Parameters:
Returns: Set<string> * (string * TypeC)[] * Map<int, CmdType>

CompileStmtC compiles a given MiniC statement to a CmdType program where the given declarations decl are used. The result is a mapping that maps program lines to CmdType instructions plus the list of used temporary variables.

decl : Map<string, TypeC>
funcArr : MiniCFunction[]
S : StmtC
Returns: Set<string> * (string * TypeC)[] * Map<int, CmdType>

ComputeCmdDependencyGraph lineBegin lineEnd cmdp

Full Usage: ComputeCmdDependencyGraph lineBegin lineEnd cmdp

Parameters:
    lineBegin : int
    lineEnd : int
    cmdp : Map<int, CmdType>

Returns: Map<int, Set<int>>

ComputeCmdDependencyGraph computes the action dependency graph of a cmd program without branch/jump instructions, i.e., of a basic block. This is a graph whose nodes are integers denoting program lines of the cmd program, and where there is an edge l->l' if l must be executed before l' (since there is a data dependency between l and l'). Data dependencies considered are read-after-write, write-after-write and write-after-read. Besides the Cmd program, also the first and last line of it is needed as argument. The result is a mapping that maps l to the set of its dependent nodes l', meaning that l has to be executed before l'.

lineBegin : int
lineEnd : int
cmdp : Map<int, CmdType>
Returns: Map<int, Set<int>>

ComputeControlDataFlowGraph cmdp

Full Usage: ComputeControlDataFlowGraph cmdp

Parameters:
Returns: Map<int, BasicBlock>

ComputeControlDataFlowGraph computes the control-dataflow graph (CDFG) of a cmd program where the generated CDFG is represented as a map from some of the program lines to BasicBlocks where the

cmdp : Map<int, CmdType>
Returns: Map<int, BasicBlock>

ControlDataFlowGraph2DotFile ostr cdfg

Full Usage: ControlDataFlowGraph2DotFile ostr cdfg

Parameters:

Writes CDFG of a cmd program as computed by ComputeControlDataFlowGraph and ComputeCmdDependencyGraph to a dot-file for visualization.

ostr : TextWriter
cdfg : Map<int, BasicBlock>

ControlFlowGraph2DotFile ostr cdfg

Full Usage: ControlFlowGraph2DotFile ostr cdfg

Parameters:

Writes CFG of a cmd program as computed by ComputeControlDataFlowGraph to a dot-file for visualization.

ostr : TextWriter
cdfg : Map<int, BasicBlock>

ForceDirectedScheduling bb delay

Full Usage: ForceDirectedScheduling bb delay

Parameters:
Returns: Set<int>[] * Map<Ops2, float[]>

ForceDirectedScheduling is a time-constrained scheduling heuristic: Given the commands of a basic block, the function first computes the ASAP and ALAP schedules. To determine the mobility intervals of the cmds, the ALAP schedule is then shifted by "delay" time steps, to stretch the mobility intervals to a schedule with Length(ASAP)+delay many steps. The function then determines a schedule that requires that many time steps where the resources are distributed as equal as possible to maximize the reuse of allocated function units. The result is the generated schedule with its resource usage matrix (mapping each step and operation to the number of operation units requires in that step).

bb : BasicBlock
delay : int
Returns: Set<int>[] * Map<Ops2, float[]>

ListScheduling bb fuMap

Full Usage: ListScheduling bb fuMap

Parameters:
Returns: Set<int>[]

List based scheduling is a resource directed scheduling method, i.e., available resources are given, and a schedule is generated that only makes use of the given resources, thus taking possibly more time than a ASAP/ALAP schedule.

bb : BasicBlock
fuMap : Map<Ops2, int>
Returns: Set<int>[]

MobilityIntervals nodesG edgesG

Full Usage: MobilityIntervals nodesG edgesG

Parameters:
Returns: Set<'a>[] * Set<'a>[] * Map<'a, (int * int)>

Given an acyclic graph represented by its set of nodes nodesG, and its edges given as adjacency map (mapping a node to its successors), this function computes the mobility intervals, i.e., a map which maps a node i to a pair (lv1,lv2) where lv1 and lv2 are the steps where node i will be scheduled to in an ASAP and ALAP schedule, respectively.

nodesG : Set<'a>
edgesG : Map<'a, Set<'a>>
Returns: Set<'a>[] * Set<'a>[] * Map<'a, (int * int)>

PrintBasicBlocks ostr cdfg

Full Usage: PrintBasicBlocks ostr cdfg

Parameters:

Prints the CDFG as a program listing with separation lines between bbs.

ostr : TextWriter
cdfg : Map<int, BasicBlock>

ResetTempVarIndex ()

Full Usage: ResetTempVarIndex ()

Parameters:
    () : unit

() : unit

ResourcesOfSchedule cmdp schedule

Full Usage: ResourcesOfSchedule cmdp schedule

Parameters:
Returns: Map<Ops2, int>

compute the ressource usage of a schedule

cmdp : Map<int, CmdType>
schedule : Set<int>[]
Returns: Map<Ops2, int>

VarIndex

Full Usage: VarIndex

Returns: int ref

Returns: int ref

printSchedule ostr bb schedule

Full Usage: printSchedule ostr bb schedule

Parameters:

print a schedule

ostr : 'a
bb : BasicBlock
schedule : Set<int>[]

resourceOfCmd cmd

Full Usage: resourceOfCmd cmd

Parameters:
Returns: Ops2 list

compute the required ressources of a command

cmd : CmdType
Returns: Ops2 list