| 989 | } |
| 990 | |
| 991 | int LlvmCodeGen::ReplaceCallSites( |
| 992 | llvm::Function* caller, llvm::Function* new_fn, const string& target_name) { |
| 993 | DCHECK(!is_compiled_); |
| 994 | DCHECK(caller != NULL); |
| 995 | DCHECK(caller->getParent() == module_); |
| 996 | DCHECK(new_fn != NULL); |
| 997 | DCHECK(find(handcrafted_functions_.begin(), handcrafted_functions_.end(), new_fn) |
| 998 | == handcrafted_functions_.end() |
| 999 | || finalized_functions_.find(new_fn) != finalized_functions_.end()); |
| 1000 | |
| 1001 | vector<llvm::CallInst*> call_sites; |
| 1002 | FindCallSites(caller, target_name, &call_sites); |
| 1003 | int replaced = 0; |
| 1004 | for (llvm::CallInst* call_instr : call_sites) { |
| 1005 | // Replace the called function |
| 1006 | call_instr->setCalledFunction(new_fn); |
| 1007 | ++replaced; |
| 1008 | } |
| 1009 | return replaced; |
| 1010 | } |
| 1011 | |
| 1012 | int LlvmCodeGen::ReplaceCallSitesWithValue( |
| 1013 | llvm::Function* caller, llvm::Value* replacement, const string& target_name) { |