diff --git a/llvm/include/llvm/GenVISC/GenVISC.h b/llvm/include/llvm/GenVISC/GenVISC.h index 05ca4e2417f89ebdd53886772439bd3d2ca29679..4326e736de464307c7e0f7c00005363aefb09b09 100644 --- a/llvm/include/llvm/GenVISC/GenVISC.h +++ b/llvm/include/llvm/GenVISC/GenVISC.h @@ -35,6 +35,9 @@ public: // Functions virtual bool runOnModule(Module &M); + static bool isVISCNodeCall(Instruction* I); + static void genKernel(Function* KernelFunction, CallInst* CI); + static void genHost(CallInst* CI); }; } // End of namespace diff --git a/llvm/lib/Transforms/GenVISC/GenVISC.cpp b/llvm/lib/Transforms/GenVISC/GenVISC.cpp index 84fc2001f48e2eda8680d7734696865fc71f7bc4..5530eac7258a5c79d6de38833851021cf89c7956 100644 --- a/llvm/lib/Transforms/GenVISC/GenVISC.cpp +++ b/llvm/lib/Transforms/GenVISC/GenVISC.cpp @@ -25,8 +25,6 @@ bool GenVISC::runOnModule(Module &M) { errs() << "-------- Searching for launch sites ----------\n"; - IntrinsicInst* II; - // Iterate over all functions in the module for (Module::iterator mi = M.begin(), me = M.end(); mi != me; ++mi) { Function* f = &*mi; @@ -34,15 +32,40 @@ bool GenVISC::runOnModule(Module &M) { for (inst_iterator i = inst_begin(f), e = inst_end(f); i != e ; ++i) { Instruction* I = &*i; // Grab pointer to Instruction + if(isVISCNodeCall(I)) { + CallInst* CI = cast<CallInst>(I); + errs() << "Found visc node call\n"; + assert(CI->getNumArgOperands() >= 4 + && "__visc_node call should have atleast 4 arguments!"); + genKernel(cast<Function>(CI->getArgOperand(0)), CI); + genHost(CI); + } } } - // Checking that we found at least one launch site - //assert((Roots.size() != 0) && "Launch site not found."); - return false; //TODO: What does returning "false" mean? } +// Helper Functions + +bool GenVISC::isVISCNodeCall(Instruction* I) { + if(!isa<CallInst>(I)) + return false; + CallInst* CI = cast<CallInst>(I); + DEBUG(errs() << *I << "\n"); + return (CI->getCalledValue()->stripPointerCasts()->getName()).equals("__visc__node"); +} + +void GenVISC::genKernel(Function* KernelF, CallInst* CI) { + // Make changes to kernel here + errs() << "Modifying Node Function: " << KernelF->getName() << "\n"; +} + +void GenVISC::genHost(CallInst* CI) { + // Make host code changes here + errs() << "Modifying Host code for __visc__node call site: " << *CI << "\n"; +} + char GenVISC::ID = 0; static RegisterPass<GenVISC> X("genvisc", "Pass to generate VISC IR from LLVM IR (with dummy function calls)", false, false);