[flang-commits] [PATCH] D114104: [FIR] Convert fir.allocmem and fir.freemem operations to calls to malloc and free, respectively

Kiran Chandramohan via Phabricator via flang-commits flang-commits at lists.llvm.org
Tue Dec 7 15:12:41 PST 2021


kiranchandramohan added a comment.

LGTM.

Thanks @AlexisPerry for this patch. I have some info and a request for a test.

Apologies for hijacking the patch with all the discussion about todo vs notify.



================
Comment at: flang/lib/Optimizer/CodeGen/CodeGen.cpp:41
 
+static mlir::Type getVoidPtrType(mlir::MLIRContext *context) {
+  return mlir::LLVM::LLVMPointerType::get(mlir::IntegerType::get(context, 8));
----------------
I just submitted a patch with this function. So you will have to remove on rebase.


================
Comment at: flang/lib/Optimizer/CodeGen/CodeGen.cpp:906
+static mlir::Value
+computeDerivedTypeSize(mlir::Location loc, mlir::Type ptrTy, mlir::Type idxTy,
+                       mlir::ConversionPatternRewriter &rewriter) {
----------------
This is already in.


================
Comment at: flang/lib/Optimizer/CodeGen/CodeGen.cpp:936
+    for (mlir::Value opnd : adaptor.getOperands())
+      size = rewriter.create<mlir::LLVM::MulOp>(
+          loc, ity, size, integerCast(loc, rewriter, ity, opnd));
----------------
I did not see an llvm.mul op in a test. Did we miss a case?

Can we try the following?
```
subroutine ss2(M,N)
  integer :: M, N
  real :: aa(M,N)
end
```

```
  func @_QPss2(%arg0: !fir.ref<i32>, %arg1: !fir.ref<i32>) {
    %0 = fir.load %arg0 : !fir.ref<i32>
    %1 = fir.convert %0 : (i32) -> index
    %2 = fir.load %arg1 : !fir.ref<i32>
    %3 = fir.convert %2 : (i32) -> index
    %4 = fir.alloca !fir.array<?x?xf32>, %1, %3 {bindc_name = "aa", uniq_name = "_QFss2Eaa"}
    return
  }
```

or 

```
subroutine sb(y,n)
  integer :: y, n
  character(len=y) :: s(n)
end subroutine
```
```
func @_QPsb(%arg0: !fir.ref<i32>, %arg1: !fir.ref<i32>) {
  %0 = fir.load %arg0 : !fir.ref<i32>
  %3 = fir.load %arg1 : !fir.ref<i32>
  %4 = fir.convert %3 : (i32) -> index
  %6 = fir.alloca !fir.array<?x!fir.char<1,?>>(%0 : i32), %4 {bindc_name = "s", uniq_name = "_QFsbEs"}
  return
}
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114104/new/

https://reviews.llvm.org/D114104



More information about the flang-commits mailing list