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/GlobalValue.h"
20 #include "llvm/IR/OperandTraits.h"
24 class GlobalIndirectSymbol : public GlobalValue {
25 void operator=(const GlobalIndirectSymbol &) = delete;
26 GlobalIndirectSymbol(const GlobalIndirectSymbol &) = delete;
29 GlobalIndirectSymbol(Type *Ty, ValueTy VTy, unsigned AddressSpace,
30 LinkageTypes Linkage, const Twine &Name, Constant *Symbol);
33 // allocate space for exactly one operand
34 void *operator new(size_t s) {
35 return User::operator new(s, 1);
38 /// Provide fast operand accessors
39 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
41 /// These methods set and retrieve indirect symbol.
42 void setIndirectSymbol(Constant *Symbol) {
43 setOperand(0, Symbol);
45 const Constant *getIndirectSymbol() const {
46 return const_cast<GlobalIndirectSymbol *>(this)->getIndirectSymbol();
48 Constant *getIndirectSymbol() {
52 const GlobalObject *getBaseObject() const {
53 return const_cast<GlobalIndirectSymbol *>(this)->getBaseObject();
55 GlobalObject *getBaseObject() {
56 return dyn_cast<GlobalObject>(getIndirectSymbol()->stripInBoundsOffsets());
59 const GlobalObject *getBaseObject(const DataLayout &DL, APInt &Offset) const {
60 return const_cast<GlobalIndirectSymbol *>(this)->getBaseObject(DL, Offset);
62 GlobalObject *getBaseObject(const DataLayout &DL, APInt &Offset) {
63 return dyn_cast<GlobalObject>(
64 getIndirectSymbol()->stripAndAccumulateInBoundsConstantOffsets(DL,
68 // Methods for support type inquiry through isa, cast, and dyn_cast:
69 static inline bool classof(const Value *V) {
70 return V->getValueID() == Value::GlobalAliasVal ||
71 V->getValueID() == Value::GlobalIFuncVal;
76 struct OperandTraits<GlobalIndirectSymbol> :
77 public FixedNumOperandTraits<GlobalIndirectSymbol, 1> {
80 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GlobalIndirectSymbol, Constant)
82 } // End llvm namespace