From 9c26763e0bc495f393f3c76bdbe1a44946088a1f Mon Sep 17 00:00:00 2001 From: Mats Larsen Date: Mon, 20 Jan 2025 22:59:58 +0900 Subject: [PATCH 1/7] [IR] Replace of PointerType::get(Type) with opaque version (NFC) In accordance with https://github.com/llvm/llvm-project/issues/123569 --- llvm/include/llvm/CodeGen/BasicTTIImpl.h | 11 +++++------ llvm/include/llvm/IR/GlobalValue.h | 3 ++- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 2 +- llvm/lib/CodeGen/GlobalISel/CallLowering.cpp | 4 ++-- .../CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | 4 ++-- llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp | 4 ++-- llvm/lib/FuzzMutate/RandomIRBuilder.cpp | 2 +- llvm/lib/IR/Core.cpp | 3 ++- llvm/lib/IR/Instructions.cpp | 2 +- llvm/lib/IR/Type.cpp | 2 +- llvm/lib/Linker/IRMover.cpp | 2 +- llvm/lib/SandboxIR/Type.cpp | 2 +- .../Target/AArch64/AArch64Arm64ECCallLowering.cpp | 4 ++-- .../Target/AMDGPU/AMDGPUAsanInstrumentation.cpp | 2 +- .../Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp | 6 +++--- llvm/lib/Target/AMDGPU/R600ISelLowering.cpp | 4 ++-- llvm/lib/Target/AMDGPU/SIISelLowering.cpp | 3 ++- llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp | 2 +- llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp | 3 +-- llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp | 8 ++++---- llvm/lib/Target/NVPTX/NVPTXLowerAlloca.cpp | 6 ++++-- llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp | 4 ++-- llvm/lib/Target/X86/X86ISelLowering.cpp | 2 +- llvm/lib/Target/X86/X86InstCombineIntrinsic.cpp | 4 ++-- llvm/lib/Transforms/CFGuard/CFGuard.cpp | 2 +- llvm/lib/Transforms/IPO/AttributorAttributes.cpp | 2 +- .../Instrumentation/AddressSanitizer.cpp | 5 +++-- .../Instrumentation/DataFlowSanitizer.cpp | 14 ++++++-------- .../Transforms/Instrumentation/GCOVProfiling.cpp | 2 +- .../lib/Transforms/Instrumentation/MemProfiler.cpp | 2 +- .../Transforms/Instrumentation/MemorySanitizer.cpp | 4 ++-- .../Transforms/Instrumentation/TypeSanitizer.cpp | 2 +- llvm/lib/Transforms/Utils/CodeExtractor.cpp | 4 ++-- llvm/lib/Transforms/Utils/LowerGlobalDtors.cpp | 2 +- llvm/lib/Transforms/Utils/ModuleUtils.cpp | 8 ++++---- llvm/tools/llvm-exegesis/lib/Assembler.cpp | 4 ++-- llvm/tools/llvm-reduce/deltas/ReduceOpcodes.cpp | 5 +---- llvm/tools/llvm-stress/llvm-stress.cpp | 4 ++-- 38 files changed, 74 insertions(+), 75 deletions(-) diff --git a/llvm/include/llvm/CodeGen/BasicTTIImpl.h b/llvm/include/llvm/CodeGen/BasicTTIImpl.h index c9f142d64ae9e..46bb84b4fec4f 100644 --- a/llvm/include/llvm/CodeGen/BasicTTIImpl.h +++ b/llvm/include/llvm/CodeGen/BasicTTIImpl.h @@ -223,12 +223,11 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase { // // First, compute the cost of the individual memory operations. InstructionCost AddrExtractCost = - IsGatherScatter - ? getScalarizationOverhead( - FixedVectorType::get( - PointerType::get(VT->getElementType(), 0), VF), - /*Insert=*/false, /*Extract=*/true, CostKind) - : 0; + IsGatherScatter ? getScalarizationOverhead( + FixedVectorType::get( + PointerType::get(VT->getContext(), 0), VF), + /*Insert=*/false, /*Extract=*/true, CostKind) + : 0; // The cost of the scalar loads/stores. InstructionCost MemoryOpCost = diff --git a/llvm/include/llvm/IR/GlobalValue.h b/llvm/include/llvm/IR/GlobalValue.h index d9104d7af5f97..2176e2c2cfbfc 100644 --- a/llvm/include/llvm/IR/GlobalValue.h +++ b/llvm/include/llvm/IR/GlobalValue.h @@ -79,7 +79,8 @@ class GlobalValue : public Constant { protected: GlobalValue(Type *Ty, ValueTy VTy, AllocInfo AllocInfo, LinkageTypes Linkage, const Twine &Name, unsigned AddressSpace) - : Constant(PointerType::get(Ty, AddressSpace), VTy, AllocInfo), + : Constant(PointerType::get(Ty->getContext(), AddressSpace), VTy, + AllocInfo), ValueType(Ty), Visibility(DefaultVisibility), UnnamedAddrVal(unsigned(UnnamedAddr::None)), DllStorageClass(DefaultStorageClass), ThreadLocal(NotThreadLocal), diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 56f5ff4b20e5d..551dfd4af88bb 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -2598,7 +2598,7 @@ Error BitcodeReader::parseTypeTableBody() { !PointerType::isValidElementType(ResultTy)) return error("Invalid type"); ContainedIDs.push_back(Record[0]); - ResultTy = PointerType::get(ResultTy, AddressSpace); + ResultTy = PointerType::get(ResultTy->getContext(), AddressSpace); break; } case bitc::TYPE_CODE_OPAQUE_POINTER: { // OPAQUE_POINTER: [addrspace] diff --git a/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp b/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp index d17b20d977ce9..437dc4f42baec 100644 --- a/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp +++ b/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp @@ -1054,7 +1054,7 @@ void CallLowering::insertSRetIncomingArgument( DemoteReg = MRI.createGenericVirtualRegister( LLT::pointer(AS, DL.getPointerSizeInBits(AS))); - Type *PtrTy = PointerType::get(F.getReturnType(), AS); + Type *PtrTy = PointerType::get(F.getContext(), AS); SmallVector ValueVTs; ComputeValueVTs(*TLI, DL, PtrTy, ValueVTs); @@ -1081,7 +1081,7 @@ void CallLowering::insertSRetOutgoingArgument(MachineIRBuilder &MIRBuilder, DL.getTypeAllocSize(RetTy), DL.getPrefTypeAlign(RetTy), false); Register DemoteReg = MIRBuilder.buildFrameIndex(FramePtrTy, FI).getReg(0); - ArgInfo DemoteArg(DemoteReg, PointerType::get(RetTy, AS), + ArgInfo DemoteArg(DemoteReg, PointerType::get(RetTy->getContext(), AS), ArgInfo::NoArgIndex); setArgFlags(DemoteArg, AttributeList::ReturnIndex, DL, CB); DemoteArg.Flags[0].setSRet(); diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index 8a5d7c0b022d9..9f1aadcb279a9 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -11004,8 +11004,8 @@ TargetLowering::LowerCallTo(TargetLowering::CallLoweringInfo &CLI) const { MachineFunction &MF = CLI.DAG.getMachineFunction(); DemoteStackIdx = MF.getFrameInfo().CreateStackObject(TySize, Alignment, false); - Type *StackSlotPtrType = PointerType::get(CLI.RetTy, - DL.getAllocaAddrSpace()); + Type *StackSlotPtrType = + PointerType::get(CLI.RetTy->getContext(), DL.getAllocaAddrSpace()); DemoteStackSlot = CLI.DAG.getFrameIndex(DemoteStackIdx, getFrameIndexTy(DL)); ArgListEntry Entry; diff --git a/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp b/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp index ee9acf0ab33a4..7fb84e97fe4ed 100644 --- a/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp +++ b/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp @@ -273,8 +273,8 @@ createLocalIndirectStubsManagerBuilder(const Triple &T) { Constant* createIRTypedAddress(FunctionType &FT, ExecutorAddr Addr) { Constant *AddrIntVal = ConstantInt::get(Type::getInt64Ty(FT.getContext()), Addr.getValue()); - Constant *AddrPtrVal = - ConstantExpr::getIntToPtr(AddrIntVal, PointerType::get(&FT, 0)); + Constant *AddrPtrVal = ConstantExpr::getIntToPtr( + AddrIntVal, PointerType::get(FT.getContext(), 0)); return AddrPtrVal; } diff --git a/llvm/lib/FuzzMutate/RandomIRBuilder.cpp b/llvm/lib/FuzzMutate/RandomIRBuilder.cpp index a684307586a61..8aea3d6f7e059 100644 --- a/llvm/lib/FuzzMutate/RandomIRBuilder.cpp +++ b/llvm/lib/FuzzMutate/RandomIRBuilder.cpp @@ -370,7 +370,7 @@ Instruction *RandomIRBuilder::newSink(BasicBlock &BB, Type *Ty = V->getType(); Ptr = createStackMemory(BB.getParent(), Ty, PoisonValue::get(Ty)); } else { - Ptr = PoisonValue::get(PointerType::get(V->getType(), 0)); + Ptr = PoisonValue::get(PointerType::get(V->getContext(), 0)); } } diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp index dc5ca68bd9985..15ab9674f496d 100644 --- a/llvm/lib/IR/Core.cpp +++ b/llvm/lib/IR/Core.cpp @@ -873,7 +873,8 @@ LLVMTypeRef LLVMArrayType2(LLVMTypeRef ElementType, uint64_t ElementCount) { } LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace) { - return wrap(PointerType::get(unwrap(ElementType), AddressSpace)); + return wrap( + PointerType::get(unwrap(ElementType)->getContext(), AddressSpace)); } LLVMBool LLVMPointerTypeIsOpaque(LLVMTypeRef Ty) { diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp index 50560e9cf218e..b585d8cfbf2e2 100644 --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp @@ -1214,7 +1214,7 @@ AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize, AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize, Align Align, const Twine &Name, InsertPosition InsertBefore) - : UnaryInstruction(PointerType::get(Ty, AddrSpace), Alloca, + : UnaryInstruction(PointerType::get(Ty->getContext(), AddrSpace), Alloca, getAISize(Ty->getContext(), ArraySize), InsertBefore), AllocatedType(Ty) { setAlignment(Align); diff --git a/llvm/lib/IR/Type.cpp b/llvm/lib/IR/Type.cpp index ffa80faf6e249..277985b6b00a3 100644 --- a/llvm/lib/IR/Type.cpp +++ b/llvm/lib/IR/Type.cpp @@ -857,7 +857,7 @@ PointerType::PointerType(LLVMContext &C, unsigned AddrSpace) } PointerType *Type::getPointerTo(unsigned AddrSpace) const { - return PointerType::get(const_cast(this), AddrSpace); + return PointerType::get(getContext(), AddrSpace); } bool PointerType::isValidElementType(Type *ElemTy) { diff --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp index be3535ae94ff4..274e61e898d21 100644 --- a/llvm/lib/Linker/IRMover.cpp +++ b/llvm/lib/Linker/IRMover.cpp @@ -297,7 +297,7 @@ Type *TypeMapTy::get(Type *Ty, SmallPtrSet &Visited) { return *Entry = VectorType::get(ElementTypes[0], cast(Ty)->getElementCount()); case Type::PointerTyID: - return *Entry = PointerType::get(ElementTypes[0], + return *Entry = PointerType::get(Ty->getContext(), cast(Ty)->getAddressSpace()); case Type::FunctionTyID: return *Entry = FunctionType::get(ElementTypes[0], diff --git a/llvm/lib/SandboxIR/Type.cpp b/llvm/lib/SandboxIR/Type.cpp index 9ecff5f0165a9..4d7c71334eca3 100644 --- a/llvm/lib/SandboxIR/Type.cpp +++ b/llvm/lib/SandboxIR/Type.cpp @@ -47,7 +47,7 @@ void Type::dump() { PointerType *PointerType::get(Type *ElementType, unsigned AddressSpace) { return cast(ElementType->getContext().getType( - llvm::PointerType::get(ElementType->LLVMTy, AddressSpace))); + llvm::PointerType::get(ElementType->LLVMTy->getContext(), AddressSpace))); } PointerType *PointerType::get(Context &Ctx, unsigned AddressSpace) { diff --git a/llvm/lib/Target/AArch64/AArch64Arm64ECCallLowering.cpp b/llvm/lib/Target/AArch64/AArch64Arm64ECCallLowering.cpp index 415edb189e60c..abd2df301880c 100644 --- a/llvm/lib/Target/AArch64/AArch64Arm64ECCallLowering.cpp +++ b/llvm/lib/Target/AArch64/AArch64Arm64ECCallLowering.cpp @@ -793,9 +793,9 @@ bool AArch64Arm64ECCallLowering::runOnModule(Module &Mod) { VoidTy = Type::getVoidTy(M->getContext()); GuardFnType = FunctionType::get(PtrTy, {PtrTy, PtrTy}, false); - GuardFnPtrType = PointerType::get(GuardFnType, 0); + GuardFnPtrType = PointerType::get(M->getContext(), 0); DispatchFnType = FunctionType::get(PtrTy, {PtrTy, PtrTy, PtrTy}, false); - DispatchFnPtrType = PointerType::get(DispatchFnType, 0); + DispatchFnPtrType = PointerType::get(M->getContext(), 0); GuardFnCFGlobal = M->getOrInsertGlobal("__os_arm64x_check_icall_cfg", GuardFnPtrType); GuardFnGlobal = diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAsanInstrumentation.cpp b/llvm/lib/Target/AMDGPU/AMDGPUAsanInstrumentation.cpp index 067fc98174033..6554863e08c91 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUAsanInstrumentation.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUAsanInstrumentation.cpp @@ -161,7 +161,7 @@ static void instrumentAddressImpl(Module &M, IRBuilder<> &IRB, size_t AccessSizeIndex = TypeStoreSizeToSizeIndex(TypeStoreSize); Type *ShadowTy = IntegerType::get(M.getContext(), std::max(8U, TypeStoreSize >> AsanScale)); - Type *ShadowPtrTy = PointerType::get(ShadowTy, 0); + Type *ShadowPtrTy = PointerType::get(M.getContext(), 0); Value *AddrLong = IRB.CreatePtrToInt(Addr, IntptrTy); Value *ShadowPtr = memToShadow(M, IRB, IntptrTy, AddrLong, AsanScale, AsanOffset); diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp b/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp index a899805dc46b1..459f85ae6169a 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp @@ -277,7 +277,7 @@ bool AMDGPUPrintfRuntimeBindingImpl::lowerPrintfForGpu(Module &M) { Type *Tys_alloc[1] = {SizetTy}; Type *I8Ty = Type::getInt8Ty(Ctx); - Type *I8Ptr = PointerType::get(I8Ty, 1); + Type *I8Ptr = PointerType::get(Ctx, 1); FunctionType *FTy_alloc = FunctionType::get(I8Ptr, Tys_alloc, false); FunctionCallee PrintfAllocFn = M.getOrInsertFunction(StringRef("__printf_alloc"), FTy_alloc, Attr); @@ -300,7 +300,7 @@ bool AMDGPUPrintfRuntimeBindingImpl::lowerPrintfForGpu(Module &M) { // basicblock splits after buffer overflow check // ConstantPointerNull *zeroIntPtr = - ConstantPointerNull::get(PointerType::get(I8Ty, 1)); + ConstantPointerNull::get(PointerType::get(Ctx, 1)); auto *cmp = cast(Builder.CreateICmpNE(pcall, zeroIntPtr, "")); if (!CI->use_empty()) { Value *result = @@ -320,7 +320,7 @@ bool AMDGPUPrintfRuntimeBindingImpl::lowerPrintfForGpu(Module &M) { I8Ty, pcall, ConstantInt::get(Ctx, APInt(32, 0)), "PrintBuffID", BrnchPoint); - Type *idPointer = PointerType::get(I32Ty, AMDGPUAS::GLOBAL_ADDRESS); + Type *idPointer = PointerType::get(Ctx, AMDGPUAS::GLOBAL_ADDRESS); Value *id_gep_cast = new BitCastInst(BufferIdx, idPointer, "PrintBuffIdCast", BrnchPoint); diff --git a/llvm/lib/Target/AMDGPU/R600ISelLowering.cpp b/llvm/lib/Target/AMDGPU/R600ISelLowering.cpp index c2e952418f1be..157ca4b08020a 100644 --- a/llvm/lib/Target/AMDGPU/R600ISelLowering.cpp +++ b/llvm/lib/Target/AMDGPU/R600ISelLowering.cpp @@ -762,8 +762,8 @@ SDValue R600TargetLowering::LowerImplicitParameter(SelectionDAG &DAG, EVT VT, const SDLoc &DL, unsigned DwordOffset) const { unsigned ByteOffset = DwordOffset * 4; - PointerType * PtrType = PointerType::get(VT.getTypeForEVT(*DAG.getContext()), - AMDGPUAS::PARAM_I_ADDRESS); + PointerType *PtrType = + PointerType::get(*DAG.getContext(), AMDGPUAS::PARAM_I_ADDRESS); // We shouldn't be using an offset wider than 16-bits for implicit parameters. assert(isInt<16>(ByteOffset)); diff --git a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp index c4b1038b12d04..7170dd79d08e6 100644 --- a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp +++ b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp @@ -7819,7 +7819,8 @@ SDValue SITargetLowering::LowerGlobalAddress(AMDGPUMachineFunction *MFI, SIInstrInfo::MO_GOTPCREL32); Type *Ty = PtrVT.getTypeForEVT(*DAG.getContext()); - PointerType *PtrTy = PointerType::get(Ty, AMDGPUAS::CONSTANT_ADDRESS); + PointerType *PtrTy = + PointerType::get(*DAG.getContext(), AMDGPUAS::CONSTANT_ADDRESS); const DataLayout &DataLayout = DAG.getDataLayout(); Align Alignment = DataLayout.getABITypeAlign(PtrTy); MachinePointerInfo PtrInfo = diff --git a/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp b/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp index 639f3bf8fc62e..6d24b7c230c7f 100644 --- a/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp +++ b/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp @@ -84,7 +84,7 @@ static Value *simplifyNeonVld1(const IntrinsicInst &II, unsigned MemAlign, return nullptr; auto *BCastInst = Builder.CreateBitCast(II.getArgOperand(0), - PointerType::get(II.getType(), 0)); + PointerType::get(II.getContext(), 0)); return Builder.CreateAlignedLoad(II.getType(), BCastInst, Align(Alignment)); } diff --git a/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp b/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp index 76c6c8fb38d62..75fcf6829c504 100644 --- a/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp @@ -154,8 +154,7 @@ Value *GenericToNVVM::remapConstant(Module *M, Function *F, Constant *C, if (I != GVMap.end()) { GlobalVariable *GV = I->second; NewValue = Builder.CreateAddrSpaceCast( - GV, - PointerType::get(GV->getValueType(), llvm::ADDRESS_SPACE_GENERIC)); + GV, PointerType::get(GV->getContext(), llvm::ADDRESS_SPACE_GENERIC)); } } else if (isa(C)) { // If any element in the constant vector or aggregate C is or uses a global diff --git a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp index c40c09c204fd7..ed493d50712a2 100644 --- a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp @@ -2804,8 +2804,8 @@ SDValue NVPTXTargetLowering::LowerVAARG(SDValue Op, SelectionDAG &DAG) const { Tmp1 = DAG.getStore(VAListLoad.getValue(1), DL, Tmp1, Tmp2, MachinePointerInfo(V)); - const Value *SrcV = - Constant::getNullValue(PointerType::get(Ty, ADDRESS_SPACE_LOCAL)); + const Value *SrcV = Constant::getNullValue( + PointerType::get(*DAG.getContext(), ADDRESS_SPACE_LOCAL)); // Load the actual argument out of the pointer VAList return DAG.getLoad(VT, DL, Tmp1, VAList, MachinePointerInfo(SrcV)); @@ -3194,8 +3194,8 @@ SDValue NVPTXTargetLowering::LowerFormalArguments( SDValue VecAddr = DAG.getNode(ISD::ADD, dl, PtrVT, Arg, DAG.getConstant(Offsets[VecIdx], dl, PtrVT)); - Value *srcValue = Constant::getNullValue(PointerType::get( - EltVT.getTypeForEVT(F->getContext()), ADDRESS_SPACE_PARAM)); + Value *srcValue = Constant::getNullValue( + PointerType::get(F->getContext(), ADDRESS_SPACE_PARAM)); const MaybeAlign PartAlign = [&]() -> MaybeAlign { if (aggregateIsPacked) diff --git a/llvm/lib/Target/NVPTX/NVPTXLowerAlloca.cpp b/llvm/lib/Target/NVPTX/NVPTXLowerAlloca.cpp index be144c5ab7baf..a7544ce2df1a2 100644 --- a/llvm/lib/Target/NVPTX/NVPTXLowerAlloca.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXLowerAlloca.cpp @@ -90,13 +90,15 @@ bool NVPTXLowerAlloca::runOnFunction(Function &F) { // addrspacecast to ADDRESS_SPACE_GENERIC. if (AllocAddrSpace == ADDRESS_SPACE_GENERIC) { auto ASCastToLocalAS = new AddrSpaceCastInst( - allocaInst, PointerType::get(ETy, ADDRESS_SPACE_LOCAL), ""); + allocaInst, + PointerType::get(ETy->getContext(), ADDRESS_SPACE_LOCAL), ""); ASCastToLocalAS->insertAfter(allocaInst); AllocaInLocalAS = ASCastToLocalAS; } auto AllocaInGenericAS = new AddrSpaceCastInst( - AllocaInLocalAS, PointerType::get(ETy, ADDRESS_SPACE_GENERIC), ""); + AllocaInLocalAS, + PointerType::get(ETy->getContext(), ADDRESS_SPACE_GENERIC), ""); AllocaInGenericAS->insertAfter(AllocaInLocalAS); for (Use &AllocaUse : llvm::make_early_inc_range(allocaInst->uses())) { diff --git a/llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp b/llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp index ceb9d852d8ec8..c763b54c8dbfe 100644 --- a/llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp @@ -594,8 +594,8 @@ void NVPTXLowerArgs::handleByValParam(const NVPTXTargetMachine &TM, UsesToUpdate.push_back(&U); Value *ArgInParamAS = new AddrSpaceCastInst( - Arg, PointerType::get(StructType, ADDRESS_SPACE_PARAM), Arg->getName(), - FirstInst); + Arg, PointerType::get(StructType->getContext(), ADDRESS_SPACE_PARAM), + Arg->getName(), FirstInst); for (Use *U : UsesToUpdate) convertToParamAS(U, ArgInParamAS, HasCvtaParam, IsGridConstant); LLVM_DEBUG(dbgs() << "No need to copy or cast " << *Arg << "\n"); diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index 33ddcb57e9b08..d644dfa3ed3e3 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -29644,7 +29644,7 @@ SDValue X86TargetLowering::LowerWin64_i128OP(SDValue Op, SelectionDAG &DAG) cons InChain = DAG.getStore(InChain, dl, Op->getOperand(i), StackPtr, MPI, Align(16)); Type *ArgTy = ArgVT.getTypeForEVT(*DAG.getContext()); - Entry.Ty = PointerType::get(ArgTy,0); + Entry.Ty = PointerType::get(*DAG.getContext(), 0); Entry.IsSExt = false; Entry.IsZExt = false; Args.push_back(Entry); diff --git a/llvm/lib/Target/X86/X86InstCombineIntrinsic.cpp b/llvm/lib/Target/X86/X86InstCombineIntrinsic.cpp index 7c9738bf08216..4426113f599ac 100644 --- a/llvm/lib/Target/X86/X86InstCombineIntrinsic.cpp +++ b/llvm/lib/Target/X86/X86InstCombineIntrinsic.cpp @@ -70,7 +70,7 @@ static Instruction *simplifyX86MaskedLoad(IntrinsicInst &II, InstCombiner &IC) { // First, cast the x86 intrinsic scalar pointer to a vector pointer to match // the LLVM intrinsic definition for the pointer argument. unsigned AddrSpace = cast(Ptr->getType())->getAddressSpace(); - PointerType *VecPtrTy = PointerType::get(II.getType(), AddrSpace); + PointerType *VecPtrTy = PointerType::get(II.getContext(), AddrSpace); Value *PtrCast = IC.Builder.CreateBitCast(Ptr, VecPtrTy, "castvec"); // The pass-through vector for an x86 masked load is a zero vector. @@ -105,7 +105,7 @@ static bool simplifyX86MaskedStore(IntrinsicInst &II, InstCombiner &IC) { // intrinsic to the LLVM intrinsic to allow target-independent optimizations. if (Value *BoolMask = getBoolVecFromMask(Mask, IC.getDataLayout())) { unsigned AddrSpace = cast(Ptr->getType())->getAddressSpace(); - PointerType *VecPtrTy = PointerType::get(Vec->getType(), AddrSpace); + PointerType *VecPtrTy = PointerType::get(Vec->getContext(), AddrSpace); Value *PtrCast = IC.Builder.CreateBitCast(Ptr, VecPtrTy, "castvec"); IC.Builder.CreateMaskedStore(Vec, PtrCast, Align(1), BoolMask); diff --git a/llvm/lib/Transforms/CFGuard/CFGuard.cpp b/llvm/lib/Transforms/CFGuard/CFGuard.cpp index 0e1a0a6ed9479..41d68b62eb8d7 100644 --- a/llvm/lib/Transforms/CFGuard/CFGuard.cpp +++ b/llvm/lib/Transforms/CFGuard/CFGuard.cpp @@ -247,7 +247,7 @@ bool CFGuardImpl::doInitialization(Module &M) { GuardFnType = FunctionType::get(Type::getVoidTy(M.getContext()), {PointerType::getUnqual(M.getContext())}, false); - GuardFnPtrType = PointerType::get(GuardFnType, 0); + GuardFnPtrType = PointerType::get(M.getContext(), 0); GuardFnGlobal = M.getOrInsertGlobal(GuardFnName, GuardFnPtrType, [&] { auto *Var = new GlobalVariable(M, GuardFnPtrType, false, diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp index 46d6d66593b4e..e897632489bb5 100644 --- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp +++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp @@ -12344,7 +12344,7 @@ struct AAIndirectCallInfoCallSite : public AAIndirectCallInfo { ChangeStatus Changed = ChangeStatus::UNCHANGED; Value *FP = CB->getCalledOperand(); if (FP->getType()->getPointerAddressSpace()) - FP = new AddrSpaceCastInst(FP, PointerType::get(FP->getType(), 0), + FP = new AddrSpaceCastInst(FP, PointerType::get(FP->getContext(), 0), FP->getName() + ".as0", CB->getIterator()); bool CBIsVoid = CB->getType()->isVoidTy(); diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp index cb84588318496..cca6f78084b46 100644 --- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -1035,7 +1035,8 @@ struct FunctionStackPoisoner : public InstVisitor { RuntimeCallInserter &RTCI) : F(F), ASan(ASan), RTCI(RTCI), DIB(*F.getParent(), /*AllowUnresolved*/ false), C(ASan.C), - IntptrTy(ASan.IntptrTy), IntptrPtrTy(PointerType::get(IntptrTy, 0)), + IntptrTy(ASan.IntptrTy), + IntptrPtrTy(PointerType::get(IntptrTy->getContext(), 0)), Mapping(ASan.Mapping), PoisonStack(ClStack && !Triple(F.getParent()->getTargetTriple()).isAMDGPU()) {} @@ -1882,7 +1883,7 @@ void AddressSanitizer::instrumentAddress(Instruction *OrigIns, Type *ShadowTy = IntegerType::get(*C, std::max(8U, TypeStoreSize >> Mapping.Scale)); - Type *ShadowPtrTy = PointerType::get(ShadowTy, 0); + Type *ShadowPtrTy = PointerType::get(*C, 0); Value *ShadowPtr = memToShadow(AddrLong, IRB); const uint64_t ShadowAlign = std::max(Alignment.valueOrOne().value() >> Mapping.Scale, 1); diff --git a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp index e226727e64d35..6ba280d460122 100644 --- a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp @@ -1790,13 +1790,12 @@ Value *DFSanFunction::getArgTLS(Type *T, unsigned ArgOffset, IRBuilder<> &IRB) { Value *Base = IRB.CreatePointerCast(DFS.ArgTLS, DFS.IntptrTy); if (ArgOffset) Base = IRB.CreateAdd(Base, ConstantInt::get(DFS.IntptrTy, ArgOffset)); - return IRB.CreateIntToPtr(Base, PointerType::get(DFS.getShadowTy(T), 0), - "_dfsarg"); + return IRB.CreateIntToPtr(Base, PointerType::get(*DFS.Ctx, 0), "_dfsarg"); } Value *DFSanFunction::getRetvalTLS(Type *T, IRBuilder<> &IRB) { - return IRB.CreatePointerCast( - DFS.RetvalTLS, PointerType::get(DFS.getShadowTy(T), 0), "_dfsret"); + return IRB.CreatePointerCast(DFS.RetvalTLS, PointerType::get(*DFS.Ctx, 0), + "_dfsret"); } Value *DFSanFunction::getRetvalOriginTLS() { return DFS.RetvalOriginTLS; } @@ -1926,8 +1925,7 @@ DataFlowSanitizer::getShadowOriginAddress(Value *Addr, Align InstAlignment, IRB.CreateAdd(ShadowLong, ConstantInt::get(IntptrTy, ShadowBase)); } IntegerType *ShadowTy = IntegerType::get(*Ctx, ShadowWidthBits); - Value *ShadowPtr = - IRB.CreateIntToPtr(ShadowLong, PointerType::get(ShadowTy, 0)); + Value *ShadowPtr = IRB.CreateIntToPtr(ShadowLong, PointerType::get(*Ctx, 0)); Value *OriginPtr = nullptr; if (shouldTrackOrigins()) { Value *OriginLong = ShadowOffset; @@ -2491,8 +2489,8 @@ void DFSanFunction::paintOrigin(IRBuilder<> &IRB, Value *Origin, Align CurrentAlignment = Alignment; if (Alignment >= IntptrAlignment && IntptrSize > OriginSize) { Value *IntptrOrigin = originToIntptr(IRB, Origin); - Value *IntptrStoreOriginPtr = IRB.CreatePointerCast( - StoreOriginAddr, PointerType::get(DFS.IntptrTy, 0)); + Value *IntptrStoreOriginPtr = + IRB.CreatePointerCast(StoreOriginAddr, PointerType::get(*DFS.Ctx, 0)); for (unsigned I = 0; I < StoreOriginSize / IntptrSize; ++I) { Value *Ptr = I ? IRB.CreateConstGEP1_32(DFS.IntptrTy, IntptrStoreOriginPtr, I) diff --git a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp index 6e86ffdc80275..5e204d7362372 100644 --- a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp +++ b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp @@ -1012,7 +1012,7 @@ void GCOVProfiler::emitGlobalConstructor( IRBuilder<> Builder(BB); FTy = FunctionType::get(Type::getVoidTy(*Ctx), false); - auto *PFTy = PointerType::get(FTy, 0); + auto *PFTy = PointerType::get(*Ctx, 0); FTy = FunctionType::get(Builder.getVoidTy(), {PFTy, PFTy}, false); // Initialize the environment and register the local writeout, flush and diff --git a/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp b/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp index f1580b025efca..9a7eec76cc1d1 100644 --- a/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp +++ b/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp @@ -511,7 +511,7 @@ void MemProfiler::instrumentAddress(Instruction *OrigIns, } Type *ShadowTy = ClHistogram ? Type::getInt8Ty(*C) : Type::getInt64Ty(*C); - Type *ShadowPtrTy = PointerType::get(ShadowTy, 0); + Type *ShadowPtrTy = PointerType::get(*C, 0); Value *ShadowPtr = memToShadow(AddrLong, IRB); Value *ShadowAddr = IRB.CreateIntToPtr(ShadowPtr, ShadowPtrTy); diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp index 6daee7a3b6e81..587e5c1cc842e 100644 --- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -6188,7 +6188,7 @@ struct VarArgI386Helper : public VarArgHelperBase { Type *RegSaveAreaPtrTy = PointerType::getUnqual(*MS.C); Value *RegSaveAreaPtrPtr = IRB.CreateIntToPtr(IRB.CreatePtrToInt(VAListTag, MS.IntptrTy), - PointerType::get(RegSaveAreaPtrTy, 0)); + PointerType::get(*MS.C, 0)); Value *RegSaveAreaPtr = IRB.CreateLoad(RegSaveAreaPtrTy, RegSaveAreaPtrPtr); Value *RegSaveAreaShadowPtr, *RegSaveAreaOriginPtr; @@ -6273,7 +6273,7 @@ struct VarArgGenericHelper : public VarArgHelperBase { Type *RegSaveAreaPtrTy = PointerType::getUnqual(*MS.C); Value *RegSaveAreaPtrPtr = IRB.CreateIntToPtr(IRB.CreatePtrToInt(VAListTag, MS.IntptrTy), - PointerType::get(RegSaveAreaPtrTy, 0)); + PointerType::get(*MS.C, 0)); Value *RegSaveAreaPtr = IRB.CreateLoad(RegSaveAreaPtrTy, RegSaveAreaPtrPtr); Value *RegSaveAreaShadowPtr, *RegSaveAreaOriginPtr; diff --git a/llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp index 2ae8106218667..94101f9663a87 100644 --- a/llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp @@ -598,7 +598,7 @@ bool TypeSanitizer::instrumentWithShadowUpdate( Value *ShadowDataInt = convertToShadowDataInt(IRB, Ptr, IntptrTy, PtrShift, ShadowBase, AppMemMask); - Type *Int8PtrPtrTy = PointerType::get(IRB.getPtrTy(), 0); + Type *Int8PtrPtrTy = PointerType::get(IRB.getContext(), 0); Value *ShadowData = IRB.CreateIntToPtr(ShadowDataInt, Int8PtrPtrTy, "shadow.ptr"); diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp index af9813775f242..ecc91739a796e 100644 --- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp +++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp @@ -849,7 +849,7 @@ Function *CodeExtractor::constructFunctionDeclaration( StructValues.insert(output); } else ParamTy.push_back( - PointerType::get(output->getType(), DL.getAllocaAddrSpace())); + PointerType::get(output->getContext(), DL.getAllocaAddrSpace())); } assert( @@ -863,7 +863,7 @@ Function *CodeExtractor::constructFunctionDeclaration( if (!AggParamTy.empty()) { StructTy = StructType::get(M->getContext(), AggParamTy); ParamTy.push_back(PointerType::get( - StructTy, ArgsInZeroAddressSpace ? 0 : DL.getAllocaAddrSpace())); + M->getContext(), ArgsInZeroAddressSpace ? 0 : DL.getAllocaAddrSpace())); } Type *RetTy = getSwitchType(); diff --git a/llvm/lib/Transforms/Utils/LowerGlobalDtors.cpp b/llvm/lib/Transforms/Utils/LowerGlobalDtors.cpp index cd79600657032..ff72ba073ad0e 100644 --- a/llvm/lib/Transforms/Utils/LowerGlobalDtors.cpp +++ b/llvm/lib/Transforms/Utils/LowerGlobalDtors.cpp @@ -138,7 +138,7 @@ static bool runImpl(Module &M) { FunctionCallee AtExit = M.getOrInsertFunction( "__cxa_atexit", FunctionType::get(Type::getInt32Ty(C), - {PointerType::get(AtExitFuncTy, 0), VoidStar, VoidStar}, + {PointerType::get(C, 0), VoidStar, VoidStar}, /*isVarArg=*/false)); // If __cxa_atexit is defined (e.g. in the case of LTO) and arg0 is not diff --git a/llvm/lib/Transforms/Utils/ModuleUtils.cpp b/llvm/lib/Transforms/Utils/ModuleUtils.cpp index 7249571f34493..df31a3d5d7c5b 100644 --- a/llvm/lib/Transforms/Utils/ModuleUtils.cpp +++ b/llvm/lib/Transforms/Utils/ModuleUtils.cpp @@ -45,9 +45,9 @@ static void appendToGlobalArray(StringRef ArrayName, Module &M, Function *F, } GVCtor->eraseFromParent(); } else { - EltTy = StructType::get(IRB.getInt32Ty(), - PointerType::get(FnTy, F->getAddressSpace()), - IRB.getPtrTy()); + EltTy = StructType::get( + IRB.getInt32Ty(), + PointerType::get(M.getContext(), F->getAddressSpace()), IRB.getPtrTy()); } // Build a 3 field global_ctor entry. We don't take a comdat key. @@ -268,7 +268,7 @@ std::pair llvm::createSanitizerCtorAndInitFunctions( BasicBlock::Create(M.getContext(), "callfunc", Ctor, RetBB); auto *InitFn = cast(InitFunction.getCallee()); auto *InitFnPtr = - PointerType::get(InitFn->getType(), InitFn->getAddressSpace()); + PointerType::get(M.getContext(), InitFn->getAddressSpace()); IRB.SetInsertPoint(EntryBB); Value *InitNotNull = IRB.CreateICmpNE(InitFn, ConstantPointerNull::get(InitFnPtr)); diff --git a/llvm/tools/llvm-exegesis/lib/Assembler.cpp b/llvm/tools/llvm-exegesis/lib/Assembler.cpp index 7a53b626c177c..1e97cd24fe099 100644 --- a/llvm/tools/llvm-exegesis/lib/Assembler.cpp +++ b/llvm/tools/llvm-exegesis/lib/Assembler.cpp @@ -136,8 +136,8 @@ MachineFunction &createVoidVoidPtrMachineFunction(StringRef FunctionName, Module *Module, MachineModuleInfo *MMI) { Type *const ReturnType = Type::getInt32Ty(Module->getContext()); - Type *const MemParamType = PointerType::get( - Type::getInt8Ty(Module->getContext()), 0 /*default address space*/); + Type *const MemParamType = + PointerType::get(Module->getContext(), 0 /*default address space*/); FunctionType *FunctionType = FunctionType::get(ReturnType, {MemParamType}, false); Function *const F = Function::Create( diff --git a/llvm/tools/llvm-reduce/deltas/ReduceOpcodes.cpp b/llvm/tools/llvm-reduce/deltas/ReduceOpcodes.cpp index 0e2a6decfbc9d..9fb4fd61c74e7 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceOpcodes.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceOpcodes.cpp @@ -106,10 +106,7 @@ static bool callLooksLikeLoadStore(CallBase *CB, Value *&DataArg, if (!PtrArg) { unsigned AS = CB->getDataLayout().getAllocaAddrSpace(); - PointerType *PtrTy = - PointerType::get(DataArg ? DataArg->getType() - : IntegerType::getInt32Ty(CB->getContext()), - AS); + PointerType *PtrTy = PointerType::get(CB->getContext(), AS); PtrArg = ConstantPointerNull::get(PtrTy); } diff --git a/llvm/tools/llvm-stress/llvm-stress.cpp b/llvm/tools/llvm-stress/llvm-stress.cpp index e44b6023fff23..544d5bdb750a3 100644 --- a/llvm/tools/llvm-stress/llvm-stress.cpp +++ b/llvm/tools/llvm-stress/llvm-stress.cpp @@ -286,7 +286,7 @@ struct Modifier { /// Pick a random pointer type. Type *pickPointerType() { Type *Ty = pickType(); - return PointerType::get(Ty, 0); + return PointerType::get(Context, 0); } /// Pick a random vector type. @@ -547,7 +547,7 @@ struct CastModifier: public Modifier { // Pointers: if (VTy->isPointerTy()) { if (!DestTy->isPointerTy()) - DestTy = PointerType::get(DestTy, 0); + DestTy = PointerType::get(Context, 0); return PT->push_back( new BitCastInst(V, DestTy, "PC", BB->getTerminator()->getIterator())); } From c07e7ac0638d86ef0a051440a91ec3cd77dbfa98 Mon Sep 17 00:00:00 2001 From: Mats Larsen Date: Mon, 20 Jan 2025 23:33:35 +0900 Subject: [PATCH 2/7] [llvm-stress] Inline pickPointerType --- llvm/tools/llvm-stress/llvm-stress.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/llvm/tools/llvm-stress/llvm-stress.cpp b/llvm/tools/llvm-stress/llvm-stress.cpp index 544d5bdb750a3..e8f5bf4b8d996 100644 --- a/llvm/tools/llvm-stress/llvm-stress.cpp +++ b/llvm/tools/llvm-stress/llvm-stress.cpp @@ -264,7 +264,7 @@ struct Modifier { if (V->getType()->isPointerTy()) return V; } - return UndefValue::get(pickPointerType()); + return UndefValue::get(PointerType::get(Context, 0)); } /// Return a random value of any vector type. @@ -283,12 +283,6 @@ struct Modifier { return (getRandom() & 1) ? pickVectorType() : pickScalarType(); } - /// Pick a random pointer type. - Type *pickPointerType() { - Type *Ty = pickType(); - return PointerType::get(Context, 0); - } - /// Pick a random vector type. Type *pickVectorType(VectorType *VTy = nullptr) { From 60c0e42eb2743390afcd78210c377dfc7174a302 Mon Sep 17 00:00:00 2001 From: Mats Larsen Date: Mon, 20 Jan 2025 23:37:07 +0900 Subject: [PATCH 3/7] [IR] Remove unnecessary branch branch --- llvm/lib/Linker/IRMover.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp index 274e61e898d21..43fcfe75ba46b 100644 --- a/llvm/lib/Linker/IRMover.cpp +++ b/llvm/lib/Linker/IRMover.cpp @@ -296,9 +296,6 @@ Type *TypeMapTy::get(Type *Ty, SmallPtrSet &Visited) { case Type::FixedVectorTyID: return *Entry = VectorType::get(ElementTypes[0], cast(Ty)->getElementCount()); - case Type::PointerTyID: - return *Entry = PointerType::get(Ty->getContext(), - cast(Ty)->getAddressSpace()); case Type::FunctionTyID: return *Entry = FunctionType::get(ElementTypes[0], ArrayRef(ElementTypes).slice(1), From f2057f1090a9367e588ad200039bb6522b0925a2 Mon Sep 17 00:00:00 2001 From: Mats Larsen Date: Mon, 20 Jan 2025 23:45:30 +0900 Subject: [PATCH 4/7] [SandboxIR] Add notice of removal for non-opaque PointerType::get --- llvm/include/llvm/SandboxIR/Type.h | 2 ++ llvm/lib/SandboxIR/Type.cpp | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/SandboxIR/Type.h b/llvm/include/llvm/SandboxIR/Type.h index 3218b991b31a2..c7a8943632bae 100644 --- a/llvm/include/llvm/SandboxIR/Type.h +++ b/llvm/include/llvm/SandboxIR/Type.h @@ -291,6 +291,8 @@ class Type { class PointerType : public Type { public: // TODO: add missing functions + + // TODO: Remove non-opaque variant of sandboxir::PointerType::get static PointerType *get(Type *ElementType, unsigned AddressSpace); static PointerType *get(Context &Ctx, unsigned AddressSpace); diff --git a/llvm/lib/SandboxIR/Type.cpp b/llvm/lib/SandboxIR/Type.cpp index 4d7c71334eca3..4734d51be2822 100644 --- a/llvm/lib/SandboxIR/Type.cpp +++ b/llvm/lib/SandboxIR/Type.cpp @@ -46,8 +46,7 @@ void Type::dump() { #endif PointerType *PointerType::get(Type *ElementType, unsigned AddressSpace) { - return cast(ElementType->getContext().getType( - llvm::PointerType::get(ElementType->LLVMTy->getContext(), AddressSpace))); + return get(ElementType->getContext(), AddressSpace); } PointerType *PointerType::get(Context &Ctx, unsigned AddressSpace) { From 41fdabaa5d5f2fe0977ccb250f845ba2fcf6d97b Mon Sep 17 00:00:00 2001 From: Mats Larsen Date: Mon, 20 Jan 2025 23:46:50 +0900 Subject: [PATCH 5/7] [ARM] Remove unnecessary bitcast --- llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp b/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp index 6d24b7c230c7f..cedd3d6ad4da5 100644 --- a/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp +++ b/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp @@ -83,9 +83,7 @@ static Value *simplifyNeonVld1(const IntrinsicInst &II, unsigned MemAlign, if (!isPowerOf2_32(Alignment)) return nullptr; - auto *BCastInst = Builder.CreateBitCast(II.getArgOperand(0), - PointerType::get(II.getContext(), 0)); - return Builder.CreateAlignedLoad(II.getType(), BCastInst, Align(Alignment)); + return Builder.CreateAlignedLoad(II.getType(), II.getArgOperand(0), Align(Alignment)); } bool ARMTTIImpl::areInlineCompatible(const Function *Caller, From 83063c6e7c78a0ac3cf456c01051c81f40c675c4 Mon Sep 17 00:00:00 2001 From: Mats Larsen Date: Mon, 20 Jan 2025 23:48:04 +0900 Subject: [PATCH 6/7] [X86] Remove unnecessary bitcast --- llvm/lib/Target/X86/X86InstCombineIntrinsic.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/llvm/lib/Target/X86/X86InstCombineIntrinsic.cpp b/llvm/lib/Target/X86/X86InstCombineIntrinsic.cpp index 4426113f599ac..a44c583a1ca51 100644 --- a/llvm/lib/Target/X86/X86InstCombineIntrinsic.cpp +++ b/llvm/lib/Target/X86/X86InstCombineIntrinsic.cpp @@ -67,15 +67,9 @@ static Instruction *simplifyX86MaskedLoad(IntrinsicInst &II, InstCombiner &IC) { // The mask is constant or extended from a bool vector. Convert this x86 // intrinsic to the LLVM intrinsic to allow target-independent optimizations. if (Value *BoolMask = getBoolVecFromMask(Mask, IC.getDataLayout())) { - // First, cast the x86 intrinsic scalar pointer to a vector pointer to match - // the LLVM intrinsic definition for the pointer argument. - unsigned AddrSpace = cast(Ptr->getType())->getAddressSpace(); - PointerType *VecPtrTy = PointerType::get(II.getContext(), AddrSpace); - Value *PtrCast = IC.Builder.CreateBitCast(Ptr, VecPtrTy, "castvec"); - // The pass-through vector for an x86 masked load is a zero vector. CallInst *NewMaskedLoad = IC.Builder.CreateMaskedLoad( - II.getType(), PtrCast, Align(1), BoolMask, ZeroVec); + II.getType(), Ptr, Align(1), BoolMask, ZeroVec); return IC.replaceInstUsesWith(II, NewMaskedLoad); } From 607dbd7341aa45b6d343a613310fb1db8686b2b4 Mon Sep 17 00:00:00 2001 From: Mats Larsen Date: Tue, 21 Jan 2025 00:20:50 +0900 Subject: [PATCH 7/7] [fix] clang format My hook is broken I think --- llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp b/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp index cedd3d6ad4da5..6b3fa04798061 100644 --- a/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp +++ b/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp @@ -83,7 +83,8 @@ static Value *simplifyNeonVld1(const IntrinsicInst &II, unsigned MemAlign, if (!isPowerOf2_32(Alignment)) return nullptr; - return Builder.CreateAlignedLoad(II.getType(), II.getArgOperand(0), Align(Alignment)); + return Builder.CreateAlignedLoad(II.getType(), II.getArgOperand(0), + Align(Alignment)); } bool ARMTTIImpl::areInlineCompatible(const Function *Caller,