[llvm-branch-commits] [mlir] edcd83a - [mlir] NFC: Rename index_t to index_type

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Mar 6 05:39:43 PST 2020


Author: Rainer Orth
Date: 2020-03-06T14:36:11+01:00
New Revision: edcd83a669b68a2d371a54dc46e647a2efe97a4f

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

LOG: [mlir] NFC: Rename index_t to index_type

mlir currently fails to build on Solaris:

  /vol/llvm/src/llvm-project/dist/mlir/lib/Conversion/VectorToLoops/ConvertVectorToLoops.cpp:78:20: error: reference to 'index_t' is ambiguous
    IndexHandle zero(index_t(0)), one(index_t(1));
                     ^
  /usr/include/sys/types.h:103:16: note: candidate found by name lookup is 'index_t'
  typedef short           index_t;
                          ^
  /vol/llvm/src/llvm-project/dist/mlir/include/mlir/EDSC/Builders.h:27:8: note: candidate found by name lookup is 'mlir::edsc::index_t'
  struct index_t {
         ^

and many more.

Given that POSIX reserves all identifiers ending in `_t` 2.2.2 The Name Space <https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html>, it seems
quite unwise to use such identifiers in user code, even more so without a distinguished
prefix.

The following patch fixes this by renaming `index_t` to `index_type`.
cases.

Tested on `amd64-pc-solaris2.11` and `sparcv9-sun-solaris2.11`.

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

(cherry picked from commit 002ec79f979b9da9dedafe7ea036e00c90a9fbb7)

Added: 
    

Modified: 
    mlir/docs/EDSC.md
    mlir/include/mlir/EDSC/Builders.h
    mlir/include/mlir/EDSC/Intrinsics.h
    mlir/lib/Conversion/VectorToLoops/ConvertVectorToLoops.cpp
    mlir/lib/EDSC/Builders.cpp
    mlir/lib/EDSC/Helpers.cpp
    mlir/test/EDSC/builder-api-test.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/docs/EDSC.md b/mlir/docs/EDSC.md
index eaaeb6c7009b..0b84d238358e 100644
--- a/mlir/docs/EDSC.md
+++ b/mlir/docs/EDSC.md
@@ -54,11 +54,11 @@ concise and structured loop nests.
               i7(constant_int(7, 32)),
               i13(constant_int(13, 32));
   AffineLoopNestBuilder(&i, lb, ub, 3)([&]{
-      lb * index_t(3) + ub;
-      lb + index_t(3);
+      lb * index_type(3) + ub;
+      lb + index_type(3);
       AffineLoopNestBuilder(&j, lb, ub, 2)([&]{
-          ceilDiv(index_t(31) * floorDiv(i + j * index_t(3), index_t(32)),
-                  index_t(32));
+          ceilDiv(index_type(31) * floorDiv(i + j * index_type(3), index_type(32)),
+                  index_type(32));
           ((f7 + f13) / f7) % f13 - f7 * f13;
           ((i7 + i13) / i7) % i13 - i7 * i13;
       });

diff  --git a/mlir/include/mlir/EDSC/Builders.h b/mlir/include/mlir/EDSC/Builders.h
index 14a4e5a4c9ad..868709446191 100644
--- a/mlir/include/mlir/EDSC/Builders.h
+++ b/mlir/include/mlir/EDSC/Builders.h
@@ -24,8 +24,8 @@ namespace mlir {
 
 namespace edsc {
 
-struct index_t {
-  explicit index_t(int64_t v) : v(v) {}
+struct index_type {
+  explicit index_type(int64_t v) : v(v) {}
   explicit operator int64_t() { return v; }
   int64_t v;
 };
@@ -310,7 +310,7 @@ class ValueHandle : public CapturableHandle {
   /// This implicit constructor is provided to each build an eager Value for a
   /// constant at the current insertion point in the IR. An implicit constructor
   /// allows idiomatic expressions mixing ValueHandle and literals.
-  ValueHandle(index_t cst);
+  ValueHandle(index_type cst);
 
   /// ValueHandle is a value type, use the default copy constructor.
   ValueHandle(const ValueHandle &other) = default;

diff  --git a/mlir/include/mlir/EDSC/Intrinsics.h b/mlir/include/mlir/EDSC/Intrinsics.h
index 4e0cda41620a..66fb90a643b8 100644
--- a/mlir/include/mlir/EDSC/Intrinsics.h
+++ b/mlir/include/mlir/EDSC/Intrinsics.h
@@ -34,7 +34,7 @@ namespace edsc {
 struct IndexHandle : public ValueHandle {
   explicit IndexHandle()
       : ValueHandle(ScopedContext::getBuilder().getIndexType()) {}
-  explicit IndexHandle(index_t v) : ValueHandle(v) {}
+  explicit IndexHandle(index_type v) : ValueHandle(v) {}
   explicit IndexHandle(Value v) : ValueHandle(v) {
     assert(v.getType() == ScopedContext::getBuilder().getIndexType() &&
            "Expected index type");
@@ -96,7 +96,7 @@ class ValueHandleArray {
   ValueHandleArray(ArrayRef<IndexHandle> vals) {
     values.append(vals.begin(), vals.end());
   }
-  ValueHandleArray(ArrayRef<index_t> vals) {
+  ValueHandleArray(ArrayRef<index_type> vals) {
     SmallVector<IndexHandle, 8> tmp(vals.begin(), vals.end());
     values.append(tmp.begin(), tmp.end());
   }

diff  --git a/mlir/lib/Conversion/VectorToLoops/ConvertVectorToLoops.cpp b/mlir/lib/Conversion/VectorToLoops/ConvertVectorToLoops.cpp
index 3ed031b985ae..975397be344a 100644
--- a/mlir/lib/Conversion/VectorToLoops/ConvertVectorToLoops.cpp
+++ b/mlir/lib/Conversion/VectorToLoops/ConvertVectorToLoops.cpp
@@ -75,7 +75,7 @@ static SmallVector<edsc::ValueHandle, 8> clip(TransferOpTy transfer,
   using namespace edsc::op;
   using edsc::intrinsics::select;
 
-  IndexHandle zero(index_t(0)), one(index_t(1));
+  IndexHandle zero(index_type(0)), one(index_type(1));
   SmallVector<edsc::ValueHandle, 8> memRefAccess(transfer.indices());
   SmallVector<edsc::ValueHandle, 8> clippedScalarAccessExprs(
       memRefAccess.size(), edsc::IndexHandle());

diff  --git a/mlir/lib/EDSC/Builders.cpp b/mlir/lib/EDSC/Builders.cpp
index b966003f24fd..868b00b44b95 100644
--- a/mlir/lib/EDSC/Builders.cpp
+++ b/mlir/lib/EDSC/Builders.cpp
@@ -65,7 +65,7 @@ MLIRContext *mlir::edsc::ScopedContext::getContext() {
   return getBuilder().getContext();
 }
 
-mlir::edsc::ValueHandle::ValueHandle(index_t cst) {
+mlir::edsc::ValueHandle::ValueHandle(index_type cst) {
   auto &b = ScopedContext::getBuilder();
   auto loc = ScopedContext::getLocation();
   v = b.create<ConstantIndexOp>(loc, cst.v).getResult();

diff  --git a/mlir/lib/EDSC/Helpers.cpp b/mlir/lib/EDSC/Helpers.cpp
index f24b2073f4dd..a8dfdeab29c5 100644
--- a/mlir/lib/EDSC/Helpers.cpp
+++ b/mlir/lib/EDSC/Helpers.cpp
@@ -24,7 +24,7 @@ static SmallVector<ValueHandle, 8> getMemRefSizes(Value memRef) {
     if (shape[idx] == -1) {
       res.push_back(ValueHandle::create<DimOp>(memRef, idx));
     } else {
-      res.push_back(static_cast<index_t>(shape[idx]));
+      res.push_back(static_cast<index_type>(shape[idx]));
     }
   }
   return res;
@@ -35,7 +35,7 @@ mlir::edsc::MemRefView::MemRefView(Value v) : base(v) {
 
   auto memrefSizeValues = getMemRefSizes(v);
   for (auto &size : memrefSizeValues) {
-    lbs.push_back(static_cast<index_t>(0));
+    lbs.push_back(static_cast<index_type>(0));
     ubs.push_back(size);
     steps.push_back(1);
   }
@@ -45,8 +45,8 @@ mlir::edsc::VectorView::VectorView(Value v) : base(v) {
   auto vectorType = v.getType().cast<VectorType>();
 
   for (auto s : vectorType.getShape()) {
-    lbs.push_back(static_cast<index_t>(0));
-    ubs.push_back(static_cast<index_t>(s));
+    lbs.push_back(static_cast<index_type>(0));
+    ubs.push_back(static_cast<index_type>(s));
     steps.push_back(1);
   }
 }

diff  --git a/mlir/test/EDSC/builder-api-test.cpp b/mlir/test/EDSC/builder-api-test.cpp
index d99118837866..381068b89cbd 100644
--- a/mlir/test/EDSC/builder-api-test.cpp
+++ b/mlir/test/EDSC/builder-api-test.cpp
@@ -67,11 +67,11 @@ TEST_FUNC(builder_dynamic_for_func_args) {
   ValueHandle i7(constant_int(7, 32));
   ValueHandle i13(constant_int(13, 32));
   AffineLoopNestBuilder(&i, lb, ub, 3)([&] {
-    lb *index_t(3) + ub;
-    lb + index_t(3);
+    lb *index_type(3) + ub;
+    lb + index_type(3);
     AffineLoopNestBuilder(&j, lb, ub, 2)([&] {
-      ceilDiv(index_t(31) * floorDiv(i + j * index_t(3), index_t(32)),
-              index_t(32));
+      ceilDiv(index_type(31) * floorDiv(i + j * index_type(3), index_type(32)),
+              index_type(32));
       ((f7 + f13) / f7) % f13 - f7 *f13;
       ((i7 + i13) / i7) % i13 - i7 *i13;
     });
@@ -411,7 +411,7 @@ TEST_FUNC(custom_ops) {
   ValueHandle vh(indexType), vh20(indexType), vh21(indexType);
   OperationHandle ih0, ih2;
   IndexHandle m, n, M(f.getArgument(0)), N(f.getArgument(1));
-  IndexHandle ten(index_t(10)), twenty(index_t(20));
+  IndexHandle ten(index_type(10)), twenty(index_type(20));
   AffineLoopNestBuilder({&m, &n}, {M, N}, {M + ten, N + twenty}, {1, 1})([&]{
     vh = MY_CUSTOM_OP({m, m + n}, {indexType}, {});
     ih0 = MY_CUSTOM_OP_0({m, m + n}, {});


        


More information about the llvm-branch-commits mailing list