summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/TargetInfo.h
diff options
context:
space:
mode:
authorYaxun Liu <Yaxun.Liu@amd.com>2016-12-09 19:01:11 +0000
committerYaxun Liu <Yaxun.Liu@amd.com>2016-12-09 19:01:11 +0000
commit8f66b4b44a3de6215c83dfc47ec4158578fb4668 (patch)
treedd42c649814f8be950985675bf91aec4ae79bc4b /clang/lib/CodeGen/TargetInfo.h
parentdf41b13b09cef3916f97db33122f18d5cef17209 (diff)
downloadbcm5719-llvm-8f66b4b44a3de6215c83dfc47ec4158578fb4668.tar.gz
bcm5719-llvm-8f66b4b44a3de6215c83dfc47ec4158578fb4668.zip
Add support for non-zero null pointer for C and OpenCL
In amdgcn target, null pointers in global, constant, and generic address space take value 0 but null pointers in private and local address space take value -1. Currently LLVM assumes all null pointers take value 0, which results in incorrectly translated IR. To workaround this issue, instead of emit null pointers in local and private address space, a null pointer in generic address space is emitted and casted to local and private address space. Tentative definition of global variables with non-zero initializer will have weak linkage instead of common linkage since common linkage requires zero initializer and does not have explicit section to hold the non-zero value. Virtual member functions getNullPointer and performAddrSpaceCast are added to TargetCodeGenInfo which by default returns ConstantPointerNull and emitting addrspacecast instruction. A virtual member function getNullPointerValue is added to TargetInfo which by default returns 0. Each target can override these virtual functions to get target specific null pointer and the null pointer value for specific address space, and perform specific translations for addrspacecast. Wrapper functions getNullPointer is added to CodegenModule and getTargetNullPointerValue is added to ASTContext to facilitate getting the target specific null pointers and their values. This change has no effect on other targets except amdgcn target. Other targets can provide support of non-zero null pointer in a similar way. This change only provides support for non-zero null pointer for C and OpenCL. Supporting for other languages will be added later incrementally. Differential Revision: https://reviews.llvm.org/D26196 llvm-svn: 289252
Diffstat (limited to 'clang/lib/CodeGen/TargetInfo.h')
-rw-r--r--clang/lib/CodeGen/TargetInfo.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/TargetInfo.h b/clang/lib/CodeGen/TargetInfo.h
index e46382596af..223d6d047af 100644
--- a/clang/lib/CodeGen/TargetInfo.h
+++ b/clang/lib/CodeGen/TargetInfo.h
@@ -220,6 +220,22 @@ public:
/// Get LLVM calling convention for OpenCL kernel.
virtual unsigned getOpenCLKernelCallingConv() const;
+
+ /// Get target specific null pointer.
+ /// \param T is the LLVM type of the null pointer.
+ /// \param QT is the clang QualType of the null pointer.
+ /// \return ConstantPointerNull with the given type \p T.
+ /// Each target can override it to return its own desired constant value.
+ virtual llvm::Constant *getNullPointer(const CodeGen::CodeGenModule &CGM,
+ llvm::PointerType *T, QualType QT) const;
+
+ /// Perform address space cast of an expression of pointer type.
+ /// \param V is the LLVM value to be casted to another address space.
+ /// \param SrcTy is the QualType of \p V.
+ /// \param DestTy is the destination QualType.
+ virtual llvm::Value *performAddrSpaceCast(CodeGen::CodeGenFunction &CGF,
+ llvm::Value *V, QualType SrcTy, QualType DestTy) const;
+
};
} // namespace CodeGen
OpenPOWER on IntegriCloud