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

Fixed bug: For internal df nodes with void return types, the genvisc pass was

not producing empty struct as return type. Fixed it
parent 13c6539b
No related branches found
No related tags found
No related merge requests found
......@@ -33,6 +33,7 @@ namespace genvisc {
// Helper Functions
static inline ConstantInt* getTimerID(Module&, enum visc_TimerID);
static void transformReturnTypeToStruct(Function* F);
// Check if the dummy function call is a __visc__node call
#define IS_VISC_CALL(callName) \
......@@ -870,6 +871,7 @@ bool GenVISC::runOnModule(Module &M) {
DEBUG(errs() << *LaunchF << "\n");
// Get i8* cast to function pointer
Function* graphFunc = cast<Function>(CI->getArgOperand(1));
transformReturnTypeToStruct(graphFunc);
Constant* F = ConstantExpr::getPointerCast(graphFunc, Type::getInt8PtrTy(Ctx));
ConstantInt* Op = cast<ConstantInt>(CI->getArgOperand(0));
......@@ -916,6 +918,7 @@ bool GenVISC::runOnModule(Module &M) {
// Get i8* cast to function pointer
Function* graphFunc = cast<Function>(CI->getArgOperand(0));
transformReturnTypeToStruct(graphFunc);
Constant* F = ConstantExpr::getPointerCast(graphFunc, Type::getInt8PtrTy(Ctx));
CallInst* CreateNodeInst = CallInst::Create(CreateNodeF,
......@@ -933,6 +936,7 @@ bool GenVISC::runOnModule(Module &M) {
// Get i8* cast to function pointer
Function* graphFunc = cast<Function>(CI->getArgOperand(0));
transformReturnTypeToStruct(graphFunc);
Constant* F = ConstantExpr::getPointerCast(graphFunc, Type::getInt8PtrTy(Ctx));
Value* CreateNode1DArgs[] = {F, CI->getArgOperand(1)};
......@@ -950,6 +954,7 @@ bool GenVISC::runOnModule(Module &M) {
// Get i8* cast to function pointer
Function* graphFunc = cast<Function>(CI->getArgOperand(0));
transformReturnTypeToStruct(graphFunc);
Constant* F = ConstantExpr::getPointerCast(graphFunc, Type::getInt8PtrTy(Ctx));
Value* CreateNode2DArgs[] = {F, CI->getArgOperand(1), CI->getArgOperand(2)};
......@@ -967,6 +972,7 @@ bool GenVISC::runOnModule(Module &M) {
// Get i8* cast to function pointer
Function* graphFunc = cast<Function>(CI->getArgOperand(0));
transformReturnTypeToStruct(graphFunc);
Constant* F = ConstantExpr::getPointerCast(graphFunc, Type::getInt8PtrTy(Ctx));
Value* CreateNode3DArgs[] = {F, CI->getArgOperand(1),
......@@ -1476,6 +1482,33 @@ static inline ConstantInt* getTimerID(Module& M, enum visc_TimerID timer) {
return ConstantInt::get(Type::getInt32Ty(M.getContext()), timer);
}
static void transformReturnTypeToStruct(Function* F) {
// Currently only works for void return types
errs() << "Transforming return type of function to Struct: " << F->getName() << "\n";
if(!F->getReturnType()->isVoidTy()) {
errs() << "Warning: Unhandled case - Only void return type handled\n";
return;
}
// 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());
}
StructType* RetTy = StructType::create(F->getContext(), None, "emptyStruct", true);
FunctionType* FTy = FunctionType::get(RetTy, ArgTypes, F->isVarArg());
PointerType* PTy = FTy->getPointerTo();
F->mutateType(PTy);
// Replace ret void instruction with ret %RetTy undef
for(auto& BB: F->getBasicBlockList()) {
if(ReturnInst* RI = dyn_cast<ReturnInst>(BB.getTerminator())) {
DEBUG(errs() << "Found return inst: "<< *RI << "\n");
ReturnInst* newRI = ReturnInst::Create(F->getContext(), UndefValue::get(RetTy));
ReplaceInstWithInst(RI, newRI);
}
}
}
char GenVISC::ID = 0;
static RegisterPass<GenVISC> X("genvisc", "Pass to generate VISC IR from LLVM IR (with dummy function calls)", false, false);
......
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