Skip to content
11 changes: 11 additions & 0 deletions clang/include/clang/Basic/TargetInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1759,6 +1759,17 @@ class TargetInfo : public TransferrableTargetInfo,
return 0;
}

/// \returns If a target exposes a flat ptr address space (a flat ptr is a ptr
/// that can be casted to / from all other target address spaces), then return
/// it. Otherwise, return std::nullopt and leave it up to the FE to correctly
/// insert specific address spaces. Note that this is target specific and
/// might not have a corresponding LangAS equivalent, thus it is not safe to
/// unconditionally invoke getLangASFromTargetAS on the value returned by this
/// interface.
virtual std::optional<unsigned> getFlatPtrAddressSpace() const {
return std::nullopt;
}

/// \returns If a target requires an address within a target specific address
/// space \p AddressSpace to be converted in order to be used, then return the
/// corresponding target specific DWARF address space.
Expand Down
6 changes: 6 additions & 0 deletions clang/lib/Basic/Targets/AMDGPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,12 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
return static_cast<unsigned>(llvm::AMDGPUAS::CONSTANT_ADDRESS);
}

/// \returns Target specific flat ptr address space; a flat ptr is a ptr that
/// can be casted to / from all other target address spaces.
std::optional<unsigned> getFlatPtrAddressSpace() const override {
return static_cast<unsigned>(llvm::AMDGPUAS::FLAT_ADDRESS);
}

/// \returns If a target requires an address within a target specific address
/// space \p AddressSpace to be converted in order to be used, then return the
/// corresponding target specific DWARF address space.
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Basic/Targets/SPIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ class LLVM_LIBRARY_VISIBILITY BaseSPIRTargetInfo : public TargetInfo {
return TargetInfo::VoidPtrBuiltinVaList;
}

std::optional<unsigned> getFlatPtrAddressSpace() const override {
return 4u; // 4 is generic i.e. flat for SPIR & SPIR-V.
}

std::optional<unsigned>
getDWARFAddressSpace(unsigned AddressSpace) const override {
return AddressSpace;
Expand Down