1 //===- Constant.cpp - The Constant classes of Sandbox IR ------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "llvm/SandboxIR/Constant.h"
10 #include "llvm/SandboxIR/Argument.h"
11 #include "llvm/SandboxIR/BasicBlock.h"
12 #include "llvm/SandboxIR/Context.h"
13 #include "llvm/SandboxIR/Function.h"
14 #include "llvm/Support/Compiler.h"
16 namespace llvm::sandboxir
{
19 void Constant::dumpOS(raw_ostream
&OS
) const {
25 ConstantInt
*ConstantInt::getTrue(Context
&Ctx
) {
26 auto *LLVMC
= llvm::ConstantInt::getTrue(Ctx
.LLVMCtx
);
27 return cast
<ConstantInt
>(Ctx
.getOrCreateConstant(LLVMC
));
29 ConstantInt
*ConstantInt::getFalse(Context
&Ctx
) {
30 auto *LLVMC
= llvm::ConstantInt::getFalse(Ctx
.LLVMCtx
);
31 return cast
<ConstantInt
>(Ctx
.getOrCreateConstant(LLVMC
));
33 ConstantInt
*ConstantInt::getBool(Context
&Ctx
, bool V
) {
34 auto *LLVMC
= llvm::ConstantInt::getBool(Ctx
.LLVMCtx
, V
);
35 return cast
<ConstantInt
>(Ctx
.getOrCreateConstant(LLVMC
));
37 Constant
*ConstantInt::getTrue(Type
*Ty
) {
38 auto *LLVMC
= llvm::ConstantInt::getTrue(Ty
->LLVMTy
);
39 return Ty
->getContext().getOrCreateConstant(LLVMC
);
41 Constant
*ConstantInt::getFalse(Type
*Ty
) {
42 auto *LLVMC
= llvm::ConstantInt::getFalse(Ty
->LLVMTy
);
43 return Ty
->getContext().getOrCreateConstant(LLVMC
);
45 Constant
*ConstantInt::getBool(Type
*Ty
, bool V
) {
46 auto *LLVMC
= llvm::ConstantInt::getBool(Ty
->LLVMTy
, V
);
47 return Ty
->getContext().getOrCreateConstant(LLVMC
);
49 ConstantInt
*ConstantInt::get(Type
*Ty
, uint64_t V
, bool IsSigned
) {
50 auto *LLVMC
= llvm::ConstantInt::get(Ty
->LLVMTy
, V
, IsSigned
);
51 return cast
<ConstantInt
>(Ty
->getContext().getOrCreateConstant(LLVMC
));
53 ConstantInt
*ConstantInt::get(IntegerType
*Ty
, uint64_t V
, bool IsSigned
) {
54 auto *LLVMC
= llvm::ConstantInt::get(Ty
->LLVMTy
, V
, IsSigned
);
55 return cast
<ConstantInt
>(Ty
->getContext().getOrCreateConstant(LLVMC
));
57 ConstantInt
*ConstantInt::getSigned(IntegerType
*Ty
, int64_t V
) {
59 llvm::ConstantInt::getSigned(cast
<llvm::IntegerType
>(Ty
->LLVMTy
), V
);
60 return cast
<ConstantInt
>(Ty
->getContext().getOrCreateConstant(LLVMC
));
62 Constant
*ConstantInt::getSigned(Type
*Ty
, int64_t V
) {
63 auto *LLVMC
= llvm::ConstantInt::getSigned(Ty
->LLVMTy
, V
);
64 return Ty
->getContext().getOrCreateConstant(LLVMC
);
66 ConstantInt
*ConstantInt::get(Context
&Ctx
, const APInt
&V
) {
67 auto *LLVMC
= llvm::ConstantInt::get(Ctx
.LLVMCtx
, V
);
68 return cast
<ConstantInt
>(Ctx
.getOrCreateConstant(LLVMC
));
70 ConstantInt
*ConstantInt::get(IntegerType
*Ty
, StringRef Str
, uint8_t Radix
) {
72 llvm::ConstantInt::get(cast
<llvm::IntegerType
>(Ty
->LLVMTy
), Str
, Radix
);
73 return cast
<ConstantInt
>(Ty
->getContext().getOrCreateConstant(LLVMC
));
75 Constant
*ConstantInt::get(Type
*Ty
, const APInt
&V
) {
76 auto *LLVMC
= llvm::ConstantInt::get(Ty
->LLVMTy
, V
);
77 return Ty
->getContext().getOrCreateConstant(LLVMC
);
79 IntegerType
*ConstantInt::getIntegerType() const {
80 auto *LLVMTy
= cast
<llvm::ConstantInt
>(Val
)->getIntegerType();
81 return cast
<IntegerType
>(Ctx
.getType(LLVMTy
));
84 bool ConstantInt::isValueValidForType(Type
*Ty
, uint64_t V
) {
85 return llvm::ConstantInt::isValueValidForType(Ty
->LLVMTy
, V
);
87 bool ConstantInt::isValueValidForType(Type
*Ty
, int64_t V
) {
88 return llvm::ConstantInt::isValueValidForType(Ty
->LLVMTy
, V
);
91 Constant
*ConstantFP::get(Type
*Ty
, double V
) {
92 auto *LLVMC
= llvm::ConstantFP::get(Ty
->LLVMTy
, V
);
93 return Ty
->getContext().getOrCreateConstant(LLVMC
);
96 Constant
*ConstantFP::get(Type
*Ty
, const APFloat
&V
) {
97 auto *LLVMC
= llvm::ConstantFP::get(Ty
->LLVMTy
, V
);
98 return Ty
->getContext().getOrCreateConstant(LLVMC
);
101 Constant
*ConstantFP::get(Type
*Ty
, StringRef Str
) {
102 auto *LLVMC
= llvm::ConstantFP::get(Ty
->LLVMTy
, Str
);
103 return Ty
->getContext().getOrCreateConstant(LLVMC
);
106 ConstantFP
*ConstantFP::get(const APFloat
&V
, Context
&Ctx
) {
107 auto *LLVMC
= llvm::ConstantFP::get(Ctx
.LLVMCtx
, V
);
108 return cast
<ConstantFP
>(Ctx
.getOrCreateConstant(LLVMC
));
111 Constant
*ConstantFP::getNaN(Type
*Ty
, bool Negative
, uint64_t Payload
) {
112 auto *LLVMC
= llvm::ConstantFP::getNaN(Ty
->LLVMTy
, Negative
, Payload
);
113 return cast
<Constant
>(Ty
->getContext().getOrCreateConstant(LLVMC
));
115 Constant
*ConstantFP::getQNaN(Type
*Ty
, bool Negative
, APInt
*Payload
) {
116 auto *LLVMC
= llvm::ConstantFP::getQNaN(Ty
->LLVMTy
, Negative
, Payload
);
117 return cast
<Constant
>(Ty
->getContext().getOrCreateConstant(LLVMC
));
119 Constant
*ConstantFP::getSNaN(Type
*Ty
, bool Negative
, APInt
*Payload
) {
120 auto *LLVMC
= llvm::ConstantFP::getSNaN(Ty
->LLVMTy
, Negative
, Payload
);
121 return cast
<Constant
>(Ty
->getContext().getOrCreateConstant(LLVMC
));
123 Constant
*ConstantFP::getZero(Type
*Ty
, bool Negative
) {
124 auto *LLVMC
= llvm::ConstantFP::getZero(Ty
->LLVMTy
, Negative
);
125 return cast
<Constant
>(Ty
->getContext().getOrCreateConstant(LLVMC
));
127 Constant
*ConstantFP::getNegativeZero(Type
*Ty
) {
128 auto *LLVMC
= llvm::ConstantFP::getNegativeZero(Ty
->LLVMTy
);
129 return cast
<Constant
>(Ty
->getContext().getOrCreateConstant(LLVMC
));
131 Constant
*ConstantFP::getInfinity(Type
*Ty
, bool Negative
) {
132 auto *LLVMC
= llvm::ConstantFP::getInfinity(Ty
->LLVMTy
, Negative
);
133 return cast
<Constant
>(Ty
->getContext().getOrCreateConstant(LLVMC
));
135 bool ConstantFP::isValueValidForType(Type
*Ty
, const APFloat
&V
) {
136 return llvm::ConstantFP::isValueValidForType(Ty
->LLVMTy
, V
);
139 Constant
*ConstantArray::get(ArrayType
*T
, ArrayRef
<Constant
*> V
) {
140 auto &Ctx
= T
->getContext();
141 SmallVector
<llvm::Constant
*> LLVMValues
;
142 LLVMValues
.reserve(V
.size());
144 LLVMValues
.push_back(cast
<llvm::Constant
>(Elm
->Val
));
146 llvm::ConstantArray::get(cast
<llvm::ArrayType
>(T
->LLVMTy
), LLVMValues
);
147 return cast
<ConstantArray
>(Ctx
.getOrCreateConstant(LLVMC
));
150 ArrayType
*ConstantArray::getType() const {
151 return cast
<ArrayType
>(
152 Ctx
.getType(cast
<llvm::ConstantArray
>(Val
)->getType()));
155 Constant
*ConstantStruct::get(StructType
*T
, ArrayRef
<Constant
*> V
) {
156 auto &Ctx
= T
->getContext();
157 SmallVector
<llvm::Constant
*> LLVMValues
;
158 LLVMValues
.reserve(V
.size());
160 LLVMValues
.push_back(cast
<llvm::Constant
>(Elm
->Val
));
162 llvm::ConstantStruct::get(cast
<llvm::StructType
>(T
->LLVMTy
), LLVMValues
);
163 return cast
<ConstantStruct
>(Ctx
.getOrCreateConstant(LLVMC
));
166 StructType
*ConstantStruct::getTypeForElements(Context
&Ctx
,
167 ArrayRef
<Constant
*> V
,
169 unsigned VecSize
= V
.size();
170 SmallVector
<Type
*, 16> EltTypes
;
171 EltTypes
.reserve(VecSize
);
172 for (Constant
*Elm
: V
)
173 EltTypes
.push_back(Elm
->getType());
174 return StructType::get(Ctx
, EltTypes
, Packed
);
177 ConstantAggregateZero
*ConstantAggregateZero::get(Type
*Ty
) {
178 auto *LLVMC
= llvm::ConstantAggregateZero::get(Ty
->LLVMTy
);
179 return cast
<ConstantAggregateZero
>(
180 Ty
->getContext().getOrCreateConstant(LLVMC
));
183 Constant
*ConstantAggregateZero::getSequentialElement() const {
184 return cast
<Constant
>(Ctx
.getValue(
185 cast
<llvm::ConstantAggregateZero
>(Val
)->getSequentialElement()));
187 Constant
*ConstantAggregateZero::getStructElement(unsigned Elt
) const {
188 return cast
<Constant
>(Ctx
.getValue(
189 cast
<llvm::ConstantAggregateZero
>(Val
)->getStructElement(Elt
)));
191 Constant
*ConstantAggregateZero::getElementValue(Constant
*C
) const {
192 return cast
<Constant
>(
193 Ctx
.getValue(cast
<llvm::ConstantAggregateZero
>(Val
)->getElementValue(
194 cast
<llvm::Constant
>(C
->Val
))));
196 Constant
*ConstantAggregateZero::getElementValue(unsigned Idx
) const {
197 return cast
<Constant
>(Ctx
.getValue(
198 cast
<llvm::ConstantAggregateZero
>(Val
)->getElementValue(Idx
)));
201 ConstantPointerNull
*ConstantPointerNull::get(PointerType
*Ty
) {
203 llvm::ConstantPointerNull::get(cast
<llvm::PointerType
>(Ty
->LLVMTy
));
204 return cast
<ConstantPointerNull
>(Ty
->getContext().getOrCreateConstant(LLVMC
));
207 PointerType
*ConstantPointerNull::getType() const {
208 return cast
<PointerType
>(
209 Ctx
.getType(cast
<llvm::ConstantPointerNull
>(Val
)->getType()));
212 UndefValue
*UndefValue::get(Type
*T
) {
213 auto *LLVMC
= llvm::UndefValue::get(T
->LLVMTy
);
214 return cast
<UndefValue
>(T
->getContext().getOrCreateConstant(LLVMC
));
217 UndefValue
*UndefValue::getSequentialElement() const {
218 return cast
<UndefValue
>(Ctx
.getOrCreateConstant(
219 cast
<llvm::UndefValue
>(Val
)->getSequentialElement()));
222 UndefValue
*UndefValue::getStructElement(unsigned Elt
) const {
223 return cast
<UndefValue
>(Ctx
.getOrCreateConstant(
224 cast
<llvm::UndefValue
>(Val
)->getStructElement(Elt
)));
227 UndefValue
*UndefValue::getElementValue(Constant
*C
) const {
228 return cast
<UndefValue
>(
229 Ctx
.getOrCreateConstant(cast
<llvm::UndefValue
>(Val
)->getElementValue(
230 cast
<llvm::Constant
>(C
->Val
))));
233 UndefValue
*UndefValue::getElementValue(unsigned Idx
) const {
234 return cast
<UndefValue
>(Ctx
.getOrCreateConstant(
235 cast
<llvm::UndefValue
>(Val
)->getElementValue(Idx
)));
238 PoisonValue
*PoisonValue::get(Type
*T
) {
239 auto *LLVMC
= llvm::PoisonValue::get(T
->LLVMTy
);
240 return cast
<PoisonValue
>(T
->getContext().getOrCreateConstant(LLVMC
));
243 PoisonValue
*PoisonValue::getSequentialElement() const {
244 return cast
<PoisonValue
>(Ctx
.getOrCreateConstant(
245 cast
<llvm::PoisonValue
>(Val
)->getSequentialElement()));
248 PoisonValue
*PoisonValue::getStructElement(unsigned Elt
) const {
249 return cast
<PoisonValue
>(Ctx
.getOrCreateConstant(
250 cast
<llvm::PoisonValue
>(Val
)->getStructElement(Elt
)));
253 PoisonValue
*PoisonValue::getElementValue(Constant
*C
) const {
254 return cast
<PoisonValue
>(
255 Ctx
.getOrCreateConstant(cast
<llvm::PoisonValue
>(Val
)->getElementValue(
256 cast
<llvm::Constant
>(C
->Val
))));
259 PoisonValue
*PoisonValue::getElementValue(unsigned Idx
) const {
260 return cast
<PoisonValue
>(Ctx
.getOrCreateConstant(
261 cast
<llvm::PoisonValue
>(Val
)->getElementValue(Idx
)));
264 void GlobalObject::setAlignment(MaybeAlign Align
) {
267 GenericSetter
<&GlobalObject::getAlign
, &GlobalObject::setAlignment
>>(
269 cast
<llvm::GlobalObject
>(Val
)->setAlignment(Align
);
272 void GlobalObject::setGlobalObjectSubClassData(unsigned V
) {
275 GenericSetter
<&GlobalObject::getGlobalObjectSubClassData
,
276 &GlobalObject::setGlobalObjectSubClassData
>>(this);
277 cast
<llvm::GlobalObject
>(Val
)->setGlobalObjectSubClassData(V
);
280 void GlobalObject::setSection(StringRef S
) {
283 GenericSetter
<&GlobalObject::getSection
, &GlobalObject::setSection
>>(
285 cast
<llvm::GlobalObject
>(Val
)->setSection(S
);
288 template <typename GlobalT
, typename LLVMGlobalT
, typename ParentT
,
289 typename LLVMParentT
>
290 GlobalT
&GlobalWithNodeAPI
<GlobalT
, LLVMGlobalT
, ParentT
, LLVMParentT
>::
291 LLVMGVToGV::operator()(LLVMGlobalT
&LLVMGV
) const {
292 return cast
<GlobalT
>(*Ctx
.getValue(&LLVMGV
));
295 // Explicit instantiations.
296 template class GlobalWithNodeAPI
<GlobalIFunc
, llvm::GlobalIFunc
, GlobalObject
,
298 template class GlobalWithNodeAPI
<Function
, llvm::Function
, GlobalObject
,
300 template class GlobalWithNodeAPI
<GlobalVariable
, llvm::GlobalVariable
,
301 GlobalObject
, llvm::GlobalObject
>;
302 template class GlobalWithNodeAPI
<GlobalAlias
, llvm::GlobalAlias
, GlobalValue
,
306 // These are needed for SandboxIRTest when building with LLVM_BUILD_LLVM_DYLIB
307 template LLVM_EXPORT_TEMPLATE GlobalIFunc
&
308 GlobalWithNodeAPI
<GlobalIFunc
, llvm::GlobalIFunc
, GlobalObject
,
309 llvm::GlobalObject
>::LLVMGVToGV::operator()(llvm::GlobalIFunc
312 template LLVM_EXPORT_TEMPLATE Function
&
313 GlobalWithNodeAPI
<Function
, llvm::Function
, GlobalObject
, llvm::GlobalObject
>::
314 LLVMGVToGV::operator()(llvm::Function
&LLVMGV
) const;
316 template LLVM_EXPORT_TEMPLATE GlobalVariable
&GlobalWithNodeAPI
<
317 GlobalVariable
, llvm::GlobalVariable
, GlobalObject
,
318 llvm::GlobalObject
>::LLVMGVToGV::operator()(llvm::GlobalVariable
&LLVMGV
)
320 template LLVM_EXPORT_TEMPLATE GlobalAlias
&
321 GlobalWithNodeAPI
<GlobalAlias
, llvm::GlobalAlias
, GlobalValue
,
322 llvm::GlobalValue
>::LLVMGVToGV::operator()(llvm::GlobalAlias
326 void GlobalIFunc::setResolver(Constant
*Resolver
) {
329 GenericSetter
<&GlobalIFunc::getResolver
, &GlobalIFunc::setResolver
>>(
331 cast
<llvm::GlobalIFunc
>(Val
)->setResolver(
332 cast
<llvm::Constant
>(Resolver
->Val
));
335 Constant
*GlobalIFunc::getResolver() const {
336 return Ctx
.getOrCreateConstant(cast
<llvm::GlobalIFunc
>(Val
)->getResolver());
339 Function
*GlobalIFunc::getResolverFunction() {
340 return cast
<Function
>(Ctx
.getOrCreateConstant(
341 cast
<llvm::GlobalIFunc
>(Val
)->getResolverFunction()));
345 GlobalVariable::LLVMGVToGV::operator()(llvm::GlobalVariable
&LLVMGV
) const {
346 return cast
<GlobalVariable
>(*Ctx
.getValue(&LLVMGV
));
349 Constant
*GlobalVariable::getInitializer() const {
350 return Ctx
.getOrCreateConstant(
351 cast
<llvm::GlobalVariable
>(Val
)->getInitializer());
354 void GlobalVariable::setInitializer(Constant
*InitVal
) {
356 .emplaceIfTracking
<GenericSetter
<&GlobalVariable::getInitializer
,
357 &GlobalVariable::setInitializer
>>(this);
358 cast
<llvm::GlobalVariable
>(Val
)->setInitializer(
359 cast
<llvm::Constant
>(InitVal
->Val
));
362 void GlobalVariable::setConstant(bool V
) {
364 .emplaceIfTracking
<GenericSetter
<&GlobalVariable::isConstant
,
365 &GlobalVariable::setConstant
>>(this);
366 cast
<llvm::GlobalVariable
>(Val
)->setConstant(V
);
369 void GlobalVariable::setExternallyInitialized(bool V
) {
372 GenericSetter
<&GlobalVariable::isExternallyInitialized
,
373 &GlobalVariable::setExternallyInitialized
>>(this);
374 cast
<llvm::GlobalVariable
>(Val
)->setExternallyInitialized(V
);
377 void GlobalAlias::setAliasee(Constant
*Aliasee
) {
380 GenericSetter
<&GlobalAlias::getAliasee
, &GlobalAlias::setAliasee
>>(
382 cast
<llvm::GlobalAlias
>(Val
)->setAliasee(cast
<llvm::Constant
>(Aliasee
->Val
));
385 Constant
*GlobalAlias::getAliasee() const {
386 return cast
<Constant
>(
387 Ctx
.getOrCreateConstant(cast
<llvm::GlobalAlias
>(Val
)->getAliasee()));
390 const GlobalObject
*GlobalAlias::getAliaseeObject() const {
391 return cast
<GlobalObject
>(Ctx
.getOrCreateConstant(
392 cast
<llvm::GlobalAlias
>(Val
)->getAliaseeObject()));
395 void GlobalValue::setUnnamedAddr(UnnamedAddr V
) {
397 .emplaceIfTracking
<GenericSetter
<&GlobalValue::getUnnamedAddr
,
398 &GlobalValue::setUnnamedAddr
>>(this);
399 cast
<llvm::GlobalValue
>(Val
)->setUnnamedAddr(V
);
402 void GlobalValue::setVisibility(VisibilityTypes V
) {
404 .emplaceIfTracking
<GenericSetter
<&GlobalValue::getVisibility
,
405 &GlobalValue::setVisibility
>>(this);
406 cast
<llvm::GlobalValue
>(Val
)->setVisibility(V
);
409 NoCFIValue
*NoCFIValue::get(GlobalValue
*GV
) {
410 auto *LLVMC
= llvm::NoCFIValue::get(cast
<llvm::GlobalValue
>(GV
->Val
));
411 return cast
<NoCFIValue
>(GV
->getContext().getOrCreateConstant(LLVMC
));
414 GlobalValue
*NoCFIValue::getGlobalValue() const {
415 auto *LLVMC
= cast
<llvm::NoCFIValue
>(Val
)->getGlobalValue();
416 return cast
<GlobalValue
>(Ctx
.getOrCreateConstant(LLVMC
));
419 PointerType
*NoCFIValue::getType() const {
420 return cast
<PointerType
>(Ctx
.getType(cast
<llvm::NoCFIValue
>(Val
)->getType()));
423 ConstantPtrAuth
*ConstantPtrAuth::get(Constant
*Ptr
, ConstantInt
*Key
,
424 ConstantInt
*Disc
, Constant
*AddrDisc
) {
425 auto *LLVMC
= llvm::ConstantPtrAuth::get(
426 cast
<llvm::Constant
>(Ptr
->Val
), cast
<llvm::ConstantInt
>(Key
->Val
),
427 cast
<llvm::ConstantInt
>(Disc
->Val
), cast
<llvm::Constant
>(AddrDisc
->Val
));
428 return cast
<ConstantPtrAuth
>(Ptr
->getContext().getOrCreateConstant(LLVMC
));
431 Constant
*ConstantPtrAuth::getPointer() const {
432 return Ctx
.getOrCreateConstant(
433 cast
<llvm::ConstantPtrAuth
>(Val
)->getPointer());
436 ConstantInt
*ConstantPtrAuth::getKey() const {
437 return cast
<ConstantInt
>(
438 Ctx
.getOrCreateConstant(cast
<llvm::ConstantPtrAuth
>(Val
)->getKey()));
441 ConstantInt
*ConstantPtrAuth::getDiscriminator() const {
442 return cast
<ConstantInt
>(Ctx
.getOrCreateConstant(
443 cast
<llvm::ConstantPtrAuth
>(Val
)->getDiscriminator()));
446 Constant
*ConstantPtrAuth::getAddrDiscriminator() const {
447 return Ctx
.getOrCreateConstant(
448 cast
<llvm::ConstantPtrAuth
>(Val
)->getAddrDiscriminator());
451 ConstantPtrAuth
*ConstantPtrAuth::getWithSameSchema(Constant
*Pointer
) const {
452 auto *LLVMC
= cast
<llvm::ConstantPtrAuth
>(Val
)->getWithSameSchema(
453 cast
<llvm::Constant
>(Pointer
->Val
));
454 return cast
<ConstantPtrAuth
>(Ctx
.getOrCreateConstant(LLVMC
));
457 BlockAddress
*BlockAddress::get(Function
*F
, BasicBlock
*BB
) {
458 auto *LLVMC
= llvm::BlockAddress::get(cast
<llvm::Function
>(F
->Val
),
459 cast
<llvm::BasicBlock
>(BB
->Val
));
460 return cast
<BlockAddress
>(F
->getContext().getOrCreateConstant(LLVMC
));
463 BlockAddress
*BlockAddress::get(BasicBlock
*BB
) {
464 auto *LLVMC
= llvm::BlockAddress::get(cast
<llvm::BasicBlock
>(BB
->Val
));
465 return cast
<BlockAddress
>(BB
->getContext().getOrCreateConstant(LLVMC
));
468 BlockAddress
*BlockAddress::lookup(const BasicBlock
*BB
) {
469 auto *LLVMC
= llvm::BlockAddress::lookup(cast
<llvm::BasicBlock
>(BB
->Val
));
470 return cast_or_null
<BlockAddress
>(BB
->getContext().getValue(LLVMC
));
473 Function
*BlockAddress::getFunction() const {
474 return cast
<Function
>(
475 Ctx
.getValue(cast
<llvm::BlockAddress
>(Val
)->getFunction()));
478 BasicBlock
*BlockAddress::getBasicBlock() const {
479 return cast
<BasicBlock
>(
480 Ctx
.getValue(cast
<llvm::BlockAddress
>(Val
)->getBasicBlock()));
483 DSOLocalEquivalent
*DSOLocalEquivalent::get(GlobalValue
*GV
) {
484 auto *LLVMC
= llvm::DSOLocalEquivalent::get(cast
<llvm::GlobalValue
>(GV
->Val
));
485 return cast
<DSOLocalEquivalent
>(GV
->getContext().getValue(LLVMC
));
488 GlobalValue
*DSOLocalEquivalent::getGlobalValue() const {
489 return cast
<GlobalValue
>(
490 Ctx
.getValue(cast
<llvm::DSOLocalEquivalent
>(Val
)->getGlobalValue()));
493 } // namespace llvm::sandboxir