Skip to content

Commit

Permalink
[fir] Add fir.embox conversion
Browse files Browse the repository at this point in the history
Convert a `fir.embox` operation to LLVM IR dialect.
A `fir.embox` is converted to a sequence of operation that
create, allocate if needed, and populate a descriptor.

Current limitiation: alignment is set by default but should be retrieved in the specific target.

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

Reviewed By: kiranchandramohan, awarzynski

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
  • Loading branch information
3 people committed Nov 18, 2021
1 parent 9cef7c1 commit af6ee58
Show file tree
Hide file tree
Showing 5 changed files with 611 additions and 5 deletions.
2 changes: 2 additions & 0 deletions flang/include/flang/Optimizer/Dialect/FIRTypes.td
Expand Up @@ -317,6 +317,8 @@ def fir_RecordType : FIR_Type<"Record", "type"> {

void finalize(llvm::ArrayRef<TypePair> lenPList,
llvm::ArrayRef<TypePair> typeList);

std::string getLoweredName() const;

detail::RecordTypeStorage const *uniqueKey() const;
}];
Expand Down
90 changes: 90 additions & 0 deletions flang/include/flang/Optimizer/Support/TypeCode.h
@@ -0,0 +1,90 @@
//===-- Optimizer/Support/TypeCode.h ----------------------------*- 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/
//
//===----------------------------------------------------------------------===//

#ifndef FORTRAN_OPTIMIZER_SUPPORT_TYPECODE_H
#define FORTRAN_OPTIMIZER_SUPPORT_TYPECODE_H

#include "flang/ISO_Fortran_binding.h"
#include "llvm/Support/ErrorHandling.h"

namespace fir {

//===----------------------------------------------------------------------===//
// Translations of category and bitwidths to the type codes defined in flang's
// ISO_Fortran_binding.h.
//===----------------------------------------------------------------------===//

inline int characterBitsToTypeCode(unsigned bitwidth) {
// clang-format off
switch (bitwidth) {
case 8: return CFI_type_char;
case 16: return CFI_type_char16_t;
case 32: return CFI_type_char32_t;
default: llvm_unreachable("unsupported character size");
}
// clang-format on
}

inline int complexBitsToTypeCode(unsigned bitwidth) {
// clang-format off
switch (bitwidth) {
case 32: return CFI_type_float_Complex;
case 64: return CFI_type_double_Complex;
case 80:
case 128: return CFI_type_long_double_Complex;
default: llvm_unreachable("unsupported complex size");
}
// clang-format on
}

inline int integerBitsToTypeCode(unsigned bitwidth) {
// clang-format off
switch (bitwidth) {
case 8: return CFI_type_int8_t;
case 16: return CFI_type_int16_t;
case 32: return CFI_type_int32_t;
case 64: return CFI_type_int64_t;
case 128: return CFI_type_int128_t;
default: llvm_unreachable("unsupported integer size");
}
// clang-format on
}

inline int logicalBitsToTypeCode(unsigned bitwidth) {
// clang-format off
switch (bitwidth) {
case 8: return CFI_type_Bool;
case 16: return CFI_type_int_least16_t;
case 32: return CFI_type_int_least32_t;
case 64: return CFI_type_int_least64_t;
default: llvm_unreachable("unsupported logical size");
}
// clang-format on
}

inline int realBitsToTypeCode(unsigned bitwidth) {
// clang-format off
switch (bitwidth) {
case 32: return CFI_type_float;
case 64: return CFI_type_double;
case 80:
case 128: return CFI_type_long_double;
default: llvm_unreachable("unsupported real size");
}
// clang-format on
}

static constexpr int derivedToTypeCode() { return CFI_type_struct; }

} // namespace fir

#endif // FORTRAN_OPTIMIZER_SUPPORT_TYPECODE_H

0 comments on commit af6ee58

Please sign in to comment.