mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-27 15:14:31 +00:00
[mlir] make vector to llvm conversion truly partial
Historically, the Vector to LLVM dialect conversion subsumed the Standard to LLVM dialect conversion patterns. This was necessary because the conversion infrastructure did not have sufficient support for reconciling type conversions. This support is now available. Only keep the patterns related to the Vector dialect in the Vector to LLVM conversion and require type casts operations to be inserted if necessary. These casts will be removed by following conversions if possible. Update integration tests to also run the Standard to LLVM conversion. There is a significant amount of test churn, which is due to (a) unnecessarily strict tests in VectorToLLVM and (b) many patterns actually targeting Standard dialect ops instead of LLVM dialect ops leading to tests actually exercising a Vector->Standard->LLVM conversion. This churn is a good illustration of the reason to make the conversion partial: now the tests only check the code in the Vector to LLVM conversion and will not be randomly broken by changes in Standard to LLVM conversion. Arguably, it may be possible to extract Vector to Standard patterns into a separate pass, but given the ongoing splitting of the Standard dialect, such pass will be short-lived and will require further refactoring. Depends On D95626 Reviewed By: nicolasvasilache, aartbik Differential Revision: https://reviews.llvm.org/D95685
This commit is contained in:
1 parent
aa56b30014
commit
ba87f99168
18 files changed
+634
-492
No files matched your search
@@ -102,6 +102,27 @@ static SmallVector<int64_t, 4> getI64SubArray(ArrayAttr arrayAttr,
|
||||
return res;
|
||||
}
|
||||
|
||||
static Value createCastToIndexLike(ConversionPatternRewriter &rewriter,
|
||||
Location loc, Type targetType, Value value) {
|
||||
if (targetType == value.getType())
|
||||
return value;
|
||||
|
||||
bool targetIsIndex = targetType.isIndex();
|
||||
bool valueIsIndex = value.getType().isIndex();
|
||||
if (targetIsIndex ^ valueIsIndex)
|
||||
return rewriter.create<IndexCastOp>(loc, targetType, value);
|
||||
|
||||
auto targetIntegerType = targetType.dyn_cast<IntegerType>();
|
||||
auto valueIntegerType = value.getType().dyn_cast<IntegerType>();
|
||||
assert(targetIntegerType && valueIntegerType &&
|
||||
"unexpected cast between types other than integers and index");
|
||||
assert(targetIntegerType.getSignedness() == valueIntegerType.getSignedness());
|
||||
|
||||
if (targetIntegerType.getWidth() > valueIntegerType.getWidth())
|
||||
return rewriter.create<SignExtendIOp>(loc, targetIntegerType, value);
|
||||
return rewriter.create<TruncateIOp>(loc, targetIntegerType, value);
|
||||
}
|
||||
|
||||
// Helper that returns a vector comparison that constructs a mask:
|
||||
// mask = [0,1,..,n-1] + [o,o,..,o] < [b,b,..,b]
|
||||
//
|
||||
@@ -131,12 +152,12 @@ static Value buildVectorComparison(ConversionPatternRewriter &rewriter,
|
||||
}
|
||||
// Add in an offset if requested.
|
||||
if (off) {
|
||||
Value o = rewriter.create<IndexCastOp>(loc, idxType, *off);
|
||||
Value o = createCastToIndexLike(rewriter, loc, idxType, *off);
|
||||
Value ov = rewriter.create<SplatOp>(loc, indices.getType(), o);
|
||||
indices = rewriter.create<AddIOp>(loc, ov, indices);
|
||||
}
|
||||
// Construct the vector comparison.
|
||||
Value bound = rewriter.create<IndexCastOp>(loc, idxType, b);
|
||||
Value bound = createCastToIndexLike(rewriter, loc, idxType, b);
|
||||
Value bounds = rewriter.create<SplatOp>(loc, indices.getType(), bound);
|
||||
return rewriter.create<CmpIOp>(loc, CmpIPredicate::slt, indices, bounds);
|
||||
}
|
||||
@@ -216,10 +237,8 @@ replaceTransferOpWithMasked(ConversionPatternRewriter &rewriter,
|
||||
LLVMTypeConverter &typeConverter, Location loc,
|
||||
TransferReadOp xferOp, ArrayRef<Value> operands,
|
||||
Value dataPtr, Value mask) {
|
||||
auto toLLVMTy = [&](Type t) { return typeConverter.convertType(t); };
|
||||
VectorType fillType = xferOp.getVectorType();
|
||||
Value fill = rewriter.create<SplatOp>(loc, fillType, xferOp.padding());
|
||||
fill = rewriter.create<LLVM::DialectCastOp>(loc, toLLVMTy(fillType), fill);
|
||||
|
||||
Type vecTy = typeConverter.convertType(xferOp.getVectorType());
|
||||
if (!vecTy)
|
||||
|
||||
Reference in new issue
Block a user