99e7532af64c49e670dc009512d2660beee4f02b
[c11llvm.git] / isAtomicCall.hpp
1 #pragma once
2
3 void printArgs(CallInst *);
4
5 bool isAtomicCall(Instruction *I)
6 {
7         if ( auto *CI = dyn_cast<CallInst>(I) ) {
8                 Function *fun = CI->getCalledFunction();
9                 if (fun == NULL)
10                         return false;
11
12                 StringRef funName = fun->getName();
13
14                 // todo: come up with better rules for function name checking
15                 if ( funName.contains("atomic_") ) {
16                         // printArgs(CI);
17                         return true;
18                 } else if (funName.contains("atomic") ) {
19                         // errs() << "intercepted atomic calls: " << *I << "\n";
20                         return true;
21                 }
22         }
23
24         return false;
25 }
26
27 void printArgs (CallInst *CI)
28 {
29         Function *fun = CI->getCalledFunction();
30         StringRef funName = fun->getName();
31
32         User::op_iterator begin = CI->arg_begin();
33         User::op_iterator end = CI->arg_end();
34
35         if ( funName.contains("atomic_") ) {
36                 std::vector<Value *> parameters;
37
38                 for (User::op_iterator it = begin; it != end; ++it) {
39                         Value *param = *it;
40                         parameters.push_back(param);
41                         errs() << *param << " type: " << *param->getType()  << "\n";
42                 }
43         }
44
45 }