Skip to content

Commit 3a7eeae

Browse files
committed
Outline getting alignment from load or store op
1 parent 8c65e3d commit 3a7eeae

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,25 @@ LogicalResult getVectorToLLVMAlignment(const LLVMTypeConverter &typeConverter,
121121
return success();
122122
}
123123

124+
// Helper to resolve the alignment for vector load/store, gather and scatter
125+
// ops. First, this method will try to obtain the preferred alignment from the
126+
// load or store operation itself. If the store or load operation does not
127+
// contain any preferred alignment, then it will get alignment attribute through
128+
// the type or the backend.
129+
template <class LoadOrStoreOp>
130+
LogicalResult getVectorToLLVMAlignment(LoadOrStoreOp loadOrStoreOp,
131+
const LLVMTypeConverter &typeConverter,
132+
VectorType vectorType,
133+
MemRefType memrefType, unsigned &align,
134+
bool useVectorAlignment) {
135+
if (auto alignment = loadOrStoreOp.getAlignment()) {
136+
align = alignment.value_or(0);
137+
return success();
138+
}
139+
return getVectorToLLVMAlignment(typeConverter, vectorType, memrefType,
140+
align, useVectorAlignment);
141+
}
142+
124143
// Check if the last stride is non-unit and has a valid memory space.
125144
static LogicalResult isMemRefTypeSupported(MemRefType memRefType,
126145
const LLVMTypeConverter &converter) {
@@ -247,8 +266,9 @@ class VectorLoadStoreConversion : public ConvertOpToLLVMPattern<LoadOrStoreOp> {
247266
MemRefType memRefTy = loadOrStoreOp.getMemRefType();
248267

249268
// Resolve alignment.
250-
unsigned align = loadOrStoreOp.getAlignment().value_or(0);
251-
if (!align && failed(getVectorToLLVMAlignment(*this->getTypeConverter(), vectorTy,
269+
unsigned align;
270+
if (failed(getVectorToLLVMAlignment(loadOrStoreOp,
271+
*this->getTypeConverter(), vectorTy,
252272
memRefTy, align, useVectorAlignment)))
253273
return rewriter.notifyMatchFailure(loadOrStoreOp,
254274
"could not resolve alignment");

0 commit comments

Comments
 (0)