[IR] Cleanup EH instructions a little bit
[oota-llvm.git] / include / llvm / IR / GlobalObject.h
1 //===-- llvm/GlobalObject.h - Class to represent global objects -*- 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 represents an independent object. That is, a function or a global
11 // variable, but not an alias.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_IR_GLOBALOBJECT_H
16 #define LLVM_IR_GLOBALOBJECT_H
17
18 #include "llvm/IR/Constant.h"
19 #include "llvm/IR/DerivedTypes.h"
20 #include "llvm/IR/GlobalValue.h"
21
22 namespace llvm {
23 class Comdat;
24 class Module;
25
26 class GlobalObject : public GlobalValue {
27   GlobalObject(const GlobalObject &) = delete;
28
29 protected:
30   GlobalObject(PointerType *Ty, ValueTy VTy, Use *Ops, unsigned NumOps,
31                LinkageTypes Linkage, const Twine &Name) = delete;
32   GlobalObject(Type *Ty, ValueTy VTy, Use *Ops, unsigned NumOps,
33                LinkageTypes Linkage, const Twine &Name,
34                unsigned AddressSpace = 0)
35       : GlobalValue(PointerType::get(Ty, AddressSpace), VTy, Ops, NumOps,
36                     Linkage, Name),
37         ObjComdat(nullptr) {
38     setGlobalValueSubClassData(0);
39   }
40
41   std::string Section;     // Section to emit this into, empty means default
42   Comdat *ObjComdat;
43   static const unsigned AlignmentBits = 5;
44   static const unsigned GlobalObjectSubClassDataBits =
45       GlobalValueSubClassDataBits - AlignmentBits;
46
47 private:
48   static const unsigned AlignmentMask = (1 << AlignmentBits) - 1;
49
50 public:
51   unsigned getAlignment() const {
52     unsigned Data = getGlobalValueSubClassData();
53     unsigned AlignmentData = Data & AlignmentMask;
54     return (1u << AlignmentData) >> 1;
55   }
56   void setAlignment(unsigned Align);
57
58   unsigned getGlobalObjectSubClassData() const;
59   void setGlobalObjectSubClassData(unsigned Val);
60
61   bool hasSection() const { return !StringRef(getSection()).empty(); }
62   const char *getSection() const { return Section.c_str(); }
63   void setSection(StringRef S);
64
65   bool hasComdat() const { return getComdat() != nullptr; }
66   const Comdat *getComdat() const { return ObjComdat; }
67   Comdat *getComdat() { return ObjComdat; }
68   void setComdat(Comdat *C) { ObjComdat = C; }
69
70   void copyAttributesFrom(const GlobalValue *Src) override;
71
72   // Methods for support type inquiry through isa, cast, and dyn_cast:
73   static inline bool classof(const Value *V) {
74     return V->getValueID() == Value::FunctionVal ||
75            V->getValueID() == Value::GlobalVariableVal;
76   }
77 };
78
79 } // End llvm namespace
80
81 #endif