MLIR  20.0.0git
IntegerSet.cpp
Go to the documentation of this file.
1 //===- IntegerSet.cpp - C API for MLIR Integer Sets -----------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "mlir-c/IntegerSet.h"
10 #include "mlir-c/AffineExpr.h"
11 #include "mlir/CAPI/AffineExpr.h"
12 #include "mlir/CAPI/IR.h"
13 #include "mlir/CAPI/IntegerSet.h"
14 #include "mlir/CAPI/Utils.h"
15 #include "mlir/IR/IntegerSet.h"
16 
17 using namespace mlir;
18 
19 MlirContext mlirIntegerSetGetContext(MlirIntegerSet set) {
20  return wrap(unwrap(set).getContext());
21 }
22 
23 bool mlirIntegerSetEqual(MlirIntegerSet s1, MlirIntegerSet s2) {
24  return unwrap(s1) == unwrap(s2);
25 }
26 
27 void mlirIntegerSetPrint(MlirIntegerSet set, MlirStringCallback callback,
28  void *userData) {
29  mlir::detail::CallbackOstream stream(callback, userData);
30  unwrap(set).print(stream);
31 }
32 
33 void mlirIntegerSetDump(MlirIntegerSet set) { unwrap(set).dump(); }
34 
35 MlirIntegerSet mlirIntegerSetEmptyGet(MlirContext context, intptr_t numDims,
36  intptr_t numSymbols) {
37  return wrap(IntegerSet::getEmptySet(static_cast<unsigned>(numDims),
38  static_cast<unsigned>(numSymbols),
39  unwrap(context)));
40 }
41 
42 MlirIntegerSet mlirIntegerSetGet(MlirContext context, intptr_t numDims,
43  intptr_t numSymbols, intptr_t numConstraints,
44  const MlirAffineExpr *constraints,
45  const bool *eqFlags) {
46  SmallVector<AffineExpr> mlirConstraints;
47  (void)unwrapList(static_cast<size_t>(numConstraints), constraints,
48  mlirConstraints);
49  return wrap(IntegerSet::get(
50  static_cast<unsigned>(numDims), static_cast<unsigned>(numSymbols),
51  mlirConstraints,
52  llvm::ArrayRef(eqFlags, static_cast<size_t>(numConstraints))));
53 }
54 
55 MlirIntegerSet
56 mlirIntegerSetReplaceGet(MlirIntegerSet set,
57  const MlirAffineExpr *dimReplacements,
58  const MlirAffineExpr *symbolReplacements,
59  intptr_t numResultDims, intptr_t numResultSymbols) {
60  SmallVector<AffineExpr> mlirDims, mlirSymbols;
61  (void)unwrapList(unwrap(set).getNumDims(), dimReplacements, mlirDims);
62  (void)unwrapList(unwrap(set).getNumSymbols(), symbolReplacements,
63  mlirSymbols);
64  return wrap(unwrap(set).replaceDimsAndSymbols(
65  mlirDims, mlirSymbols, static_cast<unsigned>(numResultDims),
66  static_cast<unsigned>(numResultSymbols)));
67 }
68 
69 bool mlirIntegerSetIsCanonicalEmpty(MlirIntegerSet set) {
70  return unwrap(set).isEmptyIntegerSet();
71 }
72 
73 intptr_t mlirIntegerSetGetNumDims(MlirIntegerSet set) {
74  return static_cast<intptr_t>(unwrap(set).getNumDims());
75 }
76 
77 intptr_t mlirIntegerSetGetNumSymbols(MlirIntegerSet set) {
78  return static_cast<intptr_t>(unwrap(set).getNumSymbols());
79 }
80 
81 intptr_t mlirIntegerSetGetNumInputs(MlirIntegerSet set) {
82  return static_cast<intptr_t>(unwrap(set).getNumInputs());
83 }
84 
85 intptr_t mlirIntegerSetGetNumConstraints(MlirIntegerSet set) {
86  return static_cast<intptr_t>(unwrap(set).getNumConstraints());
87 }
88 
89 intptr_t mlirIntegerSetGetNumEqualities(MlirIntegerSet set) {
90  return static_cast<intptr_t>(unwrap(set).getNumEqualities());
91 }
92 
93 intptr_t mlirIntegerSetGetNumInequalities(MlirIntegerSet set) {
94  return static_cast<intptr_t>(unwrap(set).getNumInequalities());
95 }
96 
97 MlirAffineExpr mlirIntegerSetGetConstraint(MlirIntegerSet set, intptr_t pos) {
98  return wrap(unwrap(set).getConstraint(static_cast<unsigned>(pos)));
99 }
100 
101 bool mlirIntegerSetIsConstraintEq(MlirIntegerSet set, intptr_t pos) {
102  return unwrap(set).isEq(pos);
103 }
MlirIntegerSet mlirIntegerSetReplaceGet(MlirIntegerSet set, const MlirAffineExpr *dimReplacements, const MlirAffineExpr *symbolReplacements, intptr_t numResultDims, intptr_t numResultSymbols)
Gets or creates a new integer set in which the values and dimensions of the given set are replaced wi...
Definition: IntegerSet.cpp:56
void mlirIntegerSetDump(MlirIntegerSet set)
Prints an integer set to the standard error stream.
Definition: IntegerSet.cpp:33
intptr_t mlirIntegerSetGetNumSymbols(MlirIntegerSet set)
Returns the number of symbols in the given set.
Definition: IntegerSet.cpp:77
bool mlirIntegerSetIsCanonicalEmpty(MlirIntegerSet set)
Checks whether the given set is a canonical empty set, e.g., the set returned by mlirIntegerSetEmptyG...
Definition: IntegerSet.cpp:69
intptr_t mlirIntegerSetGetNumEqualities(MlirIntegerSet set)
Returns the number of equalities in the given set.
Definition: IntegerSet.cpp:89
intptr_t mlirIntegerSetGetNumConstraints(MlirIntegerSet set)
Returns the number of constraints (equalities + inequalities) in the given set.
Definition: IntegerSet.cpp:85
intptr_t mlirIntegerSetGetNumInequalities(MlirIntegerSet set)
Returns the number of inequalities in the given set.
Definition: IntegerSet.cpp:93
intptr_t mlirIntegerSetGetNumInputs(MlirIntegerSet set)
Returns the number of inputs (dimensions + symbols) in the given set.
Definition: IntegerSet.cpp:81
MlirIntegerSet mlirIntegerSetEmptyGet(MlirContext context, intptr_t numDims, intptr_t numSymbols)
Gets or creates a new canonically empty integer set with the give number of dimensions and symbols in...
Definition: IntegerSet.cpp:35
bool mlirIntegerSetEqual(MlirIntegerSet s1, MlirIntegerSet s2)
Checks if two integer set objects are equal.
Definition: IntegerSet.cpp:23
void mlirIntegerSetPrint(MlirIntegerSet set, MlirStringCallback callback, void *userData)
Prints an integer set by sending chunks of the string representation and forwarding userData tocallba...
Definition: IntegerSet.cpp:27
MlirContext mlirIntegerSetGetContext(MlirIntegerSet set)
Gets the context in which the given integer set lives.
Definition: IntegerSet.cpp:19
MlirAffineExpr mlirIntegerSetGetConstraint(MlirIntegerSet set, intptr_t pos)
Returns pos-th constraint of the set.
Definition: IntegerSet.cpp:97
intptr_t mlirIntegerSetGetNumDims(MlirIntegerSet set)
Returns the number of dimensions in the given set.
Definition: IntegerSet.cpp:73
MlirIntegerSet mlirIntegerSetGet(MlirContext context, intptr_t numDims, intptr_t numSymbols, intptr_t numConstraints, const MlirAffineExpr *constraints, const bool *eqFlags)
Gets or creates a new integer set in the given context.
Definition: IntegerSet.cpp:42
bool mlirIntegerSetIsConstraintEq(MlirIntegerSet set, intptr_t pos)
Returns true of the pos-th constraint of the set is an equality constraint, false otherwise.
Definition: IntegerSet.cpp:101
static MLIRContext * getContext(OpFoldResult val)
static llvm::ArrayRef< CppTy > unwrapList(size_t size, CTy *first, llvm::SmallVectorImpl< CppTy > &storage)
Definition: Wrap.h:40
void print(raw_ostream &os) const
Outputs this diagnostic to a stream.
static IntegerSet get(unsigned dimCount, unsigned symbolCount, ArrayRef< AffineExpr > constraints, ArrayRef< bool > eqFlags)
static IntegerSet getEmptySet(unsigned numDims, unsigned numSymbols, MLIRContext *context)
Definition: IntegerSet.h:56
A simple raw ostream subclass that forwards write_impl calls to the user-supplied callback together w...
Definition: Utils.h:30
mlir::Diagnostic & unwrap(MlirDiagnostic diagnostic)
Definition: Diagnostics.h:19
MlirDiagnostic wrap(mlir::Diagnostic &diagnostic)
Definition: Diagnostics.h:24
void(* MlirStringCallback)(MlirStringRef, void *)
A callback for returning string references.
Definition: Support.h:105
Include the generated interface declarations.