[InferAddressSpaces] Support assumed addrspaces from addrspace predicates.
authorMichael Liao <michael.hliao@gmail.com>
Fri, 15 Oct 2021 03:41:16 +0000 (23:41 -0400)
committerMichael Liao <michael.hliao@gmail.com>
Mon, 8 Nov 2021 21:51:57 +0000 (16:51 -0500)
commitbf225939bc3acf936c962f24423d3bb5ddd4c93f
treeeea3301193b94832394211673cc49bcb1c469ecc
parentf3798ad5fa845771846599f3c088016e3aef800c
[InferAddressSpaces] Support assumed addrspaces from addrspace predicates.

- CUDA cannot associate memory space with pointer types. Even though Clang could add extra attributes to specify the address space explicitly on a pointer type, it breaks the portability between Clang and NVCC.
- This change proposes to assume the address space from a pointer from the assumption built upon target-specific address space predicates, such as `__isGlobal` from CUDA. E.g.,

```
  foo(float *p) {
    __builtin_assume(__isGlobal(p));
    // From there, we could assume p is a global pointer instead of a
    // generic one.
  }
```

This makes the code portable without introducing the implementation-specific features.

Note that NVCC starts to support __builtin_assume from version 11.

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D112041
21 files changed:
clang/test/CodeGen/thinlto-distributed-newpm.ll
llvm/include/llvm/Analysis/AssumptionCache.h
llvm/include/llvm/Analysis/TargetTransformInfo.h
llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
llvm/include/llvm/CodeGen/BasicTTIImpl.h
llvm/include/llvm/Target/TargetMachine.h
llvm/lib/Analysis/AssumptionCache.cpp
llvm/lib/Analysis/TargetTransformInfo.cpp
llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h
llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
llvm/lib/Target/NVPTX/NVPTXTargetMachine.h
llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
llvm/test/Other/loop-pm-invalidation.ll
llvm/test/Other/new-pass-manager.ll
llvm/test/Other/new-pm-lto-defaults.ll
llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll
llvm/test/Transforms/InferAddressSpaces/AMDGPU/builtin-assumed-addrspace.ll [new file with mode: 0644]
llvm/test/Transforms/InferAddressSpaces/NVPTX/builtin-assumed-addrspace.ll [new file with mode: 0644]
llvm/test/Transforms/LoopRotate/pr35210.ll
llvm/unittests/Analysis/AssumeBundleQueriesTest.cpp