Skip to content

Commit

Permalink
[flang] Lower more array character cases
Browse files Browse the repository at this point in the history
This patch adds more lowering and tests for character array assignment/copy.

This patch is part of the upstreaming effort from fir-dev branch.

Depends on D121300

Reviewed By: PeteSteinfeld, schweitz

Differential Revision: https://reviews.llvm.org/D121301

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
  • Loading branch information
3 people committed Mar 9, 2022
1 parent f52b5a8 commit c3a7627
Show file tree
Hide file tree
Showing 5 changed files with 702 additions and 48 deletions.
10 changes: 10 additions & 0 deletions flang/include/flang/Lower/ConvertExpr.h
Expand Up @@ -108,6 +108,16 @@ fir::MutableBoxValue createMutableBox(mlir::Location loc,
AbstractConverter &converter,
const SomeExpr &expr, SymMap &symMap);

/// Create a fir::BoxValue describing the value of \p expr.
/// If \p expr is a variable without vector subscripts, the fir::BoxValue
/// described the variable storage. Otherwise, the created fir::BoxValue
/// describes a temporary storage containing \p expr evaluation, and clean-up
/// for the temporary is added to the provided StatementContext \p stmtCtx.
fir::ExtendedValue createBoxValue(mlir::Location loc,
AbstractConverter &converter,
const SomeExpr &expr, SymMap &symMap,
StatementContext &stmtCtx);

/// Lower an array assignment expression.
///
/// 1. Evaluate the lhs to determine the rank and how to form the ArrayLoad
Expand Down
33 changes: 33 additions & 0 deletions flang/include/flang/Lower/Mangler.h
Expand Up @@ -13,6 +13,7 @@
#ifndef FORTRAN_LOWER_MANGLER_H
#define FORTRAN_LOWER_MANGLER_H

#include "flang/Evaluate/expression.h"
#include "mlir/IR/BuiltinTypes.h"
#include "llvm/ADT/StringRef.h"
#include <string>
Expand Down Expand Up @@ -58,6 +59,38 @@ std::string mangleName(const semantics::DerivedTypeSpec &);
/// Recover the bare name of the original symbol from an internal name.
std::string demangleName(llvm::StringRef name);

std::string
mangleArrayLiteral(const uint8_t *addr, size_t size,
const Fortran::evaluate::ConstantSubscripts &shape,
Fortran::common::TypeCategory cat, int kind = 0,
Fortran::common::ConstantSubscript charLen = -1);

template <Fortran::common::TypeCategory TC, int KIND>
std::string mangleArrayLiteral(
const Fortran::evaluate::Constant<Fortran::evaluate::Type<TC, KIND>> &x) {
return mangleArrayLiteral(
reinterpret_cast<const uint8_t *>(x.values().data()),
x.values().size() * sizeof(x.values()[0]), x.shape(), TC, KIND);
}

template <int KIND>
std::string
mangleArrayLiteral(const Fortran::evaluate::Constant<Fortran::evaluate::Type<
Fortran::common::TypeCategory::Character, KIND>> &x) {
return mangleArrayLiteral(
reinterpret_cast<const uint8_t *>(x.values().data()),
x.values().size() * sizeof(x.values()[0]), x.shape(),
Fortran::common::TypeCategory::Character, KIND, x.LEN());
}

inline std::string mangleArrayLiteral(
const Fortran::evaluate::Constant<Fortran::evaluate::SomeDerived> &x) {
return mangleArrayLiteral(
reinterpret_cast<const uint8_t *>(x.values().data()),
x.values().size() * sizeof(x.values()[0]), x.shape(),
Fortran::common::TypeCategory::Derived);
}

} // namespace lower::mangle
} // namespace Fortran

Expand Down

0 comments on commit c3a7627

Please sign in to comment.