[llvm] [memprof] Accept a function name in YAML (PR #119453)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 10 14:15:48 PST 2024


================
@@ -1166,6 +1171,27 @@ template <typename FrameIdTy> class CallStackRadixTreeBuilder {
 } // namespace memprof
 
 namespace yaml {
+template <> struct ScalarTraits<memprof::GUIDHex64> {
+  static void output(const memprof::GUIDHex64 &Val, void *, raw_ostream &Out) {
+    // Print GUID as a 16-digit hexadecimal number.
+    Out << format("0x%016" PRIx64, (uint64_t)Val);
+  }
+  static StringRef input(StringRef Scalar, void *, memprof::GUIDHex64 &Val) {
+    uint64_t Num;
+    if (Scalar.starts_with_insensitive("0x")) {
+      // Accept hexadecimal numbers starting with 0x or 0X.
+      if (Scalar.getAsInteger(0, Num))
+        return "invalid hex64 number";
+      Val = Num;
+    } else {
+      // Otherwise, treat the input as a string containing a function name.
+      Val = memprof::IndexedMemProfRecord::getGUID(Scalar);
+    }
+    return StringRef();
----------------
kazutakahirata wrote:

Returning the empty string indicates a success here.

If a decimal number come in, we would treat that as a function name.  I could extend the logic to accept decimal numbers to be a little more user friendly.

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


More information about the llvm-commits mailing list