[Alignment][NFC] Use MaybeAlign in AttrBuilder
[llvm-complete.git] / include / llvm / IR / GlobalIndirectSymbol.h
blobd996237aa3efb4c1cb4b59655f975c631d575b1c
1 //===- llvm/GlobalIndirectSymbol.h - GlobalIndirectSymbol class -*- C++ -*-===//
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 // This file contains the declaration of the GlobalIndirectSymbol class, which
10 // is a base class for GlobalAlias and GlobalIFunc. It contains all common code
11 // for aliases and ifuncs.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_IR_GLOBALINDIRECTSYMBOL_H
16 #define LLVM_IR_GLOBALINDIRECTSYMBOL_H
18 #include "llvm/IR/GlobalObject.h"
19 #include "llvm/IR/GlobalValue.h"
20 #include "llvm/IR/OperandTraits.h"
21 #include "llvm/IR/User.h"
22 #include "llvm/IR/Value.h"
23 #include "llvm/Support/Casting.h"
24 #include <cstddef>
26 namespace llvm {
28 class GlobalIndirectSymbol : public GlobalValue {
29 protected:
30 GlobalIndirectSymbol(Type *Ty, ValueTy VTy, unsigned AddressSpace,
31 LinkageTypes Linkage, const Twine &Name, Constant *Symbol);
33 public:
34 GlobalIndirectSymbol(const GlobalIndirectSymbol &) = delete;
35 GlobalIndirectSymbol &operator=(const GlobalIndirectSymbol &) = delete;
37 // allocate space for exactly one operand
38 void *operator new(size_t s) {
39 return User::operator new(s, 1);
42 /// Provide fast operand accessors
43 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
45 void copyAttributesFrom(const GlobalValue *Src) {
46 GlobalValue::copyAttributesFrom(Src);
49 /// These methods set and retrieve indirect symbol.
50 void setIndirectSymbol(Constant *Symbol) {
51 setOperand(0, Symbol);
53 const Constant *getIndirectSymbol() const {
54 return getOperand(0);
56 Constant *getIndirectSymbol() {
57 return const_cast<Constant *>(
58 static_cast<const GlobalIndirectSymbol *>(this)->getIndirectSymbol());
61 const GlobalObject *getBaseObject() const;
62 GlobalObject *getBaseObject() {
63 return const_cast<GlobalObject *>(
64 static_cast<const GlobalIndirectSymbol *>(this)->getBaseObject());
67 const GlobalObject *getBaseObject(const DataLayout &DL, APInt &Offset) const {
68 return dyn_cast<GlobalObject>(
69 getIndirectSymbol()->stripAndAccumulateInBoundsConstantOffsets(DL,
70 Offset));
72 GlobalObject *getBaseObject(const DataLayout &DL, APInt &Offset) {
73 return const_cast<GlobalObject *>(
74 static_cast<const GlobalIndirectSymbol *>(this)
75 ->getBaseObject(DL, Offset));
78 // Methods for support type inquiry through isa, cast, and dyn_cast:
79 static bool classof(const Value *V) {
80 return V->getValueID() == Value::GlobalAliasVal ||
81 V->getValueID() == Value::GlobalIFuncVal;
85 template <>
86 struct OperandTraits<GlobalIndirectSymbol> :
87 public FixedNumOperandTraits<GlobalIndirectSymbol, 1> {
90 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GlobalIndirectSymbol, Constant)
92 } // end namespace llvm
94 #endif // LLVM_IR_GLOBALINDIRECTSYMBOL_H