Add callee list in the llvm IR

Hello All,

I have a requirement to list all the function callee's as an entry in
the llvm IR, so that one of the llvm pass can use them and do certain
optimizations.

ex:
abc()
{
   ...
   a();
   b();
}

IR:
define void @_Z23_abc() #0 !dbg !5503 !Callee_list !5504 {
...
!5504 = !{!"a,b"}

I tried looking into SemaDeclCXX.cpp but all I was getting in the
definition data.
Can someone point out how we can do this?

Thanks in advance
Nagaraju

Just sketching and I haven’t tried any of this, but if understand things correctly, then something along the lines of this would be the idea?

for (Function &F : Module) {
if (!F.isDeclaration())
continue;
for (auto *U : F.users()) {
if (!isa(U)
continue;
U->dump();
}
}

Hi Sjoerd,
Thanks for the reply.

Just sketching and I haven't tried any of this, but if understand things correctly, then something along the lines of this would be the idea?

  for (Function &F : Module) {
    if (!F.isDeclaration())
      continue;
    for (auto *U : F.users()) {
      if (!isa<CallInst>(U)
        continue;
      U->dump();
    }
  }

I have added the suggested code in VisitCallExpr function of
SemaDecl.cpp/SemaDeclCXX.cpp/Parser.cpp files but it didn't work.
Can you please let me know which file would be the best to add this code.

Thanks,
Nagaraju