1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 11:02:59 +02:00

[IFUNC] Introduce GlobalIndirectSymbol as a base class for alias and ifunc

This patch is a part of http://reviews.llvm.org/D15525

GlobalIndirectSymbol class contains common implementation for both
aliases and ifuncs. This patch should be NFC change that just prepare
common code for ifunc support.

Differential Revision: http://reviews.llvm.org/D18433

llvm-svn: 265016
This commit is contained in:
Dmitry Polukhin 2016-03-31 14:16:21 +00:00
parent 35c4ba5d9f
commit b85d7106f9
4 changed files with 96 additions and 27 deletions

View File

@ -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 <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;
@ -36,11 +36,6 @@ class GlobalAlias : public GlobalValue, public ilist_node<GlobalAlias> {
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 @@ public:
// 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 @@ public:
///
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 {
@ -112,13 +104,6 @@ public:
}
};
template <>
struct OperandTraits<GlobalAlias> :
public FixedNumOperandTraits<GlobalAlias, 1> {
};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GlobalAlias, Constant)
} // End llvm namespace
#endif

View File

@ -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<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

View File

@ -31,6 +31,7 @@ class ConstantData;
class DataLayout;
class Function;
class GlobalAlias;
class GlobalIndirectSymbol;
class GlobalObject;
class GlobalValue;
class GlobalVariable;
@ -742,9 +743,15 @@ template <> struct isa_impl<GlobalAlias, Value> {
}
};
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);
}
};

View File

@ -293,6 +293,18 @@ void GlobalVariable::copyAttributesFrom(const GlobalValue *Src) {
}
//===----------------------------------------------------------------------===//
// 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
//===----------------------------------------------------------------------===//
@ -300,10 +312,8 @@ void GlobalVariable::copyAttributesFrom(const GlobalValue *Src) {
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::eraseFromParent() {
void GlobalAlias::setAliasee(Constant *Aliasee) {
assert((!Aliasee || Aliasee->getType() == getType()) &&
"Alias and aliasee types should match!");
setOperand(0, Aliasee);
setIndirectSymbol(Aliasee);
}