Add a default address space for globals to DataLayout
authorAlex Richardson <Alexander.Richardson@cl.cam.ac.uk>
Fri, 20 Nov 2020 15:17:52 +0000 (15:17 +0000)
committerAlex Richardson <Alexander.Richardson@cl.cam.ac.uk>
Fri, 20 Nov 2020 15:46:52 +0000 (15:46 +0000)
commit3bc4157556b01e10288df120dd068e093ae20901
treedecfba5e31c7ed830d85350fd8c9159ef6e1a144
parent4766a86cf2f9ac47b1a0288fde84dc74f55b3f11
Add a default address space for globals to DataLayout

This is similar to the existing alloca and program address spaces (D37052)
and should be used when creating/accessing global variables.
We need this in our CHERI fork of LLVM to place all globals in address space 200.
This ensures that values are accessed using CHERI load/store instructions
instead of the normal MIPS/RISC-V ones.

The problem this is trying to fix is that most of the time the type of
globals is created using a simple PointerType::getUnqual() (or ::get() with
the default address-space value of 0). This does not work for us and we get
assertion/compilation/instruction selection failures whenever a new call
is added that uses the default value of zero.

In our fork we have removed the default parameter value of zero for most
address space arguments and use DL.getProgramAddressSpace() or
DL.getGlobalsAddressSpace() whenever possible. If this change is accepted,
I will upstream follow-up patches to use DL.getGlobalsAddressSpace() instead
of relying on the default value of 0 for PointerType::get(), etc.

This patch and the follow-up changes will not have any functional changes
for existing backends with the default globals address space of zero.
A follow-up commit will change the default globals address space for
AMDGPU to 1.

Reviewed By: dylanmckay

Differential Revision: https://reviews.llvm.org/D70947
llvm/docs/LangRef.rst
llvm/include/llvm/IR/DataLayout.h
llvm/include/llvm/IR/GlobalVariable.h
llvm/lib/IR/DataLayout.cpp
llvm/lib/IR/Globals.cpp
llvm/test/Assembler/invalid-datalayout-globals-addrspace.ll [new file with mode: 0644]
llvm/unittests/IR/DataLayoutTest.cpp