1 //===- llvm/GlobalIndirectSymbol.h - GlobalIndirectSymbol class -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the declaration of the GlobalIndirectSymbol class, which
11 // is a base class for GlobalAlias and GlobalIFunc. It contains all common code
12 // for aliases and ifuncs.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_IR_GLOBALINDIRECTSYMBOL_H
17 #define LLVM_IR_GLOBALINDIRECTSYMBOL_H
19 #include "llvm/IR/GlobalObject.h"
20 #include "llvm/IR/GlobalValue.h"
21 #include "llvm/IR/OperandTraits.h"
22 #include "llvm/IR/User.h"
23 #include "llvm/IR/Value.h"
24 #include "llvm/Support/Casting.h"
29 class GlobalIndirectSymbol : public GlobalValue {
31 GlobalIndirectSymbol(Type *Ty, ValueTy VTy, unsigned AddressSpace,
32 LinkageTypes Linkage, const Twine &Name, Constant *Symbol);
35 GlobalIndirectSymbol(const GlobalIndirectSymbol &) = delete;
36 GlobalIndirectSymbol &operator=(const GlobalIndirectSymbol &) = delete;
38 // allocate space for exactly one operand
39 void *operator new(size_t s) {
40 return User::operator new(s, 1);
43 /// Provide fast operand accessors
44 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
46 /// These methods set and retrieve indirect symbol.
47 void setIndirectSymbol(Constant *Symbol) {
48 setOperand(0, Symbol);
50 const Constant *getIndirectSymbol() const {
51 return const_cast<GlobalIndirectSymbol *>(this)->getIndirectSymbol();
53 Constant *getIndirectSymbol() {
57 const GlobalObject *getBaseObject() const {
58 return const_cast<GlobalIndirectSymbol *>(this)->getBaseObject();
60 GlobalObject *getBaseObject() {
61 return dyn_cast<GlobalObject>(getIndirectSymbol()->stripInBoundsOffsets());
64 const GlobalObject *getBaseObject(const DataLayout &DL, APInt &Offset) const {
65 return const_cast<GlobalIndirectSymbol *>(this)->getBaseObject(DL, Offset);
67 GlobalObject *getBaseObject(const DataLayout &DL, APInt &Offset) {
68 return dyn_cast<GlobalObject>(
69 getIndirectSymbol()->stripAndAccumulateInBoundsConstantOffsets(DL,
73 // Methods for support type inquiry through isa, cast, and dyn_cast:
74 static inline bool classof(const Value *V) {
75 return V->getValueID() == Value::GlobalAliasVal ||
76 V->getValueID() == Value::GlobalIFuncVal;
81 struct OperandTraits<GlobalIndirectSymbol> :
82 public FixedNumOperandTraits<GlobalIndirectSymbol, 1> {
85 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GlobalIndirectSymbol, Constant)
87 } // end namespace llvm
89 #endif // LLVM_IR_GLOBALINDIRECTSYMBOL_H