[TableGen] Fix validateOperandClass for non Phyical Reg (#118146)
[llvm-project.git] / llvm / lib / IR / TypedPointerType.cpp
blob85f7a5a2ae4c30687cfa651fa2e2cb077fd43f19
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 //===----------------------------------------------------------------------===//
12 #include "llvm/IR/TypedPointerType.h"
13 #include "LLVMContextImpl.h"
15 using namespace llvm;
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!");
21 LLVMContextImpl *CImpl = EltTy->getContext().pImpl;
23 TypedPointerType *&Entry =
24 CImpl->ASTypedPointerTypes[std::make_pair(EltTy, AddressSpace)];
26 if (!Entry)
27 Entry = new (CImpl->Alloc) TypedPointerType(EltTy, AddressSpace);
28 return Entry;
31 TypedPointerType::TypedPointerType(Type *E, unsigned AddrSpace)
32 : Type(E->getContext(), TypedPointerTyID), PointeeTy(E) {
33 ContainedTys = &PointeeTy;
34 NumContainedTys = 1;
35 setSubclassData(AddrSpace);
38 bool TypedPointerType::isValidElementType(Type *ElemTy) {
39 return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() &&
40 !ElemTy->isMetadataTy() && !ElemTy->isTokenTy() &&
41 !ElemTy->isX86_AMXTy();