Changing Alignment of global variables in LLVM

What is the best way to change the alignment of global variables and allocated structures in LLVM during one of its optimization passes?

For example, I want to change,

@u = internal unnamed_addr global [5 x [65 x [65 x [65 x double]]]] zeroinitializer, align 16

to align to 32 bytes.

How can this be accomplished so that all other references in the code accessing this structure are also updated.

Thank You

The effective alignment is part of the load and store operations. Updating those would mean that you need to know which ones are based on the @u address.

You can come up with some heuristics that track values through getelementptr and similar constructs in llvm IR and which will work in most cases.

However as you can have arbitrary computations to create the address for a load/store tracking the source of such computations is actually undecidable in general and you may have cases where you cannot determine the origin when allowing arbitrary IR.
Because of this I'd recommend to rather adjust the frontends type system so the loads and stores are created with the correct alignment in the first place.

- Matthias

If I know for sure I am accessing 32 byte chunks at a time, how can I go about changing the alignment of @u?

Should I use DataLayout’s reset method? I couldn’t find a method to change alignment of one global variable.

Thanks

If I know for sure I am accessing 32 byte chunks at a time, how can I go about changing the alignment of @u?

Should I use DataLayout’s reset method? I couldn’t find a method to change alignment of one global variable.

GlobalObject::setAlignment()?

  • Matthias

This is what we used in BBAC and PAMD (ISMM 2017); these systems transform globals to align them on a power-of-two boundary. Regards, John Criswell