[Mlir-commits] [mlir] beb889c - Make array pointers in the CAPI const

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Nov 19 11:57:19 PST 2020


Author: George
Date: 2020-11-19T11:56:29-08:00
New Revision: beb889c1ffe68aee8d42c0ddbcd85d021963fb62

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

LOG: Make array pointers in the CAPI const

These pointers do not need to be mutable. This has an affect that generated function signatures in the Swift bindings now use `UnsafePointer` instead of `UnsafeMutablePointer`.

Reviewed By: ftynse, mehdi_amini

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

Added: 
    

Modified: 
    mlir/include/mlir-c/IR.h
    mlir/include/mlir-c/StandardAttributes.h
    mlir/include/mlir-c/StandardTypes.h
    mlir/lib/CAPI/IR/IR.cpp
    mlir/lib/CAPI/IR/StandardAttributes.cpp
    mlir/lib/CAPI/IR/StandardTypes.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir-c/IR.h b/mlir/include/mlir-c/IR.h
index 78924d9ae2c5..6c9394c38b17 100644
--- a/mlir/include/mlir-c/IR.h
+++ b/mlir/include/mlir-c/IR.h
@@ -224,19 +224,19 @@ MLIR_CAPI_EXPORTED MlirOperationState mlirOperationStateGet(const char *name,
 /// Adds a list of components to the operation state.
 MLIR_CAPI_EXPORTED void mlirOperationStateAddResults(MlirOperationState *state,
                                                      intptr_t n,
-                                                     MlirType *results);
+                                                     MlirType const *results);
 MLIR_CAPI_EXPORTED void mlirOperationStateAddOperands(MlirOperationState *state,
                                                       intptr_t n,
-                                                      MlirValue *operands);
+                                                      MlirValue const *operands);
 MLIR_CAPI_EXPORTED void
 mlirOperationStateAddOwnedRegions(MlirOperationState *state, intptr_t n,
-                                  MlirRegion *regions);
+                                  MlirRegion const *regions);
 MLIR_CAPI_EXPORTED void
 mlirOperationStateAddSuccessors(MlirOperationState *state, intptr_t n,
-                                MlirBlock *successors);
+                                MlirBlock const *successors);
 MLIR_CAPI_EXPORTED void
 mlirOperationStateAddAttributes(MlirOperationState *state, intptr_t n,
-                                MlirNamedAttribute *attributes);
+                                MlirNamedAttribute const *attributes);
 
 //===----------------------------------------------------------------------===//
 // Op Printing flags API.
@@ -425,7 +425,7 @@ MLIR_CAPI_EXPORTED void mlirRegionInsertOwnedBlockBefore(MlirRegion region,
 
 /** Creates a new empty block with the given argument types and transfers
  * ownership to the caller. */
-MLIR_CAPI_EXPORTED MlirBlock mlirBlockCreate(intptr_t nArgs, MlirType *args);
+MLIR_CAPI_EXPORTED MlirBlock mlirBlockCreate(intptr_t nArgs, MlirType const *args);
 
 /// Takes a block owned by the caller and destroys it.
 MLIR_CAPI_EXPORTED void mlirBlockDestroy(MlirBlock block);

diff  --git a/mlir/include/mlir-c/StandardAttributes.h b/mlir/include/mlir-c/StandardAttributes.h
index 161722e03914..be858bd19433 100644
--- a/mlir/include/mlir-c/StandardAttributes.h
+++ b/mlir/include/mlir-c/StandardAttributes.h
@@ -47,7 +47,7 @@ MLIR_CAPI_EXPORTED int mlirAttributeIsAArray(MlirAttribute attr);
  * context. */
 MLIR_CAPI_EXPORTED MlirAttribute mlirArrayAttrGet(MlirContext ctx,
                                                   intptr_t numElements,
-                                                  MlirAttribute *elements);
+                                                  MlirAttribute const *elements);
 
 /// Returns the number of elements stored in the given array attribute.
 MLIR_CAPI_EXPORTED intptr_t mlirArrayAttrGetNumElements(MlirAttribute attr);
@@ -66,7 +66,7 @@ MLIR_CAPI_EXPORTED int mlirAttributeIsADictionary(MlirAttribute attr);
 /** Creates a dictionary attribute containing the given list of elements in the
  * provided context. */
 MLIR_CAPI_EXPORTED MlirAttribute mlirDictionaryAttrGet(
-    MlirContext ctx, intptr_t numElements, MlirNamedAttribute *elements);
+    MlirContext ctx, intptr_t numElements, MlirNamedAttribute const *elements);
 
 /// Returns the number of attributes contained in a dictionary attribute.
 MLIR_CAPI_EXPORTED intptr_t
@@ -207,7 +207,7 @@ MLIR_CAPI_EXPORTED int mlirAttributeIsASymbolRef(MlirAttribute attr);
  * null-terminated and its length must be specified. */
 MLIR_CAPI_EXPORTED MlirAttribute
 mlirSymbolRefAttrGet(MlirContext ctx, intptr_t length, const char *symbol,
-                     intptr_t numReferences, MlirAttribute *references);
+                     intptr_t numReferences, MlirAttribute const *references);
 
 /** Returns the string reference to the root referenced symbol. The data remains
  * live as long as the context in which the attribute lives. */

diff  --git a/mlir/include/mlir-c/StandardTypes.h b/mlir/include/mlir-c/StandardTypes.h
index ff53910cb154..7b51ad8d6a77 100644
--- a/mlir/include/mlir-c/StandardTypes.h
+++ b/mlir/include/mlir-c/StandardTypes.h
@@ -225,7 +225,7 @@ MLIR_CAPI_EXPORTED int mlirTypeIsAUnrankedMemRef(MlirType type);
 MLIR_CAPI_EXPORTED MlirType mlirMemRefTypeGet(MlirType elementType,
                                               intptr_t rank, int64_t *shape,
                                               intptr_t numMaps,
-                                              MlirAttribute *affineMaps,
+                                              MlirAttribute const *affineMaps,
                                               unsigned memorySpace);
 
 /** Creates a MemRef type with the given rank, shape, memory space and element
@@ -277,7 +277,7 @@ MLIR_CAPI_EXPORTED int mlirTypeIsATuple(MlirType type);
  * type is owned by the context. */
 MLIR_CAPI_EXPORTED MlirType mlirTupleTypeGet(MlirContext ctx,
                                              intptr_t numElements,
-                                             MlirType *elements);
+                                             MlirType const *elements);
 
 /// Returns the number of types contained in a tuple.
 MLIR_CAPI_EXPORTED intptr_t mlirTupleTypeGetNumTypes(MlirType type);
@@ -295,9 +295,9 @@ MLIR_CAPI_EXPORTED int mlirTypeIsAFunction(MlirType type);
 /// Creates a function type, mapping a list of input types to result types.
 MLIR_CAPI_EXPORTED MlirType mlirFunctionTypeGet(MlirContext ctx,
                                                 intptr_t numInputs,
-                                                MlirType *inputs,
+                                                MlirType const *inputs,
                                                 intptr_t numResults,
-                                                MlirType *results);
+                                                MlirType const *results);
 
 /// Returns the number of input types.
 MLIR_CAPI_EXPORTED intptr_t mlirFunctionTypeGetNumInputs(MlirType type);

diff  --git a/mlir/lib/CAPI/IR/IR.cpp b/mlir/lib/CAPI/IR/IR.cpp
index 5899b83aed33..f2329afce7e0 100644
--- a/mlir/lib/CAPI/IR/IR.cpp
+++ b/mlir/lib/CAPI/IR/IR.cpp
@@ -188,24 +188,24 @@ MlirOperationState mlirOperationStateGet(const char *name, MlirLocation loc) {
   state->sizeName += n;
 
 void mlirOperationStateAddResults(MlirOperationState *state, intptr_t n,
-                                  MlirType *results) {
+                                  MlirType const *results) {
   APPEND_ELEMS(MlirType, nResults, results);
 }
 
 void mlirOperationStateAddOperands(MlirOperationState *state, intptr_t n,
-                                   MlirValue *operands) {
+                                   MlirValue const *operands) {
   APPEND_ELEMS(MlirValue, nOperands, operands);
 }
 void mlirOperationStateAddOwnedRegions(MlirOperationState *state, intptr_t n,
-                                       MlirRegion *regions) {
+                                       MlirRegion const *regions) {
   APPEND_ELEMS(MlirRegion, nRegions, regions);
 }
 void mlirOperationStateAddSuccessors(MlirOperationState *state, intptr_t n,
-                                     MlirBlock *successors) {
+                                     MlirBlock const *successors) {
   APPEND_ELEMS(MlirBlock, nSuccessors, successors);
 }
 void mlirOperationStateAddAttributes(MlirOperationState *state, intptr_t n,
-                                     MlirNamedAttribute *attributes) {
+                                     MlirNamedAttribute const *attributes) {
   APPEND_ELEMS(MlirNamedAttribute, nAttributes, attributes);
 }
 
@@ -390,7 +390,7 @@ void mlirRegionDestroy(MlirRegion region) {
 // Block API.
 //===----------------------------------------------------------------------===//
 
-MlirBlock mlirBlockCreate(intptr_t nArgs, MlirType *args) {
+MlirBlock mlirBlockCreate(intptr_t nArgs, MlirType const *args) {
   Block *b = new Block;
   for (intptr_t i = 0; i < nArgs; ++i)
     b->addArgument(unwrap(args[i]));

diff  --git a/mlir/lib/CAPI/IR/StandardAttributes.cpp b/mlir/lib/CAPI/IR/StandardAttributes.cpp
index 4e9f03e57a3f..c23383fd5085 100644
--- a/mlir/lib/CAPI/IR/StandardAttributes.cpp
+++ b/mlir/lib/CAPI/IR/StandardAttributes.cpp
@@ -40,7 +40,7 @@ int mlirAttributeIsAArray(MlirAttribute attr) {
 }
 
 MlirAttribute mlirArrayAttrGet(MlirContext ctx, intptr_t numElements,
-                               MlirAttribute *elements) {
+                               MlirAttribute const *elements) {
   SmallVector<Attribute, 8> attrs;
   return wrap(ArrayAttr::get(
       unwrapList(static_cast<size_t>(numElements), elements, attrs),
@@ -64,7 +64,7 @@ int mlirAttributeIsADictionary(MlirAttribute attr) {
 }
 
 MlirAttribute mlirDictionaryAttrGet(MlirContext ctx, intptr_t numElements,
-                                    MlirNamedAttribute *elements) {
+                                    MlirNamedAttribute const *elements) {
   SmallVector<NamedAttribute, 8> attributes;
   attributes.reserve(numElements);
   for (intptr_t i = 0; i < numElements; ++i)
@@ -207,7 +207,7 @@ int mlirAttributeIsASymbolRef(MlirAttribute attr) {
 
 MlirAttribute mlirSymbolRefAttrGet(MlirContext ctx, intptr_t length,
                                    const char *symbol, intptr_t numReferences,
-                                   MlirAttribute *references) {
+                                   MlirAttribute const *references) {
   SmallVector<FlatSymbolRefAttr, 4> refs;
   refs.reserve(numReferences);
   for (intptr_t i = 0; i < numReferences; ++i)
@@ -324,7 +324,7 @@ int mlirAttributeIsADenseFPElements(MlirAttribute attr) {
 
 MlirAttribute mlirDenseElementsAttrGet(MlirType shapedType,
                                        intptr_t numElements,
-                                       MlirAttribute *elements) {
+                                       MlirAttribute const *elements) {
   SmallVector<Attribute, 8> attributes;
   return wrap(
       DenseElementsAttr::get(unwrap(shapedType).cast<ShapedType>(),
@@ -423,7 +423,7 @@ MlirAttribute mlirDenseElementsAttrDoubleGet(MlirType shapedType,
 
 MlirAttribute mlirDenseElementsAttrStringGet(MlirType shapedType,
                                              intptr_t numElements,
-                                             intptr_t *strLengths,
+                                             intptr_t const *strLengths,
                                              const char **strs) {
   SmallVector<StringRef, 8> values;
   values.reserve(numElements);

diff  --git a/mlir/lib/CAPI/IR/StandardTypes.cpp b/mlir/lib/CAPI/IR/StandardTypes.cpp
index 989d68e092f9..9253058b1c6e 100644
--- a/mlir/lib/CAPI/IR/StandardTypes.cpp
+++ b/mlir/lib/CAPI/IR/StandardTypes.cpp
@@ -221,7 +221,7 @@ MlirType mlirUnrankedTensorTypeGetChecked(MlirType elementType,
 int mlirTypeIsAMemRef(MlirType type) { return unwrap(type).isa<MemRefType>(); }
 
 MlirType mlirMemRefTypeGet(MlirType elementType, intptr_t rank, int64_t *shape,
-                           intptr_t numMaps, MlirAffineMap *affineMaps,
+                           intptr_t numMaps, MlirAffineMap const *affineMaps,
                            unsigned memorySpace) {
   SmallVector<AffineMap, 1> maps;
   (void)unwrapList(numMaps, affineMaps, maps);
@@ -285,7 +285,7 @@ unsigned mlirUnrankedMemrefGetMemorySpace(MlirType type) {
 int mlirTypeIsATuple(MlirType type) { return unwrap(type).isa<TupleType>(); }
 
 MlirType mlirTupleTypeGet(MlirContext ctx, intptr_t numElements,
-                          MlirType *elements) {
+                          MlirType const *elements) {
   SmallVector<Type, 4> types;
   ArrayRef<Type> typeRef = unwrapList(numElements, elements, types);
   return wrap(TupleType::get(typeRef, unwrap(ctx)));
@@ -308,8 +308,8 @@ int mlirTypeIsAFunction(MlirType type) {
 }
 
 MlirType mlirFunctionTypeGet(MlirContext ctx, intptr_t numInputs,
-                             MlirType *inputs, intptr_t numResults,
-                             MlirType *results) {
+                             MlirType const *inputs, intptr_t numResults,
+                             MlirType const *results) {
   SmallVector<Type, 4> inputsList;
   SmallVector<Type, 4> resultsList;
   (void)unwrapList(numInputs, inputs, inputsList);


        


More information about the Mlir-commits mailing list