@@ -517,6 +517,67 @@ def fir_ZeroOp : fir_OneResultOp<"zero_bits", [NoMemoryEffect]> {
517
517
let assemblyFormat = "type($intype) attr-dict";
518
518
}
519
519
520
+ def fir_OmpTargetAllocMemOp : fir_Op<"omp_target_allocmem",
521
+ [MemoryEffects<[MemAlloc<DefaultResource>]>, AttrSizedOperandSegments]> {
522
+ let summary = "allocate storage on an openmp device for an object of a given type";
523
+
524
+ let description = [{
525
+ Creates a heap memory reference suitable for storing a value of the
526
+ given type, T. The heap refernce returned has type `!fir.heap<T>`.
527
+ The memory object is in an undefined state. `allocmem` operations must
528
+ be paired with `freemem` operations to avoid memory leaks.
529
+
530
+ ```
531
+ %0 = fir.omp_target_allocmem !fir.array<10 x f32>
532
+ ```
533
+ }];
534
+
535
+ let arguments = (ins
536
+ Arg<AnyIntegerType>:$device,
537
+ TypeAttr:$in_type,
538
+ OptionalAttr<StrAttr>:$uniq_name,
539
+ OptionalAttr<StrAttr>:$bindc_name,
540
+ Variadic<AnyIntegerType>:$typeparams,
541
+ Variadic<AnyIntegerType>:$shape
542
+ );
543
+ let results = (outs fir_HeapType);
544
+
545
+ let extraClassDeclaration = [{
546
+ mlir::Type getAllocatedType();
547
+ bool hasLenParams() { return !getTypeparams().empty(); }
548
+ bool hasShapeOperands() { return !getShape().empty(); }
549
+ unsigned numLenParams() { return getTypeparams().size(); }
550
+ operand_range getLenParams() { return getTypeparams(); }
551
+ unsigned numShapeOperands() { return getShape().size(); }
552
+ operand_range getShapeOperands() { return getShape(); }
553
+ static mlir::Type getRefTy(mlir::Type ty);
554
+ }];
555
+ }
556
+
557
+ def fir_OmpTargetFreeMemOp : fir_Op<"omp_target_freemem",
558
+ [MemoryEffects<[MemFree]>]> {
559
+ let summary = "free a heap object";
560
+
561
+ let description = [{
562
+ Deallocates a heap memory reference that was allocated by an `allocmem`.
563
+ The memory object that is deallocated is placed in an undefined state
564
+ after `fir.freemem`. Optimizations may treat the loading of an object
565
+ in the undefined state as undefined behavior. This includes aliasing
566
+ references, such as the result of an `fir.embox`.Add commentMore actions
567
+
568
+ ```
569
+ %21 = fir.omp_target_allocmem !fir.type<ZT(p:i32){field:i32}>
570
+ ...
571
+ fir.omp_target_freemem %21 : !fir.heap<!fir.type<ZT>>
572
+ ```
573
+ }];
574
+
575
+ let arguments = (ins
576
+ Arg<AnyIntegerType, "", [MemFree]>:$device,
577
+ Arg<fir_HeapType, "", [MemFree]>:$heapref
578
+ );
579
+ }
580
+
520
581
//===----------------------------------------------------------------------===//
521
582
// Terminator operations
522
583
//===----------------------------------------------------------------------===//
0 commit comments