Skip to content

Commit

Permalink
Make array pointers in the CAPI const
Browse files Browse the repository at this point in the history
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
  • Loading branch information
George committed Nov 19, 2020
1 parent 22ec72f commit beb889c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
12 changes: 6 additions & 6 deletions mlir/include/mlir-c/IR.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions mlir/include/mlir-c/StandardAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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. */
Expand Down
8 changes: 4 additions & 4 deletions mlir/include/mlir-c/StandardTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions mlir/lib/CAPI/IR/IR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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]));
Expand Down
10 changes: 5 additions & 5 deletions mlir/lib/CAPI/IR/StandardAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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>(),
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions mlir/lib/CAPI/IR/StandardTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)));
Expand All @@ -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);
Expand Down

0 comments on commit beb889c

Please sign in to comment.