-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir] Fix conflict of user defined reserved functions with internal prototypes #123378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3b892e6
bdb69fc
d26a77d
5ec38d6
9079caf
475409c
874a1cd
2d7dc5d
a7f3308
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,18 +14,19 @@ | |
|
||
using namespace mlir; | ||
|
||
namespace { | ||
LLVM::LLVMFuncOp getNotalignedAllocFn(const LLVMTypeConverter *typeConverter, | ||
Operation *module, Type indexType) { | ||
static FailureOr<LLVM::LLVMFuncOp> | ||
getNotalignedAllocFn(const LLVMTypeConverter *typeConverter, Operation *module, | ||
Type indexType) { | ||
bool useGenericFn = typeConverter->getOptions().useGenericFunctions; | ||
if (useGenericFn) | ||
return LLVM::lookupOrCreateGenericAllocFn(module, indexType); | ||
|
||
return LLVM::lookupOrCreateMallocFn(module, indexType); | ||
} | ||
|
||
LLVM::LLVMFuncOp getAlignedAllocFn(const LLVMTypeConverter *typeConverter, | ||
Operation *module, Type indexType) { | ||
static FailureOr<LLVM::LLVMFuncOp> | ||
getAlignedAllocFn(const LLVMTypeConverter *typeConverter, Operation *module, | ||
Type indexType) { | ||
bool useGenericFn = typeConverter->getOptions().useGenericFunctions; | ||
|
||
if (useGenericFn) | ||
|
@@ -34,8 +35,6 @@ LLVM::LLVMFuncOp getAlignedAllocFn(const LLVMTypeConverter *typeConverter, | |
return LLVM::lookupOrCreateAlignedAllocFn(module, indexType); | ||
} | ||
|
||
} // end namespace | ||
|
||
Value AllocationOpLLVMLowering::createAligned( | ||
ConversionPatternRewriter &rewriter, Location loc, Value input, | ||
Value alignment) { | ||
|
@@ -80,10 +79,13 @@ std::tuple<Value, Value> AllocationOpLLVMLowering::allocateBufferManuallyAlign( | |
<< " to integer address space " | ||
"failed. Consider adding memory space conversions."; | ||
} | ||
LLVM::LLVMFuncOp allocFuncOp = getNotalignedAllocFn( | ||
FailureOr<LLVM::LLVMFuncOp> allocFuncOp = getNotalignedAllocFn( | ||
getTypeConverter(), op->getParentWithTrait<OpTrait::SymbolTable>(), | ||
getIndexType()); | ||
auto results = rewriter.create<LLVM::CallOp>(loc, allocFuncOp, sizeBytes); | ||
if (failed(allocFuncOp)) | ||
return std::make_tuple(Value(), Value()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this result in a crash later on? If so, this would also require a FailureOr wrapping. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The returned pair of value is populated and finally verified here: AllocLikeConvertion.cpp // Allocate the underlying buffer.
auto [allocatedPtr, alignedPtr] =
this->allocateBuffer(rewriter, loc, size, op);
if (!allocatedPtr || !alignedPtr)
return rewriter.notifyMatchFailure(loc,
"underlying buffer allocation failed"); Here empty value is assigned as the invalid state and properly handled. I prefer to leave it as is, and a separate PR might be more appropriate to modernize the error handling style if we do have a preference. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fine for me 🙂 |
||
auto results = | ||
rewriter.create<LLVM::CallOp>(loc, allocFuncOp.value(), sizeBytes); | ||
|
||
Value allocatedPtr = | ||
castAllocFuncResult(rewriter, loc, results.getResult(), memRefType, | ||
|
@@ -146,11 +148,13 @@ Value AllocationOpLLVMLowering::allocateBufferAutoAlign( | |
sizeBytes = createAligned(rewriter, loc, sizeBytes, allocAlignment); | ||
|
||
Type elementPtrType = this->getElementPtrType(memRefType); | ||
LLVM::LLVMFuncOp allocFuncOp = getAlignedAllocFn( | ||
FailureOr<LLVM::LLVMFuncOp> allocFuncOp = getAlignedAllocFn( | ||
getTypeConverter(), op->getParentWithTrait<OpTrait::SymbolTable>(), | ||
getIndexType()); | ||
if (failed(allocFuncOp)) | ||
return Value(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handled at MemRefToLLVM.cpp Value ptr = allocateBufferAutoAlign(
rewriter, loc, sizeBytes, op, &defaultLayout,
alignedAllocationGetAlignment(rewriter, loc, cast<memref::AllocOp>(op),
&defaultLayout));
if (!ptr)
return std::make_tuple(Value(), Value());
return std::make_tuple(ptr, ptr); in the same style. |
||
auto results = rewriter.create<LLVM::CallOp>( | ||
loc, allocFuncOp, ValueRange({allocAlignment, sizeBytes})); | ||
loc, allocFuncOp.value(), ValueRange({allocAlignment, sizeBytes})); | ||
|
||
return castAllocFuncResult(rewriter, loc, results.getResult(), memRefType, | ||
elementPtrType, *getTypeConverter()); | ||
|
Uh oh!
There was an error while loading. Please reload this page.