1//===- Constant.cpp - The Constant classes of Sandbox IR ------------------===//
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#include "llvm/SandboxIR/Constant.h"
10#include "llvm/SandboxIR/BasicBlock.h"
11#include "llvm/SandboxIR/Context.h"
12#include "llvm/SandboxIR/Function.h"
13#include "llvm/Support/Compiler.h"
14
15namespace llvm::sandboxir {
16
17#ifndef NDEBUG
18void Constant::dumpOS(raw_ostream &OS) const {
19 dumpCommonPrefix(OS);
20 dumpCommonSuffix(OS);
21}
22#endif // NDEBUG
23
24ConstantInt *ConstantInt::getTrue(Context &Ctx) {
25 auto *LLVMC = llvm::ConstantInt::getTrue(Context&: Ctx.LLVMCtx);
26 return cast<ConstantInt>(Val: Ctx.getOrCreateConstant(LLVMC));
27}
28ConstantInt *ConstantInt::getFalse(Context &Ctx) {
29 auto *LLVMC = llvm::ConstantInt::getFalse(Context&: Ctx.LLVMCtx);
30 return cast<ConstantInt>(Val: Ctx.getOrCreateConstant(LLVMC));
31}
32ConstantInt *ConstantInt::getBool(Context &Ctx, bool V) {
33 auto *LLVMC = llvm::ConstantInt::getBool(Context&: Ctx.LLVMCtx, V);
34 return cast<ConstantInt>(Val: Ctx.getOrCreateConstant(LLVMC));
35}
36Constant *ConstantInt::getTrue(Type *Ty) {
37 auto *LLVMC = llvm::ConstantInt::getTrue(Ty: Ty->LLVMTy);
38 return Ty->getContext().getOrCreateConstant(LLVMC);
39}
40Constant *ConstantInt::getFalse(Type *Ty) {
41 auto *LLVMC = llvm::ConstantInt::getFalse(Ty: Ty->LLVMTy);
42 return Ty->getContext().getOrCreateConstant(LLVMC);
43}
44Constant *ConstantInt::getBool(Type *Ty, bool V) {
45 auto *LLVMC = llvm::ConstantInt::getBool(Ty: Ty->LLVMTy, V);
46 return Ty->getContext().getOrCreateConstant(LLVMC);
47}
48Constant *ConstantInt::get(Type *Ty, uint64_t V, bool IsSigned) {
49 auto *LLVMC = llvm::ConstantInt::get(Ty: Ty->LLVMTy, V, IsSigned);
50 return Ty->getContext().getOrCreateConstant(LLVMC);
51}
52ConstantInt *ConstantInt::get(IntegerType *Ty, uint64_t V, bool IsSigned) {
53 auto *LLVMC = llvm::ConstantInt::get(Ty: Ty->LLVMTy, V, IsSigned);
54 return cast<ConstantInt>(Val: Ty->getContext().getOrCreateConstant(LLVMC));
55}
56ConstantInt *ConstantInt::getSigned(IntegerType *Ty, int64_t V) {
57 auto *LLVMC =
58 llvm::ConstantInt::getSigned(Ty: cast<llvm::IntegerType>(Val: Ty->LLVMTy), V);
59 return cast<ConstantInt>(Val: Ty->getContext().getOrCreateConstant(LLVMC));
60}
61Constant *ConstantInt::getSigned(Type *Ty, int64_t V) {
62 auto *LLVMC = llvm::ConstantInt::getSigned(Ty: Ty->LLVMTy, V);
63 return Ty->getContext().getOrCreateConstant(LLVMC);
64}
65ConstantInt *ConstantInt::get(Context &Ctx, const APInt &V) {
66 auto *LLVMC = llvm::ConstantInt::get(Context&: Ctx.LLVMCtx, V);
67 return cast<ConstantInt>(Val: Ctx.getOrCreateConstant(LLVMC));
68}
69ConstantInt *ConstantInt::get(IntegerType *Ty, StringRef Str, uint8_t Radix) {
70 auto *LLVMC =
71 llvm::ConstantInt::get(Ty: cast<llvm::IntegerType>(Val: Ty->LLVMTy), Str, Radix);
72 return cast<ConstantInt>(Val: Ty->getContext().getOrCreateConstant(LLVMC));
73}
74Constant *ConstantInt::get(Type *Ty, const APInt &V) {
75 auto *LLVMC = llvm::ConstantInt::get(Ty: Ty->LLVMTy, V);
76 return Ty->getContext().getOrCreateConstant(LLVMC);
77}
78IntegerType *ConstantInt::getIntegerType() const {
79 auto *LLVMTy = cast<llvm::ConstantInt>(Val)->getIntegerType();
80 return cast<IntegerType>(Val: Ctx.getType(LLVMTy));
81}
82
83bool ConstantInt::isValueValidForType(Type *Ty, uint64_t V) {
84 return llvm::ConstantInt::isValueValidForType(Ty: Ty->LLVMTy, V);
85}
86bool ConstantInt::isValueValidForType(Type *Ty, int64_t V) {
87 return llvm::ConstantInt::isValueValidForType(Ty: Ty->LLVMTy, V);
88}
89
90Constant *ConstantFP::get(Type *Ty, double V) {
91 auto *LLVMC = llvm::ConstantFP::get(Ty: Ty->LLVMTy, V);
92 return Ty->getContext().getOrCreateConstant(LLVMC);
93}
94
95Constant *ConstantFP::get(Type *Ty, const APFloat &V) {
96 auto *LLVMC = llvm::ConstantFP::get(Ty: Ty->LLVMTy, V);
97 return Ty->getContext().getOrCreateConstant(LLVMC);
98}
99
100Constant *ConstantFP::get(Type *Ty, StringRef Str) {
101 auto *LLVMC = llvm::ConstantFP::get(Ty: Ty->LLVMTy, Str);
102 return Ty->getContext().getOrCreateConstant(LLVMC);
103}
104
105ConstantFP *ConstantFP::get(const APFloat &V, Context &Ctx) {
106 auto *LLVMC = llvm::ConstantFP::get(Context&: Ctx.LLVMCtx, V);
107 return cast<ConstantFP>(Val: Ctx.getOrCreateConstant(LLVMC));
108}
109
110Constant *ConstantFP::getNaN(Type *Ty, bool Negative, uint64_t Payload) {
111 auto *LLVMC = llvm::ConstantFP::getNaN(Ty: Ty->LLVMTy, Negative, Payload);
112 return cast<Constant>(Val: Ty->getContext().getOrCreateConstant(LLVMC));
113}
114Constant *ConstantFP::getQNaN(Type *Ty, bool Negative, APInt *Payload) {
115 auto *LLVMC = llvm::ConstantFP::getQNaN(Ty: Ty->LLVMTy, Negative, Payload);
116 return cast<Constant>(Val: Ty->getContext().getOrCreateConstant(LLVMC));
117}
118Constant *ConstantFP::getSNaN(Type *Ty, bool Negative, APInt *Payload) {
119 auto *LLVMC = llvm::ConstantFP::getSNaN(Ty: Ty->LLVMTy, Negative, Payload);
120 return cast<Constant>(Val: Ty->getContext().getOrCreateConstant(LLVMC));
121}
122Constant *ConstantFP::getZero(Type *Ty, bool Negative) {
123 auto *LLVMC = llvm::ConstantFP::getZero(Ty: Ty->LLVMTy, Negative);
124 return cast<Constant>(Val: Ty->getContext().getOrCreateConstant(LLVMC));
125}
126Constant *ConstantFP::getNegativeZero(Type *Ty) {
127 auto *LLVMC = llvm::ConstantFP::getNegativeZero(Ty: Ty->LLVMTy);
128 return cast<Constant>(Val: Ty->getContext().getOrCreateConstant(LLVMC));
129}
130Constant *ConstantFP::getInfinity(Type *Ty, bool Negative) {
131 auto *LLVMC = llvm::ConstantFP::getInfinity(Ty: Ty->LLVMTy, Negative);
132 return cast<Constant>(Val: Ty->getContext().getOrCreateConstant(LLVMC));
133}
134bool ConstantFP::isValueValidForType(Type *Ty, const APFloat &V) {
135 return llvm::ConstantFP::isValueValidForType(Ty: Ty->LLVMTy, V);
136}
137
138Constant *ConstantArray::get(ArrayType *T, ArrayRef<Constant *> V) {
139 auto &Ctx = T->getContext();
140 SmallVector<llvm::Constant *> LLVMValues;
141 LLVMValues.reserve(N: V.size());
142 for (auto *Elm : V)
143 LLVMValues.push_back(Elt: cast<llvm::Constant>(Val: Elm->Val));
144 auto *LLVMC =
145 llvm::ConstantArray::get(T: cast<llvm::ArrayType>(Val: T->LLVMTy), V: LLVMValues);
146 return cast<ConstantArray>(Val: Ctx.getOrCreateConstant(LLVMC));
147}
148
149ArrayType *ConstantArray::getType() const {
150 return cast<ArrayType>(
151 Val: Ctx.getType(LLVMTy: cast<llvm::ConstantArray>(Val)->getType()));
152}
153
154Constant *ConstantStruct::get(StructType *T, ArrayRef<Constant *> V) {
155 auto &Ctx = T->getContext();
156 SmallVector<llvm::Constant *> LLVMValues;
157 LLVMValues.reserve(N: V.size());
158 for (auto *Elm : V)
159 LLVMValues.push_back(Elt: cast<llvm::Constant>(Val: Elm->Val));
160 auto *LLVMC =
161 llvm::ConstantStruct::get(T: cast<llvm::StructType>(Val: T->LLVMTy), V: LLVMValues);
162 return cast<ConstantStruct>(Val: Ctx.getOrCreateConstant(LLVMC));
163}
164
165StructType *ConstantStruct::getTypeForElements(Context &Ctx,
166 ArrayRef<Constant *> V,
167 bool Packed) {
168 unsigned VecSize = V.size();
169 SmallVector<Type *, 16> EltTypes;
170 EltTypes.reserve(N: VecSize);
171 for (Constant *Elm : V)
172 EltTypes.push_back(Elt: Elm->getType());
173 return StructType::get(Ctx, Elements: EltTypes, IsPacked: Packed);
174}
175
176Constant *ConstantVector::get(ArrayRef<Constant *> V) {
177 assert(!V.empty() && "Expected non-empty V!");
178 auto &Ctx = V[0]->getContext();
179 SmallVector<llvm::Constant *, 8> LLVMV;
180 LLVMV.reserve(N: V.size());
181 for (auto *Elm : V)
182 LLVMV.push_back(Elt: cast<llvm::Constant>(Val: Elm->Val));
183 return Ctx.getOrCreateConstant(LLVMC: llvm::ConstantVector::get(V: LLVMV));
184}
185
186Constant *ConstantVector::getSplat(ElementCount EC, Constant *Elt) {
187 auto *LLVMElt = cast<llvm::Constant>(Val: Elt->Val);
188 auto &Ctx = Elt->getContext();
189 return Ctx.getOrCreateConstant(LLVMC: llvm::ConstantVector::getSplat(EC, Elt: LLVMElt));
190}
191
192Constant *ConstantVector::getSplatValue(bool AllowPoison) const {
193 auto *LLVMSplatValue = cast_or_null<llvm::Constant>(
194 Val: cast<llvm::ConstantVector>(Val)->getSplatValue(AllowPoison));
195 return LLVMSplatValue ? Ctx.getOrCreateConstant(LLVMC: LLVMSplatValue) : nullptr;
196}
197
198ConstantAggregateZero *ConstantAggregateZero::get(Type *Ty) {
199 auto *LLVMC = llvm::ConstantAggregateZero::get(Ty: Ty->LLVMTy);
200 return cast<ConstantAggregateZero>(
201 Val: Ty->getContext().getOrCreateConstant(LLVMC));
202}
203
204Constant *ConstantAggregateZero::getSequentialElement() const {
205 return cast<Constant>(Val: Ctx.getValue(
206 V: cast<llvm::ConstantAggregateZero>(Val)->getSequentialElement()));
207}
208Constant *ConstantAggregateZero::getStructElement(unsigned Elt) const {
209 return cast<Constant>(Val: Ctx.getValue(
210 V: cast<llvm::ConstantAggregateZero>(Val)->getStructElement(Elt)));
211}
212Constant *ConstantAggregateZero::getElementValue(Constant *C) const {
213 return cast<Constant>(
214 Val: Ctx.getValue(V: cast<llvm::ConstantAggregateZero>(Val)->getElementValue(
215 C: cast<llvm::Constant>(Val: C->Val))));
216}
217Constant *ConstantAggregateZero::getElementValue(unsigned Idx) const {
218 return cast<Constant>(Val: Ctx.getValue(
219 V: cast<llvm::ConstantAggregateZero>(Val)->getElementValue(Idx)));
220}
221
222ConstantPointerNull *ConstantPointerNull::get(PointerType *Ty) {
223 auto *LLVMC =
224 llvm::ConstantPointerNull::get(T: cast<llvm::PointerType>(Val: Ty->LLVMTy));
225 return cast<ConstantPointerNull>(Val: Ty->getContext().getOrCreateConstant(LLVMC));
226}
227
228Type *ConstantPointerNull::getType() const {
229 return Ctx.getType(LLVMTy: cast<llvm::ConstantPointerNull>(Val)->getType());
230}
231
232PointerType *ConstantPointerNull::getPointerType() const {
233 return cast<PointerType>(
234 Val: Ctx.getType(LLVMTy: cast<llvm::ConstantPointerNull>(Val)->getPointerType()));
235}
236
237UndefValue *UndefValue::get(Type *T) {
238 auto *LLVMC = llvm::UndefValue::get(T: T->LLVMTy);
239 return cast<UndefValue>(Val: T->getContext().getOrCreateConstant(LLVMC));
240}
241
242UndefValue *UndefValue::getSequentialElement() const {
243 return cast<UndefValue>(Val: Ctx.getOrCreateConstant(
244 LLVMC: cast<llvm::UndefValue>(Val)->getSequentialElement()));
245}
246
247UndefValue *UndefValue::getStructElement(unsigned Elt) const {
248 return cast<UndefValue>(Val: Ctx.getOrCreateConstant(
249 LLVMC: cast<llvm::UndefValue>(Val)->getStructElement(Elt)));
250}
251
252UndefValue *UndefValue::getElementValue(Constant *C) const {
253 return cast<UndefValue>(
254 Val: Ctx.getOrCreateConstant(LLVMC: cast<llvm::UndefValue>(Val)->getElementValue(
255 C: cast<llvm::Constant>(Val: C->Val))));
256}
257
258UndefValue *UndefValue::getElementValue(unsigned Idx) const {
259 return cast<UndefValue>(Val: Ctx.getOrCreateConstant(
260 LLVMC: cast<llvm::UndefValue>(Val)->getElementValue(Idx)));
261}
262
263PoisonValue *PoisonValue::get(Type *T) {
264 auto *LLVMC = llvm::PoisonValue::get(T: T->LLVMTy);
265 return cast<PoisonValue>(Val: T->getContext().getOrCreateConstant(LLVMC));
266}
267
268PoisonValue *PoisonValue::getSequentialElement() const {
269 return cast<PoisonValue>(Val: Ctx.getOrCreateConstant(
270 LLVMC: cast<llvm::PoisonValue>(Val)->getSequentialElement()));
271}
272
273PoisonValue *PoisonValue::getStructElement(unsigned Elt) const {
274 return cast<PoisonValue>(Val: Ctx.getOrCreateConstant(
275 LLVMC: cast<llvm::PoisonValue>(Val)->getStructElement(Elt)));
276}
277
278PoisonValue *PoisonValue::getElementValue(Constant *C) const {
279 return cast<PoisonValue>(
280 Val: Ctx.getOrCreateConstant(LLVMC: cast<llvm::PoisonValue>(Val)->getElementValue(
281 C: cast<llvm::Constant>(Val: C->Val))));
282}
283
284PoisonValue *PoisonValue::getElementValue(unsigned Idx) const {
285 return cast<PoisonValue>(Val: Ctx.getOrCreateConstant(
286 LLVMC: cast<llvm::PoisonValue>(Val)->getElementValue(Idx)));
287}
288
289void GlobalVariable::setAlignment(MaybeAlign Align) {
290 Ctx.getTracker()
291 .emplaceIfTracking<GenericSetter<&GlobalVariable::getAlign,
292 &GlobalVariable::setAlignment>>(Args: this);
293 cast<llvm::GlobalVariable>(Val)->setAlignment(Align);
294}
295
296void GlobalObject::setSection(StringRef S) {
297 Ctx.getTracker()
298 .emplaceIfTracking<
299 GenericSetter<&GlobalObject::getSection, &GlobalObject::setSection>>(
300 Args: this);
301 cast<llvm::GlobalObject>(Val)->setSection(S);
302}
303
304template <typename GlobalT, typename LLVMGlobalT, typename ParentT,
305 typename LLVMParentT>
306GlobalT &GlobalWithNodeAPI<GlobalT, LLVMGlobalT, ParentT, LLVMParentT>::
307 LLVMGVToGV::operator()(LLVMGlobalT &LLVMGV) const {
308 return cast<GlobalT>(*Ctx.getValue(&LLVMGV));
309}
310
311// Explicit instantiations.
312template class LLVM_EXPORT_TEMPLATE GlobalWithNodeAPI<
313 GlobalIFunc, llvm::GlobalIFunc, GlobalObject, llvm::GlobalObject>;
314template class LLVM_EXPORT_TEMPLATE GlobalWithNodeAPI<
315 Function, llvm::Function, GlobalObject, llvm::GlobalObject>;
316template class LLVM_EXPORT_TEMPLATE GlobalWithNodeAPI<
317 GlobalVariable, llvm::GlobalVariable, GlobalObject, llvm::GlobalObject>;
318template class LLVM_EXPORT_TEMPLATE GlobalWithNodeAPI<
319 GlobalAlias, llvm::GlobalAlias, GlobalValue, llvm::GlobalValue>;
320
321void GlobalIFunc::setResolver(Constant *Resolver) {
322 Ctx.getTracker()
323 .emplaceIfTracking<
324 GenericSetter<&GlobalIFunc::getResolver, &GlobalIFunc::setResolver>>(
325 Args: this);
326 cast<llvm::GlobalIFunc>(Val)->setResolver(
327 cast<llvm::Constant>(Val: Resolver->Val));
328}
329
330Constant *GlobalIFunc::getResolver() const {
331 return Ctx.getOrCreateConstant(LLVMC: cast<llvm::GlobalIFunc>(Val)->getResolver());
332}
333
334Function *GlobalIFunc::getResolverFunction() {
335 return cast<Function>(Val: Ctx.getOrCreateConstant(
336 LLVMC: cast<llvm::GlobalIFunc>(Val)->getResolverFunction()));
337}
338
339GlobalVariable &
340GlobalVariable::LLVMGVToGV::operator()(llvm::GlobalVariable &LLVMGV) const {
341 return cast<GlobalVariable>(Val&: *Ctx.getValue(V: &LLVMGV));
342}
343
344Constant *GlobalVariable::getInitializer() const {
345 return Ctx.getOrCreateConstant(
346 LLVMC: cast<llvm::GlobalVariable>(Val)->getInitializer());
347}
348
349void GlobalVariable::setInitializer(Constant *InitVal) {
350 Ctx.getTracker()
351 .emplaceIfTracking<GenericSetter<&GlobalVariable::getInitializer,
352 &GlobalVariable::setInitializer>>(Args: this);
353 cast<llvm::GlobalVariable>(Val)->setInitializer(
354 cast<llvm::Constant>(Val: InitVal->Val));
355}
356
357void GlobalVariable::setConstant(bool V) {
358 Ctx.getTracker()
359 .emplaceIfTracking<GenericSetter<&GlobalVariable::isConstant,
360 &GlobalVariable::setConstant>>(Args: this);
361 cast<llvm::GlobalVariable>(Val)->setConstant(V);
362}
363
364void GlobalVariable::setExternallyInitialized(bool V) {
365 Ctx.getTracker()
366 .emplaceIfTracking<
367 GenericSetter<&GlobalVariable::isExternallyInitialized,
368 &GlobalVariable::setExternallyInitialized>>(Args: this);
369 cast<llvm::GlobalVariable>(Val)->setExternallyInitialized(V);
370}
371
372void GlobalAlias::setAliasee(Constant *Aliasee) {
373 Ctx.getTracker()
374 .emplaceIfTracking<
375 GenericSetter<&GlobalAlias::getAliasee, &GlobalAlias::setAliasee>>(
376 Args: this);
377 cast<llvm::GlobalAlias>(Val)->setAliasee(cast<llvm::Constant>(Val: Aliasee->Val));
378}
379
380Constant *GlobalAlias::getAliasee() const {
381 return cast<Constant>(
382 Val: Ctx.getOrCreateConstant(LLVMC: cast<llvm::GlobalAlias>(Val)->getAliasee()));
383}
384
385const GlobalObject *GlobalAlias::getAliaseeObject() const {
386 return cast<GlobalObject>(Val: Ctx.getOrCreateConstant(
387 LLVMC: cast<llvm::GlobalAlias>(Val)->getAliaseeObject()));
388}
389
390void GlobalValue::setUnnamedAddr(UnnamedAddr V) {
391 Ctx.getTracker()
392 .emplaceIfTracking<GenericSetter<&GlobalValue::getUnnamedAddr,
393 &GlobalValue::setUnnamedAddr>>(Args: this);
394 cast<llvm::GlobalValue>(Val)->setUnnamedAddr(V);
395}
396
397void GlobalValue::setVisibility(VisibilityTypes V) {
398 Ctx.getTracker()
399 .emplaceIfTracking<GenericSetter<&GlobalValue::getVisibility,
400 &GlobalValue::setVisibility>>(Args: this);
401 cast<llvm::GlobalValue>(Val)->setVisibility(V);
402}
403
404NoCFIValue *NoCFIValue::get(GlobalValue *GV) {
405 auto *LLVMC = llvm::NoCFIValue::get(GV: cast<llvm::GlobalValue>(Val: GV->Val));
406 return cast<NoCFIValue>(Val: GV->getContext().getOrCreateConstant(LLVMC));
407}
408
409GlobalValue *NoCFIValue::getGlobalValue() const {
410 auto *LLVMC = cast<llvm::NoCFIValue>(Val)->getGlobalValue();
411 return cast<GlobalValue>(Val: Ctx.getOrCreateConstant(LLVMC));
412}
413
414PointerType *NoCFIValue::getType() const {
415 return cast<PointerType>(Val: Ctx.getType(LLVMTy: cast<llvm::NoCFIValue>(Val)->getType()));
416}
417
418ConstantPtrAuth *ConstantPtrAuth::get(Constant *Ptr, ConstantInt *Key,
419 ConstantInt *Disc, Constant *AddrDisc,
420 Constant *DeactivationSymbol) {
421 auto *LLVMC = llvm::ConstantPtrAuth::get(
422 Ptr: cast<llvm::Constant>(Val: Ptr->Val), Key: cast<llvm::ConstantInt>(Val: Key->Val),
423 Disc: cast<llvm::ConstantInt>(Val: Disc->Val), AddrDisc: cast<llvm::Constant>(Val: AddrDisc->Val),
424 DeactivationSymbol: cast<llvm::Constant>(Val: DeactivationSymbol->Val));
425 return cast<ConstantPtrAuth>(Val: Ptr->getContext().getOrCreateConstant(LLVMC));
426}
427
428Constant *ConstantPtrAuth::getPointer() const {
429 return Ctx.getOrCreateConstant(
430 LLVMC: cast<llvm::ConstantPtrAuth>(Val)->getPointer());
431}
432
433ConstantInt *ConstantPtrAuth::getKey() const {
434 return cast<ConstantInt>(
435 Val: Ctx.getOrCreateConstant(LLVMC: cast<llvm::ConstantPtrAuth>(Val)->getKey()));
436}
437
438ConstantInt *ConstantPtrAuth::getDiscriminator() const {
439 return cast<ConstantInt>(Val: Ctx.getOrCreateConstant(
440 LLVMC: cast<llvm::ConstantPtrAuth>(Val)->getDiscriminator()));
441}
442
443Constant *ConstantPtrAuth::getAddrDiscriminator() const {
444 return Ctx.getOrCreateConstant(
445 LLVMC: cast<llvm::ConstantPtrAuth>(Val)->getAddrDiscriminator());
446}
447
448Constant *ConstantPtrAuth::getDeactivationSymbol() const {
449 return Ctx.getOrCreateConstant(
450 LLVMC: cast<llvm::ConstantPtrAuth>(Val)->getDeactivationSymbol());
451}
452
453ConstantPtrAuth *ConstantPtrAuth::getWithSameSchema(Constant *Pointer) const {
454 auto *LLVMC = cast<llvm::ConstantPtrAuth>(Val)->getWithSameSchema(
455 Pointer: cast<llvm::Constant>(Val: Pointer->Val));
456 return cast<ConstantPtrAuth>(Val: Ctx.getOrCreateConstant(LLVMC));
457}
458
459BlockAddress *BlockAddress::get(Function *F, BasicBlock *BB) {
460 auto *LLVMC = llvm::BlockAddress::get(F: cast<llvm::Function>(Val: F->Val),
461 BB: cast<llvm::BasicBlock>(Val: BB->Val));
462 return cast<BlockAddress>(Val: F->getContext().getOrCreateConstant(LLVMC));
463}
464
465BlockAddress *BlockAddress::get(BasicBlock *BB) {
466 auto *LLVMC = llvm::BlockAddress::get(BB: cast<llvm::BasicBlock>(Val: BB->Val));
467 return cast<BlockAddress>(Val: BB->getContext().getOrCreateConstant(LLVMC));
468}
469
470BlockAddress *BlockAddress::lookup(const BasicBlock *BB) {
471 auto *LLVMC = llvm::BlockAddress::lookup(BB: cast<llvm::BasicBlock>(Val: BB->Val));
472 return cast_or_null<BlockAddress>(Val: BB->getContext().getValue(V: LLVMC));
473}
474
475Function *BlockAddress::getFunction() const {
476 return cast<Function>(
477 Val: Ctx.getValue(V: cast<llvm::BlockAddress>(Val)->getFunction()));
478}
479
480BasicBlock *BlockAddress::getBasicBlock() const {
481 return cast<BasicBlock>(
482 Val: Ctx.getValue(V: cast<llvm::BlockAddress>(Val)->getBasicBlock()));
483}
484
485DSOLocalEquivalent *DSOLocalEquivalent::get(GlobalValue *GV) {
486 auto *LLVMC = llvm::DSOLocalEquivalent::get(GV: cast<llvm::GlobalValue>(Val: GV->Val));
487 return cast<DSOLocalEquivalent>(Val: GV->getContext().getValue(V: LLVMC));
488}
489
490GlobalValue *DSOLocalEquivalent::getGlobalValue() const {
491 return cast<GlobalValue>(
492 Val: Ctx.getValue(V: cast<llvm::DSOLocalEquivalent>(Val)->getGlobalValue()));
493}
494
495} // namespace llvm::sandboxir
496