Skip to content

Commit

Permalink
Reduce abuse of default values in the GlobalAlias constructor.
Browse files Browse the repository at this point in the history
This is in preparation for adding an optional offset.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209073 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
espindola committed May 17, 2014
1 parent a2f8219 commit fbd8cc0
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 28 deletions.
19 changes: 16 additions & 3 deletions include/llvm/IR/GlobalAlias.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,22 @@ class GlobalAlias : public GlobalValue, public ilist_node<GlobalAlias> {
}
/// If a parent module is specified, the alias is automatically inserted into
/// the end of the specified module's alias list.
GlobalAlias(Type *Ty, LinkageTypes Linkage, const Twine &Name = "",
GlobalObject *Aliasee = nullptr, Module *Parent = nullptr,
unsigned AddressSpace = 0);
GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage,
const Twine &Name, GlobalObject *Aliasee, Module *Parent);

// Without the Aliasee.
GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage,
const Twine &Name, Module *Parent);

// The module is taken from the Aliasee.
GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage,
const Twine &Name, GlobalObject *Aliasee);

// Type, Parent and AddressSpace taken from the Aliasee.
GlobalAlias(LinkageTypes Linkage, const Twine &Name, GlobalObject *Aliasee);

// Linkage, Type, Parent and AddressSpace taken from the Aliasee.
GlobalAlias(const Twine &Name, GlobalObject *Aliasee);

/// Provide fast operand accessors
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
Expand Down
4 changes: 2 additions & 2 deletions lib/AsmParser/LLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,8 +697,8 @@ bool LLParser::ParseAlias(const std::string &Name, LocTy NameLoc,

// Okay, create the alias but do not insert it into the module yet.
std::unique_ptr<GlobalAlias> GA(
new GlobalAlias(Ty, (GlobalValue::LinkageTypes)Linkage, Name, Aliasee,
/*Parent*/ nullptr, AddrSpace));
new GlobalAlias(Ty, AddrSpace, (GlobalValue::LinkageTypes)Linkage, Name,
Aliasee, /*Parent*/ nullptr));
GA->setVisibility((GlobalValue::VisibilityTypes)Visibility);
GA->setDLLStorageClass((GlobalValue::DLLStorageClassTypes)DLLStorageClass);

Expand Down
4 changes: 2 additions & 2 deletions lib/Bitcode/Reader/BitcodeReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2004,8 +2004,8 @@ error_code BitcodeReader::ParseModule(bool Resume) {
return Error(InvalidTypeForValue);

auto *NewGA =
new GlobalAlias(PTy->getElementType(), GetDecodedLinkage(Record[2]),
"", nullptr, TheModule, PTy->getAddressSpace());
new GlobalAlias(PTy->getElementType(), PTy->getAddressSpace(),
GetDecodedLinkage(Record[2]), "", TheModule);
// Old bitcode files didn't have visibility field.
// Local linkage must have default visibility.
if (Record.size() > 3 && !NewGA->hasLocalLinkage())
Expand Down
6 changes: 3 additions & 3 deletions lib/IR/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1489,9 +1489,9 @@ void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit) {
LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
const char *Name) {
auto *PTy = cast<PointerType>(unwrap(Ty));
return wrap(new GlobalAlias(
PTy->getElementType(), GlobalValue::ExternalLinkage, Name,
unwrap<GlobalObject>(Aliasee), unwrap(M), PTy->getAddressSpace()));
return wrap(new GlobalAlias(PTy->getElementType(), PTy->getAddressSpace(),
GlobalValue::ExternalLinkage, Name,
unwrap<GlobalObject>(Aliasee), unwrap(M)));
}

/*--.. Operations on functions .............................................--*/
Expand Down
23 changes: 20 additions & 3 deletions lib/IR/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ void GlobalVariable::copyAttributesFrom(const GlobalValue *Src) {
// GlobalAlias Implementation
//===----------------------------------------------------------------------===//

GlobalAlias::GlobalAlias(Type *Ty, LinkageTypes Link, const Twine &Name,
GlobalObject *Aliasee, Module *ParentModule,
unsigned AddressSpace)
GlobalAlias::GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Link,
const Twine &Name, GlobalObject *Aliasee,
Module *ParentModule)
: GlobalValue(PointerType::get(Ty, AddressSpace), Value::GlobalAliasVal,
&Op<0>(), 1, Link, Name) {
LeakDetector::addGarbageObject(this);
Expand All @@ -225,6 +225,23 @@ GlobalAlias::GlobalAlias(Type *Ty, LinkageTypes Link, const Twine &Name,
ParentModule->getAliasList().push_back(this);
}

GlobalAlias::GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage,
const Twine &Name, Module *Parent)
: GlobalAlias(Ty, AddressSpace, Linkage, Name, nullptr, Parent) {}

GlobalAlias::GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage,
const Twine &Name, GlobalObject *Aliasee)
: GlobalAlias(Ty, AddressSpace, Linkage, Name, Aliasee,
Aliasee->getParent()) {}

GlobalAlias::GlobalAlias(LinkageTypes Link, const Twine &Name,
GlobalObject *Aliasee)
: GlobalAlias(Aliasee->getType()->getElementType(),
Aliasee->getType()->getAddressSpace(), Link, Name, Aliasee) {}

GlobalAlias::GlobalAlias(const Twine &Name, GlobalObject *Aliasee)
: GlobalAlias(Aliasee->getLinkage(), Name, Aliasee) {}

void GlobalAlias::setParent(Module *parent) {
if (getParent())
LeakDetector::addGarbageObject(this);
Expand Down
5 changes: 2 additions & 3 deletions lib/Linker/LinkModules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -922,9 +922,8 @@ bool ModuleLinker::linkAliasProto(GlobalAlias *SGA) {
// If there is no linkage to be performed or we're linking from the source,
// bring over SGA.
auto *PTy = cast<PointerType>(TypeMap.get(SGA->getType()));
auto *NewDA =
new GlobalAlias(PTy->getElementType(), SGA->getLinkage(), SGA->getName(),
/*aliasee*/ nullptr, DstM, PTy->getAddressSpace());
auto *NewDA = new GlobalAlias(PTy->getElementType(), PTy->getAddressSpace(),
SGA->getLinkage(), SGA->getName(), DstM);
copyGVAttributes(NewDA, SGA);
if (NewVisibility)
NewDA->setVisibility(*NewVisibility);
Expand Down
4 changes: 2 additions & 2 deletions lib/Transforms/IPO/MergeFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1328,8 +1328,8 @@ void MergeFunctions::writeThunk(Function *F, Function *G) {
// Replace G with an alias to F and delete G.
void MergeFunctions::writeAlias(Function *F, Function *G) {
PointerType *PTy = G->getType();
auto *GA = new GlobalAlias(PTy->getElementType(), G->getLinkage(), "", F,
G->getParent(), PTy->getAddressSpace());
auto *GA = new GlobalAlias(PTy->getElementType(), PTy->getAddressSpace(),
G->getLinkage(), "", F);
F->setAlignment(std::max(F->getAlignment(), G->getAlignment()));
GA->takeName(G);
GA->setVisibility(G->getVisibility());
Expand Down
5 changes: 2 additions & 3 deletions lib/Transforms/Utils/CloneModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ Module *llvm::CloneModule(const Module *M, ValueToValueMapTy &VMap) {
for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end();
I != E; ++I) {
auto *PTy = cast<PointerType>(I->getType());
auto *GA =
new GlobalAlias(PTy->getElementType(), I->getLinkage(), I->getName(),
nullptr, New, PTy->getAddressSpace());
auto *GA = new GlobalAlias(PTy->getElementType(), PTy->getAddressSpace(),
I->getLinkage(), I->getName(), New);
GA->copyAttributesFrom(I);
VMap[I] = GA;
}
Expand Down
3 changes: 1 addition & 2 deletions unittests/IR/ConstantsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,7 @@ TEST(ConstantsTest, ReplaceInAliasTest) {

Type *Int32Ty = Type::getInt32Ty(getGlobalContext());
auto *Global = cast<GlobalObject>(M->getOrInsertGlobal("dummy", Int32Ty));
auto *GA = new GlobalAlias(Int32Ty, GlobalValue::ExternalLinkage, "alias",
Global, M.get());
auto *GA = new GlobalAlias(GlobalValue::ExternalLinkage, "alias", Global);
EXPECT_DEATH(Global->replaceAllUsesWith(GA),
"replaceAliasUseWith cannot form an alias cycle");
}
Expand Down
3 changes: 1 addition & 2 deletions unittests/IR/VerifierTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ TEST(VerifierTest, AliasUnnamedAddr) {
GlobalVariable *Aliasee = new GlobalVariable(M, Ty, true,
GlobalValue::ExternalLinkage,
Init, "foo");
auto *GA =
new GlobalAlias(Ty, GlobalValue::ExternalLinkage, "bar", Aliasee, &M);
auto *GA = new GlobalAlias(GlobalValue::ExternalLinkage, "bar", Aliasee);
GA->setUnnamedAddr(true);
std::string Error;
raw_string_ostream ErrorOS(Error);
Expand Down
4 changes: 1 addition & 3 deletions unittests/Transforms/Utils/SpecialCaseList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ class SpecialCaseListTest : public ::testing::Test {
}

GlobalAlias *makeAlias(StringRef Name, GlobalObject *Aliasee) {
return new GlobalAlias(Aliasee->getType()->getElementType(),
GlobalValue::ExternalLinkage, Name, Aliasee,
Aliasee->getParent());
return new GlobalAlias(GlobalValue::ExternalLinkage, Name, Aliasee);
}

SpecialCaseList *makeSpecialCaseList(StringRef List, std::string &Error) {
Expand Down

0 comments on commit fbd8cc0

Please sign in to comment.