@@ -406,57 +406,66 @@ def CIR_PtrDiffOp : CIR_Op<"ptr_diff", [Pure, SameTypeOperands]> {
406406//===----------------------------------------------------------------------===//
407407// PtrStrideOp
408408//===----------------------------------------------------------------------===//
409+
410+ // These mirror the GEPNoWrapFlags in LLVM IR Dialect.
409411def CIR_GEPNone : I32BitEnumCaseNone<"none">;
410412def CIR_GEPInboundsFlag : I32BitEnumCaseBit<"inboundsFlag", 0, "inbounds_flag">;
411413def CIR_GEPNusw : I32BitEnumCaseBit<"nusw", 1>;
412414def CIR_GEPNuw : I32BitEnumCaseBit<"nuw", 2>;
413- def CIR_GEPInbounds
414- : BitEnumCaseGroup<"inbounds", [CIR_GEPInboundsFlag, CIR_GEPNusw]>;
415-
416- def CIR_GEPNoWrapFlags
417- : CIR_I32BitEnum<"CIR_GEPNoWrapFlags", "::cir::CIR_GEPNoWrapFlags",
418- [CIR_GEPNone, CIR_GEPInboundsFlag, CIR_GEPNusw, CIR_GEPNuw,
419- CIR_GEPInbounds]> {
420- let cppNamespace = "::cir";
415+ def CIR_GEPInbounds : BitEnumCaseGroup<"inbounds", [
416+ CIR_GEPInboundsFlag, CIR_GEPNusw]>;
417+
418+ def CIR_GEPNoWrapFlags : CIR_I32BitEnum<"GEPNoWrapFlags", "no-wrap flags", [
419+ CIR_GEPNone,
420+ CIR_GEPInboundsFlag,
421+ CIR_GEPNusw,
422+ CIR_GEPNuw,
423+ CIR_GEPInbounds
424+ ]> {
421425 let printBitEnumPrimaryGroups = 1;
422426}
423427
424428def CIR_GEPNoWrapFlagsProp : EnumProp<CIR_GEPNoWrapFlags> {
425- let defaultValue = interfaceType# "::none";
429+ let defaultValue = enum.cppType # "::" # " none";
426430}
427431
428432def CIR_PtrStrideOp : CIR_Op<"ptr_stride",[
429433 Pure, AllTypesMatch<["base", "result"]>
430434]> {
431435 let summary = "Pointer access with stride";
432436 let description = [{
433- Given a base pointer as first operand, provides a new pointer after applying
434- a stride (second operand).
435-
436- ```mlir
437- %3 = cir.const 0 : i32
438-
439- %4 = cir.ptr_stride(%2 : !cir.ptr<i32>, %3 : i32), !cir.ptr<i32>
437+ The `cir.ptr_stride` operation computes a new pointer from a base pointer
438+ and an integer stride, similar to a single-index `getelementptr` in LLVM IR.
439+ It moves the pointer by `stride * sizeof(element_type)` bytes.
440440
441- %5 = cir.ptr_stride(%2 : !cir.ptr<i32>, %3 : i32, inbounds), !cir.ptr<i32>
441+ Optional no-wrap flags refine pointer arithmetic semantics, that mirror
442+ LLVM's GEP no-wrap semantics.
442443
443- %6 = cir.ptr_stride(%2 : !cir.ptr<i32>, %3 : i32, inbounds|nuw), !cir.ptr<i32>
444+ Example:
444445
446+ ```mlir
447+ %3 = cir.ptr_stride %1, %2 : (!cir.ptr<i32>, i32) ->!cir.ptr<i32>
448+ %4 = cir.ptr_stride inbounds %1, %2 : (!cir.ptr<i32>, i32) -> !cir.ptr<i32>
449+ %5 = cir.ptr_stride inbounds|nuw %1, %2 : (!cir.ptr<i32>, i32) -> !cir.ptr<i32>
445450 ```
446451 }];
447452
448- let arguments = (ins CIR_PointerType:$base, CIR_AnyFundamentalIntType:$stride,
449- CIR_GEPNoWrapFlagsProp:$noWrapFlags);
453+ let arguments = (ins
454+ CIR_PointerType:$base,
455+ CIR_AnyFundamentalIntType:$stride,
456+ CIR_GEPNoWrapFlagsProp:$noWrapFlags
457+ );
450458
451459 let results = (outs CIR_PointerType:$result);
452460
453461 let assemblyFormat = [{
454- ($noWrapFlags^)? $base`,` $stride `:` functional-type(operands, results) attr-dict
462+ ($noWrapFlags^)? $base`,` $stride `:` functional-type(operands, results)
463+ attr-dict
455464 }];
456465
457466 let extraClassDeclaration = [{
458467 // Get type pointed by the base pointer.
459- mlir::Type getElementTy () {
468+ mlir::Type getElementType () {
460469 return getBase().getType().getPointee();
461470 }
462471 }];
0 commit comments