[LLVMdev] Advice on field access, adding a Modula-3 front end

Krzysztof Parzyszek kparzysz at codeaurora.org
Thu Apr 10 19:02:11 PDT 2014


On 4/10/2014 8:40 PM, Rodney M. Bates wrote:
>
> I could probably create llvm IR in this style by generating explicit
> address arithmetic, but I suspect that might hurt the optimization
> possibilities, perhaps a lot.  It looks like re-raising the level to
> field numbers would not be horribly difficult, but it would require
> using information in the M3 IR that is apparently intended to be debug
> info only.

You don't have to "re-raise" it, you may simply manufacture struct types 
that correspond to the data being used, which shouldn't be too hard if 
the data accesses to a specific member are always of the same size and 
type.  To avoid problems with the layout differing between targets, you 
could make the type "packed" and make the padding explicit.  This does 
not solve problems with unions, for which address arithmetic and type 
casting may be necessary.


> I presume llvm does its own memory layout for structs?

It uses the data layout that is provided when you create the 
TargetMachine for a given target.  In other words, it can be different 
for each supported target.


> It is worse with global variables and constants.  Here, in the M3 IR,
> for each compilation unit, these have been collected into two records,
> one for constants and one for variables, with the memory layout within
> them already done.  These are accessed with byte offsets within the
> two records.  What makes it more complicated is that some of the
> fields are in a fixed layout that the runtime system expects.  So to
> use field number access, I would still need to force llvm to accept
> the memory layout I supply.  Can I do that?

Yes. Make it "packed" and add explicit padding.

The only problem may be with translating the debug information.  If all 
global variables became members of some aggregate, then I'm not sure how 
to generate debug information for them that would preserve original 
names and other relevant information.


-Krzysztof


-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
hosted by The Linux Foundation



More information about the llvm-dev mailing list