|
26 | 26 | #include "llvm/CodeGen/MachineBasicBlock.h" |
27 | 27 | #include "llvm/CodeGen/MachineInstr.h" |
28 | 28 | #include "llvm/CodeGen/MachineMemOperand.h" |
| 29 | +#include "llvm/IR/Constants.h" |
29 | 30 | #include "llvm/IR/EHPersonalities.h" |
| 31 | +#include "llvm/IR/Instructions.h" |
30 | 32 | #include "llvm/Support/Allocator.h" |
31 | 33 | #include "llvm/Support/ArrayRecycler.h" |
32 | 34 | #include "llvm/Support/AtomicOrdering.h" |
33 | 35 | #include "llvm/Support/Compiler.h" |
| 36 | +#include "llvm/Support/MD5.h" |
34 | 37 | #include "llvm/Support/Recycler.h" |
35 | 38 | #include "llvm/Target/TargetOptions.h" |
36 | 39 | #include <bitset> |
@@ -517,6 +520,32 @@ class LLVM_ABI MachineFunction { |
517 | 520 | SmallVector<ArgRegPair, 1> ArgRegPairs; |
518 | 521 | /// Callee type ids. |
519 | 522 | SmallVector<ConstantInt *, 4> CalleeTypeIds; |
| 523 | + |
| 524 | + CallSiteInfo() = default; |
| 525 | + |
| 526 | + /// Extracts the numeric type id from the CallBase's callee_type Metadata, |
| 527 | + /// and sets CalleeTypeIds. This is used as type id for the indirect call in |
| 528 | + /// the call graph section. |
| 529 | + CallSiteInfo(const CallBase &CB) { |
| 530 | + // Call graph section needs numeric callee_type id only for indirect |
| 531 | + // calls. |
| 532 | + if (!CB.isIndirectCall()) |
| 533 | + return; |
| 534 | + |
| 535 | + MDNode *CalleeTypeList = CB.getMetadata(LLVMContext::MD_callee_type); |
| 536 | + if (!CalleeTypeList) |
| 537 | + return; |
| 538 | + |
| 539 | + for (const MDOperand &Op : CalleeTypeList->operands()) { |
| 540 | + MDNode *TypeMD = cast<MDNode>(Op); |
| 541 | + MDString *TypeIdStr = cast<MDString>(TypeMD->getOperand(1)); |
| 542 | + // Compute numeric type id from generalized type id string |
| 543 | + uint64_t TypeIdVal = MD5Hash(TypeIdStr->getString()); |
| 544 | + IntegerType *Int64Ty = Type::getInt64Ty(CB.getContext()); |
| 545 | + CalleeTypeIds.push_back( |
| 546 | + ConstantInt::get(Int64Ty, TypeIdVal, /*IsSigned=*/false)); |
| 547 | + } |
| 548 | + } |
520 | 549 | }; |
521 | 550 |
|
522 | 551 | struct CalledGlobalInfo { |
|
0 commit comments