[flang-commits] [flang] 5eca6ad - [fir] Use contralized values for indexing box

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Wed Nov 10 06:35:28 PST 2021


Author: Valentin Clement
Date: 2021-11-10T15:35:19+01:00
New Revision: 5eca6ad75274115571a6ded7bd014de534a92067

URL: https://github.com/llvm/llvm-project/commit/5eca6ad75274115571a6ded7bd014de534a92067
DIFF: https://github.com/llvm/llvm-project/commit/5eca6ad75274115571a6ded7bd014de534a92067.diff

LOG: [fir] Use contralized values for indexing box

Add constant to index the different values in a box so that
they can be reused for the codegen part as well.

Reviewed By: awarzynski

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

Added: 
    

Modified: 
    flang/lib/Optimizer/CodeGen/TypeConverter.h

Removed: 
    


################################################################################
diff  --git a/flang/lib/Optimizer/CodeGen/TypeConverter.h b/flang/lib/Optimizer/CodeGen/TypeConverter.h
index 9e3a9261ec37..39e774bdcd7e 100644
--- a/flang/lib/Optimizer/CodeGen/TypeConverter.h
+++ b/flang/lib/Optimizer/CodeGen/TypeConverter.h
@@ -21,6 +21,18 @@
 #include "llvm/ADT/StringMap.h"
 #include "llvm/Support/Debug.h"
 
+// Position of the 
diff erent values in a `fir.box`.
+static constexpr unsigned kAddrPosInBox = 0;
+static constexpr unsigned kElemLenPosInBox = 1;
+static constexpr unsigned kVersionPosInBox = 2;
+static constexpr unsigned kRankPosInBox = 3;
+static constexpr unsigned kTypePosInBox = 4;
+static constexpr unsigned kAttributePosInBox = 5;
+static constexpr unsigned kF18AddendumPosInBox = 6;
+static constexpr unsigned kDimsPosInBox = 7;
+static constexpr unsigned kOptTypePtrPosInBox = 8;
+static constexpr unsigned kOptRowTypePosInBox = 9;
+
 namespace fir {
 
 /// FIR type converter
@@ -107,17 +119,23 @@ class LLVMTypeConverter : public mlir::LLVMTypeConverter {
     else
       dataDescFields.push_back(mlir::LLVM::LLVMPointerType::get(eleTy));
     // elem_len
-    dataDescFields.push_back(getDescFieldTypeModel<1>()(&getContext()));
+    dataDescFields.push_back(
+        getDescFieldTypeModel<kElemLenPosInBox>()(&getContext()));
     // version
-    dataDescFields.push_back(getDescFieldTypeModel<2>()(&getContext()));
+    dataDescFields.push_back(
+        getDescFieldTypeModel<kVersionPosInBox>()(&getContext()));
     // rank
-    dataDescFields.push_back(getDescFieldTypeModel<3>()(&getContext()));
+    dataDescFields.push_back(
+        getDescFieldTypeModel<kRankPosInBox>()(&getContext()));
     // type
-    dataDescFields.push_back(getDescFieldTypeModel<4>()(&getContext()));
+    dataDescFields.push_back(
+        getDescFieldTypeModel<kTypePosInBox>()(&getContext()));
     // attribute
-    dataDescFields.push_back(getDescFieldTypeModel<5>()(&getContext()));
+    dataDescFields.push_back(
+        getDescFieldTypeModel<kAttributePosInBox>()(&getContext()));
     // f18Addendum
-    dataDescFields.push_back(getDescFieldTypeModel<6>()(&getContext()));
+    dataDescFields.push_back(
+        getDescFieldTypeModel<kF18AddendumPosInBox>()(&getContext()));
     // [dims]
     if (rank == unknownRank()) {
       if (auto seqTy = ele.dyn_cast<SequenceType>())
@@ -126,14 +144,15 @@ class LLVMTypeConverter : public mlir::LLVMTypeConverter {
         rank = 0;
     }
     if (rank > 0) {
-      auto rowTy = getDescFieldTypeModel<7>()(&getContext());
+      auto rowTy = getDescFieldTypeModel<kDimsPosInBox>()(&getContext());
       dataDescFields.push_back(mlir::LLVM::LLVMArrayType::get(rowTy, rank));
     }
     // opt-type-ptr: i8* (see fir.tdesc)
     if (requiresExtendedDesc(ele)) {
       dataDescFields.push_back(
-          getExtendedDescFieldTypeModel<8>()(&getContext()));
-      auto rowTy = getExtendedDescFieldTypeModel<9>()(&getContext());
+          getExtendedDescFieldTypeModel<kOptTypePtrPosInBox>()(&getContext()));
+      auto rowTy =
+          getExtendedDescFieldTypeModel<kOptRowTypePosInBox>()(&getContext());
       dataDescFields.push_back(mlir::LLVM::LLVMArrayType::get(rowTy, 1));
       if (auto recTy = fir::unwrapSequenceType(ele).dyn_cast<fir::RecordType>())
         if (recTy.getNumLenParams() > 0) {


        


More information about the flang-commits mailing list