Directly referencing a basic block

Hello!

I’m currently translating a project from LLVM IR to MLIR and I’ve run into an issue I can’t find the solution to.

At specific points in our functions we need to have labels as such:

    .globl    func_1                    # -- Begin function func_1
    .p2align    2
    .type    func_1,@function
func_1:                           # @func_1
    .cfi_startproc
.Ltmp13:                                # Block address taken
# %bb.0:                                # %func_1
    ...
    instructions
    ...
.Ltmp14:                                # Block address taken
# %bb.1:                                # %func_1_lookup1
    ...
    instructions
    ...
.Lfunc_end14:
    .size    func_1, .Lfunc_end14-func_1
    .cfi_endproc

To be more specific, we need the labels Ltmp13 and Ltmp14 to be generated, and these labels are later referenced in a global lookup table:

    .word    6                               # 0x6
    .zero    4
    .quad    0
    .word    0                               # 0x0
    .word    0                               # 0x0
    .quad    .Ltmp13
    .word    0                               # 0x0
    .zero    4

However, the techniques used in the LLVM IR project, such as directly referencing a LLVM BasicBlock no longer work here.

How would I do this in MLIR?

Have you tried using regions (not isolated from above) as simulacrum for basic blocks? You could try to create a simple op that all it does is hold the label reference by containing all ops between the label and the next break (label, jump, constant pool).

There may be an upstream dialect op that you can use, but if not, creating a small dialect with a single op will at least give you an idea how to work with it in MLIR, then perhaps propose something later.