Skip to content

Commit a0a1619

Browse files
committed
improve inline comments + outdated code removal
1 parent 5e37eeb commit a0a1619

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

mlir/lib/Dialect/LLVMIR/IR/LLVMMemorySlot.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ static bool areConversionCompatible(const DataLayout &layout, Type lhs,
148148
if (lhs == rhs)
149149
return true;
150150

151-
// Aggregate types cannot be casted.
152151
if (!isSupportedTypeForConversion(lhs) || !isSupportedTypeForConversion(rhs))
153152
return false;
154153
return layout.getTypeSize(lhs) <= layout.getTypeSize(rhs);
@@ -168,8 +167,10 @@ constexpr const static uint64_t kBitsInByte = 8;
168167
static Value createConversionSequence(RewriterBase &rewriter, Location loc,
169168
Value srcValue, Type targetType,
170169
const DataLayout &dataLayout) {
171-
// Get the types of the source and destination values.
170+
// Get the types of the source and target values.
172171
Type srcType = srcValue.getType();
172+
assert(areConversionCompatible(dataLayout, targetType, srcType) &&
173+
"expected that the compatibility was checked before");
173174

174175
uint64_t srcTypeSize = dataLayout.getTypeSize(srcType);
175176
uint64_t targetTypeSize = dataLayout.getTypeSize(targetType);
@@ -178,26 +179,14 @@ static Value createConversionSequence(RewriterBase &rewriter, Location loc,
178179
if (srcType == targetType)
179180
return srcValue;
180181

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-
189182
// In the special case of casting one pointer to another, we want to generate
190183
// an address space cast. Bitcasts of pointers are not allowed and using
191184
// pointer to integer conversions are not equivalent due to the loss or
192185
// provenance.
193186
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))
198188
return rewriter.createOrFold<LLVM::AddrSpaceCastOp>(loc, targetType,
199189
srcValue);
200-
}
201190

202191
IntegerType valueSizeInteger =
203192
rewriter.getIntegerType(srcTypeSize * kBitsInByte);
@@ -211,7 +200,7 @@ static Value createConversionSequence(RewriterBase &rewriter, Location loc,
211200
replacement = rewriter.createOrFold<LLVM::BitcastOp>(loc, valueSizeInteger,
212201
replacement);
213202

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.
215204
if (targetTypeSize != srcTypeSize) {
216205
if (!isLittleEndian(dataLayout)) {
217206
uint64_t shiftAmount = (srcTypeSize - targetTypeSize) * kBitsInByte;
@@ -226,7 +215,7 @@ static Value createConversionSequence(RewriterBase &rewriter, Location loc,
226215
replacement);
227216
}
228217

229-
// Now cast the integer to the actual destination type if required.
218+
// Now cast the integer to the actual target type if required.
230219
if (isa<LLVM::LLVMPointerType>(targetType))
231220
replacement =
232221
rewriter.createOrFold<LLVM::IntToPtrOp>(loc, targetType, replacement);

0 commit comments

Comments
 (0)