-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[mlir][ptr] Add ptr.ptr_diff
operation
#157354
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
607a3e0
5ea8571
c25dd35
f4a8eb2
3fca67d
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 |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
#include "mlir/IR/Matchers.h" | ||
#include "mlir/Interfaces/DataLayoutInterfaces.h" | ||
#include "mlir/Transforms/InliningUtils.h" | ||
#include "llvm/ADT/StringExtras.h" | ||
#include "llvm/ADT/TypeSwitch.h" | ||
|
||
using namespace mlir; | ||
|
@@ -391,6 +392,39 @@ LogicalResult PtrAddOp::inferReturnTypes( | |
return success(); | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// PtrDiffOp | ||
//===----------------------------------------------------------------------===// | ||
|
||
LogicalResult PtrDiffOp::verify() { | ||
// If the operands are not shaped early exit. | ||
if (!isa<ShapedType>(getLhs().getType())) | ||
return success(); | ||
|
||
// Just check the container type matches, `SameOperandsAndResultShape` handles | ||
// the actual shape. | ||
if (getResult().getType().getTypeID() != getLhs().getType().getTypeID()) { | ||
return emitError() << "expected the result to have the same container " | ||
"type as the operands when operands are shaped"; | ||
} | ||
|
||
return success(); | ||
} | ||
|
||
ptr::PtrType PtrDiffOp::getPtrType() { | ||
Type lhsType = getLhs().getType(); | ||
if (auto shapedType = dyn_cast<ShapedType>(lhsType)) | ||
return cast<ptr::PtrType>(shapedType.getElementType()); | ||
return cast<ptr::PtrType>(lhsType); | ||
} | ||
|
||
Type PtrDiffOp::getIntType() { | ||
Type resultType = getResult().getType(); | ||
if (auto shapedType = dyn_cast<ShapedType>(resultType)) | ||
return shapedType.getElementType(); | ||
return resultType; | ||
} | ||
|
||
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. Can we get a folder for the subtraction? 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. Sure, in general I need to improve the folders and canonicalizers of the entire dialect, so how about a new PR for that? |
||
//===----------------------------------------------------------------------===// | ||
// ToPtrOp | ||
//===----------------------------------------------------------------------===// | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like an accidental include.