From 3beddeee6c59c4941da9c4b3659e42b9c92cd61d Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Mon, 14 Sep 2015 20:29:26 +0000 Subject: [PATCH] [opaque pointer types] Switch a few cases of getElementType over, since I had them lying around anyway git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247610 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/GlobalMerge.cpp | 8 +++----- lib/Linker/LinkModules.cpp | 4 ++-- lib/Transforms/IPO/LowerBitSets.cpp | 24 ++++++++++++------------ lib/Transforms/IPO/MergeFunctions.cpp | 4 +--- lib/Transforms/Utils/CloneModule.cpp | 7 +++---- 5 files changed, 21 insertions(+), 26 deletions(-) diff --git a/lib/CodeGen/GlobalMerge.cpp b/lib/CodeGen/GlobalMerge.cpp index 3d3f354bcdd..da5c9459548 100644 --- a/lib/CodeGen/GlobalMerge.cpp +++ b/lib/CodeGen/GlobalMerge.cpp @@ -441,13 +441,13 @@ bool GlobalMerge::doMerge(const SmallVectorImpl &Globals, M, MergedTy, isConst, GlobalValue::PrivateLinkage, MergedInit, "_MergedGlobals", nullptr, GlobalVariable::NotThreadLocal, AddrSpace); - for (ssize_t k = i, idx = 0; k != j; k = GlobalSet.find_next(k)) { + for (ssize_t k = i, idx = 0; k != j; k = GlobalSet.find_next(k), ++idx) { GlobalValue::LinkageTypes Linkage = Globals[k]->getLinkage(); std::string Name = Globals[k]->getName(); Constant *Idx[2] = { ConstantInt::get(Int32Ty, 0), - ConstantInt::get(Int32Ty, idx++) + ConstantInt::get(Int32Ty, idx), }; Constant *GEP = ConstantExpr::getInBoundsGetElementPtr(MergedTy, MergedGV, Idx); @@ -461,9 +461,7 @@ bool GlobalMerge::doMerge(const SmallVectorImpl &Globals, // MergedGlobals variable) may be dead stripped at link time. if (Linkage != GlobalValue::InternalLinkage || !TM->getTargetTriple().isOSBinFormatMachO()) { - auto *PTy = cast(GEP->getType()); - GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(), - Linkage, Name, GEP, &M); + GlobalAlias::create(Tys[idx], AddrSpace, Linkage, Name, GEP, &M); } NumMerged++; diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index 4b676cdf9dc..4d939a62f4b 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -585,8 +585,8 @@ static GlobalAlias *copyGlobalAliasProto(TypeMapTy &TypeMap, Module &DstM, const GlobalAlias *SGA) { // If there is no linkage to be performed or we're linking from the source, // bring over SGA. - auto *PTy = cast(TypeMap.get(SGA->getType())); - return GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(), + auto *Ty = TypeMap.get(SGA->getValueType()); + return GlobalAlias::create(Ty, SGA->getType()->getPointerAddressSpace(), SGA->getLinkage(), SGA->getName(), &DstM); } diff --git a/lib/Transforms/IPO/LowerBitSets.cpp b/lib/Transforms/IPO/LowerBitSets.cpp index 555fc4f45a9..5d7feb14a51 100644 --- a/lib/Transforms/IPO/LowerBitSets.cpp +++ b/lib/Transforms/IPO/LowerBitSets.cpp @@ -537,7 +537,7 @@ void LowerBitSets::buildBitSetsFromGlobalVariables( const DataLayout &DL = M->getDataLayout(); for (GlobalVariable *G : Globals) { GlobalInits.push_back(G->getInitializer()); - uint64_t InitSize = DL.getTypeAllocSize(G->getInitializer()->getType()); + uint64_t InitSize = DL.getTypeAllocSize(G->getValueType()); // Compute the amount of padding required. uint64_t Padding = NextPowerOf2(InitSize - 1) - InitSize; @@ -553,12 +553,12 @@ void LowerBitSets::buildBitSetsFromGlobalVariables( if (!GlobalInits.empty()) GlobalInits.pop_back(); Constant *NewInit = ConstantStruct::getAnon(M->getContext(), GlobalInits); - auto CombinedGlobal = + auto *CombinedGlobal = new GlobalVariable(*M, NewInit->getType(), /*isConstant=*/true, GlobalValue::PrivateLinkage, NewInit); - const StructLayout *CombinedGlobalLayout = - DL.getStructLayout(cast(NewInit->getType())); + StructType *NewTy = cast(NewInit->getType()); + const StructLayout *CombinedGlobalLayout = DL.getStructLayout(NewTy); // Compute the offsets of the original globals within the new global. DenseMap GlobalLayout; @@ -580,10 +580,10 @@ void LowerBitSets::buildBitSetsFromGlobalVariables( if (LinkerSubsectionsViaSymbols) { Globals[I]->replaceAllUsesWith(CombinedGlobalElemPtr); } else { - GlobalAlias *GAlias = GlobalAlias::create( - Globals[I]->getType()->getElementType(), - Globals[I]->getType()->getAddressSpace(), Globals[I]->getLinkage(), - "", CombinedGlobalElemPtr, M); + assert(Globals[I]->getType()->getAddressSpace() == 0); + GlobalAlias *GAlias = GlobalAlias::create(NewTy->getElementType(I * 2), 0, + Globals[I]->getLinkage(), "", + CombinedGlobalElemPtr, M); GAlias->setVisibility(Globals[I]->getVisibility()); GAlias->takeName(Globals[I]); Globals[I]->replaceAllUsesWith(GAlias); @@ -818,10 +818,10 @@ void LowerBitSets::buildBitSetsFromFunctions(ArrayRef BitSets, if (LinkerSubsectionsViaSymbols || Functions[I]->isDeclarationForLinker()) { Functions[I]->replaceAllUsesWith(CombinedGlobalElemPtr); } else { - GlobalAlias *GAlias = GlobalAlias::create( - Functions[I]->getType()->getElementType(), - Functions[I]->getType()->getAddressSpace(), - Functions[I]->getLinkage(), "", CombinedGlobalElemPtr, M); + assert(Functions[I]->getType()->getAddressSpace() == 0); + GlobalAlias *GAlias = GlobalAlias::create(Functions[I]->getValueType(), 0, + Functions[I]->getLinkage(), "", + CombinedGlobalElemPtr, M); GAlias->setVisibility(Functions[I]->getVisibility()); GAlias->takeName(Functions[I]); Functions[I]->replaceAllUsesWith(GAlias); diff --git a/lib/Transforms/IPO/MergeFunctions.cpp b/lib/Transforms/IPO/MergeFunctions.cpp index a1f45137bf5..2b0bcdff72f 100644 --- a/lib/Transforms/IPO/MergeFunctions.cpp +++ b/lib/Transforms/IPO/MergeFunctions.cpp @@ -1682,9 +1682,7 @@ 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 = GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(), - G->getLinkage(), "", F); + auto *GA = GlobalAlias::create(G->getLinkage(), "", F); F->setAlignment(std::max(F->getAlignment(), G->getAlignment())); GA->takeName(G); GA->setVisibility(G->getVisibility()); diff --git a/lib/Transforms/Utils/CloneModule.cpp b/lib/Transforms/Utils/CloneModule.cpp index 9136b19ccb9..3adb6e433ec 100644 --- a/lib/Transforms/Utils/CloneModule.cpp +++ b/lib/Transforms/Utils/CloneModule.cpp @@ -94,10 +94,9 @@ Module *llvm::CloneModule( // correctness. continue; } - auto *PTy = cast(I->getType()); - auto *GA = - GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(), - I->getLinkage(), I->getName(), New); + auto *GA = GlobalAlias::create(I->getValueType(), + I->getType()->getPointerAddressSpace(), + I->getLinkage(), I->getName(), New); GA->copyAttributesFrom(I); VMap[I] = GA; } -- 2.11.0