From: Eli Bendersky Date: Thu, 6 Nov 2014 17:05:49 +0000 (+0000) Subject: Clean up NVPTXLowerStructArgs.cpp. NFC X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=9b644c87495bbd17ba318481577a896e690ac19f;p=oota-llvm.git Clean up NVPTXLowerStructArgs.cpp. NFC * Remove unnecessary const_casts and C-style casts * Simplify attribute access code * Simplify ArrayRef creation * 80-col and clang-format git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221464 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/NVPTX/NVPTXLowerStructArgs.cpp b/lib/Target/NVPTX/NVPTXLowerStructArgs.cpp index b592023631b..3149399afb3 100644 --- a/lib/Target/NVPTX/NVPTXLowerStructArgs.cpp +++ b/lib/Target/NVPTX/NVPTXLowerStructArgs.cpp @@ -57,14 +57,12 @@ INITIALIZE_PASS(NVPTXLowerStructArgs, "nvptx-lower-struct-args", void NVPTXLowerStructArgs::handleParam(Argument *Arg) { Function *Func = Arg->getParent(); Instruction *FirstInst = &(Func->getEntryBlock().front()); - const PointerType *PType = dyn_cast(Arg->getType()); + PointerType *PType = dyn_cast(Arg->getType()); assert(PType && "Expecting pointer type in handleParam"); - const Type *StructType = PType->getElementType(); - - AllocaInst *AllocA = - new AllocaInst(const_cast(StructType), Arg->getName(), FirstInst); + Type *StructType = PType->getElementType(); + AllocaInst *AllocA = new AllocaInst(StructType, Arg->getName(), FirstInst); /* Set the alignment to alignment of the byval parameter. This is because, * later load/stores assume that alignment, and we are going to replace @@ -75,74 +73,59 @@ void NVPTXLowerStructArgs::handleParam(Argument *Arg) { Arg->replaceAllUsesWith(AllocA); // Get the cvt.gen.to.param intrinsic - const Type *CvtTypes[2] = { - Type::getInt8PtrTy(Func->getParent()->getContext(), ADDRESS_SPACE_PARAM), - Type::getInt8PtrTy(Func->getParent()->getContext(), ADDRESS_SPACE_GENERIC) - }; + Type *CvtTypes[] = { + Type::getInt8PtrTy(Func->getParent()->getContext(), ADDRESS_SPACE_PARAM), + Type::getInt8PtrTy(Func->getParent()->getContext(), + ADDRESS_SPACE_GENERIC)}; Function *CvtFunc = Intrinsic::getDeclaration( - Func->getParent(), Intrinsic::nvvm_ptr_gen_to_param, - ArrayRef(const_cast(CvtTypes), 2)); - std::vector BC1; - BC1.push_back( + Func->getParent(), Intrinsic::nvvm_ptr_gen_to_param, CvtTypes); + + Value *BitcastArgs[] = { new BitCastInst(Arg, Type::getInt8PtrTy(Func->getParent()->getContext(), ADDRESS_SPACE_GENERIC), - Arg->getName(), FirstInst)); - CallInst *CallCVT = CallInst::Create(CvtFunc, ArrayRef(BC1), - "cvt_to_param", FirstInst); - - BitCastInst *BitCast = - new BitCastInst(CallCVT, PointerType::get(const_cast(StructType), - ADDRESS_SPACE_PARAM), - Arg->getName(), FirstInst); + Arg->getName(), FirstInst)}; + CallInst *CallCVT = + CallInst::Create(CvtFunc, BitcastArgs, "cvt_to_param", FirstInst); + + BitCastInst *BitCast = new BitCastInst( + CallCVT, PointerType::get(StructType, ADDRESS_SPACE_PARAM), + Arg->getName(), FirstInst); LoadInst *LI = new LoadInst(BitCast, Arg->getName(), FirstInst); new StoreInst(LI, AllocA, FirstInst); } -/// ============================================================================= -/// If the function had a struct ptr arg, say foo(%struct.x *byval %d), then -/// add the following instructions to the first basic block : -/// -/// %temp = alloca %struct.x, align 8 -/// %tt1 = bitcast %struct.x * %d to i8 * -/// %tt2 = llvm.nvvm.cvt.gen.to.param %tt2 -/// %tempd = bitcast i8 addrspace(101) * to %struct.x addrspace(101) * -/// %tv = load %struct.x addrspace(101) * %tempd -/// store %struct.x %tv, %struct.x * %temp, align 8 -/// -/// The above code allocates some space in the stack and copies the incoming -/// struct from param space to local space. -/// Then replace all occurences of %d by %temp. -/// ============================================================================= +// ============================================================================= +// If the function had a struct ptr arg, say foo(%struct.x *byval %d), then +// add the following instructions to the first basic block : +// +// %temp = alloca %struct.x, align 8 +// %tt1 = bitcast %struct.x * %d to i8 * +// %tt2 = llvm.nvvm.cvt.gen.to.param %tt2 +// %tempd = bitcast i8 addrspace(101) * to %struct.x addrspace(101) * +// %tv = load %struct.x addrspace(101) * %tempd +// store %struct.x %tv, %struct.x * %temp, align 8 +// +// The above code allocates some space in the stack and copies the incoming +// struct from param space to local space. +// Then replace all occurences of %d by %temp. +// ============================================================================= void NVPTXLowerStructArgs::handleStructPtrArgs(Function &F) { - const AttributeSet &PAL = F.getAttributes(); - - unsigned Idx = 1; - for (Argument &Arg : F.args()) { - const Type *Ty = Arg.getType(); - - const PointerType *PTy = dyn_cast(Ty); - - if (PTy) { - if (PAL.hasAttribute(Idx, Attribute::ByVal)) { - // cout << "Has struct ptr args" << std::endl; - handleParam(&Arg); - } + if (Arg.getType()->isPointerTy() && Arg.hasByValAttr()) { + handleParam(&Arg); } - Idx++; } } -/// ============================================================================= -/// Main function for this pass. -/// ============================================================================= +// ============================================================================= +// Main function for this pass. +// ============================================================================= bool NVPTXLowerStructArgs::runOnFunction(Function &F) { // Skip non-kernels. See the comments at the top of this file. if (!isKernelFunction(F)) return false; handleStructPtrArgs(F); - return true; }