-
Notifications
You must be signed in to change notification settings - Fork 2
ForeC Compilation Process
Eugene edited this page Apr 16, 2024
·
8 revisions
The ForeC compiler is focussed on generating C-code that is amenable to static timing analysis. The static thread schedule of a ForeC program is based on a total ordering of its threads. Each type of scheduling routine follows a general template, which is instantiated core and thread information. The optimisation of C-code generated by the ForeC compiler is left to the C-compiler.
- Lexical analysis and tokenisation using
Flex - Construction of abstract syntax tree (AST) of ForeC source program and header file using
Bison - Semantic analysis: mostly recursive depth-first search (DFS) of AST
- Symbol table of variables, inputs, outputs, shared, typedefs, enums, labels, functions, threads
- Computation of each thread's variable accesses (read/write). At each
parstatement, take the union of the threads' variable accesses. Propagate variable accesses up the thread hierarchy until themainthread is reached. If a variable is associated with multiple threads, then it is a shared variable - Propagate knowledge of shared variables back down to all the (nested)
parstatements to determine the necessary handling of shared variable copying and combining. A shared variable does not need a combine function if it never has parallel writers (sequential writers are inherently mutually exclusive) - Check that all defined threads have a core allocation, and that all allocated threads have been defined
- Check for instantaneous loops. Conservatively evaluate the reaching of
pausestatements inif-else,switch, andabortstatements, or that loops have a defined upper-bound
- Construct abstract control-flow graph from the AST, focussing on the forking-joining of threads, conditionals, pauses, and abort scopes. Threads and functions are linked to their "call sites"
- Check that threads do not recursively fork each other: DFS of CFG and identifying revisited threads
- Derive a CFG for each core, based on their allocated threads: DFS of CFG. Create stubs for parent threads.
Helps in defining the master and slave cores of each
parstatement and the inter-core synchronisation points needed to manage the distributed forking and joining of threads
- Generate a linked list for each core to manage the run-time scheduling of thread execution and
inter-core synchronisation: DFS of CFG
- Cooperative scheduling is assumed with left-to-right assignment of thread execution priority
- The master core's initial linked list contains the main thread, and scheduling routines to handle
par-specific thread forking and global tick synchronisation - Each slave core's initial linked list contains scheduling routines that handle
par-specific thread forking and global tick synchronisation - For each
parstatement, generate a linked list for each participating core. Include scheduling routines that checkabortconditions and handlepartermination. Handle nestedparstatements by inserting scheduling routines, that handlepar-specific thread forking into the linked lists, after their parent thread - When a thread executes a
parstatement, the parent thread (master core) and correspondingparroutines (slave cores) are replaced by thepar's linked lists. When threads terminate (join), they remove themselves from their core's linked list - When a
parstatement terminates, the remnants of thepar's linked lists are removed and the parent thread andparroutines are reinstated
- Generate core and par-specific scheduling routines for global tick synchronisation,
parexecution,partermination, combining of shared variables, and checking ofabortconditions. Works on uniqueparIDs and busy waiting on status variables, updated atomically. C and ASM comments are used to demarcate the scheduling routines for analysis - Generate C-code for each thread body by walking their AST. Insert C-code for copying shared variables, but
only for threads that possibly write to the shared variables. From the original thread body, regenerate the
existing C statements and expand the ForeC statements into C-code. The
parandpausestatements and their corresponding scheduling routines will jump between each other - Generate C-code for each function by walking their AST