@@ -401,57 +401,66 @@ def CIR_PtrDiffOp : CIR_Op<"ptr_diff", [Pure, SameTypeOperands]> {
401401//===----------------------------------------------------------------------===//
402402// PtrStrideOp
403403//===----------------------------------------------------------------------===//
404+
405+ // These mirror the GEPNoWrapFlags in LLVM IR Dialect.
404406def CIR_GEPNone : I32BitEnumCaseNone<"none">;
405407def CIR_GEPInboundsFlag : I32BitEnumCaseBit<"inboundsFlag", 0, "inbounds_flag">;
406408def CIR_GEPNusw : I32BitEnumCaseBit<"nusw", 1>;
407409def CIR_GEPNuw : I32BitEnumCaseBit<"nuw", 2>;
408- def CIR_GEPInbounds
409- : BitEnumCaseGroup<"inbounds", [CIR_GEPInboundsFlag, CIR_GEPNusw]>;
410-
411- def CIR_GEPNoWrapFlags
412- : CIR_I32BitEnum<"CIR_GEPNoWrapFlags", "::cir::CIR_GEPNoWrapFlags",
413- [CIR_GEPNone, CIR_GEPInboundsFlag, CIR_GEPNusw, CIR_GEPNuw,
414- CIR_GEPInbounds]> {
415- let cppNamespace = "::cir";
410+ def CIR_GEPInbounds : BitEnumCaseGroup<"inbounds", [
411+ CIR_GEPInboundsFlag, CIR_GEPNusw]>;
412+
413+ def CIR_GEPNoWrapFlags : CIR_I32BitEnum<"GEPNoWrapFlags", "no-wrap flags", [
414+ CIR_GEPNone,
415+ CIR_GEPInboundsFlag,
416+ CIR_GEPNusw,
417+ CIR_GEPNuw,
418+ CIR_GEPInbounds
419+ ]> {
416420 let printBitEnumPrimaryGroups = 1;
417421}
418422
419423def CIR_GEPNoWrapFlagsProp : EnumProp<CIR_GEPNoWrapFlags> {
420- let defaultValue = interfaceType# "::none";
424+ let defaultValue = enum.cppType # "::" # " none";
421425}
422426
423427def CIR_PtrStrideOp : CIR_Op<"ptr_stride",[
424428 Pure, AllTypesMatch<["base", "result"]>
425429]> {
426430 let summary = "Pointer access with stride";
427431 let description = [{
428- Given a base pointer as first operand, provides a new pointer after applying
429- a stride (second operand).
430-
431- ```mlir
432- %3 = cir.const 0 : i32
433-
434- %4 = cir.ptr_stride(%2 : !cir.ptr<i32>, %3 : i32), !cir.ptr<i32>
432+ The `cir.ptr_stride` operation computes a new pointer from a base pointer
433+ and an integer stride, similar to a single-index `getelementptr` in LLVM IR.
434+ It moves the pointer by `stride * sizeof(element_type)` bytes.
435435
436- %5 = cir.ptr_stride(%2 : !cir.ptr<i32>, %3 : i32, inbounds), !cir.ptr<i32>
436+ Optional no-wrap flags refine pointer arithmetic semantics, that mirror
437+ LLVM's GEP no-wrap semantics.
437438
438- %6 = cir.ptr_stride(%2 : !cir.ptr<i32>, %3 : i32, inbounds|nuw), !cir.ptr<i32>
439+ Example:
439440
441+ ```mlir
442+ %3 = cir.ptr_stride %1, %2 : (!cir.ptr<i32>, i32) ->!cir.ptr<i32>
443+ %4 = cir.ptr_stride inbounds %1, %2 : (!cir.ptr<i32>, i32) -> !cir.ptr<i32>
444+ %5 = cir.ptr_stride inbounds|nuw %1, %2 : (!cir.ptr<i32>, i32) -> !cir.ptr<i32>
440445 ```
441446 }];
442447
443- let arguments = (ins CIR_PointerType:$base, CIR_AnyFundamentalIntType:$stride,
444- CIR_GEPNoWrapFlagsProp:$noWrapFlags);
448+ let arguments = (ins
449+ CIR_PointerType:$base,
450+ CIR_AnyFundamentalIntType:$stride,
451+ CIR_GEPNoWrapFlagsProp:$noWrapFlags
452+ );
445453
446454 let results = (outs CIR_PointerType:$result);
447455
448456 let assemblyFormat = [{
449- ($noWrapFlags^)? $base`,` $stride `:` functional-type(operands, results) attr-dict
457+ ($noWrapFlags^)? $base`,` $stride `:` functional-type(operands, results)
458+ attr-dict
450459 }];
451460
452461 let extraClassDeclaration = [{
453462 // Get type pointed by the base pointer.
454- mlir::Type getElementTy () {
463+ mlir::Type getElementType () {
455464 return getBase().getType().getPointee();
456465 }
457466 }];
0 commit comments