Skip to content

Commit

Permalink
[flang][hlfir] Array constructor lowering [part 1/4]
Browse files Browse the repository at this point in the history
This is the first and biggest chunk that introduces support for
array constructor to HLFIR.

This patch:
- adds a new ConvertArrayConstructor.cpp that centralizes the
  code dealing with array constructor lowering.
- introduces a framework to lower array constructor according to
  different strategies: A common analysis of the array constructor is
  done, and based on that, a lowering startegy is selected and driven
  through the ac-values of the array constructor. See
  ConvertArrayConstructor.cpp comments for more details.
- implements the first strategy that creates a temporary inlined and
  updates it with inlined code. This strategy can only be used if the
  temporary can be pre-allocated (i.e: the extents and length parameters
  can be pre-computed without evaluating any ac-values), and if all the
  ac-value expressions are scalars.

For the sake of simplicity, characters and derived type will be enabled
once all the strategies are added.

Reviewed By: clementval, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D144102
  • Loading branch information
jeanPerier committed Feb 16, 2023
1 parent 849c440 commit ffde9f1
Show file tree
Hide file tree
Showing 5 changed files with 872 additions and 3 deletions.
46 changes: 46 additions & 0 deletions flang/include/flang/Lower/ConvertArrayConstructor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//===-- ConvertArrayConstructor.h -- Array constructor lowering -*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/
//
//===----------------------------------------------------------------------===//
///
/// Implements the conversion from evaluate::ArrayConstructor to HLFIR.
///
//===----------------------------------------------------------------------===//
#ifndef FORTRAN_LOWER_CONVERTARRAYCONSTRUCTOR_H
#define FORTRAN_LOWER_CONVERTARRAYCONSTRUCTOR_H

#include "flang/Evaluate/type.h"
#include "flang/Optimizer/Builder/HLFIRTools.h"

namespace Fortran::evaluate {
template <typename T>
class ArrayConstructor;
}

namespace Fortran::lower {
class AbstractConverter;
class SymMap;
class StatementContext;

/// Class to lower evaluate::ArrayConstructor<T> to hlfir::EntityWithAttributes.
template <typename T>
class ArrayConstructorBuilder {
public:
static hlfir::EntityWithAttributes
gen(mlir::Location loc, Fortran::lower::AbstractConverter &converter,
const Fortran::evaluate::ArrayConstructor<T> &expr,
Fortran::lower::SymMap &symMap,
Fortran::lower::StatementContext &stmtCtx);
};
using namespace evaluate;
FOR_EACH_SPECIFIC_TYPE(extern template class ArrayConstructorBuilder, )
} // namespace Fortran::lower

#endif // FORTRAN_LOWER_CONVERTARRAYCONSTRUCTOR_H
1 change: 1 addition & 0 deletions flang/lib/Lower/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ add_flang_library(FortranLower
Bridge.cpp
CallInterface.cpp
Coarray.cpp
ConvertArrayConstructor.cpp
ConvertCall.cpp
ConvertConstant.cpp
ConvertExpr.cpp
Expand Down
Loading

0 comments on commit ffde9f1

Please sign in to comment.