[opaque pointer types] Switch a few cases of getElementType over, since I had them...
authorDavid Blaikie <dblaikie@gmail.com>
Mon, 14 Sep 2015 20:29:26 +0000 (20:29 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Mon, 14 Sep 2015 20:29:26 +0000 (20:29 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247610 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/GlobalMerge.cpp
lib/Linker/LinkModules.cpp
lib/Transforms/IPO/LowerBitSets.cpp
lib/Transforms/IPO/MergeFunctions.cpp
lib/Transforms/Utils/CloneModule.cpp

index 3d3f354bcdd9e499c85409773d987012113378eb..da5c94595489df229988412f2d3ba166d114ac3b 100644 (file)
@@ -441,13 +441,13 @@ bool GlobalMerge::doMerge(const SmallVectorImpl<GlobalVariable *> &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<GlobalVariable *> &Globals,
       // MergedGlobals variable) may be dead stripped at link time.
       if (Linkage != GlobalValue::InternalLinkage ||
           !TM->getTargetTriple().isOSBinFormatMachO()) {
-        auto *PTy = cast<PointerType>(GEP->getType());
-        GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
-                            Linkage, Name, GEP, &M);
+        GlobalAlias::create(Tys[idx], AddrSpace, Linkage, Name, GEP, &M);
       }
 
       NumMerged++;
index 4b676cdf9dcd430505ae098d6816d59295e75756..4d939a62f4bb76fac4d530cb58834cf7de8aca7c 100644 (file)
@@ -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<PointerType>(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);
 }
 
index 555fc4f45a9c65f6ab4a9506adca41060f3fceb6..5d7feb14a511c9e53bb4d42f87a6079590725668 100644 (file)
@@ -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<StructType>(NewInit->getType()));
+  StructType *NewTy = cast<StructType>(NewInit->getType());
+  const StructLayout *CombinedGlobalLayout = DL.getStructLayout(NewTy);
 
   // Compute the offsets of the original globals within the new global.
   DenseMap<GlobalObject *, uint64_t> 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<Metadata *> 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);
index a1f45137bf5c3207518900c57472fe420c6c06d6..2b0bcdff72f527ce1d8456336ca2191487570d18 100644 (file)
@@ -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());
index 9136b19ccb9a0033841bbcf084c3df94e508c255..3adb6e433ec4c1b50d61bf3caa4904edf4978c8a 100644 (file)
@@ -94,10 +94,9 @@ Module *llvm::CloneModule(
       // correctness.
       continue;
     }
-    auto *PTy = cast<PointerType>(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;
   }