1 //===-- CGOps.cpp -- FIR codegen operations -------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "CGOps.h"
14 #include "flang/Optimizer/Dialect/FIRDialect.h"
15 #include "flang/Optimizer/Dialect/FIROps.h"
16 #include "flang/Optimizer/Dialect/FIRType.h"
17 
18 /// FIR codegen dialect constructor.
FIRCodeGenDialect(mlir::MLIRContext * ctx)19 fir::FIRCodeGenDialect::FIRCodeGenDialect(mlir::MLIRContext *ctx)
20     : mlir::Dialect("fircg", ctx, mlir::TypeID::get<FIRCodeGenDialect>()) {
21   addOperations<
22 #define GET_OP_LIST
23 #include "flang/Optimizer/CodeGen/CGOps.cpp.inc"
24       >();
25 }
26 
27 // anchor the class vtable to this compilation unit
~FIRCodeGenDialect()28 fir::FIRCodeGenDialect::~FIRCodeGenDialect() {
29   // do nothing
30 }
31 
32 #define GET_OP_CLASSES
33 #include "flang/Optimizer/CodeGen/CGOps.cpp.inc"
34 
getOutRank()35 unsigned fir::cg::XEmboxOp::getOutRank() {
36   if (slice().empty())
37     return getRank();
38   auto outRank = fir::SliceOp::getOutputRank(slice());
39   assert(outRank >= 1);
40   return outRank;
41 }
42 
getOutRank()43 unsigned fir::cg::XReboxOp::getOutRank() {
44   if (auto seqTy =
45           fir::dyn_cast_ptrOrBoxEleTy(getType()).dyn_cast<fir::SequenceType>())
46     return seqTy.getDimension();
47   return 0;
48 }
49 
getRank()50 unsigned fir::cg::XReboxOp::getRank() {
51   if (auto seqTy = fir::dyn_cast_ptrOrBoxEleTy(box().getType())
52                        .dyn_cast<fir::SequenceType>())
53     return seqTy.getDimension();
54   return 0;
55 }
56 
getRank()57 unsigned fir::cg::XArrayCoorOp::getRank() {
58   auto memrefTy = memref().getType();
59   if (memrefTy.isa<fir::BoxType>())
60     if (auto seqty =
61             fir::dyn_cast_ptrOrBoxEleTy(memrefTy).dyn_cast<fir::SequenceType>())
62       return seqty.getDimension();
63   return shape().size();
64 }
65