CACAO
Compiler.hpp
Go to the documentation of this file.
1 /* src/vm/jit/compiler2/Compiler.hpp - 2nd stage Just-In-Time compiler
2 
3  Copyright (C) 2013
4  CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 
6  This file is part of CACAO.
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2, or (at
11  your option) any later version.
12 
13  This program is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  02110-1301, USA.
22 
23 */
24 
25 /**
26  * @file
27  * Second stage compiler class.
28  */
29 
30 #ifndef _JIT_COMPILER2_COMPILER
31 #define _JIT_COMPILER2_COMPILER
32 
33 #include "vm/method.hpp"
34 #include "toolbox/Option.hpp"
35 
36 namespace cacao {
37 namespace jit {
38 /**
39  * Second stage compiler namespace.
40  * @ingroup compiler2
41  *
42  * All parts specific to the second stage compiler are contained in this
43  * namespace.
44  */
45 namespace compiler2 {
46 
47 /**
48  * @defgroup compiler2 Second Stage Compiler
49  *
50  * This module contains the second stage compiler. The second stage compiler
51  * (compiler2) is an optimizing Just-In-Time (JIT) compiler for the CACAO
52  * virtual machine. It is intended to compile and optimize frequently used
53  * methods. The main design goals are code quality and usability in terms
54  * of how difficult it is to create new compiler passes.
55  *
56  * # Intermediate Representations #
57  *
58  * The compiler centers around two different representation models for
59  * the code. In the architecture independent part a SSA based graph
60  * representation is used. The absence of a concrete scheduling makes most
61  * optimization and analyse passes easier.
62  *
63  * For the architecture dependent part the graph representation is successively
64  * transformed into a list of machine instructions. This form is more suitable
65  * for low level tasks such as register allocation and code generation. The
66  * following sections will go more details of both representations
67  *
68  * ## High level intermediate representation ##
69  *
70  * The main data structure of this representation is the Instruction class.
71  * An Instruction can take an arbitrary number of input Values and produce
72  * on output Value. The inputs are modeled as pointer to other Instructions.
73  * The Instruction itself is the only representative of the value it produces.
74  * There are no such things as variables or registers. Each value is defined
75  * exactly once, at the Instruction that computes it. This is one requirement
76  * for the SSA representation. Phi instruction (PHIInst) are used to join
77  * values from different control flow paths. An Instruction with the pointers
78  * to its operands form a so-called Use-Def chain. All Use-Def chains together
79  * for a Data Flow Graph.
80  *
81  * Unfortunately this is not enough to comprise the
82  * complete semantics of a method. Language constructs like conditionals and
83  * loops require some notion of control flow. The traditional approach is to
84  * introduce basic blocks. A basic block is a list instructions which one entry
85  * at the first instruction and one exit at last instruction. There are no side
86  * entries or exits. A basic block might have several preceding and several
87  * succeeding basic blocs. The last instruction always changes the control flow
88  * via a goto, jump, switch, return, etc. instruction.
89  *
90  * The basic block representation is more restrictive than necessary. Many
91  * instructions are have no dependencies on basic block boundaries. They only
92  * depend on their input operands. So in order to keep the freedom of the
93  * Data Flow Graph a lightweight replacement model for basic blocks is used.
94  * Control flow joins (which would mark the start of a basic block) are
95  * modeled as instructions on its own, namely BeginInst. A BeginInst can
96  * have several predecessors. Control flow changes (end of basic blocks) are
97  * modeled as EndInst. A EndInst may have several successors. Every BeginIns
98  * has exactly one EndInst. Such an instruction pair forms a frame for a
99  * traditional basic block. To model the control flow dependencies of
100  * instructions another type of input edges is introduces, so-called dependency
101  * links. Most instruction do not have any dependency links although some
102  * instructions need them to maintain the semantics, for example PHIInst.
103  * A PHIInst joins values from different preceding control flow paths. The
104  * operands of a PHIInst are in direct correspondence to the predecessors
105  * of the BeginInst they are connected to.
106  *
107  * ## Low level intermediate representation ##
108  *
109  */
110 
111 
113 
114 typedef u1 MachineCode;
115 
117 
118 } // end namespace cacao
119 } // end namespace jit
120 } // end namespace compiler2
121 
122 #endif /* _JIT_COMPILER2_COMPILER */
123 
124 
125 /*
126  * These are local overrides for various environment variables in Emacs.
127  * Please do not remove this and leave it at the end of the file, where
128  * Emacs will automagically detect them.
129  * ---------------------------------------------------------------------
130  * Local variables:
131  * mode: c++
132  * indent-tabs-mode: t
133  * c-basic-offset: 4
134  * tab-width: 4
135  * End:
136  * vim:noexpandtab:sw=4:ts=4:
137  */
MachineCode * compile(methodinfo *m)
Definition: Compiler.cpp:123
uint8_t u1
Definition: types.hpp:40
Option< bool > enabled("DebugCompiler2","compiler with compiler2", false, option::xx_root())
Definition: Compiler.hpp:112
This file contains the command line option parsing library.