IR: Add COMDATs to the IR
[oota-llvm.git] / include / llvm / IR / GlobalObject.h
1 //===-- llvm/GlobalObject.h - Class to represent a global object *- 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 &) LLVM_DELETED_FUNCTION;
28
29 protected:
30   GlobalObject(Type *Ty, ValueTy VTy, Use *Ops, unsigned NumOps,
31                LinkageTypes Linkage, const Twine &Name)
32       : GlobalValue(Ty, VTy, Ops, NumOps, Linkage, Name), ObjComdat(nullptr) {
33     setGlobalValueSubClassData(0);
34   }
35
36   std::string Section;     // Section to emit this into, empty means default
37   Comdat *ObjComdat;
38 public:
39   unsigned getAlignment() const {
40     return (1u << getGlobalValueSubClassData()) >> 1;
41   }
42   void setAlignment(unsigned Align);
43
44   bool hasSection() const { return !StringRef(getSection()).empty(); }
45   const char *getSection() const { return Section.c_str(); }
46   void setSection(StringRef S);
47
48   bool hasComdat() const { return getComdat() != nullptr; }
49   const Comdat *getComdat() const { return ObjComdat; }
50   Comdat *getComdat() { return ObjComdat; }
51   void setComdat(Comdat *C) { ObjComdat = C; }
52
53   void copyAttributesFrom(const GlobalValue *Src) override;
54
55   // Methods for support type inquiry through isa, cast, and dyn_cast:
56   static inline bool classof(const Value *V) {
57     return V->getValueID() == Value::FunctionVal ||
58            V->getValueID() == Value::GlobalVariableVal;
59   }
60 };
61
62 } // End llvm namespace
63
64 #endif