mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-21 18:29:46 +00:00
Use the example from clang, not the GCC frontend, which doesn't exist anymore.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@146461 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d56ef8d709
commit
a349539f87
@ -5119,43 +5119,44 @@ int *foo(struct ST *s) {
|
||||
}
|
||||
</pre>
|
||||
|
||||
<p>The LLVM code generated by the GCC frontend is:</p>
|
||||
<p>The LLVM code generated by Clang is:</p>
|
||||
|
||||
<pre class="doc_code">
|
||||
%RT = <a href="#namedtypes">type</a> { i8 , [10 x [20 x i32]], i8 }
|
||||
%ST = <a href="#namedtypes">type</a> { i32, double, %RT }
|
||||
%struct.RT = <a href="#namedtypes">type</a> { i8, [10 x [20 x i32]], i8 }
|
||||
%struct.ST = <a href="#namedtypes">type</a> { i32, double, %struct.RT }
|
||||
|
||||
define i32* @foo(%ST* %s) {
|
||||
define i32* @foo(%struct.ST* %s) nounwind uwtable readnone optsize ssp {
|
||||
entry:
|
||||
%reg = getelementptr %ST* %s, i32 1, i32 2, i32 1, i32 5, i32 13
|
||||
ret i32* %reg
|
||||
%arrayidx = getelementptr inbounds %struct.ST* %s, i64 1, i32 2, i32 1, i64 5, i64 13
|
||||
ret i32* %arrayidx
|
||||
}
|
||||
</pre>
|
||||
|
||||
<h5>Semantics:</h5>
|
||||
<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
|
||||
type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ i32, double, %RT
|
||||
}</tt>' type, a structure. The second index indexes into the third element
|
||||
of the structure, yielding a '<tt>%RT</tt>' = '<tt>{ i8 , [10 x [20 x i32]],
|
||||
i8 }</tt>' type, another structure. The third index indexes into the second
|
||||
element of the structure, yielding a '<tt>[10 x [20 x i32]]</tt>' type, an
|
||||
array. The two dimensions of the array are subscripted into, yielding an
|
||||
'<tt>i32</tt>' type. The '<tt>getelementptr</tt>' instruction returns a
|
||||
pointer to this element, thus computing a value of '<tt>i32*</tt>' type.</p>
|
||||
<p>In the example above, the first index is indexing into the
|
||||
'<tt>%struct.ST*</tt>' type, which is a pointer, yielding a
|
||||
'<tt>%struct.ST</tt>' = '<tt>{ i32, double, %struct.RT }</tt>' type, a
|
||||
structure. The second index indexes into the third element of the structure,
|
||||
yielding a '<tt>%struct.RT</tt>' = '<tt>{ i8 , [10 x [20 x i32]], i8 }</tt>'
|
||||
type, another structure. The third index indexes into the second element of
|
||||
the structure, yielding a '<tt>[10 x [20 x i32]]</tt>' type, an array. The
|
||||
two dimensions of the array are subscripted into, yielding an '<tt>i32</tt>'
|
||||
type. The '<tt>getelementptr</tt>' instruction returns a pointer to this
|
||||
element, thus computing a value of '<tt>i32*</tt>' type.</p>
|
||||
|
||||
<p>Note that it is perfectly legal to index partially through a structure,
|
||||
returning a pointer to an inner element. Because of this, the LLVM code for
|
||||
the given testcase is equivalent to:</p>
|
||||
|
||||
<pre>
|
||||
define i32* @foo(%ST* %s) {
|
||||
%t1 = getelementptr %ST* %s, i32 1 <i>; yields %ST*:%t1</i>
|
||||
%t2 = getelementptr %ST* %t1, i32 0, i32 2 <i>; yields %RT*:%t2</i>
|
||||
%t3 = getelementptr %RT* %t2, i32 0, i32 1 <i>; yields [10 x [20 x i32]]*:%t3</i>
|
||||
%t4 = getelementptr [10 x [20 x i32]]* %t3, i32 0, i32 5 <i>; yields [20 x i32]*:%t4</i>
|
||||
%t5 = getelementptr [20 x i32]* %t4, i32 0, i32 13 <i>; yields i32*:%t5</i>
|
||||
ret i32* %t5
|
||||
}
|
||||
<pre class="doc_code">
|
||||
define i32* @foo(%struct.ST* %s) {
|
||||
%t1 = getelementptr %struct.ST* %s, i32 1 <i>; yields %struct.ST*:%t1</i>
|
||||
%t2 = getelementptr %struct.ST* %t1, i32 0, i32 2 <i>; yields %struct.RT*:%t2</i>
|
||||
%t3 = getelementptr %struct.RT* %t2, i32 0, i32 1 <i>; yields [10 x [20 x i32]]*:%t3</i>
|
||||
%t4 = getelementptr [10 x [20 x i32]]* %t3, i32 0, i32 5 <i>; yields [20 x i32]*:%t4</i>
|
||||
%t5 = getelementptr [20 x i32]* %t4, i32 0, i32 13 <i>; yields i32*:%t5</i>
|
||||
ret i32* %t5
|
||||
}
|
||||
</pre>
|
||||
|
||||
<p>If the <tt>inbounds</tt> keyword is present, the result value of the
|
||||
|
Loading…
Reference in New Issue
Block a user