]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/IR/GlobalIndirectSymbol.h
Merge ^/head r305081 through r305086.
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / IR / GlobalIndirectSymbol.h
1 //===- llvm/GlobalIndirectSymbol.h - GlobalIndirectSymbol class -*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_IR_GLOBALINDIRECTSYMBOL_H
17 #define LLVM_IR_GLOBALINDIRECTSYMBOL_H
18
19 #include "llvm/IR/GlobalValue.h"
20 #include "llvm/IR/OperandTraits.h"
21
22 namespace llvm {
23
24 class GlobalIndirectSymbol : public GlobalValue {
25   void operator=(const GlobalIndirectSymbol &) = delete;
26   GlobalIndirectSymbol(const GlobalIndirectSymbol &) = delete;
27
28 protected:
29   GlobalIndirectSymbol(Type *Ty, ValueTy VTy, unsigned AddressSpace,
30       LinkageTypes Linkage, const Twine &Name, Constant *Symbol);
31
32 public:
33   // allocate space for exactly one operand
34   void *operator new(size_t s) {
35     return User::operator new(s, 1);
36   }
37
38   /// Provide fast operand accessors
39   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
40
41   /// These methods set and retrieve indirect symbol.
42   void setIndirectSymbol(Constant *Symbol) {
43     setOperand(0, Symbol);
44   }
45   const Constant *getIndirectSymbol() const {
46     return const_cast<GlobalIndirectSymbol *>(this)->getIndirectSymbol();
47   }
48   Constant *getIndirectSymbol() {
49     return getOperand(0);
50   }
51
52   const GlobalObject *getBaseObject() const {
53     return const_cast<GlobalIndirectSymbol *>(this)->getBaseObject();
54   }
55   GlobalObject *getBaseObject() {
56     return dyn_cast<GlobalObject>(getIndirectSymbol()->stripInBoundsOffsets());
57   }
58
59   const GlobalObject *getBaseObject(const DataLayout &DL, APInt &Offset) const {
60     return const_cast<GlobalIndirectSymbol *>(this)->getBaseObject(DL, Offset);
61   }
62   GlobalObject *getBaseObject(const DataLayout &DL, APInt &Offset) {
63     return dyn_cast<GlobalObject>(
64         getIndirectSymbol()->stripAndAccumulateInBoundsConstantOffsets(DL,
65                                                                        Offset));
66   }
67
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;
72   }
73 };
74
75 template <>
76 struct OperandTraits<GlobalIndirectSymbol> :
77   public FixedNumOperandTraits<GlobalIndirectSymbol, 1> {
78 };
79
80 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GlobalIndirectSymbol, Constant)
81
82 } // End llvm namespace
83
84 #endif