This is an archive of the discontinued LLVM Phabricator instance.

Associate functions with address spaces
AbandonedPublic

Authored by dylanmckay on Aug 18 2017, 8:50 PM.

Details

Summary

I am popping this up on Phabricator for early feedback.

**NOTE*: I will submit this in several smaller patches once this is actually ready.

This adds support for letting targets specify which address
spaces their functions should reside in by default.

This is the first step towards placing functions into the correct
address space for Harvard architectures.

This requires address space to be specified when creating functions. In general, you should always be using DataLayout.getProgramAddressSpace() unless you have a reason not to.

Event Timeline

dylanmckay created this revision.Aug 18 2017, 8:50 PM
dylanmckay retitled this revision from Add default address space for functions to the data layout to Associate functions with address spaces.Aug 18 2017, 8:52 PM
dylanmckay edited the summary of this revision. (Show Details)
dylanmckay added inline comments.Aug 18 2017, 9:02 PM
include/llvm/IR/DerivedTypes.h
106

I worry that other LLVM developers will see AddrSpace and naively enter 0, which would break all Harvard architectures.

One way around this could be make the ctor take a DataLayout instead, but you shouldn't really need one to construct this.

Any ideas are very welcome!

I intend to add many more tests once I've had some feedback

I meant to post that comment on this diff

bjope added a subscriber: bjope.Aug 19 2017, 8:05 AM

Place switch tables in the program memory address space

pcc added inline comments.Aug 20 2017, 8:08 PM
include/llvm/IR/DerivedTypes.h
106

I don't understand why this needs to be part of the function type. It seems to me that this ought to work in the same way as for global variables, i.e. function takes an address space at construction time which is used to create its pointer type; address space is queried by querying address space on the pointer type.

theraven added inline comments.Aug 21 2017, 12:54 AM
include/llvm/IR/DerivedTypes.h
106

Indeed. One of the big differences between the C and LLVM models is that C address spaces are properties of objects whereas LLVM address spaces are properties of pointers. The LLVM model is cleaner, but associating an address space with a function would be inconsistent.

dylanmckay added inline comments.Aug 21 2017, 11:57 AM
include/llvm/IR/DerivedTypes.h
106

I originally implemented this in the way you all are mentioning, but I had to backtrack when I saw these two lines

FunctionType *FT =
    FunctionType::get(RetType, ParamTypeList, isVarArg, AddrSpace);
  PointerType *PFT = PointerType::getUnqual(FT);

I just read up and realised that getUnqual will always use the generic address space, and so this is not relevant.

I will move the field to Function, similar to the way it is done for global variables.

asb added a subscriber: asb.Aug 21 2017, 11:59 PM

Abandoning this for now, will upload a new set of patches which places address space on Function and not FunctionType.

dylanmckay abandoned this revision.Aug 23 2017, 1:28 AM
dylanmckay added a comment.EditedAug 23 2017, 1:58 AM

Have raised

  • Add program address space to data layout D37052
  • Insert switch tables into the program memory address space D37053
  • Require address space to be specified when creating functions D37054
  • [clang] Require address space to be specified when creating functions D37057