diff options
author | Manuel Jacob <me@manueljacob.de> | 2016-01-16 20:30:46 +0000 |
---|---|---|
committer | Manuel Jacob <me@manueljacob.de> | 2016-01-16 20:30:46 +0000 |
commit | 5f6eaac6115a44f4ef3d819123f8694d3d5825ea (patch) | |
tree | 4f2535126e469abb4e8af765dcd1692ec466424a /llvm | |
parent | 7cdedc1e029ea5860f9077abb39013ae7cc6e9cf (diff) | |
download | bcm5719-llvm-5f6eaac6115a44f4ef3d819123f8694d3d5825ea.tar.gz bcm5719-llvm-5f6eaac6115a44f4ef3d819123f8694d3d5825ea.zip |
GlobalValue: use getValueType() instead of getType()->getPointerElementType().
Reviewers: mjacob
Subscribers: jholewinski, arsenm, dsanders, dblaikie
Patch by Eduard Burtescu.
Differential Revision: http://reviews.llvm.org/D16260
llvm-svn: 257999
Diffstat (limited to 'llvm')
38 files changed, 72 insertions, 81 deletions
diff --git a/llvm/lib/Analysis/GlobalsModRef.cpp b/llvm/lib/Analysis/GlobalsModRef.cpp index 425d9de876b..db3d5f781d8 100644 --- a/llvm/lib/Analysis/GlobalsModRef.cpp +++ b/llvm/lib/Analysis/GlobalsModRef.cpp @@ -310,7 +310,7 @@ void GlobalsAAResult::AnalyzeGlobals(Module &M) { ++NumNonAddrTakenGlobalVars; // If this global holds a pointer type, see if it is an indirect global. - if (GV.getType()->getElementType()->isPointerTy() && + if (GV.getValueType()->isPointerTy() && AnalyzeIndirectGlobalMemory(&GV)) ++NumIndirectGlobalVars; } diff --git a/llvm/lib/Analysis/Lint.cpp b/llvm/lib/Analysis/Lint.cpp index 2dfb09c95ad..b6d74c9c799 100644 --- a/llvm/lib/Analysis/Lint.cpp +++ b/llvm/lib/Analysis/Lint.cpp @@ -435,7 +435,7 @@ void Lint::visitMemoryReference(Instruction &I, // If the global may be defined differently in another compilation unit // then don't warn about funky memory accesses. if (GV->hasDefinitiveInitializer()) { - Type *GTy = GV->getType()->getElementType(); + Type *GTy = GV->getValueType(); if (GTy->isSized()) BaseSize = DL->getTypeAllocSize(GTy); BaseAlign = GV->getAlignment(); diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 9a17f5660b2..ae7d9216373 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -1560,7 +1560,7 @@ static unsigned getAlignment(const Value *V, const DataLayout &DL) { Align = GO->getAlignment(); if (Align == 0) { if (auto *GVar = dyn_cast<GlobalVariable>(GO)) { - Type *ObjectType = GVar->getType()->getElementType(); + Type *ObjectType = GVar->getValueType(); if (ObjectType->isSized()) { // If the object is defined in the current Module, we'll be giving // it the preferred alignment. Otherwise, we have to assume that it diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp index 725063a8177..6888211c9fe 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -83,8 +83,8 @@ static const ConstantExpr *getMergedGlobalExpr(const Value *V) { // First operand points to a global struct. Value *Ptr = CE->getOperand(0); - if (!isa<GlobalValue>(Ptr) || - !isa<StructType>(cast<PointerType>(Ptr->getType())->getElementType())) + GlobalValue *GV = dyn_cast<GlobalValue>(Ptr); + if (!GV || !isa<StructType>(GV->getValueType())) return nullptr; // Second operand is zero. diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp index c8007a524e7..5341493b9fa 100644 --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -1744,7 +1744,7 @@ bool CodeGenPrepare::optimizeCallInst(CallInst *CI, bool& ModifiedDT) { GlobalVariable *GV; if ((GV = dyn_cast<GlobalVariable>(Val)) && GV->canIncreaseAlignment() && GV->getAlignment() < PrefAlign && - DL->getTypeAllocSize(GV->getType()->getElementType()) >= + DL->getTypeAllocSize(GV->getValueType()) >= MinSize + Offset2) GV->setAlignment(PrefAlign); } diff --git a/llvm/lib/ExecutionEngine/ExecutionEngine.cpp b/llvm/lib/ExecutionEngine/ExecutionEngine.cpp index 7d09ec6d1da..45e06cb525b 100644 --- a/llvm/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/llvm/lib/ExecutionEngine/ExecutionEngine.cpp @@ -103,7 +103,7 @@ public: /// \brief Returns the address the GlobalVariable should be written into. The /// GVMemoryBlock object prefixes that. static char *Create(const GlobalVariable *GV, const DataLayout& TD) { - Type *ElTy = GV->getType()->getElementType(); + Type *ElTy = GV->getValueType(); size_t GVSize = (size_t)TD.getTypeAllocSize(ElTy); void *RawMemory = ::operator new( alignTo(sizeof(GVMemoryBlock), TD.getPreferredAlignment(GV)) + GVSize); @@ -1353,7 +1353,7 @@ void ExecutionEngine::EmitGlobalVariable(const GlobalVariable *GV) { if (!GV->isThreadLocal()) InitializeMemory(GV->getInitializer(), GA); - Type *ElTy = GV->getType()->getElementType(); + Type *ElTy = GV->getValueType(); size_t GVSize = (size_t)getDataLayout().getTypeAllocSize(ElTy); NumInitBytes += (unsigned)GVSize; ++NumGlobals; diff --git a/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp b/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp index 34564e42b10..34b2b13abe4 100644 --- a/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp +++ b/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp @@ -116,7 +116,7 @@ Function* cloneFunctionDecl(Module &Dst, const Function &F, ValueToValueMapTy *VMap) { assert(F.getParent() != &Dst && "Can't copy decl over existing function."); Function *NewF = - Function::Create(cast<FunctionType>(F.getType()->getElementType()), + Function::Create(cast<FunctionType>(F.getValueType()), F.getLinkage(), F.getName(), &Dst); NewF->copyAttributesFrom(&F); @@ -154,7 +154,7 @@ GlobalVariable* cloneGlobalVariableDecl(Module &Dst, const GlobalVariable &GV, ValueToValueMapTy *VMap) { assert(GV.getParent() != &Dst && "Can't copy decl over existing global var."); GlobalVariable *NewGV = new GlobalVariable( - Dst, GV.getType()->getElementType(), GV.isConstant(), + Dst, GV.getValueType(), GV.isConstant(), GV.getLinkage(), nullptr, GV.getName(), nullptr, GV.getThreadLocalMode(), GV.getType()->getAddressSpace()); NewGV->copyAttributesFrom(&GV); diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp index 0ce44e105cc..758a92b75e4 100644 --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -2416,7 +2416,7 @@ void AssemblyWriter::printGlobal(const GlobalVariable *GV) { Out << "addrspace(" << AddressSpace << ") "; if (GV->isExternallyInitialized()) Out << "externally_initialized "; Out << (GV->isConstant() ? "constant " : "global "); - TypePrinter.print(GV->getType()->getElementType(), Out); + TypePrinter.print(GV->getValueType(), Out); if (GV->hasInitializer()) { Out << ' '; diff --git a/llvm/lib/IR/DataLayout.cpp b/llvm/lib/IR/DataLayout.cpp index 5ec5f92b388..8230f429b05 100644 --- a/llvm/lib/IR/DataLayout.cpp +++ b/llvm/lib/IR/DataLayout.cpp @@ -764,7 +764,7 @@ uint64_t DataLayout::getIndexedOffset(Type *ptrTy, /// global. This includes an explicitly requested alignment (if the global /// has one). unsigned DataLayout::getPreferredAlignment(const GlobalVariable *GV) const { - Type *ElemType = GV->getType()->getElementType(); + Type *ElemType = GV->getValueType(); unsigned Alignment = getPrefTypeAlignment(ElemType); unsigned GVAlignment = GV->getAlignment(); if (GVAlignment >= Alignment) { diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp index a61b62bd968..2b8a4cf029a 100644 --- a/llvm/lib/IR/Globals.cpp +++ b/llvm/lib/IR/Globals.cpp @@ -242,7 +242,7 @@ void GlobalVariable::setInitializer(Constant *InitVal) { setGlobalVariableNumOperands(0); } } else { - assert(InitVal->getType() == getType()->getElementType() && + assert(InitVal->getType() == getValueType() && "Initializer type must match GlobalVariable type"); // Note, the num operands is used to compute the offset of the operand, so // the order here matters. We need to set num operands to 1 first so that diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index a4cc785c6fa..8db7fec0a16 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -521,7 +521,7 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) { void Verifier::visitGlobalVariable(const GlobalVariable &GV) { if (GV.hasInitializer()) { - Assert(GV.getInitializer()->getType() == GV.getType()->getElementType(), + Assert(GV.getInitializer()->getType() == GV.getValueType(), "Global variable initializer type does not match global " "variable type!", &GV); diff --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp index 8dd59f9e0e3..de368498ef2 100644 --- a/llvm/lib/Linker/IRMover.cpp +++ b/llvm/lib/Linker/IRMover.cpp @@ -719,7 +719,7 @@ GlobalVariable *IRLinker::copyGlobalVariableProto(const GlobalVariable *SGVar) { // identical version of the symbol over in the dest module... the // initializer will be filled in later by LinkGlobalInits. GlobalVariable *NewDGV = - new GlobalVariable(DstM, TypeMap.get(SGVar->getType()->getElementType()), + new GlobalVariable(DstM, TypeMap.get(SGVar->getValueType()), SGVar->isConstant(), GlobalValue::ExternalLinkage, /*init*/ nullptr, SGVar->getName(), /*insertbefore*/ nullptr, SGVar->getThreadLocalMode(), @@ -759,7 +759,7 @@ GlobalValue *IRLinker::copyGlobalValueProto(const GlobalValue *SGV, NewGV = copyGlobalAliasProto(cast<GlobalAlias>(SGV)); else NewGV = new GlobalVariable( - DstM, TypeMap.get(SGV->getType()->getElementType()), + DstM, TypeMap.get(SGV->getValueType()), /*isConstant*/ false, GlobalValue::ExternalLinkage, /*init*/ nullptr, SGV->getName(), /*insertbefore*/ nullptr, SGV->getThreadLocalMode(), @@ -802,8 +802,8 @@ void IRLinker::computeTypeMapping() { } // Unify the element type of appending arrays. - ArrayType *DAT = cast<ArrayType>(DGV->getType()->getElementType()); - ArrayType *SAT = cast<ArrayType>(SGV.getType()->getElementType()); + ArrayType *DAT = cast<ArrayType>(DGV->getValueType()); + ArrayType *SAT = cast<ArrayType>(SGV.getValueType()); TypeMap.addTypeMapping(DAT->getElementType(), SAT->getElementType()); } @@ -874,7 +874,7 @@ static void getArrayElements(const Constant *C, /// Return true on error. Constant *IRLinker::linkAppendingVarProto(GlobalVariable *DstGV, const GlobalVariable *SrcGV) { - Type *EltTy = cast<ArrayType>(TypeMap.get(SrcGV->getType()->getElementType())) + Type *EltTy = cast<ArrayType>(TypeMap.get(SrcGV->getValueType())) ->getElementType(); StringRef Name = SrcGV->getName(); @@ -895,7 +895,7 @@ Constant *IRLinker::linkAppendingVarProto(GlobalVariable *DstGV, } if (DstGV) { - ArrayType *DstTy = cast<ArrayType>(DstGV->getType()->getElementType()); + ArrayType *DstTy = cast<ArrayType>(DstGV->getValueType()); if (!SrcGV->hasAppendingLinkage() || !DstGV->hasAppendingLinkage()) { emitError( diff --git a/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp index 6ffa71e1477..a418f640c02 100644 --- a/llvm/lib/Linker/LinkModules.cpp +++ b/llvm/lib/Linker/LinkModules.cpp @@ -471,10 +471,8 @@ bool ModuleLinker::computeResultingSelectionKind(StringRef ComdatName, const DataLayout &DstDL = DstM.getDataLayout(); const DataLayout &SrcDL = SrcM.getDataLayout(); - uint64_t DstSize = - DstDL.getTypeAllocSize(DstGV->getType()->getPointerElementType()); - uint64_t SrcSize = - SrcDL.getTypeAllocSize(SrcGV->getType()->getPointerElementType()); + uint64_t DstSize = DstDL.getTypeAllocSize(DstGV->getValueType()); + uint64_t SrcSize = SrcDL.getTypeAllocSize(SrcGV->getValueType()); if (Result == Comdat::SelectionKind::ExactMatch) { if (SrcGV->getInitializer() != DstGV->getInitializer()) return emitError("Linking COMDATs named '" + ComdatName + @@ -598,8 +596,8 @@ bool ModuleLinker::shouldLinkFromSource(bool &LinkFromSrc, } const DataLayout &DL = Dest.getParent()->getDataLayout(); - uint64_t DestSize = DL.getTypeAllocSize(Dest.getType()->getElementType()); - uint64_t SrcSize = DL.getTypeAllocSize(Src.getType()->getElementType()); + uint64_t DestSize = DL.getTypeAllocSize(Dest.getValueType()); + uint64_t SrcSize = DL.getTypeAllocSize(Src.getValueType()); LinkFromSrc = SrcSize > DestSize; return false; } diff --git a/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp b/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp index 6c868880bca..1016e14a94a 100644 --- a/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp +++ b/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp @@ -687,7 +687,7 @@ bool AArch64DAGToDAGISel::SelectAddrModeIndexed(SDValue N, unsigned Size, const GlobalValue *GV = GAN->getGlobal(); unsigned Alignment = GV->getAlignment(); - Type *Ty = GV->getType()->getElementType(); + Type *Ty = GV->getValueType(); if (Alignment == 0 && Ty->isSized()) Alignment = DL.getABITypeAlignment(Ty); diff --git a/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp b/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp index 1a59a460ee7..3589a0daceb 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp @@ -808,7 +808,7 @@ SDValue AMDGPUTargetLowering::LowerGlobalAddress(AMDGPUMachineFunction* MFI, unsigned Offset; if (MFI->LocalMemoryObjects.count(GV) == 0) { - uint64_t Size = DL.getTypeAllocSize(GV->getType()->getElementType()); + uint64_t Size = DL.getTypeAllocSize(GV->getValueType()); Offset = MFI->LDSSize; MFI->LocalMemoryObjects[GV] = Offset; // XXX: Account for alignment? @@ -822,7 +822,7 @@ SDValue AMDGPUTargetLowering::LowerGlobalAddress(AMDGPUMachineFunction* MFI, } case AMDGPUAS::CONSTANT_ADDRESS: { MachineFrameInfo *FrameInfo = DAG.getMachineFunction().getFrameInfo(); - Type *EltType = GV->getType()->getElementType(); + Type *EltType = GV->getValueType(); unsigned Size = DL.getTypeAllocSize(EltType); unsigned Alignment = DL.getPrefTypeAlignment(EltType); diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp b/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp index 87d50d58705..393cb791931 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp @@ -78,8 +78,7 @@ bool AMDGPUPromoteAlloca::runOnFunction(Function &F) { for (Module::global_iterator I = Mod->global_begin(), E = Mod->global_end(); I != E; ++I) { GlobalVariable *GV = &*I; - PointerType *GVTy = GV->getType(); - if (GVTy->getAddressSpace() != AMDGPUAS::LOCAL_ADDRESS) + if (GV->getType()->getAddressSpace() != AMDGPUAS::LOCAL_ADDRESS) continue; for (Value::use_iterator U = GV->use_begin(), UE = GV->use_end(); U != UE; ++U) { @@ -88,7 +87,7 @@ bool AMDGPUPromoteAlloca::runOnFunction(Function &F) { continue; if (Use->getParent()->getParent() == &F) LocalMemAvailable -= - Mod->getDataLayout().getTypeAllocSize(GVTy->getElementType()); + Mod->getDataLayout().getTypeAllocSize(GV->getValueType()); } } } diff --git a/llvm/lib/Target/CppBackend/CPPBackend.cpp b/llvm/lib/Target/CppBackend/CPPBackend.cpp index 5ea6551ebc9..dd5590307ee 100644 --- a/llvm/lib/Target/CppBackend/CPPBackend.cpp +++ b/llvm/lib/Target/CppBackend/CPPBackend.cpp @@ -437,7 +437,7 @@ std::string CppWriter::getCppName(const Value* val) { if (const GlobalVariable* GV = dyn_cast<GlobalVariable>(val)) { name = std::string("gvar_") + - getTypePrefix(GV->getType()->getElementType()); + getTypePrefix(GV->getValueType()); } else if (isa<Function>(val)) { name = std::string("func_"); } else if (const Constant* C = dyn_cast<Constant>(val)) { @@ -997,13 +997,13 @@ void CppWriter::printVariableHead(const GlobalVariable *GV) { if (is_inline) { Out << " = mod->getGlobalVariable(mod->getContext(), "; printEscapedString(GV->getName()); - Out << ", " << getCppName(GV->getType()->getElementType()) << ",true)"; + Out << ", " << getCppName(GV->getValueType()) << ",true)"; nl(Out) << "if (!" << getCppName(GV) << ") {"; in(); nl(Out) << getCppName(GV); } Out << " = new GlobalVariable(/*Module=*/*mod, "; nl(Out) << "/*Type=*/"; - printCppName(GV->getType()->getElementType()); + printCppName(GV->getValueType()); Out << ","; nl(Out) << "/*isConstant=*/" << (GV->isConstant()?"true":"false"); Out << ","; diff --git a/llvm/lib/Target/Hexagon/HexagonTargetObjectFile.cpp b/llvm/lib/Target/Hexagon/HexagonTargetObjectFile.cpp index ccca62021f5..177c348d7c8 100644 --- a/llvm/lib/Target/Hexagon/HexagonTargetObjectFile.cpp +++ b/llvm/lib/Target/Hexagon/HexagonTargetObjectFile.cpp @@ -74,7 +74,7 @@ IsGlobalInSmallSection(const GlobalValue *GV, const TargetMachine &TM, return false; if (Kind.isBSS() || Kind.isData() || Kind.isCommon()) { - Type *Ty = GV->getType()->getElementType(); + Type *Ty = GV->getValueType(); return IsInSmallSection( GV->getParent()->getDataLayout().getTypeAllocSize(Ty)); } diff --git a/llvm/lib/Target/Mips/MipsTargetObjectFile.cpp b/llvm/lib/Target/Mips/MipsTargetObjectFile.cpp index 146f33bda24..79df9a05148 100644 --- a/llvm/lib/Target/Mips/MipsTargetObjectFile.cpp +++ b/llvm/lib/Target/Mips/MipsTargetObjectFile.cpp @@ -106,7 +106,7 @@ IsGlobalInSmallSectionImpl(const GlobalValue *GV, GV->hasCommonLinkage())) return false; - Type *Ty = GV->getType()->getElementType(); + Type *Ty = GV->getValueType(); return IsInSmallSection( GV->getParent()->getDataLayout().getTypeAllocSize(Ty)); } diff --git a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp index e8c36089a77..e04dfdd3c4d 100644 --- a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp @@ -1030,7 +1030,7 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar, // GlobalVariables are always constant pointers themselves. PointerType *PTy = GVar->getType(); - Type *ETy = PTy->getElementType(); + Type *ETy = GVar->getValueType(); if (GVar->hasExternalLinkage()) { if (GVar->hasInitializer()) @@ -1341,11 +1341,10 @@ void NVPTXAsmPrinter::emitPTXGlobalVariable(const GlobalVariable *GVar, const DataLayout &DL = getDataLayout(); // GlobalVariables are always constant pointers themselves. - PointerType *PTy = GVar->getType(); - Type *ETy = PTy->getElementType(); + Type *ETy = GVar->getValueType(); O << "."; - emitPTXAddressSpace(PTy->getAddressSpace(), O); + emitPTXAddressSpace(GVar->getType()->getAddressSpace(), O); if (GVar->getAlignment() == 0) O << " .align " << (int)DL.getPrefTypeAlignment(ETy); else @@ -1715,9 +1714,8 @@ void NVPTXAsmPrinter::printScalarConstant(const Constant *CPV, raw_ostream &O) { return; } if (const GlobalValue *GVar = dyn_cast<GlobalValue>(CPV)) { - PointerType *PTy = dyn_cast<PointerType>(GVar->getType()); bool IsNonGenericPointer = false; - if (PTy && PTy->getAddressSpace() != 0) { + if (GVar->getType()->getAddressSpace() != 0) { IsNonGenericPointer = true; } if (EmitGeneric && !isa<Function>(CPV) && !IsNonGenericPointer) { diff --git a/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp b/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp index 62ca5e9f9f6..5ace765f260 100644 --- a/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp @@ -86,7 +86,7 @@ bool GenericToNVVM::runOnModule(Module &M) { !llvm::isTexture(*GV) && !llvm::isSurface(*GV) && !llvm::isSampler(*GV) && !GV->getName().startswith("llvm.")) { GlobalVariable *NewGV = new GlobalVariable( - M, GV->getType()->getElementType(), GV->isConstant(), + M, GV->getValueType(), GV->isConstant(), GV->getLinkage(), GV->hasInitializer() ? GV->getInitializer() : nullptr, "", GV, GV->getThreadLocalMode(), llvm::ADDRESS_SPACE_GLOBAL); @@ -172,7 +172,7 @@ Value *GenericToNVVM::getOrInsertCVTA(Module *M, Function *F, // See if the address space conversion requires the operand to be bitcast // to i8 addrspace(n)* first. - EVT ExtendedGVType = EVT::getEVT(GVType->getElementType(), true); + EVT ExtendedGVType = EVT::getEVT(GV->getValueType(), true); if (!ExtendedGVType.isInteger() && !ExtendedGVType.isFloatingPoint()) { // A bitcast to i8 addrspace(n)* on the operand is needed. LLVMContext &Context = M->getContext(); @@ -191,12 +191,12 @@ Value *GenericToNVVM::getOrInsertCVTA(Module *M, Function *F, // Another bitcast from i8 * to <the element type of GVType> * is // required. DestTy = - PointerType::get(GVType->getElementType(), llvm::ADDRESS_SPACE_GENERIC); + PointerType::get(GV->getValueType(), llvm::ADDRESS_SPACE_GENERIC); CVTA = Builder.CreateBitCast(CVTA, DestTy, "cvta"); } else { // A simple CVTA is enough. SmallVector<Type *, 2> ParamTypes; - ParamTypes.push_back(PointerType::get(GVType->getElementType(), + ParamTypes.push_back(PointerType::get(GV->getValueType(), llvm::ADDRESS_SPACE_GENERIC)); ParamTypes.push_back(GVType); Function *CVTAFunction = Intrinsic::getDeclaration( diff --git a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp index af9ad077a7c..cdac55c3b1f 100644 --- a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp +++ b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp @@ -4091,7 +4091,7 @@ static bool isFunctionGlobalAddress(SDValue Callee) { Callee.getOpcode() == ISD::TargetGlobalTLSAddress) return false; - return G->getGlobal()->getType()->getElementType()->isFunctionTy(); + return G->getGlobal()->getValueType()->isFunctionTy(); } return false; diff --git a/llvm/lib/Target/XCore/XCoreAsmPrinter.cpp b/llvm/lib/Target/XCore/XCoreAsmPrinter.cpp index b00cdd5040e..be66e6cb812 100644 --- a/llvm/lib/Target/XCore/XCoreAsmPrinter.cpp +++ b/llvm/lib/Target/XCore/XCoreAsmPrinter.cpp @@ -93,8 +93,7 @@ void XCoreAsmPrinter::emitArrayBound(MCSymbol *Sym, const GlobalVariable *GV) { assert( ( GV->hasExternalLinkage() || GV->hasWeakLinkage() || GV->hasLinkOnceLinkage() || GV->hasCommonLinkage() ) && "Unexpected linkage"); - if (ArrayType *ATy = dyn_cast<ArrayType>( - cast<PointerType>(GV->getType())->getElementType())) { + if (ArrayType *ATy = dyn_cast<ArrayType>(GV->getValueType())) { MCSymbol *SymGlob = OutContext.getOrCreateSymbol( Twine(Sym->getName() + StringRef(".globound"))); diff --git a/llvm/lib/Target/XCore/XCoreISelLowering.cpp b/llvm/lib/Target/XCore/XCoreISelLowering.cpp index 38e6df06bd0..68c8e227f52 100644 --- a/llvm/lib/Target/XCore/XCoreISelLowering.cpp +++ b/llvm/lib/Target/XCore/XCoreISelLowering.cpp @@ -257,7 +257,7 @@ SDValue XCoreTargetLowering::getGlobalAddressWrapper(SDValue GA, // FIXME there is no actual debug info here SDLoc dl(GA); - if (GV->getType()->getElementType()->isFunctionTy()) + if (GV->getValueType()->isFunctionTy()) return DAG.getNode(XCoreISD::PCRelativeWrapper, dl, MVT::i32, GA); const auto *GVar = dyn_cast<GlobalVariable>(GV); @@ -272,7 +272,7 @@ static bool IsSmallObject(const GlobalValue *GV, const XCoreTargetLowering &XTL) if (XTL.getTargetMachine().getCodeModel() == CodeModel::Small) return true; - Type *ObjType = GV->getType()->getPointerElementType(); + Type *ObjType = GV->getValueType(); if (!ObjType->isSized()) return false; diff --git a/llvm/lib/Target/XCore/XCoreLowerThreadLocal.cpp b/llvm/lib/Target/XCore/XCoreLowerThreadLocal.cpp index f0b720151b1..9e98b47380f 100644 --- a/llvm/lib/Target/XCore/XCoreLowerThreadLocal.cpp +++ b/llvm/lib/Target/XCore/XCoreLowerThreadLocal.cpp @@ -189,7 +189,7 @@ bool XCoreLowerThreadLocal::lowerGlobal(GlobalVariable *GV) { return false; // Create replacement global. - ArrayType *NewType = createLoweredType(GV->getType()->getElementType()); + ArrayType *NewType = createLoweredType(GV->getValueType()); Constant *NewInitializer = nullptr; if (GV->hasInitializer()) NewInitializer = createLoweredInitializer(NewType, diff --git a/llvm/lib/Target/XCore/XCoreTargetObjectFile.cpp b/llvm/lib/Target/XCore/XCoreTargetObjectFile.cpp index aa16ecc148d..4a77d82b9ac 100644 --- a/llvm/lib/Target/XCore/XCoreTargetObjectFile.cpp +++ b/llvm/lib/Target/XCore/XCoreTargetObjectFile.cpp @@ -122,7 +122,7 @@ XCoreTargetObjectFile::SelectSectionForGlobal(const GlobalValue *GV, if (Kind.isMergeableConst8()) return MergeableConst8Section; if (Kind.isMergeableConst16()) return MergeableConst16Section; } - Type *ObjType = GV->getType()->getPointerElementType(); + Type *ObjType = GV->getValueType(); auto &DL = GV->getParent()->getDataLayout(); if (TM.getCodeModel() == CodeModel::Small || !ObjType->isSized() || DL.getTypeAllocSize(ObjType) < CodeModelLargeSize) { diff --git a/llvm/lib/Transforms/IPO/ExtractGV.cpp b/llvm/lib/Transforms/IPO/ExtractGV.cpp index 1a3b9253d72..23e517797ca 100644 --- a/llvm/lib/Transforms/IPO/ExtractGV.cpp +++ b/llvm/lib/Transforms/IPO/ExtractGV.cpp @@ -128,7 +128,7 @@ namespace { makeVisible(*CurI, Delete); if (Delete) { - Type *Ty = CurI->getType()->getElementType(); + Type *Ty = CurI->getValueType(); CurI->removeFromParent(); llvm::Value *Declaration; diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp index fd7736905fe..d308f5dd9eb 100644 --- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp +++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp @@ -120,7 +120,7 @@ static bool isLeakCheckerRoot(GlobalVariable *GV) { return false; SmallVector<Type *, 4> Types; - Types.push_back(cast<PointerType>(GV->getType())->getElementType()); + Types.push_back(GV->getValueType()); unsigned Limit = 20; do { @@ -867,9 +867,8 @@ OptimizeGlobalAddressOfMalloc(GlobalVariable *GV, CallInst *CI, Type *AllocTy, } Constant *RepValue = NewGV; - if (NewGV->getType() != GV->getType()->getElementType()) - RepValue = ConstantExpr::getBitCast(RepValue, - GV->getType()->getElementType()); + if (NewGV->getType() != GV->getValueType()) + RepValue = ConstantExpr::getBitCast(RepValue, GV->getValueType()); // If there is a comparison against null, we will insert a global bool to // keep track of whether the global was initialized yet or not. @@ -1397,8 +1396,8 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, CallInst *CI, // Insert a store of null into each global. for (unsigned i = 0, e = FieldGlobals.size(); i != e; ++i) { - PointerType *PT = cast<PointerType>(FieldGlobals[i]->getType()); - Constant *Null = Constant::getNullValue(PT->getElementType()); + Type *ValTy = cast<GlobalValue>(FieldGlobals[i])->getValueType(); + Constant *Null = Constant::getNullValue(ValTy); new StoreInst(Null, FieldGlobals[i], SI); } // Erase the original store. @@ -1583,7 +1582,7 @@ static bool optimizeOnceStoredGlobal(GlobalVariable *GV, Value *StoredOnceVal, /// boolean and select between the two values whenever it is used. This exposes /// the values to other scalar optimizations. static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal) { - Type *GVElType = GV->getType()->getElementType(); + Type *GVElType = GV->getValueType(); // If GVElType is already i1, it is already shrunk. If the type of the GV is // an FP value, pointer or vector, don't do this optimization because a select @@ -1879,7 +1878,7 @@ bool GlobalOpt::processInternalGlobal(GlobalVariable *GV, // If the global is in different address space, don't bring it to stack. if (!GS.HasMultipleAccessingFunctions && GS.AccessingFunction && - GV->getType()->getElementType()->isSingleValueType() && + GV->getValueType()->isSingleValueType() && GV->getType()->getAddressSpace() == 0 && !GV->isExternallyInitialized() && allNonInstructionUsersCanBeMadeInstructions(GV) && @@ -1888,7 +1887,7 @@ bool GlobalOpt::processInternalGlobal(GlobalVariable *GV, DEBUG(dbgs() << "LOCALIZING GLOBAL: " << *GV << "\n"); Instruction &FirstI = const_cast<Instruction&>(*GS.AccessingFunction ->getEntryBlock().begin()); - Type *ElemTy = GV->getType()->getElementType(); + Type *ElemTy = GV->getValueType(); // FIXME: Pass Global's alignment when globals have alignment AllocaInst *Alloca = new AllocaInst(ElemTy, nullptr, GV->getName(), &FirstI); @@ -2627,7 +2626,7 @@ bool Evaluator::EvaluateBlock(BasicBlock::iterator CurInst, Value *PtrArg = getVal(II->getArgOperand(1)); Value *Ptr = PtrArg->stripPointerCasts(); if (GlobalVariable *GV = dyn_cast<GlobalVariable>(Ptr)) { - Type *ElemTy = cast<PointerType>(GV->getType())->getElementType(); + Type *ElemTy = GV->getValueType(); if (!Size->isAllOnesValue() && Size->getValue().getLimitedValue() >= DL.getTypeStoreSize(ElemTy)) { diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index 090245d1b22..708e8f55250 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -2351,8 +2351,7 @@ InstCombiner::transformCallThroughTrampoline(CallSite CS, "transformCallThroughTrampoline called with incorrect CallSite."); Function *NestF =cast<Function>(Tramp->getArgOperand(1)->stripPointerCasts()); - PointerType *NestFPTy = cast<PointerType>(NestF->getType()); - FunctionType *NestFTy = cast<FunctionType>(NestFPTy->getElementType()); + FunctionType *NestFTy = cast<FunctionType>(NestF->getValueType()); const AttributeSet &NestAttrs = NestF->getAttributes(); if (!NestAttrs.isEmpty()) { diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp index 71cbf775f8a..51b3850a7a5 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp @@ -637,7 +637,7 @@ static bool isObjectSizeLessThanOrEq(Value *V, uint64_t MaxSize, if (!GV->hasDefinitiveInitializer() || !GV->isConstant()) return false; - uint64_t InitSize = DL.getTypeAllocSize(GV->getType()->getElementType()); + uint64_t InitSize = DL.getTypeAllocSize(GV->getValueType()); if (InitSize > MaxSize) return false; continue; diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp index a9df5e5898a..c00765f762e 100644 --- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -1184,7 +1184,7 @@ void AddressSanitizerModule::createInitializerPoisonCalls( } bool AddressSanitizerModule::ShouldInstrumentGlobal(GlobalVariable *G) { - Type *Ty = cast<PointerType>(G->getType())->getElementType(); + Type *Ty = G->getValueType(); DEBUG(dbgs() << "GLOBAL: " << *G << "\n"); if (GlobalsMD.get(G).IsBlacklisted) return false; @@ -1338,8 +1338,7 @@ bool AddressSanitizerModule::InstrumentGlobals(IRBuilder<> &IRB, Module &M) { M, MD.Name.empty() ? G->getName() : MD.Name, /*AllowMerging*/ true); - PointerType *PtrTy = cast<PointerType>(G->getType()); - Type *Ty = PtrTy->getElementType(); + Type *Ty = G->getValueType(); uint64_t SizeInBytes = DL.getTypeAllocSize(Ty); uint64_t MinRZ = MinRedzoneSizeForGlobal(); // MinRZ <= RZ <= kMaxGlobalRedzone diff --git a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp index d459fc50d13..42f4701275a 100644 --- a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp @@ -134,7 +134,7 @@ namespace { StringRef GetGlobalTypeString(const GlobalValue &G) { // Types of GlobalVariables are always pointer types. - Type *GType = G.getType()->getElementType(); + Type *GType = G.getValueType(); // For now we support blacklisting struct types only. if (StructType *SGType = dyn_cast<StructType>(GType)) { if (!SGType->isLiteral()) @@ -166,7 +166,7 @@ class DFSanABIList { if (isIn(*GA.getParent(), Category)) return true; - if (isa<FunctionType>(GA.getType()->getElementType())) + if (isa<FunctionType>(GA.getValueType())) return SCL->inSection("fun", GA.getName(), Category); return SCL->inSection("global", GA.getName(), Category) || diff --git a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp index fa939aee252..d6fdf26ab76 100644 --- a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp +++ b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp @@ -874,7 +874,7 @@ Function *GCOVProfiler::insertCounterWriteout( GlobalVariable *GV = CountersBySP[j].first; unsigned Arcs = - cast<ArrayType>(GV->getType()->getElementType())->getNumElements(); + cast<ArrayType>(GV->getValueType())->getNumElements(); Builder.CreateCall(EmitArcs, {Builder.getInt32(Arcs), Builder.CreateConstGEP2_64(GV, 0, 0)}); } @@ -966,7 +966,7 @@ insertFlush(ArrayRef<std::pair<GlobalVariable*, MDNode*> > CountersBySP) { I = CountersBySP.begin(), E = CountersBySP.end(); I != E; ++I) { GlobalVariable *GV = I->first; - Constant *Null = Constant::getNullValue(GV->getType()->getElementType()); + Constant *Null = Constant::getNullValue(GV->getValueType()); Builder.CreateStore(Null, GV); } diff --git a/llvm/lib/Transforms/Scalar/PlaceSafepoints.cpp b/llvm/lib/Transforms/Scalar/PlaceSafepoints.cpp index b56b3559912..3df40df861f 100644 --- a/llvm/lib/Transforms/Scalar/PlaceSafepoints.cpp +++ b/llvm/lib/Transforms/Scalar/PlaceSafepoints.cpp @@ -763,7 +763,7 @@ InsertSafepointPoll(Instruction *InsertBefore, auto *F = M->getFunction(GCSafepointPollName); assert(F && "gc.safepoint_poll function is missing"); - assert(F->getType()->getElementType() == + assert(F->getValueType() == FunctionType::get(Type::getVoidTy(M->getContext()), false) && "gc.safepoint_poll declared with wrong type"); assert(!F->empty() && "gc.safepoint_poll must be a non-empty function"); diff --git a/llvm/lib/Transforms/Scalar/SCCP.cpp b/llvm/lib/Transforms/Scalar/SCCP.cpp index 8569e080873..d966678e520 100644 --- a/llvm/lib/Transforms/Scalar/SCCP.cpp +++ b/llvm/lib/Transforms/Scalar/SCCP.cpp @@ -228,7 +228,7 @@ public: /// performing Interprocedural SCCP. void TrackValueOfGlobalVariable(GlobalVariable *GV) { // We only track the contents of scalar globals. - if (GV->getType()->getElementType()->isSingleValueType()) { + if (GV->getValueType()->isSingleValueType()) { LatticeVal &IV = TrackedGlobals[GV]; if (!isa<UndefValue>(GV->getInitializer())) IV.markConstant(GV->getInitializer()); diff --git a/llvm/lib/Transforms/Utils/CloneModule.cpp b/llvm/lib/Transforms/Utils/CloneModule.cpp index ab083353ece..53de62a28eb 100644 --- a/llvm/lib/Transforms/Utils/CloneModule.cpp +++ b/llvm/lib/Transforms/Utils/CloneModule.cpp @@ -53,7 +53,7 @@ std::unique_ptr<Module> llvm::CloneModule( for (Module::const_global_iterator I = M->global_begin(), E = M->global_end(); I != E; ++I) { GlobalVariable *GV = new GlobalVariable(*New, - I->getType()->getElementType(), + I->getValueType(), I->isConstant(), I->getLinkage(), (Constant*) nullptr, I->getName(), (GlobalVariable*) nullptr, @@ -66,7 +66,7 @@ std::unique_ptr<Module> llvm::CloneModule( // Loop over the functions in the module, making external functions as before for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I) { Function *NF = - Function::Create(cast<FunctionType>(I->getType()->getElementType()), + Function::Create(cast<FunctionType>(I->getValueType()), I->getLinkage(), I->getName(), New.get()); NF->copyAttributesFrom(&*I); VMap[&*I] = NF; diff --git a/llvm/lib/Transforms/Utils/ModuleUtils.cpp b/llvm/lib/Transforms/Utils/ModuleUtils.cpp index 9ec28a3f3d4..040ae963b34 100644 --- a/llvm/lib/Transforms/Utils/ModuleUtils.cpp +++ b/llvm/lib/Transforms/Utils/ModuleUtils.cpp @@ -33,7 +33,7 @@ static void appendToGlobalArray(const char *Array, if (GlobalVariable *GVCtor = M.getNamedGlobal(Array)) { // If there is a global_ctors array, use the existing struct type, which can // have 2 or 3 fields. - ArrayType *ATy = cast<ArrayType>(GVCtor->getType()->getElementType()); + ArrayType *ATy = cast<ArrayType>(GVCtor->getValueType()); EltTy = cast<StructType>(ATy->getElementType()); if (Constant *Init = GVCtor->getInitializer()) { unsigned n = Init->getNumOperands(); diff --git a/llvm/tools/llvm-nm/llvm-nm.cpp b/llvm/tools/llvm-nm/llvm-nm.cpp index b812233034e..50960653f75 100644 --- a/llvm/tools/llvm-nm/llvm-nm.cpp +++ b/llvm/tools/llvm-nm/llvm-nm.cpp @@ -792,7 +792,7 @@ static char getSymbolNMTypeChar(MachOObjectFile &Obj, basic_symbol_iterator I) { } static char getSymbolNMTypeChar(const GlobalValue &GV) { - if (GV.getType()->getElementType()->isFunctionTy()) + if (GV.getValueType()->isFunctionTy()) return 't'; // FIXME: should we print 'b'? At the IR level we cannot be sure if this // will be in bss or not, but we could approximate. |