From 268019cc4b1693ef1d00d7a72faaa00a807fa22e Mon Sep 17 00:00:00 2001 From: akashk4 <akashk4@illinois.edu> Date: Wed, 8 Jan 2020 06:13:01 -0600 Subject: [PATCH] Properly Handling CloneFunction with Additional Args -- Partially tested to work --- hpvm/include/SupportVISC/DFG2LLVM.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/hpvm/include/SupportVISC/DFG2LLVM.h b/hpvm/include/SupportVISC/DFG2LLVM.h index 1e45e87ccb..c3db1a77c1 100644 --- a/hpvm/include/SupportVISC/DFG2LLVM.h +++ b/hpvm/include/SupportVISC/DFG2LLVM.h @@ -324,11 +324,16 @@ Value* CodeGenTraversal::getStringPointer(const Twine& S, Instruction* IB, const // F->mutateType(PTy); //} +void renameNewArgument(Function *newF, const Twine& argName){ + // Get Last argument in Function Arg List and rename it to given name + Argument *lastArg = &*(newF->arg_end() - 1); + lastArg->setName(argName); +} + // Creates a function with an additional argument of the specified type and // name. The previous function is not deleted. Function *CodeGenTraversal::addArgument(Function* F, Type* Ty, const Twine& name) { - // Add the argument to argument list - new Argument(Ty, name, F); + Argument *new_arg = new Argument(Ty, name); // Create the argument type list with added argument types std::vector<Type*> ArgTypes; @@ -340,8 +345,11 @@ Function *CodeGenTraversal::addArgument(Function* F, Type* Ty, const Twine& name // function type. We need to change the type of this function to reflect the // added arguments. So, we create a clone of this function with the correct // type. - FunctionType* FTy = FunctionType::get(F->getReturnType(), ArgTypes, F->isVarArg()); - Function *newF = viscUtils::cloneFunction(F, FTy, false); + FunctionType *FTy = FunctionType::get(F->getReturnType(), ArgTypes, F->isVarArg()); + Function *newF = Function::Create(FTy, F->getLinkage(), + F->getName() + "_cloned", F->getParent()); + renameNewArgument(newF, name); + newF = viscUtils::cloneFunction(F, newF, false); // Check if the function is used by a metadata node if(F->isUsedByMetadata()) { -- GitLab