================
@@ -440,6 +452,42 @@ void WebAssemblyAsmPrinter::emitEndOfAsmFile(Module &M) {
   EmitProducerInfo(M);
   EmitTargetFeatures(M);
   EmitFunctionAttributes(M);
+
+  // Subtarget may be null if no functions have been defined in file
+  if (Subtarget && Subtarget->hasBranchHinting())
+    emitBranchHintSection();
+}
+
+void WebAssemblyAsmPrinter::emitBranchHintSection() const {
+  MCSectionWasm *BranchHintsSection = OutContext.getWasmSection(
+      ".custom_section.metadata.code.branch_hint", SectionKind::getMetadata());
+  const uint32_t NumFunctionHints =
+      std::count_if(BranchHints.begin(), BranchHints.end(),
+                    [](const auto &BHR) { return !BHR.Hints.empty(); });
+  if (NumFunctionHints == 0)
+    return;
+  OutStreamer->pushSection();
+  OutStreamer->switchSection(BranchHintsSection);
+  OutStreamer->emitULEB128IntValue(NumFunctionHints);
+  for (const auto &BHR : BranchHints) {
+    if (BHR.Hints.empty())
+      continue;
+    // emit relocatable function index for the function symbol
+    OutStreamer->emitULEB128Value(MCSymbolRefExpr::create(
+        BHR.FuncSym, WebAssembly::S_FUNCINDEX, OutContext));
+    // emit the number of hints for this function (is constant -> does not need
+    // handling by target streamer for reloc)
+    OutStreamer->emitULEB128IntValue(BHR.Hints.size());
+    for (const auto &[instrSym, hint] : BHR.Hints) {
+      assert(hint == 0 || hint == 1);
+      // offset from function start
+      OutStreamer->emitULEB128Value(MCSymbolRefExpr::create(
+          instrSym, WebAssembly::S_DEBUG_REF, OutContext));
----------------
Lukasdoe wrote:

resolved since it is no longer required :)

https://github.com/llvm/llvm-project/pull/146230
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to