@@ -79,6 +79,13 @@ class LLVMLoweringInfo {
7979class CIR_Op<string mnemonic, list<Trait> traits = []> :
8080 Op<CIR_Dialect, mnemonic, traits>, LLVMLoweringInfo;
8181
82+ //===----------------------------------------------------------------------===//
83+ // CIR Op Traits
84+ //===----------------------------------------------------------------------===//
85+
86+ def SameFirstOperandAndResultType :
87+ NativeOpTrait<"SameFirstOperandAndResultType">;
88+
8289//===----------------------------------------------------------------------===//
8390// CastOp
8491//===----------------------------------------------------------------------===//
@@ -229,6 +236,40 @@ def CastOp : CIR_Op<"cast",
229236 let hasFolder = 1;
230237}
231238
239+
240+ //===----------------------------------------------------------------------===//
241+ // PtrStrideOp
242+ //===----------------------------------------------------------------------===//
243+
244+ def PtrStrideOp : CIR_Op<"ptr_stride",
245+ [Pure, SameFirstOperandAndResultType]> {
246+ let summary = "Pointer access with stride";
247+ let description = [{
248+ Given a base pointer as first operand, provides a new pointer after applying
249+ a stride (second operand).
250+
251+ ```mlir
252+ %3 = cir.const 0 : i32
253+ %4 = cir.ptr_stride(%2 : !cir.ptr<i32>, %3 : i32), !cir.ptr<i32>
254+ ```
255+ }];
256+
257+ let arguments = (ins CIR_PointerType:$base, PrimitiveInt:$stride);
258+ let results = (outs CIR_PointerType:$result);
259+
260+ let assemblyFormat = [{
261+ `(` $base `:` qualified(type($base)) `,` $stride `:`
262+ qualified(type($stride)) `)` `,` qualified(type($result)) attr-dict
263+ }];
264+
265+ let extraClassDeclaration = [{
266+ // Get type pointed by the base pointer.
267+ mlir::Type getElementTy() {
268+ return mlir::cast<cir::PointerType>(getBase().getType()).getPointee();
269+ }
270+ }];
271+ }
272+
232273//===----------------------------------------------------------------------===//
233274// ConstantOp
234275//===----------------------------------------------------------------------===//
0 commit comments