Doubts about SymbolTable mechanics

Hello!

First of all, thanks for any help provided.

I am writing a toy programming language as an excuse for learning MLIR. I have already some constructs like pattern matching and destructuring working nicely. Now I am trying to add the possibility to declare variables in the language. For this reason I added some operations to my dialect. If I am not incorrect, there are two APIs available to work with Operations, either through results-operands chains or through symbols. I am trying the latter approach for this feature I want to implement.

I implemented the following Operands:

  • tmplang.subprogramParam: Allows me to declare a parameter
  • tmplang.varRef: Allows me to use of prev-defined parameter

An example of MLIR described would be the following:

  tmplang.subprogram private @foo(%arg0: i32) -> i32 {
    tmplang.subprogramParam(%arg0) "private" @a : i32
    %1 = tmplang.varRef @a : i32
    ...

The problems I am finding are the following:

  1. My conversions passes are organized in the following manner (just describing the relevant ones):
    1º - TmplangToFunc: tmplang.subprogram and tmplang.return to FuncOp operations, func.FuncOp and func.ReturnOp respectively
    2º - TmplangToLLVM: FuncOps to LLVM, and rest of Tmplang to LLVM (tmplang.subprogramParam, tmplang.varRef, etc)

    In the step the problem I find is that when transforming tmplang.subprogram to func.FuncOp the symbol table disapears since func.FuncOp does not have the trait SymbolTable. This makes impossible to proceed with . Does this I mean I have to leave out the FuncOp dialect and implement my own solution?

  2. I want to to lower in the pass TmplangToLLVM the operands in the following manner:

  • tmplang.subprogramParam: alloca + store

  • tmplang.varRef: just be able to reference the alloca of the referenced variable

    The problem I am finding is that I have no way to reference the alloca when lowering the tmplang.varRef. I am not finding any SymbolTable method that allows me doing this. Are symbols only for global values (functions, gobal vars, etc)? I am approaching this in the wrong way and I should stick with the results-operands approach?

I would like to know what I am doing wrong and if possible what are the steps, docs, etc; needed to fix them.

Thanks again!