Skip to content

Commit 0259456

Browse files
committed
[presburger] Develope python bindings for presburger
c++ library This MR is work in progress.
1 parent 9bf68c2 commit 0259456

File tree

11 files changed

+1928
-0
lines changed

11 files changed

+1928
-0
lines changed

llvm/include/llvm/ADT/DynamicAPInt.h

+7
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,13 @@ class DynamicAPInt {
217217

218218
raw_ostream &print(raw_ostream &OS) const;
219219
LLVM_DUMP_METHOD void dump() const;
220+
221+
void *getAsOpaquePointer() const { return const_cast<DynamicAPInt *>(this); }
222+
223+
static DynamicAPInt *getFromOpaquePointer(const void *Pointer) {
224+
return const_cast<DynamicAPInt *>(
225+
reinterpret_cast<const DynamicAPInt *>(Pointer));
226+
}
220227
};
221228

222229
inline raw_ostream &operator<<(raw_ostream &OS, const DynamicAPInt &X) {

mlir/include/mlir-c/Presburger.h

+527
Large diffs are not rendered by default.

mlir/include/mlir/Analysis/Presburger/IntegerRelation.h

+9
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,15 @@ class IntegerRelation {
753753
// false.
754754
bool isFullDim();
755755

756+
void *getAsOpaquePointer() const {
757+
return const_cast<IntegerRelation *>(this);
758+
}
759+
760+
static IntegerRelation *getFromOpaquePointer(const void *pointer) {
761+
return const_cast<IntegerRelation *>(
762+
reinterpret_cast<const IntegerRelation *>(pointer));
763+
}
764+
756765
void print(raw_ostream &os) const;
757766
void dump() const;
758767

mlir/include/mlir/CAPI/Presburger.h

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef MLIR_CAPI_PRESBURGER_H
2+
#define MLIR_CAPI_PRESBURGER_H
3+
4+
#include "mlir-c/Presburger.h"
5+
#include "mlir/Analysis/Presburger/IntegerRelation.h"
6+
#include "mlir/Analysis/Presburger/PresburgerSpace.h"
7+
#include "mlir/CAPI/Wrap.h"
8+
#include "llvm/ADT/DynamicAPInt.h"
9+
10+
DEFINE_C_API_PTR_METHODS(MlirPresburgerIntegerRelation,
11+
mlir::presburger::IntegerRelation)
12+
13+
static inline MlirPresburgerDynamicAPInt wrap(llvm::DynamicAPInt *cpp) {
14+
return MlirPresburgerDynamicAPInt{cpp->getAsOpaquePointer()};
15+
}
16+
17+
static inline llvm::DynamicAPInt *unwrap(MlirPresburgerDynamicAPInt c) {
18+
return llvm::DynamicAPInt::getFromOpaquePointer(c.ptr);
19+
}
20+
21+
#endif /* MLIR_CAPI_PRESBURGER_H */

0 commit comments

Comments
 (0)