[llvm] [llvm-remarkutil] Add an instruction-mix tool (PR #140598)

Jon Roelofs via llvm-commits llvm-commits at lists.llvm.org
Tue May 20 18:36:47 PDT 2025


================
@@ -0,0 +1,125 @@
+
+#include "RemarkUtilHelpers.h"
+#include "RemarkUtilRegistry.h"
+
+#include "llvm/Support/Format.h"
+#include "llvm/Support/FormattedStream.h"
+#include "llvm/Support/Regex.h"
+
+#include <numeric>
+
+using namespace llvm;
+using namespace remarks;
+using namespace llvm::remarkutil;
+
+namespace instructionmix {
+
+static cl::SubCommand
+    InstructionMix("instruction-mix",
+                   "Instruction Mix (requires asm-printer remarks)");
+
+static cl::opt<std::string>
+    FunctionFilter("filter", cl::sub(InstructionMix), cl::init(".*"),
+                   cl::value_desc("filter_regex"),
+                   cl::desc("regex to filter functions with"));
+
+enum ReportStyleOptions { human_output, csv_output };
+static cl::opt<ReportStyleOptions> ReportStyle(
+    "report_style", cl::sub(InstructionMix),
+    cl::init(ReportStyleOptions::human_output),
+    cl::desc("Choose the report output format:"),
+    cl::values(clEnumValN(human_output, "human", "Human-readable format"),
+               clEnumValN(csv_output, "csv", "CSV format")));
+
+INPUT_FORMAT_COMMAND_LINE_OPTIONS(InstructionMix)
+INPUT_OUTPUT_COMMAND_LINE_OPTIONS(InstructionMix)
+DEBUG_LOC_INFO_COMMAND_LINE_OPTIONS(InstructionMix)
+
+static Error tryInstructionMix() {
+  auto MaybeOF =
+      getOutputFileWithFlags(OutputFileName, sys::fs::OF_TextWithCRLF);
+  if (!MaybeOF)
+    return MaybeOF.takeError();
+
+  auto OF = std::move(*MaybeOF);
+  auto MaybeBuf = getInputMemoryBuffer(InputFileName);
+  if (!MaybeBuf)
+    return MaybeBuf.takeError();
+  auto MaybeParser = createRemarkParser(InputFormat, (*MaybeBuf)->getBuffer());
+  if (!MaybeParser)
+    return MaybeParser.takeError();
+
+  Regex Filter(FunctionFilter);
----------------
jroelofs wrote:

This turned into a bit of a small refactor. I'll split that out as a separate PR.

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


More information about the llvm-commits mailing list