LLVM API Documentation
00001 //===-- llvm/GlobalObject.h - Class to represent a global object *- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This represents an independent object. That is, a function or a global 00011 // variable, but not an alias. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #ifndef LLVM_IR_GLOBALOBJECT_H 00016 #define LLVM_IR_GLOBALOBJECT_H 00017 00018 #include "llvm/IR/Constant.h" 00019 #include "llvm/IR/DerivedTypes.h" 00020 #include "llvm/IR/GlobalValue.h" 00021 00022 namespace llvm { 00023 class Comdat; 00024 class Module; 00025 00026 class GlobalObject : public GlobalValue { 00027 GlobalObject(const GlobalObject &) LLVM_DELETED_FUNCTION; 00028 00029 protected: 00030 GlobalObject(Type *Ty, ValueTy VTy, Use *Ops, unsigned NumOps, 00031 LinkageTypes Linkage, const Twine &Name) 00032 : GlobalValue(Ty, VTy, Ops, NumOps, Linkage, Name), ObjComdat(nullptr) { 00033 setGlobalValueSubClassData(0); 00034 } 00035 00036 std::string Section; // Section to emit this into, empty means default 00037 Comdat *ObjComdat; 00038 public: 00039 unsigned getAlignment() const { 00040 return (1u << getGlobalValueSubClassData()) >> 1; 00041 } 00042 void setAlignment(unsigned Align); 00043 00044 bool hasSection() const { return !StringRef(getSection()).empty(); } 00045 const char *getSection() const { return Section.c_str(); } 00046 void setSection(StringRef S); 00047 00048 bool hasComdat() const { return getComdat() != nullptr; } 00049 const Comdat *getComdat() const { return ObjComdat; } 00050 Comdat *getComdat() { return ObjComdat; } 00051 void setComdat(Comdat *C) { ObjComdat = C; } 00052 00053 void copyAttributesFrom(const GlobalValue *Src) override; 00054 00055 // Methods for support type inquiry through isa, cast, and dyn_cast: 00056 static inline bool classof(const Value *V) { 00057 return V->getValueID() == Value::FunctionVal || 00058 V->getValueID() == Value::GlobalVariableVal; 00059 } 00060 }; 00061 00062 } // End llvm namespace 00063 00064 #endif