xref: /aosp_15_r20/external/swiftshader/third_party/llvm-16.0/llvm/lib/IR/TypedPointerType.cpp (revision 03ce13f70fcc45d86ee91b7ee4cab1936a95046e)
1 //===- TypedPointerType.cpp - Typed Pointer Type --------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 //
10 //===----------------------------------------------------------------------===//
11 
12 #include "llvm/IR/TypedPointerType.h"
13 #include "LLVMContextImpl.h"
14 
15 using namespace llvm;
16 
get(Type * EltTy,unsigned AddressSpace)17 TypedPointerType *TypedPointerType::get(Type *EltTy, unsigned AddressSpace) {
18   assert(EltTy && "Can't get a pointer to <null> type!");
19   assert(isValidElementType(EltTy) && "Invalid type for pointer element!");
20 
21   LLVMContextImpl *CImpl = EltTy->getContext().pImpl;
22 
23   // Since AddressSpace #0 is the common case, we special case it.
24   TypedPointerType *&Entry =
25       CImpl->ASTypedPointerTypes[std::make_pair(EltTy, AddressSpace)];
26 
27   if (!Entry)
28     Entry = new (CImpl->Alloc) TypedPointerType(EltTy, AddressSpace);
29   return Entry;
30 }
31 
TypedPointerType(Type * E,unsigned AddrSpace)32 TypedPointerType::TypedPointerType(Type *E, unsigned AddrSpace)
33     : Type(E->getContext(), TypedPointerTyID), PointeeTy(E) {
34   ContainedTys = &PointeeTy;
35   NumContainedTys = 1;
36   setSubclassData(AddrSpace);
37 }
38 
isValidElementType(Type * ElemTy)39 bool TypedPointerType::isValidElementType(Type *ElemTy) {
40   return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() &&
41          !ElemTy->isMetadataTy() && !ElemTy->isTokenTy() &&
42          !ElemTy->isX86_AMXTy();
43 }
44