Skip to content

Commit

Permalink
[NFC][OpaquePtr] Use GlobalValue::getValueType() more
Browse files Browse the repository at this point in the history
Instead of getType()->getElementType().
  • Loading branch information
aeubanks committed Jul 9, 2021
1 parent 486992f commit 4e60132
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion llvm/lib/IR/Module.cpp
Expand Up @@ -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<FunctionType>(F->getType()->getElementType());
FunctionType *FT = dyn_cast<FunctionType>(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
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Linker/LinkModules.cpp
Expand Up @@ -438,13 +438,12 @@ void ModuleLinker::dropReplacedComdat(
} else {
auto &Alias = cast<GlobalAlias>(GV);
Module &M = *Alias.getParent();
PointerType &Ty = *cast<PointerType>(Alias.getType());
GlobalValue *Declaration;
if (auto *FTy = dyn_cast<FunctionType>(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);
}
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Object/IRSymtab.cpp
Expand Up @@ -277,8 +277,8 @@ Error Builder::addSymbol(const ModuleSymbolTable &Msymtab,
if (!GVar)
return make_error<StringError>("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();
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/IPO/GlobalOpt.cpp
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Utils/MemoryOpRemark.cpp
Expand Up @@ -306,7 +306,7 @@ static Optional<StringRef> nameOrNone(const Value *V) {
void MemoryOpRemark::visitVariable(const Value *V,
SmallVectorImpl<VariableInfo> &Result) {
if (auto *GV = dyn_cast<GlobalVariable>(V)) {
auto *Ty = cast<PointerType>(GV->getType())->getElementType();
auto *Ty = GV->getValueType();
uint64_t Size = DL.getTypeSizeInBits(Ty).getFixedSize();
VariableInfo Var{nameOrNone(GV), Size};
if (!Var.isEmpty())
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Utils/ValueMapper.cpp
Expand Up @@ -1032,8 +1032,8 @@ void Mapper::mapAppendingVariable(GlobalVariable &GV, Constant *InitPrefix,
Elements.push_back(NewV);
}

GV.setInitializer(ConstantArray::get(
cast<ArrayType>(GV.getType()->getElementType()), Elements));
GV.setInitializer(
ConstantArray::get(cast<ArrayType>(GV.getValueType()), Elements));
}

void Mapper::scheduleMapGlobalInitializer(GlobalVariable &GV, Constant &Init,
Expand Down
3 changes: 1 addition & 2 deletions llvm/unittests/Transforms/Utils/ModuleUtilsTest.cpp
Expand Up @@ -28,8 +28,7 @@ static int getUsedListSize(Module &M, StringRef Name) {
auto *UsedList = M.getGlobalVariable(Name);
if (!UsedList)
return 0;
auto *UsedListBaseArrayType =
cast<ArrayType>(UsedList->getType()->getElementType());
auto *UsedListBaseArrayType = cast<ArrayType>(UsedList->getValueType());
return UsedListBaseArrayType->getNumElements();
}

Expand Down

0 comments on commit 4e60132

Please sign in to comment.