[llvm] [SandboxIR][Bench] Initial patch for performance tracking (PR #107296)
Alina Sbirlea via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 5 10:33:26 PDT 2024
================
@@ -0,0 +1,115 @@
+//===- SandboxIRBench.cpp -------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// These tests measure the performance of some core SandboxIR functions and
+// compare them against LLVM IR.
+//
+//===----------------------------------------------------------------------===//
+
+#include "benchmark/benchmark.h"
+#include "llvm/AsmParser/Parser.h"
+#include "llvm/IR/BasicBlock.h"
+#include "llvm/IR/DataLayout.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/Instruction.h"
+#include "llvm/IR/Module.h"
+#include "llvm/SandboxIR/SandboxIR.h"
+#include "llvm/Support/SourceMgr.h"
+#include <memory>
+
+using namespace llvm;
+
+static std::unique_ptr<Module> parseIR(LLVMContext &C, const char *IR) {
+ SMDiagnostic Err;
+ std::unique_ptr<Module> M = parseAssemblyString(IR, Err, C);
+ if (!M)
+ Err.print("SandboxIRBench", errs());
+ return M;
+}
+
+enum class IR {
+ LLVM,
+ SBox,
+};
+// Traits to get llvm::BasicBlock/sandboxir::BasicBlock from IR::LLVM/IR::SBox.
+template <IR IRTy> struct TypeSelect {};
+template <> struct TypeSelect<IR::LLVM> {
+ using BasicBlock = llvm::BasicBlock;
+};
+template <> struct TypeSelect<IR::SBox> {
+ using BasicBlock = sandboxir::BasicBlock;
+};
+
+template <IR IRTy>
+static typename TypeSelect<IRTy>::BasicBlock *
+genIR(std::unique_ptr<llvm::Module> &LLVMM, LLVMContext &LLVMCtx,
+ sandboxir::Context &Ctx,
+ std::function<std::string(unsigned)> GenerateIRStr,
+ unsigned NumInstrs = 0u) {
+ std::string IRStr = GenerateIRStr(NumInstrs);
+ LLVMM = parseIR(LLVMCtx, IRStr.c_str());
+ llvm::Function *LLVMF = &*LLVMM->getFunction("foo");
+ llvm::BasicBlock *LLVMBB = &*LLVMF->begin();
+
+ sandboxir::Function *F = Ctx.createFunction(LLVMF);
----------------
alinas wrote:
This patch is adding benchmarking for LLVM-IR vs Sandbox-IR traversal, but it will not benchmark the creation of SandboxIR, as it's done in both currently. Can you add this in a follow up?
https://github.com/llvm/llvm-project/pull/107296
More information about the llvm-commits
mailing list