[flang-commits] [flang] [flang] Fix the incorrect insertion point for alloca (PR #65999)
via flang-commits
flang-commits at lists.llvm.org
Tue Sep 12 00:30:42 PDT 2023
================
@@ -333,25 +333,30 @@ class FIROpConversion : public mlir::ConvertOpToLLVMPattern<FromOp> {
return rewriter.create<mlir::LLVM::GEPOp>(loc, ty, base, cv);
}
- // Find the LLVMFuncOp in whose entry block the alloca should be inserted.
- // The order to find the LLVMFuncOp is as follows:
- // 1. The parent operation of the current block if it is a LLVMFuncOp.
- // 2. The first ancestor that is a LLVMFuncOp.
- mlir::LLVM::LLVMFuncOp
- getFuncForAllocaInsert(mlir::ConversionPatternRewriter &rewriter) const {
- mlir::Operation *parentOp = rewriter.getInsertionBlock()->getParentOp();
- return mlir::isa<mlir::LLVM::LLVMFuncOp>(parentOp)
- ? mlir::cast<mlir::LLVM::LLVMFuncOp>(parentOp)
- : parentOp->getParentOfType<mlir::LLVM::LLVMFuncOp>();
+ // Find the Block in which the alloca should be inserted.
+ // The order to recursively find the proper block:
+ // 1. An OpenMP Op
+ // 2. A LLVMFuncOp
+ // 3. The first ancestor that is an OpenMP Op or a LLVMFuncOp
+ static mlir::Block *getBlockForAllocaInsert(mlir::Operation *op) {
+ if (auto iface =
+ mlir::dyn_cast<mlir::omp::OutlineableOpenMPOpInterface>(op)) {
+ return iface.getAllocaBlock();
+ } else if (auto llvmFuncOp = mlir::dyn_cast<mlir::LLVM::LLVMFuncOp>(op)) {
+ return &llvmFuncOp.front();
+ } else {
+ return getBlockForAllocaInsert(op->getParentOp());
+ }
----------------
jeanPerier wrote:
small nit about the style flang lowering/codegen uses LLVM coding conventions:
- [no else after return](https://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return)
- [no braces for single line if-else](https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements)
https://github.com/llvm/llvm-project/pull/65999
More information about the flang-commits
mailing list