@@ -126,17 +126,16 @@ pub fn llbitsize_of_real(cx: @crate_ctxt, t: TypeRef) -> uint {
126
126
}
127
127
}
128
128
129
- // Returns the "default" size of t, which is calculated by casting null to a
130
- // *T and then doing gep(1) on it and measuring the result. Really, look in
131
- // the LLVM sources. It does that. So this is likely similar to the ABI size
132
- // (i.e. including alignment-padding), but goodness knows which alignment it
133
- // winds up using. Probably the ABI one? Not recommended.
129
+ /// Returns the size of the type as an LLVM constant integer value.
134
130
pub fn llsize_of ( cx : @crate_ctxt , t : TypeRef ) -> ValueRef {
135
- unsafe {
136
- return llvm:: LLVMConstIntCast ( lib:: llvm:: llvm:: LLVMSizeOf ( t) ,
137
- cx. int_type ,
138
- False ) ;
139
- }
131
+ // Once upon a time, this called LLVMSizeOf, which does a
132
+ // getelementptr(1) on a null pointer and casts to an int, in
133
+ // order to obtain the type size as a value without requiring the
134
+ // target data layout. But we have the target data layout, so
135
+ // there's no need for that contrivance. The instruction
136
+ // selection DAG generator would flatten that GEP(1) node into a
137
+ // constant of the type's alloc size, so let's save it some work.
138
+ return C_uint ( cx, llsize_of_alloc ( cx, t) ) ;
140
139
}
141
140
142
141
// Returns the "default" size of t (see above), or 1 if the size would
0 commit comments