[flang] answer some comments

Original-commit: flang-compiler/f18@8161f77f60
Tree-same-pre-rewrite: false
This commit is contained in:
Jean Perier 2019-02-22 09:06:44 -08:00 committed by GitHub
parent 9b1d928990
commit 6fbbcfcb49
4 changed files with 34 additions and 36 deletions

View File

@ -162,11 +162,9 @@ ComplexPart FoldOperation(FoldingContext &context, ComplexPart &&complexPart) {
FoldOperation(context, std::move(complex)), complexPart.part()};
}
namespace intrinsicHelper {
// helpers to fold intrinsic function references
// Define callable types used in a common utility that
// takes care of array and cast/conversion aspects for elemental intrinsics
template<typename TR, typename... TArgs>
using ScalarFunc = std::function<Scalar<TR>(const Scalar<TArgs> &...)>;
template<typename TR, typename... TArgs>
@ -191,7 +189,7 @@ static inline Expr<TR> FoldElementalIntrinsicHelper(FoldingContext &context,
return Expr<TR>{Constant<TR>{func(*std::get<I>(scalars)...)}};
}
}
// TODO: handle arrays when Constant<T> can represent them
// TODO: handle Constant<T> that hold arrays
return Expr<TR>{std::move(funcRef)};
}
@ -207,12 +205,10 @@ static Expr<TR> FoldElementalIntrinsic(FoldingContext &context,
return FoldElementalIntrinsicHelper<ScalarFuncWithContext, TR, TA...>(
context, std::move(funcRef), func, std::index_sequence_for<TA...>{});
}
}
template<int KIND>
Expr<Type<TypeCategory::Integer, KIND>> FoldOperation(FoldingContext &context,
FunctionRef<Type<TypeCategory::Integer, KIND>> &&funcRef) {
using namespace intrinsicHelper;
using T = Type<TypeCategory::Integer, KIND>;
for (std::optional<ActualArgument> &arg : funcRef.arguments()) {
if (arg.has_value()) {
@ -238,15 +234,13 @@ Expr<Type<TypeCategory::Integer, KIND>> FoldOperation(FoldingContext &context,
common::die("len() result not SubscriptInteger");
}
} else if (name == "iand") {
if (auto *x{std::get_if<BOZLiteralConstant>(
&funcRef.arguments()[0]->value->u)}) {
*funcRef.arguments()[0]->value =
Fold(context, ConvertToType<T>(std::move(*x)));
}
if (auto *x{std::get_if<BOZLiteralConstant>(
&funcRef.arguments()[1]->value->u)}) {
*funcRef.arguments()[1]->value =
Fold(context, ConvertToType<T>(std::move(*x)));
// TODO change intrinsic.cc so that it already has handled BOZ conversions
for (int i{0}; i <= 1; ++i) {
if (auto *x{std::get_if<BOZLiteralConstant>(
&funcRef.arguments()[i]->value->u)}) {
*funcRef.arguments()[i]->value =
Fold(context, ConvertToType<T>(std::move(*x)));
}
}
return FoldElementalIntrinsic<T, T, T>(
context, std::move(funcRef), ScalarFunc<T, T, T>(&Scalar<T>::IAND));
@ -274,7 +268,6 @@ Expr<Type<TypeCategory::Integer, KIND>> FoldOperation(FoldingContext &context,
template<int KIND>
Expr<Type<TypeCategory::Real, KIND>> FoldOperation(FoldingContext &context,
FunctionRef<Type<TypeCategory::Real, KIND>> &&funcRef) {
using namespace intrinsicHelper;
using T = Type<TypeCategory::Real, KIND>;
for (std::optional<ActualArgument> &arg : funcRef.arguments()) {
if (arg.has_value()) {
@ -354,7 +347,6 @@ Expr<Type<TypeCategory::Real, KIND>> FoldOperation(FoldingContext &context,
template<int KIND>
Expr<Type<TypeCategory::Complex, KIND>> FoldOperation(FoldingContext &context,
FunctionRef<Type<TypeCategory::Complex, KIND>> &&funcRef) {
using namespace intrinsicHelper;
using T = Type<TypeCategory::Complex, KIND>;
for (std::optional<ActualArgument> &arg : funcRef.arguments()) {
if (arg.has_value()) {
@ -415,7 +407,6 @@ Expr<Type<TypeCategory::Complex, KIND>> FoldOperation(FoldingContext &context,
template<int KIND>
Expr<Type<TypeCategory::Logical, KIND>> FoldOperation(FoldingContext &context,
FunctionRef<Type<TypeCategory::Logical, KIND>> &&funcRef) {
using namespace intrinsicHelper;
using T = Type<TypeCategory::Logical, KIND>;
for (std::optional<ActualArgument> &arg : funcRef.arguments()) {
if (arg.has_value()) {

View File

@ -152,16 +152,13 @@ template<int KIND> struct HostTypeHelper<Type<TypeCategory::Complex, KIND>> {
std::complex<HostType<RealT>>, UnsupportedType>;
};
template<int KIND> struct HostTypeHelper<Type<TypeCategory::Character, KIND>> {
template<int KIND> struct HostTypeHelper<Type<TypeCategory::Logical, KIND>> {
using Type = std::conditional_t<KIND <= 8, std::uint8_t, UnsupportedType>;
};
template<> struct HostTypeHelper<Type<TypeCategory::Character, 1>> {
using Type = std::string;
};
template<> struct HostTypeHelper<Type<TypeCategory::Character, 2>> {
using Type = std::u16string;
template<int KIND> struct HostTypeHelper<Type<TypeCategory::Character, KIND>> {
using Type =
Scalar<typename Fortran::evaluate::Type<TypeCategory::Character, KIND>>;
};
// Type mapping from host types to F18 types. This need to be placed after all
@ -195,7 +192,7 @@ template<TypeCategory cat, int KIND> struct NextBiggerReal {
using Type = void;
};
template<TypeCategory cat> struct NextBiggerReal<cat, 2> {
using Type = Fortran::evaluate::Type<cat, 3>;
using Type = Fortran::evaluate::Type<cat, 4>;
};
template<TypeCategory cat> struct NextBiggerReal<cat, 3> {
using Type = Fortran::evaluate::Type<cat, 4>;
@ -204,6 +201,14 @@ template<TypeCategory cat> struct NextBiggerReal<cat, 4> {
using Type = Fortran::evaluate::Type<cat, 8>;
};
template<TypeCategory cat> struct NextBiggerReal<cat, 8> {
using Type = Fortran::evaluate::Type<cat, 10>;
};
template<TypeCategory cat> struct NextBiggerReal<cat, 10> {
using Type = Fortran::evaluate::Type<cat, 16>;
};
template<int KIND>
struct BiggerOrSameHostTypeHelper<Type<TypeCategory::Real, KIND>> {
using T = Fortran::evaluate::Type<TypeCategory::Real, KIND>;

View File

@ -1,4 +1,4 @@
// Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved.
// Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -32,14 +32,14 @@
#include <vector>
namespace Fortran::evaluate {
class FoldingContext; // forward declare
class FoldingContext;
namespace rte {
using TypeCode = unsigned char;
template<typename TR, typename... TA> using FuncPointer = TR (*)(TA...);
enum PassBy { Ref, Val };
enum class PassBy { Ref, Val };
template<typename TA, PassBy Pass = PassBy::Ref> struct ArgumentInfo {
using Type = TA;
static constexpr PassBy pass{Pass};
@ -98,6 +98,8 @@ struct HostRteProcedureSymbol : RteProcedureSymbol {
template<typename HostTR, typename... HostTA>
HostRteProcedureSymbol(const std::string &name,
FuncPointer<HostTR, HostTA...> func, bool isElemental = false);
HostRteProcedureSymbol(const RteProcedureSymbol &rteProc, const void *handle)
: RteProcedureSymbol{rteProc}, handle{handle} {}
const void *handle;
};
@ -112,7 +114,9 @@ struct HostRte {
const std::string name{sym.name};
procedures.insert(std::make_pair(name, std::move(sym)));
}
bool HasEquivalentProcedure(const RteProcedureSymbol &sym) const;
HostRte() { DefaultInit(); }
~HostRte();
void DefaultInit(); // load functions from <cmath> and <complex>
void LoadTargetRteLibrary(const TargetRteLibrary &lib); // TODO
template<template<typename> typename ConstantContainer, typename TR,
@ -122,7 +126,7 @@ struct HostRte {
// some data structure of HostRteProcedureSymbol
std::multimap<std::string, const HostRteProcedureSymbol> procedures;
std::map<std::string, void *>
dynamicallyLoadedLibraries; // keep the handles for dlcose
dynamicallyLoadedLibraries; // keep the handles for dlclose
};
}

View File

@ -1,4 +1,4 @@
// Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved.
// Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -25,7 +25,7 @@
#include "host.h"
#include "rte-interface.h"
#include "type.h"
#include "../../lib/common/template.h"
#include "../common/template.h"
#include <cfenv>
#include <tuple>
@ -33,11 +33,9 @@
namespace Fortran::evaluate::rte {
// Defines meaningful types for the runtime
class Void {};
class Descriptor {};
using RteTypes = common::CombineTuples<std::tuple<Void, Descriptor>,
evaluate::AllIntrinsicTypes>;
// Define meaningful types for the runtime
// TODO: add the support for void and descriptor
using RteTypes = evaluate::AllIntrinsicTypes;
template<typename T, typename... TT> struct IndexInTupleHelper {};
template<typename T, typename... TT>