[PATCH] D114557: [fir] Add base for runtime builder unittests

Diana Picus via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 25 05:38:55 PST 2021


rovka added inline comments.


================
Comment at: flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h:62
+template <>
+constexpr TypeBuilderFunc getModel<short int>() {
+  return [](mlir::MLIRContext *context) -> mlir::Type {
----------------
(moving the discussion here from [[ https://reviews.llvm.org/D114460 | D114460 ]])
What I had in mind was either:
Option 1 - SFINAE:

```
template <typename T>
static constexpr typenane std::enable_if_t<std::is_integral_v<T>, TypeBuilderFunc> getModel() {
  return [](mlir::MLIRContext *context) -> mlir::Type {
    return mlir::IntegerType::get(context, 8 * sizeof(T));
  };
}
// [...] lots of similar templates for is_floating_point, is_pointer etc etc
```
or Option 2 - single template (probably easier to follow and maintain):
template <typename T>
static constexpr TypeBuilderFunc getModel() {
  return [](mlir::MLIRContext *context) -> mlir::Type {
     if constexpr (std::is_integral_v<T>) {
        return mlir::IntegerType::get(context, 8 * sizeof(T));
     } else // [...] branches for std::is_floating_point, is_pointer etc
  };
}


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114557/new/

https://reviews.llvm.org/D114557



More information about the llvm-commits mailing list