|
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> |
@@ -486,6 +489,40 @@ class LLVM_ABI MachineFunction { |
486 | 489 | struct CallSiteInfo { |
487 | 490 | /// Vector of call argument and its forwarding register. |
488 | 491 | SmallVector<ArgRegPair, 1> ArgRegPairs; |
| 492 | + |
| 493 | + /// Callee type id. |
| 494 | + ConstantInt *TypeId = nullptr; |
| 495 | + |
| 496 | + CallSiteInfo() = default; |
| 497 | + |
| 498 | + /// Extracts the numeric type id from the CallBase's type operand bundle, |
| 499 | + /// and sets TypeId. This is used as type id for the indirect call in the |
| 500 | + /// call graph section. |
| 501 | + CallSiteInfo(const CallBase &CB) { |
| 502 | + // Call graph section needs numeric type id only for indirect calls. |
| 503 | + if (!CB.isIndirectCall()) |
| 504 | + return; |
| 505 | + |
| 506 | + std::optional<OperandBundleUse> Opt = |
| 507 | + CB.getOperandBundle(LLVMContext::OB_type); |
| 508 | + // Return if the operand bundle for call graph section cannot be found. |
| 509 | + if (!Opt) |
| 510 | + return; |
| 511 | + |
| 512 | + // Get generalized type id string |
| 513 | + auto OB = *Opt; |
| 514 | + assert(OB.Inputs.size() == 1 && "invalid input size"); |
| 515 | + auto *OBVal = OB.Inputs.front().get(); |
| 516 | + auto *TypeIdMD = cast<MetadataAsValue>(OBVal)->getMetadata(); |
| 517 | + auto *TypeIdStr = cast<MDString>(TypeIdMD); |
| 518 | + assert(TypeIdStr->getString().ends_with(".generalized") && |
| 519 | + "invalid type identifier"); |
| 520 | + |
| 521 | + // Compute numeric type id from generalized type id string |
| 522 | + uint64_t TypeIdVal = MD5Hash(TypeIdStr->getString()); |
| 523 | + IntegerType *Int64Ty = Type::getInt64Ty(CB.getContext()); |
| 524 | + TypeId = ConstantInt::get(Int64Ty, TypeIdVal, /*IsSigned=*/false); |
| 525 | + } |
489 | 526 | }; |
490 | 527 |
|
491 | 528 | private: |
|
0 commit comments