a12761964986dd76fa2483af5bf6a3f31d397eb0
[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                 if ( (CI->isTailCall() && funName.contains("atomic_")) ||
15                         funName.contains("atomic_compare_exchange_") ) {
16                         // printArgs(CI);
17                         return true;
18                 }
19         }
20
21         return false;
22 }
23
24 void printArgs (CallInst *CI)
25 {
26         Function *fun = CI->getCalledFunction();
27         StringRef funName = fun->getName();
28
29         User::op_iterator begin = CI->arg_begin();
30         User::op_iterator end = CI->arg_end();
31
32         if ( funName.contains("atomic_") ) {
33                 std::vector<Value *> parameters;
34
35                 for (User::op_iterator it = begin; it != end; ++it) {
36                         Value *param = *it;
37                         parameters.push_back(param);
38                         errs() << *param << " type: " << *param->getType()  << "\n";
39                 }
40         }
41
42 }