# Changeset 1362 for Deliverables/D4.2-4.3

Ignore:
Timestamp:
Oct 12, 2011, 5:54:04 PM (8 years ago)
Message:

d4-2 report almost complete

File:
1 edited

Unmodified
Added
Removed
• ## Deliverables/D4.2-4.3/reports/D4-2.tex

 r1361 The compiler's backend consists of four distinct intermediate languages: RTL, ERTL, LTL and LIN. A fifth language, RTLabs, serves as the exit point of the backend and the entry point of the frontend. RTL, ERTL and LTL are graph based' languages, whereas LIN is a linearised language RTL, ERTL and LTL are graph based' languages, whereas LIN is a linearised language, the final language before translation to assembly. We now briefly discuss the properties of the intermediate languages, and discuss the various transformations that take place during the translation process: \paragraph{RTLabs ((Abstract) Register Transfer Language)} As mentioned, this is the final language of the compiler's frontend and the entry point for the backend. This language uses pseudoregisters, not hardware registers. During the translation pass from RTLabs to RTL instruction selection is carried out. \paragraph{RTL (Register Transfer Language)} This language uses pseudoregisters, not hardware registers. Tailcall elimination is carried out during the translation from RTL to ERTL. \paragraph{ERTL (Extended Register Transfer Language)} In this language most instructions still operate on pseudoregisters, apart from instructions that move data to, and from, the accumulator. The ERTL to LTL pass performs the following transformations: liveness analysis, register colouring and register/stack slot allocation. \paragraph{LTL (Linearised Transfer Language)} The name is somewhat of a misnomer, as the language is \emph{not} linearised, and is in fact still graph based, but uses hardware registers instead of pseudoregisters. Tunnelling (branch compression) should be implemented here. \paragraph{LIN (Linearised)} This is a linearised form of the LTL language; function graphs have been linearised into lists of statements. All registers have been translated into hardware registers or stack addresses. This is the final stage of compilation before translating directly into assembly language. %-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-% Functions for adding statements to a graph, searching the graph, and so on, are remarkably similar across all languages, but are duplicated in the O'Caml code. As a result, we chose to abstract the representation of internal functions for the RTL, ERTL, LTL and LIN intermediate languages into a joint' representation. This representation is parameterised by a record that dictates the layout of the function body for each intermediate language. For instance, in RTL, the layout is graph like, whereas in LIN, the layout is a linearised list of statements. Further, a generalised way of accessing the successor statement to the one currently under consideration is needed, and so forth. Our joint internal function record looks like so: \begin{lstlisting} record joint_internal_function (globals: list ident) (p:params globals) : Type[0] ≝ { ... joint_if_params   : paramsT p; joint_if_locals   : localsT p; ... joint_if_code     : codeT … p; ... }. \end{lstlisting} In particular, everything that can vary between differing intermediate languages has been parameterised. Here, we see the number of parameters, the listing of local variables, and the internal code representation has been parameterised. Other particulars are also parameterised, though here omitted. Hopefully this abstraction process will reduce the number of proofs that need to be written, dealing with internal functions. We only need to prove once that fetching a statement's successor is correct', and we inherit this property for free for every intermediate language. \paragraph{Changes between languages made explicit} Due to the bureaucracy inherent in explicating each intermediate language's syntax in the O'Caml compiler, it can often be hard to see exactly what changes between each successive intermediate language. By abstracting the syntax of the RTL, ERTL, LTL and LIN intermediate languages, we make these changes much clearer. Our abstraction takes the following form: \begin{lstlisting} inductive joint_instruction (p: params__) (globals: list ident): Type[0] := | COMMENT: String $\rightarrow$ joint_instruction p globals | COST_LABEL: costlabel $\rightarrow$ joint_instruction p globals | INT: generic_reg p $\rightarrow$ Byte $\rightarrow$ joint_instruction p globals ... | extension: extend_statements p $\rightarrow$ joint_instruction p globals. \end{lstlisting} We first note that for the majority of intermediate languages, many instructions are shared. However, these instructions expect different register types (either a pseudoregister or a hardware register) as arguments. We must therefore parameterise the joint syntax with a record of parameters that will be specialised to each intermediate language. In the type above, this parameterisation is realised wit the \texttt{params\_\_} record. Further, we note that some intermediate languages have language specific instructions (i.e. the instructions that change between languages). We therefore add a new constructor to the syntax, \texttt{extension}, which expects a value of type \texttt{extend\_statements p}. As \texttt{p} varies between intermediate languages, we can provide language specific extensions to the syntax of the joint language. For example, ERTL's extended syntax consists of the following extra statements: \begin{lstlisting} inductive ertl_statement_extension: Type[0] := | ertl_st_ext_new_frame: ertl_statement_extension | ertl_st_ext_del_frame: ertl_statement_extension | ertl_st_ext_frame_size: register $\rightarrow$ ertl_statement_extension. \end{lstlisting} These are further packaged into an ERTL specific instance of \texttt{params\_\_} as follows: \begin{lstlisting} definition ertl_params__: params__ := mk_params__ register register ... ertl_statement_extension. \end{lstlisting} \paragraph{Possible language commutations} \paragraph{Instruction selection} The backend translation passes of the CerCo compiler differ quite a bit from the CompCert compiler. In the CompCert compiler, linearisation occurs much earlier in the compilation chain, and passes such as register colouring and allocation are carried out on a linearised form of program. Contrast this with our own approach, where the code is represented as a graph for much longer. However, by abstracting the representation of intermediate functions, we are now much more free to reorder translation passes as we see fit. The linearisation process, for instance, now no longer cares about the specific representation of code in the source and target languages. It just relies on a common interface. We are therefore, in theory, free to pick where we wish to linearise our representation. This adds an unusual flexibility into the compilation process, and allows us to freely experiment with different orderings of translation passes. %-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-% A few difficult-to-close, but non-computational (i.e. they do not prevent us from executing the compiler inside Matita), proof obligations have been closed using daemons in the backend. These proof obligations originate with our use of dependent types for expressing invariants in the compiler. \textbf{Branch compression (tunnelling).} This was a feature of the O'Caml compiler. It is not yet currently implemented in the Matita compiler. This feature is only an optimisation, and will not affect the correctness of the compiler. \textbf{Real' tailcalls} For the time being, tailcalls in the backend are translated to vanilla' function calls during the ERTL to LTL pass. This should be routine. \item We plan to port the O'Caml compiler's implementation of tailcalls when this is completed. We plan to port the O'Caml compiler's implementation of tailcalls when this is completed, and eventually port the branch compression code currently in the O'Caml compiler to the Matita implementation. This should not cause any major problems. \item \end{center} %-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-% % SECTION.                                                                    % %-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-% \subsection{Listing of important functions} \label{subsect.listing.important.functions} \end{document}
Note: See TracChangeset for help on using the changeset viewer.