Skip to content
Snippets Groups Projects
Commit 25bedf2c authored by Prakalp Srivastava's avatar Prakalp Srivastava
Browse files

Changed GenVISC pass to automatically infer return type of internal nodes from...

Changed GenVISC pass to automatically infer return type of internal nodes from bind output intrinsics
parent d81e5882
No related branches found
No related tags found
No related merge requests found
......@@ -1077,6 +1077,55 @@ bool GenVISC::runOnModule(Module &M) {
"", CI);
DEBUG(errs() << "Found visc bindOut call: " << *CI << "\n");
DEBUG(errs() << "\tSubstitute with: " << *BindOutInst << "\n");
DEBUG(errs() << "Fixing the return type of the function\n");
// FIXME: What if the child node function has not been visited already.
// i.e., it's return type has not been fixed.
Function* F = I->getParent()->getParent();
errs() << F->getName() << "\n";
IntrinsicInst* NodeIntrinsic = cast<IntrinsicInst>(CI->getArgOperand(0));
errs() << "Node intrinsic: " << *NodeIntrinsic << "\n";
Function* ChildF = cast<Function>(NodeIntrinsic->getArgOperand(0)->stripPointerCasts());
errs() << ChildF->getName() << "\n";
int srcpos = cast<ConstantInt>(CI->getArgOperand(1))->getSExtValue();
int destpos = cast<ConstantInt>(CI->getArgOperand(2))->getSExtValue();
StructType* ChildReturnTy = cast<StructType>(ChildF->getReturnType());
Type* ReturnType = F->getReturnType();
errs() << *ReturnType << "\n";
assert(ReturnType->isVoidTy() || isa<StructType>(ReturnType)
&& "Return type should either be a struct or void type!");
// Get the return struct type. If void, create empty struct
StructType* ReturnStructTy;
if(ReturnType->isVoidTy())
ReturnStructTy = StructType::create(Ctx, None, Twine("struct.out."+F->getName()).str(), true);
else
ReturnStructTy = cast<StructType>(ReturnType);
std::vector<Type*> TyList;
for (unsigned i=0; i<ReturnStructTy->getNumElements(); i++)
TyList.push_back(ReturnStructTy->getElementType(i));
TyList.insert(TyList.begin()+destpos, ChildReturnTy->getElementType(srcpos));
StructType* NewReturnTy = StructType::create(Ctx, TyList, ReturnStructTy->getName(), true);
// Create the argument type list with added argument types
std::vector<Type*> ArgTypes;
for(Function::const_arg_iterator ai = F->arg_begin(), ae = F->arg_end();
ai != ae; ++ai) {
ArgTypes.push_back(ai->getType());
}
FunctionType* FTy = FunctionType::get(NewReturnTy, ArgTypes, F->isVarArg());
PointerType* PTy = FTy->getPointerTo();
F->mutateType(PTy);
// This is certainly an internal node, and hence just one BB with one
// return terminator instruction. Change return statement
ReturnInst* RI = cast<ReturnInst>(F->getEntryBlock().getTerminator());
ReturnInst* newRI = ReturnInst::Create(Ctx, UndefValue::get(NewReturnTy));
ReplaceInstWithInst(RI, newRI);
CI->replaceAllUsesWith(BindOutInst);
toBeErased.push_back(CI);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment