Files
TheRock/compiler/amd-llvm/llvm/unittests/tools/llvm-mca/MCATestBase.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

133 lines
4.4 KiB
C++

#include "MCATestBase.h"
#include "Views/SummaryView.h"
#include "llvm/MCA/CustomBehaviour.h"
#include "llvm/MCA/InstrBuilder.h"
#include "llvm/MCA/Pipeline.h"
#include "llvm/MCA/SourceMgr.h"
#include "llvm/MCA/View.h"
#include "llvm/Support/JSON.h"
#include "llvm/Support/WithColor.h"
#include <string>
using namespace llvm;
using namespace mca;
const Target *MCATestBase::getLLVMTarget() const {
std::string Error;
return TargetRegistry::lookupTarget(TheTriple, Error);
}
mca::PipelineOptions MCATestBase::getDefaultPipelineOptions() {
mca::PipelineOptions PO(/*MicroOpQueue=*/0, /*DecoderThroughput=*/0,
/*DispatchWidth=*/0,
/*RegisterFileSize=*/0,
/*LoadQueueSize=*/0, /*StoreQueueSize=*/0,
/*AssumeNoAlias=*/true,
/*EnableBottleneckAnalysis=*/false);
return PO;
}
void MCATestBase::SetUp() {
TheTarget = getLLVMTarget();
ASSERT_NE(TheTarget, nullptr);
STI.reset(TheTarget->createMCSubtargetInfo(TheTriple, CPUName, MAttr));
ASSERT_TRUE(STI);
ASSERT_TRUE(STI->isCPUStringValid(CPUName));
MRI.reset(TheTarget->createMCRegInfo(TheTriple));
ASSERT_TRUE(MRI);
auto MCOptions = getMCTargetOptions();
MAI.reset(TheTarget->createMCAsmInfo(*MRI, TheTriple, MCOptions));
ASSERT_TRUE(MAI);
Ctx = std::make_unique<MCContext>(TheTriple, *MAI, *MRI, *STI);
MOFI.reset(TheTarget->createMCObjectFileInfo(*Ctx, /*PIC=*/false));
Ctx->setObjectFileInfo(MOFI.get());
MCII.reset(TheTarget->createMCInstrInfo());
ASSERT_TRUE(MCII);
MCIA.reset(TheTarget->createMCInstrAnalysis(MCII.get()));
ASSERT_TRUE(MCIA);
IP.reset(TheTarget->createMCInstPrinter(TheTriple, /*AssemblerDialect=*/0,
*MAI, *MCII, *MRI));
ASSERT_TRUE(IP);
}
Error MCATestBase::runBaselineMCA(
json::Object &Result, ArrayRef<MCInst> Insts, ArrayRef<mca::View *> Views,
const mca::PipelineOptions *PO,
ArrayRef<std::pair<StringRef, StringRef>> Descs) {
mca::Context MCA(*MRI, *STI);
// Enable instruments when descriptions are provided
auto IM =
std::make_unique<mca::InstrumentManager>(*STI, *MCII, !Descs.empty());
mca::InstrBuilder IB(*STI, *MCII, *MRI, MCIA.get(), *IM, /*CallLatency=*/100);
SmallVector<mca::Instrument *> Instruments;
SmallVector<mca::UniqueInstrument> InstrumentsOwner;
for (const auto &Desc : Descs) {
auto I = IM->createInstrument(Desc.first, Desc.second);
Instruments.push_back(I.get());
InstrumentsOwner.push_back(std::move(I));
}
SmallVector<std::unique_ptr<mca::Instruction>> LoweredInsts;
for (const auto &MCI : Insts) {
Expected<std::unique_ptr<mca::Instruction>> Inst =
IB.createInstruction(MCI, Instruments);
if (!Inst) {
if (auto NewE =
handleErrors(Inst.takeError(),
[this](const mca::InstructionError<MCInst> &IE) {
std::string InstructionStr;
raw_string_ostream SS(InstructionStr);
WithColor::error() << IE.Message << '\n';
IP->printInst(&IE.Inst, 0, "", *STI, SS);
WithColor::note()
<< "instruction: " << InstructionStr << '\n';
})) {
// Default case.
return NewE;
}
} else {
LoweredInsts.emplace_back(std::move(Inst.get()));
}
}
mca::CircularSourceMgr SM(LoweredInsts, /*Iterations=*/1);
// Empty CustomBehaviour.
auto CB = std::make_unique<mca::CustomBehaviour>(*STI, SM, *MCII);
mca::PipelineOptions ThePO = PO ? *PO : getDefaultPipelineOptions();
auto P = MCA.createDefaultPipeline(ThePO, SM, *CB);
SmallVector<std::unique_ptr<mca::View>, 1> DefaultViews;
if (Views.empty()) {
// By default, we only add SummaryView.
auto SV = std::make_unique<SummaryView>(STI->getSchedModel(), Insts,
ThePO.DispatchWidth);
P->addEventListener(SV.get());
DefaultViews.emplace_back(std::move(SV));
} else {
for (auto *V : Views)
P->addEventListener(V);
}
// Run the pipeline.
Expected<unsigned> Cycles = P->run();
if (!Cycles)
return Cycles.takeError();
for (const auto *V : Views)
Result[V->getNameAsString()] = V->toJSON();
for (const auto &V : DefaultViews)
Result[V->getNameAsString()] = V->toJSON();
return Error::success();
}