From 4e6013250d319a7ca4fc7fb5ba9ac7b1b28d2b4f 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(). --- llvm/lib/IR/Module.cpp | 2 +- llvm/lib/Linker/LinkModules.cpp | 3 +-- llvm/lib/Object/IRSymtab.cpp | 4 ++-- llvm/lib/Transforms/IPO/GlobalOpt.cpp | 2 +- llvm/lib/Transforms/Utils/MemoryOpRemark.cpp | 2 +- llvm/lib/Transforms/Utils/ValueMapper.cpp | 4 ++-- llvm/unittests/Transforms/Utils/ModuleUtilsTest.cpp | 3 +-- 7 files changed, 9 insertions(+), 11 deletions(-) diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp index 9b955500b6180f..7c18dc0ed299ff 100644 --- a/llvm/lib/IR/Module.cpp +++ b/llvm/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/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp index 98793c58738823..943c2faaf1b111 100644 --- a/llvm/lib/Linker/LinkModules.cpp +++ b/llvm/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/llvm/lib/Object/IRSymtab.cpp b/llvm/lib/Object/IRSymtab.cpp index 70655d1a26be98..bcada85a0c1177 100644 --- a/llvm/lib/Object/IRSymtab.cpp +++ b/llvm/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/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp index ed67b20a4d3dd3..6ac9690251e059 100644 --- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp +++ b/llvm/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/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp b/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp index 0f0b551f754a20..68d4dd9d576b39 100644 --- a/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp +++ b/llvm/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/llvm/lib/Transforms/Utils/ValueMapper.cpp b/llvm/lib/Transforms/Utils/ValueMapper.cpp index a89c92376034d6..f3afd42e616323 100644 --- a/llvm/lib/Transforms/Utils/ValueMapper.cpp +++ b/llvm/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/llvm/unittests/Transforms/Utils/ModuleUtilsTest.cpp b/llvm/unittests/Transforms/Utils/ModuleUtilsTest.cpp index 5a1d9245f1595e..e1bc58fda0e38f 100644 --- a/llvm/unittests/Transforms/Utils/ModuleUtilsTest.cpp +++ b/llvm/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(); }