[Mlir-commits] [mlir] Support polynomial attributes with floating point coefficients (PR #91137)

Jeremy Kun llvmlistbot at llvm.org
Mon May 13 11:59:30 PDT 2024


j2kun wrote:

> > I have ~IntMonomial() = default; which then references the base class destructor,
> 
> The base class destructor being declared as pure virtual (`= 0;`), I'm puzzled about this reference?

This is mainly my ignorance of the right way to do things in C++, so I could use advice.

I think this should suffice?

```patch
diff --git a/mlir/include/mlir/Dialect/Polynomial/IR/Polynomial.h b/mlir/include/mlir/Dialect/Polynomial/IR/Polynomial.h
index 2b3f0e105c6..7f5b9b4670e 100644
--- a/mlir/include/mlir/Dialect/Polynomial/IR/Polynomial.h
+++ b/mlir/include/mlir/Dialect/Polynomial/IR/Polynomial.h
@@ -35,7 +35,7 @@ class MonomialBase {
 public:
   MonomialBase(const CoefficientType &coeff, const APInt &expo)
       : coefficient(coeff), exponent(expo) {}
-  virtual ~MonomialBase() = 0;
+  virtual ~MonomialBase() = default;

   const CoefficientType &getCoefficient() const { return coefficient; }
   CoefficientType &getMutableCoefficient() { return coefficient; }
diff --git a/mlir/lib/Dialect/Polynomial/IR/Polynomial.cpp b/mlir/lib/Dialect/Polynomial/IR/Polynomial.cpp
index 42e678fad06..e85bced3cca 100644
--- a/mlir/lib/Dialect/Polynomial/IR/Polynomial.cpp
+++ b/mlir/lib/Dialect/Polynomial/IR/Polynomial.cpp
@@ -14,9 +14,6 @@
 namespace mlir {
 namespace polynomial {

-template <typename T>
-MonomialBase<T>::~MonomialBase() {}
-
 template <typename PolyT, typename MonomialT>
 FailureOr<PolyT> fromMonomialsImpl(ArrayRef<MonomialT> monomials) {
   // A polynomial's terms are canonically stored in order of increasing degree.
```

Or should I be directly defining the particular instantiations used?

```cpp
template<> MonomialBase<APInt>::~MonomialBase() = default;
template<> MonomialBase<APFloat>::~MonomialBase() = default;
```

https://github.com/llvm/llvm-project/pull/91137


More information about the Mlir-commits mailing list