Index: llvm/trunk/include/llvm/IR/GlobalAlias.h =================================================================== --- llvm/trunk/include/llvm/IR/GlobalAlias.h +++ llvm/trunk/include/llvm/IR/GlobalAlias.h @@ -17,15 +17,15 @@ #include "llvm/ADT/Twine.h" #include "llvm/ADT/ilist_node.h" -#include "llvm/IR/GlobalValue.h" -#include "llvm/IR/OperandTraits.h" +#include "llvm/IR/GlobalIndirectSymbol.h" namespace llvm { class Module; template class SymbolTableListTraits; -class GlobalAlias : public GlobalValue, public ilist_node { +class GlobalAlias : public GlobalIndirectSymbol, + public ilist_node { friend class SymbolTableListTraits; void operator=(const GlobalAlias &) = delete; GlobalAlias(const GlobalAlias &) = delete; @@ -36,11 +36,6 @@ const Twine &Name, Constant *Aliasee, Module *Parent); public: - // allocate space for exactly one operand - void *operator new(size_t s) { - return User::operator new(s, 1); - } - /// If a parent module is specified, the alias is automatically inserted into /// the end of the specified module's alias list. static GlobalAlias *create(Type *Ty, unsigned AddressSpace, @@ -64,9 +59,6 @@ // Linkage, Type, Parent and AddressSpace taken from the Aliasee. static GlobalAlias *create(const Twine &Name, GlobalValue *Aliasee); - /// Provide fast operand accessors - DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant); - /// removeFromParent - This method unlinks 'this' from the containing module, /// but does not delete it. /// @@ -77,13 +69,13 @@ /// void eraseFromParent() override; - /// These methods retrive and set alias target. + /// These methods retrieve and set alias target. void setAliasee(Constant *Aliasee); const Constant *getAliasee() const { - return const_cast(this)->getAliasee(); + return getIndirectSymbol(); } Constant *getAliasee() { - return getOperand(0); + return getIndirectSymbol(); } const GlobalObject *getBaseObject() const { @@ -112,13 +104,6 @@ } }; -template <> -struct OperandTraits : - public FixedNumOperandTraits { -}; - -DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GlobalAlias, Constant) - } // End llvm namespace #endif Index: llvm/trunk/include/llvm/IR/GlobalIndirectSymbol.h =================================================================== --- llvm/trunk/include/llvm/IR/GlobalIndirectSymbol.h +++ llvm/trunk/include/llvm/IR/GlobalIndirectSymbol.h @@ -0,0 +1,67 @@ +//===- llvm/GlobalIndirectSymbol.h - GlobalIndirectSymbol class -*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file contains the declaration of the GlobalIndirectSymbol class, which +// is a base class for GlobalAlias and GlobalIFunc. It contains all common code +// for aliases and ifuncs. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_IR_GLOBALINDIRECTSYMBOL_H +#define LLVM_IR_GLOBALINDIRECTSYMBOL_H + +#include "llvm/IR/GlobalValue.h" +#include "llvm/IR/OperandTraits.h" + +namespace llvm { + +class GlobalIndirectSymbol : public GlobalValue { + void operator=(const GlobalIndirectSymbol &) = delete; + GlobalIndirectSymbol(const GlobalIndirectSymbol &) = delete; + +protected: + GlobalIndirectSymbol(Type *Ty, ValueTy VTy, unsigned AddressSpace, + LinkageTypes Linkage, const Twine &Name, Constant *Symbol); + +public: + // allocate space for exactly one operand + void *operator new(size_t s) { + return User::operator new(s, 1); + } + + /// Provide fast operand accessors + DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant); + + /// These methods set and retrieve indirect symbol. + void setIndirectSymbol(Constant *Symbol) { + setOperand(0, Symbol); + } + const Constant *getIndirectSymbol() const { + return const_cast(this)->getIndirectSymbol(); + } + Constant *getIndirectSymbol() { + return getOperand(0); + } + + // Methods for support type inquiry through isa, cast, and dyn_cast: + static inline bool classof(const Value *V) { + return V->getValueID() == Value::GlobalAliasVal; + } +}; + +template <> +struct OperandTraits : + public FixedNumOperandTraits { +}; + +DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GlobalIndirectSymbol, Constant) + +} // End llvm namespace + +#endif Index: llvm/trunk/include/llvm/IR/Value.h =================================================================== --- llvm/trunk/include/llvm/IR/Value.h +++ llvm/trunk/include/llvm/IR/Value.h @@ -31,6 +31,7 @@ class DataLayout; class Function; class GlobalAlias; +class GlobalIndirectSymbol; class GlobalObject; class GlobalValue; class GlobalVariable; @@ -742,9 +743,15 @@ } }; +template <> struct isa_impl { + static inline bool doit(const Value &Val) { + return isa(Val); + } +}; + template <> struct isa_impl { static inline bool doit(const Value &Val) { - return isa(Val) || isa(Val); + return isa(Val) || isa(Val); } }; Index: llvm/trunk/lib/IR/Globals.cpp =================================================================== --- llvm/trunk/lib/IR/Globals.cpp +++ llvm/trunk/lib/IR/Globals.cpp @@ -294,16 +294,26 @@ //===----------------------------------------------------------------------===// +// GlobalIndirectSymbol Implementation +//===----------------------------------------------------------------------===// + +GlobalIndirectSymbol::GlobalIndirectSymbol(Type *Ty, ValueTy VTy, + unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, + Constant *Symbol) + : GlobalValue(Ty, VTy, &Op<0>(), 1, Linkage, Name, AddressSpace) { + Op<0>() = Symbol; +} + + +//===----------------------------------------------------------------------===// // GlobalAlias Implementation //===----------------------------------------------------------------------===// GlobalAlias::GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Link, const Twine &Name, Constant *Aliasee, Module *ParentModule) - : GlobalValue(Ty, Value::GlobalAliasVal, &Op<0>(), 1, Link, Name, - AddressSpace) { - Op<0>() = Aliasee; - + : GlobalIndirectSymbol(Ty, Value::GlobalAliasVal, AddressSpace, Link, Name, + Aliasee) { if (ParentModule) ParentModule->getAliasList().push_back(this); } @@ -352,5 +362,5 @@ void GlobalAlias::setAliasee(Constant *Aliasee) { assert((!Aliasee || Aliasee->getType() == getType()) && "Alias and aliasee types should match!"); - setOperand(0, Aliasee); + setIndirectSymbol(Aliasee); }