-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[IR] Initial introduction of memset_pattern #97583
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
627f1ef
3a0d10a
d710a1f
4bcc00e
7d1347c
60ba68b
be558f9
dfc0564
8ac8b69
6d16c82
55ee84a
1e60edd
88b5af3
ea429b4
e9c98c8
30d59b9
d83fdfb
64bc6af
c19adc1
03e07d5
a7373b7
a68aa8d
9580ab0
4ebc985
78bad3b
71dd9b5
ad7585c
4d6d9ab
0b0e81e
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 |
---|---|---|
|
@@ -15434,6 +15434,63 @@ The behavior of '``llvm.memset.inline.*``' is equivalent to the behavior of | |
'``llvm.memset.*``', but the generated code is guaranteed not to call any | ||
external functions. | ||
|
||
.. _int_experimental_memset_pattern: | ||
|
||
'``llvm.experimental.memset.pattern``' Intrinsic | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
Syntax: | ||
""""""" | ||
|
||
This is an overloaded intrinsic. You can use | ||
``llvm.experimental.memset.pattern`` on any integer bit width and for | ||
different address spaces. Not all targets support all bit widths however. | ||
|
||
:: | ||
|
||
declare void @llvm.experimental.memset.pattern.p0.i128.i64(ptr <dest>, i128 <val>, | ||
i64 <count>, i1 <isvolatile>) | ||
|
||
Overview: | ||
""""""""" | ||
|
||
The '``llvm.experimental.memset.pattern.*``' intrinsics fill a block of memory | ||
with a particular value. This may be expanded to an inline loop, a sequence of | ||
stores, or a libcall depending on what is available for the target and the | ||
expected performance and code size impact. | ||
|
||
Arguments: | ||
"""""""""" | ||
|
||
The first argument is a pointer to the destination to fill, the second | ||
is the value with which to fill it, the third argument is an integer | ||
argument specifying the number of times to fill the value, and the fourth is a | ||
boolean indicating a volatile access. | ||
|
||
The :ref:`align <attr_align>` parameter attribute can be provided | ||
for the first argument. | ||
|
||
If the ``isvolatile`` parameter is ``true``, the | ||
``llvm.experimental.memset.pattern`` call is a :ref:`volatile operation | ||
<volatile>`. The detailed access behavior is not very cleanly specified and it | ||
is unwise to depend on it. | ||
|
||
Semantics: | ||
"""""""""" | ||
|
||
The '``llvm.experimental.memset.pattern*``' intrinsic fills memory starting at | ||
the destination location with the given pattern ``<count>`` times, | ||
incrementing by the allocation size of the type each time. The stores follow | ||
asb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
the usual semantics of store instructions, including regarding endianness and | ||
padding. If the argument is known to be aligned to some boundary, this can be | ||
specified as an attribute on the argument. | ||
|
||
If ``<count>`` is 0, it is no-op modulo the behavior of attributes attached to | ||
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. If the size is not an integral number of bytes, what happens with the padding bits? 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 behavior is the same as whatever stores of the type would do. Possibly we should just explicit refer to store semantics here and reduce the description to something like this:
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. Thanks, that's much clearer - I've adopted that wording. |
||
the arguments. | ||
If ``<count>`` is not a well-defined value, the behavior is undefined. | ||
If ``<count>`` is not zero, ``<dest>`` should be well-defined, otherwise the | ||
behavior is undefined. | ||
|
||
.. _int_sqrt: | ||
|
||
'``llvm.sqrt.*``' Intrinsic | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1263,6 +1263,41 @@ class MemSetInlineInst : public MemSetInst { | |
} | ||
}; | ||
|
||
/// This is the base class for llvm.experimental.memset.pattern | ||
class MemSetPatternIntrinsic : public MemIntrinsicBase<MemIntrinsic> { | ||
private: | ||
enum { ARG_VOLATILE = 3 }; | ||
|
||
public: | ||
ConstantInt *getVolatileCst() const { | ||
return cast<ConstantInt>(const_cast<Value *>(getArgOperand(ARG_VOLATILE))); | ||
} | ||
|
||
bool isVolatile() const { return !getVolatileCst()->isZero(); } | ||
|
||
void setVolatile(Constant *V) { setArgOperand(ARG_VOLATILE, V); } | ||
|
||
// Methods for support of type inquiry through isa, cast, and dyn_cast: | ||
static bool classof(const IntrinsicInst *I) { | ||
return I->getIntrinsicID() == Intrinsic::experimental_memset_pattern; | ||
} | ||
static bool classof(const Value *V) { | ||
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); | ||
} | ||
}; | ||
|
||
/// This class wraps the llvm.experimental.memset.pattern intrinsic. | ||
class MemSetPatternInst : public MemSetBase<MemSetPatternIntrinsic> { | ||
public: | ||
// Methods for support type inquiry through isa, cast, and dyn_cast: | ||
static bool classof(const IntrinsicInst *I) { | ||
return I->getIntrinsicID() == Intrinsic::experimental_memset_pattern; | ||
} | ||
static bool classof(const Value *V) { | ||
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); | ||
} | ||
}; | ||
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. Why do we need both MemSetPatternIntrinsic and MemSetPatternInst? 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. I'm mirroring the pattern followed by other mem intrinsics, and although it's not super pretty, having both classes like this (as for the standard MemSet intrinsics) seems the way that reduces copy and paste of accessor code. 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. Hm okay, I thought this might only be needed for cases where we have both atomic and non-atomic variants. |
||
|
||
/// This class wraps the llvm.memcpy/memmove intrinsics. | ||
class MemTransferInst : public MemTransferBase<MemIntrinsic> { | ||
public: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1006,6 +1006,17 @@ def int_memset_inline | |
NoCapture<ArgIndex<0>>, WriteOnly<ArgIndex<0>>, | ||
ImmArg<ArgIndex<3>>]>; | ||
|
||
// Memset variant that writes a given pattern. | ||
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. Comment what the operands are 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. Added with inline comments (there's not a totally consistent pattern for describing args - many intrinsics have no description at all, but I see some other examples in the file using inline comments for the args) 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. Really we ought to have tablegen mandatory doc strings |
||
def int_experimental_memset_pattern | ||
: Intrinsic<[], | ||
[llvm_anyptr_ty, // Destination. | ||
llvm_anyint_ty, // Pattern value. | ||
llvm_anyint_ty, // Count (number of times to fill value). | ||
llvm_i1_ty], // IsVolatile. | ||
[IntrWriteMem, IntrArgMemOnly, IntrWillReturn, IntrNoFree, IntrNoCallback, | ||
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. DefaultAttrIntrinsic would hide most of these 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. I dug through this and unfortunately I can't make use of |
||
NoCapture<ArgIndex<0>>, WriteOnly<ArgIndex<0>>, | ||
ImmArg<ArgIndex<3>>]>; | ||
|
||
// FIXME: Add version of these floating point intrinsics which allow non-default | ||
// rounding modes and FP exception handling. | ||
|
||
|
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.
Do we need a Verifier check to check that the size is integral number of bytes?
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.
I've now added this check to the verifier.
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.
Actually that was my bad. There was some discussion about this before and in the end non-integral bitwidths should work and are tested in
llvm/test/Transforms/PreISelIntrinsicLowering/RISCV/memset-pattern.ll
. I've now pushed a fix to LangRef to remove the stated restriction.