| Misha Brukman | c501f55 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | 
|  | 2 | "http://www.w3.org/TR/html4/strict.dtd"> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3 | <html> | 
|  | 4 | <head> | 
|  | 5 | <title>LLVM Assembly Language Reference Manual</title> | 
| Reid Spencer | cb84e43 | 2004-08-26 20:44:00 +0000 | [diff] [blame] | 6 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | 
|  | 7 | <meta name="author" content="Chris Lattner"> | 
|  | 8 | <meta name="description" | 
|  | 9 | content="LLVM Assembly Language Reference Manual."> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 10 | <link rel="stylesheet" href="llvm.css" type="text/css"> | 
|  | 11 | </head> | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 12 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 13 | <body> | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 14 |  | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 15 | <div class="doc_title"> LLVM Language Reference Manual </div> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 16 | <ol> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 17 | <li><a href="#abstract">Abstract</a></li> | 
|  | 18 | <li><a href="#introduction">Introduction</a></li> | 
|  | 19 | <li><a href="#identifiers">Identifiers</a></li> | 
| Chris Lattner | 6af02f3 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 20 | <li><a href="#highlevel">High Level Structure</a> | 
|  | 21 | <ol> | 
|  | 22 | <li><a href="#modulestructure">Module Structure</a></li> | 
| Chris Lattner | d79749a | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 23 | <li><a href="#linkage">Linkage Types</a></li> | 
| Chris Lattner | 0132aff | 2005-05-06 22:57:40 +0000 | [diff] [blame^] | 24 | <li><a href="#callingconv">Calling Conventions</a></li> | 
| Chris Lattner | 6af02f3 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 25 | <li><a href="#globalvars">Global Variables</a></li> | 
|  | 26 | <li><a href="#functionstructure">Function Structure</a></li> | 
|  | 27 | </ol> | 
|  | 28 | </li> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 29 | <li><a href="#typesystem">Type System</a> | 
|  | 30 | <ol> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 31 | <li><a href="#t_primitive">Primitive Types</a> | 
|  | 32 | <ol> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 33 | <li><a href="#t_classifications">Type Classifications</a></li> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 34 | </ol> | 
|  | 35 | </li> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 36 | <li><a href="#t_derived">Derived Types</a> | 
|  | 37 | <ol> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 38 | <li><a href="#t_array">Array Type</a></li> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 39 | <li><a href="#t_function">Function Type</a></li> | 
|  | 40 | <li><a href="#t_pointer">Pointer Type</a></li> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 41 | <li><a href="#t_struct">Structure Type</a></li> | 
| Chris Lattner | c8cb695 | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 42 | <li><a href="#t_packed">Packed Type</a></li> | 
| Chris Lattner | 37b6b09 | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 43 | <li><a href="#t_opaque">Opaque Type</a></li> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 44 | </ol> | 
|  | 45 | </li> | 
|  | 46 | </ol> | 
|  | 47 | </li> | 
| Chris Lattner | 6af02f3 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 48 | <li><a href="#constants">Constants</a> | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 49 | <ol> | 
|  | 50 | <li><a href="#simpleconstants">Simple Constants</a> | 
|  | 51 | <li><a href="#aggregateconstants">Aggregate Constants</a> | 
|  | 52 | <li><a href="#globalconstants">Global Variable and Function Addresses</a> | 
|  | 53 | <li><a href="#undefvalues">Undefined Values</a> | 
|  | 54 | <li><a href="#constantexprs">Constant Expressions</a> | 
|  | 55 | </ol> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 56 | </li> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 57 | <li><a href="#instref">Instruction Reference</a> | 
|  | 58 | <ol> | 
|  | 59 | <li><a href="#terminators">Terminator Instructions</a> | 
|  | 60 | <ol> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 61 | <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li> | 
|  | 62 | <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 63 | <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li> | 
|  | 64 | <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 65 | <li><a href="#i_unwind">'<tt>unwind</tt>'  Instruction</a></li> | 
| Chris Lattner | 08b7d5b | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 66 | <li><a href="#i_unreachable">'<tt>unreachable</tt>' Instruction</a></li> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 67 | </ol> | 
|  | 68 | </li> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 69 | <li><a href="#binaryops">Binary Operations</a> | 
|  | 70 | <ol> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 71 | <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li> | 
|  | 72 | <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li> | 
|  | 73 | <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li> | 
|  | 74 | <li><a href="#i_div">'<tt>div</tt>' Instruction</a></li> | 
|  | 75 | <li><a href="#i_rem">'<tt>rem</tt>' Instruction</a></li> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 76 | <li><a href="#i_setcc">'<tt>set<i>cc</i></tt>' Instructions</a></li> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 77 | </ol> | 
|  | 78 | </li> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 79 | <li><a href="#bitwiseops">Bitwise Binary Operations</a> | 
|  | 80 | <ol> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 81 | <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 82 | <li><a href="#i_or">'<tt>or</tt>'  Instruction</a></li> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 83 | <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li> | 
|  | 84 | <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li> | 
|  | 85 | <li><a href="#i_shr">'<tt>shr</tt>' Instruction</a></li> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 86 | </ol> | 
|  | 87 | </li> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 88 | <li><a href="#memoryops">Memory Access Operations</a> | 
|  | 89 | <ol> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 90 | <li><a href="#i_malloc">'<tt>malloc</tt>'   Instruction</a></li> | 
|  | 91 | <li><a href="#i_free">'<tt>free</tt>'     Instruction</a></li> | 
|  | 92 | <li><a href="#i_alloca">'<tt>alloca</tt>'   Instruction</a></li> | 
|  | 93 | <li><a href="#i_load">'<tt>load</tt>'     Instruction</a></li> | 
|  | 94 | <li><a href="#i_store">'<tt>store</tt>'    Instruction</a></li> | 
|  | 95 | <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li> | 
|  | 96 | </ol> | 
|  | 97 | </li> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 98 | <li><a href="#otherops">Other Operations</a> | 
|  | 99 | <ol> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 100 | <li><a href="#i_phi">'<tt>phi</tt>'   Instruction</a></li> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 101 | <li><a href="#i_cast">'<tt>cast .. to</tt>' Instruction</a></li> | 
| Chris Lattner | b53c28d | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 102 | <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 103 | <li><a href="#i_call">'<tt>call</tt>'  Instruction</a></li> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 104 | <li><a href="#i_vanext">'<tt>vanext</tt>' Instruction</a></li> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 105 | <li><a href="#i_vaarg">'<tt>vaarg</tt>'  Instruction</a></li> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 106 | </ol> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 107 | </li> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 108 | </ol> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 109 | </li> | 
| Chris Lattner | bd64b4e | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 110 | <li><a href="#intrinsics">Intrinsic Functions</a> | 
| Chris Lattner | bd64b4e | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 111 | <ol> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 112 | <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a> | 
|  | 113 | <ol> | 
|  | 114 | <li><a href="#i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li> | 
|  | 115 | <li><a href="#i_va_end">'<tt>llvm.va_end</tt>'   Intrinsic</a></li> | 
|  | 116 | <li><a href="#i_va_copy">'<tt>llvm.va_copy</tt>'  Intrinsic</a></li> | 
|  | 117 | </ol> | 
|  | 118 | </li> | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 119 | <li><a href="#int_gc">Accurate Garbage Collection Intrinsics</a> | 
|  | 120 | <ol> | 
|  | 121 | <li><a href="#i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a></li> | 
|  | 122 | <li><a href="#i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a></li> | 
|  | 123 | <li><a href="#i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a></li> | 
|  | 124 | </ol> | 
|  | 125 | </li> | 
| Chris Lattner | 3649c3a | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 126 | <li><a href="#int_codegen">Code Generator Intrinsics</a> | 
|  | 127 | <ol> | 
|  | 128 | <li><a href="#i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li> | 
|  | 129 | <li><a href="#i_frameaddress">'<tt>llvm.frameaddress</tt>'   Intrinsic</a></li> | 
| Chris Lattner | c8a2c22 | 2005-02-28 19:24:19 +0000 | [diff] [blame] | 130 | <li><a href="#i_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a></li> | 
| Andrew Lenharth | b442791 | 2005-03-28 20:05:49 +0000 | [diff] [blame] | 131 | <li><a href="#i_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a></li> | 
| John Criswell | aa1c3c1 | 2004-04-09 16:43:20 +0000 | [diff] [blame] | 132 | </ol> | 
|  | 133 | </li> | 
|  | 134 | <li><a href="#int_os">Operating System Intrinsics</a> | 
|  | 135 | <ol> | 
| Chris Lattner | 3b4f437 | 2004-06-11 02:28:03 +0000 | [diff] [blame] | 136 | <li><a href="#i_readport">'<tt>llvm.readport</tt>' Intrinsic</a></li> | 
|  | 137 | <li><a href="#i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a></li> | 
| John Criswell | a450122 | 2004-04-12 15:02:16 +0000 | [diff] [blame] | 138 | <li><a href="#i_readio">'<tt>llvm.readio</tt>'   Intrinsic</a></li> | 
|  | 139 | <li><a href="#i_writeio">'<tt>llvm.writeio</tt>'   Intrinsic</a></li> | 
| Chris Lattner | 3649c3a | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 140 | </ol> | 
| Chris Lattner | fee1146 | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 141 | <li><a href="#int_libc">Standard C Library Intrinsics</a> | 
|  | 142 | <ol> | 
|  | 143 | <li><a href="#i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a></li> | 
| Chris Lattner | f30152e | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 144 | <li><a href="#i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a></li> | 
| Chris Lattner | 3649c3a | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 145 | <li><a href="#i_memset">'<tt>llvm.memset</tt>' Intrinsic</a></li> | 
| Alkis Evlogimenos | 9d74062 | 2004-06-12 19:19:14 +0000 | [diff] [blame] | 146 | <li><a href="#i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a></li> | 
| Chris Lattner | fee1146 | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 147 | </ol> | 
|  | 148 | </li> | 
| Andrew Lenharth | 1d46352 | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 149 | <li><a href="#int_count">Bit counting Intrinsics</a> | 
|  | 150 | <ol> | 
|  | 151 | <li><a href="#int_ctpop">'<tt>llvm.ctpop</tt>' Intrinsic </a></li> | 
|  | 152 | <li><a href="#int_cttz">'<tt>llvm.cttz</tt>' Intrinsic </a></li> | 
|  | 153 | <li><a href="#int_ctlz">'<tt>llvm.ctlz</tt>' Intrinsic </a></li> | 
|  | 154 | </ol> | 
|  | 155 | </li> | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 156 | <li><a href="#int_debugger">Debugger intrinsics</a></li> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 157 | </ol> | 
|  | 158 | </li> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 159 | </ol> | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 160 |  | 
|  | 161 | <div class="doc_author"> | 
|  | 162 | <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a> | 
|  | 163 | and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></p> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 164 | </div> | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 165 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 166 | <!-- *********************************************************************** --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 167 | <div class="doc_section"> <a name="abstract">Abstract </a></div> | 
|  | 168 | <!-- *********************************************************************** --> | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 169 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 170 | <div class="doc_text"> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 171 | <p>This document is a reference manual for the LLVM assembly language. | 
|  | 172 | LLVM is an SSA based representation that provides type safety, | 
|  | 173 | low-level operations, flexibility, and the capability of representing | 
|  | 174 | 'all' high-level languages cleanly.  It is the common code | 
|  | 175 | representation used throughout all phases of the LLVM compilation | 
|  | 176 | strategy.</p> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 177 | </div> | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 178 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 179 | <!-- *********************************************************************** --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 180 | <div class="doc_section"> <a name="introduction">Introduction</a> </div> | 
|  | 181 | <!-- *********************************************************************** --> | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 182 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 183 | <div class="doc_text"> | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 184 |  | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 185 | <p>The LLVM code representation is designed to be used in three | 
|  | 186 | different forms: as an in-memory compiler IR, as an on-disk bytecode | 
|  | 187 | representation (suitable for fast loading by a Just-In-Time compiler), | 
|  | 188 | and as a human readable assembly language representation.  This allows | 
|  | 189 | LLVM to provide a powerful intermediate representation for efficient | 
|  | 190 | compiler transformations and analysis, while providing a natural means | 
|  | 191 | to debug and visualize the transformations.  The three different forms | 
|  | 192 | of LLVM are all equivalent.  This document describes the human readable | 
|  | 193 | representation and notation.</p> | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 194 |  | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 195 | <p>The LLVM representation aims to be a light-weight and low-level | 
|  | 196 | while being expressive, typed, and extensible at the same time.  It | 
|  | 197 | aims to be a "universal IR" of sorts, by being at a low enough level | 
|  | 198 | that high-level ideas may be cleanly mapped to it (similar to how | 
|  | 199 | microprocessors are "universal IR's", allowing many source languages to | 
|  | 200 | be mapped to them).  By providing type information, LLVM can be used as | 
|  | 201 | the target of optimizations: for example, through pointer analysis, it | 
|  | 202 | can be proven that a C automatic variable is never accessed outside of | 
|  | 203 | the current function... allowing it to be promoted to a simple SSA | 
|  | 204 | value instead of a memory location.</p> | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 205 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 206 | </div> | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 207 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 208 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 209 | <div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div> | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 210 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 211 | <div class="doc_text"> | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 212 |  | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 213 | <p>It is important to note that this document describes 'well formed' | 
|  | 214 | LLVM assembly language.  There is a difference between what the parser | 
|  | 215 | accepts and what is considered 'well formed'.  For example, the | 
|  | 216 | following instruction is syntactically okay, but not well formed:</p> | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 217 |  | 
|  | 218 | <pre> | 
|  | 219 | %x = <a href="#i_add">add</a> int 1, %x | 
|  | 220 | </pre> | 
|  | 221 |  | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 222 | <p>...because the definition of <tt>%x</tt> does not dominate all of | 
|  | 223 | its uses. The LLVM infrastructure provides a verification pass that may | 
|  | 224 | be used to verify that an LLVM module is well formed.  This pass is | 
|  | 225 | automatically run by the parser after parsing input assembly, and by | 
|  | 226 | the optimizer before it outputs bytecode.  The violations pointed out | 
|  | 227 | by the verifier pass indicate bugs in transformation passes or input to | 
|  | 228 | the parser.</p> | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 229 |  | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 230 | <!-- Describe the typesetting conventions here. --> </div> | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 231 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 232 | <!-- *********************************************************************** --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 233 | <div class="doc_section"> <a name="identifiers">Identifiers</a> </div> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 234 | <!-- *********************************************************************** --> | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 235 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 236 | <div class="doc_text"> | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 237 |  | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 238 | <p>LLVM uses three different forms of identifiers, for different | 
|  | 239 | purposes:</p> | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 240 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 241 | <ol> | 
| Chris Lattner | d79749a | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 242 | <li>Named values are represented as a string of characters with a '%' prefix. | 
|  | 243 | For example, %foo, %DivisionByZero, %a.really.long.identifier.  The actual | 
|  | 244 | regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'. | 
|  | 245 | Identifiers which require other characters in their names can be surrounded | 
|  | 246 | with quotes.  In this way, anything except a <tt>"</tt> character can be used | 
|  | 247 | in a name.</li> | 
|  | 248 |  | 
|  | 249 | <li>Unnamed values are represented as an unsigned numeric value with a '%' | 
|  | 250 | prefix.  For example, %12, %2, %44.</li> | 
|  | 251 |  | 
| Reid Spencer | 8f08d80 | 2004-12-09 18:02:53 +0000 | [diff] [blame] | 252 | <li>Constants, which are described in a <a href="#constants">section about | 
|  | 253 | constants</a>, below.</li> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 254 | </ol> | 
| Chris Lattner | d79749a | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 255 |  | 
|  | 256 | <p>LLVM requires that values start with a '%' sign for two reasons: Compilers | 
|  | 257 | don't need to worry about name clashes with reserved words, and the set of | 
|  | 258 | reserved words may be expanded in the future without penalty.  Additionally, | 
|  | 259 | unnamed identifiers allow a compiler to quickly come up with a temporary | 
|  | 260 | variable without having to avoid symbol table conflicts.</p> | 
|  | 261 |  | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 262 | <p>Reserved words in LLVM are very similar to reserved words in other | 
|  | 263 | languages. There are keywords for different opcodes ('<tt><a | 
| Chris Lattner | d79749a | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 264 | href="#i_add">add</a></tt>', '<tt><a href="#i_cast">cast</a></tt>', '<tt><a | 
|  | 265 | href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a | 
|  | 266 | href="#t_void">void</a></tt>', '<tt><a href="#t_uint">uint</a></tt>', etc...), | 
|  | 267 | and others.  These reserved words cannot conflict with variable names, because | 
|  | 268 | none of them start with a '%' character.</p> | 
|  | 269 |  | 
|  | 270 | <p>Here is an example of LLVM code to multiply the integer variable | 
|  | 271 | '<tt>%X</tt>' by 8:</p> | 
|  | 272 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 273 | <p>The easy way:</p> | 
| Chris Lattner | d79749a | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 274 |  | 
|  | 275 | <pre> | 
|  | 276 | %result = <a href="#i_mul">mul</a> uint %X, 8 | 
|  | 277 | </pre> | 
|  | 278 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 279 | <p>After strength reduction:</p> | 
| Chris Lattner | d79749a | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 280 |  | 
|  | 281 | <pre> | 
|  | 282 | %result = <a href="#i_shl">shl</a> uint %X, ubyte 3 | 
|  | 283 | </pre> | 
|  | 284 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 285 | <p>And the hard way:</p> | 
| Chris Lattner | d79749a | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 286 |  | 
|  | 287 | <pre> | 
|  | 288 | <a href="#i_add">add</a> uint %X, %X           <i>; yields {uint}:%0</i> | 
|  | 289 | <a href="#i_add">add</a> uint %0, %0           <i>; yields {uint}:%1</i> | 
|  | 290 | %result = <a href="#i_add">add</a> uint %1, %1 | 
|  | 291 | </pre> | 
|  | 292 |  | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 293 | <p>This last way of multiplying <tt>%X</tt> by 8 illustrates several | 
|  | 294 | important lexical features of LLVM:</p> | 
| Chris Lattner | d79749a | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 295 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 296 | <ol> | 
| Chris Lattner | d79749a | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 297 |  | 
|  | 298 | <li>Comments are delimited with a '<tt>;</tt>' and go until the end of | 
|  | 299 | line.</li> | 
|  | 300 |  | 
|  | 301 | <li>Unnamed temporaries are created when the result of a computation is not | 
|  | 302 | assigned to a named value.</li> | 
|  | 303 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 304 | <li>Unnamed temporaries are numbered sequentially</li> | 
| Chris Lattner | d79749a | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 305 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 306 | </ol> | 
| Chris Lattner | d79749a | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 307 |  | 
|  | 308 | <p>...and it also show a convention that we follow in this document.  When | 
|  | 309 | demonstrating instructions, we will follow an instruction with a comment that | 
|  | 310 | defines the type and name of value produced.  Comments are shown in italic | 
|  | 311 | text.</p> | 
|  | 312 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 313 | </div> | 
| Chris Lattner | 6af02f3 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 314 |  | 
|  | 315 | <!-- *********************************************************************** --> | 
|  | 316 | <div class="doc_section"> <a name="highlevel">High Level Structure</a> </div> | 
|  | 317 | <!-- *********************************************************************** --> | 
|  | 318 |  | 
|  | 319 | <!-- ======================================================================= --> | 
|  | 320 | <div class="doc_subsection"> <a name="modulestructure">Module Structure</a> | 
|  | 321 | </div> | 
|  | 322 |  | 
|  | 323 | <div class="doc_text"> | 
|  | 324 |  | 
|  | 325 | <p>LLVM programs are composed of "Module"s, each of which is a | 
|  | 326 | translation unit of the input programs.  Each module consists of | 
|  | 327 | functions, global variables, and symbol table entries.  Modules may be | 
|  | 328 | combined together with the LLVM linker, which merges function (and | 
|  | 329 | global variable) definitions, resolves forward declarations, and merges | 
|  | 330 | symbol table entries. Here is an example of the "hello world" module:</p> | 
|  | 331 |  | 
|  | 332 | <pre><i>; Declare the string constant as a global constant...</i> | 
|  | 333 | <a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a | 
|  | 334 | href="#globalvars">constant</a> <a href="#t_array">[13 x sbyte]</a> c"hello world\0A\00"          <i>; [13 x sbyte]*</i> | 
|  | 335 |  | 
|  | 336 | <i>; External declaration of the puts function</i> | 
|  | 337 | <a href="#functionstructure">declare</a> int %puts(sbyte*)                                            <i>; int(sbyte*)* </i> | 
|  | 338 |  | 
|  | 339 | <i>; Definition of main function</i> | 
|  | 340 | int %main() {                                                        <i>; int()* </i> | 
|  | 341 | <i>; Convert [13x sbyte]* to sbyte *...</i> | 
|  | 342 | %cast210 = <a | 
|  | 343 | href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, long 0, long 0 <i>; sbyte*</i> | 
|  | 344 |  | 
|  | 345 | <i>; Call puts function to write out the string to stdout...</i> | 
|  | 346 | <a | 
|  | 347 | href="#i_call">call</a> int %puts(sbyte* %cast210)                              <i>; int</i> | 
|  | 348 | <a | 
|  | 349 | href="#i_ret">ret</a> int 0<br>}<br></pre> | 
|  | 350 |  | 
|  | 351 | <p>This example is made up of a <a href="#globalvars">global variable</a> | 
|  | 352 | named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>" | 
|  | 353 | function, and a <a href="#functionstructure">function definition</a> | 
|  | 354 | for "<tt>main</tt>".</p> | 
|  | 355 |  | 
| Chris Lattner | d79749a | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 356 | <p>In general, a module is made up of a list of global values, | 
|  | 357 | where both functions and global variables are global values.  Global values are | 
|  | 358 | represented by a pointer to a memory location (in this case, a pointer to an | 
|  | 359 | array of char, and a pointer to a function), and have one of the following <a | 
|  | 360 | href="#linkage">linkage types</a>.</p> | 
| Chris Lattner | 6af02f3 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 361 |  | 
| Chris Lattner | d79749a | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 362 | </div> | 
|  | 363 |  | 
|  | 364 | <!-- ======================================================================= --> | 
|  | 365 | <div class="doc_subsection"> | 
|  | 366 | <a name="linkage">Linkage Types</a> | 
|  | 367 | </div> | 
|  | 368 |  | 
|  | 369 | <div class="doc_text"> | 
|  | 370 |  | 
|  | 371 | <p> | 
|  | 372 | All Global Variables and Functions have one of the following types of linkage: | 
|  | 373 | </p> | 
| Chris Lattner | 6af02f3 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 374 |  | 
|  | 375 | <dl> | 
| Chris Lattner | d79749a | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 376 |  | 
| Chris Lattner | 6af02f3 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 377 | <dt><tt><b><a name="linkage_internal">internal</a></b></tt> </dt> | 
| Chris Lattner | d79749a | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 378 |  | 
|  | 379 | <dd>Global values with internal linkage are only directly accessible by | 
|  | 380 | objects in the current module.  In particular, linking code into a module with | 
|  | 381 | an internal global value may cause the internal to be renamed as necessary to | 
|  | 382 | avoid collisions.  Because the symbol is internal to the module, all | 
|  | 383 | references can be updated.  This corresponds to the notion of the | 
|  | 384 | '<tt>static</tt>' keyword in C, or the idea of "anonymous namespaces" in C++. | 
| Chris Lattner | 6af02f3 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 385 | </dd> | 
| Chris Lattner | d79749a | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 386 |  | 
| Chris Lattner | 6af02f3 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 387 | <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt> | 
| Chris Lattner | d79749a | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 388 |  | 
|  | 389 | <dd>"<tt>linkonce</tt>" linkage is similar to <tt>internal</tt> linkage, with | 
|  | 390 | the twist that linking together two modules defining the same | 
|  | 391 | <tt>linkonce</tt> globals will cause one of the globals to be discarded.  This | 
|  | 392 | is typically used to implement inline functions.  Unreferenced | 
|  | 393 | <tt>linkonce</tt> globals are allowed to be discarded. | 
| Chris Lattner | 6af02f3 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 394 | </dd> | 
| Chris Lattner | d79749a | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 395 |  | 
| Chris Lattner | 6af02f3 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 396 | <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt> | 
| Chris Lattner | d79749a | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 397 |  | 
|  | 398 | <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt> linkage, | 
|  | 399 | except that unreferenced <tt>weak</tt> globals may not be discarded.  This is | 
|  | 400 | used to implement constructs in C such as "<tt>int X;</tt>" at global scope. | 
| Chris Lattner | 6af02f3 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 401 | </dd> | 
| Chris Lattner | d79749a | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 402 |  | 
| Chris Lattner | 6af02f3 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 403 | <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt> | 
| Chris Lattner | d79749a | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 404 |  | 
|  | 405 | <dd>"<tt>appending</tt>" linkage may only be applied to global variables of | 
|  | 406 | pointer to array type.  When two global variables with appending linkage are | 
|  | 407 | linked together, the two global arrays are appended together.  This is the | 
|  | 408 | LLVM, typesafe, equivalent of having the system linker append together | 
|  | 409 | "sections" with identical names when .o files are linked. | 
| Chris Lattner | 6af02f3 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 410 | </dd> | 
| Chris Lattner | d79749a | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 411 |  | 
| Chris Lattner | 6af02f3 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 412 | <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt> | 
| Chris Lattner | d79749a | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 413 |  | 
|  | 414 | <dd>If none of the above identifiers are used, the global is externally | 
|  | 415 | visible, meaning that it participates in linkage and can be used to resolve | 
|  | 416 | external symbol references. | 
| Chris Lattner | 6af02f3 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 417 | </dd> | 
|  | 418 | </dl> | 
|  | 419 |  | 
| Chris Lattner | 6af02f3 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 420 | <p><a name="linkage_external">For example, since the "<tt>.LC0</tt>" | 
|  | 421 | variable is defined to be internal, if another module defined a "<tt>.LC0</tt>" | 
|  | 422 | variable and was linked with this one, one of the two would be renamed, | 
|  | 423 | preventing a collision.  Since "<tt>main</tt>" and "<tt>puts</tt>" are | 
|  | 424 | external (i.e., lacking any linkage declarations), they are accessible | 
|  | 425 | outside of the current module.  It is illegal for a function <i>declaration</i> | 
|  | 426 | to have any linkage type other than "externally visible".</a></p> | 
| Chris Lattner | d79749a | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 427 |  | 
| Chris Lattner | 6af02f3 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 428 | </div> | 
|  | 429 |  | 
|  | 430 | <!-- ======================================================================= --> | 
|  | 431 | <div class="doc_subsection"> | 
| Chris Lattner | 0132aff | 2005-05-06 22:57:40 +0000 | [diff] [blame^] | 432 | <a name="callingconv">Calling Conventions</a> | 
|  | 433 | </div> | 
|  | 434 |  | 
|  | 435 | <div class="doc_text"> | 
|  | 436 |  | 
|  | 437 | <p>LLVM <a href="#functionstructure">functions</a>, <a href="#i_call">calls</a> | 
|  | 438 | and <a href="#i_invoke">invokes</a> can all have an optional calling convention | 
|  | 439 | specified for the call.  The calling convention of any pair of dynamic | 
|  | 440 | caller/callee must match, or the behavior of the program is undefined.  The | 
|  | 441 | following calling conventions are supported by LLVM, and more may be added in | 
|  | 442 | the future:</p> | 
|  | 443 |  | 
|  | 444 | <dl> | 
|  | 445 | <dt><b>"<tt>ccc</tt>" - The C calling convention</b>:</dt> | 
|  | 446 |  | 
|  | 447 | <dd>This calling convention (the default if no other calling convention is | 
|  | 448 | specified) matches the target C calling conventions.  This calling convention | 
|  | 449 | supports varargs function calls, and tolerates some mismatch in the declared | 
|  | 450 | prototype and implemented declaration of the function (as does normal C). | 
|  | 451 | </dd> | 
|  | 452 |  | 
|  | 453 | <dt><b>"<tt>fastcc</tt>" - The fast calling convention</b>:</dt> | 
|  | 454 |  | 
|  | 455 | <dd>This calling convention attempts to make calls as fast as possible | 
|  | 456 | (e.g. by passing things in registers).  This calling convention allows the | 
|  | 457 | target to use whatever tricks it wants to produce fast code for the target, | 
|  | 458 | without having to conform to an externally specified ABI.  This calling | 
|  | 459 | convention does not support varargs and requires the prototype of all callees | 
|  | 460 | to exactly match the prototype of the function definition. | 
|  | 461 | </dd> | 
|  | 462 |  | 
|  | 463 | <dt><b>"<tt>coldcc</tt>" - The cold calling convention</b>:</dt> | 
|  | 464 |  | 
|  | 465 | <dd>This calling convention attempts to make code in the caller as efficient | 
|  | 466 | as possible under the assumption that the call is not commonly executed.  As | 
|  | 467 | such, these calls often preserve all registers so that the call does not break | 
|  | 468 | any live ranges in the caller side.  This calling convention does not support | 
|  | 469 | varargs and requires the prototype of all callees to exactly match the | 
|  | 470 | prototype of the function definition. | 
|  | 471 | </dd> | 
|  | 472 |  | 
|  | 473 | <dt><b>"<tt>cc <<it>n</it>></tt>" - Numbered convention</b>:</dt> | 
|  | 474 |  | 
|  | 475 | <dd>Any calling convention may be specified by number, allowing | 
|  | 476 | target-specific calling conventions to be used.  Target specific calling | 
|  | 477 | conventions start at 64. | 
|  | 478 | </dd> | 
|  | 479 |  | 
|  | 480 | <p>More calling conventions can be added/defined on an as-needed basis, to | 
|  | 481 | support pascal conventions or any other well-known target-independent | 
|  | 482 | convention.</p> | 
|  | 483 |  | 
|  | 484 | </div> | 
|  | 485 |  | 
|  | 486 | <!-- ======================================================================= --> | 
|  | 487 | <div class="doc_subsection"> | 
| Chris Lattner | 6af02f3 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 488 | <a name="globalvars">Global Variables</a> | 
|  | 489 | </div> | 
|  | 490 |  | 
|  | 491 | <div class="doc_text"> | 
|  | 492 |  | 
| Chris Lattner | 5d5aede | 2005-02-12 19:30:21 +0000 | [diff] [blame] | 493 | <p>Global variables define regions of memory allocated at compilation time | 
|  | 494 | instead of run-time.  Global variables may optionally be initialized.  A | 
|  | 495 | variable may be defined as a global "constant", which indicates that the | 
|  | 496 | contents of the variable will <b>never</b> be modified (enabling better | 
|  | 497 | optimization, allowing the global data to be placed in the read-only section of | 
|  | 498 | an executable, etc).  Note that variables that need runtime initialization | 
|  | 499 | cannot be marked "constant", as there is a store to the variable.</p> | 
|  | 500 |  | 
|  | 501 | <p> | 
|  | 502 | LLVM explicitly allows <em>declarations</em> of global variables to be marked | 
|  | 503 | constant, even if the final definition of the global is not.  This capability | 
|  | 504 | can be used to enable slightly better optimization of the program, but requires | 
|  | 505 | the language definition to guarantee that optimizations based on the | 
|  | 506 | 'constantness' are valid for the translation units that do not include the | 
|  | 507 | definition. | 
|  | 508 | </p> | 
| Chris Lattner | 6af02f3 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 509 |  | 
|  | 510 | <p>As SSA values, global variables define pointer values that are in | 
|  | 511 | scope (i.e. they dominate) all basic blocks in the program.  Global | 
|  | 512 | variables always define a pointer to their "content" type because they | 
|  | 513 | describe a region of memory, and all memory objects in LLVM are | 
|  | 514 | accessed through pointers.</p> | 
|  | 515 |  | 
|  | 516 | </div> | 
|  | 517 |  | 
|  | 518 |  | 
|  | 519 | <!-- ======================================================================= --> | 
|  | 520 | <div class="doc_subsection"> | 
|  | 521 | <a name="functionstructure">Functions</a> | 
|  | 522 | </div> | 
|  | 523 |  | 
|  | 524 | <div class="doc_text"> | 
|  | 525 |  | 
| Chris Lattner | 0132aff | 2005-05-06 22:57:40 +0000 | [diff] [blame^] | 526 | <p>LLVM function definitions consist of an optional <a href="#linkage">linkage | 
|  | 527 | type</a>, an optional <a href="#callingconv">calling convention</a>, a return | 
|  | 528 | type, a function name, a (possibly empty) argument list, an opening curly brace, | 
|  | 529 | a list of basic blocks, and a closing curly brace.  LLVM function declarations | 
|  | 530 | are defined with the "<tt>declare</tt>" keyword, an optional <a | 
|  | 531 | href="#callingconv">calling convention</a>, a return type, a function name, and | 
|  | 532 | a possibly empty list of arguments.</p> | 
| Chris Lattner | 6af02f3 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 533 |  | 
|  | 534 | <p>A function definition contains a list of basic blocks, forming the CFG for | 
|  | 535 | the function.  Each basic block may optionally start with a label (giving the | 
|  | 536 | basic block a symbol table entry), contains a list of instructions, and ends | 
|  | 537 | with a <a href="#terminators">terminator</a> instruction (such as a branch or | 
|  | 538 | function return).</p> | 
|  | 539 |  | 
|  | 540 | <p>The first basic block in program is special in two ways: it is immediately | 
|  | 541 | executed on entrance to the function, and it is not allowed to have predecessor | 
|  | 542 | basic blocks (i.e. there can not be any branches to the entry block of a | 
|  | 543 | function).  Because the block can have no predecessors, it also cannot have any | 
|  | 544 | <a href="#i_phi">PHI nodes</a>.</p> | 
|  | 545 |  | 
|  | 546 | <p>LLVM functions are identified by their name and type signature.  Hence, two | 
|  | 547 | functions with the same name but different parameter lists or return values are | 
| Chris Lattner | 455fc8c | 2005-03-07 22:13:59 +0000 | [diff] [blame] | 548 | considered different functions, and LLVM will resolve references to each | 
| Chris Lattner | 6af02f3 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 549 | appropriately.</p> | 
|  | 550 |  | 
|  | 551 | </div> | 
|  | 552 |  | 
|  | 553 |  | 
|  | 554 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 555 | <!-- *********************************************************************** --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 556 | <div class="doc_section"> <a name="typesystem">Type System</a> </div> | 
|  | 557 | <!-- *********************************************************************** --> | 
| Chris Lattner | 6af02f3 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 558 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 559 | <div class="doc_text"> | 
| Chris Lattner | 6af02f3 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 560 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 561 | <p>The LLVM type system is one of the most important features of the | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 562 | intermediate representation.  Being typed enables a number of | 
|  | 563 | optimizations to be performed on the IR directly, without having to do | 
|  | 564 | extra analyses on the side before the transformation.  A strong type | 
|  | 565 | system makes it easier to read the generated code and enables novel | 
|  | 566 | analyses and transformations that are not feasible to perform on normal | 
|  | 567 | three address code representations.</p> | 
| Chris Lattner | 6af02f3 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 568 |  | 
|  | 569 | </div> | 
|  | 570 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 571 | <!-- ======================================================================= --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 572 | <div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 573 | <div class="doc_text"> | 
| John Criswell | 417228d | 2004-04-09 16:48:45 +0000 | [diff] [blame] | 574 | <p>The primitive types are the fundamental building blocks of the LLVM | 
| Chris Lattner | 455fc8c | 2005-03-07 22:13:59 +0000 | [diff] [blame] | 575 | system. The current set of primitive types is as follows:</p> | 
| Misha Brukman | c501f55 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 576 |  | 
| Reid Spencer | c3c4c4f | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 577 | <table class="layout"> | 
|  | 578 | <tr class="layout"> | 
|  | 579 | <td class="left"> | 
|  | 580 | <table> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 581 | <tbody> | 
| Reid Spencer | c3c4c4f | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 582 | <tr><th>Type</th><th>Description</th></tr> | 
|  | 583 | <tr><td><tt>void</tt></td><td>No value</td></tr> | 
| Misha Brukman | 36c6bc1 | 2005-04-22 18:02:52 +0000 | [diff] [blame] | 584 | <tr><td><tt>ubyte</tt></td><td>Unsigned 8-bit value</td></tr> | 
|  | 585 | <tr><td><tt>ushort</tt></td><td>Unsigned 16-bit value</td></tr> | 
|  | 586 | <tr><td><tt>uint</tt></td><td>Unsigned 32-bit value</td></tr> | 
|  | 587 | <tr><td><tt>ulong</tt></td><td>Unsigned 64-bit value</td></tr> | 
|  | 588 | <tr><td><tt>float</tt></td><td>32-bit floating point value</td></tr> | 
| Reid Spencer | c3c4c4f | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 589 | <tr><td><tt>label</tt></td><td>Branch destination</td></tr> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 590 | </tbody> | 
|  | 591 | </table> | 
| Reid Spencer | c3c4c4f | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 592 | </td> | 
|  | 593 | <td class="right"> | 
|  | 594 | <table> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 595 | <tbody> | 
| Reid Spencer | c3c4c4f | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 596 | <tr><th>Type</th><th>Description</th></tr> | 
|  | 597 | <tr><td><tt>bool</tt></td><td>True or False value</td></tr> | 
| Misha Brukman | 36c6bc1 | 2005-04-22 18:02:52 +0000 | [diff] [blame] | 598 | <tr><td><tt>sbyte</tt></td><td>Signed 8-bit value</td></tr> | 
|  | 599 | <tr><td><tt>short</tt></td><td>Signed 16-bit value</td></tr> | 
|  | 600 | <tr><td><tt>int</tt></td><td>Signed 32-bit value</td></tr> | 
|  | 601 | <tr><td><tt>long</tt></td><td>Signed 64-bit value</td></tr> | 
|  | 602 | <tr><td><tt>double</tt></td><td>64-bit floating point value</td></tr> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 603 | </tbody> | 
|  | 604 | </table> | 
| Reid Spencer | c3c4c4f | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 605 | </td> | 
|  | 606 | </tr> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 607 | </table> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 608 | </div> | 
| Reid Spencer | c3c4c4f | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 609 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 610 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 611 | <div class="doc_subsubsection"> <a name="t_classifications">Type | 
|  | 612 | Classifications</a> </div> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 613 | <div class="doc_text"> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 614 | <p>These different primitive types fall into a few useful | 
|  | 615 | classifications:</p> | 
| Misha Brukman | c501f55 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 616 |  | 
|  | 617 | <table border="1" cellspacing="0" cellpadding="4"> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 618 | <tbody> | 
| Reid Spencer | c3c4c4f | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 619 | <tr><th>Classification</th><th>Types</th></tr> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 620 | <tr> | 
|  | 621 | <td><a name="t_signed">signed</a></td> | 
|  | 622 | <td><tt>sbyte, short, int, long, float, double</tt></td> | 
|  | 623 | </tr> | 
|  | 624 | <tr> | 
|  | 625 | <td><a name="t_unsigned">unsigned</a></td> | 
|  | 626 | <td><tt>ubyte, ushort, uint, ulong</tt></td> | 
|  | 627 | </tr> | 
|  | 628 | <tr> | 
|  | 629 | <td><a name="t_integer">integer</a></td> | 
|  | 630 | <td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td> | 
|  | 631 | </tr> | 
|  | 632 | <tr> | 
|  | 633 | <td><a name="t_integral">integral</a></td> | 
| Misha Brukman | 20f9a62 | 2004-08-12 20:16:08 +0000 | [diff] [blame] | 634 | <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long</tt> | 
|  | 635 | </td> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 636 | </tr> | 
|  | 637 | <tr> | 
|  | 638 | <td><a name="t_floating">floating point</a></td> | 
|  | 639 | <td><tt>float, double</tt></td> | 
|  | 640 | </tr> | 
|  | 641 | <tr> | 
|  | 642 | <td><a name="t_firstclass">first class</a></td> | 
| Misha Brukman | 20f9a62 | 2004-08-12 20:16:08 +0000 | [diff] [blame] | 643 | <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long,<br> | 
|  | 644 | float, double, <a href="#t_pointer">pointer</a>, | 
|  | 645 | <a href="#t_packed">packed</a></tt></td> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 646 | </tr> | 
|  | 647 | </tbody> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 648 | </table> | 
| Misha Brukman | c501f55 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 649 |  | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 650 | <p>The <a href="#t_firstclass">first class</a> types are perhaps the | 
|  | 651 | most important.  Values of these types are the only ones which can be | 
|  | 652 | produced by instructions, passed as arguments, or used as operands to | 
|  | 653 | instructions.  This means that all structures and arrays must be | 
|  | 654 | manipulated either by pointer or by component.</p> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 655 | </div> | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 656 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 657 | <!-- ======================================================================= --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 658 | <div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div> | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 659 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 660 | <div class="doc_text"> | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 661 |  | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 662 | <p>The real power in LLVM comes from the derived types in the system. | 
|  | 663 | This is what allows a programmer to represent arrays, functions, | 
|  | 664 | pointers, and other useful types.  Note that these derived types may be | 
|  | 665 | recursive: For example, it is possible to have a two dimensional array.</p> | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 666 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 667 | </div> | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 668 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 669 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 670 | <div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div> | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 671 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 672 | <div class="doc_text"> | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 673 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 674 | <h5>Overview:</h5> | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 675 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 676 | <p>The array type is a very simple derived type that arranges elements | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 677 | sequentially in memory.  The array type requires a size (number of | 
|  | 678 | elements) and an underlying data type.</p> | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 679 |  | 
| Chris Lattner | 590645f | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 680 | <h5>Syntax:</h5> | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 681 |  | 
|  | 682 | <pre> | 
|  | 683 | [<# elements> x <elementtype>] | 
|  | 684 | </pre> | 
|  | 685 |  | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 686 | <p>The number of elements is a constant integer value, elementtype may | 
|  | 687 | be any type with a size.</p> | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 688 |  | 
| Chris Lattner | 590645f | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 689 | <h5>Examples:</h5> | 
| Reid Spencer | c3c4c4f | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 690 | <table class="layout"> | 
|  | 691 | <tr class="layout"> | 
|  | 692 | <td class="left"> | 
|  | 693 | <tt>[40 x int ]</tt><br/> | 
|  | 694 | <tt>[41 x int ]</tt><br/> | 
|  | 695 | <tt>[40 x uint]</tt><br/> | 
|  | 696 | </td> | 
|  | 697 | <td class="left"> | 
|  | 698 | Array of 40 integer values.<br/> | 
|  | 699 | Array of 41 integer values.<br/> | 
|  | 700 | Array of 40 unsigned integer values.<br/> | 
|  | 701 | </td> | 
|  | 702 | </tr> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 703 | </table> | 
| Reid Spencer | c3c4c4f | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 704 | <p>Here are some examples of multidimensional arrays:</p> | 
|  | 705 | <table class="layout"> | 
|  | 706 | <tr class="layout"> | 
|  | 707 | <td class="left"> | 
|  | 708 | <tt>[3 x [4 x int]]</tt><br/> | 
|  | 709 | <tt>[12 x [10 x float]]</tt><br/> | 
|  | 710 | <tt>[2 x [3 x [4 x uint]]]</tt><br/> | 
|  | 711 | </td> | 
|  | 712 | <td class="left"> | 
|  | 713 | 3x4 array integer values.<br/> | 
|  | 714 | 12x10 array of single precision floating point values.<br/> | 
|  | 715 | 2x3x4 array of unsigned integer values.<br/> | 
|  | 716 | </td> | 
|  | 717 | </tr> | 
|  | 718 | </table> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 719 | </div> | 
| Reid Spencer | c3c4c4f | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 720 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 721 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 722 | <div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 723 | <div class="doc_text"> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 724 | <h5>Overview:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 725 | <p>The function type can be thought of as a function signature.  It | 
|  | 726 | consists of a return type and a list of formal parameter types. | 
| John Criswell | a0d50d2 | 2003-11-25 21:45:46 +0000 | [diff] [blame] | 727 | Function types are usually used to build virtual function tables | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 728 | (which are structures of pointers to functions), for indirect function | 
|  | 729 | calls, and when defining a function.</p> | 
| John Criswell | a0d50d2 | 2003-11-25 21:45:46 +0000 | [diff] [blame] | 730 | <p> | 
|  | 731 | The return type of a function type cannot be an aggregate type. | 
|  | 732 | </p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 733 | <h5>Syntax:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 734 | <pre>  <returntype> (<parameter list>)<br></pre> | 
| Misha Brukman | 20f9a62 | 2004-08-12 20:16:08 +0000 | [diff] [blame] | 735 | <p>Where '<tt><parameter list></tt>' is a comma-separated list of type | 
|  | 736 | specifiers.  Optionally, the parameter list may include a type <tt>...</tt>, | 
| Chris Lattner | 5ed6061 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 737 | which indicates that the function takes a variable number of arguments. | 
|  | 738 | Variable argument functions can access their arguments with the <a | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 739 | href="#int_varargs">variable argument handling intrinsic</a> functions.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 740 | <h5>Examples:</h5> | 
| Reid Spencer | c3c4c4f | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 741 | <table class="layout"> | 
|  | 742 | <tr class="layout"> | 
|  | 743 | <td class="left"> | 
|  | 744 | <tt>int (int)</tt> <br/> | 
|  | 745 | <tt>float (int, int *) *</tt><br/> | 
|  | 746 | <tt>int (sbyte *, ...)</tt><br/> | 
|  | 747 | </td> | 
|  | 748 | <td class="left"> | 
|  | 749 | function taking an <tt>int</tt>, returning an <tt>int</tt><br/> | 
|  | 750 | <a href="#t_pointer">Pointer</a> to a function that takes an | 
| Misha Brukman | 20f9a62 | 2004-08-12 20:16:08 +0000 | [diff] [blame] | 751 | <tt>int</tt> and a <a href="#t_pointer">pointer</a> to <tt>int</tt>, | 
| Reid Spencer | c3c4c4f | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 752 | returning <tt>float</tt>.<br/> | 
|  | 753 | A vararg function that takes at least one <a href="#t_pointer">pointer</a> | 
|  | 754 | to <tt>sbyte</tt> (signed char in C), which returns an integer.  This is | 
|  | 755 | the signature for <tt>printf</tt> in LLVM.<br/> | 
|  | 756 | </td> | 
|  | 757 | </tr> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 758 | </table> | 
| Misha Brukman | c501f55 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 759 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 760 | </div> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 761 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 762 | <div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 763 | <div class="doc_text"> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 764 | <h5>Overview:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 765 | <p>The structure type is used to represent a collection of data members | 
|  | 766 | together in memory.  The packing of the field types is defined to match | 
|  | 767 | the ABI of the underlying processor.  The elements of a structure may | 
|  | 768 | be any type that has a size.</p> | 
|  | 769 | <p>Structures are accessed using '<tt><a href="#i_load">load</a></tt> | 
|  | 770 | and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a | 
|  | 771 | field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>' | 
|  | 772 | instruction.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 773 | <h5>Syntax:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 774 | <pre>  { <type list> }<br></pre> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 775 | <h5>Examples:</h5> | 
| Reid Spencer | c3c4c4f | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 776 | <table class="layout"> | 
|  | 777 | <tr class="layout"> | 
|  | 778 | <td class="left"> | 
|  | 779 | <tt>{ int, int, int }</tt><br/> | 
|  | 780 | <tt>{ float, int (int) * }</tt><br/> | 
|  | 781 | </td> | 
|  | 782 | <td class="left"> | 
|  | 783 | a triple of three <tt>int</tt> values<br/> | 
|  | 784 | A pair, where the first element is a <tt>float</tt> and the second element | 
|  | 785 | is a <a href="#t_pointer">pointer</a> to a <a href="#t_function">function</a> | 
|  | 786 | that takes an <tt>int</tt>, returning an <tt>int</tt>.<br/> | 
|  | 787 | </td> | 
|  | 788 | </tr> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 789 | </table> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 790 | </div> | 
| Reid Spencer | c3c4c4f | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 791 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 792 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 793 | <div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 794 | <div class="doc_text"> | 
| Chris Lattner | 590645f | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 795 | <h5>Overview:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 796 | <p>As in many languages, the pointer type represents a pointer or | 
|  | 797 | reference to another object, which must live in memory.</p> | 
| Chris Lattner | 590645f | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 798 | <h5>Syntax:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 799 | <pre>  <type> *<br></pre> | 
| Chris Lattner | 590645f | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 800 | <h5>Examples:</h5> | 
| Reid Spencer | c3c4c4f | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 801 | <table class="layout"> | 
|  | 802 | <tr class="layout"> | 
|  | 803 | <td class="left"> | 
|  | 804 | <tt>[4x int]*</tt><br/> | 
|  | 805 | <tt>int (int *) *</tt><br/> | 
|  | 806 | </td> | 
|  | 807 | <td class="left"> | 
|  | 808 | A <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a> of | 
|  | 809 | four <tt>int</tt> values<br/> | 
|  | 810 | A <a href="#t_pointer">pointer</a> to a <a | 
| Chris Lattner | 16fb003 | 2005-02-19 02:22:14 +0000 | [diff] [blame] | 811 | href="#t_function">function</a> that takes an <tt>int*</tt>, returning an | 
| Reid Spencer | c3c4c4f | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 812 | <tt>int</tt>.<br/> | 
|  | 813 | </td> | 
|  | 814 | </tr> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 815 | </table> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 816 | </div> | 
| Reid Spencer | c3c4c4f | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 817 |  | 
| Chris Lattner | c8cb695 | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 818 | <!-- _______________________________________________________________________ --> | 
|  | 819 | <div class="doc_subsubsection"> <a name="t_packed">Packed Type</a> </div> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 820 | <div class="doc_text"> | 
| Chris Lattner | 37b6b09 | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 821 |  | 
| Chris Lattner | c8cb695 | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 822 | <h5>Overview:</h5> | 
| Chris Lattner | 37b6b09 | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 823 |  | 
| Chris Lattner | c8cb695 | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 824 | <p>A packed type is a simple derived type that represents a vector | 
|  | 825 | of elements.  Packed types are used when multiple primitive data | 
|  | 826 | are operated in parallel using a single instruction (SIMD). | 
|  | 827 | A packed type requires a size (number of | 
|  | 828 | elements) and an underlying primitive data type.  Packed types are | 
|  | 829 | considered <a href="#t_firstclass">first class</a>.</p> | 
| Chris Lattner | 37b6b09 | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 830 |  | 
| Chris Lattner | c8cb695 | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 831 | <h5>Syntax:</h5> | 
| Chris Lattner | 37b6b09 | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 832 |  | 
|  | 833 | <pre> | 
|  | 834 | < <# elements> x <elementtype> > | 
|  | 835 | </pre> | 
|  | 836 |  | 
| Chris Lattner | c8cb695 | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 837 | <p>The number of elements is a constant integer value, elementtype may | 
|  | 838 | be any integral or floating point type.</p> | 
| Chris Lattner | 37b6b09 | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 839 |  | 
| Chris Lattner | c8cb695 | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 840 | <h5>Examples:</h5> | 
| Chris Lattner | 37b6b09 | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 841 |  | 
| Reid Spencer | c3c4c4f | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 842 | <table class="layout"> | 
|  | 843 | <tr class="layout"> | 
|  | 844 | <td class="left"> | 
|  | 845 | <tt><4 x int></tt><br/> | 
|  | 846 | <tt><8 x float></tt><br/> | 
|  | 847 | <tt><2 x uint></tt><br/> | 
|  | 848 | </td> | 
|  | 849 | <td class="left"> | 
|  | 850 | Packed vector of 4 integer values.<br/> | 
|  | 851 | Packed vector of 8 floating-point values.<br/> | 
|  | 852 | Packed vector of 2 unsigned integer values.<br/> | 
|  | 853 | </td> | 
|  | 854 | </tr> | 
|  | 855 | </table> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 856 | </div> | 
|  | 857 |  | 
| Chris Lattner | 37b6b09 | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 858 | <!-- _______________________________________________________________________ --> | 
|  | 859 | <div class="doc_subsubsection"> <a name="t_opaque">Opaque Type</a> </div> | 
|  | 860 | <div class="doc_text"> | 
|  | 861 |  | 
|  | 862 | <h5>Overview:</h5> | 
|  | 863 |  | 
|  | 864 | <p>Opaque types are used to represent unknown types in the system.  This | 
|  | 865 | corresponds (for example) to the C notion of a foward declared structure type. | 
|  | 866 | In LLVM, opaque types can eventually be resolved to any type (not just a | 
|  | 867 | structure type).</p> | 
|  | 868 |  | 
|  | 869 | <h5>Syntax:</h5> | 
|  | 870 |  | 
|  | 871 | <pre> | 
|  | 872 | opaque | 
|  | 873 | </pre> | 
|  | 874 |  | 
|  | 875 | <h5>Examples:</h5> | 
|  | 876 |  | 
|  | 877 | <table class="layout"> | 
|  | 878 | <tr class="layout"> | 
|  | 879 | <td class="left"> | 
|  | 880 | <tt>opaque</tt> | 
|  | 881 | </td> | 
|  | 882 | <td class="left"> | 
|  | 883 | An opaque type.<br/> | 
|  | 884 | </td> | 
|  | 885 | </tr> | 
|  | 886 | </table> | 
|  | 887 | </div> | 
|  | 888 |  | 
|  | 889 |  | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 890 | <!-- *********************************************************************** --> | 
|  | 891 | <div class="doc_section"> <a name="constants">Constants</a> </div> | 
|  | 892 | <!-- *********************************************************************** --> | 
|  | 893 |  | 
|  | 894 | <div class="doc_text"> | 
|  | 895 |  | 
|  | 896 | <p>LLVM has several different basic types of constants.  This section describes | 
|  | 897 | them all and their syntax.</p> | 
|  | 898 |  | 
|  | 899 | </div> | 
|  | 900 |  | 
|  | 901 | <!-- ======================================================================= --> | 
| Reid Spencer | 8f08d80 | 2004-12-09 18:02:53 +0000 | [diff] [blame] | 902 | <div class="doc_subsection"><a name="simpleconstants">Simple Constants</a></div> | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 903 |  | 
|  | 904 | <div class="doc_text"> | 
|  | 905 |  | 
|  | 906 | <dl> | 
|  | 907 | <dt><b>Boolean constants</b></dt> | 
|  | 908 |  | 
|  | 909 | <dd>The two strings '<tt>true</tt>' and '<tt>false</tt>' are both valid | 
|  | 910 | constants of the <tt><a href="#t_primitive">bool</a></tt> type. | 
|  | 911 | </dd> | 
|  | 912 |  | 
|  | 913 | <dt><b>Integer constants</b></dt> | 
|  | 914 |  | 
| Reid Spencer | 8f08d80 | 2004-12-09 18:02:53 +0000 | [diff] [blame] | 915 | <dd>Standard integers (such as '4') are constants of the <a | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 916 | href="#t_integer">integer</a> type.  Negative numbers may be used with signed | 
|  | 917 | integer types. | 
|  | 918 | </dd> | 
|  | 919 |  | 
|  | 920 | <dt><b>Floating point constants</b></dt> | 
|  | 921 |  | 
|  | 922 | <dd>Floating point constants use standard decimal notation (e.g. 123.421), | 
|  | 923 | exponential notation (e.g. 1.23421e+2), or a more precise hexadecimal | 
| Reid Spencer | 8f08d80 | 2004-12-09 18:02:53 +0000 | [diff] [blame] | 924 | notation.  Floating point constants have an optional hexadecimal | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 925 | notation (see below).  Floating point constants must have a <a | 
|  | 926 | href="#t_floating">floating point</a> type. </dd> | 
|  | 927 |  | 
|  | 928 | <dt><b>Null pointer constants</b></dt> | 
|  | 929 |  | 
| John Criswell | dfe6a86 | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 930 | <dd>The identifier '<tt>null</tt>' is recognized as a null pointer constant | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 931 | and must be of <a href="#t_pointer">pointer type</a>.</dd> | 
|  | 932 |  | 
|  | 933 | </dl> | 
|  | 934 |  | 
| John Criswell | dfe6a86 | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 935 | <p>The one non-intuitive notation for constants is the optional hexadecimal form | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 936 | of floating point constants.  For example, the form '<tt>double | 
|  | 937 | 0x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double | 
|  | 938 | 4.5e+15</tt>'.  The only time hexadecimal floating point constants are required | 
| Reid Spencer | 8f08d80 | 2004-12-09 18:02:53 +0000 | [diff] [blame] | 939 | (and the only time that they are generated by the disassembler) is when a | 
|  | 940 | floating point constant must be emitted but it cannot be represented as a | 
|  | 941 | decimal floating point number.  For example, NaN's, infinities, and other | 
|  | 942 | special values are represented in their IEEE hexadecimal format so that | 
|  | 943 | assembly and disassembly do not cause any bits to change in the constants.</p> | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 944 |  | 
|  | 945 | </div> | 
|  | 946 |  | 
|  | 947 | <!-- ======================================================================= --> | 
|  | 948 | <div class="doc_subsection"><a name="aggregateconstants">Aggregate Constants</a> | 
|  | 949 | </div> | 
|  | 950 |  | 
|  | 951 | <div class="doc_text"> | 
| Chris Lattner | 455fc8c | 2005-03-07 22:13:59 +0000 | [diff] [blame] | 952 | <p>Aggregate constants arise from aggregation of simple constants | 
|  | 953 | and smaller aggregate constants.</p> | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 954 |  | 
|  | 955 | <dl> | 
|  | 956 | <dt><b>Structure constants</b></dt> | 
|  | 957 |  | 
|  | 958 | <dd>Structure constants are represented with notation similar to structure | 
|  | 959 | type definitions (a comma separated list of elements, surrounded by braces | 
| Chris Lattner | 455fc8c | 2005-03-07 22:13:59 +0000 | [diff] [blame] | 960 | (<tt>{}</tt>)).  For example: "<tt>{ int 4, float 17.0, int* %G }</tt>", | 
|  | 961 | where "<tt>%G</tt>" is declared as "<tt>%G = external global int</tt>".  Structure constants | 
|  | 962 | must have <a href="#t_struct">structure type</a>, and the number and | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 963 | types of elements must match those specified by the type. | 
|  | 964 | </dd> | 
|  | 965 |  | 
|  | 966 | <dt><b>Array constants</b></dt> | 
|  | 967 |  | 
|  | 968 | <dd>Array constants are represented with notation similar to array type | 
|  | 969 | definitions (a comma separated list of elements, surrounded by square brackets | 
| John Criswell | dfe6a86 | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 970 | (<tt>[]</tt>)).  For example: "<tt>[ int 42, int 11, int 74 ]</tt>".  Array | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 971 | constants must have <a href="#t_array">array type</a>, and the number and | 
|  | 972 | types of elements must match those specified by the type. | 
|  | 973 | </dd> | 
|  | 974 |  | 
|  | 975 | <dt><b>Packed constants</b></dt> | 
|  | 976 |  | 
|  | 977 | <dd>Packed constants are represented with notation similar to packed type | 
|  | 978 | definitions (a comma separated list of elements, surrounded by | 
| John Criswell | dfe6a86 | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 979 | less-than/greater-than's (<tt><></tt>)).  For example: "<tt>< int 42, | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 980 | int 11, int 74, int 100 ></tt>".  Packed constants must have <a | 
|  | 981 | href="#t_packed">packed type</a>, and the number and types of elements must | 
|  | 982 | match those specified by the type. | 
|  | 983 | </dd> | 
|  | 984 |  | 
|  | 985 | <dt><b>Zero initialization</b></dt> | 
|  | 986 |  | 
|  | 987 | <dd>The string '<tt>zeroinitializer</tt>' can be used to zero initialize a | 
|  | 988 | value to zero of <em>any</em> type, including scalar and aggregate types. | 
|  | 989 | This is often used to avoid having to print large zero initializers (e.g. for | 
|  | 990 | large arrays), and is always exactly equivalent to using explicit zero | 
|  | 991 | initializers. | 
|  | 992 | </dd> | 
|  | 993 | </dl> | 
|  | 994 |  | 
|  | 995 | </div> | 
|  | 996 |  | 
|  | 997 | <!-- ======================================================================= --> | 
|  | 998 | <div class="doc_subsection"> | 
|  | 999 | <a name="globalconstants">Global Variable and Function Addresses</a> | 
|  | 1000 | </div> | 
|  | 1001 |  | 
|  | 1002 | <div class="doc_text"> | 
|  | 1003 |  | 
|  | 1004 | <p>The addresses of <a href="#globalvars">global variables</a> and <a | 
|  | 1005 | href="#functionstructure">functions</a> are always implicitly valid (link-time) | 
| John Criswell | dfe6a86 | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 1006 | constants.  These constants are explicitly referenced when the <a | 
|  | 1007 | href="#identifiers">identifier for the global</a> is used and always have <a | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1008 | href="#t_pointer">pointer</a> type. For example, the following is a legal LLVM | 
|  | 1009 | file:</p> | 
|  | 1010 |  | 
|  | 1011 | <pre> | 
|  | 1012 | %X = global int 17 | 
|  | 1013 | %Y = global int 42 | 
|  | 1014 | %Z = global [2 x int*] [ int* %X, int* %Y ] | 
|  | 1015 | </pre> | 
|  | 1016 |  | 
|  | 1017 | </div> | 
|  | 1018 |  | 
|  | 1019 | <!-- ======================================================================= --> | 
| Reid Spencer | 641f5c9 | 2004-12-09 18:13:12 +0000 | [diff] [blame] | 1020 | <div class="doc_subsection"><a name="undefvalues">Undefined Values</a></div> | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1021 | <div class="doc_text"> | 
| Reid Spencer | 641f5c9 | 2004-12-09 18:13:12 +0000 | [diff] [blame] | 1022 | <p>The string '<tt>undef</tt>' is recognized as a type-less constant that has | 
|  | 1023 | no specific value.  Undefined values may be of any type, and be used anywhere | 
|  | 1024 | a constant is permitted.</p> | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1025 |  | 
| Reid Spencer | 641f5c9 | 2004-12-09 18:13:12 +0000 | [diff] [blame] | 1026 | <p>Undefined values indicate to the compiler that the program is well defined | 
|  | 1027 | no matter what value is used, giving the compiler more freedom to optimize. | 
|  | 1028 | </p> | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1029 | </div> | 
|  | 1030 |  | 
|  | 1031 | <!-- ======================================================================= --> | 
|  | 1032 | <div class="doc_subsection"><a name="constantexprs">Constant Expressions</a> | 
|  | 1033 | </div> | 
|  | 1034 |  | 
|  | 1035 | <div class="doc_text"> | 
|  | 1036 |  | 
|  | 1037 | <p>Constant expressions are used to allow expressions involving other constants | 
|  | 1038 | to be used as constants.  Constant expressions may be of any <a | 
|  | 1039 | href="#t_firstclass">first class</a> type, and may involve any LLVM operation | 
|  | 1040 | that does not have side effects (e.g. load and call are not supported).  The | 
|  | 1041 | following is the syntax for constant expressions:</p> | 
|  | 1042 |  | 
|  | 1043 | <dl> | 
|  | 1044 | <dt><b><tt>cast ( CST to TYPE )</tt></b></dt> | 
|  | 1045 |  | 
|  | 1046 | <dd>Cast a constant to another type.</dd> | 
|  | 1047 |  | 
|  | 1048 | <dt><b><tt>getelementptr ( CSTPTR, IDX0, IDX1, ... )</tt></b></dt> | 
|  | 1049 |  | 
|  | 1050 | <dd>Perform the <a href="#i_getelementptr">getelementptr operation</a> on | 
|  | 1051 | constants.  As with the <a href="#i_getelementptr">getelementptr</a> | 
|  | 1052 | instruction, the index list may have zero or more indexes, which are required | 
|  | 1053 | to make sense for the type of "CSTPTR".</dd> | 
|  | 1054 |  | 
|  | 1055 | <dt><b><tt>OPCODE ( LHS, RHS )</tt></b></dt> | 
|  | 1056 |  | 
| Reid Spencer | 641f5c9 | 2004-12-09 18:13:12 +0000 | [diff] [blame] | 1057 | <dd>Perform the specified operation of the LHS and RHS constants. OPCODE may | 
|  | 1058 | be any of the <a href="#binaryops">binary</a> or <a href="#bitwiseops">bitwise | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1059 | binary</a> operations.  The constraints on operands are the same as those for | 
|  | 1060 | the corresponding instruction (e.g. no bitwise operations on floating point | 
|  | 1061 | are allowed).</dd> | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1062 | </dl> | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1063 | </div> | 
| Chris Lattner | b165261 | 2004-03-08 16:49:10 +0000 | [diff] [blame] | 1064 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1065 | <!-- *********************************************************************** --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1066 | <div class="doc_section"> <a name="instref">Instruction Reference</a> </div> | 
|  | 1067 | <!-- *********************************************************************** --> | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1068 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1069 | <div class="doc_text"> | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1070 |  | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1071 | <p>The LLVM instruction set consists of several different | 
|  | 1072 | classifications of instructions: <a href="#terminators">terminator | 
|  | 1073 | instructions</a>, <a href="#binaryops">binary instructions</a>, <a | 
|  | 1074 | href="#memoryops">memory instructions</a>, and <a href="#otherops">other | 
|  | 1075 | instructions</a>.</p> | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1076 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1077 | </div> | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1078 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1079 | <!-- ======================================================================= --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1080 | <div class="doc_subsection"> <a name="terminators">Terminator | 
|  | 1081 | Instructions</a> </div> | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1082 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1083 | <div class="doc_text"> | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1084 |  | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1085 | <p>As mentioned <a href="#functionstructure">previously</a>, every | 
|  | 1086 | basic block in a program ends with a "Terminator" instruction, which | 
|  | 1087 | indicates which block should be executed after the current block is | 
|  | 1088 | finished. These terminator instructions typically yield a '<tt>void</tt>' | 
|  | 1089 | value: they produce control flow, not values (the one exception being | 
|  | 1090 | the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p> | 
| John Criswell | dfe6a86 | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 1091 | <p>There are six different terminator instructions: the '<a | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1092 | href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>' | 
|  | 1093 | instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction, | 
| Chris Lattner | 08b7d5b | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 1094 | the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the '<a | 
|  | 1095 | href="#i_unwind"><tt>unwind</tt></a>' instruction, and the '<a | 
|  | 1096 | href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p> | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1097 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1098 | </div> | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1099 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1100 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1101 | <div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>' | 
|  | 1102 | Instruction</a> </div> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1103 | <div class="doc_text"> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1104 | <h5>Syntax:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1105 | <pre>  ret <type> <value>       <i>; Return a value from a non-void function</i> | 
| Chris Lattner | 590645f | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1106 | ret void                 <i>; Return from void function</i> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1107 | </pre> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1108 | <h5>Overview:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1109 | <p>The '<tt>ret</tt>' instruction is used to return control flow (and a | 
|  | 1110 | value) from a function, back to the caller.</p> | 
| John Criswell | 417228d | 2004-04-09 16:48:45 +0000 | [diff] [blame] | 1111 | <p>There are two forms of the '<tt>ret</tt>' instruction: one that | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1112 | returns a value and then causes control flow, and one that just causes | 
|  | 1113 | control flow to occur.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1114 | <h5>Arguments:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1115 | <p>The '<tt>ret</tt>' instruction may return any '<a | 
|  | 1116 | href="#t_firstclass">first class</a>' type.  Notice that a function is | 
|  | 1117 | not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>' | 
|  | 1118 | instruction inside of the function that returns a value that does not | 
|  | 1119 | match the return type of the function.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1120 | <h5>Semantics:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1121 | <p>When the '<tt>ret</tt>' instruction is executed, control flow | 
|  | 1122 | returns back to the calling function's context.  If the caller is a "<a | 
| John Criswell | 40db33f | 2004-06-25 15:16:57 +0000 | [diff] [blame] | 1123 | href="#i_call"><tt>call</tt></a>" instruction, execution continues at | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1124 | the instruction after the call.  If the caller was an "<a | 
|  | 1125 | href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues | 
|  | 1126 | at the beginning "normal" of the destination block.  If the instruction | 
|  | 1127 | returns a value, that value shall set the call or invoke instruction's | 
|  | 1128 | return value.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1129 | <h5>Example:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1130 | <pre>  ret int 5                       <i>; Return an integer value of 5</i> | 
| Chris Lattner | 590645f | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1131 | ret void                        <i>; Return from a void function</i> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1132 | </pre> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1133 | </div> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1134 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1135 | <div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1136 | <div class="doc_text"> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1137 | <h5>Syntax:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1138 | <pre>  br bool <cond>, label <iftrue>, label <iffalse><br>  br label <dest>          <i>; Unconditional branch</i> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1139 | </pre> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1140 | <h5>Overview:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1141 | <p>The '<tt>br</tt>' instruction is used to cause control flow to | 
|  | 1142 | transfer to a different basic block in the current function.  There are | 
|  | 1143 | two forms of this instruction, corresponding to a conditional branch | 
|  | 1144 | and an unconditional branch.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1145 | <h5>Arguments:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1146 | <p>The conditional branch form of the '<tt>br</tt>' instruction takes a | 
|  | 1147 | single '<tt>bool</tt>' value and two '<tt>label</tt>' values.  The | 
|  | 1148 | unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>' | 
|  | 1149 | value as a target.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1150 | <h5>Semantics:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1151 | <p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>' | 
|  | 1152 | argument is evaluated.  If the value is <tt>true</tt>, control flows | 
|  | 1153 | to the '<tt>iftrue</tt>' <tt>label</tt> argument.  If "cond" is <tt>false</tt>, | 
|  | 1154 | control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1155 | <h5>Example:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1156 | <pre>Test:<br>  %cond = <a href="#i_setcc">seteq</a> int %a, %b<br>  br bool %cond, label %IfEqual, label %IfUnequal<br>IfEqual:<br>  <a | 
|  | 1157 | href="#i_ret">ret</a> int 1<br>IfUnequal:<br>  <a href="#i_ret">ret</a> int 0<br></pre> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1158 | </div> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1159 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | cf96c6c | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1160 | <div class="doc_subsubsection"> | 
|  | 1161 | <a name="i_switch">'<tt>switch</tt>' Instruction</a> | 
|  | 1162 | </div> | 
|  | 1163 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1164 | <div class="doc_text"> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1165 | <h5>Syntax:</h5> | 
| Chris Lattner | cf96c6c | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1166 |  | 
|  | 1167 | <pre> | 
|  | 1168 | switch <intty> <value>, label <defaultdest> [ <intty> <val>, label <dest> ... ] | 
|  | 1169 | </pre> | 
|  | 1170 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1171 | <h5>Overview:</h5> | 
| Chris Lattner | cf96c6c | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1172 |  | 
|  | 1173 | <p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of | 
|  | 1174 | several different places.  It is a generalization of the '<tt>br</tt>' | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1175 | instruction, allowing a branch to occur to one of many possible | 
|  | 1176 | destinations.</p> | 
| Chris Lattner | cf96c6c | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1177 |  | 
|  | 1178 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1179 | <h5>Arguments:</h5> | 
| Chris Lattner | cf96c6c | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1180 |  | 
|  | 1181 | <p>The '<tt>switch</tt>' instruction uses three parameters: an integer | 
|  | 1182 | comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and | 
|  | 1183 | an array of pairs of comparison value constants and '<tt>label</tt>'s.  The | 
|  | 1184 | table is not allowed to contain duplicate constant entries.</p> | 
|  | 1185 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1186 | <h5>Semantics:</h5> | 
| Chris Lattner | cf96c6c | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1187 |  | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1188 | <p>The <tt>switch</tt> instruction specifies a table of values and | 
|  | 1189 | destinations. When the '<tt>switch</tt>' instruction is executed, this | 
| John Criswell | bcbb18c | 2004-06-25 16:05:06 +0000 | [diff] [blame] | 1190 | table is searched for the given value.  If the value is found, control flow is | 
|  | 1191 | transfered to the corresponding destination; otherwise, control flow is | 
|  | 1192 | transfered to the default destination.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1193 |  | 
| Chris Lattner | cf96c6c | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1194 | <h5>Implementation:</h5> | 
|  | 1195 |  | 
|  | 1196 | <p>Depending on properties of the target machine and the particular | 
|  | 1197 | <tt>switch</tt> instruction, this instruction may be code generated in different | 
| John Criswell | bcbb18c | 2004-06-25 16:05:06 +0000 | [diff] [blame] | 1198 | ways.  For example, it could be generated as a series of chained conditional | 
|  | 1199 | branches or with a lookup table.</p> | 
| Chris Lattner | cf96c6c | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1200 |  | 
|  | 1201 | <h5>Example:</h5> | 
|  | 1202 |  | 
|  | 1203 | <pre> | 
|  | 1204 | <i>; Emulate a conditional br instruction</i> | 
|  | 1205 | %Val = <a href="#i_cast">cast</a> bool %value to int | 
|  | 1206 | switch int %Val, label %truedest [int 0, label %falsedest ] | 
|  | 1207 |  | 
|  | 1208 | <i>; Emulate an unconditional br instruction</i> | 
|  | 1209 | switch uint 0, label %dest [ ] | 
|  | 1210 |  | 
|  | 1211 | <i>; Implement a jump table:</i> | 
|  | 1212 | switch uint %val, label %otherwise [ uint 0, label %onzero | 
|  | 1213 | uint 1, label %onone | 
|  | 1214 | uint 2, label %ontwo ] | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1215 | </pre> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1216 | </div> | 
| Chris Lattner | 0132aff | 2005-05-06 22:57:40 +0000 | [diff] [blame^] | 1217 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1218 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 0132aff | 2005-05-06 22:57:40 +0000 | [diff] [blame^] | 1219 | <div class="doc_subsubsection"> | 
|  | 1220 | <a name="i_invoke">'<tt>invoke</tt>' Instruction</a> | 
|  | 1221 | </div> | 
|  | 1222 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1223 | <div class="doc_text"> | 
| Chris Lattner | 0132aff | 2005-05-06 22:57:40 +0000 | [diff] [blame^] | 1224 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1225 | <h5>Syntax:</h5> | 
| Chris Lattner | 0132aff | 2005-05-06 22:57:40 +0000 | [diff] [blame^] | 1226 |  | 
|  | 1227 | <pre> | 
|  | 1228 | <result> = invoke [<a href="#callingconv">cconv</a>] <ptr to function ty> %<function ptr val>(<function args>) | 
|  | 1229 | to label <normal label> except label <exception label> | 
|  | 1230 | </pre> | 
|  | 1231 |  | 
| Chris Lattner | a8292f3 | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 1232 | <h5>Overview:</h5> | 
| Chris Lattner | 0132aff | 2005-05-06 22:57:40 +0000 | [diff] [blame^] | 1233 |  | 
|  | 1234 | <p>The '<tt>invoke</tt>' instruction causes control to transfer to a specified | 
|  | 1235 | function, with the possibility of control flow transfer to either the | 
|  | 1236 | '<tt>normal</tt>' <tt>label</tt> label or the | 
|  | 1237 | '<tt>exception</tt>'<tt>label</tt>.  If the callee function returns with the | 
|  | 1238 | "<tt><a href="#i_ret">ret</a></tt>" instruction, control flow will return to the | 
|  | 1239 | "normal" label.  If the callee (or any indirect callees) returns with the "<a | 
|  | 1240 | href="#i_unwind"><tt>unwind</tt></a>" instruction, control is interrupted, and | 
|  | 1241 | continued at the dynamically nearest "except" label.</p> | 
|  | 1242 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1243 | <h5>Arguments:</h5> | 
| Chris Lattner | 0132aff | 2005-05-06 22:57:40 +0000 | [diff] [blame^] | 1244 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1245 | <p>This instruction requires several arguments:</p> | 
| Chris Lattner | 0132aff | 2005-05-06 22:57:40 +0000 | [diff] [blame^] | 1246 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1247 | <ol> | 
| Chris Lattner | 0132aff | 2005-05-06 22:57:40 +0000 | [diff] [blame^] | 1248 | <li> | 
|  | 1249 | <p>The optional "cconv" marker indicates which <a href="callingconv">calling | 
|  | 1250 | convention</a> the call should use.  If none is specified, the call defaults | 
|  | 1251 | to using C calling conventions. | 
|  | 1252 | </li> | 
|  | 1253 | <li>'<tt>ptr to function ty</tt>': shall be the signature of the pointer to | 
|  | 1254 | function value being invoked.  In most cases, this is a direct function | 
|  | 1255 | invocation, but indirect <tt>invoke</tt>s are just as possible, branching off | 
|  | 1256 | an arbitrary pointer to function value. | 
|  | 1257 | </li> | 
|  | 1258 |  | 
|  | 1259 | <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer to a | 
|  | 1260 | function to be invoked. </li> | 
|  | 1261 |  | 
|  | 1262 | <li>'<tt>function args</tt>': argument list whose types match the function | 
|  | 1263 | signature argument types.  If the function signature indicates the function | 
|  | 1264 | accepts a variable number of arguments, the extra arguments can be | 
|  | 1265 | specified. </li> | 
|  | 1266 |  | 
|  | 1267 | <li>'<tt>normal label</tt>': the label reached when the called function | 
|  | 1268 | executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li> | 
|  | 1269 |  | 
|  | 1270 | <li>'<tt>exception label</tt>': the label reached when a callee returns with | 
|  | 1271 | the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li> | 
|  | 1272 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1273 | </ol> | 
| Chris Lattner | 0132aff | 2005-05-06 22:57:40 +0000 | [diff] [blame^] | 1274 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1275 | <h5>Semantics:</h5> | 
| Chris Lattner | 0132aff | 2005-05-06 22:57:40 +0000 | [diff] [blame^] | 1276 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1277 | <p>This instruction is designed to operate as a standard '<tt><a | 
| Chris Lattner | 0132aff | 2005-05-06 22:57:40 +0000 | [diff] [blame^] | 1278 | href="#i_call">call</a></tt>' instruction in most regards.  The primary | 
|  | 1279 | difference is that it establishes an association with a label, which is used by | 
|  | 1280 | the runtime library to unwind the stack.</p> | 
|  | 1281 |  | 
|  | 1282 | <p>This instruction is used in languages with destructors to ensure that proper | 
|  | 1283 | cleanup is performed in the case of either a <tt>longjmp</tt> or a thrown | 
|  | 1284 | exception.  Additionally, this is important for implementation of | 
|  | 1285 | '<tt>catch</tt>' clauses in high-level languages that support them.</p> | 
|  | 1286 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1287 | <h5>Example:</h5> | 
| Chris Lattner | 0132aff | 2005-05-06 22:57:40 +0000 | [diff] [blame^] | 1288 | <pre> | 
|  | 1289 | %retval = invoke int %Test(int 15)             to label %Continue | 
|  | 1290 | except label %TestCleanup     <i>; {int}:retval set</i> | 
|  | 1291 | %retval = invoke <a href="#callingconv">coldcc</a> int %Test(int 15)             to label %Continue | 
|  | 1292 | except label %TestCleanup     <i>; {int}:retval set</i> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1293 | </pre> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1294 | </div> | 
| Chris Lattner | 08b7d5b | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 1295 |  | 
|  | 1296 |  | 
| Chris Lattner | 5ed6061 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 1297 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 08b7d5b | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 1298 |  | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1299 | <div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>' | 
|  | 1300 | Instruction</a> </div> | 
| Chris Lattner | 08b7d5b | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 1301 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1302 | <div class="doc_text"> | 
| Chris Lattner | 08b7d5b | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 1303 |  | 
| Chris Lattner | 5ed6061 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 1304 | <h5>Syntax:</h5> | 
| Chris Lattner | 08b7d5b | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 1305 | <pre> | 
|  | 1306 | unwind | 
|  | 1307 | </pre> | 
|  | 1308 |  | 
| Chris Lattner | 5ed6061 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 1309 | <h5>Overview:</h5> | 
| Chris Lattner | 08b7d5b | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 1310 |  | 
|  | 1311 | <p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow | 
|  | 1312 | at the first callee in the dynamic call stack which used an <a | 
|  | 1313 | href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call.  This is | 
|  | 1314 | primarily used to implement exception handling.</p> | 
|  | 1315 |  | 
| Chris Lattner | 5ed6061 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 1316 | <h5>Semantics:</h5> | 
| Chris Lattner | 08b7d5b | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 1317 |  | 
|  | 1318 | <p>The '<tt>unwind</tt>' intrinsic causes execution of the current function to | 
|  | 1319 | immediately halt.  The dynamic call stack is then searched for the first <a | 
|  | 1320 | href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack.  Once found, | 
|  | 1321 | execution continues at the "exceptional" destination block specified by the | 
|  | 1322 | <tt>invoke</tt> instruction.  If there is no <tt>invoke</tt> instruction in the | 
|  | 1323 | dynamic call chain, undefined behavior results.</p> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1324 | </div> | 
| Chris Lattner | 08b7d5b | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 1325 |  | 
|  | 1326 | <!-- _______________________________________________________________________ --> | 
|  | 1327 |  | 
|  | 1328 | <div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>' | 
|  | 1329 | Instruction</a> </div> | 
|  | 1330 |  | 
|  | 1331 | <div class="doc_text"> | 
|  | 1332 |  | 
|  | 1333 | <h5>Syntax:</h5> | 
|  | 1334 | <pre> | 
|  | 1335 | unreachable | 
|  | 1336 | </pre> | 
|  | 1337 |  | 
|  | 1338 | <h5>Overview:</h5> | 
|  | 1339 |  | 
|  | 1340 | <p>The '<tt>unreachable</tt>' instruction has no defined semantics.  This | 
|  | 1341 | instruction is used to inform the optimizer that a particular portion of the | 
|  | 1342 | code is not reachable.  This can be used to indicate that the code after a | 
|  | 1343 | no-return function cannot be reached, and other facts.</p> | 
|  | 1344 |  | 
|  | 1345 | <h5>Semantics:</h5> | 
|  | 1346 |  | 
|  | 1347 | <p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p> | 
|  | 1348 | </div> | 
|  | 1349 |  | 
|  | 1350 |  | 
|  | 1351 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1352 | <!-- ======================================================================= --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1353 | <div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1354 | <div class="doc_text"> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1355 | <p>Binary operators are used to do most of the computation in a | 
|  | 1356 | program.  They require two operands, execute an operation on them, and | 
| John Criswell | dfe6a86 | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 1357 | produce a single value.  The operands might represent | 
| Chris Lattner | c8cb695 | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 1358 | multiple data, as is the case with the <a href="#t_packed">packed</a> data type. | 
|  | 1359 | The result value of a binary operator is not | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1360 | necessarily the same type as its operands.</p> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1361 | <p>There are several different binary operators:</p> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1362 | </div> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1363 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1364 | <div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>' | 
|  | 1365 | Instruction</a> </div> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1366 | <div class="doc_text"> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1367 | <h5>Syntax:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1368 | <pre>  <result> = add <ty> <var1>, <var2>   <i>; yields {ty}:result</i> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1369 | </pre> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1370 | <h5>Overview:</h5> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1371 | <p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1372 | <h5>Arguments:</h5> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1373 | <p>The two arguments to the '<tt>add</tt>' instruction must be either <a | 
| Chris Lattner | c8cb695 | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 1374 | href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> values. | 
|  | 1375 | This instruction can also take <a href="#t_packed">packed</a> versions of the values. | 
|  | 1376 | Both arguments must have identical types.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1377 | <h5>Semantics:</h5> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1378 | <p>The value produced is the integer or floating point sum of the two | 
|  | 1379 | operands.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1380 | <h5>Example:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1381 | <pre>  <result> = add int 4, %var          <i>; yields {int}:result = 4 + %var</i> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1382 | </pre> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1383 | </div> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1384 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1385 | <div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>' | 
|  | 1386 | Instruction</a> </div> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1387 | <div class="doc_text"> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1388 | <h5>Syntax:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1389 | <pre>  <result> = sub <ty> <var1>, <var2>   <i>; yields {ty}:result</i> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1390 | </pre> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1391 | <h5>Overview:</h5> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1392 | <p>The '<tt>sub</tt>' instruction returns the difference of its two | 
|  | 1393 | operands.</p> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1394 | <p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>' | 
|  | 1395 | instruction present in most other intermediate representations.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1396 | <h5>Arguments:</h5> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1397 | <p>The two arguments to the '<tt>sub</tt>' instruction must be either <a | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1398 | href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> | 
| Chris Lattner | c8cb695 | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 1399 | values. | 
|  | 1400 | This instruction can also take <a href="#t_packed">packed</a> versions of the values. | 
|  | 1401 | Both arguments must have identical types.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1402 | <h5>Semantics:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1403 | <p>The value produced is the integer or floating point difference of | 
|  | 1404 | the two operands.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1405 | <h5>Example:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1406 | <pre>  <result> = sub int 4, %var          <i>; yields {int}:result = 4 - %var</i> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1407 | <result> = sub int 0, %val          <i>; yields {int}:result = -%var</i> | 
|  | 1408 | </pre> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1409 | </div> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1410 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1411 | <div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>' | 
|  | 1412 | Instruction</a> </div> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1413 | <div class="doc_text"> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1414 | <h5>Syntax:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1415 | <pre>  <result> = mul <ty> <var1>, <var2>   <i>; yields {ty}:result</i> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1416 | </pre> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1417 | <h5>Overview:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1418 | <p>The  '<tt>mul</tt>' instruction returns the product of its two | 
|  | 1419 | operands.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1420 | <h5>Arguments:</h5> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1421 | <p>The two arguments to the '<tt>mul</tt>' instruction must be either <a | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1422 | href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> | 
| Chris Lattner | c8cb695 | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 1423 | values. | 
|  | 1424 | This instruction can also take <a href="#t_packed">packed</a> versions of the values. | 
|  | 1425 | Both arguments must have identical types.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1426 | <h5>Semantics:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1427 | <p>The value produced is the integer or floating point product of the | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1428 | two operands.</p> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1429 | <p>There is no signed vs unsigned multiplication.  The appropriate | 
|  | 1430 | action is taken based on the type of the operand.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1431 | <h5>Example:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1432 | <pre>  <result> = mul int 4, %var          <i>; yields {int}:result = 4 * %var</i> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1433 | </pre> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1434 | </div> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1435 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1436 | <div class="doc_subsubsection"> <a name="i_div">'<tt>div</tt>' | 
|  | 1437 | Instruction</a> </div> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1438 | <div class="doc_text"> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1439 | <h5>Syntax:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1440 | <pre>  <result> = div <ty> <var1>, <var2>   <i>; yields {ty}:result</i> | 
|  | 1441 | </pre> | 
|  | 1442 | <h5>Overview:</h5> | 
|  | 1443 | <p>The '<tt>div</tt>' instruction returns the quotient of its two | 
|  | 1444 | operands.</p> | 
|  | 1445 | <h5>Arguments:</h5> | 
|  | 1446 | <p>The two arguments to the '<tt>div</tt>' instruction must be either <a | 
|  | 1447 | href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> | 
| Chris Lattner | c8cb695 | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 1448 | values. | 
|  | 1449 | This instruction can also take <a href="#t_packed">packed</a> versions of the values. | 
|  | 1450 | Both arguments must have identical types.</p> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1451 | <h5>Semantics:</h5> | 
|  | 1452 | <p>The value produced is the integer or floating point quotient of the | 
|  | 1453 | two operands.</p> | 
|  | 1454 | <h5>Example:</h5> | 
|  | 1455 | <pre>  <result> = div int 4, %var          <i>; yields {int}:result = 4 / %var</i> | 
|  | 1456 | </pre> | 
|  | 1457 | </div> | 
|  | 1458 | <!-- _______________________________________________________________________ --> | 
|  | 1459 | <div class="doc_subsubsection"> <a name="i_rem">'<tt>rem</tt>' | 
|  | 1460 | Instruction</a> </div> | 
|  | 1461 | <div class="doc_text"> | 
|  | 1462 | <h5>Syntax:</h5> | 
|  | 1463 | <pre>  <result> = rem <ty> <var1>, <var2>   <i>; yields {ty}:result</i> | 
|  | 1464 | </pre> | 
|  | 1465 | <h5>Overview:</h5> | 
|  | 1466 | <p>The '<tt>rem</tt>' instruction returns the remainder from the | 
|  | 1467 | division of its two operands.</p> | 
|  | 1468 | <h5>Arguments:</h5> | 
|  | 1469 | <p>The two arguments to the '<tt>rem</tt>' instruction must be either <a | 
|  | 1470 | href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> | 
| Chris Lattner | c8cb695 | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 1471 | values. | 
|  | 1472 | This instruction can also take <a href="#t_packed">packed</a> versions of the values. | 
|  | 1473 | Both arguments must have identical types.</p> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1474 | <h5>Semantics:</h5> | 
|  | 1475 | <p>This returns the <i>remainder</i> of a division (where the result | 
|  | 1476 | has the same sign as the divisor), not the <i>modulus</i> (where the | 
|  | 1477 | result has the same sign as the dividend) of a value.  For more | 
|  | 1478 | information about the difference, see: <a | 
|  | 1479 | href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The | 
|  | 1480 | Math Forum</a>.</p> | 
|  | 1481 | <h5>Example:</h5> | 
|  | 1482 | <pre>  <result> = rem int 4, %var          <i>; yields {int}:result = 4 % %var</i> | 
|  | 1483 | </pre> | 
|  | 1484 | </div> | 
|  | 1485 | <!-- _______________________________________________________________________ --> | 
|  | 1486 | <div class="doc_subsubsection"> <a name="i_setcc">'<tt>set<i>cc</i></tt>' | 
|  | 1487 | Instructions</a> </div> | 
|  | 1488 | <div class="doc_text"> | 
|  | 1489 | <h5>Syntax:</h5> | 
|  | 1490 | <pre>  <result> = seteq <ty> <var1>, <var2>   <i>; yields {bool}:result</i> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1491 | <result> = setne <ty> <var1>, <var2>   <i>; yields {bool}:result</i> | 
|  | 1492 | <result> = setlt <ty> <var1>, <var2>   <i>; yields {bool}:result</i> | 
|  | 1493 | <result> = setgt <ty> <var1>, <var2>   <i>; yields {bool}:result</i> | 
|  | 1494 | <result> = setle <ty> <var1>, <var2>   <i>; yields {bool}:result</i> | 
|  | 1495 | <result> = setge <ty> <var1>, <var2>   <i>; yields {bool}:result</i> | 
|  | 1496 | </pre> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1497 | <h5>Overview:</h5> | 
|  | 1498 | <p>The '<tt>set<i>cc</i></tt>' family of instructions returns a boolean | 
|  | 1499 | value based on a comparison of their two operands.</p> | 
|  | 1500 | <h5>Arguments:</h5> | 
|  | 1501 | <p>The two arguments to the '<tt>set<i>cc</i></tt>' instructions must | 
|  | 1502 | be of <a href="#t_firstclass">first class</a> type (it is not possible | 
|  | 1503 | to compare '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>' | 
|  | 1504 | or '<tt>void</tt>' values, etc...).  Both arguments must have identical | 
|  | 1505 | types.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1506 | <h5>Semantics:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1507 | <p>The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' | 
|  | 1508 | value if both operands are equal.<br> | 
|  | 1509 | The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' | 
|  | 1510 | value if both operands are unequal.<br> | 
|  | 1511 | The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' | 
|  | 1512 | value if the first operand is less than the second operand.<br> | 
|  | 1513 | The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' | 
|  | 1514 | value if the first operand is greater than the second operand.<br> | 
|  | 1515 | The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' | 
|  | 1516 | value if the first operand is less than or equal to the second operand.<br> | 
|  | 1517 | The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' | 
|  | 1518 | value if the first operand is greater than or equal to the second | 
|  | 1519 | operand.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1520 | <h5>Example:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1521 | <pre>  <result> = seteq int   4, 5        <i>; yields {bool}:result = false</i> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1522 | <result> = setne float 4, 5        <i>; yields {bool}:result = true</i> | 
|  | 1523 | <result> = setlt uint  4, 5        <i>; yields {bool}:result = true</i> | 
|  | 1524 | <result> = setgt sbyte 4, 5        <i>; yields {bool}:result = false</i> | 
|  | 1525 | <result> = setle sbyte 4, 5        <i>; yields {bool}:result = true</i> | 
|  | 1526 | <result> = setge sbyte 4, 5        <i>; yields {bool}:result = false</i> | 
|  | 1527 | </pre> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1528 | </div> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1529 | <!-- ======================================================================= --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1530 | <div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary | 
|  | 1531 | Operations</a> </div> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1532 | <div class="doc_text"> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1533 | <p>Bitwise binary operators are used to do various forms of | 
|  | 1534 | bit-twiddling in a program.  They are generally very efficient | 
| John Criswell | dfe6a86 | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 1535 | instructions and can commonly be strength reduced from other | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1536 | instructions.  They require two operands, execute an operation on them, | 
|  | 1537 | and produce a single value.  The resulting value of the bitwise binary | 
|  | 1538 | operators is always the same type as its first operand.</p> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1539 | </div> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1540 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1541 | <div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>' | 
|  | 1542 | Instruction</a> </div> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1543 | <div class="doc_text"> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1544 | <h5>Syntax:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1545 | <pre>  <result> = and <ty> <var1>, <var2>   <i>; yields {ty}:result</i> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1546 | </pre> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1547 | <h5>Overview:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1548 | <p>The '<tt>and</tt>' instruction returns the bitwise logical and of | 
|  | 1549 | its two operands.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1550 | <h5>Arguments:</h5> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1551 | <p>The two arguments to the '<tt>and</tt>' instruction must be <a | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1552 | href="#t_integral">integral</a> values.  Both arguments must have | 
|  | 1553 | identical types.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1554 | <h5>Semantics:</h5> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1555 | <p>The truth table used for the '<tt>and</tt>' instruction is:</p> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1556 | <p> </p> | 
| Misha Brukman | c501f55 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 1557 | <div style="align: center"> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1558 | <table border="1" cellspacing="0" cellpadding="4"> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1559 | <tbody> | 
|  | 1560 | <tr> | 
|  | 1561 | <td>In0</td> | 
|  | 1562 | <td>In1</td> | 
|  | 1563 | <td>Out</td> | 
|  | 1564 | </tr> | 
|  | 1565 | <tr> | 
|  | 1566 | <td>0</td> | 
|  | 1567 | <td>0</td> | 
|  | 1568 | <td>0</td> | 
|  | 1569 | </tr> | 
|  | 1570 | <tr> | 
|  | 1571 | <td>0</td> | 
|  | 1572 | <td>1</td> | 
|  | 1573 | <td>0</td> | 
|  | 1574 | </tr> | 
|  | 1575 | <tr> | 
|  | 1576 | <td>1</td> | 
|  | 1577 | <td>0</td> | 
|  | 1578 | <td>0</td> | 
|  | 1579 | </tr> | 
|  | 1580 | <tr> | 
|  | 1581 | <td>1</td> | 
|  | 1582 | <td>1</td> | 
|  | 1583 | <td>1</td> | 
|  | 1584 | </tr> | 
|  | 1585 | </tbody> | 
|  | 1586 | </table> | 
| Misha Brukman | c501f55 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 1587 | </div> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1588 | <h5>Example:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1589 | <pre>  <result> = and int 4, %var         <i>; yields {int}:result = 4 & %var</i> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1590 | <result> = and int 15, 40          <i>; yields {int}:result = 8</i> | 
|  | 1591 | <result> = and int 4, 8            <i>; yields {int}:result = 0</i> | 
|  | 1592 | </pre> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1593 | </div> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1594 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1595 | <div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1596 | <div class="doc_text"> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1597 | <h5>Syntax:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1598 | <pre>  <result> = or <ty> <var1>, <var2>   <i>; yields {ty}:result</i> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1599 | </pre> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1600 | <h5>Overview:</h5> | 
|  | 1601 | <p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive | 
|  | 1602 | or of its two operands.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1603 | <h5>Arguments:</h5> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1604 | <p>The two arguments to the '<tt>or</tt>' instruction must be <a | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1605 | href="#t_integral">integral</a> values.  Both arguments must have | 
|  | 1606 | identical types.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1607 | <h5>Semantics:</h5> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1608 | <p>The truth table used for the '<tt>or</tt>' instruction is:</p> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1609 | <p> </p> | 
| Misha Brukman | c501f55 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 1610 | <div style="align: center"> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1611 | <table border="1" cellspacing="0" cellpadding="4"> | 
|  | 1612 | <tbody> | 
|  | 1613 | <tr> | 
|  | 1614 | <td>In0</td> | 
|  | 1615 | <td>In1</td> | 
|  | 1616 | <td>Out</td> | 
|  | 1617 | </tr> | 
|  | 1618 | <tr> | 
|  | 1619 | <td>0</td> | 
|  | 1620 | <td>0</td> | 
|  | 1621 | <td>0</td> | 
|  | 1622 | </tr> | 
|  | 1623 | <tr> | 
|  | 1624 | <td>0</td> | 
|  | 1625 | <td>1</td> | 
|  | 1626 | <td>1</td> | 
|  | 1627 | </tr> | 
|  | 1628 | <tr> | 
|  | 1629 | <td>1</td> | 
|  | 1630 | <td>0</td> | 
|  | 1631 | <td>1</td> | 
|  | 1632 | </tr> | 
|  | 1633 | <tr> | 
|  | 1634 | <td>1</td> | 
|  | 1635 | <td>1</td> | 
|  | 1636 | <td>1</td> | 
|  | 1637 | </tr> | 
|  | 1638 | </tbody> | 
|  | 1639 | </table> | 
| Misha Brukman | c501f55 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 1640 | </div> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1641 | <h5>Example:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1642 | <pre>  <result> = or int 4, %var         <i>; yields {int}:result = 4 | %var</i> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1643 | <result> = or int 15, 40          <i>; yields {int}:result = 47</i> | 
|  | 1644 | <result> = or int 4, 8            <i>; yields {int}:result = 12</i> | 
|  | 1645 | </pre> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1646 | </div> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1647 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1648 | <div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>' | 
|  | 1649 | Instruction</a> </div> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1650 | <div class="doc_text"> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1651 | <h5>Syntax:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1652 | <pre>  <result> = xor <ty> <var1>, <var2>   <i>; yields {ty}:result</i> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1653 | </pre> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1654 | <h5>Overview:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1655 | <p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive | 
|  | 1656 | or of its two operands.  The <tt>xor</tt> is used to implement the | 
|  | 1657 | "one's complement" operation, which is the "~" operator in C.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1658 | <h5>Arguments:</h5> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1659 | <p>The two arguments to the '<tt>xor</tt>' instruction must be <a | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1660 | href="#t_integral">integral</a> values.  Both arguments must have | 
|  | 1661 | identical types.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1662 | <h5>Semantics:</h5> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1663 | <p>The truth table used for the '<tt>xor</tt>' instruction is:</p> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1664 | <p> </p> | 
| Misha Brukman | c501f55 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 1665 | <div style="align: center"> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1666 | <table border="1" cellspacing="0" cellpadding="4"> | 
|  | 1667 | <tbody> | 
|  | 1668 | <tr> | 
|  | 1669 | <td>In0</td> | 
|  | 1670 | <td>In1</td> | 
|  | 1671 | <td>Out</td> | 
|  | 1672 | </tr> | 
|  | 1673 | <tr> | 
|  | 1674 | <td>0</td> | 
|  | 1675 | <td>0</td> | 
|  | 1676 | <td>0</td> | 
|  | 1677 | </tr> | 
|  | 1678 | <tr> | 
|  | 1679 | <td>0</td> | 
|  | 1680 | <td>1</td> | 
|  | 1681 | <td>1</td> | 
|  | 1682 | </tr> | 
|  | 1683 | <tr> | 
|  | 1684 | <td>1</td> | 
|  | 1685 | <td>0</td> | 
|  | 1686 | <td>1</td> | 
|  | 1687 | </tr> | 
|  | 1688 | <tr> | 
|  | 1689 | <td>1</td> | 
|  | 1690 | <td>1</td> | 
|  | 1691 | <td>0</td> | 
|  | 1692 | </tr> | 
|  | 1693 | </tbody> | 
|  | 1694 | </table> | 
| Misha Brukman | c501f55 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 1695 | </div> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1696 | <p> </p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1697 | <h5>Example:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1698 | <pre>  <result> = xor int 4, %var         <i>; yields {int}:result = 4 ^ %var</i> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1699 | <result> = xor int 15, 40          <i>; yields {int}:result = 39</i> | 
|  | 1700 | <result> = xor int 4, 8            <i>; yields {int}:result = 12</i> | 
| Chris Lattner | 5ed6061 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 1701 | <result> = xor int %V, -1          <i>; yields {int}:result = ~%V</i> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1702 | </pre> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1703 | </div> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1704 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1705 | <div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>' | 
|  | 1706 | Instruction</a> </div> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1707 | <div class="doc_text"> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1708 | <h5>Syntax:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1709 | <pre>  <result> = shl <ty> <var1>, ubyte <var2>   <i>; yields {ty}:result</i> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1710 | </pre> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1711 | <h5>Overview:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1712 | <p>The '<tt>shl</tt>' instruction returns the first operand shifted to | 
|  | 1713 | the left a specified number of bits.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1714 | <h5>Arguments:</h5> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1715 | <p>The first argument to the '<tt>shl</tt>' instruction must be an <a | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1716 | href="#t_integer">integer</a> type.  The second argument must be an '<tt>ubyte</tt>' | 
|  | 1717 | type.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1718 | <h5>Semantics:</h5> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1719 | <p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1720 | <h5>Example:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1721 | <pre>  <result> = shl int 4, ubyte %var   <i>; yields {int}:result = 4 << %var</i> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1722 | <result> = shl int 4, ubyte 2      <i>; yields {int}:result = 16</i> | 
|  | 1723 | <result> = shl int 1, ubyte 10     <i>; yields {int}:result = 1024</i> | 
|  | 1724 | </pre> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1725 | </div> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1726 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1727 | <div class="doc_subsubsection"> <a name="i_shr">'<tt>shr</tt>' | 
|  | 1728 | Instruction</a> </div> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1729 | <div class="doc_text"> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1730 | <h5>Syntax:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1731 | <pre>  <result> = shr <ty> <var1>, ubyte <var2>   <i>; yields {ty}:result</i> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1732 | </pre> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1733 | <h5>Overview:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1734 | <p>The '<tt>shr</tt>' instruction returns the first operand shifted to | 
|  | 1735 | the right a specified number of bits.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1736 | <h5>Arguments:</h5> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1737 | <p>The first argument to the '<tt>shr</tt>' instruction must be an <a | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1738 | href="#t_integer">integer</a> type.  The second argument must be an '<tt>ubyte</tt>' | 
|  | 1739 | type.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1740 | <h5>Semantics:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1741 | <p>If the first argument is a <a href="#t_signed">signed</a> type, the | 
|  | 1742 | most significant bit is duplicated in the newly free'd bit positions. | 
|  | 1743 | If the first argument is unsigned, zero bits shall fill the empty | 
|  | 1744 | positions.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1745 | <h5>Example:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1746 | <pre>  <result> = shr int 4, ubyte %var   <i>; yields {int}:result = 4 >> %var</i> | 
| Chris Lattner | 33426d9 | 2003-06-18 21:30:51 +0000 | [diff] [blame] | 1747 | <result> = shr uint 4, ubyte 1     <i>; yields {uint}:result = 2</i> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1748 | <result> = shr int 4, ubyte 2      <i>; yields {int}:result = 1</i> | 
| Chris Lattner | 33426d9 | 2003-06-18 21:30:51 +0000 | [diff] [blame] | 1749 | <result> = shr sbyte 4, ubyte 3    <i>; yields {sbyte}:result = 0</i> | 
|  | 1750 | <result> = shr sbyte -2, ubyte 1   <i>; yields {sbyte}:result = -1</i> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1751 | </pre> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1752 | </div> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1753 | <!-- ======================================================================= --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1754 | <div class="doc_subsection"> <a name="memoryops">Memory Access | 
|  | 1755 | Operations</a></div> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1756 | <div class="doc_text"> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1757 | <p>A key design point of an SSA-based representation is how it | 
|  | 1758 | represents memory.  In LLVM, no memory locations are in SSA form, which | 
|  | 1759 | makes things very simple.  This section describes how to read, write, | 
| John Criswell | dfe6a86 | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 1760 | allocate, and free memory in LLVM.</p> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1761 | </div> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1762 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1763 | <div class="doc_subsubsection"> <a name="i_malloc">'<tt>malloc</tt>' | 
|  | 1764 | Instruction</a> </div> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1765 | <div class="doc_text"> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1766 | <h5>Syntax:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1767 | <pre>  <result> = malloc <type>, uint <NumElements>     <i>; yields {type*}:result</i> | 
| Chris Lattner | 590645f | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1768 | <result> = malloc <type>                         <i>; yields {type*}:result</i> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1769 | </pre> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1770 | <h5>Overview:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1771 | <p>The '<tt>malloc</tt>' instruction allocates memory from the system | 
|  | 1772 | heap and returns a pointer to it.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1773 | <h5>Arguments:</h5> | 
| John Criswell | a92e586 | 2004-02-24 16:13:56 +0000 | [diff] [blame] | 1774 | <p>The '<tt>malloc</tt>' instruction allocates <tt>sizeof(<type>)*NumElements</tt> | 
|  | 1775 | bytes of memory from the operating system and returns a pointer of the | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1776 | appropriate type to the program.  The second form of the instruction is | 
|  | 1777 | a shorter version of the first instruction that defaults to allocating | 
|  | 1778 | one element.</p> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1779 | <p>'<tt>type</tt>' must be a sized type.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1780 | <h5>Semantics:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1781 | <p>Memory is allocated using the system "<tt>malloc</tt>" function, and | 
|  | 1782 | a pointer is returned.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1783 | <h5>Example:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1784 | <pre>  %array  = malloc [4 x ubyte ]                    <i>; yields {[%4 x ubyte]*}:array</i> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1785 |  | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1786 | %size   = <a | 
|  | 1787 | href="#i_add">add</a> uint 2, 2                          <i>; yields {uint}:size = uint 4</i> | 
| Chris Lattner | 590645f | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1788 | %array1 = malloc ubyte, uint 4                   <i>; yields {ubyte*}:array1</i> | 
|  | 1789 | %array2 = malloc [12 x ubyte], uint %size        <i>; yields {[12 x ubyte]*}:array2</i> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1790 | </pre> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1791 | </div> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1792 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1793 | <div class="doc_subsubsection"> <a name="i_free">'<tt>free</tt>' | 
|  | 1794 | Instruction</a> </div> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1795 | <div class="doc_text"> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1796 | <h5>Syntax:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1797 | <pre>  free <type> <value>                              <i>; yields {void}</i> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1798 | </pre> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1799 | <h5>Overview:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1800 | <p>The '<tt>free</tt>' instruction returns memory back to the unused | 
|  | 1801 | memory heap, to be reallocated in the future.</p> | 
|  | 1802 | <p> </p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1803 | <h5>Arguments:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1804 | <p>'<tt>value</tt>' shall be a pointer value that points to a value | 
|  | 1805 | that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>' | 
|  | 1806 | instruction.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1807 | <h5>Semantics:</h5> | 
| John Criswell | dfe6a86 | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 1808 | <p>Access to the memory pointed to by the pointer is no longer defined | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1809 | after this instruction executes.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1810 | <h5>Example:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1811 | <pre>  %array  = <a href="#i_malloc">malloc</a> [4 x ubyte]                    <i>; yields {[4 x ubyte]*}:array</i> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1812 | free   [4 x ubyte]* %array | 
|  | 1813 | </pre> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1814 | </div> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1815 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1816 | <div class="doc_subsubsection"> <a name="i_alloca">'<tt>alloca</tt>' | 
|  | 1817 | Instruction</a> </div> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1818 | <div class="doc_text"> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1819 | <h5>Syntax:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1820 | <pre>  <result> = alloca <type>, uint <NumElements>  <i>; yields {type*}:result</i> | 
| Chris Lattner | 590645f | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1821 | <result> = alloca <type>                      <i>; yields {type*}:result</i> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1822 | </pre> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1823 | <h5>Overview:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1824 | <p>The '<tt>alloca</tt>' instruction allocates memory on the current | 
|  | 1825 | stack frame of the procedure that is live until the current function | 
|  | 1826 | returns to its caller.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1827 | <h5>Arguments:</h5> | 
| John Criswell | dfe6a86 | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 1828 | <p>The '<tt>alloca</tt>' instruction allocates <tt>sizeof(<type>)*NumElements</tt> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1829 | bytes of memory on the runtime stack, returning a pointer of the | 
|  | 1830 | appropriate type to the program.  The second form of the instruction is | 
|  | 1831 | a shorter version of the first that defaults to allocating one element.</p> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1832 | <p>'<tt>type</tt>' may be any sized type.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1833 | <h5>Semantics:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1834 | <p>Memory is allocated, a pointer is returned.  '<tt>alloca</tt>'d | 
|  | 1835 | memory is automatically released when the function returns.  The '<tt>alloca</tt>' | 
|  | 1836 | instruction is commonly used to represent automatic variables that must | 
|  | 1837 | have an address available.  When the function returns (either with the <tt><a | 
|  | 1838 | href="#i_ret">ret</a></tt> or <tt><a href="#i_invoke">invoke</a></tt> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1839 | instructions), the memory is reclaimed.</p> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1840 | <h5>Example:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1841 | <pre>  %ptr = alloca int                              <i>; yields {int*}:ptr</i> | 
| Chris Lattner | 590645f | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1842 | %ptr = alloca int, uint 4                      <i>; yields {int*}:ptr</i> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1843 | </pre> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1844 | </div> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1845 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1846 | <div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>' | 
|  | 1847 | Instruction</a> </div> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1848 | <div class="doc_text"> | 
| Chris Lattner | 095735d | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1849 | <h5>Syntax:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1850 | <pre>  <result> = load <ty>* <pointer><br>  <result> = volatile load <ty>* <pointer><br></pre> | 
| Chris Lattner | 095735d | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1851 | <h5>Overview:</h5> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1852 | <p>The '<tt>load</tt>' instruction is used to read from memory.</p> | 
| Chris Lattner | 095735d | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1853 | <h5>Arguments:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1854 | <p>The argument to the '<tt>load</tt>' instruction specifies the memory | 
|  | 1855 | address to load from.  The pointer must point to a <a | 
| Chris Lattner | 10ee965 | 2004-06-03 22:57:15 +0000 | [diff] [blame] | 1856 | href="#t_firstclass">first class</a> type.  If the <tt>load</tt> is | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1857 | marked as <tt>volatile</tt> then the optimizer is not allowed to modify | 
|  | 1858 | the number or order of execution of this <tt>load</tt> with other | 
|  | 1859 | volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt> | 
|  | 1860 | instructions. </p> | 
| Chris Lattner | 095735d | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1861 | <h5>Semantics:</h5> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1862 | <p>The location of memory pointed to is loaded.</p> | 
| Chris Lattner | 095735d | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1863 | <h5>Examples:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1864 | <pre>  %ptr = <a href="#i_alloca">alloca</a> int                               <i>; yields {int*}:ptr</i> | 
|  | 1865 | <a | 
|  | 1866 | href="#i_store">store</a> int 3, int* %ptr                          <i>; yields {void}</i> | 
| Chris Lattner | 095735d | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1867 | %val = load int* %ptr                           <i>; yields {int}:val = int 3</i> | 
|  | 1868 | </pre> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1869 | </div> | 
| Chris Lattner | 095735d | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1870 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1871 | <div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>' | 
|  | 1872 | Instruction</a> </div> | 
| Chris Lattner | 095735d | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1873 | <h5>Syntax:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1874 | <pre>  store <ty> <value>, <ty>* <pointer>                   <i>; yields {void}</i> | 
| Chris Lattner | 12d456c | 2003-09-08 18:27:49 +0000 | [diff] [blame] | 1875 | volatile store <ty> <value>, <ty>* <pointer>                   <i>; yields {void}</i> | 
| Chris Lattner | 095735d | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1876 | </pre> | 
| Chris Lattner | 095735d | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1877 | <h5>Overview:</h5> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1878 | <p>The '<tt>store</tt>' instruction is used to write to memory.</p> | 
| Chris Lattner | 095735d | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1879 | <h5>Arguments:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1880 | <p>There are two arguments to the '<tt>store</tt>' instruction: a value | 
|  | 1881 | to store and an address to store it into.  The type of the '<tt><pointer></tt>' | 
|  | 1882 | operand must be a pointer to the type of the '<tt><value></tt>' | 
|  | 1883 | operand. If the <tt>store</tt> is marked as <tt>volatile</tt> then the | 
|  | 1884 | optimizer is not allowed to modify the number or order of execution of | 
|  | 1885 | this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a | 
|  | 1886 | href="#i_store">store</a></tt> instructions.</p> | 
|  | 1887 | <h5>Semantics:</h5> | 
|  | 1888 | <p>The contents of memory are updated to contain '<tt><value></tt>' | 
|  | 1889 | at the location specified by the '<tt><pointer></tt>' operand.</p> | 
| Chris Lattner | 095735d | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1890 | <h5>Example:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1891 | <pre>  %ptr = <a href="#i_alloca">alloca</a> int                               <i>; yields {int*}:ptr</i> | 
|  | 1892 | <a | 
|  | 1893 | href="#i_store">store</a> int 3, int* %ptr                          <i>; yields {void}</i> | 
| Chris Lattner | 095735d | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1894 | %val = load int* %ptr                           <i>; yields {int}:val = int 3</i> | 
|  | 1895 | </pre> | 
| Chris Lattner | 095735d | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1896 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 33fd702 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 1897 | <div class="doc_subsubsection"> | 
|  | 1898 | <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a> | 
|  | 1899 | </div> | 
|  | 1900 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1901 | <div class="doc_text"> | 
| Chris Lattner | 590645f | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1902 | <h5>Syntax:</h5> | 
| Chris Lattner | 33fd702 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 1903 | <pre> | 
|  | 1904 | <result> = getelementptr <ty>* <ptrval>{, <ty> <idx>}* | 
|  | 1905 | </pre> | 
|  | 1906 |  | 
| Chris Lattner | 590645f | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1907 | <h5>Overview:</h5> | 
| Chris Lattner | 33fd702 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 1908 |  | 
|  | 1909 | <p> | 
|  | 1910 | The '<tt>getelementptr</tt>' instruction is used to get the address of a | 
|  | 1911 | subelement of an aggregate data structure.</p> | 
|  | 1912 |  | 
| Chris Lattner | 590645f | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1913 | <h5>Arguments:</h5> | 
| Chris Lattner | 33fd702 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 1914 |  | 
|  | 1915 | <p>This instruction takes a list of integer constants that indicate what | 
|  | 1916 | elements of the aggregate object to index to.  The actual types of the arguments | 
|  | 1917 | provided depend on the type of the first pointer argument.  The | 
|  | 1918 | '<tt>getelementptr</tt>' instruction is used to index down through the type | 
|  | 1919 | levels of a structure.  When indexing into a structure, only <tt>uint</tt> | 
|  | 1920 | integer constants are allowed.  When indexing into an array or pointer | 
|  | 1921 | <tt>int</tt> and <tt>long</tt> indexes are allowed of any sign.</p> | 
|  | 1922 |  | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1923 | <p>For example, let's consider a C code fragment and how it gets | 
|  | 1924 | compiled to LLVM:</p> | 
| Chris Lattner | 33fd702 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 1925 |  | 
|  | 1926 | <pre> | 
|  | 1927 | struct RT { | 
|  | 1928 | char A; | 
|  | 1929 | int B[10][20]; | 
|  | 1930 | char C; | 
|  | 1931 | }; | 
|  | 1932 | struct ST { | 
|  | 1933 | int X; | 
|  | 1934 | double Y; | 
|  | 1935 | struct RT Z; | 
|  | 1936 | }; | 
|  | 1937 |  | 
|  | 1938 | int *foo(struct ST *s) { | 
|  | 1939 | return &s[1].Z.B[5][13]; | 
|  | 1940 | } | 
|  | 1941 | </pre> | 
|  | 1942 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1943 | <p>The LLVM code generated by the GCC frontend is:</p> | 
| Chris Lattner | 33fd702 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 1944 |  | 
|  | 1945 | <pre> | 
|  | 1946 | %RT = type { sbyte, [10 x [20 x int]], sbyte } | 
|  | 1947 | %ST = type { int, double, %RT } | 
|  | 1948 |  | 
| Brian Gaeke | 317ef96 | 2004-07-02 21:08:14 +0000 | [diff] [blame] | 1949 | implementation | 
|  | 1950 |  | 
|  | 1951 | int* %foo(%ST* %s) { | 
|  | 1952 | entry: | 
|  | 1953 | %reg = getelementptr %ST* %s, int 1, uint 2, uint 1, int 5, int 13 | 
| Chris Lattner | 33fd702 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 1954 | ret int* %reg | 
|  | 1955 | } | 
|  | 1956 | </pre> | 
|  | 1957 |  | 
| Chris Lattner | 590645f | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1958 | <h5>Semantics:</h5> | 
| Chris Lattner | 33fd702 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 1959 |  | 
|  | 1960 | <p>The index types specified for the '<tt>getelementptr</tt>' instruction depend | 
| Chris Lattner | 10ee965 | 2004-06-03 22:57:15 +0000 | [diff] [blame] | 1961 | on the pointer type that is being index into. <a href="#t_pointer">Pointer</a> | 
|  | 1962 | and <a href="#t_array">array</a> types require <tt>uint</tt>, <tt>int</tt>, | 
|  | 1963 | <tt>ulong</tt>, or <tt>long</tt> values, and <a href="#t_struct">structure</a> | 
| Chris Lattner | 33fd702 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 1964 | types require <tt>uint</tt> <b>constants</b>.</p> | 
|  | 1965 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1966 | <p>In the example above, the first index is indexing into the '<tt>%ST*</tt>' | 
| Chris Lattner | 33fd702 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 1967 | type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int, double, %RT | 
|  | 1968 | }</tt>' type, a structure.  The second index indexes into the third element of | 
|  | 1969 | the structure, yielding a '<tt>%RT</tt>' = '<tt>{ sbyte, [10 x [20 x int]], | 
|  | 1970 | sbyte }</tt>' type, another structure.  The third index indexes into the second | 
|  | 1971 | element of the structure, yielding a '<tt>[10 x [20 x int]]</tt>' type, an | 
|  | 1972 | array.  The two dimensions of the array are subscripted into, yielding an | 
|  | 1973 | '<tt>int</tt>' type.  The '<tt>getelementptr</tt>' instruction return a pointer | 
|  | 1974 | to this element, thus computing a value of '<tt>int*</tt>' type.</p> | 
|  | 1975 |  | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1976 | <p>Note that it is perfectly legal to index partially through a | 
|  | 1977 | structure, returning a pointer to an inner element.  Because of this, | 
|  | 1978 | the LLVM code for the given testcase is equivalent to:</p> | 
| Chris Lattner | 33fd702 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 1979 |  | 
|  | 1980 | <pre> | 
| Chris Lattner | 455fc8c | 2005-03-07 22:13:59 +0000 | [diff] [blame] | 1981 | int* %foo(%ST* %s) { | 
| Chris Lattner | 33fd702 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 1982 | %t1 = getelementptr %ST* %s, int 1                        <i>; yields %ST*:%t1</i> | 
|  | 1983 | %t2 = getelementptr %ST* %t1, int 0, uint 2               <i>; yields %RT*:%t2</i> | 
|  | 1984 | %t3 = getelementptr %RT* %t2, int 0, uint 1               <i>; yields [10 x [20 x int]]*:%t3</i> | 
|  | 1985 | %t4 = getelementptr [10 x [20 x int]]* %t3, int 0, int 5  <i>; yields [20 x int]*:%t4</i> | 
|  | 1986 | %t5 = getelementptr [20 x int]* %t4, int 0, int 13        <i>; yields int*:%t5</i> | 
|  | 1987 | ret int* %t5 | 
|  | 1988 | } | 
| Chris Lattner | a8292f3 | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 1989 | </pre> | 
| Chris Lattner | 590645f | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1990 | <h5>Example:</h5> | 
| Chris Lattner | 33fd702 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 1991 | <pre> | 
|  | 1992 | <i>; yields [12 x ubyte]*:aptr</i> | 
|  | 1993 | %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, uint 1 | 
|  | 1994 | </pre> | 
|  | 1995 |  | 
|  | 1996 | </div> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1997 | <!-- ======================================================================= --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1998 | <div class="doc_subsection"> <a name="otherops">Other Operations</a> </div> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1999 | <div class="doc_text"> | 
| John Criswell | 417228d | 2004-04-09 16:48:45 +0000 | [diff] [blame] | 2000 | <p>The instructions in this category are the "miscellaneous" | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2001 | instructions, which defy better classification.</p> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2002 | </div> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2003 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2004 | <div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>' | 
|  | 2005 | Instruction</a> </div> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2006 | <div class="doc_text"> | 
| Chris Lattner | 70de663 | 2001-07-09 00:26:23 +0000 | [diff] [blame] | 2007 | <h5>Syntax:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2008 | <pre>  <result> = phi <ty> [ <val0>, <label0>], ...<br></pre> | 
| Chris Lattner | 70de663 | 2001-07-09 00:26:23 +0000 | [diff] [blame] | 2009 | <h5>Overview:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2010 | <p>The '<tt>phi</tt>' instruction is used to implement the φ node in | 
|  | 2011 | the SSA graph representing the function.</p> | 
| Chris Lattner | 70de663 | 2001-07-09 00:26:23 +0000 | [diff] [blame] | 2012 | <h5>Arguments:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2013 | <p>The type of the incoming values are specified with the first type | 
|  | 2014 | field. After this, the '<tt>phi</tt>' instruction takes a list of pairs | 
|  | 2015 | as arguments, with one pair for each predecessor basic block of the | 
|  | 2016 | current block.  Only values of <a href="#t_firstclass">first class</a> | 
|  | 2017 | type may be used as the value arguments to the PHI node.  Only labels | 
|  | 2018 | may be used as the label arguments.</p> | 
|  | 2019 | <p>There must be no non-phi instructions between the start of a basic | 
|  | 2020 | block and the PHI instructions: i.e. PHI instructions must be first in | 
|  | 2021 | a basic block.</p> | 
| Chris Lattner | 70de663 | 2001-07-09 00:26:23 +0000 | [diff] [blame] | 2022 | <h5>Semantics:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2023 | <p>At runtime, the '<tt>phi</tt>' instruction logically takes on the | 
|  | 2024 | value specified by the parameter, depending on which basic block we | 
|  | 2025 | came from in the last <a href="#terminators">terminator</a> instruction.</p> | 
| Chris Lattner | a8292f3 | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 2026 | <h5>Example:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2027 | <pre>Loop:       ; Infinite loop that counts from 0 on up...<br>  %indvar = phi uint [ 0, %LoopHeader ], [ %nextindvar, %Loop ]<br>  %nextindvar = add uint %indvar, 1<br>  br label %Loop<br></pre> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2028 | </div> | 
| Chris Lattner | b53c28d | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 2029 |  | 
| Chris Lattner | a8292f3 | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 2030 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | b53c28d | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 2031 | <div class="doc_subsubsection"> | 
|  | 2032 | <a name="i_cast">'<tt>cast .. to</tt>' Instruction</a> | 
|  | 2033 | </div> | 
|  | 2034 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2035 | <div class="doc_text"> | 
| Chris Lattner | b53c28d | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 2036 |  | 
| Chris Lattner | a8292f3 | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 2037 | <h5>Syntax:</h5> | 
| Chris Lattner | b53c28d | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 2038 |  | 
|  | 2039 | <pre> | 
|  | 2040 | <result> = cast <ty> <value> to <ty2>             <i>; yields ty2</i> | 
| Chris Lattner | a8292f3 | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 2041 | </pre> | 
| Chris Lattner | b53c28d | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 2042 |  | 
| Chris Lattner | a8292f3 | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 2043 | <h5>Overview:</h5> | 
| Chris Lattner | b53c28d | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 2044 |  | 
|  | 2045 | <p> | 
|  | 2046 | The '<tt>cast</tt>' instruction is used as the primitive means to convert | 
|  | 2047 | integers to floating point, change data type sizes, and break type safety (by | 
|  | 2048 | casting pointers). | 
|  | 2049 | </p> | 
|  | 2050 |  | 
|  | 2051 |  | 
| Chris Lattner | a8292f3 | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 2052 | <h5>Arguments:</h5> | 
| Chris Lattner | b53c28d | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 2053 |  | 
|  | 2054 | <p> | 
|  | 2055 | The '<tt>cast</tt>' instruction takes a value to cast, which must be a first | 
|  | 2056 | class value, and a type to cast it to, which must also be a <a | 
|  | 2057 | href="#t_firstclass">first class</a> type. | 
|  | 2058 | </p> | 
|  | 2059 |  | 
| Chris Lattner | a8292f3 | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 2060 | <h5>Semantics:</h5> | 
| Chris Lattner | b53c28d | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 2061 |  | 
|  | 2062 | <p> | 
|  | 2063 | This instruction follows the C rules for explicit casts when determining how the | 
|  | 2064 | data being cast must change to fit in its new container. | 
|  | 2065 | </p> | 
|  | 2066 |  | 
|  | 2067 | <p> | 
|  | 2068 | When casting to bool, any value that would be considered true in the context of | 
|  | 2069 | a C '<tt>if</tt>' condition is converted to the boolean '<tt>true</tt>' values, | 
|  | 2070 | all else are '<tt>false</tt>'. | 
|  | 2071 | </p> | 
|  | 2072 |  | 
|  | 2073 | <p> | 
|  | 2074 | When extending an integral value from a type of one signness to another (for | 
|  | 2075 | example '<tt>sbyte</tt>' to '<tt>ulong</tt>'), the value is sign-extended if the | 
|  | 2076 | <b>source</b> value is signed, and zero-extended if the source value is | 
|  | 2077 | unsigned. <tt>bool</tt> values are always zero extended into either zero or | 
|  | 2078 | one. | 
|  | 2079 | </p> | 
|  | 2080 |  | 
| Chris Lattner | 70de663 | 2001-07-09 00:26:23 +0000 | [diff] [blame] | 2081 | <h5>Example:</h5> | 
| Chris Lattner | b53c28d | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 2082 |  | 
|  | 2083 | <pre> | 
|  | 2084 | %X = cast int 257 to ubyte              <i>; yields ubyte:1</i> | 
| Chris Lattner | d8f8ede | 2002-06-25 18:03:17 +0000 | [diff] [blame] | 2085 | %Y = cast int 123 to bool               <i>; yields bool:true</i> | 
| Chris Lattner | 70de663 | 2001-07-09 00:26:23 +0000 | [diff] [blame] | 2086 | </pre> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2087 | </div> | 
| Chris Lattner | b53c28d | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 2088 |  | 
|  | 2089 | <!-- _______________________________________________________________________ --> | 
|  | 2090 | <div class="doc_subsubsection"> | 
|  | 2091 | <a name="i_select">'<tt>select</tt>' Instruction</a> | 
|  | 2092 | </div> | 
|  | 2093 |  | 
|  | 2094 | <div class="doc_text"> | 
|  | 2095 |  | 
|  | 2096 | <h5>Syntax:</h5> | 
|  | 2097 |  | 
|  | 2098 | <pre> | 
|  | 2099 | <result> = select bool <cond>, <ty> <val1>, <ty> <val2>             <i>; yields ty</i> | 
|  | 2100 | </pre> | 
|  | 2101 |  | 
|  | 2102 | <h5>Overview:</h5> | 
|  | 2103 |  | 
|  | 2104 | <p> | 
|  | 2105 | The '<tt>select</tt>' instruction is used to choose one value based on a | 
|  | 2106 | condition, without branching. | 
|  | 2107 | </p> | 
|  | 2108 |  | 
|  | 2109 |  | 
|  | 2110 | <h5>Arguments:</h5> | 
|  | 2111 |  | 
|  | 2112 | <p> | 
|  | 2113 | The '<tt>select</tt>' instruction requires a boolean value indicating the condition, and two values of the same <a href="#t_firstclass">first class</a> type. | 
|  | 2114 | </p> | 
|  | 2115 |  | 
|  | 2116 | <h5>Semantics:</h5> | 
|  | 2117 |  | 
|  | 2118 | <p> | 
|  | 2119 | If the boolean condition evaluates to true, the instruction returns the first | 
|  | 2120 | value argument, otherwise it returns the second value argument. | 
|  | 2121 | </p> | 
|  | 2122 |  | 
|  | 2123 | <h5>Example:</h5> | 
|  | 2124 |  | 
|  | 2125 | <pre> | 
|  | 2126 | %X = select bool true, ubyte 17, ubyte 42          <i>; yields ubyte:17</i> | 
|  | 2127 | </pre> | 
|  | 2128 | </div> | 
|  | 2129 |  | 
|  | 2130 |  | 
|  | 2131 |  | 
|  | 2132 |  | 
|  | 2133 |  | 
| Chris Lattner | 70de663 | 2001-07-09 00:26:23 +0000 | [diff] [blame] | 2134 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | e23c139 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 2135 | <div class="doc_subsubsection"> | 
|  | 2136 | <a name="i_call">'<tt>call</tt>' Instruction</a> | 
|  | 2137 | </div> | 
|  | 2138 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2139 | <div class="doc_text"> | 
| Chris Lattner | e23c139 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 2140 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2141 | <h5>Syntax:</h5> | 
| Chris Lattner | e23c139 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 2142 | <pre> | 
| Chris Lattner | 0132aff | 2005-05-06 22:57:40 +0000 | [diff] [blame^] | 2143 | <result> = [tail] call [<a href="#callingconv">cconv</a>] <ty>* <fnptrval>(<param list>) | 
| Chris Lattner | e23c139 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 2144 | </pre> | 
|  | 2145 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2146 | <h5>Overview:</h5> | 
| Chris Lattner | e23c139 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 2147 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2148 | <p>The '<tt>call</tt>' instruction represents a simple function call.</p> | 
| Chris Lattner | e23c139 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 2149 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2150 | <h5>Arguments:</h5> | 
| Chris Lattner | e23c139 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 2151 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2152 | <p>This instruction requires several arguments:</p> | 
| Chris Lattner | e23c139 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 2153 |  | 
| Chris Lattner | a8292f3 | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 2154 | <ol> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2155 | <li> | 
| Chris Lattner | 0132aff | 2005-05-06 22:57:40 +0000 | [diff] [blame^] | 2156 | <p>The optional "tail" marker indicates whether the callee function accesses | 
|  | 2157 | any allocas or varargs in the caller.  If the "tail" marker is present, the | 
| Chris Lattner | e23c139 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 2158 | function call is eligible for tail call optimization.  Note that calls may | 
|  | 2159 | be marked "tail" even if they do not occur before a <a | 
|  | 2160 | href="#i_ret"><tt>ret</tt></a> instruction. | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2161 | </li> | 
|  | 2162 | <li> | 
| Chris Lattner | 0132aff | 2005-05-06 22:57:40 +0000 | [diff] [blame^] | 2163 | <p>The optional "cconv" marker indicates which <a href="callingconv">calling | 
|  | 2164 | convention</a> the call should use.  If none is specified, the call defaults | 
|  | 2165 | to using C calling conventions. | 
|  | 2166 | </li> | 
|  | 2167 | <li> | 
| Chris Lattner | e23c139 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 2168 | <p>'<tt>ty</tt>': shall be the signature of the pointer to function value | 
|  | 2169 | being invoked.  The argument types must match the types implied by this | 
|  | 2170 | signature.</p> | 
|  | 2171 | </li> | 
|  | 2172 | <li> | 
|  | 2173 | <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a function to | 
|  | 2174 | be invoked. In most cases, this is a direct function invocation, but | 
|  | 2175 | indirect <tt>call</tt>s are just as possible, calling an arbitrary pointer | 
|  | 2176 | to function values.</p> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2177 | </li> | 
|  | 2178 | <li> | 
|  | 2179 | <p>'<tt>function args</tt>': argument list whose types match the | 
| Reid Spencer | d845d16 | 2005-05-01 22:22:57 +0000 | [diff] [blame] | 2180 | function signature argument types. All arguments must be of | 
|  | 2181 | <a href="#t_firstclass">first class</a> type. If the function signature | 
|  | 2182 | indicates the function accepts a variable number of arguments, the extra | 
|  | 2183 | arguments can be specified.</p> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2184 | </li> | 
| Chris Lattner | a8292f3 | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 2185 | </ol> | 
| Chris Lattner | e23c139 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 2186 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2187 | <h5>Semantics:</h5> | 
| Chris Lattner | e23c139 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 2188 |  | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2189 | <p>The '<tt>call</tt>' instruction is used to cause control flow to | 
|  | 2190 | transfer to a specified function, with its incoming arguments bound to | 
|  | 2191 | the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>' | 
|  | 2192 | instruction in the called function, control flow continues with the | 
|  | 2193 | instruction after the function call, and the return value of the | 
|  | 2194 | function is bound to the result argument.  This is a simpler case of | 
|  | 2195 | the <a href="#i_invoke">invoke</a> instruction.</p> | 
| Chris Lattner | e23c139 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 2196 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2197 | <h5>Example:</h5> | 
| Chris Lattner | e23c139 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 2198 |  | 
|  | 2199 | <pre> | 
|  | 2200 | %retval = call int %test(int %argc) | 
|  | 2201 | call int(sbyte*, ...) *%printf(sbyte* %msg, int 12, sbyte 42); | 
|  | 2202 | %X = tail call int %foo() | 
| Chris Lattner | 0132aff | 2005-05-06 22:57:40 +0000 | [diff] [blame^] | 2203 | %Y = tail call <a href="#callingconv">fastcc</a> int %foo() | 
| Chris Lattner | e23c139 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 2204 | </pre> | 
|  | 2205 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2206 | </div> | 
| Chris Lattner | 6a4a049 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2207 |  | 
| Chris Lattner | bd64b4e | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2208 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 6a4a049 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2209 | <div class="doc_subsubsection"> | 
|  | 2210 | <a name="i_vanext">'<tt>vanext</tt>' Instruction</a> | 
|  | 2211 | </div> | 
|  | 2212 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2213 | <div class="doc_text"> | 
| Chris Lattner | 6a4a049 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2214 |  | 
| Chris Lattner | bd64b4e | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2215 | <h5>Syntax:</h5> | 
| Chris Lattner | 6a4a049 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2216 |  | 
|  | 2217 | <pre> | 
|  | 2218 | <resultarglist> = vanext <va_list> <arglist>, <argty> | 
|  | 2219 | </pre> | 
|  | 2220 |  | 
| Chris Lattner | bd64b4e | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2221 | <h5>Overview:</h5> | 
| Chris Lattner | 6a4a049 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2222 |  | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2223 | <p>The '<tt>vanext</tt>' instruction is used to access arguments passed | 
|  | 2224 | through the "variable argument" area of a function call.  It is used to | 
|  | 2225 | implement the <tt>va_arg</tt> macro in C.</p> | 
| Chris Lattner | 6a4a049 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2226 |  | 
| Chris Lattner | bd64b4e | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2227 | <h5>Arguments:</h5> | 
| Chris Lattner | 6a4a049 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2228 |  | 
|  | 2229 | <p>This instruction takes a <tt>va_list</tt> value and the type of the | 
|  | 2230 | argument. It returns another <tt>va_list</tt>. The actual type of | 
|  | 2231 | <tt>va_list</tt> may be defined differently for different targets.  Most targets | 
|  | 2232 | use a <tt>va_list</tt> type of <tt>sbyte*</tt> or some other pointer type.</p> | 
|  | 2233 |  | 
| Chris Lattner | bd64b4e | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2234 | <h5>Semantics:</h5> | 
| Chris Lattner | 6a4a049 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2235 |  | 
|  | 2236 | <p>The '<tt>vanext</tt>' instruction advances the specified <tt>va_list</tt> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2237 | past an argument of the specified type.  In conjunction with the <a | 
|  | 2238 | href="#i_vaarg"><tt>vaarg</tt></a> instruction, it is used to implement | 
|  | 2239 | the <tt>va_arg</tt> macro available in C.  For more information, see | 
|  | 2240 | the variable argument handling <a href="#int_varargs">Intrinsic | 
|  | 2241 | Functions</a>.</p> | 
| Chris Lattner | 6a4a049 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2242 |  | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2243 | <p>It is legal for this instruction to be called in a function which | 
|  | 2244 | does not take a variable number of arguments, for example, the <tt>vfprintf</tt> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2245 | function.</p> | 
| Chris Lattner | 6a4a049 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2246 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2247 | <p><tt>vanext</tt> is an LLVM instruction instead of an <a | 
| Chris Lattner | 6a4a049 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2248 | href="#intrinsics">intrinsic function</a> because it takes a type as an | 
|  | 2249 | argument.  The type refers to the current argument in the <tt>va_list</tt>, it | 
|  | 2250 | tells the compiler how far on the stack it needs to advance to find the next | 
|  | 2251 | argument</p> | 
|  | 2252 |  | 
| Chris Lattner | bd64b4e | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2253 | <h5>Example:</h5> | 
| Chris Lattner | 6a4a049 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2254 |  | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2255 | <p>See the <a href="#int_varargs">variable argument processing</a> | 
|  | 2256 | section.</p> | 
| Chris Lattner | 6a4a049 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2257 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2258 | </div> | 
| Chris Lattner | 6a4a049 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2259 |  | 
| Chris Lattner | 26ca62e | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 2260 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 6a4a049 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2261 | <div class="doc_subsubsection"> | 
|  | 2262 | <a name="i_vaarg">'<tt>vaarg</tt>' Instruction</a> | 
|  | 2263 | </div> | 
|  | 2264 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2265 | <div class="doc_text"> | 
| Chris Lattner | 6a4a049 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2266 |  | 
| Chris Lattner | 26ca62e | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 2267 | <h5>Syntax:</h5> | 
| Chris Lattner | 6a4a049 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2268 |  | 
|  | 2269 | <pre> | 
|  | 2270 | <resultval> = vaarg <va_list> <arglist>, <argty> | 
|  | 2271 | </pre> | 
|  | 2272 |  | 
| Chris Lattner | 26ca62e | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 2273 | <h5>Overview:</h5> | 
| Chris Lattner | 6a4a049 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2274 |  | 
|  | 2275 | <p>The '<tt>vaarg</tt>' instruction is used to access arguments passed through | 
|  | 2276 | the "variable argument" area of a function call.  It is used to implement the | 
|  | 2277 | <tt>va_arg</tt> macro in C.</p> | 
|  | 2278 |  | 
| Chris Lattner | 26ca62e | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 2279 | <h5>Arguments:</h5> | 
| Chris Lattner | 6a4a049 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2280 |  | 
|  | 2281 | <p>This instruction takes a <tt>va_list</tt> value and the type of the | 
|  | 2282 | argument. It returns a value of the specified argument type.  Again, the actual | 
|  | 2283 | type of <tt>va_list</tt> is target specific.</p> | 
|  | 2284 |  | 
| Chris Lattner | 26ca62e | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 2285 | <h5>Semantics:</h5> | 
| Chris Lattner | 6a4a049 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2286 |  | 
|  | 2287 | <p>The '<tt>vaarg</tt>' instruction loads an argument of the specified type from | 
|  | 2288 | the specified <tt>va_list</tt>.  In conjunction with the <a | 
|  | 2289 | href="#i_vanext"><tt>vanext</tt></a> instruction, it is used to implement the | 
|  | 2290 | <tt>va_arg</tt> macro available in C.  For more information, see the variable | 
|  | 2291 | argument handling <a href="#int_varargs">Intrinsic Functions</a>.</p> | 
|  | 2292 |  | 
|  | 2293 | <p>It is legal for this instruction to be called in a function which does not | 
|  | 2294 | take a variable number of arguments, for example, the <tt>vfprintf</tt> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2295 | function.</p> | 
| Chris Lattner | 6a4a049 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2296 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2297 | <p><tt>vaarg</tt> is an LLVM instruction instead of an <a | 
| Chris Lattner | 6a4a049 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2298 | href="#intrinsics">intrinsic function</a> because it takes an type as an | 
|  | 2299 | argument.</p> | 
|  | 2300 |  | 
| Chris Lattner | 26ca62e | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 2301 | <h5>Example:</h5> | 
| Chris Lattner | 6a4a049 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2302 |  | 
|  | 2303 | <p>See the <a href="#int_varargs">variable argument processing</a> section.</p> | 
|  | 2304 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2305 | </div> | 
| Chris Lattner | 941515c | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 2306 |  | 
| Chris Lattner | bd64b4e | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2307 | <!-- *********************************************************************** --> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2308 | <div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div> | 
|  | 2309 | <!-- *********************************************************************** --> | 
| Chris Lattner | 941515c | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 2310 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2311 | <div class="doc_text"> | 
| Chris Lattner | fee1146 | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 2312 |  | 
|  | 2313 | <p>LLVM supports the notion of an "intrinsic function".  These functions have | 
|  | 2314 | well known names and semantics, and are required to follow certain | 
|  | 2315 | restrictions. Overall, these instructions represent an extension mechanism for | 
|  | 2316 | the LLVM language that does not require changing all of the transformations in | 
|  | 2317 | LLVM to add to the language (or the bytecode reader/writer, the parser, | 
|  | 2318 | etc...).</p> | 
|  | 2319 |  | 
|  | 2320 | <p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix, this | 
|  | 2321 | prefix is reserved in LLVM for intrinsic names, thus functions may not be named | 
|  | 2322 | this.  Intrinsic functions must always be external functions: you cannot define | 
|  | 2323 | the body of intrinsic functions.  Intrinsic functions may only be used in call | 
|  | 2324 | or invoke instructions: it is illegal to take the address of an intrinsic | 
|  | 2325 | function.  Additionally, because intrinsic functions are part of the LLVM | 
|  | 2326 | language, it is required that they all be documented here if any are added.</p> | 
|  | 2327 |  | 
|  | 2328 |  | 
|  | 2329 | <p> | 
|  | 2330 | Adding an intrinsic to LLVM is straight-forward if it is possible to express the | 
|  | 2331 | concept in LLVM directly (ie, code generator support is not _required_).  To do | 
|  | 2332 | this, extend the default implementation of the IntrinsicLowering class to handle | 
|  | 2333 | the intrinsic.  Code generators use this class to lower intrinsics they do not | 
|  | 2334 | understand to raw LLVM instructions that they do. | 
|  | 2335 | </p> | 
|  | 2336 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2337 | </div> | 
| Chris Lattner | 941515c | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 2338 |  | 
| Chris Lattner | bd64b4e | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2339 | <!-- ======================================================================= --> | 
| Chris Lattner | 941515c | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 2340 | <div class="doc_subsection"> | 
|  | 2341 | <a name="int_varargs">Variable Argument Handling Intrinsics</a> | 
|  | 2342 | </div> | 
|  | 2343 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2344 | <div class="doc_text"> | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 2345 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2346 | <p>Variable argument support is defined in LLVM with the <a | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2347 | href="#i_vanext"><tt>vanext</tt></a> instruction and these three | 
|  | 2348 | intrinsic functions.  These functions are related to the similarly | 
|  | 2349 | named macros defined in the <tt><stdarg.h></tt> header file.</p> | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 2350 |  | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2351 | <p>All of these functions operate on arguments that use a | 
|  | 2352 | target-specific value type "<tt>va_list</tt>".  The LLVM assembly | 
|  | 2353 | language reference manual does not define what this type is, so all | 
|  | 2354 | transformations should be prepared to handle intrinsics with any type | 
|  | 2355 | used.</p> | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 2356 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2357 | <p>This example shows how the <a href="#i_vanext"><tt>vanext</tt></a> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2358 | instruction and the variable argument handling intrinsic functions are | 
|  | 2359 | used.</p> | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 2360 |  | 
| Chris Lattner | fee1146 | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 2361 | <pre> | 
|  | 2362 | int %test(int %X, ...) { | 
|  | 2363 | ; Initialize variable argument processing | 
|  | 2364 | %ap = call sbyte* %<a href="#i_va_start">llvm.va_start</a>() | 
|  | 2365 |  | 
|  | 2366 | ; Read a single integer argument | 
|  | 2367 | %tmp = vaarg sbyte* %ap, int | 
|  | 2368 |  | 
|  | 2369 | ; Advance to the next argument | 
|  | 2370 | %ap2 = vanext sbyte* %ap, int | 
|  | 2371 |  | 
|  | 2372 | ; Demonstrate usage of llvm.va_copy and llvm.va_end | 
|  | 2373 | %aq = call sbyte* %<a href="#i_va_copy">llvm.va_copy</a>(sbyte* %ap2) | 
|  | 2374 | call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %aq) | 
|  | 2375 |  | 
|  | 2376 | ; Stop processing of arguments. | 
|  | 2377 | call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %ap2) | 
|  | 2378 | ret int %tmp | 
|  | 2379 | } | 
|  | 2380 | </pre> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2381 | </div> | 
| Chris Lattner | 941515c | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 2382 |  | 
| Chris Lattner | bd64b4e | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2383 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 941515c | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 2384 | <div class="doc_subsubsection"> | 
|  | 2385 | <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a> | 
|  | 2386 | </div> | 
|  | 2387 |  | 
|  | 2388 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2389 | <div class="doc_text"> | 
| Chris Lattner | bd64b4e | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2390 | <h5>Syntax:</h5> | 
| Reid Spencer | 7821d06 | 2005-04-26 20:50:44 +0000 | [diff] [blame] | 2391 | <pre>  declare <va_list> %llvm.va_start()<br></pre> | 
| Chris Lattner | bd64b4e | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2392 | <h5>Overview:</h5> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2393 | <p>The '<tt>llvm.va_start</tt>' intrinsic returns a new <tt><arglist></tt> | 
|  | 2394 | for subsequent use by the variable argument intrinsics.</p> | 
| Chris Lattner | bd64b4e | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2395 | <h5>Semantics:</h5> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2396 | <p>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2397 | macro available in C.  In a target-dependent way, it initializes and | 
|  | 2398 | returns a <tt>va_list</tt> element, so that the next <tt>vaarg</tt> | 
|  | 2399 | will produce the first variable argument passed to the function.  Unlike | 
|  | 2400 | the C <tt>va_start</tt> macro, this intrinsic does not need to know the | 
|  | 2401 | last argument of the function, the compiler can figure that out.</p> | 
|  | 2402 | <p>Note that this intrinsic function is only legal to be called from | 
|  | 2403 | within the body of a variable argument function.</p> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2404 | </div> | 
| Chris Lattner | 941515c | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 2405 |  | 
| Chris Lattner | bd64b4e | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2406 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 941515c | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 2407 | <div class="doc_subsubsection"> | 
|  | 2408 | <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a> | 
|  | 2409 | </div> | 
|  | 2410 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2411 | <div class="doc_text"> | 
| Chris Lattner | bd64b4e | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2412 | <h5>Syntax:</h5> | 
| Reid Spencer | 7821d06 | 2005-04-26 20:50:44 +0000 | [diff] [blame] | 2413 | <pre>  declare void %llvm.va_end(<va_list> <arglist>)<br></pre> | 
| Chris Lattner | bd64b4e | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2414 | <h5>Overview:</h5> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2415 | <p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt><arglist></tt> | 
|  | 2416 | which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt> | 
|  | 2417 | or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p> | 
| Chris Lattner | bd64b4e | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2418 | <h5>Arguments:</h5> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2419 | <p>The argument is a <tt>va_list</tt> to destroy.</p> | 
| Chris Lattner | bd64b4e | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2420 | <h5>Semantics:</h5> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2421 | <p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt> | 
| Chris Lattner | 48b383b0 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2422 | macro available in C.  In a target-dependent way, it destroys the <tt>va_list</tt>. | 
|  | 2423 | Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a | 
|  | 2424 | href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly | 
|  | 2425 | with calls to <tt>llvm.va_end</tt>.</p> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2426 | </div> | 
| Chris Lattner | 941515c | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 2427 |  | 
| Chris Lattner | bd64b4e | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2428 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 941515c | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 2429 | <div class="doc_subsubsection"> | 
|  | 2430 | <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a> | 
|  | 2431 | </div> | 
|  | 2432 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2433 | <div class="doc_text"> | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 2434 |  | 
| Chris Lattner | bd64b4e | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2435 | <h5>Syntax:</h5> | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 2436 |  | 
|  | 2437 | <pre> | 
| Reid Spencer | 7821d06 | 2005-04-26 20:50:44 +0000 | [diff] [blame] | 2438 | declare <va_list> %llvm.va_copy(<va_list> <destarglist>) | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 2439 | </pre> | 
|  | 2440 |  | 
| Chris Lattner | bd64b4e | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2441 | <h5>Overview:</h5> | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 2442 |  | 
|  | 2443 | <p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position | 
|  | 2444 | from the source argument list to the destination argument list.</p> | 
|  | 2445 |  | 
| Chris Lattner | bd64b4e | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2446 | <h5>Arguments:</h5> | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 2447 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2448 | <p>The argument is the <tt>va_list</tt> to copy.</p> | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 2449 |  | 
| Chris Lattner | bd64b4e | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2450 | <h5>Semantics:</h5> | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 2451 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2452 | <p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt> | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 2453 | macro available in C.  In a target-dependent way, it copies the source | 
|  | 2454 | <tt>va_list</tt> element into the returned list.  This intrinsic is necessary | 
| Chris Lattner | 53e5e2a | 2004-06-21 22:52:48 +0000 | [diff] [blame] | 2455 | because the <tt><a href="#i_va_start">llvm.va_start</a></tt> intrinsic may be | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 2456 | arbitrarily complex and require memory allocation, for example.</p> | 
|  | 2457 |  | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2458 | </div> | 
| Chris Lattner | 941515c | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 2459 |  | 
| Chris Lattner | fee1146 | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 2460 | <!-- ======================================================================= --> | 
|  | 2461 | <div class="doc_subsection"> | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 2462 | <a name="int_gc">Accurate Garbage Collection Intrinsics</a> | 
|  | 2463 | </div> | 
|  | 2464 |  | 
|  | 2465 | <div class="doc_text"> | 
|  | 2466 |  | 
|  | 2467 | <p> | 
|  | 2468 | LLVM support for <a href="GarbageCollection.html">Accurate Garbage | 
|  | 2469 | Collection</a> requires the implementation and generation of these intrinsics. | 
|  | 2470 | These intrinsics allow identification of <a href="#i_gcroot">GC roots on the | 
|  | 2471 | stack</a>, as well as garbage collector implementations that require <a | 
|  | 2472 | href="#i_gcread">read</a> and <a href="#i_gcwrite">write</a> barriers. | 
|  | 2473 | Front-ends for type-safe garbage collected languages should generate these | 
|  | 2474 | intrinsics to make use of the LLVM garbage collectors.  For more details, see <a | 
|  | 2475 | href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>. | 
|  | 2476 | </p> | 
|  | 2477 | </div> | 
|  | 2478 |  | 
|  | 2479 | <!-- _______________________________________________________________________ --> | 
|  | 2480 | <div class="doc_subsubsection"> | 
|  | 2481 | <a name="i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a> | 
|  | 2482 | </div> | 
|  | 2483 |  | 
|  | 2484 | <div class="doc_text"> | 
|  | 2485 |  | 
|  | 2486 | <h5>Syntax:</h5> | 
|  | 2487 |  | 
|  | 2488 | <pre> | 
| Reid Spencer | 7821d06 | 2005-04-26 20:50:44 +0000 | [diff] [blame] | 2489 | declare void %llvm.gcroot(<ty>** %ptrloc, <ty2>* %metadata) | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 2490 | </pre> | 
|  | 2491 |  | 
|  | 2492 | <h5>Overview:</h5> | 
|  | 2493 |  | 
| John Criswell | dfe6a86 | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 2494 | <p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existence of a GC root to | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 2495 | the code generator, and allows some metadata to be associated with it.</p> | 
|  | 2496 |  | 
|  | 2497 | <h5>Arguments:</h5> | 
|  | 2498 |  | 
|  | 2499 | <p>The first argument specifies the address of a stack object that contains the | 
|  | 2500 | root pointer.  The second pointer (which must be either a constant or a global | 
|  | 2501 | value address) contains the meta-data to be associated with the root.</p> | 
|  | 2502 |  | 
|  | 2503 | <h5>Semantics:</h5> | 
|  | 2504 |  | 
|  | 2505 | <p>At runtime, a call to this intrinsics stores a null pointer into the "ptrloc" | 
|  | 2506 | location.  At compile-time, the code generator generates information to allow | 
|  | 2507 | the runtime to find the pointer at GC safe points. | 
|  | 2508 | </p> | 
|  | 2509 |  | 
|  | 2510 | </div> | 
|  | 2511 |  | 
|  | 2512 |  | 
|  | 2513 | <!-- _______________________________________________________________________ --> | 
|  | 2514 | <div class="doc_subsubsection"> | 
|  | 2515 | <a name="i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a> | 
|  | 2516 | </div> | 
|  | 2517 |  | 
|  | 2518 | <div class="doc_text"> | 
|  | 2519 |  | 
|  | 2520 | <h5>Syntax:</h5> | 
|  | 2521 |  | 
|  | 2522 | <pre> | 
| Reid Spencer | 7821d06 | 2005-04-26 20:50:44 +0000 | [diff] [blame] | 2523 | declare sbyte* %llvm.gcread(sbyte** %Ptr) | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 2524 | </pre> | 
|  | 2525 |  | 
|  | 2526 | <h5>Overview:</h5> | 
|  | 2527 |  | 
|  | 2528 | <p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap | 
|  | 2529 | locations, allowing garbage collector implementations that require read | 
|  | 2530 | barriers.</p> | 
|  | 2531 |  | 
|  | 2532 | <h5>Arguments:</h5> | 
|  | 2533 |  | 
|  | 2534 | <p>The argument is the address to read from, which should be an address | 
|  | 2535 | allocated from the garbage collector.</p> | 
|  | 2536 |  | 
|  | 2537 | <h5>Semantics:</h5> | 
|  | 2538 |  | 
|  | 2539 | <p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load | 
|  | 2540 | instruction, but may be replaced with substantially more complex code by the | 
|  | 2541 | garbage collector runtime, as needed.</p> | 
|  | 2542 |  | 
|  | 2543 | </div> | 
|  | 2544 |  | 
|  | 2545 |  | 
|  | 2546 | <!-- _______________________________________________________________________ --> | 
|  | 2547 | <div class="doc_subsubsection"> | 
|  | 2548 | <a name="i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a> | 
|  | 2549 | </div> | 
|  | 2550 |  | 
|  | 2551 | <div class="doc_text"> | 
|  | 2552 |  | 
|  | 2553 | <h5>Syntax:</h5> | 
|  | 2554 |  | 
|  | 2555 | <pre> | 
| Reid Spencer | 7821d06 | 2005-04-26 20:50:44 +0000 | [diff] [blame] | 2556 | declare void %llvm.gcwrite(sbyte* %P1, sbyte** %P2) | 
| Chris Lattner | 757528b0b | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 2557 | </pre> | 
|  | 2558 |  | 
|  | 2559 | <h5>Overview:</h5> | 
|  | 2560 |  | 
|  | 2561 | <p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap | 
|  | 2562 | locations, allowing garbage collector implementations that require write | 
|  | 2563 | barriers (such as generational or reference counting collectors).</p> | 
|  | 2564 |  | 
|  | 2565 | <h5>Arguments:</h5> | 
|  | 2566 |  | 
|  | 2567 | <p>The first argument is the reference to store, and the second is the heap | 
|  | 2568 | location to store to.</p> | 
|  | 2569 |  | 
|  | 2570 | <h5>Semantics:</h5> | 
|  | 2571 |  | 
|  | 2572 | <p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store | 
|  | 2573 | instruction, but may be replaced with substantially more complex code by the | 
|  | 2574 | garbage collector runtime, as needed.</p> | 
|  | 2575 |  | 
|  | 2576 | </div> | 
|  | 2577 |  | 
|  | 2578 |  | 
|  | 2579 |  | 
|  | 2580 | <!-- ======================================================================= --> | 
|  | 2581 | <div class="doc_subsection"> | 
| Chris Lattner | 3649c3a | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 2582 | <a name="int_codegen">Code Generator Intrinsics</a> | 
|  | 2583 | </div> | 
|  | 2584 |  | 
|  | 2585 | <div class="doc_text"> | 
|  | 2586 | <p> | 
|  | 2587 | These intrinsics are provided by LLVM to expose special features that may only | 
|  | 2588 | be implemented with code generator support. | 
|  | 2589 | </p> | 
|  | 2590 |  | 
|  | 2591 | </div> | 
|  | 2592 |  | 
|  | 2593 | <!-- _______________________________________________________________________ --> | 
|  | 2594 | <div class="doc_subsubsection"> | 
|  | 2595 | <a name="i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a> | 
|  | 2596 | </div> | 
|  | 2597 |  | 
|  | 2598 | <div class="doc_text"> | 
|  | 2599 |  | 
|  | 2600 | <h5>Syntax:</h5> | 
|  | 2601 | <pre> | 
| Reid Spencer | 7821d06 | 2005-04-26 20:50:44 +0000 | [diff] [blame] | 2602 | declare void* %llvm.returnaddress(uint <level>) | 
| Chris Lattner | 3649c3a | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 2603 | </pre> | 
|  | 2604 |  | 
|  | 2605 | <h5>Overview:</h5> | 
|  | 2606 |  | 
|  | 2607 | <p> | 
|  | 2608 | The '<tt>llvm.returnaddress</tt>' intrinsic returns a target-specific value | 
|  | 2609 | indicating the return address of the current function or one of its callers. | 
|  | 2610 | </p> | 
|  | 2611 |  | 
|  | 2612 | <h5>Arguments:</h5> | 
|  | 2613 |  | 
|  | 2614 | <p> | 
|  | 2615 | The argument to this intrinsic indicates which function to return the address | 
|  | 2616 | for.  Zero indicates the calling function, one indicates its caller, etc.  The | 
|  | 2617 | argument is <b>required</b> to be a constant integer value. | 
|  | 2618 | </p> | 
|  | 2619 |  | 
|  | 2620 | <h5>Semantics:</h5> | 
|  | 2621 |  | 
|  | 2622 | <p> | 
|  | 2623 | The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating | 
|  | 2624 | the return address of the specified call frame, or zero if it cannot be | 
|  | 2625 | identified.  The value returned by this intrinsic is likely to be incorrect or 0 | 
|  | 2626 | for arguments other than zero, so it should only be used for debugging purposes. | 
|  | 2627 | </p> | 
|  | 2628 |  | 
|  | 2629 | <p> | 
|  | 2630 | Note that calling this intrinsic does not prevent function inlining or other | 
| Chris Lattner | 2e6eb5f | 2005-03-07 20:30:51 +0000 | [diff] [blame] | 2631 | aggressive transformations, so the value returned may not be that of the obvious | 
| Chris Lattner | 3649c3a | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 2632 | source-language caller. | 
|  | 2633 | </p> | 
|  | 2634 | </div> | 
|  | 2635 |  | 
|  | 2636 |  | 
|  | 2637 | <!-- _______________________________________________________________________ --> | 
|  | 2638 | <div class="doc_subsubsection"> | 
|  | 2639 | <a name="i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a> | 
|  | 2640 | </div> | 
|  | 2641 |  | 
|  | 2642 | <div class="doc_text"> | 
|  | 2643 |  | 
|  | 2644 | <h5>Syntax:</h5> | 
|  | 2645 | <pre> | 
| Reid Spencer | 7821d06 | 2005-04-26 20:50:44 +0000 | [diff] [blame] | 2646 | declare void* %llvm.frameaddress(uint <level>) | 
| Chris Lattner | 3649c3a | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 2647 | </pre> | 
|  | 2648 |  | 
|  | 2649 | <h5>Overview:</h5> | 
|  | 2650 |  | 
|  | 2651 | <p> | 
|  | 2652 | The '<tt>llvm.frameaddress</tt>' intrinsic returns the target-specific frame | 
|  | 2653 | pointer value for the specified stack frame. | 
|  | 2654 | </p> | 
|  | 2655 |  | 
|  | 2656 | <h5>Arguments:</h5> | 
|  | 2657 |  | 
|  | 2658 | <p> | 
|  | 2659 | The argument to this intrinsic indicates which function to return the frame | 
|  | 2660 | pointer for.  Zero indicates the calling function, one indicates its caller, | 
|  | 2661 | etc.  The argument is <b>required</b> to be a constant integer value. | 
|  | 2662 | </p> | 
|  | 2663 |  | 
|  | 2664 | <h5>Semantics:</h5> | 
|  | 2665 |  | 
|  | 2666 | <p> | 
|  | 2667 | The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating | 
|  | 2668 | the frame address of the specified call frame, or zero if it cannot be | 
|  | 2669 | identified.  The value returned by this intrinsic is likely to be incorrect or 0 | 
|  | 2670 | for arguments other than zero, so it should only be used for debugging purposes. | 
|  | 2671 | </p> | 
|  | 2672 |  | 
|  | 2673 | <p> | 
|  | 2674 | Note that calling this intrinsic does not prevent function inlining or other | 
| Chris Lattner | 2e6eb5f | 2005-03-07 20:30:51 +0000 | [diff] [blame] | 2675 | aggressive transformations, so the value returned may not be that of the obvious | 
| Chris Lattner | 3649c3a | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 2676 | source-language caller. | 
|  | 2677 | </p> | 
|  | 2678 | </div> | 
|  | 2679 |  | 
| Chris Lattner | c8a2c22 | 2005-02-28 19:24:19 +0000 | [diff] [blame] | 2680 | <!-- _______________________________________________________________________ --> | 
|  | 2681 | <div class="doc_subsubsection"> | 
|  | 2682 | <a name="i_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a> | 
|  | 2683 | </div> | 
|  | 2684 |  | 
|  | 2685 | <div class="doc_text"> | 
|  | 2686 |  | 
|  | 2687 | <h5>Syntax:</h5> | 
|  | 2688 | <pre> | 
| Reid Spencer | 7821d06 | 2005-04-26 20:50:44 +0000 | [diff] [blame] | 2689 | declare void %llvm.prefetch(sbyte * <address>, | 
|  | 2690 | uint <rw>, uint <locality>) | 
| Chris Lattner | c8a2c22 | 2005-02-28 19:24:19 +0000 | [diff] [blame] | 2691 | </pre> | 
|  | 2692 |  | 
|  | 2693 | <h5>Overview:</h5> | 
|  | 2694 |  | 
|  | 2695 |  | 
|  | 2696 | <p> | 
|  | 2697 | The '<tt>llvm.prefetch</tt>' intrinsic is a hint to the code generator to insert | 
|  | 2698 | a prefetch instruction if supported, otherwise it is a noop.  Prefetches have no | 
| Chris Lattner | ff85107 | 2005-02-28 19:47:14 +0000 | [diff] [blame] | 2699 | effect on the behavior of the program, but can change its performance | 
|  | 2700 | characteristics. | 
| Chris Lattner | c8a2c22 | 2005-02-28 19:24:19 +0000 | [diff] [blame] | 2701 | </p> | 
|  | 2702 |  | 
|  | 2703 | <h5>Arguments:</h5> | 
|  | 2704 |  | 
|  | 2705 | <p> | 
|  | 2706 | <tt>address</tt> is the address to be prefetched, <tt>rw</tt> is the specifier | 
|  | 2707 | determining if the fetch should be for a read (0) or write (1), and | 
|  | 2708 | <tt>locality</tt> is a temporal locality specifier ranging from (0) - no | 
| Chris Lattner | d3e641c | 2005-03-07 20:31:38 +0000 | [diff] [blame] | 2709 | locality, to (3) - extremely local keep in cache.  The <tt>rw</tt> and | 
| Chris Lattner | c8a2c22 | 2005-02-28 19:24:19 +0000 | [diff] [blame] | 2710 | <tt>locality</tt> arguments must be constant integers. | 
|  | 2711 | </p> | 
|  | 2712 |  | 
|  | 2713 | <h5>Semantics:</h5> | 
|  | 2714 |  | 
|  | 2715 | <p> | 
|  | 2716 | This intrinsic does not modify the behavior of the program.  In particular, | 
|  | 2717 | prefetches cannot trap and do not produce a value.  On targets that support this | 
|  | 2718 | intrinsic, the prefetch can provide hints to the processor cache for better | 
|  | 2719 | performance. | 
|  | 2720 | </p> | 
|  | 2721 |  | 
|  | 2722 | </div> | 
|  | 2723 |  | 
| Andrew Lenharth | b442791 | 2005-03-28 20:05:49 +0000 | [diff] [blame] | 2724 | <!-- _______________________________________________________________________ --> | 
|  | 2725 | <div class="doc_subsubsection"> | 
|  | 2726 | <a name="i_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a> | 
|  | 2727 | </div> | 
|  | 2728 |  | 
|  | 2729 | <div class="doc_text"> | 
|  | 2730 |  | 
|  | 2731 | <h5>Syntax:</h5> | 
|  | 2732 | <pre> | 
| Reid Spencer | 7821d06 | 2005-04-26 20:50:44 +0000 | [diff] [blame] | 2733 | declare void %llvm.pcmarker( uint <id> ) | 
| Andrew Lenharth | b442791 | 2005-03-28 20:05:49 +0000 | [diff] [blame] | 2734 | </pre> | 
|  | 2735 |  | 
|  | 2736 | <h5>Overview:</h5> | 
|  | 2737 |  | 
|  | 2738 |  | 
|  | 2739 | <p> | 
|  | 2740 | The '<tt>llvm.pcmarker</tt>' intrinsic is a method to export a PC in a region of | 
|  | 2741 | code to simulators and other tools.  The method is target specific, but it is | 
|  | 2742 | expected that the marker will use exported symbols to transmit the PC of the marker. | 
|  | 2743 | The marker makes no guaranties that it will remain with any specific instruction | 
|  | 2744 | after optimizations.  It is possible that the presense of a marker will inhibit | 
|  | 2745 | optimizations.  The intended use is to be inserted after optmizations to allow | 
|  | 2746 | corrolations of simulation runs. | 
|  | 2747 | </p> | 
|  | 2748 |  | 
|  | 2749 | <h5>Arguments:</h5> | 
|  | 2750 |  | 
|  | 2751 | <p> | 
|  | 2752 | <tt>id</tt> is a numerical id identifying the marker. | 
|  | 2753 | </p> | 
|  | 2754 |  | 
|  | 2755 | <h5>Semantics:</h5> | 
|  | 2756 |  | 
|  | 2757 | <p> | 
|  | 2758 | This intrinsic does not modify the behavior of the program.  Backends that do not | 
|  | 2759 | support this intrinisic may ignore it. | 
|  | 2760 | </p> | 
|  | 2761 |  | 
|  | 2762 | </div> | 
|  | 2763 |  | 
| Chris Lattner | c8a2c22 | 2005-02-28 19:24:19 +0000 | [diff] [blame] | 2764 |  | 
| John Criswell | aa1c3c1 | 2004-04-09 16:43:20 +0000 | [diff] [blame] | 2765 | <!-- ======================================================================= --> | 
|  | 2766 | <div class="doc_subsection"> | 
|  | 2767 | <a name="int_os">Operating System Intrinsics</a> | 
|  | 2768 | </div> | 
|  | 2769 |  | 
|  | 2770 | <div class="doc_text"> | 
|  | 2771 | <p> | 
|  | 2772 | These intrinsics are provided by LLVM to support the implementation of | 
|  | 2773 | operating system level code. | 
|  | 2774 | </p> | 
|  | 2775 |  | 
|  | 2776 | </div> | 
| John Criswell | a450122 | 2004-04-12 15:02:16 +0000 | [diff] [blame] | 2777 |  | 
| John Criswell | 508b93c | 2004-04-09 15:23:37 +0000 | [diff] [blame] | 2778 | <!-- _______________________________________________________________________ --> | 
|  | 2779 | <div class="doc_subsubsection"> | 
|  | 2780 | <a name="i_readport">'<tt>llvm.readport</tt>' Intrinsic</a> | 
|  | 2781 | </div> | 
|  | 2782 |  | 
|  | 2783 | <div class="doc_text"> | 
|  | 2784 |  | 
|  | 2785 | <h5>Syntax:</h5> | 
|  | 2786 | <pre> | 
| Reid Spencer | 7821d06 | 2005-04-26 20:50:44 +0000 | [diff] [blame] | 2787 | declare <integer type> %llvm.readport (<integer type> <address>) | 
| John Criswell | 508b93c | 2004-04-09 15:23:37 +0000 | [diff] [blame] | 2788 | </pre> | 
|  | 2789 |  | 
|  | 2790 | <h5>Overview:</h5> | 
|  | 2791 |  | 
|  | 2792 | <p> | 
| John Criswell | aa1c3c1 | 2004-04-09 16:43:20 +0000 | [diff] [blame] | 2793 | The '<tt>llvm.readport</tt>' intrinsic reads data from the specified hardware | 
|  | 2794 | I/O port. | 
| John Criswell | 508b93c | 2004-04-09 15:23:37 +0000 | [diff] [blame] | 2795 | </p> | 
|  | 2796 |  | 
|  | 2797 | <h5>Arguments:</h5> | 
|  | 2798 |  | 
|  | 2799 | <p> | 
| John Criswell | aa1c3c1 | 2004-04-09 16:43:20 +0000 | [diff] [blame] | 2800 | The argument to this intrinsic indicates the hardware I/O address from which | 
|  | 2801 | to read the data.  The address is in the hardware I/O address namespace (as | 
|  | 2802 | opposed to being a memory location for memory mapped I/O). | 
| John Criswell | 508b93c | 2004-04-09 15:23:37 +0000 | [diff] [blame] | 2803 | </p> | 
|  | 2804 |  | 
|  | 2805 | <h5>Semantics:</h5> | 
|  | 2806 |  | 
|  | 2807 | <p> | 
| John Criswell | aa1c3c1 | 2004-04-09 16:43:20 +0000 | [diff] [blame] | 2808 | The '<tt>llvm.readport</tt>' intrinsic reads data from the hardware I/O port | 
|  | 2809 | specified by <i>address</i> and returns the value.  The address and return | 
|  | 2810 | value must be integers, but the size is dependent upon the platform upon which | 
|  | 2811 | the program is code generated.  For example, on x86, the address must be an | 
| Misha Brukman | 36c6bc1 | 2005-04-22 18:02:52 +0000 | [diff] [blame] | 2812 | unsigned 16-bit value, and the return value must be 8, 16, or 32 bits. | 
| John Criswell | 508b93c | 2004-04-09 15:23:37 +0000 | [diff] [blame] | 2813 | </p> | 
|  | 2814 |  | 
|  | 2815 | </div> | 
|  | 2816 |  | 
|  | 2817 | <!-- _______________________________________________________________________ --> | 
|  | 2818 | <div class="doc_subsubsection"> | 
|  | 2819 | <a name="i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a> | 
|  | 2820 | </div> | 
|  | 2821 |  | 
|  | 2822 | <div class="doc_text"> | 
|  | 2823 |  | 
|  | 2824 | <h5>Syntax:</h5> | 
|  | 2825 | <pre> | 
| Chris Lattner | 74d3f82 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 2826 | call void (<integer type>, <integer type>)* | 
|  | 2827 | %llvm.writeport (<integer type> <value>, | 
|  | 2828 | <integer type> <address>) | 
| John Criswell | 508b93c | 2004-04-09 15:23:37 +0000 | [diff] [blame] | 2829 | </pre> | 
|  | 2830 |  | 
|  | 2831 | <h5>Overview:</h5> | 
|  | 2832 |  | 
|  | 2833 | <p> | 
| John Criswell | aa1c3c1 | 2004-04-09 16:43:20 +0000 | [diff] [blame] | 2834 | The '<tt>llvm.writeport</tt>' intrinsic writes data to the specified hardware | 
|  | 2835 | I/O port. | 
| John Criswell | 508b93c | 2004-04-09 15:23:37 +0000 | [diff] [blame] | 2836 | </p> | 
|  | 2837 |  | 
|  | 2838 | <h5>Arguments:</h5> | 
|  | 2839 |  | 
|  | 2840 | <p> | 
| John Criswell | 7a57647 | 2004-04-12 16:33:19 +0000 | [diff] [blame] | 2841 | The first argument is the value to write to the I/O port. | 
| John Criswell | 508b93c | 2004-04-09 15:23:37 +0000 | [diff] [blame] | 2842 | </p> | 
|  | 2843 |  | 
|  | 2844 | <p> | 
| John Criswell | 7a57647 | 2004-04-12 16:33:19 +0000 | [diff] [blame] | 2845 | The second argument indicates the hardware I/O address to which data should be | 
|  | 2846 | written.  The address is in the hardware I/O address namespace (as opposed to | 
|  | 2847 | being a memory location for memory mapped I/O). | 
| John Criswell | 508b93c | 2004-04-09 15:23:37 +0000 | [diff] [blame] | 2848 | </p> | 
|  | 2849 |  | 
|  | 2850 | <h5>Semantics:</h5> | 
|  | 2851 |  | 
|  | 2852 | <p> | 
|  | 2853 | The '<tt>llvm.writeport</tt>' intrinsic writes <i>value</i> to the I/O port | 
|  | 2854 | specified by <i>address</i>.  The address and value must be integers, but the | 
|  | 2855 | size is dependent upon the platform upon which the program is code generated. | 
| Misha Brukman | 36c6bc1 | 2005-04-22 18:02:52 +0000 | [diff] [blame] | 2856 | For example, on x86, the address must be an unsigned 16-bit value, and the | 
| John Criswell | aa1c3c1 | 2004-04-09 16:43:20 +0000 | [diff] [blame] | 2857 | value written must be 8, 16, or 32 bits in length. | 
| John Criswell | 508b93c | 2004-04-09 15:23:37 +0000 | [diff] [blame] | 2858 | </p> | 
|  | 2859 |  | 
|  | 2860 | </div> | 
| Chris Lattner | 3649c3a | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 2861 |  | 
| John Criswell | a450122 | 2004-04-12 15:02:16 +0000 | [diff] [blame] | 2862 | <!-- _______________________________________________________________________ --> | 
|  | 2863 | <div class="doc_subsubsection"> | 
|  | 2864 | <a name="i_readio">'<tt>llvm.readio</tt>' Intrinsic</a> | 
|  | 2865 | </div> | 
|  | 2866 |  | 
|  | 2867 | <div class="doc_text"> | 
|  | 2868 |  | 
|  | 2869 | <h5>Syntax:</h5> | 
|  | 2870 | <pre> | 
| Reid Spencer | 7821d06 | 2005-04-26 20:50:44 +0000 | [diff] [blame] | 2871 | declare <result> %llvm.readio (<ty> * <pointer>) | 
| John Criswell | a450122 | 2004-04-12 15:02:16 +0000 | [diff] [blame] | 2872 | </pre> | 
|  | 2873 |  | 
|  | 2874 | <h5>Overview:</h5> | 
|  | 2875 |  | 
|  | 2876 | <p> | 
|  | 2877 | The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O | 
|  | 2878 | address. | 
|  | 2879 | </p> | 
|  | 2880 |  | 
|  | 2881 | <h5>Arguments:</h5> | 
|  | 2882 |  | 
|  | 2883 | <p> | 
| John Criswell | 7a57647 | 2004-04-12 16:33:19 +0000 | [diff] [blame] | 2884 | The argument to this intrinsic is a pointer indicating the memory address from | 
|  | 2885 | which to read the data.  The data must be a | 
|  | 2886 | <a href="#t_firstclass">first class</a> type. | 
| John Criswell | a450122 | 2004-04-12 15:02:16 +0000 | [diff] [blame] | 2887 | </p> | 
|  | 2888 |  | 
|  | 2889 | <h5>Semantics:</h5> | 
|  | 2890 |  | 
|  | 2891 | <p> | 
|  | 2892 | The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O | 
| John Criswell | 7a57647 | 2004-04-12 16:33:19 +0000 | [diff] [blame] | 2893 | location specified by <i>pointer</i> and returns the value.  The argument must | 
|  | 2894 | be a pointer, and the return value must be a | 
|  | 2895 | <a href="#t_firstclass">first class</a> type.  However, certain architectures | 
| Misha Brukman | 36c6bc1 | 2005-04-22 18:02:52 +0000 | [diff] [blame] | 2896 | may not support I/O on all first class types.  For example, 32-bit processors | 
| John Criswell | 7a57647 | 2004-04-12 16:33:19 +0000 | [diff] [blame] | 2897 | may only support I/O on data types that are 32 bits or less. | 
| John Criswell | a450122 | 2004-04-12 15:02:16 +0000 | [diff] [blame] | 2898 | </p> | 
|  | 2899 |  | 
|  | 2900 | <p> | 
| John Criswell | 7a57647 | 2004-04-12 16:33:19 +0000 | [diff] [blame] | 2901 | This intrinsic enforces an in-order memory model for llvm.readio and | 
|  | 2902 | llvm.writeio calls on machines that use dynamic scheduling.  Dynamically | 
|  | 2903 | scheduled processors may execute loads and stores out of order, re-ordering at | 
|  | 2904 | run time accesses to memory mapped I/O registers.  Using these intrinsics | 
|  | 2905 | ensures that accesses to memory mapped I/O registers occur in program order. | 
| John Criswell | a450122 | 2004-04-12 15:02:16 +0000 | [diff] [blame] | 2906 | </p> | 
|  | 2907 |  | 
|  | 2908 | </div> | 
|  | 2909 |  | 
|  | 2910 | <!-- _______________________________________________________________________ --> | 
|  | 2911 | <div class="doc_subsubsection"> | 
|  | 2912 | <a name="i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a> | 
|  | 2913 | </div> | 
|  | 2914 |  | 
|  | 2915 | <div class="doc_text"> | 
|  | 2916 |  | 
|  | 2917 | <h5>Syntax:</h5> | 
|  | 2918 | <pre> | 
| Reid Spencer | 7821d06 | 2005-04-26 20:50:44 +0000 | [diff] [blame] | 2919 | declare void %llvm.writeio (<ty1> <value>, <ty2> * <pointer>) | 
| John Criswell | a450122 | 2004-04-12 15:02:16 +0000 | [diff] [blame] | 2920 | </pre> | 
|  | 2921 |  | 
|  | 2922 | <h5>Overview:</h5> | 
|  | 2923 |  | 
|  | 2924 | <p> | 
|  | 2925 | The '<tt>llvm.writeio</tt>' intrinsic writes data to the specified memory | 
|  | 2926 | mapped I/O address. | 
|  | 2927 | </p> | 
|  | 2928 |  | 
|  | 2929 | <h5>Arguments:</h5> | 
|  | 2930 |  | 
|  | 2931 | <p> | 
| John Criswell | 7a57647 | 2004-04-12 16:33:19 +0000 | [diff] [blame] | 2932 | The first argument is the value to write to the memory mapped I/O location. | 
|  | 2933 | The second argument is a pointer indicating the memory address to which the | 
|  | 2934 | data should be written. | 
| John Criswell | a450122 | 2004-04-12 15:02:16 +0000 | [diff] [blame] | 2935 | </p> | 
|  | 2936 |  | 
|  | 2937 | <h5>Semantics:</h5> | 
|  | 2938 |  | 
|  | 2939 | <p> | 
|  | 2940 | The '<tt>llvm.writeio</tt>' intrinsic writes <i>value</i> to the memory mapped | 
| John Criswell | 7a57647 | 2004-04-12 16:33:19 +0000 | [diff] [blame] | 2941 | I/O address specified by <i>pointer</i>.  The value must be a | 
|  | 2942 | <a href="#t_firstclass">first class</a> type.  However, certain architectures | 
| Misha Brukman | 36c6bc1 | 2005-04-22 18:02:52 +0000 | [diff] [blame] | 2943 | may not support I/O on all first class types.  For example, 32-bit processors | 
| John Criswell | 7a57647 | 2004-04-12 16:33:19 +0000 | [diff] [blame] | 2944 | may only support I/O on data types that are 32 bits or less. | 
| John Criswell | a450122 | 2004-04-12 15:02:16 +0000 | [diff] [blame] | 2945 | </p> | 
|  | 2946 |  | 
|  | 2947 | <p> | 
| John Criswell | 7a57647 | 2004-04-12 16:33:19 +0000 | [diff] [blame] | 2948 | This intrinsic enforces an in-order memory model for llvm.readio and | 
|  | 2949 | llvm.writeio calls on machines that use dynamic scheduling.  Dynamically | 
|  | 2950 | scheduled processors may execute loads and stores out of order, re-ordering at | 
|  | 2951 | run time accesses to memory mapped I/O registers.  Using these intrinsics | 
|  | 2952 | ensures that accesses to memory mapped I/O registers occur in program order. | 
| John Criswell | a450122 | 2004-04-12 15:02:16 +0000 | [diff] [blame] | 2953 | </p> | 
|  | 2954 |  | 
|  | 2955 | </div> | 
|  | 2956 |  | 
| Chris Lattner | 3649c3a | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 2957 | <!-- ======================================================================= --> | 
|  | 2958 | <div class="doc_subsection"> | 
| Chris Lattner | fee1146 | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 2959 | <a name="int_libc">Standard C Library Intrinsics</a> | 
|  | 2960 | </div> | 
|  | 2961 |  | 
|  | 2962 | <div class="doc_text"> | 
|  | 2963 | <p> | 
| Chris Lattner | 3649c3a | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 2964 | LLVM provides intrinsics for a few important standard C library functions. | 
|  | 2965 | These intrinsics allow source-language front-ends to pass information about the | 
|  | 2966 | alignment of the pointer arguments to the code generator, providing opportunity | 
|  | 2967 | for more efficient code generation. | 
| Chris Lattner | fee1146 | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 2968 | </p> | 
|  | 2969 |  | 
|  | 2970 | </div> | 
|  | 2971 |  | 
|  | 2972 | <!-- _______________________________________________________________________ --> | 
|  | 2973 | <div class="doc_subsubsection"> | 
|  | 2974 | <a name="i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a> | 
|  | 2975 | </div> | 
|  | 2976 |  | 
|  | 2977 | <div class="doc_text"> | 
|  | 2978 |  | 
|  | 2979 | <h5>Syntax:</h5> | 
|  | 2980 | <pre> | 
| Reid Spencer | cf669d8 | 2005-04-26 20:41:16 +0000 | [diff] [blame] | 2981 | declare void %llvm.memcpy(sbyte* <dest>, sbyte* <src>, | 
|  | 2982 | uint <len>, uint <align>) | 
| Chris Lattner | fee1146 | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 2983 | </pre> | 
|  | 2984 |  | 
|  | 2985 | <h5>Overview:</h5> | 
|  | 2986 |  | 
|  | 2987 | <p> | 
|  | 2988 | The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source | 
|  | 2989 | location to the destination location. | 
|  | 2990 | </p> | 
|  | 2991 |  | 
|  | 2992 | <p> | 
|  | 2993 | Note that, unlike the standard libc function, the <tt>llvm.memcpy</tt> intrinsic | 
|  | 2994 | does not return a value, and takes an extra alignment argument. | 
|  | 2995 | </p> | 
|  | 2996 |  | 
|  | 2997 | <h5>Arguments:</h5> | 
|  | 2998 |  | 
|  | 2999 | <p> | 
|  | 3000 | The first argument is a pointer to the destination, the second is a pointer to | 
|  | 3001 | the source.  The third argument is an (arbitrarily sized) integer argument | 
|  | 3002 | specifying the number of bytes to copy, and the fourth argument is the alignment | 
|  | 3003 | of the source and destination locations. | 
|  | 3004 | </p> | 
|  | 3005 |  | 
| Chris Lattner | 4c67c48 | 2004-02-12 21:18:15 +0000 | [diff] [blame] | 3006 | <p> | 
|  | 3007 | If the call to this intrinisic has an alignment value that is not 0 or 1, then | 
|  | 3008 | the caller guarantees that the size of the copy is a multiple of the alignment | 
|  | 3009 | and that both the source and destination pointers are aligned to that boundary. | 
|  | 3010 | </p> | 
|  | 3011 |  | 
| Chris Lattner | fee1146 | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 3012 | <h5>Semantics:</h5> | 
|  | 3013 |  | 
|  | 3014 | <p> | 
|  | 3015 | The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source | 
|  | 3016 | location to the destination location, which are not allowed to overlap.  It | 
|  | 3017 | copies "len" bytes of memory over.  If the argument is known to be aligned to | 
|  | 3018 | some boundary, this can be specified as the fourth argument, otherwise it should | 
|  | 3019 | be set to 0 or 1. | 
|  | 3020 | </p> | 
|  | 3021 | </div> | 
|  | 3022 |  | 
|  | 3023 |  | 
| Chris Lattner | f30152e | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 3024 | <!-- _______________________________________________________________________ --> | 
|  | 3025 | <div class="doc_subsubsection"> | 
|  | 3026 | <a name="i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a> | 
|  | 3027 | </div> | 
|  | 3028 |  | 
|  | 3029 | <div class="doc_text"> | 
|  | 3030 |  | 
|  | 3031 | <h5>Syntax:</h5> | 
|  | 3032 | <pre> | 
| Reid Spencer | cf669d8 | 2005-04-26 20:41:16 +0000 | [diff] [blame] | 3033 | declare void %llvm.memmove(sbyte* <dest>, sbyte* <src>, | 
|  | 3034 | uint <len>, uint <align>) | 
| Chris Lattner | f30152e | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 3035 | </pre> | 
|  | 3036 |  | 
|  | 3037 | <h5>Overview:</h5> | 
|  | 3038 |  | 
|  | 3039 | <p> | 
|  | 3040 | The '<tt>llvm.memmove</tt>' intrinsic moves a block of memory from the source | 
|  | 3041 | location to the destination location. It is similar to the '<tt>llvm.memcpy</tt>' | 
|  | 3042 | intrinsic but allows the two memory locations to overlap. | 
|  | 3043 | </p> | 
|  | 3044 |  | 
|  | 3045 | <p> | 
|  | 3046 | Note that, unlike the standard libc function, the <tt>llvm.memmove</tt> intrinsic | 
|  | 3047 | does not return a value, and takes an extra alignment argument. | 
|  | 3048 | </p> | 
|  | 3049 |  | 
|  | 3050 | <h5>Arguments:</h5> | 
|  | 3051 |  | 
|  | 3052 | <p> | 
|  | 3053 | The first argument is a pointer to the destination, the second is a pointer to | 
|  | 3054 | the source.  The third argument is an (arbitrarily sized) integer argument | 
|  | 3055 | specifying the number of bytes to copy, and the fourth argument is the alignment | 
|  | 3056 | of the source and destination locations. | 
|  | 3057 | </p> | 
|  | 3058 |  | 
| Chris Lattner | 4c67c48 | 2004-02-12 21:18:15 +0000 | [diff] [blame] | 3059 | <p> | 
|  | 3060 | If the call to this intrinisic has an alignment value that is not 0 or 1, then | 
|  | 3061 | the caller guarantees that the size of the copy is a multiple of the alignment | 
|  | 3062 | and that both the source and destination pointers are aligned to that boundary. | 
|  | 3063 | </p> | 
|  | 3064 |  | 
| Chris Lattner | f30152e | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 3065 | <h5>Semantics:</h5> | 
|  | 3066 |  | 
|  | 3067 | <p> | 
|  | 3068 | The '<tt>llvm.memmove</tt>' intrinsic copies a block of memory from the source | 
|  | 3069 | location to the destination location, which may overlap.  It | 
|  | 3070 | copies "len" bytes of memory over.  If the argument is known to be aligned to | 
|  | 3071 | some boundary, this can be specified as the fourth argument, otherwise it should | 
|  | 3072 | be set to 0 or 1. | 
|  | 3073 | </p> | 
|  | 3074 | </div> | 
|  | 3075 |  | 
| Chris Lattner | 941515c | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 3076 |  | 
| Chris Lattner | 3649c3a | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 3077 | <!-- _______________________________________________________________________ --> | 
|  | 3078 | <div class="doc_subsubsection"> | 
|  | 3079 | <a name="i_memset">'<tt>llvm.memset</tt>' Intrinsic</a> | 
|  | 3080 | </div> | 
|  | 3081 |  | 
|  | 3082 | <div class="doc_text"> | 
|  | 3083 |  | 
|  | 3084 | <h5>Syntax:</h5> | 
|  | 3085 | <pre> | 
| Reid Spencer | cf669d8 | 2005-04-26 20:41:16 +0000 | [diff] [blame] | 3086 | declare void %llvm.memset(sbyte* <dest>, ubyte <val>, | 
|  | 3087 | uint <len>, uint <align>) | 
| Chris Lattner | 3649c3a | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 3088 | </pre> | 
|  | 3089 |  | 
|  | 3090 | <h5>Overview:</h5> | 
|  | 3091 |  | 
|  | 3092 | <p> | 
|  | 3093 | The '<tt>llvm.memset</tt>' intrinsic fills a block of memory with a particular | 
|  | 3094 | byte value. | 
|  | 3095 | </p> | 
|  | 3096 |  | 
|  | 3097 | <p> | 
|  | 3098 | Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic | 
|  | 3099 | does not return a value, and takes an extra alignment argument. | 
|  | 3100 | </p> | 
|  | 3101 |  | 
|  | 3102 | <h5>Arguments:</h5> | 
|  | 3103 |  | 
|  | 3104 | <p> | 
|  | 3105 | The first argument is a pointer to the destination to fill, the second is the | 
|  | 3106 | byte value to fill it with, the third argument is an (arbitrarily sized) integer | 
|  | 3107 | argument specifying the number of bytes to fill, and the fourth argument is the | 
|  | 3108 | known alignment of destination location. | 
|  | 3109 | </p> | 
|  | 3110 |  | 
|  | 3111 | <p> | 
|  | 3112 | If the call to this intrinisic has an alignment value that is not 0 or 1, then | 
|  | 3113 | the caller guarantees that the size of the copy is a multiple of the alignment | 
|  | 3114 | and that the destination pointer is aligned to that boundary. | 
|  | 3115 | </p> | 
|  | 3116 |  | 
|  | 3117 | <h5>Semantics:</h5> | 
|  | 3118 |  | 
|  | 3119 | <p> | 
|  | 3120 | The '<tt>llvm.memset</tt>' intrinsic fills "len" bytes of memory starting at the | 
|  | 3121 | destination location.  If the argument is known to be aligned to some boundary, | 
|  | 3122 | this can be specified as the fourth argument, otherwise it should be set to 0 or | 
|  | 3123 | 1. | 
|  | 3124 | </p> | 
|  | 3125 | </div> | 
|  | 3126 |  | 
|  | 3127 |  | 
| Chris Lattner | 3b4f437 | 2004-06-11 02:28:03 +0000 | [diff] [blame] | 3128 | <!-- _______________________________________________________________________ --> | 
|  | 3129 | <div class="doc_subsubsection"> | 
| Alkis Evlogimenos | 0fa3923 | 2004-06-13 01:16:15 +0000 | [diff] [blame] | 3130 | <a name="i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a> | 
|  | 3131 | </div> | 
|  | 3132 |  | 
|  | 3133 | <div class="doc_text"> | 
|  | 3134 |  | 
|  | 3135 | <h5>Syntax:</h5> | 
|  | 3136 | <pre> | 
| Reid Spencer | 7821d06 | 2005-04-26 20:50:44 +0000 | [diff] [blame] | 3137 | declare bool %llvm.isunordered(<float or double> Val1, <float or double> Val2) | 
| Alkis Evlogimenos | 0fa3923 | 2004-06-13 01:16:15 +0000 | [diff] [blame] | 3138 | </pre> | 
|  | 3139 |  | 
|  | 3140 | <h5>Overview:</h5> | 
|  | 3141 |  | 
|  | 3142 | <p> | 
|  | 3143 | The '<tt>llvm.isunordered</tt>' intrinsic returns true if either or both of the | 
|  | 3144 | specified floating point values is a NAN. | 
|  | 3145 | </p> | 
|  | 3146 |  | 
|  | 3147 | <h5>Arguments:</h5> | 
|  | 3148 |  | 
|  | 3149 | <p> | 
|  | 3150 | The arguments are floating point numbers of the same type. | 
|  | 3151 | </p> | 
|  | 3152 |  | 
|  | 3153 | <h5>Semantics:</h5> | 
|  | 3154 |  | 
|  | 3155 | <p> | 
|  | 3156 | If either or both of the arguments is a SNAN or QNAN, it returns true, otherwise | 
|  | 3157 | false. | 
|  | 3158 | </p> | 
|  | 3159 | </div> | 
|  | 3160 |  | 
|  | 3161 |  | 
| Andrew Lenharth | 1d46352 | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 3162 | <!-- ======================================================================= --> | 
|  | 3163 | <div class="doc_subsection"> | 
|  | 3164 | <a name="int_count">Bit Counting Intrinsics</a> | 
|  | 3165 | </div> | 
|  | 3166 |  | 
|  | 3167 | <div class="doc_text"> | 
|  | 3168 | <p> | 
|  | 3169 | LLVM provides intrinsics for a few important bit counting operations. | 
|  | 3170 | These allow efficient code generation for some algorithms. | 
|  | 3171 | </p> | 
|  | 3172 |  | 
|  | 3173 | </div> | 
|  | 3174 |  | 
|  | 3175 | <!-- _______________________________________________________________________ --> | 
|  | 3176 | <div class="doc_subsubsection"> | 
|  | 3177 | <a name="int_ctpop">'<tt>llvm.ctpop</tt>' Intrinsic</a> | 
|  | 3178 | </div> | 
|  | 3179 |  | 
|  | 3180 | <div class="doc_text"> | 
|  | 3181 |  | 
|  | 3182 | <h5>Syntax:</h5> | 
|  | 3183 | <pre> | 
|  | 3184 | declare int %llvm.ctpop(int <src>) | 
|  | 3185 |  | 
|  | 3186 | </pre> | 
|  | 3187 |  | 
|  | 3188 | <h5>Overview:</h5> | 
|  | 3189 |  | 
|  | 3190 | <p> | 
|  | 3191 | The '<tt>llvm.ctpop</tt>' intrinsic counts the number of ones in a variable. | 
|  | 3192 | </p> | 
|  | 3193 |  | 
|  | 3194 | <h5>Arguments:</h5> | 
|  | 3195 |  | 
|  | 3196 | <p> | 
| Andrew Lenharth | 5be6f13 | 2005-05-04 14:58:31 +0000 | [diff] [blame] | 3197 | The only argument is the value to be counted.  The argument may be of any integer type. | 
| Andrew Lenharth | 1d46352 | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 3198 | </p> | 
|  | 3199 |  | 
|  | 3200 | <h5>Semantics:</h5> | 
|  | 3201 |  | 
|  | 3202 | <p> | 
|  | 3203 | The '<tt>llvm.ctpop</tt>' intrinsic counts the 1's in a variable. | 
|  | 3204 | </p> | 
|  | 3205 | </div> | 
|  | 3206 |  | 
|  | 3207 | <!-- _______________________________________________________________________ --> | 
|  | 3208 | <div class="doc_subsubsection"> | 
|  | 3209 | <a name="int_cttz">'<tt>llvm.cttz</tt>' Intrinsic</a> | 
|  | 3210 | </div> | 
|  | 3211 |  | 
|  | 3212 | <div class="doc_text"> | 
|  | 3213 |  | 
|  | 3214 | <h5>Syntax:</h5> | 
|  | 3215 | <pre> | 
|  | 3216 | declare int %llvm.cttz(int <src>) | 
|  | 3217 |  | 
|  | 3218 | </pre> | 
|  | 3219 |  | 
|  | 3220 | <h5>Overview:</h5> | 
|  | 3221 |  | 
|  | 3222 | <p> | 
|  | 3223 | The '<tt>llvm.cttz</tt>' intrinsic counts the number of trailing zeros. | 
|  | 3224 | </p> | 
|  | 3225 |  | 
|  | 3226 | <h5>Arguments:</h5> | 
|  | 3227 |  | 
|  | 3228 | <p> | 
| Andrew Lenharth | 5be6f13 | 2005-05-04 14:58:31 +0000 | [diff] [blame] | 3229 | The only argument is the value to be counted.  The argument may be of any integer type. | 
| Andrew Lenharth | 1d46352 | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 3230 | </p> | 
|  | 3231 |  | 
|  | 3232 | <h5>Semantics:</h5> | 
|  | 3233 |  | 
|  | 3234 | <p> | 
|  | 3235 | The '<tt>llvm.cttz</tt>' intrinsic counts the trailing zeros in a variable.  If the src == 0 | 
|  | 3236 | then the result is the size in bits of the type of src. | 
|  | 3237 | </p> | 
|  | 3238 | </div> | 
|  | 3239 |  | 
|  | 3240 | <!-- _______________________________________________________________________ --> | 
|  | 3241 | <div class="doc_subsubsection"> | 
|  | 3242 | <a name="int_ctlz">'<tt>llvm.ctlz</tt>' Intrinsic</a> | 
|  | 3243 | </div> | 
|  | 3244 |  | 
|  | 3245 | <div class="doc_text"> | 
|  | 3246 |  | 
|  | 3247 | <h5>Syntax:</h5> | 
|  | 3248 | <pre> | 
|  | 3249 | declare int %llvm.ctlz(int <src>) | 
|  | 3250 |  | 
|  | 3251 | </pre> | 
|  | 3252 |  | 
|  | 3253 | <h5>Overview:</h5> | 
|  | 3254 |  | 
|  | 3255 | <p> | 
|  | 3256 | The '<tt>llvm.ctlz</tt>' intrinsic counts the number of leading zeros in a variable. | 
|  | 3257 | </p> | 
|  | 3258 |  | 
|  | 3259 | <h5>Arguments:</h5> | 
|  | 3260 |  | 
|  | 3261 | <p> | 
| Andrew Lenharth | 5be6f13 | 2005-05-04 14:58:31 +0000 | [diff] [blame] | 3262 | The only argument is the value to be counted.  The argument may be of any integer type. | 
| Andrew Lenharth | 1d46352 | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 3263 | </p> | 
|  | 3264 |  | 
|  | 3265 | <h5>Semantics:</h5> | 
|  | 3266 |  | 
|  | 3267 | <p> | 
|  | 3268 | The '<tt>llvm.ctlz</tt>' intrinsic counts the leading zeros in a variable.  If the src == 0 | 
|  | 3269 | then the result is the size in bits of the type of src. | 
|  | 3270 | </p> | 
|  | 3271 | </div> | 
| Chris Lattner | 3b4f437 | 2004-06-11 02:28:03 +0000 | [diff] [blame] | 3272 |  | 
|  | 3273 |  | 
| Chris Lattner | 941515c | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 3274 | <!-- ======================================================================= --> | 
|  | 3275 | <div class="doc_subsection"> | 
|  | 3276 | <a name="int_debugger">Debugger Intrinsics</a> | 
|  | 3277 | </div> | 
|  | 3278 |  | 
|  | 3279 | <div class="doc_text"> | 
|  | 3280 | <p> | 
|  | 3281 | The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix), | 
|  | 3282 | are described in the <a | 
|  | 3283 | href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level | 
|  | 3284 | Debugging</a> document. | 
|  | 3285 | </p> | 
|  | 3286 | </div> | 
|  | 3287 |  | 
|  | 3288 |  | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3289 | <!-- *********************************************************************** --> | 
| Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3290 | <hr> | 
| Misha Brukman | c501f55 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 3291 | <address> | 
|  | 3292 | <a href="http://jigsaw.w3.org/css-validator/check/referer"><img | 
|  | 3293 | src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a> | 
|  | 3294 | <a href="http://validator.w3.org/check/referer"><img | 
|  | 3295 | src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a> | 
|  | 3296 |  | 
|  | 3297 | <a href="mailto:sabre@nondot.org">Chris Lattner</a><br> | 
|  | 3298 | <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br> | 
|  | 3299 | Last modified: $Date$ | 
|  | 3300 | </address> | 
| Misha Brukman | 7630785 | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3301 | </body> | 
|  | 3302 | </html> |