diff options
Diffstat (limited to 'include/llvm')
-rw-r--r-- | include/llvm/CodeGen/AsmPrinter.h | 2 | ||||
-rw-r--r-- | include/llvm/IR/Function.h | 4 | ||||
-rw-r--r-- | include/llvm/IR/GlobalAlias.h | 4 | ||||
-rw-r--r-- | include/llvm/IR/GlobalObject.h | 58 | ||||
-rw-r--r-- | include/llvm/IR/GlobalValue.h | 20 | ||||
-rw-r--r-- | include/llvm/IR/GlobalVariable.h | 4 | ||||
-rw-r--r-- | include/llvm/IR/Value.h | 10 |
7 files changed, 88 insertions, 14 deletions
diff --git a/include/llvm/CodeGen/AsmPrinter.h b/include/llvm/CodeGen/AsmPrinter.h index d5c3e721b0..b53fb423d8 100644 --- a/include/llvm/CodeGen/AsmPrinter.h +++ b/include/llvm/CodeGen/AsmPrinter.h @@ -233,7 +233,7 @@ public: /// requested, it will override the alignment request if required for /// correctness. /// - void EmitAlignment(unsigned NumBits, const GlobalValue *GV = nullptr) const; + void EmitAlignment(unsigned NumBits, const GlobalObject *GO = nullptr) const; /// This method prints the label for the specified MachineBasicBlock, an /// alignment (if present) and a comment describing it if appropriate. diff --git a/include/llvm/IR/Function.h b/include/llvm/IR/Function.h index 3566002ae1..22444bd300 100644 --- a/include/llvm/IR/Function.h +++ b/include/llvm/IR/Function.h @@ -23,7 +23,7 @@ #include "llvm/IR/Attributes.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/CallingConv.h" -#include "llvm/IR/GlobalValue.h" +#include "llvm/IR/GlobalObject.h" #include "llvm/Support/Compiler.h" namespace llvm { @@ -68,7 +68,7 @@ private: mutable ilist_half_node<Argument> Sentinel; }; -class Function : public GlobalValue, public ilist_node<Function> { +class Function : public GlobalObject, public ilist_node<Function> { public: typedef iplist<Argument> ArgumentListType; typedef iplist<BasicBlock> BasicBlockListType; diff --git a/include/llvm/IR/GlobalAlias.h b/include/llvm/IR/GlobalAlias.h index ad02996e2d..5aa4261256 100644 --- a/include/llvm/IR/GlobalAlias.h +++ b/include/llvm/IR/GlobalAlias.h @@ -68,8 +68,8 @@ public: /// This method tries to ultimately resolve the alias by going through the /// aliasing chain and trying to find the very last global. Returns NULL if a /// cycle was found. - GlobalValue *getAliasedGlobal(); - const GlobalValue *getAliasedGlobal() const { + GlobalObject *getAliasedGlobal(); + const GlobalObject *getAliasedGlobal() const { return const_cast<GlobalAlias *>(this)->getAliasedGlobal(); } diff --git a/include/llvm/IR/GlobalObject.h b/include/llvm/IR/GlobalObject.h new file mode 100644 index 0000000000..3bc8b8531d --- /dev/null +++ b/include/llvm/IR/GlobalObject.h @@ -0,0 +1,58 @@ +//===-- llvm/GlobalObject.h - Class to represent a global object *- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This represents an independent object. That is, a function or a global +// variable, but not an alias. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_IR_GLOBALOBJECT_H +#define LLVM_IR_GLOBALOBJECT_H + +#include "llvm/IR/Constant.h" +#include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/GlobalValue.h" + +namespace llvm { + +class Module; + +class GlobalObject : public GlobalValue { + GlobalObject(const GlobalObject &) LLVM_DELETED_FUNCTION; + +protected: + GlobalObject(Type *Ty, ValueTy VTy, Use *Ops, unsigned NumOps, + LinkageTypes Linkage, const Twine &Name) + : GlobalValue(Ty, VTy, Ops, NumOps, Linkage, Name) { + setGlobalValueSubClassData(0); + } + + std::string Section; // Section to emit this into, empty means default +public: + unsigned getAlignment() const { + return (1u << getGlobalValueSubClassData()) >> 1; + } + void setAlignment(unsigned Align); + + bool hasSection() const { return !getSection().empty(); } + const std::string &getSection() const { return Section; } + void setSection(StringRef S); + + void copyAttributesFrom(const GlobalValue *Src) override; + + // Methods for support type inquiry through isa, cast, and dyn_cast: + static inline bool classof(const Value *V) { + return V->getValueID() == Value::FunctionVal || + V->getValueID() == Value::GlobalVariableVal; + } +}; + +} // End llvm namespace + +#endif diff --git a/include/llvm/IR/GlobalValue.h b/include/llvm/IR/GlobalValue.h index 4d0d5e181f..0ed302cdb4 100644 --- a/include/llvm/IR/GlobalValue.h +++ b/include/llvm/IR/GlobalValue.h @@ -62,7 +62,7 @@ protected: GlobalValue(Type *Ty, ValueTy VTy, Use *Ops, unsigned NumOps, LinkageTypes Linkage, const Twine &Name) : Constant(Ty, VTy, Ops, NumOps), Linkage(Linkage), - Visibility(DefaultVisibility), Alignment(0), UnnamedAddr(0), + Visibility(DefaultVisibility), UnnamedAddr(0), DllStorageClass(DefaultStorageClass), Parent(nullptr) { setName(Name); } @@ -71,18 +71,29 @@ protected: // Linkage and Visibility from turning into negative values. LinkageTypes Linkage : 5; // The linkage of this global unsigned Visibility : 2; // The visibility style of this global - unsigned Alignment : 16; // Alignment of this symbol, must be power of two unsigned UnnamedAddr : 1; // This value's address is not significant unsigned DllStorageClass : 2; // DLL storage class + +private: + // Give subclasses access to what otherwise would be wasted padding. + // (22 + 2 + 1 + 2 + 5) == 32. + unsigned SubClassData : 22; +protected: + unsigned getGlobalValueSubClassData() const { + return SubClassData; + } + void setGlobalValueSubClassData(unsigned V) { + assert(V < (1 << 22) && "It will not fit"); + SubClassData = V; + } + Module *Parent; // The containing module. - std::string Section; // Section to emit this into, empty mean default public: ~GlobalValue() { removeDeadConstantUsers(); // remove any dead constants using this. } unsigned getAlignment() const; - void setAlignment(unsigned Align); bool hasUnnamedAddr() const { return UnnamedAddr; } void setUnnamedAddr(bool Val) { UnnamedAddr = Val; } @@ -112,7 +123,6 @@ public: bool hasSection() const { return !getSection().empty(); } const std::string &getSection() const; - void setSection(StringRef S); /// Global values are always pointers. inline PointerType *getType() const { diff --git a/include/llvm/IR/GlobalVariable.h b/include/llvm/IR/GlobalVariable.h index d73e826225..8cd4332b1a 100644 --- a/include/llvm/IR/GlobalVariable.h +++ b/include/llvm/IR/GlobalVariable.h @@ -22,7 +22,7 @@ #include "llvm/ADT/Twine.h" #include "llvm/ADT/ilist_node.h" -#include "llvm/IR/GlobalValue.h" +#include "llvm/IR/GlobalObject.h" #include "llvm/IR/OperandTraits.h" namespace llvm { @@ -32,7 +32,7 @@ class Constant; template<typename ValueSubClass, typename ItemParentClass> class SymbolTableListTraits; -class GlobalVariable : public GlobalValue, public ilist_node<GlobalVariable> { +class GlobalVariable : public GlobalObject, public ilist_node<GlobalVariable> { friend class SymbolTableListTraits<GlobalVariable, Module>; void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; void operator=(const GlobalVariable &) LLVM_DELETED_FUNCTION; diff --git a/include/llvm/IR/Value.h b/include/llvm/IR/Value.h index 7108af564f..01586831bc 100644 --- a/include/llvm/IR/Value.h +++ b/include/llvm/IR/Value.h @@ -31,6 +31,7 @@ class Constant; class DataLayout; class Function; class GlobalAlias; +class GlobalObject; class GlobalValue; class GlobalVariable; class InlineAsm; @@ -526,8 +527,13 @@ template <> struct isa_impl<GlobalAlias, Value> { template <> struct isa_impl<GlobalValue, Value> { static inline bool doit(const Value &Val) { - return isa<GlobalVariable>(Val) || isa<Function>(Val) || - isa<GlobalAlias>(Val); + return isa<GlobalObject>(Val) || isa<GlobalAlias>(Val); + } +}; + +template <> struct isa_impl<GlobalObject, Value> { + static inline bool doit(const Value &Val) { + return isa<GlobalVariable>(Val) || isa<Function>(Val); } }; |