Files
TheRock/compiler/amd-llvm/llvm/unittests/Transforms/Utils/ProfDataUtilTest.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

84 lines
2.3 KiB
C++

//===----- ProfDataUtils.cpp - Unit tests for ProfDataUtils ---------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include "llvm/AsmParser/Parser.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/ProfDataUtils.h"
#include "llvm/Support/SourceMgr.h"
#include "gtest/gtest.h"
using namespace llvm;
static std::unique_ptr<Module> parseIR(LLVMContext &C, const char *IR) {
SMDiagnostic Err;
std::unique_ptr<Module> Mod = parseAssemblyString(IR, Err, C);
if (!Mod)
Err.print("ProfDataUtilsTests", errs());
return Mod;
}
TEST(ProfDataUtils, extractWeights) {
LLVMContext C;
std::unique_ptr<Module> M = parseIR(C, R"IR(
define void @foo(i1 %cond0) {
entry:
br i1 %cond0, label %bb0, label %bb1, !prof !1
bb0:
%0 = mul i32 1, 2
br label %bb1
bb1:
ret void
}
!1 = !{!"branch_weights", i32 1, i32 100000}
)IR");
Function *F = M->getFunction("foo");
auto &Entry = F->getEntryBlock();
auto &I = Entry.front();
auto *Branch = dyn_cast<CondBrInst>(&I);
EXPECT_NE(nullptr, Branch);
auto *ProfileData = Branch->getMetadata(LLVMContext::MD_prof);
EXPECT_NE(ProfileData, nullptr);
EXPECT_TRUE(hasProfMD(I));
SmallVector<uint32_t> Weights;
EXPECT_TRUE(extractBranchWeights(ProfileData, Weights));
EXPECT_EQ(Weights[0], 1U);
EXPECT_EQ(Weights[1], 100000U);
EXPECT_EQ(Weights.size(), 2U);
}
TEST(ProfDataUtils, NoWeights) {
LLVMContext C;
std::unique_ptr<Module> M = parseIR(C, R"IR(
define void @foo(i1 %cond0) {
entry:
br i1 %cond0, label %bb0, label %bb1
bb0:
%0 = mul i32 1, 2
br label %bb1
bb1:
ret void
}
)IR");
Function *F = M->getFunction("foo");
auto &Entry = F->getEntryBlock();
auto &I = Entry.front();
auto *Branch = dyn_cast<CondBrInst>(&I);
EXPECT_NE(nullptr, Branch);
auto *ProfileData = Branch->getMetadata(LLVMContext::MD_prof);
EXPECT_EQ(ProfileData, nullptr);
EXPECT_FALSE(hasProfMD(I));
SmallVector<uint32_t> Weights;
EXPECT_FALSE(extractBranchWeights(ProfileData, Weights));
EXPECT_EQ(Weights.size(), 0U);
}