[llvm-branch-commits] [llvm][AsmPrinter] Emit call graph section (PR #87576)

Matt Arsenault via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Feb 11 21:13:03 PST 2025


================
@@ -1642,6 +1642,102 @@ void AsmPrinter::emitStackUsage(const MachineFunction &MF) {
     *StackUsageStream << "static\n";
 }
 
+/// Extracts a generalized numeric type identifier of a Function's type from
+/// type metadata. Returns null if metadata cannot be found.
+static ConstantInt *extractNumericCGTypeId(const Function &F) {
+  SmallVector<MDNode *, 2> Types;
+  F.getMetadata(LLVMContext::MD_type, Types);
+  MDString *MDGeneralizedTypeId = nullptr;
+  for (const auto &Type : Types) {
+    if (Type->getNumOperands() == 2 && isa<MDString>(Type->getOperand(1))) {
+      auto *TMDS = cast<MDString>(Type->getOperand(1));
+      if (TMDS->getString().ends_with("generalized")) {
+        MDGeneralizedTypeId = TMDS;
+        break;
+      }
+    }
+  }
+
+  if (!MDGeneralizedTypeId)
+    return nullptr;
+
+  uint64_t TypeIdVal = llvm::MD5Hash(MDGeneralizedTypeId->getString());
+  Type *Int64Ty = Type::getInt64Ty(F.getContext());
+  return cast<ConstantInt>(ConstantInt::get(Int64Ty, TypeIdVal));
----------------
arsenm wrote:

This cast is unnecessary. 
```suggestion
  return ConstantInt::get(Int64Ty, TypeIdVal);
```

https://github.com/llvm/llvm-project/pull/87576


More information about the llvm-branch-commits mailing list