This is an archive of the discontinued LLVM Phabricator instance.

TargetMachine: Add address space to getPointerSize
ClosedPublic

Authored by arsenm on Mar 6 2018, 9:53 AM.

Details

Reviewers
bjope
Summary

I'm not sure why these wrappers are here rather than just exposing the contained DataLayout

Diff Detail

Event Timeline

arsenm created this revision.Mar 6 2018, 9:53 AM
bjope added a subscriber: bjope.Mar 6 2018, 11:56 AM
bjope added inline comments.
include/llvm/Target/TargetMachine.h
141–155

Can we skip the default =0 for these?

If I remember correclty there are FIXME comments in DataLayout about removing the defaults in DataLayout. I think the idea is that people often forget to provide the correct address space. If an address space is mandatory one needs to motivate at a specific call site if it for example is correct to always use 0 instead of looking up the address space for the type. The amount of call sites where it always is correct to use a hard-coded 0 is probably very few.

arsenm added inline comments.Mar 7 2018, 6:46 AM
include/llvm/Target/TargetMachine.h
141–155

I would like to remove the default, but the context where this was used I don't see where the pointer is coming from (i.e. a few places AsmPrinter).

I'm doing this because it seems like the TargetMachine is the natural place to check the pointer size in GlobalISel's LegalizeInfo

bjope added inline comments.Mar 8 2018, 6:02 AM
include/llvm/Target/TargetMachine.h
141–155

My idea was to, for example, replace all old calls to this method into:
getPointerSize(0 /* TODO: Check/describe why address space 0 is correct here*/)
and, by that removing the default setting, and pushing the TODO down to the call sites.

arsenm updated this revision to Diff 137575.Mar 8 2018, 8:01 AM

Remove default. I did my best to guess at the context these were used for. Some of the DebugInfo ones are questionable, as well as AsmPrinter::getPointerSize

bjope added a comment.Mar 9 2018, 2:43 AM

Thanks Matt! I like this version without the default argument.

I think your guesses about correct address spaces are as good as mine. But I'm not 100% sure about a few diffs where we now use the "program AS" instead of AS=0. See my inline comments.

lib/CodeGen/AsmPrinter/AsmPrinter.cpp
218–220

As far as I can see this determines size of dwarf::DW_FORM_ref_addr for DWARF2, as it is used from DIEInteger::SizeOf().
(It is also used in test code in unittests/DebugInfo/DWARF/DwarfGenerator.cpp)

In DWARF2 DW_FORM_ref_addr was (confusingly) defined as being the size of an address on the target machine. Not sure what that means if there are several address spaces with different sizes on the target machine.

In our out-of-tree-target (a DSP) we have getPointerSize(0) != getProgramPointerSize(). Although we do not use DWARF2, so I do not think it really matter for us...

You could play it safe and simply do TM.getPointerSize(0), to avoid any functional change in this patch. But using TM.getProgramPointerSize() might actually be more correct. I do not really know.

984

Seems reasonable to me.

lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
1529–1530

Maybe one needs to inspect Ty here to really find out which address space that should be used.
I'd leave it as Asm->TM.getPointerSize(0) if being uncertain (to avoid changing behavior by mistake).

arsenm added inline comments.Mar 13 2018, 7:40 AM
lib/CodeGen/AsmPrinter/AsmPrinter.cpp
218–220

I think this needs getDWARFAddressSpace, but that may need a mapping to the target address space

arsenm updated this revision to Diff 138191.Mar 13 2018, 7:43 AM

Leave 0 in another place

bjope accepted this revision.Mar 13 2018, 9:59 AM

LGTM

This revision is now accepted and ready to land.Mar 13 2018, 9:59 AM
arsenm closed this revision.Mar 13 2018, 5:39 PM

r327467