From 97a23ab28ad91d589e6c0bb5dee6ae78c154da8a Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Tue, 15 Sep 2020 14:48:40 +0100 Subject: [PATCH] AMDGPUPrintfRuntimeBinding.cpp - drop unnecessary casts/dyn_casts. NFCI. GetElementPtrInst::Create returns a GetElementPtrInst* so we don't need to cast. Similarly IntegerType inherits from the Type base class. Also, I've used auto* in a few places to cleanup the code. Helps fix some clang-tidy warnings which saw the dyn_casts and warned that these can return null. --- .../Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp | 40 ++++++++++------------ 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp b/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp index 524a34b..31c6c0b 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp @@ -379,9 +379,8 @@ bool AMDGPUPrintfRuntimeBinding::lowerPrintfForGpu( ConstantInt::get(Ctx, APInt(32, StringRef("0"), 10)); ZeroIdxList.push_back(zeroInt); - GetElementPtrInst *BufferIdx = - dyn_cast(GetElementPtrInst::Create( - nullptr, pcall, ZeroIdxList, "PrintBuffID", Brnch)); + GetElementPtrInst *BufferIdx = GetElementPtrInst::Create( + nullptr, pcall, ZeroIdxList, "PrintBuffID", Brnch); Type *idPointer = PointerType::get(I32Ty, AMDGPUAS::GLOBAL_ADDRESS); Value *id_gep_cast = @@ -395,8 +394,8 @@ bool AMDGPUPrintfRuntimeBinding::lowerPrintfForGpu( FourthIdxList.push_back(fourInt); // 1st 4 bytes hold the printf_id // the following GEP is the buffer pointer - BufferIdx = cast(GetElementPtrInst::Create( - nullptr, pcall, FourthIdxList, "PrintBuffGep", Brnch)); + BufferIdx = GetElementPtrInst::Create(nullptr, pcall, FourthIdxList, + "PrintBuffGep", Brnch); Type *Int32Ty = Type::getInt32Ty(Ctx); Type *Int64Ty = Type::getInt64Ty(Ctx); @@ -409,17 +408,15 @@ bool AMDGPUPrintfRuntimeBinding::lowerPrintfForGpu( if (ArgType->isFPOrFPVectorTy() && !isa(ArgType)) { Type *IType = (ArgType->isFloatTy()) ? Int32Ty : Int64Ty; if (OpConvSpecifiers[ArgCount - 1] == 'f') { - ConstantFP *fpCons = dyn_cast(Arg); - if (fpCons) { - APFloat Val(fpCons->getValueAPF()); + if (auto *FpCons = dyn_cast(Arg)) { + APFloat Val(FpCons->getValueAPF()); bool Lost = false; Val.convert(APFloat::IEEEsingle(), APFloat::rmNearestTiesToEven, &Lost); Arg = ConstantFP::get(Ctx, Val); IType = Int32Ty; - } else { - FPExtInst *FpExt = dyn_cast(Arg); - if (FpExt && FpExt->getType()->isDoubleTy() && + } else if (auto *FpExt = dyn_cast(Arg)) { + if (FpExt->getType()->isDoubleTy() && FpExt->getOperand(0)->getType()->isFloatTy()) { Arg = FpExt->getOperand(0); IType = Int32Ty; @@ -431,9 +428,8 @@ bool AMDGPUPrintfRuntimeBinding::lowerPrintfForGpu( } else if (ArgType->getTypeID() == Type::PointerTyID) { if (shouldPrintAsStr(OpConvSpecifiers[ArgCount - 1], ArgType)) { const char *S = NonLiteralStr; - if (ConstantExpr *ConstExpr = dyn_cast(Arg)) { - GlobalVariable *GV = - dyn_cast(ConstExpr->getOperand(0)); + if (auto *ConstExpr = dyn_cast(Arg)) { + auto *GV = dyn_cast(ConstExpr->getOperand(0)); if (GV && GV->hasInitializer()) { Constant *Init = GV->getInitializer(); ConstantDataArray *CA = dyn_cast(Init); @@ -491,27 +487,27 @@ bool AMDGPUPrintfRuntimeBinding::lowerPrintfForGpu( switch (EleSize) { default: EleCount = TotalSize / 64; - IType = dyn_cast(Type::getInt64Ty(ArgType->getContext())); + IType = Type::getInt64Ty(ArgType->getContext()); break; case 8: if (EleCount >= 8) { EleCount = TotalSize / 64; - IType = dyn_cast(Type::getInt64Ty(ArgType->getContext())); + IType = Type::getInt64Ty(ArgType->getContext()); } else if (EleCount >= 3) { EleCount = 1; - IType = dyn_cast(Type::getInt32Ty(ArgType->getContext())); + IType = Type::getInt32Ty(ArgType->getContext()); } else { EleCount = 1; - IType = dyn_cast(Type::getInt16Ty(ArgType->getContext())); + IType = Type::getInt16Ty(ArgType->getContext()); } break; case 16: if (EleCount >= 3) { EleCount = TotalSize / 64; - IType = dyn_cast(Type::getInt64Ty(ArgType->getContext())); + IType = Type::getInt64Ty(ArgType->getContext()); } else { EleCount = 1; - IType = dyn_cast(Type::getInt32Ty(ArgType->getContext())); + IType = Type::getInt32Ty(ArgType->getContext()); } break; } @@ -539,8 +535,8 @@ bool AMDGPUPrintfRuntimeBinding::lowerPrintfForGpu( (void)StBuff; if (I + 1 == E && ArgCount + 1 == CI->getNumArgOperands()) break; - BufferIdx = dyn_cast(GetElementPtrInst::Create( - nullptr, BufferIdx, BuffOffset, "PrintBuffNextPtr", Brnch)); + BufferIdx = GetElementPtrInst::Create(nullptr, BufferIdx, BuffOffset, + "PrintBuffNextPtr", Brnch); LLVM_DEBUG(dbgs() << "inserting gep to the printf buffer:\n" << *BufferIdx << '\n'); } -- 2.7.4