mirror of
https://github.com/RPCS3/llvm.git
synced 2025-01-05 19:29:54 +00:00
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@236160 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
a19abeb7ab
commit
39e7388a19
@ -33,8 +33,8 @@ class GlobalAlias : public GlobalValue, public ilist_node<GlobalAlias> {
|
|||||||
|
|
||||||
void setParent(Module *parent);
|
void setParent(Module *parent);
|
||||||
|
|
||||||
GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage,
|
GlobalAlias(PointerType *Ty, LinkageTypes Linkage, const Twine &Name,
|
||||||
const Twine &Name, Constant *Aliasee, Module *Parent);
|
Constant *Aliasee, Module *Parent);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// allocate space for exactly one operand
|
// allocate space for exactly one operand
|
||||||
@ -44,19 +44,17 @@ public:
|
|||||||
|
|
||||||
/// If a parent module is specified, the alias is automatically inserted into
|
/// If a parent module is specified, the alias is automatically inserted into
|
||||||
/// the end of the specified module's alias list.
|
/// the end of the specified module's alias list.
|
||||||
static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
|
static GlobalAlias *create(PointerType *Ty, LinkageTypes Linkage,
|
||||||
LinkageTypes Linkage, const Twine &Name,
|
const Twine &Name, Constant *Aliasee,
|
||||||
Constant *Aliasee, Module *Parent);
|
|
||||||
|
|
||||||
// Without the Aliasee.
|
|
||||||
static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
|
|
||||||
LinkageTypes Linkage, const Twine &Name,
|
|
||||||
Module *Parent);
|
Module *Parent);
|
||||||
|
|
||||||
|
// Without the Aliasee.
|
||||||
|
static GlobalAlias *create(PointerType *Ty, LinkageTypes Linkage,
|
||||||
|
const Twine &Name, Module *Parent);
|
||||||
|
|
||||||
// The module is taken from the Aliasee.
|
// The module is taken from the Aliasee.
|
||||||
static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
|
static GlobalAlias *create(PointerType *Ty, LinkageTypes Linkage,
|
||||||
LinkageTypes Linkage, const Twine &Name,
|
const Twine &Name, GlobalValue *Aliasee);
|
||||||
GlobalValue *Aliasee);
|
|
||||||
|
|
||||||
// Type, Parent and AddressSpace taken from the Aliasee.
|
// Type, Parent and AddressSpace taken from the Aliasee.
|
||||||
static GlobalAlias *create(LinkageTypes Linkage, const Twine &Name,
|
static GlobalAlias *create(LinkageTypes Linkage, const Twine &Name,
|
||||||
|
@ -663,13 +663,11 @@ bool LLParser::ParseAlias(const std::string &Name, LocTy NameLoc, unsigned L,
|
|||||||
auto *PTy = dyn_cast<PointerType>(AliaseeType);
|
auto *PTy = dyn_cast<PointerType>(AliaseeType);
|
||||||
if (!PTy)
|
if (!PTy)
|
||||||
return Error(AliaseeLoc, "An alias must have pointer type");
|
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.
|
// Okay, create the alias but do not insert it into the module yet.
|
||||||
std::unique_ptr<GlobalAlias> GA(
|
std::unique_ptr<GlobalAlias> GA(
|
||||||
GlobalAlias::create(Ty, AddrSpace, (GlobalValue::LinkageTypes)Linkage,
|
GlobalAlias::create(PTy, (GlobalValue::LinkageTypes)Linkage, Name,
|
||||||
Name, Aliasee, /*Parent*/ nullptr));
|
Aliasee, /*Parent*/ nullptr));
|
||||||
GA->setThreadLocalMode(TLM);
|
GA->setThreadLocalMode(TLM);
|
||||||
GA->setVisibility((GlobalValue::VisibilityTypes)Visibility);
|
GA->setVisibility((GlobalValue::VisibilityTypes)Visibility);
|
||||||
GA->setDLLStorageClass((GlobalValue::DLLStorageClassTypes)DLLStorageClass);
|
GA->setDLLStorageClass((GlobalValue::DLLStorageClassTypes)DLLStorageClass);
|
||||||
|
@ -3041,8 +3041,7 @@ std::error_code BitcodeReader::ParseModule(bool Resume,
|
|||||||
return Error("Invalid type for value");
|
return Error("Invalid type for value");
|
||||||
|
|
||||||
auto *NewGA =
|
auto *NewGA =
|
||||||
GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
|
GlobalAlias::create(PTy, getDecodedLinkage(Record[2]), "", TheModule);
|
||||||
getDecodedLinkage(Record[2]), "", TheModule);
|
|
||||||
// Old bitcode files didn't have visibility field.
|
// Old bitcode files didn't have visibility field.
|
||||||
// Local linkage must have default visibility.
|
// Local linkage must have default visibility.
|
||||||
if (Record.size() > 3 && !NewGA->hasLocalLinkage())
|
if (Record.size() > 3 && !NewGA->hasLocalLinkage())
|
||||||
|
@ -459,8 +459,7 @@ bool GlobalMerge::doMerge(SmallVectorImpl<GlobalVariable *> &Globals,
|
|||||||
if (Linkage != GlobalValue::InternalLinkage) {
|
if (Linkage != GlobalValue::InternalLinkage) {
|
||||||
// Generate a new alias...
|
// Generate a new alias...
|
||||||
auto *PTy = cast<PointerType>(GEP->getType());
|
auto *PTy = cast<PointerType>(GEP->getType());
|
||||||
GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
|
GlobalAlias::create(PTy, Linkage, Name, GEP, &M);
|
||||||
Linkage, Name, GEP, &M);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NumMerged++;
|
NumMerged++;
|
||||||
|
@ -61,9 +61,7 @@ void CloneSubModule(llvm::Module &Dst, const Module &Src,
|
|||||||
for (Module::const_alias_iterator I = Src.alias_begin(), E = Src.alias_end();
|
for (Module::const_alias_iterator I = Src.alias_begin(), E = Src.alias_end();
|
||||||
I != E; ++I) {
|
I != E; ++I) {
|
||||||
auto *PTy = cast<PointerType>(I->getType());
|
auto *PTy = cast<PointerType>(I->getType());
|
||||||
auto *GA =
|
auto *GA = GlobalAlias::create(PTy, I->getLinkage(), I->getName(), &Dst);
|
||||||
GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
|
|
||||||
I->getLinkage(), I->getName(), &Dst);
|
|
||||||
GA->copyAttributesFrom(I);
|
GA->copyAttributesFrom(I);
|
||||||
VMap[I] = GA;
|
VMap[I] = GA;
|
||||||
}
|
}
|
||||||
|
@ -1634,8 +1634,7 @@ void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit) {
|
|||||||
LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
|
LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
|
||||||
const char *Name) {
|
const char *Name) {
|
||||||
auto *PTy = cast<PointerType>(unwrap(Ty));
|
auto *PTy = cast<PointerType>(unwrap(Ty));
|
||||||
return wrap(GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
|
return wrap(GlobalAlias::create(PTy, GlobalValue::ExternalLinkage, Name,
|
||||||
GlobalValue::ExternalLinkage, Name,
|
|
||||||
unwrap<Constant>(Aliasee), unwrap(M)));
|
unwrap<Constant>(Aliasee), unwrap(M)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,40 +241,35 @@ void GlobalVariable::copyAttributesFrom(const GlobalValue *Src) {
|
|||||||
// GlobalAlias Implementation
|
// GlobalAlias Implementation
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
GlobalAlias::GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Link,
|
GlobalAlias::GlobalAlias(PointerType *Ty, LinkageTypes Link, const Twine &Name,
|
||||||
const Twine &Name, Constant *Aliasee,
|
Constant *Aliasee, Module *ParentModule)
|
||||||
Module *ParentModule)
|
: GlobalValue(Ty, Value::GlobalAliasVal, &Op<0>(), 1, Link, Name) {
|
||||||
: GlobalValue(PointerType::get(Ty, AddressSpace), Value::GlobalAliasVal,
|
|
||||||
&Op<0>(), 1, Link, Name) {
|
|
||||||
Op<0>() = Aliasee;
|
Op<0>() = Aliasee;
|
||||||
|
|
||||||
if (ParentModule)
|
if (ParentModule)
|
||||||
ParentModule->getAliasList().push_back(this);
|
ParentModule->getAliasList().push_back(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalAlias *GlobalAlias::create(Type *Ty, unsigned AddressSpace,
|
GlobalAlias *GlobalAlias::create(PointerType *Ty, LinkageTypes Link,
|
||||||
LinkageTypes Link, const Twine &Name,
|
const Twine &Name, Constant *Aliasee,
|
||||||
Constant *Aliasee, Module *ParentModule) {
|
Module *ParentModule) {
|
||||||
return new GlobalAlias(Ty, AddressSpace, Link, Name, Aliasee, ParentModule);
|
return new GlobalAlias(Ty, Link, Name, Aliasee, ParentModule);
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalAlias *GlobalAlias::create(Type *Ty, unsigned AddressSpace,
|
GlobalAlias *GlobalAlias::create(PointerType *Ty, LinkageTypes Linkage,
|
||||||
LinkageTypes Linkage, const Twine &Name,
|
const Twine &Name, Module *Parent) {
|
||||||
Module *Parent) {
|
return create(Ty, Linkage, Name, nullptr, Parent);
|
||||||
return create(Ty, AddressSpace, Linkage, Name, nullptr, Parent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalAlias *GlobalAlias::create(Type *Ty, unsigned AddressSpace,
|
GlobalAlias *GlobalAlias::create(PointerType *Ty, LinkageTypes Linkage,
|
||||||
LinkageTypes Linkage, const Twine &Name,
|
const Twine &Name, GlobalValue *Aliasee) {
|
||||||
GlobalValue *Aliasee) {
|
return create(Ty, Linkage, Name, Aliasee, Aliasee->getParent());
|
||||||
return create(Ty, AddressSpace, Linkage, Name, Aliasee, Aliasee->getParent());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalAlias *GlobalAlias::create(LinkageTypes Link, const Twine &Name,
|
GlobalAlias *GlobalAlias::create(LinkageTypes Link, const Twine &Name,
|
||||||
GlobalValue *Aliasee) {
|
GlobalValue *Aliasee) {
|
||||||
PointerType *PTy = Aliasee->getType();
|
PointerType *PTy = Aliasee->getType();
|
||||||
return create(PTy->getElementType(), PTy->getAddressSpace(), Link, Name,
|
return create(PTy, Link, Name, Aliasee);
|
||||||
Aliasee);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalAlias *GlobalAlias::create(const Twine &Name, GlobalValue *Aliasee) {
|
GlobalAlias *GlobalAlias::create(const Twine &Name, GlobalValue *Aliasee) {
|
||||||
|
@ -582,8 +582,7 @@ static GlobalAlias *copyGlobalAliasProto(TypeMapTy &TypeMap, Module &DstM,
|
|||||||
// If there is no linkage to be performed or we're linking from the source,
|
// If there is no linkage to be performed or we're linking from the source,
|
||||||
// bring over SGA.
|
// bring over SGA.
|
||||||
auto *PTy = cast<PointerType>(TypeMap.get(SGA->getType()));
|
auto *PTy = cast<PointerType>(TypeMap.get(SGA->getType()));
|
||||||
return GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
|
return GlobalAlias::create(PTy, SGA->getLinkage(), SGA->getName(), &DstM);
|
||||||
SGA->getLinkage(), SGA->getName(), &DstM);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static GlobalValue *copyGlobalValueProto(TypeMapTy &TypeMap, Module &DstM,
|
static GlobalValue *copyGlobalValueProto(TypeMapTy &TypeMap, Module &DstM,
|
||||||
|
@ -358,8 +358,9 @@ void LowerBitSets::allocateByteArrays() {
|
|||||||
if (LinkerSubsectionsViaSymbols) {
|
if (LinkerSubsectionsViaSymbols) {
|
||||||
BAI->ByteArray->replaceAllUsesWith(GEP);
|
BAI->ByteArray->replaceAllUsesWith(GEP);
|
||||||
} else {
|
} else {
|
||||||
GlobalAlias *Alias = GlobalAlias::create(
|
GlobalAlias *Alias =
|
||||||
Int8Ty, 0, GlobalValue::PrivateLinkage, "bits", GEP, M);
|
GlobalAlias::create(PointerType::getUnqual(Int8Ty),
|
||||||
|
GlobalValue::PrivateLinkage, "bits", GEP, M);
|
||||||
BAI->ByteArray->replaceAllUsesWith(Alias);
|
BAI->ByteArray->replaceAllUsesWith(Alias);
|
||||||
}
|
}
|
||||||
BAI->ByteArray->eraseFromParent();
|
BAI->ByteArray->eraseFromParent();
|
||||||
@ -401,7 +402,7 @@ Value *LowerBitSets::createBitSetTest(IRBuilder<> &B, BitSetInfo &BSI,
|
|||||||
// Each use of the byte array uses a different alias. This makes the
|
// Each use of the byte array uses a different alias. This makes the
|
||||||
// backend less likely to reuse previously computed byte array addresses,
|
// backend less likely to reuse previously computed byte array addresses,
|
||||||
// improving the security of the CFI mechanism based on this pass.
|
// 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",
|
GlobalValue::PrivateLinkage, "bits_use",
|
||||||
ByteArray, M);
|
ByteArray, M);
|
||||||
}
|
}
|
||||||
@ -553,10 +554,9 @@ void LowerBitSets::buildBitSetsFromGlobals(
|
|||||||
if (LinkerSubsectionsViaSymbols) {
|
if (LinkerSubsectionsViaSymbols) {
|
||||||
Globals[I]->replaceAllUsesWith(CombinedGlobalElemPtr);
|
Globals[I]->replaceAllUsesWith(CombinedGlobalElemPtr);
|
||||||
} else {
|
} else {
|
||||||
GlobalAlias *GAlias = GlobalAlias::create(
|
GlobalAlias *GAlias =
|
||||||
Globals[I]->getType()->getElementType(),
|
GlobalAlias::create(Globals[I]->getType(), Globals[I]->getLinkage(),
|
||||||
Globals[I]->getType()->getAddressSpace(), Globals[I]->getLinkage(),
|
"", CombinedGlobalElemPtr, M);
|
||||||
"", CombinedGlobalElemPtr, M);
|
|
||||||
GAlias->takeName(Globals[I]);
|
GAlias->takeName(Globals[I]);
|
||||||
Globals[I]->replaceAllUsesWith(GAlias);
|
Globals[I]->replaceAllUsesWith(GAlias);
|
||||||
}
|
}
|
||||||
|
@ -1358,8 +1358,7 @@ void MergeFunctions::writeThunk(Function *F, Function *G) {
|
|||||||
// Replace G with an alias to F and delete G.
|
// Replace G with an alias to F and delete G.
|
||||||
void MergeFunctions::writeAlias(Function *F, Function *G) {
|
void MergeFunctions::writeAlias(Function *F, Function *G) {
|
||||||
PointerType *PTy = G->getType();
|
PointerType *PTy = G->getType();
|
||||||
auto *GA = GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
|
auto *GA = GlobalAlias::create(PTy, G->getLinkage(), "", F);
|
||||||
G->getLinkage(), "", F);
|
|
||||||
F->setAlignment(std::max(F->getAlignment(), G->getAlignment()));
|
F->setAlignment(std::max(F->getAlignment(), G->getAlignment()));
|
||||||
GA->takeName(G);
|
GA->takeName(G);
|
||||||
GA->setVisibility(G->getVisibility());
|
GA->setVisibility(G->getVisibility());
|
||||||
|
@ -69,9 +69,7 @@ Module *llvm::CloneModule(const Module *M, ValueToValueMapTy &VMap) {
|
|||||||
for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end();
|
for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end();
|
||||||
I != E; ++I) {
|
I != E; ++I) {
|
||||||
auto *PTy = cast<PointerType>(I->getType());
|
auto *PTy = cast<PointerType>(I->getType());
|
||||||
auto *GA =
|
auto *GA = GlobalAlias::create(PTy, I->getLinkage(), I->getName(), New);
|
||||||
GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
|
|
||||||
I->getLinkage(), I->getName(), New);
|
|
||||||
GA->copyAttributesFrom(I);
|
GA->copyAttributesFrom(I);
|
||||||
VMap[I] = GA;
|
VMap[I] = GA;
|
||||||
}
|
}
|
||||||
|
@ -348,7 +348,7 @@ TEST(ConstantsTest, GEPReplaceWithConstant) {
|
|||||||
std::unique_ptr<Module> M(new Module("MyModule", Context));
|
std::unique_ptr<Module> M(new Module("MyModule", Context));
|
||||||
|
|
||||||
Type *IntTy = Type::getInt32Ty(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 *C1 = ConstantInt::get(IntTy, 1);
|
||||||
auto *Placeholder = new GlobalVariable(
|
auto *Placeholder = new GlobalVariable(
|
||||||
*M, IntTy, false, GlobalValue::ExternalWeakLinkage, nullptr);
|
*M, IntTy, false, GlobalValue::ExternalWeakLinkage, nullptr);
|
||||||
@ -361,7 +361,7 @@ TEST(ConstantsTest, GEPReplaceWithConstant) {
|
|||||||
|
|
||||||
auto *Global = new GlobalVariable(*M, PtrTy, false,
|
auto *Global = new GlobalVariable(*M, PtrTy, false,
|
||||||
GlobalValue::ExternalLinkage, nullptr);
|
GlobalValue::ExternalLinkage, nullptr);
|
||||||
auto *Alias = GlobalAlias::create(IntTy, 0, GlobalValue::ExternalLinkage,
|
auto *Alias = GlobalAlias::create(PtrTy, GlobalValue::ExternalLinkage,
|
||||||
"alias", Global, M.get());
|
"alias", Global, M.get());
|
||||||
Placeholder->replaceAllUsesWith(Alias);
|
Placeholder->replaceAllUsesWith(Alias);
|
||||||
ASSERT_EQ(GEP, Ref->getInitializer());
|
ASSERT_EQ(GEP, Ref->getInitializer());
|
||||||
|
Loading…
Reference in New Issue
Block a user