-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[CIR] Add binary operators #132420
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
[CIR] Add binary operators #132420
Changes from all commits
706c944
e2e0fa4
a77053b
ad4b4c2
a3c8c79
c66dac4
be5af08
77aa79b
56fbcba
455edf2
4428f8b
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 |
---|---|---|
|
@@ -826,6 +826,69 @@ def ForOp : CIR_Op<"for", [LoopOpInterface, NoRegionArguments]> { | |
}]; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// BinOp | ||
//===----------------------------------------------------------------------===// | ||
|
||
// FIXME: represent Commutative, Idempotent traits for appropriate binops | ||
def BinOpKind_Mul : I32EnumAttrCase<"Mul", 1, "mul">; | ||
def BinOpKind_Div : I32EnumAttrCase<"Div", 2, "div">; | ||
def BinOpKind_Rem : I32EnumAttrCase<"Rem", 3, "rem">; | ||
def BinOpKind_Add : I32EnumAttrCase<"Add", 4, "add">; | ||
def BinOpKind_Sub : I32EnumAttrCase<"Sub", 5, "sub">; | ||
def BinOpKind_And : I32EnumAttrCase<"And", 8, "and">; | ||
def BinOpKind_Xor : I32EnumAttrCase<"Xor", 9, "xor">; | ||
def BinOpKind_Or : I32EnumAttrCase<"Or", 10, "or">; | ||
// TODO(cir): Do we need a min binop? | ||
def BinOpKind_Max : I32EnumAttrCase<"Max", 11, "max">; | ||
|
||
def BinOpKind : I32EnumAttr< | ||
"BinOpKind", | ||
"binary operation (arith and logic) kind", | ||
[BinOpKind_Mul, BinOpKind_Div, BinOpKind_Rem, | ||
BinOpKind_Add, BinOpKind_Sub, | ||
BinOpKind_And, BinOpKind_Xor, | ||
BinOpKind_Or, BinOpKind_Max]> { | ||
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. Max isn't listed on the ClangIR GitHub pages. We should update those soon. |
||
let cppNamespace = "::cir"; | ||
} | ||
|
||
def BinOp : CIR_Op<"binop", [Pure, | ||
SameTypeOperands, SameOperandsAndResultType]> { | ||
|
||
let summary = "Binary operations (arith and logic)"; | ||
let description = [{ | ||
cir.binop performs the binary operation according to | ||
the specified opcode kind: [mul, div, rem, add, sub, | ||
and, xor, or, max]. | ||
|
||
It requires two input operands and has one result, all types | ||
should be the same. | ||
|
||
```mlir | ||
%7 = cir.binop(add, %1, %2) : !s32i | ||
%7 = cir.binop(mul, %1, %2) : !u8i | ||
``` | ||
}]; | ||
|
||
// TODO: get more accurate than CIR_AnyType | ||
let results = (outs CIR_AnyType:$result); | ||
let arguments = (ins Arg<BinOpKind, "binop kind">:$kind, | ||
CIR_AnyType:$lhs, CIR_AnyType:$rhs, | ||
UnitAttr:$no_unsigned_wrap, | ||
UnitAttr:$no_signed_wrap, | ||
UnitAttr:$saturated); | ||
|
||
let assemblyFormat = [{ | ||
`(` $kind `,` $lhs `,` $rhs `)` | ||
(`nsw` $no_signed_wrap^)? | ||
(`nuw` $no_unsigned_wrap^)? | ||
(`sat` $saturated^)? | ||
`:` type($lhs) attr-dict | ||
}]; | ||
|
||
let hasVerifier = 1; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// GlobalOp | ||
//===----------------------------------------------------------------------===// | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,9 @@ struct MissingFeatures { | |
static bool opUnarySignedOverflow() { return false; } | ||
static bool opUnaryPromotionType() { return false; } | ||
|
||
// Clang early optimizations or things defered to LLVM lowering. | ||
static bool mayHaveIntegerOverflow() { return false; } | ||
|
||
// Misc | ||
static bool cxxABI() { return false; } | ||
static bool tryEmitAsConstant() { return false; } | ||
|
@@ -93,16 +96,19 @@ struct MissingFeatures { | |
static bool stackSaveOp() { return false; } | ||
static bool aggValueSlot() { return false; } | ||
static bool generateDebugInfo() { return false; } | ||
static bool pointerOverflowSanitizer() { return false; } | ||
static bool fpConstraints() { return false; } | ||
static bool sanitizers() { return false; } | ||
static bool addHeapAllocSiteMetadata() { return false; } | ||
static bool targetCodeGenInfoGetNullPointer() { return false; } | ||
static bool CGFPOptionsRAII() { return false; } | ||
static bool loopInfoStack() { return false; } | ||
static bool requiresCleanups() { return false; } | ||
static bool createProfileWeightsForLoop() { return false; } | ||
static bool emitCondLikelihoodViaExpectIntrinsic() { return false; } | ||
static bool pgoUse() { return false; } | ||
static bool cgFPOptionsRAII() { return false; } | ||
static bool metaDataNode() { return false; } | ||
static bool fastMathFlags() { return false; } | ||
|
||
// Missing types | ||
static bool dataMemberType() { return false; } | ||
|
@@ -111,6 +117,8 @@ struct MissingFeatures { | |
static bool scalableVectors() { return false; } | ||
static bool unsizedTypes() { return false; } | ||
static bool vectorType() { return false; } | ||
static bool complexType() { return false; } | ||
static bool fixedPointType() { return false; } | ||
|
||
// Future CIR operations | ||
static bool awaitOp() { return false; } | ||
|
@@ -127,6 +135,8 @@ struct MissingFeatures { | |
static bool ternaryOp() { return false; } | ||
static bool tryOp() { return false; } | ||
static bool zextOp() { return false; } | ||
static bool ptrStrideOp() { return false; } | ||
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. @AmrDeveloper Be sure to look for the places where this is used when you add support for cir.ptr_stride. |
||
static bool ptrDiffOp() { return false; } | ||
}; | ||
|
||
} // namespace cir | ||
|
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.
What does
max
represent in the language? Or is this something we transform to?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 is to support
__builtin_elementwise_max
and at least one corresponding SIMD intrinsic function (see llvm/clangir#1201).I can't find that
TODO
in the git history of the incubator for some reason. But since there is a__builtin_elementwise_min
I assume there needs to be a min as well.Both builtins are still NYI though so I could remove them for the time being.