Port this test from dejagnu to unit testing.
[oota-llvm.git] / docs / CodeGenerator.html
index 3e965af2793979d8523b8fd15c26bbc4795982d3..009ecd676788ef2b4a8b48c4128dac6b090ed246 100644 (file)
@@ -2,6 +2,7 @@
                       "http://www.w3.org/TR/html4/strict.dtd">
 <html>
 <head>
+  <meta http-equiv="content-type" content="text/html; charset=utf-8">
   <title>The LLVM Target-Independent Code Generator</title>
   <link rel="stylesheet" href="llvm.css" type="text/css">
 </head>
@@ -25,7 +26,7 @@
       <li><a href="#targetmachine">The <tt>TargetMachine</tt> class</a></li>
       <li><a href="#targetdata">The <tt>TargetData</tt> class</a></li>
       <li><a href="#targetlowering">The <tt>TargetLowering</tt> class</a></li>
-      <li><a href="#mregisterinfo">The <tt>MRegisterInfo</tt> class</a></li>
+      <li><a href="#targetregisterinfo">The <tt>TargetRegisterInfo</tt> class</a></li>
       <li><a href="#targetinstrinfo">The <tt>TargetInstrInfo</tt> class</a></li>
       <li><a href="#targetframeinfo">The <tt>TargetFrameInfo</tt> class</a></li>
       <li><a href="#targetsubtarget">The <tt>TargetSubtarget</tt> class</a></li>
@@ -49,6 +50,7 @@
                                           Process</a></li>
       <li><a href="#selectiondag_build">Initial SelectionDAG
                                         Construction</a></li>
+      <li><a href="#selectiondag_legalize_types">SelectionDAG LegalizeTypes Phase</a></li>
       <li><a href="#selectiondag_legalize">SelectionDAG Legalize Phase</a></li>
       <li><a href="#selectiondag_optimize">SelectionDAG Optimization
                                            Phase: the DAG Combiner</a></li>
   </li>
   <li><a href="#targetimpls">Target-specific Implementation Notes</a>
     <ul>
+    <li><a href="#tailcallopt">Tail call optimization</a></li>
     <li><a href="#x86">The X86 backend</a></li>
-    </ul>
-  </li>
+    <li><a href="#ppc">The PowerPC backend</a>
+      <ul>
+      <li><a href="#ppc_abi">LLVM PowerPC ABI</a></li>
+      <li><a href="#ppc_frame">Frame Layout</a></li>
+      <li><a href="#ppc_prolog">Prolog/Epilog</a></li>
+      <li><a href="#ppc_dynamic">Dynamic Allocation</a></li>
+      </ul></li>
+    </ul></li>
 
 </ol>
 
 <div class="doc_author">
   <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>,
-                <a href="mailto:isanbard@gmail.com">Bill Wendling</a>, and
+                <a href="mailto:isanbard@gmail.com">Bill Wendling</a>,
                 <a href="mailto:pronesto@gmail.com">Fernando Magno Quintao
-                                                    Pereira</a></p>
+                                                    Pereira</a> and
+                <a href="mailto:jlaskey@mac.com">Jim Laskey</a></p>
 </div>
 
 <div class="doc_warning">
@@ -374,20 +384,19 @@ operations.  Among other things, this class indicates:</p>
   <li>the type to use for shift amounts</li>
   <li>various high-level characteristics, like whether it is profitable to turn
       division by a constant into a multiplication sequence</li>
-</ol>
+</ul>
 
 </div>
 
 <!-- ======================================================================= -->
 <div class="doc_subsection">
-  <a name="mregisterinfo">The <tt>MRegisterInfo</tt> class</a>
+  <a name="targetregisterinfo">The <tt>TargetRegisterInfo</tt> class</a>
 </div>
 
 <div class="doc_text">
 
-<p>The <tt>MRegisterInfo</tt> class (which will eventually be renamed to
-<tt>TargetRegisterInfo</tt>) is used to describe the register file of the
-target and any interactions between the registers.</p>
+<p>The <tt>TargetRegisterInfo</tt> class is used to describe the register
+file of the target and any interactions between the registers.</p>
 
 <p>Registers in the code generator are represented in the code generator by
 unsigned integers.  Physical registers (those that actually exist in the target
@@ -400,8 +409,8 @@ register (used for assembly output and debugging dumps) and a set of aliases
 (used to indicate whether one register overlaps with another).
 </p>
 
-<p>In addition to the per-register description, the <tt>MRegisterInfo</tt> class
-exposes a set of processor specific register classes (instances of the
+<p>In addition to the per-register description, the <tt>TargetRegisterInfo</tt>
+class exposes a set of processor specific register classes (instances of the
 <tt>TargetRegisterClass</tt> class).  Each register class contains sets of
 registers that have the same properties (for example, they are all 32-bit
 integer registers).  Each SSA virtual register created by the instruction
@@ -613,9 +622,9 @@ copies a virtual register into or out of a physical register when needed.</p>
 
 <div class="doc_code">
 <pre>
-int %test(int %X, int %Y) {
-  %Z = div int %X, %Y
-  ret int %Z
+define i32 @test(i32 %X, i32 %Y) {
+  %Z = udiv i32 %X, %Y
+  ret i32 %Z
 }
 </pre>
 </div>
@@ -711,8 +720,7 @@ comes from.</p>
 corresponds one-to-one with the LLVM function input to the instruction selector.
 In addition to a list of basic blocks, the <tt>MachineFunction</tt> contains a
 a <tt>MachineConstantPool</tt>, a <tt>MachineFrameInfo</tt>, a
-<tt>MachineFunctionInfo</tt>, a <tt>SSARegMap</tt>, and a set of live in and
-live out registers for the function.  See
+<tt>MachineFunctionInfo</tt>, and a <tt>MachineRegisterInfo</tt>.  See
 <tt>include/llvm/CodeGen/MachineFunction.h</tt> for more information.</p>
 
 </div>
@@ -740,16 +748,14 @@ explains how they work and some of the rationale behind their design.</p>
 <p>
 Instruction Selection is the process of translating LLVM code presented to the
 code generator into target-specific machine instructions.  There are several
-well-known ways to do this in the literature.  In LLVM there are two main forms:
-the SelectionDAG based instruction selector framework and an old-style 'simple'
-instruction selector, which effectively peephole selects each LLVM instruction
-into a series of machine instructions.  We recommend that all targets use the
-SelectionDAG infrastructure.
+well-known ways to do this in the literature.  LLVM uses a SelectionDAG based
+instruction selector.
 </p>
 
 <p>Portions of the DAG instruction selector are generated from the target 
 description (<tt>*.td</tt>) files.  Our goal is for the entire instruction
-selector to be generated from these <tt>.td</tt> files.</p>
+selector to be generated from these <tt>.td</tt> files, though currently
+there are still things that require custom C++ code.</p>
 </div>
 
 <!-- _______________________________________________________________________ -->
@@ -782,10 +788,11 @@ define multiple values.  For example, a combined div/rem operation will define
 both the dividend and the remainder. Many other situations require multiple
 values as well.  Each node also has some number of operands, which are edges 
 to the node defining the used value.  Because nodes may define multiple values,
-edges are represented by instances of the <tt>SDOperand</tt> class, which is 
+edges are represented by instances of the <tt>SDValue</tt> class, which is 
 a <tt>&lt;SDNode, unsigned&gt;</tt> pair, indicating the node and result
 value being used, respectively.  Each value produced by an <tt>SDNode</tt> has
-an associated <tt>MVT::ValueType</tt> indicating what type the value is.</p>
+an associated <tt>MVT</tt> (Machine Value Type) indicating what the type of the
+value is.</p>
 
 <p>SelectionDAGs contain two different kinds of values: those that represent
 data flow and those that represent control flow dependencies.  Data values are
@@ -807,8 +814,9 @@ basic block function it would be the return node.</p>
 operations and supported types.  On a 32-bit PowerPC, for example, a DAG with
 a value of type i1, i8, i16, or i64 would be illegal, as would a DAG that uses a
 SREM or UREM operation.  The
-<a href="#selectiondag_legalize">legalize</a> phase is responsible for turning
-an illegal DAG into a legal DAG.</p>
+<a href="#selectinodag_legalize_types">legalize types</a> and
+<a href="#selectiondag_legalize">legalize operations</a> phases are
+responsible for turning an illegal DAG into a legal DAG.</p>
 
 </div>
 
@@ -831,12 +839,18 @@ an illegal DAG into a legal DAG.</p>
     pairs) for targets that support these meta operations.  This makes the
     resultant code more efficient and the <a href="#selectiondag_select">select
     instructions from DAG</a> phase (below) simpler.</li>
-<li><a href="#selectiondag_legalize">Legalize SelectionDAG</a> - This stage
-    converts the illegal SelectionDAG to a legal SelectionDAG by eliminating
-    unsupported operations and data types.</li>
-<li><a href="#selectiondag_optimize">Optimize SelectionDAG (#2)</a> - This
-    second run of the SelectionDAG optimizes the newly legalized DAG to
-    eliminate inefficiencies introduced by legalization.</li>
+<li><a href="#selectiondag_legalize_types">Legalize SelectionDAG Types</a> - This
+    stage transforms SelectionDAG nodes to eliminate any types that are
+    unsupported on the target.</li>
+<li><a href="#selectiondag_optimize">Optimize SelectionDAG</a> - The
+    SelectionDAG optimizer is run to clean up redundancies exposed
+    by type legalization.</li>
+<li><a href="#selectiondag_legalize">Legalize SelectionDAG Types</a> - This
+    stage transforms SelectionDAG nodes to eliminate any types that are
+    unsupported on the target.</li>
+<li><a href="#selectiondag_optimize">Optimize SelectionDAG</a> - The
+    SelectionDAG optimizer is run to eliminate inefficiencies introduced
+    by operation legalization.</li>
 <li><a href="#selectiondag_select">Select instructions from DAG</a> - Finally,
     the target instruction selector matches the DAG operations to target
     instructions.  This process translates the target-independent input DAG into
@@ -851,13 +865,28 @@ an illegal DAG into a legal DAG.</p>
 rest of the code generation passes are run.</p>
 
 <p>One great way to visualize what is going on here is to take advantage of a 
-few LLC command line options.  In particular, the <tt>-view-isel-dags</tt>
-option pops up a window with the SelectionDAG input to the Select phase for all
-of the code compiled (if you only get errors printed to the console while using
-this, you probably <a href="ProgrammersManual.html#ViewGraph">need to configure
-your system</a> to add support for it).  The <tt>-view-sched-dags</tt> option
-views the SelectionDAG output from the Select phase and input to the Scheduler
-phase.</p>
+few LLC command line options.  The following options pop up a window displaying
+the SelectionDAG at specific times (if you only get errors printed to the console
+while using this, you probably
+<a href="ProgrammersManual.html#ViewGraph">need to configure your system</a> to
+add support for it).</p>
+
+<ul>
+<li><tt>-view-dag-combine1-dags</tt> displays the DAG after being built, before
+    the first optimization pass.</li>
+<li><tt>-view-legalize-dags</tt> displays the DAG before Legalization.</li>
+<li><tt>-view-dag-combine2-dags</tt> displays the DAG before the second
+    optimization pass.</li>
+<li><tt>-view-isel-dags</tt> displays the DAG before the Select phase.</li>
+<li><tt>-view-sched-dags</tt> displays the DAG before Scheduling.</li>
+</ul>
+
+<p>The <tt>-view-sunit-dags</tt> displays the Scheduler's dependency graph.
+This graph is based on the final SelectionDAG, with nodes that must be
+scheduled together bundled into a single scheduling-unit node, and with
+immediate operands and other nodes that aren't relevant for scheduling
+omitted.
+</p>
 
 </div>
 
@@ -873,13 +902,47 @@ input by the <tt>SelectionDAGLowering</tt> class in the
 <tt>lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp</tt> file.  The intent of this
 pass is to expose as much low-level, target-specific details to the SelectionDAG
 as possible.  This pass is mostly hard-coded (e.g. an LLVM <tt>add</tt> turns
-into an <tt>SDNode add</tt> while a <tt>geteelementptr</tt> is expanded into the
+into an <tt>SDNode add</tt> while a <tt>getelementptr</tt> is expanded into the
 obvious arithmetic). This pass requires target-specific hooks to lower calls,
 returns, varargs, etc.  For these features, the
 <tt><a href="#targetlowering">TargetLowering</a></tt> interface is used.</p>
 
 </div>
 
+<!-- _______________________________________________________________________ -->
+<div class="doc_subsubsection">
+  <a name="selectiondag_legalize_types">SelectionDAG LegalizeTypes Phase</a>
+</div>
+
+<div class="doc_text">
+
+<p>The Legalize phase is in charge of converting a DAG to only use the types
+that are natively supported by the target.</p>
+
+<p>There are two main ways of converting values of unsupported scalar types
+   to values of supported types: converting small types to 
+   larger types ("promoting"), and breaking up large integer types
+   into smaller ones ("expanding").  For example, a target might require
+   that all f32 values are promoted to f64 and that all i1/i8/i16 values
+   are promoted to i32.  The same target might require that all i64 values
+   be expanded into pairs of i32 values.  These changes can insert sign and
+   zero extensions as needed to make sure that the final code has the same
+   behavior as the input.</p>
+
+<p>There are two main ways of converting values of unsupported vector types
+   to value of supported types: splitting vector types, multiple times if
+   necessary, until a legal type is found, and extending vector types by
+   adding elements to the end to round them out to legal types ("widening").
+   If a vector gets split all the way down to single-element parts with
+   no supported vector type being found, the elements are converted to
+   scalars ("scalarizing").</p>
+
+<p>A target implementation tells the legalizer which types are supported
+   (and which register class to use for them) by calling the
+   <tt>addRegisterClass</tt> method in its TargetLowering constructor.</p>
+
+</div>
+
 <!-- _______________________________________________________________________ -->
 <div class="doc_subsubsection">
   <a name="selectiondag_legalize">SelectionDAG Legalize Phase</a>
@@ -887,46 +950,28 @@ returns, varargs, etc.  For these features, the
 
 <div class="doc_text">
 
-<p>The Legalize phase is in charge of converting a DAG to only use the types and
-operations that are natively supported by the target.  This involves two major
-tasks:</p>
+<p>The Legalize phase is in charge of converting a DAG to only use the
+operations that are natively supported by the target.</p>
 
-<ol>
-<li><p>Convert values of unsupported types to values of supported types.</p>
-    <p>There are two main ways of doing this: converting small types to 
-       larger types ("promoting"), and breaking up large integer types
-       into smaller ones ("expanding").  For example, a target might require
-       that all f32 values are promoted to f64 and that all i1/i8/i16 values
-       are promoted to i32.  The same target might require that all i64 values
-       be expanded into i32 values.  These changes can insert sign and zero
-       extensions as needed to make sure that the final code has the same
-       behavior as the input.</p>
-    <p>A target implementation tells the legalizer which types are supported
-       (and which register class to use for them) by calling the
-       <tt>addRegisterClass</tt> method in its TargetLowering constructor.</p>
-</li>
+<p>Targets often have weird constraints, such as not supporting every
+   operation on every supported datatype (e.g. X86 does not support byte
+   conditional moves and PowerPC does not support sign-extending loads from
+   a 16-bit memory location).  Legalize takes care of this by open-coding
+   another sequence of operations to emulate the operation ("expansion"), by
+   promoting one type to a larger type that supports the operation
+   ("promotion"), or by using a target-specific hook to implement the
+   legalization ("custom").</p>
 
-<li><p>Eliminate operations that are not supported by the target.</p>
-    <p>Targets often have weird constraints, such as not supporting every
-       operation on every supported datatype (e.g. X86 does not support byte
-       conditional moves and PowerPC does not support sign-extending loads from
-       a 16-bit memory location).  Legalize takes care of this by open-coding
-       another sequence of operations to emulate the operation ("expansion"), by
-       promoting one type to a larger type that supports the operation
-       ("promotion"), or by using a target-specific hook to implement the
-       legalization ("custom").</p>
-    <p>A target implementation tells the legalizer which operations are not
-       supported (and which of the above three actions to take) by calling the
-       <tt>setOperationAction</tt> method in its <tt>TargetLowering</tt>
-       constructor.</p>
-</li>
-</ol>
+<p>A target implementation tells the legalizer which operations are not
+   supported (and which of the above three actions to take) by calling the
+   <tt>setOperationAction</tt> method in its <tt>TargetLowering</tt>
+   constructor.</p>
 
-<p>Prior to the existance of the Legalize pass, we required that every target
+<p>Prior to the existence of the Legalize passes, we required that every target
 <a href="#selectiondag_optimize">selector</a> supported and handled every
 operator and type even if they are not natively supported.  The introduction of
-the Legalize phase allows all of the cannonicalization patterns to be shared
-across targets, and makes it very easy to optimize the cannonicalized code
+the Legalize phases allows all of the canonicalization patterns to be shared
+across targets, and makes it very easy to optimize the canonicalized code
 because it is still in the form of a DAG.</p>
 
 </div>
@@ -939,12 +984,12 @@ because it is still in the form of a DAG.</p>
 
 <div class="doc_text">
 
-<p>The SelectionDAG optimization phase is run twice for code generation: once
-immediately after the DAG is built and once after legalization.  The first run
-of the pass allows the initial code to be cleaned up (e.g. performing 
+<p>The SelectionDAG optimization phase is run multiple times for code generation,
+immediately after the DAG is built and once after each legalization.  The first
+run of the pass allows the initial code to be cleaned up (e.g. performing 
 optimizations that depend on knowing that the operators have restricted type 
-inputs).  The second run of the pass cleans up the messy code generated by the 
-Legalize pass, which allows Legalize to be very simple (it can focus on making
+inputs).  Subsequent runs of the pass clean up the messy code generated by the 
+Legalize passes, which allows Legalize to be very simple (it can focus on making
 code legal instead of focusing on generating <em>good</em> and legal code).</p>
 
 <p>One important class of optimizations performed is optimizing inserted sign
@@ -1032,7 +1077,7 @@ def FADDS : AForm_2&lt;59, 21,
 <p>The portion of the instruction definition in bold indicates the pattern used
 to match the instruction.  The DAG operators (like <tt>fmul</tt>/<tt>fadd</tt>)
 are defined in the <tt>lib/Target/TargetSelectionDAG.td</tt> file.  
-"<tt>F4RC</tt>" is the register class of the input and result values.<p>
+"<tt>F4RC</tt>" is the register class of the input and result values.</p>
 
 <p>The TableGen DAG instruction selector generator reads the instruction 
 patterns in the <tt>.td</tt> file and automatically builds parts of the pattern
@@ -1103,11 +1148,12 @@ primarily because it is a work in progress and is not yet finished:</p>
 <li>There is no great way to support matching complex addressing modes yet.  In
     the future, we will extend pattern fragments to allow them to define
     multiple values (e.g. the four operands of the <a href="#x86_memory">X86
-    addressing mode</a>).  In addition, we'll extend fragments so that a
+    addressing mode</a>, which are currently matched with custom C++ code).
+    In addition, we'll extend fragments so that a
     fragment can match multiple different patterns.</li>
 <li>We don't automatically infer flags like isStore/isLoad yet.</li>
 <li>We don't automatically generate the set of supported registers and
-    operations for the <a href="#"selectiondag_legalize>Legalizer</a> yet.</li>
+    operations for the <a href="#selectiondag_legalize">Legalizer</a> yet.</li>
 <li>We don't have a way of tying in custom legalized nodes yet.</li>
 </ul>
 
@@ -1148,7 +1194,6 @@ SelectionDAGs.</p>
 <ol>
 <li>Optional function-at-a-time selection.</li>
 <li>Auto-generate entire selector from <tt>.td</tt> file.</li>
-</li>
 </ol>
 
 </div>
@@ -1168,9 +1213,9 @@ SelectionDAGs.</p>
 
 <p>Live Intervals are the ranges (intervals) where a variable is <i>live</i>.
 They are used by some <a href="#regalloc">register allocator</a> passes to
-determine if two or more virtual registers which require the same register are
-live at the same point in the program (conflict).  When this situation occurs,
-one virtual register must be <i>spilled</i>.</p>
+determine if two or more virtual registers which require the same physical
+register are live at the same point in the program (i.e., they conflict).  When
+this situation occurs, one virtual register must be <i>spilled</i>.</p>
 
 </div>
 
@@ -1186,10 +1231,10 @@ calculate the set of registers that are immediately dead after the
 instruction (i.e., the instruction calculates the value, but it is
 never used) and the set of registers that are used by the instruction,
 but are never used after the instruction (i.e., they are killed). Live
-variable information is computed for each <i>virtual</i> and
+variable information is computed for each <i>virtual</i> register and
 <i>register allocatable</i> physical register in the function.  This
 is done in a very efficient manner because it uses SSA to sparsely
-computer lifetime information for virtual registers (which are in SSA
+compute lifetime information for virtual registers (which are in SSA
 form) and only has to track physical registers within a block.  Before
 register allocation, LLVM can assume that physical registers are only
 live within a single basic block.  This allows it to do a single,
@@ -1200,14 +1245,14 @@ a stack pointer or condition codes), it is not tracked.</p>
 <p>Physical registers may be live in to or out of a function. Live in values
 are typically arguments in registers. Live out values are typically return
 values in registers. Live in values are marked as such, and are given a dummy
-"defining" instruction during live interval analysis. If the last basic block
+"defining" instruction during live intervals analysis. If the last basic block
 of a function is a <tt>return</tt>, then it's marked as using all live out
 values in the function.</p>
 
 <p><tt>PHI</tt> nodes need to be handled specially, because the calculation
 of the live variable information from a depth first traversal of the CFG of
 the function won't guarantee that a virtual register used by the <tt>PHI</tt>
-node is defined before it's used. When a <tt>PHI</tt> node is encounted, only
+node is defined before it's used. When a <tt>PHI</tt> node is encountered, only
 the definition is handled, because the uses will be handled in other basic
 blocks.</p>
 
@@ -1227,8 +1272,17 @@ defining instruction is encountered.</p>
 </div>
 
 <div class="doc_text">
-<p>To Be Written</p>
-</ol>
+
+<p>We now have the information available to perform the live intervals analysis
+and build the live intervals themselves.  We start off by numbering the basic
+blocks and machine instructions.  We then handle the "live-in" values.  These
+are in physical registers, so the physical register is assumed to be killed by
+the end of the basic block.  Live intervals for virtual registers are computed
+for some ordering of the machine instructions <tt>[1, N]</tt>.  A live interval
+is an interval <tt>[i, j)</tt>, where <tt>1 &lt;= i &lt;= j &lt; N</tt>, for which a
+variable is live.</p>
+
+<p><i><b>More to come...</b></i></p>
 
 </div>
 
@@ -1239,14 +1293,14 @@ defining instruction is encountered.</p>
 
 <div class="doc_text">
 
-<p>The <i>Register Allocation problem</i> consists in mapping a
-program <i>P<sub>v</sub></i>, that can use an unbounded number of
-virtual registers, to a program <i>P<sub>p</sub></i> that contains a
-finite (possibly small) number of physical registers. Each target
-architecture has a different number of physical registers. If the
-number of physical registers is not enough to accommodate all the
-virtual registers, some of them will have to be mapped into
-memory. These virtuals are called <i>spilled virtuals</i>.</p>
+<p>The <i>Register Allocation problem</i> consists in mapping a program
+<i>P<sub>v</sub></i>, that can use an unbounded number of virtual
+registers, to a program <i>P<sub>p</sub></i> that contains a finite
+(possibly small) number of physical registers. Each target architecture has
+a different number of physical registers. If the number of physical
+registers is not enough to accommodate all the virtual registers, some of
+them will have to be mapped into memory. These virtuals are called
+<i>spilled virtuals</i>.</p>
 
 </div>
 
@@ -1274,7 +1328,7 @@ X86 architecture, the registers <tt>EAX</tt>, <tt>AX</tt> and
 marked as <i>aliased</i> in LLVM. Given a particular architecture, you
 can check which registers are aliased by inspecting its
 <tt>RegisterInfo.td</tt> file. Moreover, the method
-<tt>MRegisterInfo::getAliasSet(p_reg)</tt> returns an array containing
+<tt>TargetRegisterInfo::getAliasSet(p_reg)</tt> returns an array containing
 all the physical registers aliased to the register <tt>p_reg</tt>.</p>
 
 <p>Physical registers, in LLVM, are grouped in <i>Register Classes</i>.
@@ -1289,13 +1343,13 @@ this code can be used:
 
 <div class="doc_code">
 <pre>
-bool RegMapping_Fer::compatible_class(MachineFunction &mf,
+bool RegMapping_Fer::compatible_class(MachineFunction &amp;mf,
                                       unsigned v_reg,
                                       unsigned p_reg) {
-  assert(MRegisterInfo::isPhysicalRegister(p_reg) &&
+  assert(TargetRegisterInfo::isPhysicalRegister(p_reg) &amp;&amp;
          "Target register must be physical");
-  const TargetRegisterClass *trc = mf.getSSARegMap()->getRegClass(v_reg);
-  return trc->contains(p_reg);
+  const TargetRegisterClass *trc = mf.getRegInfo().getRegClass(v_reg);
+  return trc-&gt;contains(p_reg);
 }
 </pre>
 </div>
@@ -1317,14 +1371,14 @@ physical registers, different virtual registers never share the same
 number. The smallest virtual register is normally assigned the number
 1024. This may change, so, in order to know which is the first virtual
 register, you should access
-<tt>MRegisterInfo::FirstVirtualRegister</tt>. Any register whose
+<tt>TargetRegisterInfo::FirstVirtualRegister</tt>. Any register whose
 number is greater than or equal to
-<tt>MRegisterInfo::FirstVirtualRegister</tt> is considered a virtual
+<tt>TargetRegisterInfo::FirstVirtualRegister</tt> is considered a virtual
 register. Whereas physical registers are statically defined in a
 <tt>TargetRegisterInfo.td</tt> file and cannot be created by the
 application developer, that is not the case with virtual registers.
 In order to create new virtual registers, use the method
-<tt>SSARegMap::createVirtualRegister()</tt>. This method will return a
+<tt>MachineRegisterInfo::createVirtualRegister()</tt>. This method will return a
 virtual register with the highest code.
 </p>
 
@@ -1341,7 +1395,7 @@ if that register is being used by the instruction. The method
 <tt>MachineOperand::isDef()</tt> informs if that registers is being
 defined.</p>
 
-<p>We will call physical registers present in the LLVM bytecode before
+<p>We will call physical registers present in the LLVM bitcode before
 register allocation <i>pre-colored registers</i>. Pre-colored
 registers are used in many different situations, for instance, to pass
 parameters of functions calls, and to store results of particular
@@ -1376,7 +1430,7 @@ overwritten by the values of virtual registers while still alive.</p>
 
 <p>There are two ways to map virtual registers to physical registers (or to
 memory slots). The first way, that we will call <i>direct mapping</i>,
-is based on the use of methods of the classes <tt>MRegisterInfo</tt>,
+is based on the use of methods of the classes <tt>TargetRegisterInfo</tt>,
 and <tt>MachineOperand</tt>. The second way, that we will call
 <i>indirect mapping</i>, relies on the <tt>VirtRegMap</tt> class in
 order to insert loads and stores sending and getting values to and from
@@ -1390,8 +1444,8 @@ target function being compiled in order to get and store values in
 memory. To assign a physical register to a virtual register present in
 a given operand, use <tt>MachineOperand::setReg(p_reg)</tt>. To insert
 a store instruction, use
-<tt>MRegisterInfo::storeRegToStackSlot(...)</tt>, and to insert a load
-instruction, use <tt>MRegisterInfo::loadRegFromStackSlot</tt>.</p>
+<tt>TargetRegisterInfo::storeRegToStackSlot(...)</tt>, and to insert a load
+instruction, use <tt>TargetRegisterInfo::loadRegFromStackSlot</tt>.</p>
 
 <p>The indirect mapping shields the application developer from the
 complexities of inserting load and store instructions. In order to map
@@ -1449,12 +1503,12 @@ instance, in situations where an instruction such as <tt>%a = ADD %b
 <div class="doc_code">
 <pre>
 %a = MOVE %b
-%a = ADD %a %b
+%a = ADD %a %c
 </pre>
 </div>
 
 <p>Notice that, internally, the second instruction is represented as
-<tt>ADD %a[def/use] %b</tt>. I.e., the register operand <tt>%a</tt> is
+<tt>ADD %a[def/use] %c</tt>. I.e., the register operand <tt>%a</tt> is
 both used and defined by the instruction.</p>
 
 </div>
@@ -1478,7 +1532,7 @@ semantics.</p>
 from the target code. The most traditional PHI deconstruction
 algorithm replaces PHI instructions with copy instructions. That is
 the strategy adopted by LLVM. The SSA deconstruction algorithm is
-implemented in n<tt>lib/CodeGen/>PHIElimination.cpp</tt>. In order to
+implemented in <tt>lib/CodeGen/PHIElimination.cpp</tt>. In order to
 invoke this pass, the identifier <tt>PHIEliminationID</tt> must be
 marked as required in the code of the register allocator.</p>
 
@@ -1502,7 +1556,7 @@ instance, a sequence of instructions such as:</p>
 </pre>
 </div>
 
-<p>can be safely substituted by the single instruction:
+<p>can be safely substituted by the single instruction:</p>
 
 <div class="doc_code">
 <pre>
@@ -1511,7 +1565,7 @@ instance, a sequence of instructions such as:</p>
 </div>
 
 <p>Instructions can be folded with the
-<tt>MRegisterInfo::foldMemoryOperand(...)</tt> method. Care must be
+<tt>TargetRegisterInfo::foldMemoryOperand(...)</tt> method. Care must be
 taken when folding instructions; a folded instruction can be quite
 different from the original instruction. See
 <tt>LiveIntervals::addIntervalsForSpills</tt> in
@@ -1603,7 +1657,51 @@ are specific to the code generator for a particular target.</p>
 
 </div>
 
+<!-- ======================================================================= -->
+<div class="doc_subsection">
+  <a name="tailcallopt">Tail call optimization</a>
+</div>
+
+<div class="doc_text">
+  <p>Tail call optimization, callee reusing the stack of the caller, is currently supported on x86/x86-64 and PowerPC. It is performed if:
+    <ul>
+      <li>Caller and callee have the calling convention <tt>fastcc</tt>.</li>
+      <li>The call is a tail call - in tail position (ret immediately follows call and ret uses value of call or is void).</li>
+      <li>Option <tt>-tailcallopt</tt> is enabled.</li>
+      <li>Platform specific constraints are met.</li>
+    </ul>
+  </p>
 
+  <p>x86/x86-64 constraints:
+    <ul>
+      <li>No variable argument lists are used.</li>
+      <li>On x86-64 when generating GOT/PIC code only module-local calls (visibility = hidden or protected) are supported.</li>
+    </ul>
+  </p>
+  <p>PowerPC constraints:
+    <ul>
+      <li>No variable argument lists are used.</li>
+      <li>No byval parameters are used.</li>
+      <li>On ppc32/64 GOT/PIC only module-local calls (visibility = hidden or protected) are supported.</li>
+    </ul>
+  </p>
+  <p>Example:</p>
+  <p>Call as <tt>llc -tailcallopt test.ll</tt>.
+    <div class="doc_code">
+      <pre>
+declare fastcc i32 @tailcallee(i32 inreg %a1, i32 inreg %a2, i32 %a3, i32 %a4)
+
+define fastcc i32 @tailcaller(i32 %in1, i32 %in2) {
+  %l1 = add i32 %in1, %in2
+  %tmp = tail call fastcc i32 @tailcallee(i32 %in1 inreg, i32 %in2 inreg, i32 %in1, i32 %l1)
+  ret i32 %tmp
+}</pre>
+    </div>
+  </p>
+  <p>Implications of <tt>-tailcallopt</tt>:</p>
+  <p>To support tail call optimization in situations where the callee has more arguments than the caller a 'callee pops arguments' convention is used. This currently causes each <tt>fastcc</tt> call that is not tail call optimized (because one or more of above constraints are not met) to be followed by a readjustment of the stack. So performance might be worse in such cases.</p>
+  <p>On x86 and x86-64 one register is reserved for indirect tail calls (e.g via a function pointer). So there is one less register for integer argument passing. For x86 this means 2 registers (if <tt>inreg</tt> parameter attribute is used) and for x86-64 this means 5 register are used.</p>
+</div>
 <!-- ======================================================================= -->
 <div class="doc_subsection">
   <a name="x86">The X86 backend</a>
@@ -1612,11 +1710,9 @@ are specific to the code generator for a particular target.</p>
 <div class="doc_text">
 
 <p>The X86 code generator lives in the <tt>lib/Target/X86</tt> directory.  This
-code generator currently targets a generic P6-like processor.  As such, it
-produces a few P6-and-above instructions (like conditional moves), but it does
-not make use of newer features like MMX or SSE.  In the future, the X86 backend
-will have sub-target support added for specific processor families and 
-implementations.</p>
+code generator is capable of targeting a variety of x86-32 and x86-64
+processors, and includes support for ISA extensions such as MMX and SSE.
+</p>
 
 </div>
 
@@ -1636,11 +1732,31 @@ that people test.</p>
 <li><b>i386-unknown-freebsd5.3</b> - FreeBSD 5.3</li>
 <li><b>i686-pc-cygwin</b> - Cygwin on Win32</li>
 <li><b>i686-pc-mingw32</b> - MingW on Win32</li>
+<li><b>i386-pc-mingw32msvc</b> - MingW crosscompiler on Linux</li>
 <li><b>i686-apple-darwin*</b> - Apple Darwin on X86</li>
 </ul>
 
 </div>
 
+<!-- _______________________________________________________________________ -->
+<div class="doc_subsubsection">
+  <a name="x86_cc">X86 Calling Conventions supported</a>
+</div>
+
+
+<div class="doc_text">
+
+<p>The following target-specific calling conventions are known to backend:</p>
+
+<ul>
+<li><b>x86_StdCall</b> - stdcall calling convention seen on Microsoft Windows
+platform (CC ID = 64).</li>
+<li><b>x86_FastCall</b> - fastcall calling convention seen on Microsoft Windows
+platform (CC ID = 65).</li>
+</ul>
+
+</div>
+
 <!-- _______________________________________________________________________ -->
 <div class="doc_subsubsection">
   <a name="x86_memory">Representing X86 addressing modes in MachineInstrs</a>
@@ -1692,13 +1808,230 @@ a character per operand with an optional special size. For example:</p>
 
 </div>
 
+<!-- ======================================================================= -->
+<div class="doc_subsection">
+  <a name="ppc">The PowerPC backend</a>
+</div>
+
+<div class="doc_text">
+<p>The PowerPC code generator lives in the lib/Target/PowerPC directory.  The
+code generation is retargetable to several variations or <i>subtargets</i> of
+the PowerPC ISA; including ppc32, ppc64 and altivec.
+</p>
+</div>
+
+<!-- _______________________________________________________________________ -->
+<div class="doc_subsubsection">
+  <a name="ppc_abi">LLVM PowerPC ABI</a>
+</div>
+
+<div class="doc_text">
+<p>LLVM follows the AIX PowerPC ABI, with two deviations. LLVM uses a PC
+relative (PIC) or static addressing for accessing global values, so no TOC (r2)
+is used. Second, r31 is used as a frame pointer to allow dynamic growth of a
+stack frame.  LLVM takes advantage of having no TOC to provide space to save
+the frame pointer in the PowerPC linkage area of the caller frame.  Other
+details of PowerPC ABI can be found at <a href=
+"http://developer.apple.com/documentation/DeveloperTools/Conceptual/LowLevelABI/Articles/32bitPowerPC.html"
+>PowerPC ABI.</a> Note: This link describes the 32 bit ABI.  The
+64 bit ABI is similar except space for GPRs are 8 bytes wide (not 4) and r13 is
+reserved for system use.</p>
+</div>
+
+<!-- _______________________________________________________________________ -->
+<div class="doc_subsubsection">
+  <a name="ppc_frame">Frame Layout</a>
+</div>
+
+<div class="doc_text">
+<p>The size of a PowerPC frame is usually fixed for the duration of a
+function&rsquo;s invocation.  Since the frame is fixed size, all references into
+the frame can be accessed via fixed offsets from the stack pointer.  The
+exception to this is when dynamic alloca or variable sized arrays are present,
+then a base pointer (r31) is used as a proxy for the stack pointer and stack
+pointer is free to grow or shrink.  A base pointer is also used if llvm-gcc is
+not passed the -fomit-frame-pointer flag. The stack pointer is always aligned to
+16 bytes, so that space allocated for altivec vectors will be properly
+aligned.</p>
+<p>An invocation frame is laid out as follows (low memory at top);</p>
+</div>
+
+<div class="doc_text">
+<table class="layout">
+       <tr>
+               <td>Linkage<br><br></td>
+       </tr>
+       <tr>
+               <td>Parameter area<br><br></td>
+       </tr>
+       <tr>
+               <td>Dynamic area<br><br></td>
+       </tr>
+       <tr>
+               <td>Locals area<br><br></td>
+       </tr>
+       <tr>
+               <td>Saved registers area<br><br></td>
+       </tr>
+       <tr style="border-style: none hidden none hidden;">
+               <td><br></td>
+       </tr>
+       <tr>
+               <td>Previous Frame<br><br></td>
+       </tr>
+</table>
+</div>
+
+<div class="doc_text">
+<p>The <i>linkage</i> area is used by a callee to save special registers prior
+to allocating its own frame.  Only three entries are relevant to LLVM. The
+first entry is the previous stack pointer (sp), aka link.  This allows probing
+tools like gdb or exception handlers to quickly scan the frames in the stack.  A
+function epilog can also use the link to pop the frame from the stack.  The
+third entry in the linkage area is used to save the return address from the lr
+register. Finally, as mentioned above, the last entry is used to save the
+previous frame pointer (r31.)  The entries in the linkage area are the size of a
+GPR, thus the linkage area is 24 bytes long in 32 bit mode and 48 bytes in 64
+bit mode.</p>
+</div>
+
+<div class="doc_text">
+<p>32 bit linkage area</p>
+<table class="layout">
+       <tr>
+               <td>0</td>
+               <td>Saved SP (r1)</td>
+       </tr>
+       <tr>
+               <td>4</td>
+               <td>Saved CR</td>
+       </tr>
+       <tr>
+               <td>8</td>
+               <td>Saved LR</td>
+       </tr>
+       <tr>
+               <td>12</td>
+               <td>Reserved</td>
+       </tr>
+       <tr>
+               <td>16</td>
+               <td>Reserved</td>
+       </tr>
+       <tr>
+               <td>20</td>
+               <td>Saved FP (r31)</td>
+       </tr>
+</table>
+</div>
+
+<div class="doc_text">
+<p>64 bit linkage area</p>
+<table class="layout">
+       <tr>
+               <td>0</td>
+               <td>Saved SP (r1)</td>
+       </tr>
+       <tr>
+               <td>8</td>
+               <td>Saved CR</td>
+       </tr>
+       <tr>
+               <td>16</td>
+               <td>Saved LR</td>
+       </tr>
+       <tr>
+               <td>24</td>
+               <td>Reserved</td>
+       </tr>
+       <tr>
+               <td>32</td>
+               <td>Reserved</td>
+       </tr>
+       <tr>
+               <td>40</td>
+               <td>Saved FP (r31)</td>
+       </tr>
+</table>
+</div>
+
+<div class="doc_text">
+<p>The <i>parameter area</i> is used to store arguments being passed to a callee
+function.  Following the PowerPC ABI, the first few arguments are actually
+passed in registers, with the space in the parameter area unused.  However, if
+there are not enough registers or the callee is a thunk or vararg function,
+these register arguments can be spilled into the parameter area.  Thus, the
+parameter area must be large enough to store all the parameters for the largest
+call sequence made by the caller.  The size must also be minimally large enough
+to spill registers r3-r10.  This allows callees blind to the call signature,
+such as thunks and vararg functions, enough space to cache the argument
+registers.  Therefore, the parameter area is minimally 32 bytes (64 bytes in 64
+bit mode.)  Also note that since the parameter area is a fixed offset from the
+top of the frame, that a callee can access its spilt arguments using fixed
+offsets from the stack pointer (or base pointer.)</p>
+</div>
+
+<div class="doc_text">
+<p>Combining the information about the linkage, parameter areas and alignment. A
+stack frame is minimally 64 bytes in 32 bit mode and 128 bytes in 64 bit
+mode.</p>
+</div>
+
+<div class="doc_text">
+<p>The <i>dynamic area</i> starts out as size zero.  If a function uses dynamic
+alloca then space is added to the stack, the linkage and parameter areas are
+shifted to top of stack, and the new space is available immediately below the
+linkage and parameter areas.  The cost of shifting the linkage and parameter
+areas is minor since only the link value needs to be copied.  The link value can
+be easily fetched by adding the original frame size to the base pointer.  Note
+that allocations in the dynamic space need to observe 16 byte alignment.</p>
+</div>
+
+<div class="doc_text">
+<p>The <i>locals area</i> is where the llvm compiler reserves space for local
+variables.</p>
+</div>
+
+<div class="doc_text">
+<p>The <i>saved registers area</i> is where the llvm compiler spills callee saved
+registers on entry to the callee.</p>
+</div>
+
+<!-- _______________________________________________________________________ -->
+<div class="doc_subsubsection">
+  <a name="ppc_prolog">Prolog/Epilog</a>
+</div>
+
+<div class="doc_text">
+<p>The llvm prolog and epilog are the same as described in the PowerPC ABI, with
+the following exceptions.  Callee saved registers are spilled after the frame is
+created.  This allows the llvm epilog/prolog support to be common with other
+targets.  The base pointer callee saved register r31 is saved in the TOC slot of
+linkage area.  This simplifies allocation of space for the base pointer and
+makes it convenient to locate programatically and during debugging.</p>
+</div>
+
+<!-- _______________________________________________________________________ -->
+<div class="doc_subsubsection">
+  <a name="ppc_dynamic">Dynamic Allocation</a>
+</div>
+
+<div class="doc_text">
+<p></p>
+</div>
+
+<div class="doc_text">
+<p><i>TODO - More to come.</i></p>
+</div>
+
+
 <!-- *********************************************************************** -->
 <hr>
 <address>
   <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
-  src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
+  src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a>
   <a href="http://validator.w3.org/check/referer"><img
-  src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
+  src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a>
 
   <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
   <a href="http://llvm.org">The LLVM Compiler Infrastructure</a><br>