Initializing a global array of labels in llvm-IR

I’m porting a legacy system over to llvm. To support all existing functionality I need to store addresses to arbitrary places in the code, so that I later can find those locations in the executable. I could probably use debug data, but my target currently doesn’t support dwarf.

So I start out with

__builtin_region_start("Tag");
/* do something */
__builtin_region_stop("Tag");
/*do something else */
__builtin_region_start("Tag2");
/* do something */
__builtin_region_stop("Tag2");
/*do something else */
__builtin_region_start("Tag");
/* do something */
__builtin_region_stop("Tag");
/*do something else */

In llvm I want to rewrite it to something like:

@Tag_start = dso_local global [2 x ptr] , [ptr @lbl1, ptr @lbl5]
@Tag_stop = dso_local global [2 x ptr] , [ptr @lbl2, ptr @lbl6]
@Tag2_start = dso_local global [1 x ptr] , [ptr @lbl3]
@Tag2_stop = dso_local global [1 x ptr] , [ptr @lbl4]

lbl1:
/* do something */
lbl2:
/*do something else */
lbl3:
/* do something */
lbl4:
/*do something else */
lbl5:
/* do something */
lbl6:
/*do something else */

I can then extract what I need from the object file after it has been relocated. Basically:

    Tag: start[<address>,<address>],stop[<address>,<address>]
    Tag2: start[<address>], stop[<address>]

I can create the labels and get handles to them as BlockAddress, but I don’t seem to be able to create the global object, since I can’t get the global variables type to line up with anything derived from the block address.
BlockAddress dumps as an i8*, but that is not a scalar so I can’t use that to build a constant for the initializer.
Looking at code examples from source like (void *)myptr=&&lbl; dumps out as type ptr rather than i8* but I haven’t found a way to create such a type from inside llvm. There is an LabelTy in the type system, but I haven’t found how to create such types, so I haven’t been able to see if it gets me closer to what I want to do.
Any Ideas?

I figured it out myself :slight_smile:
Make the array of address size ints and wrap the label pointer in a ptrtoint constexpr