From 88ddab380f5c4d2e79b8ab64abf367074569eea4 Mon Sep 17 00:00:00 2001 From: Akash Kothari <akashk4@tyler.cs.illinois.edu> Date: Sat, 18 Jan 2020 15:54:42 -0600 Subject: [PATCH] Fix to bug in DFG2LLVM_NVPTX pass --- hpvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hpvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp b/hpvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp index c85a8a4f2d..27910715fe 100644 --- a/hpvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp +++ b/hpvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp @@ -1137,6 +1137,7 @@ void CGT_NVPTX::codeGen(DFLeafNode* N) { // Function to replace call instructions to functions in the kernel std::map<Function *, Function *> OrgToClonedFuncMap; std::vector<Function *> FuncToBeRemoved; + std::vector<CallInst *> CallstoRemoved; auto CloneAndReplaceCall = [&] (CallInst *CI, Function *OrgFunc) { Function* NewFunc; // Check if the called function has already been cloned before. @@ -1157,7 +1158,7 @@ void CGT_NVPTX::codeGen(DFLeafNode* N) { CallInst* Inst = CallInst::Create(NewFunc, args, OrgFunc->getReturnType()->isVoidTy()? "" : CI->getName(), CI); CI->replaceAllUsesWith(Inst); - IItoRemove.push_back(CI); + CallstoRemoved.push_back(CI); return NewFunc; }; @@ -1880,6 +1881,11 @@ void CGT_NVPTX::codeGen(DFLeafNode* N) { KernelM->getFunctionList().push_back(F); } + for (auto *I : reverse(CallstoRemoved)) { + DEBUG(errs() << "Erasing: " << *I << "\n"); + I->eraseFromParent(); + } + addCLMetadata(F_nvptx); kernel->KernelFunction = F_nvptx; errs() << "Identified kernel - " << kernel->KernelFunction->getName() << "\n"; -- GitLab