Hey @Arie, like @ftynse mentioned this is an area I’m exploring. I have a basic MLIR dialect for C that I’m improving, but this week I’ve been focusing on building out my C lexer and parser to be more fully-featured. For example, before this week my lexer did not support the string literal in your example,
"Hello world\n", but now it does
Depending on your specific interests, I could share some code with you:
- If you wish to transform C source code into MLIR, either to MLIR’s LLVM dialect, or to a C dialect, that’s exactly what my project entails, so I could share the whole thing – but I’m not finished. I’m currently rewriting the lexing/parsing layer to properly handle all of C’s grammar elements. For example, yesterday I improved my lexer to handle integer constants like
0xdeadbeefUll. If you could wait a few weeks, I think my frontend will be able to translate most C source code into MLIR.
- If you wish to use MLIR builders to create MLIR code that represents the equivalent of your hello world C source program, I could share my dialect with you. It can mostly handle your example: a
c.call operation to
printf, and a
c.constant of type
!c<"char*"> with a value of
However, I haven’t spent any time building out optimizations. My project would merely translate your old class projects into MLIR, I don’t have anything that would optimize them, certainly not beyond anything GCC or Clang do today.
(For those who may be curious: I’m writing my own C lexer/parser mostly for fun, and also because I didn’t want to try and shoehorn MLIR generation into an existing compiler like Clang. And if the C dialect I come up with is any good, I do want to talk about including it in the MLIR project itself, but I want to make sure it can handle any C code my frontend throws at it first.)
If you wait a few weeks, I’ll put what I have on GitHub, and you’ll at least be able to translate your class projects into MLIR. Beyond that, we can brainstorm then about what optimizations we could develop.