@@ -148,7 +148,6 @@ static bool areConversionCompatible(const DataLayout &layout, Type lhs,
148
148
if (lhs == rhs)
149
149
return true ;
150
150
151
- // Aggregate types cannot be casted.
152
151
if (!isSupportedTypeForConversion (lhs) || !isSupportedTypeForConversion (rhs))
153
152
return false ;
154
153
return layout.getTypeSize (lhs) <= layout.getTypeSize (rhs);
@@ -168,8 +167,10 @@ constexpr const static uint64_t kBitsInByte = 8;
168
167
static Value createConversionSequence (RewriterBase &rewriter, Location loc,
169
168
Value srcValue, Type targetType,
170
169
const DataLayout &dataLayout) {
171
- // Get the types of the source and destination values.
170
+ // Get the types of the source and target values.
172
171
Type srcType = srcValue.getType ();
172
+ assert (areConversionCompatible (dataLayout, targetType, srcType) &&
173
+ " expected that the compatibility was checked before" );
173
174
174
175
uint64_t srcTypeSize = dataLayout.getTypeSize (srcType);
175
176
uint64_t targetTypeSize = dataLayout.getTypeSize (targetType);
@@ -178,26 +179,14 @@ static Value createConversionSequence(RewriterBase &rewriter, Location loc,
178
179
if (srcType == targetType)
179
180
return srcValue;
180
181
181
- // The code below is currently not capable of handling aggregate types as it
182
- // makes use of bitcasts. Aggregates cannot be bitcast.
183
- // TODO: We should have a `LLVMAggregateType` base class to easily perform
184
- // this `isa`.
185
- if (isa<LLVM::LLVMArrayType, LLVM::LLVMStructType>(srcType) ||
186
- isa<LLVM::LLVMArrayType, LLVM::LLVMStructType>(targetType))
187
- return nullptr ;
188
-
189
182
// In the special case of casting one pointer to another, we want to generate
190
183
// an address space cast. Bitcasts of pointers are not allowed and using
191
184
// pointer to integer conversions are not equivalent due to the loss or
192
185
// provenance.
193
186
if (isa<LLVM::LLVMPointerType>(targetType) &&
194
- isa<LLVM::LLVMPointerType>(srcType)) {
195
- // Abort the conversion if the pointers have different bitwidths.
196
- if (srcTypeSize != targetTypeSize)
197
- return nullptr ;
187
+ isa<LLVM::LLVMPointerType>(srcType))
198
188
return rewriter.createOrFold <LLVM::AddrSpaceCastOp>(loc, targetType,
199
189
srcValue);
200
- }
201
190
202
191
IntegerType valueSizeInteger =
203
192
rewriter.getIntegerType (srcTypeSize * kBitsInByte );
@@ -211,7 +200,7 @@ static Value createConversionSequence(RewriterBase &rewriter, Location loc,
211
200
replacement = rewriter.createOrFold <LLVM::BitcastOp>(loc, valueSizeInteger,
212
201
replacement);
213
202
214
- // Truncate the integer if the size of the read is less than the value.
203
+ // Truncate the integer if the size of the target is less than the value.
215
204
if (targetTypeSize != srcTypeSize) {
216
205
if (!isLittleEndian (dataLayout)) {
217
206
uint64_t shiftAmount = (srcTypeSize - targetTypeSize) * kBitsInByte ;
@@ -226,7 +215,7 @@ static Value createConversionSequence(RewriterBase &rewriter, Location loc,
226
215
replacement);
227
216
}
228
217
229
- // Now cast the integer to the actual destination type if required.
218
+ // Now cast the integer to the actual target type if required.
230
219
if (isa<LLVM::LLVMPointerType>(targetType))
231
220
replacement =
232
221
rewriter.createOrFold <LLVM::IntToPtrOp>(loc, targetType, replacement);
0 commit comments