[llvm] r236160 - [opaque pointer type] Pass GlobalAlias the actual pointer type rather than decomposing it into pointee type + address space
David Blaikie
dblaikie at gmail.com
Wed Apr 29 14:22:40 PDT 2015
Author: dblaikie
Date: Wed Apr 29 16:22:39 2015
New Revision: 236160
URL: http://llvm.org/viewvc/llvm-project?rev=236160&view=rev
Log:
[opaque pointer type] Pass GlobalAlias the actual pointer type rather than decomposing it into pointee type + address space
Many of the callers already have the pointer type anyway, and for the
couple of callers that don't it's pretty easy to call PointerType::get
on the pointee type and address space.
This avoids LLParser from using PointerType::getElementType when parsing
GlobalAliases from IR.
Modified:
llvm/trunk/include/llvm/IR/GlobalAlias.h
llvm/trunk/lib/AsmParser/LLParser.cpp
llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/trunk/lib/CodeGen/GlobalMerge.cpp
llvm/trunk/lib/ExecutionEngine/Orc/CloneSubModule.cpp
llvm/trunk/lib/IR/Core.cpp
llvm/trunk/lib/IR/Globals.cpp
llvm/trunk/lib/Linker/LinkModules.cpp
llvm/trunk/lib/Transforms/IPO/LowerBitSets.cpp
llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp
llvm/trunk/lib/Transforms/Utils/CloneModule.cpp
llvm/trunk/unittests/IR/ConstantsTest.cpp
Modified: llvm/trunk/include/llvm/IR/GlobalAlias.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/GlobalAlias.h?rev=236160&r1=236159&r2=236160&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/GlobalAlias.h (original)
+++ llvm/trunk/include/llvm/IR/GlobalAlias.h Wed Apr 29 16:22:39 2015
@@ -33,8 +33,8 @@ class GlobalAlias : public GlobalValue,
void setParent(Module *parent);
- GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage,
- const Twine &Name, Constant *Aliasee, Module *Parent);
+ GlobalAlias(PointerType *Ty, LinkageTypes Linkage, const Twine &Name,
+ Constant *Aliasee, Module *Parent);
public:
// allocate space for exactly one operand
@@ -44,19 +44,17 @@ public:
/// 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,
- LinkageTypes Linkage, const Twine &Name,
- Constant *Aliasee, Module *Parent);
+ static GlobalAlias *create(PointerType *Ty, LinkageTypes Linkage,
+ const Twine &Name, Constant *Aliasee,
+ Module *Parent);
// Without the Aliasee.
- static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
- LinkageTypes Linkage, const Twine &Name,
- Module *Parent);
+ static GlobalAlias *create(PointerType *Ty, LinkageTypes Linkage,
+ const Twine &Name, Module *Parent);
// The module is taken from the Aliasee.
- static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
- LinkageTypes Linkage, const Twine &Name,
- GlobalValue *Aliasee);
+ static GlobalAlias *create(PointerType *Ty, LinkageTypes Linkage,
+ const Twine &Name, GlobalValue *Aliasee);
// Type, Parent and AddressSpace taken from the Aliasee.
static GlobalAlias *create(LinkageTypes Linkage, const Twine &Name,
Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=236160&r1=236159&r2=236160&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Wed Apr 29 16:22:39 2015
@@ -663,13 +663,11 @@ bool LLParser::ParseAlias(const std::str
auto *PTy = dyn_cast<PointerType>(AliaseeType);
if (!PTy)
return Error(AliaseeLoc, "An alias must have pointer type");
- Type *Ty = PTy->getElementType();
- unsigned AddrSpace = PTy->getAddressSpace();
// Okay, create the alias but do not insert it into the module yet.
std::unique_ptr<GlobalAlias> GA(
- GlobalAlias::create(Ty, AddrSpace, (GlobalValue::LinkageTypes)Linkage,
- Name, Aliasee, /*Parent*/ nullptr));
+ GlobalAlias::create(PTy, (GlobalValue::LinkageTypes)Linkage, Name,
+ Aliasee, /*Parent*/ nullptr));
GA->setThreadLocalMode(TLM);
GA->setVisibility((GlobalValue::VisibilityTypes)Visibility);
GA->setDLLStorageClass((GlobalValue::DLLStorageClassTypes)DLLStorageClass);
Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=236160&r1=236159&r2=236160&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Wed Apr 29 16:22:39 2015
@@ -3041,8 +3041,7 @@ std::error_code BitcodeReader::ParseModu
return Error("Invalid type for value");
auto *NewGA =
- GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
- getDecodedLinkage(Record[2]), "", TheModule);
+ GlobalAlias::create(PTy, getDecodedLinkage(Record[2]), "", TheModule);
// Old bitcode files didn't have visibility field.
// Local linkage must have default visibility.
if (Record.size() > 3 && !NewGA->hasLocalLinkage())
Modified: llvm/trunk/lib/CodeGen/GlobalMerge.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalMerge.cpp?rev=236160&r1=236159&r2=236160&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalMerge.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalMerge.cpp Wed Apr 29 16:22:39 2015
@@ -459,8 +459,7 @@ bool GlobalMerge::doMerge(SmallVectorImp
if (Linkage != GlobalValue::InternalLinkage) {
// Generate a new alias...
auto *PTy = cast<PointerType>(GEP->getType());
- GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
- Linkage, Name, GEP, &M);
+ GlobalAlias::create(PTy, Linkage, Name, GEP, &M);
}
NumMerged++;
Modified: llvm/trunk/lib/ExecutionEngine/Orc/CloneSubModule.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/CloneSubModule.cpp?rev=236160&r1=236159&r2=236160&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/CloneSubModule.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/CloneSubModule.cpp Wed Apr 29 16:22:39 2015
@@ -61,9 +61,7 @@ void CloneSubModule(llvm::Module &Dst, c
for (Module::const_alias_iterator I = Src.alias_begin(), E = Src.alias_end();
I != E; ++I) {
auto *PTy = cast<PointerType>(I->getType());
- auto *GA =
- GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
- I->getLinkage(), I->getName(), &Dst);
+ auto *GA = GlobalAlias::create(PTy, I->getLinkage(), I->getName(), &Dst);
GA->copyAttributesFrom(I);
VMap[I] = GA;
}
Modified: llvm/trunk/lib/IR/Core.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Core.cpp?rev=236160&r1=236159&r2=236160&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Core.cpp (original)
+++ llvm/trunk/lib/IR/Core.cpp Wed Apr 29 16:22:39 2015
@@ -1634,8 +1634,7 @@ void LLVMSetExternallyInitialized(LLVMVa
LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
const char *Name) {
auto *PTy = cast<PointerType>(unwrap(Ty));
- return wrap(GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
- GlobalValue::ExternalLinkage, Name,
+ return wrap(GlobalAlias::create(PTy, GlobalValue::ExternalLinkage, Name,
unwrap<Constant>(Aliasee), unwrap(M)));
}
Modified: llvm/trunk/lib/IR/Globals.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Globals.cpp?rev=236160&r1=236159&r2=236160&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Globals.cpp (original)
+++ llvm/trunk/lib/IR/Globals.cpp Wed Apr 29 16:22:39 2015
@@ -241,40 +241,35 @@ void GlobalVariable::copyAttributesFrom(
// GlobalAlias Implementation
//===----------------------------------------------------------------------===//
-GlobalAlias::GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Link,
- const Twine &Name, Constant *Aliasee,
- Module *ParentModule)
- : GlobalValue(PointerType::get(Ty, AddressSpace), Value::GlobalAliasVal,
- &Op<0>(), 1, Link, Name) {
+GlobalAlias::GlobalAlias(PointerType *Ty, LinkageTypes Link, const Twine &Name,
+ Constant *Aliasee, Module *ParentModule)
+ : GlobalValue(Ty, Value::GlobalAliasVal, &Op<0>(), 1, Link, Name) {
Op<0>() = Aliasee;
if (ParentModule)
ParentModule->getAliasList().push_back(this);
}
-GlobalAlias *GlobalAlias::create(Type *Ty, unsigned AddressSpace,
- LinkageTypes Link, const Twine &Name,
- Constant *Aliasee, Module *ParentModule) {
- return new GlobalAlias(Ty, AddressSpace, Link, Name, Aliasee, ParentModule);
+GlobalAlias *GlobalAlias::create(PointerType *Ty, LinkageTypes Link,
+ const Twine &Name, Constant *Aliasee,
+ Module *ParentModule) {
+ return new GlobalAlias(Ty, Link, Name, Aliasee, ParentModule);
}
-GlobalAlias *GlobalAlias::create(Type *Ty, unsigned AddressSpace,
- LinkageTypes Linkage, const Twine &Name,
- Module *Parent) {
- return create(Ty, AddressSpace, Linkage, Name, nullptr, Parent);
+GlobalAlias *GlobalAlias::create(PointerType *Ty, LinkageTypes Linkage,
+ const Twine &Name, Module *Parent) {
+ return create(Ty, Linkage, Name, nullptr, Parent);
}
-GlobalAlias *GlobalAlias::create(Type *Ty, unsigned AddressSpace,
- LinkageTypes Linkage, const Twine &Name,
- GlobalValue *Aliasee) {
- return create(Ty, AddressSpace, Linkage, Name, Aliasee, Aliasee->getParent());
+GlobalAlias *GlobalAlias::create(PointerType *Ty, LinkageTypes Linkage,
+ const Twine &Name, GlobalValue *Aliasee) {
+ return create(Ty, Linkage, Name, Aliasee, Aliasee->getParent());
}
GlobalAlias *GlobalAlias::create(LinkageTypes Link, const Twine &Name,
GlobalValue *Aliasee) {
PointerType *PTy = Aliasee->getType();
- return create(PTy->getElementType(), PTy->getAddressSpace(), Link, Name,
- Aliasee);
+ return create(PTy, Link, Name, Aliasee);
}
GlobalAlias *GlobalAlias::create(const Twine &Name, GlobalValue *Aliasee) {
Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=236160&r1=236159&r2=236160&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Wed Apr 29 16:22:39 2015
@@ -582,8 +582,7 @@ static GlobalAlias *copyGlobalAliasProto
// 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()));
- return GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
- SGA->getLinkage(), SGA->getName(), &DstM);
+ return GlobalAlias::create(PTy, SGA->getLinkage(), SGA->getName(), &DstM);
}
static GlobalValue *copyGlobalValueProto(TypeMapTy &TypeMap, Module &DstM,
Modified: llvm/trunk/lib/Transforms/IPO/LowerBitSets.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/LowerBitSets.cpp?rev=236160&r1=236159&r2=236160&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/LowerBitSets.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/LowerBitSets.cpp Wed Apr 29 16:22:39 2015
@@ -358,8 +358,9 @@ void LowerBitSets::allocateByteArrays()
if (LinkerSubsectionsViaSymbols) {
BAI->ByteArray->replaceAllUsesWith(GEP);
} else {
- GlobalAlias *Alias = GlobalAlias::create(
- Int8Ty, 0, GlobalValue::PrivateLinkage, "bits", GEP, M);
+ GlobalAlias *Alias =
+ GlobalAlias::create(PointerType::getUnqual(Int8Ty),
+ GlobalValue::PrivateLinkage, "bits", GEP, M);
BAI->ByteArray->replaceAllUsesWith(Alias);
}
BAI->ByteArray->eraseFromParent();
@@ -401,7 +402,7 @@ Value *LowerBitSets::createBitSetTest(IR
// Each use of the byte array uses a different alias. This makes the
// backend less likely to reuse previously computed byte array addresses,
// improving the security of the CFI mechanism based on this pass.
- ByteArray = GlobalAlias::create(BAI->ByteArray->getValueType(), 0,
+ ByteArray = GlobalAlias::create(BAI->ByteArray->getType(),
GlobalValue::PrivateLinkage, "bits_use",
ByteArray, M);
}
@@ -553,10 +554,9 @@ void LowerBitSets::buildBitSetsFromGloba
if (LinkerSubsectionsViaSymbols) {
Globals[I]->replaceAllUsesWith(CombinedGlobalElemPtr);
} else {
- GlobalAlias *GAlias = GlobalAlias::create(
- Globals[I]->getType()->getElementType(),
- Globals[I]->getType()->getAddressSpace(), Globals[I]->getLinkage(),
- "", CombinedGlobalElemPtr, M);
+ GlobalAlias *GAlias =
+ GlobalAlias::create(Globals[I]->getType(), Globals[I]->getLinkage(),
+ "", CombinedGlobalElemPtr, M);
GAlias->takeName(Globals[I]);
Globals[I]->replaceAllUsesWith(GAlias);
}
Modified: llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp?rev=236160&r1=236159&r2=236160&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp Wed Apr 29 16:22:39 2015
@@ -1358,8 +1358,7 @@ void MergeFunctions::writeThunk(Function
// Replace G with an alias to F and delete G.
void MergeFunctions::writeAlias(Function *F, Function *G) {
PointerType *PTy = G->getType();
- auto *GA = GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
- G->getLinkage(), "", F);
+ auto *GA = GlobalAlias::create(PTy, G->getLinkage(), "", F);
F->setAlignment(std::max(F->getAlignment(), G->getAlignment()));
GA->takeName(G);
GA->setVisibility(G->getVisibility());
Modified: llvm/trunk/lib/Transforms/Utils/CloneModule.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/CloneModule.cpp?rev=236160&r1=236159&r2=236160&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/CloneModule.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/CloneModule.cpp Wed Apr 29 16:22:39 2015
@@ -69,9 +69,7 @@ Module *llvm::CloneModule(const Module *
for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end();
I != E; ++I) {
auto *PTy = cast<PointerType>(I->getType());
- auto *GA =
- GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
- I->getLinkage(), I->getName(), New);
+ auto *GA = GlobalAlias::create(PTy, I->getLinkage(), I->getName(), New);
GA->copyAttributesFrom(I);
VMap[I] = GA;
}
Modified: llvm/trunk/unittests/IR/ConstantsTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/ConstantsTest.cpp?rev=236160&r1=236159&r2=236160&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/ConstantsTest.cpp (original)
+++ llvm/trunk/unittests/IR/ConstantsTest.cpp Wed Apr 29 16:22:39 2015
@@ -348,7 +348,7 @@ TEST(ConstantsTest, GEPReplaceWithConsta
std::unique_ptr<Module> M(new Module("MyModule", Context));
Type *IntTy = Type::getInt32Ty(Context);
- Type *PtrTy = PointerType::get(IntTy, 0);
+ auto *PtrTy = PointerType::get(IntTy, 0);
auto *C1 = ConstantInt::get(IntTy, 1);
auto *Placeholder = new GlobalVariable(
*M, IntTy, false, GlobalValue::ExternalWeakLinkage, nullptr);
@@ -361,7 +361,7 @@ TEST(ConstantsTest, GEPReplaceWithConsta
auto *Global = new GlobalVariable(*M, PtrTy, false,
GlobalValue::ExternalLinkage, nullptr);
- auto *Alias = GlobalAlias::create(IntTy, 0, GlobalValue::ExternalLinkage,
+ auto *Alias = GlobalAlias::create(PtrTy, GlobalValue::ExternalLinkage,
"alias", Global, M.get());
Placeholder->replaceAllUsesWith(Alias);
ASSERT_EQ(GEP, Ref->getInitializer());
More information about the llvm-commits
mailing list