#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 <typename ValueSubClass> class SymbolTableListTraits;
-class GlobalAlias : public GlobalValue, public ilist_node<GlobalAlias> {
+class GlobalAlias : public GlobalIndirectSymbol,
+ public ilist_node<GlobalAlias> {
friend class SymbolTableListTraits<GlobalAlias>;
void operator=(const GlobalAlias &) = delete;
GlobalAlias(const GlobalAlias &) = delete;
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,
// 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.
///
///
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<GlobalAlias *>(this)->getAliasee();
+ return getIndirectSymbol();
}
Constant *getAliasee() {
- return getOperand(0);
+ return getIndirectSymbol();
}
const GlobalObject *getBaseObject() const {
}
};
-template <>
-struct OperandTraits<GlobalAlias> :
- public FixedNumOperandTraits<GlobalAlias, 1> {
-};
-
-DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GlobalAlias, Constant)
-
} // End llvm namespace
#endif
--- /dev/null
+//===- 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<GlobalIndirectSymbol *>(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<GlobalIndirectSymbol> :
+ public FixedNumOperandTraits<GlobalIndirectSymbol, 1> {
+};
+
+DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GlobalIndirectSymbol, Constant)
+
+} // End llvm namespace
+
+#endif
class DataLayout;
class Function;
class GlobalAlias;
+class GlobalIndirectSymbol;
class GlobalObject;
class GlobalValue;
class GlobalVariable;
}
};
+template <> struct isa_impl<GlobalIndirectSymbol, Value> {
+ static inline bool doit(const Value &Val) {
+ return isa<GlobalAlias>(Val);
+ }
+};
+
template <> struct isa_impl<GlobalValue, Value> {
static inline bool doit(const Value &Val) {
- return isa<GlobalObject>(Val) || isa<GlobalAlias>(Val);
+ return isa<GlobalObject>(Val) || isa<GlobalIndirectSymbol>(Val);
}
};
//===----------------------------------------------------------------------===//
+// 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);
}
void GlobalAlias::setAliasee(Constant *Aliasee) {
assert((!Aliasee || Aliasee->getType() == getType()) &&
"Alias and aliasee types should match!");
- setOperand(0, Aliasee);
+ setIndirectSymbol(Aliasee);
}