-
Notifications
You must be signed in to change notification settings - Fork 167
[CIR] Add GEP flags to ptr stride op #1863
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
base: main
Are you sure you want to change the base?
Conversation
✅ With the latest revision this PR passed the C/C++ code formatter. |
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.
Nice! This also needs CIRGen changes and lowering to LLVM support, but looks like a good start
It might make sense for |
is there any historical reason why we didn't consolidate the two? |
Nope, I introduced |
I like |
I added lowering and codegen, I added OGCG test initially but was reluctant if i should push it. I also didn't remove the missing feature check, i'm not sure how feature ready this is compared to OG. |
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.
Can this be first ported to incubator then mirrored here.
def GEPInbounds : BitEnumCaseGroup<"inbounds", [GEPInboundsFlag, GEPNusw]>; | ||
|
||
def GEPNoWrapFlags | ||
: I32BitEnum<"GEPNoWrapFlags", "::cir::GEPNoWrapFlags", |
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.
We should add CIR_I32BitEnum
similar to CIR_I32Enum
.
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'll add a test implement but would love another review on this
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.
Could we just replace these with CIR_I32Enum
instead? That way it would match the other enum
s we use.
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'm more keen on keeping the 1-to-1 mapping between the LLVM dialect and this PR, but i can change if need 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.
Oh I see, they're fundamentally different types.
def GEPNoWrapFlagsProp : EnumProp<GEPNoWrapFlags> { | ||
let defaultValue = interfaceType#"::none"; | ||
} |
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.
Ay reason for property here, and in operation? Named attributes in operations are defaulted to properties, no need to wrap it.
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 just copied verbatim from the LLVM dialect, i'll incorporate your comments to the next push
Using GEPNoWrapFlags directly resulted in this
/Users/jjasmine/Developer/igalia/clangir/clang/include/clang/CIR/Dialect/IR/CIROps.td:406:5: error: unexpected def type; only defs deriving from TypeConstraint or Attr or Property are allowed
def CIR_PtrStrideOp : CIR_Op<"ptr_stride",[
^
`(` $base `:` qualified(type($base)) `,` $stride `:` qualified(type($stride))(`,` $noWrapFlags^)?`)` | ||
`,` qualified(type($result)) attr-dict |
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 should have been $base, $stride : funstional-type attr-dict
in the first place. We can fix that fist in separate PR.
Then I would suggest ($noWrapFlags^)? $base, $stride : funstional-type attr-dict
.
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.
yeah i can file an issue for that
I dont quite follow, this repo is the incubator yes? |
- Add CIR_I32BitEnum similar to CIR_I32Enum. - Add usage example where we use enums - Use look up table instead of static cast when converting from CIR to LLVM
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.
Need to update the CIR-to-LLVM GEP flag function. Also some formatting nits.
class CIR_I32BitEnum<string name, string summary, list<BitEnumCaseBase> cases> | ||
: I32BitEnum<name, summary, cases> { |
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.
Looking at other dialects, I think this should be:
class CIR_I32BitEnum<string name, string summary, list<BitEnumCaseBase> cases> | |
: I32BitEnum<name, summary, cases> { | |
class CIR_I32BitEnumAttr<string name, string summary, list<BitEnumCaseBase> cases> | |
: I32BitEnumAttr<name, summary, cases> { |
%4 = cir.ptr_stride(%2 : !cir.ptr<i32>, %3 : i32, inbounds), !cir.ptr<i32> | ||
|
||
%4 = cir.ptr_stride(%2 : !cir.ptr<i32>, %3 : i32, inbounds|nuw), !cir.ptr<i32> |
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.
%4 = cir.ptr_stride(%2 : !cir.ptr<i32>, %3 : i32, inbounds), !cir.ptr<i32> | |
%4 = cir.ptr_stride(%2 : !cir.ptr<i32>, %3 : i32, inbounds|nuw), !cir.ptr<i32> | |
%5 = cir.ptr_stride(%2 : !cir.ptr<i32>, %3 : i32, inbounds), !cir.ptr<i32> | |
%6 = cir.ptr_stride(%2 : !cir.ptr<i32>, %3 : i32, inbounds|nuw), !cir.ptr<i32> |
static std::unordered_map<cir::CIR_GEPNoWrapFlags, mlir::LLVM::GEPNoWrapFlags> | ||
mp = { | ||
{cir::CIR_GEPNoWrapFlags::none, mlir::LLVM::GEPNoWrapFlags::none}, | ||
{cir::CIR_GEPNoWrapFlags::inbounds, | ||
mlir::LLVM::GEPNoWrapFlags::inbounds}, | ||
{cir::CIR_GEPNoWrapFlags::inboundsFlag, | ||
mlir::LLVM::GEPNoWrapFlags::inboundsFlag}, | ||
{cir::CIR_GEPNoWrapFlags::nusw, mlir::LLVM::GEPNoWrapFlags::nusw}, | ||
{cir::CIR_GEPNoWrapFlags::nuw, mlir::LLVM::GEPNoWrapFlags::nuw}, | ||
}; | ||
mlir::LLVM::GEPNoWrapFlags x = mlir::LLVM::GEPNoWrapFlags::none; | ||
for (auto [key, _] : mp) | ||
x = x | mp.at(flags & key); | ||
return x; |
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.
Don't use a static
map like this, it introduces shared state.
This should just be a series of if (flags & cir::CIR_GEP...) x |= mlir::LLVM::GEP...;
From the comment on PR review #1844, it seems like we're missing the flags for GEP.
I'm opening the PR to add the flags.
The first commit is just a prototype to gather opinions and reviews to see if I'm heading to the right direction with this.