//
// The LLVM Compiler Infrastructure
//
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
//
//===----------------------------------------------------------------------===//
+#include "llvm/Constants.h"
#include "llvm/GlobalVariable.h"
#include "llvm/GlobalAlias.h"
#include "llvm/DerivedTypes.h"
GlobalVariable::GlobalVariable(const Type *Ty, bool constant, LinkageTypes Link,
Constant *InitVal, const std::string &Name,
- Module *ParentModule, bool ThreadLocal)
- : GlobalValue(PointerType::get(Ty), Value::GlobalVariableVal,
+ Module *ParentModule, bool ThreadLocal,
+ unsigned AddressSpace)
+ : GlobalValue(PointerType::get(Ty, AddressSpace), Value::GlobalVariableVal,
&Initializer, InitVal != 0, Link, Name),
isConstantGlobal(constant), isThreadLocalSymbol(ThreadLocal) {
if (InitVal) {
GlobalVariable::GlobalVariable(const Type *Ty, bool constant, LinkageTypes Link,
Constant *InitVal, const std::string &Name,
- GlobalVariable *Before, bool ThreadLocal)
- : GlobalValue(PointerType::get(Ty), Value::GlobalVariableVal,
+ GlobalVariable *Before, bool ThreadLocal,
+ unsigned AddressSpace)
+ : GlobalValue(PointerType::get(Ty, AddressSpace), Value::GlobalVariableVal,
&Initializer, InitVal != 0, Link, Name),
isConstantGlobal(constant), isThreadLocalSymbol(ThreadLocal) {
if (InitVal) {
}
bool GlobalAlias::isDeclaration() const {
- const GlobalValue* AV = dyn_cast_or_null<const GlobalValue>(getAliasee());
- return (AV && AV->isDeclaration());
+ const GlobalValue* AV = getAliasedGlobal();
+ if (AV)
+ return AV->isDeclaration();
+ else
+ return false;
}
void GlobalAlias::setAliasee(Constant *Aliasee)
{
- if (Aliasee) {
- assert(Aliasee->getType() == getType() &&
+ if (Aliasee)
+ assert(Aliasee->getType() == getType() &&
"Alias and aliasee types should match!");
- setOperand(0, Aliasee);
+
+ setOperand(0, Aliasee);
+}
+
+const GlobalValue *GlobalAlias::getAliasedGlobal() const {
+ const Constant *C = getAliasee();
+ if (C) {
+ if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
+ return GV;
+ else {
+ const ConstantExpr *CE = 0;
+ if ((CE = dyn_cast<ConstantExpr>(C)) &&
+ (CE->getOpcode() == Instruction::BitCast ||
+ CE->getOpcode() == Instruction::GetElementPtr))
+ return dyn_cast<GlobalValue>(CE->getOperand(0));
+ else
+ assert(0 && "Unsupported aliasee");
+ }
}
+ return 0;
}