LLVM
15.0.0git
lib
Target
DirectX
DXILPointerType.cpp
Go to the documentation of this file.
1
//===- Target/DirectX/DXILTypedPointerType.cpp - DXIL Typed Pointer Type
2
//-------===//
3
//
4
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5
// See https://llvm.org/LICENSE.txt for license information.
6
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "
DXILPointerType.h
"
14
#include "
llvm/ADT/Any.h
"
15
#include "
llvm/ADT/DenseMap.h
"
16
#include "
llvm/IR/LLVMContext.h
"
17
18
using namespace
llvm
;
19
using namespace
llvm::dxil
;
20
21
class
TypedPointerTracking
{
22
public
:
23
TypedPointerTracking
() {}
24
DenseMap<Type *, std::unique_ptr<TypedPointerType>
>
PointerTypes
;
25
DenseMap<std::pair<Type *, unsigned>
, std::unique_ptr<TypedPointerType>>
26
ASPointerTypes
;
27
};
28
29
TypedPointerType
*
TypedPointerType::get
(
Type
*EltTy,
unsigned
AddressSpace
) {
30
assert
(EltTy &&
"Can't get a pointer to <null> type!"
);
31
assert
(
isValidElementType
(EltTy) &&
"Invalid type for pointer element!"
);
32
33
llvm::Any
&TargetData = EltTy->
getContext
().
getTargetData
();
34
if
(!TargetData.
hasValue
())
35
TargetData =
Any
{std::make_shared<TypedPointerTracking>()};
36
37
assert
(
any_isa
<std::shared_ptr<TypedPointerTracking>>(TargetData) &&
38
"Unexpected target data type"
);
39
40
std::shared_ptr<TypedPointerTracking> Tracking =
41
any_cast<std::shared_ptr<TypedPointerTracking>>(TargetData);
42
43
// Since AddressSpace #0 is the common case, we special case it.
44
std::unique_ptr<TypedPointerType> &Entry =
45
AddressSpace
== 0
46
? Tracking->PointerTypes[EltTy]
47
: Tracking->ASPointerTypes[std::make_pair(EltTy,
AddressSpace
)];
48
49
if
(!Entry)
50
Entry = std::unique_ptr<TypedPointerType>(
51
new
TypedPointerType
(EltTy,
AddressSpace
));
52
return
Entry.get();
53
}
54
55
TypedPointerType::TypedPointerType(
Type
*
E
,
unsigned
AddrSpace)
56
:
Type
(
E
->getContext(), DXILPointerTyID), PointeeTy(
E
) {
57
ContainedTys
= &PointeeTy;
58
NumContainedTys
= 1;
59
setSubclassData
(AddrSpace);
60
}
61
62
bool
TypedPointerType::isValidElementType
(
Type
*ElemTy) {
63
return
!ElemTy->
isVoidTy
() && !ElemTy->
isLabelTy
() &&
64
!ElemTy->
isMetadataTy
() && !ElemTy->
isTokenTy
() &&
65
!ElemTy->
isX86_AMXTy
();
66
}
TypedPointerTracking::ASPointerTypes
DenseMap< std::pair< Type *, unsigned >, std::unique_ptr< TypedPointerType > > ASPointerTypes
Definition:
DXILPointerType.cpp:26
llvm::Any::hasValue
bool hasValue() const
Definition:
Any.h:103
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:
AddressRanges.h:17
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition:
Type.h:45
DenseMap.h
DXILPointerType.h
llvm::Type::isMetadataTy
bool isMetadataTy() const
Return true if this is 'metadata'.
Definition:
Type.h:185
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::Type::isTokenTy
bool isTokenTy() const
Return true if this is 'token'.
Definition:
Type.h:188
llvm::dxil::TypedPointerType
Definition:
DXILPointerType.h:22
llvm::AddressSpace
AddressSpace
Definition:
NVPTXBaseInfo.h:21
llvm::dxil
Definition:
DXILPointerType.h:18
llvm::DenseMap
Definition:
DenseMap.h:716
llvm::dxil::TypedPointerType::isValidElementType
static bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
Definition:
DXILPointerType.cpp:62
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::Type::isVoidTy
bool isVoidTy() const
Return true if this is 'void'.
Definition:
Type.h:139
llvm::Type::setSubclassData
void setSubclassData(unsigned val)
Definition:
Type.h:99
llvm::any_isa
bool any_isa(const Any &Value)
Definition:
Any.h:121
llvm::Type::isLabelTy
bool isLabelTy() const
Return true if this is 'label'.
Definition:
Type.h:182
TypedPointerTracking
Definition:
DXILPointerType.cpp:21
llvm::Type::getContext
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition:
Type.h:128
TypedPointerTracking::PointerTypes
DenseMap< Type *, std::unique_ptr< TypedPointerType > > PointerTypes
Definition:
DXILPointerType.cpp:24
llvm::Type::NumContainedTys
unsigned NumContainedTys
Keeps track of how many Type*'s there are in the ContainedTys list.
Definition:
Type.h:106
llvm::Any
Definition:
Any.h:28
llvm::Type::ContainedTys
Type *const * ContainedTys
A pointer to the array of Types contained by this Type.
Definition:
Type.h:113
Any.h
llvm::LLVMContext::getTargetData
llvm::Any & getTargetData() const
Optionally target-spcific data can be attached to the context for lifetime management and bypassing l...
Definition:
LLVMContext.cpp:378
LLVMContext.h
llvm::Type::isX86_AMXTy
bool isX86_AMXTy() const
Return true if this is X86 AMX.
Definition:
Type.h:176
TypedPointerTracking::TypedPointerTracking
TypedPointerTracking()
Definition:
DXILPointerType.cpp:23
llvm::dxil::TypedPointerType::get
static TypedPointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
Definition:
DXILPointerType.cpp:29
Generated on Sat Jun 25 2022 13:55:52 for LLVM by
1.8.17