From 23aa69f1e882f0a63a76bcdaa5688e60ccd451da Mon Sep 17 00:00:00 2001 From: Mordan Vitalii Date: Thu, 11 May 2023 21:59:41 +0500 Subject: [PATCH] Collecting coverage for new interpreter based on IrToc Signed-off-by: Mordan Vitalii --- compiler/optimizer/code_generator/codegen.cpp | 14 +++++++++++++ compiler/optimizer/ir/graph.h | 5 ++++- compiler/optimizer/ir/runtime_interface.h | 2 ++ runtime/entrypoints/entrypoints.cpp | 20 +++++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/compiler/optimizer/code_generator/codegen.cpp b/compiler/optimizer/code_generator/codegen.cpp index 865dd79bd..5a26e484b 100644 --- a/compiler/optimizer/code_generator/codegen.cpp +++ b/compiler/optimizer/code_generator/codegen.cpp @@ -390,6 +390,13 @@ bool Codegen::VisitGraph() for (auto bb : blocks) { GetEncoder()->BindLabel(bb->GetId()); + // TODO(mwx851039): put under #ifdef + if (GetGraph()->IsInterpreterMode() && !bb->IsEmpty()) { + InsertTrace(TypedImm(static_cast(TraceId::COV_START_BLOCK)), + TypedImm(reinterpret_cast(GetGraph()->GetMethod())), + TypedImm(GetEncoder()->GetCursorOffset()), + TypedImm(bb->GetId())); + } for (auto inst : bb->AllInsts()) { SCOPED_DISASM_INST(this, inst); @@ -400,6 +407,13 @@ bool Codegen::VisitGraph() } } #endif + // TODO(mwx851039): put under #ifdef + if (GetGraph()->IsInterpreterMode() && bb->GetLastInst() == inst) { + InsertTrace(TypedImm(static_cast(TraceId::COV_END_BLOCK)), + TypedImm(reinterpret_cast(GetGraph()->GetMethod())), + TypedImm(GetEncoder()->GetCursorOffset()), + TypedImm(bb->GetId())); + } visitor.VisitInstruction(inst); if (!visitor.GetResult()) { COMPILER_LOG(DEBUG, CODEGEN) diff --git a/compiler/optimizer/ir/graph.h b/compiler/optimizer/ir/graph.h index dfad04b0c..515f017e1 100644 --- a/compiler/optimizer/ir/graph.h +++ b/compiler/optimizer/ir/graph.h @@ -337,7 +337,10 @@ public: { return IsAotMode() || GetMode().IsInterpreter() || GetMode().IsFastPath() || GetMode().IsInterpreterEntry(); } - + bool IsInterpreterMode() const + { + return GetMode().IsInterpreter() || GetMode().IsInterpreterEntry(); + } bool IsDefaultLocationsInit() const { return FlagDefaultLocationsInit::Get(bit_fields_); diff --git a/compiler/optimizer/ir/runtime_interface.h b/compiler/optimizer/ir/runtime_interface.h index d9204e8a5..cfaed3297 100644 --- a/compiler/optimizer/ir/runtime_interface.h +++ b/compiler/optimizer/ir/runtime_interface.h @@ -1223,6 +1223,8 @@ enum class TraceId { METHOD_EXIT = 1U << 1U, PRINT_ARG = 1U << 2U, TLAB_EVENT = 1U << 3U, + COV_START_BLOCK = 1U << 4U, + COV_END_BLOCK = 1U << 5U, }; enum class DeoptimizeType : uint8_t { diff --git a/runtime/entrypoints/entrypoints.cpp b/runtime/entrypoints/entrypoints.cpp index 9f6f27f9a..cc7519f79 100644 --- a/runtime/entrypoints/entrypoints.cpp +++ b/runtime/entrypoints/entrypoints.cpp @@ -1021,6 +1021,26 @@ extern "C" void TraceEntrypoint(size_t pid, ...) EVENT_TLAB_ALLOC(ManagedThread::GetCurrent()->GetId(), tlab, inst_name, memory, size); break; } + case TraceId::COV_START_BLOCK: { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,clang-analyzer-valist.Uninitialized) + [[maybe_unused]] size_t handle = va_arg(args, size_t); + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,clang-analyzer-valist.Uninitialized) + [[maybe_unused]] size_t pc = va_arg(args, size_t); + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,clang-analyzer-valist.Uninitialized) + [[maybe_unused]] size_t bb = va_arg(args, size_t); + std::cerr << "TraceId::COV_START_BLOCK, handle=" << handle << ", pc=" << pc << ", bb=" << bb << std::endl; + break; + } + case TraceId::COV_END_BLOCK: { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,clang-analyzer-valist.Uninitialized) + [[maybe_unused]] size_t handle = va_arg(args, size_t); + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,clang-analyzer-valist.Uninitialized) + [[maybe_unused]] size_t pc = va_arg(args, size_t); + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,clang-analyzer-valist.Uninitialized) + [[maybe_unused]] size_t bb = va_arg(args, size_t); + std::cerr << "TraceId::COV_END_BLOCK, handle=" << handle << ", pc=" << pc << ", bb=" << bb << std::endl; + break; + } default: { break; } -- Gitee