From e29819ce26138cc83a10a60379a06ea38d666f6c Mon Sep 17 00:00:00 2001 From: Arthur Eubanks Date: Fri, 9 Jul 2021 09:55:07 -0700 Subject: [PATCH] [NFC][OpaquePtr] Use GlobalValue::getValueType() more Instead of getType()->getElementType(). --- lib/IR/Module.cpp | 2 +- lib/Linker/LinkModules.cpp | 3 +-- lib/Object/IRSymtab.cpp | 4 ++-- lib/Transforms/IPO/GlobalOpt.cpp | 2 +- lib/Transforms/Utils/MemoryOpRemark.cpp | 2 +- lib/Transforms/Utils/ValueMapper.cpp | 4 ++-- unittests/Transforms/Utils/ModuleUtilsTest.cpp | 3 +-- 7 files changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/IR/Module.cpp b/lib/IR/Module.cpp index 9b955500b61..7c18dc0ed29 100644 --- a/lib/IR/Module.cpp +++ b/lib/IR/Module.cpp @@ -506,7 +506,7 @@ std::string Module::getUniqueIntrinsicName(StringRef BaseName, Intrinsic::ID Id, } // A declaration with this name already exists. Remember it. - FunctionType *FT = dyn_cast(F->getType()->getElementType()); + FunctionType *FT = dyn_cast(F->getValueType()); auto UinItInserted = UniquedIntrinsicNames.insert({{Id, FT}, Count}); if (FT == Proto) { // It was a declaration for our prototype. This entry was allocated in the diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index 98793c58738..943c2faaf1b 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -438,13 +438,12 @@ void ModuleLinker::dropReplacedComdat( } else { auto &Alias = cast(GV); Module &M = *Alias.getParent(); - PointerType &Ty = *cast(Alias.getType()); GlobalValue *Declaration; if (auto *FTy = dyn_cast(Alias.getValueType())) { Declaration = Function::Create(FTy, GlobalValue::ExternalLinkage, "", &M); } else { Declaration = - new GlobalVariable(M, Ty.getElementType(), /*isConstant*/ false, + new GlobalVariable(M, Alias.getValueType(), /*isConstant*/ false, GlobalValue::ExternalLinkage, /*Initializer*/ nullptr); } diff --git a/lib/Object/IRSymtab.cpp b/lib/Object/IRSymtab.cpp index 70655d1a26b..bcada85a0c1 100644 --- a/lib/Object/IRSymtab.cpp +++ b/lib/Object/IRSymtab.cpp @@ -277,8 +277,8 @@ Error Builder::addSymbol(const ModuleSymbolTable &Msymtab, if (!GVar) return make_error("Only variables can have common linkage!", inconvertibleErrorCode()); - Uncommon().CommonSize = GV->getParent()->getDataLayout().getTypeAllocSize( - GV->getType()->getElementType()); + Uncommon().CommonSize = + GV->getParent()->getDataLayout().getTypeAllocSize(GV->getValueType()); Uncommon().CommonAlign = GVar->getAlignment(); } diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp index ed67b20a4d3..6ac9690251e 100644 --- a/lib/Transforms/IPO/GlobalOpt.cpp +++ b/lib/Transforms/IPO/GlobalOpt.cpp @@ -1186,7 +1186,7 @@ static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal) { DIExpression *E = GVe->getExpression(); const DataLayout &DL = GV->getParent()->getDataLayout(); unsigned SizeInOctets = - DL.getTypeAllocSizeInBits(NewGV->getType()->getElementType()) / 8; + DL.getTypeAllocSizeInBits(NewGV->getValueType()) / 8; // It is expected that the address of global optimized variable is on // top of the stack. After optimization, value of that variable will diff --git a/lib/Transforms/Utils/MemoryOpRemark.cpp b/lib/Transforms/Utils/MemoryOpRemark.cpp index 0f0b551f754..68d4dd9d576 100644 --- a/lib/Transforms/Utils/MemoryOpRemark.cpp +++ b/lib/Transforms/Utils/MemoryOpRemark.cpp @@ -306,7 +306,7 @@ static Optional nameOrNone(const Value *V) { void MemoryOpRemark::visitVariable(const Value *V, SmallVectorImpl &Result) { if (auto *GV = dyn_cast(V)) { - auto *Ty = cast(GV->getType())->getElementType(); + auto *Ty = GV->getValueType(); uint64_t Size = DL.getTypeSizeInBits(Ty).getFixedSize(); VariableInfo Var{nameOrNone(GV), Size}; if (!Var.isEmpty()) diff --git a/lib/Transforms/Utils/ValueMapper.cpp b/lib/Transforms/Utils/ValueMapper.cpp index a89c9237603..f3afd42e616 100644 --- a/lib/Transforms/Utils/ValueMapper.cpp +++ b/lib/Transforms/Utils/ValueMapper.cpp @@ -1032,8 +1032,8 @@ void Mapper::mapAppendingVariable(GlobalVariable &GV, Constant *InitPrefix, Elements.push_back(NewV); } - GV.setInitializer(ConstantArray::get( - cast(GV.getType()->getElementType()), Elements)); + GV.setInitializer( + ConstantArray::get(cast(GV.getValueType()), Elements)); } void Mapper::scheduleMapGlobalInitializer(GlobalVariable &GV, Constant &Init, diff --git a/unittests/Transforms/Utils/ModuleUtilsTest.cpp b/unittests/Transforms/Utils/ModuleUtilsTest.cpp index 5a1d9245f15..e1bc58fda0e 100644 --- a/unittests/Transforms/Utils/ModuleUtilsTest.cpp +++ b/unittests/Transforms/Utils/ModuleUtilsTest.cpp @@ -28,8 +28,7 @@ static int getUsedListSize(Module &M, StringRef Name) { auto *UsedList = M.getGlobalVariable(Name); if (!UsedList) return 0; - auto *UsedListBaseArrayType = - cast(UsedList->getType()->getElementType()); + auto *UsedListBaseArrayType = cast(UsedList->getValueType()); return UsedListBaseArrayType->getNumElements(); }