llvm / llvm/Polygeist

Support for overloading built-in operators

Open
#205 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
624
Forks
170
PR merge metrics
No merged PRs in 30d

Description

Hi! While Polygeist seems to have good support for structs, member functions and templating, I came across issues when trying to overload built-in operators.

A simple case is:

struct Pair {
  int first;
  int second;
  Pair operator+(Pair other) {
    return Pair{this->first + other.first, this->second + other.second};
  }
};
Pair timesTwo(Pair p) { return p + p; }

running: mlir-clang -v -S -function=* -scal-rep=0 --memref-fullrank ${file} produces:

CXXConstructExpr 0xeb86c20 'struct Pair' 'void (struct Pair &&) noexcept' elidable
`-MaterializeTemporaryExpr 0xeb86c08 'struct Pair' xvalue
  `-CXXOperatorCallExpr 0xeb86bd0 'struct Pair' '+'
    |-ImplicitCastExpr 0xeb86bb8 'struct Pair (*)(struct Pair)' <FunctionToPointerDecay>
    | `-DeclRefExpr 0xeb86b70 'struct Pair (struct Pair)' lvalue CXXMethod 0xeb682e8 'operator+' 'struct Pair (struct Pair)'
    |-DeclRefExpr 0xeb86980 'struct Pair' lvalue ParmVar 0xeb86800 'p' 'struct Pair'
    `-CXXConstructExpr 0xeb86b40 'struct Pair' 'void (const struct Pair &) noexcept'
      `-ImplicitCastExpr 0xeb869c0 'const struct Pair' lvalue <NoOp>
        `-DeclRefExpr 0xeb869a0 'struct Pair' lvalue ParmVar 0xeb86800 'p' 'struct Pair'
cleanup not handled
CXXConstructExpr 0xeb86780 'struct Pair' 'void (struct Pair &&) noexcept' elidable
`-MaterializeTemporaryExpr 0xeb68be8 'struct Pair' xvalue
  `-CXXFunctionalCastExpr 0xeb68758 'struct Pair' functional cast to struct Pair <NoOp>
    `-InitListExpr 0xeb685c8 'struct Pair'
      |-BinaryOperator 0xeb68478 'int' '+'
      | |-ImplicitCastExpr 0xeb68448 'int' <LValueToRValue>
      | | `-MemberExpr 0xeb683c8 'int' lvalue ->first 0xeb68130
      | |   `-CXXThisExpr 0xeb683b8 'struct Pair *' this
      | `-ImplicitCastExpr 0xeb68460 'int' <LValueToRValue>
      |   `-MemberExpr 0xeb68418 'int' lvalue .first 0xeb68130
      |     `-DeclRefExpr 0xeb683f8 'struct Pair' lvalue ParmVar 0xeb681f8 'other' 'struct Pair'
      `-BinaryOperator 0xeb68558 'int' '+'
        |-ImplicitCastExpr 0xeb68528 'int' <LValueToRValue>
        | `-MemberExpr 0xeb684a8 'int' lvalue ->second 0xeb68198
        |   `-CXXThisExpr 0xeb68498 'struct Pair *' this
        `-ImplicitCastExpr 0xeb68540 'int' <LValueToRValue>
          `-MemberExpr 0xeb684f8 'int' lvalue .second 0xeb68198
            `-DeclRefExpr 0xeb684d8 'struct Pair' lvalue ParmVar 0xeb681f8 'other' 'struct Pair'
cleanup not handled

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided Pair example with the listed mlir-clang command and inspect handling of CXXOperatorCallExpr, CXXConstructExpr, and the reported “cleanup not handled” cases. Done means the overloaded built-in operator example is accepted without those unsupported-node errors and produces the expected MLIR output.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.