2007-04-28 13:45:00 +00:00
|
|
|
//===-------- llvm/GlobalAlias.h - GlobalAlias class ------------*- C++ -*-===//
|
2007-04-25 16:42:39 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-04-25 16:42:39 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains the declaration of the GlobalAlias class, which
|
2007-04-28 13:45:00 +00:00
|
|
|
// represents a single function or variable alias in the IR.
|
2007-04-25 16:42:39 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-01-10 00:45:19 +00:00
|
|
|
#ifndef LLVM_IR_GLOBALALIAS_H
|
|
|
|
#define LLVM_IR_GLOBALALIAS_H
|
2007-04-25 16:42:39 +00:00
|
|
|
|
2012-12-03 17:02:12 +00:00
|
|
|
#include "llvm/ADT/Twine.h"
|
|
|
|
#include "llvm/ADT/ilist_node.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/GlobalValue.h"
|
|
|
|
#include "llvm/IR/OperandTraits.h"
|
2007-04-25 16:42:39 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
class Module;
|
|
|
|
template<typename ValueSubClass, typename ItemParentClass>
|
|
|
|
class SymbolTableListTraits;
|
|
|
|
|
2008-07-28 21:51:04 +00:00
|
|
|
class GlobalAlias : public GlobalValue, public ilist_node<GlobalAlias> {
|
2007-04-25 16:42:39 +00:00
|
|
|
friend class SymbolTableListTraits<GlobalAlias, Module>;
|
2012-09-17 07:16:40 +00:00
|
|
|
void operator=(const GlobalAlias &) LLVM_DELETED_FUNCTION;
|
|
|
|
GlobalAlias(const GlobalAlias &) LLVM_DELETED_FUNCTION;
|
2007-04-25 16:42:39 +00:00
|
|
|
|
|
|
|
void setParent(Module *parent);
|
|
|
|
|
2014-05-17 21:29:57 +00:00
|
|
|
GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage,
|
2014-06-03 02:41:57 +00:00
|
|
|
const Twine &Name, Constant *Aliasee, Module *Parent);
|
2014-05-17 21:29:57 +00:00
|
|
|
|
2007-04-25 16:42:39 +00:00
|
|
|
public:
|
2008-05-10 08:32:32 +00:00
|
|
|
// allocate space for exactly one operand
|
2008-04-06 20:25:17 +00:00
|
|
|
void *operator new(size_t s) {
|
2008-05-10 08:32:32 +00:00
|
|
|
return User::operator new(s, 1);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2014-05-17 21:29:57 +00:00
|
|
|
|
2014-05-16 13:34:04 +00:00
|
|
|
/// If a parent module is specified, the alias is automatically inserted into
|
|
|
|
/// the end of the specified module's alias list.
|
2014-05-17 21:29:57 +00:00
|
|
|
static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
|
|
|
|
LinkageTypes Linkage, const Twine &Name,
|
2014-06-03 02:41:57 +00:00
|
|
|
Constant *Aliasee, Module *Parent);
|
2014-05-17 19:57:46 +00:00
|
|
|
|
|
|
|
// Without the Aliasee.
|
2014-05-17 21:29:57 +00:00
|
|
|
static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
|
|
|
|
LinkageTypes Linkage, const Twine &Name,
|
|
|
|
Module *Parent);
|
2014-05-17 19:57:46 +00:00
|
|
|
|
|
|
|
// The module is taken from the Aliasee.
|
2014-05-17 21:29:57 +00:00
|
|
|
static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
|
|
|
|
LinkageTypes Linkage, const Twine &Name,
|
2014-06-03 02:41:57 +00:00
|
|
|
GlobalValue *Aliasee);
|
2014-05-17 19:57:46 +00:00
|
|
|
|
|
|
|
// Type, Parent and AddressSpace taken from the Aliasee.
|
2014-05-17 21:29:57 +00:00
|
|
|
static GlobalAlias *create(LinkageTypes Linkage, const Twine &Name,
|
2014-06-03 02:41:57 +00:00
|
|
|
GlobalValue *Aliasee);
|
2014-05-17 19:57:46 +00:00
|
|
|
|
|
|
|
// Linkage, Type, Parent and AddressSpace taken from the Aliasee.
|
2014-06-03 02:41:57 +00:00
|
|
|
static GlobalAlias *create(const Twine &Name, GlobalValue *Aliasee);
|
2007-04-25 16:42:39 +00:00
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
/// Provide fast operand accessors
|
2011-08-01 12:20:36 +00:00
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
|
2008-05-10 08:32:32 +00:00
|
|
|
|
2007-04-25 16:42:39 +00:00
|
|
|
/// removeFromParent - This method unlinks 'this' from the containing module,
|
|
|
|
/// but does not delete it.
|
|
|
|
///
|
2014-03-05 06:35:38 +00:00
|
|
|
void removeFromParent() override;
|
2007-04-25 16:42:39 +00:00
|
|
|
|
|
|
|
/// eraseFromParent - This method unlinks 'this' from the containing module
|
|
|
|
/// and deletes it.
|
|
|
|
///
|
2014-03-05 06:35:38 +00:00
|
|
|
void eraseFromParent() override;
|
2007-04-25 16:42:39 +00:00
|
|
|
|
2014-06-03 02:41:57 +00:00
|
|
|
/// These methods retrive and set alias target.
|
|
|
|
void setAliasee(Constant *Aliasee);
|
|
|
|
const Constant *getAliasee() const {
|
2014-05-16 19:35:39 +00:00
|
|
|
return const_cast<GlobalAlias *>(this)->getAliasee();
|
2007-04-28 13:45:00 +00:00
|
|
|
}
|
2014-06-03 02:41:57 +00:00
|
|
|
Constant *getAliasee() {
|
|
|
|
return getOperand(0);
|
2014-05-16 19:35:39 +00:00
|
|
|
}
|
|
|
|
|
2014-06-27 18:19:56 +00:00
|
|
|
const GlobalObject *getBaseObject() const {
|
|
|
|
return const_cast<GlobalAlias *>(this)->getBaseObject();
|
|
|
|
}
|
|
|
|
GlobalObject *getBaseObject() {
|
|
|
|
return dyn_cast<GlobalObject>(getAliasee()->stripInBoundsOffsets());
|
|
|
|
}
|
|
|
|
|
|
|
|
const GlobalObject *getBaseObject(const DataLayout &DL, APInt &Offset) const {
|
|
|
|
return const_cast<GlobalAlias *>(this)->getBaseObject(DL, Offset);
|
|
|
|
}
|
|
|
|
GlobalObject *getBaseObject(const DataLayout &DL, APInt &Offset) {
|
|
|
|
return dyn_cast<GlobalObject>(
|
|
|
|
getAliasee()->stripAndAccumulateInBoundsConstantOffsets(DL, Offset));
|
|
|
|
}
|
|
|
|
|
2013-10-09 16:07:32 +00:00
|
|
|
static bool isValidLinkage(LinkageTypes L) {
|
|
|
|
return isExternalLinkage(L) || isLocalLinkage(L) ||
|
|
|
|
isWeakLinkage(L) || isLinkOnceLinkage(L);
|
|
|
|
}
|
|
|
|
|
2007-04-25 16:42:39 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return V->getValueID() == Value::GlobalAliasVal;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
template <>
|
2011-01-11 15:07:38 +00:00
|
|
|
struct OperandTraits<GlobalAlias> :
|
|
|
|
public FixedNumOperandTraits<GlobalAlias, 1> {
|
2008-05-10 08:32:32 +00:00
|
|
|
};
|
|
|
|
|
2011-08-22 09:37:03 +00:00
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GlobalAlias, Constant)
|
2008-05-10 08:32:32 +00:00
|
|
|
|
2007-04-25 16:42:39 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|