1 //===---- MCATestBase.h -----------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
8 // Test fixture common to all MCA tests.
9 //===----------------------------------------------------------------------===//
11 #ifndef LLVM_UNITTESTS_TOOLS_LLVMMCA_MCATESTBASE_H
12 #define LLVM_UNITTESTS_TOOLS_LLVMMCA_MCATESTBASE_H
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/MC/MCAsmInfo.h"
16 #include "llvm/MC/MCContext.h"
17 #include "llvm/MC/MCInst.h"
18 #include "llvm/MC/MCInstPrinter.h"
19 #include "llvm/MC/MCInstrAnalysis.h"
20 #include "llvm/MC/MCInstrInfo.h"
21 #include "llvm/MC/MCObjectFileInfo.h"
22 #include "llvm/MC/MCRegisterInfo.h"
23 #include "llvm/MC/MCSubtargetInfo.h"
24 #include "llvm/MC/MCTargetOptions.h"
25 #include "llvm/MC/TargetRegistry.h"
26 #include "llvm/MCA/Context.h"
27 #include "llvm/TargetParser/SubtargetFeature.h"
28 #include "llvm/TargetParser/Triple.h"
30 #include "gtest/gtest.h"
35 } // end namespace json
40 class MCATestBase
: public ::testing::Test
{
42 // Note: Subclass ctors are expected to perform target-specific
44 MCATestBase(StringRef TripleStr
, StringRef CPUName
, StringRef MAttr
= "")
45 : TheTriple(TripleStr
), CPUName(CPUName
), MAttr(MAttr
) {}
47 /// Factory function to create a Target.
48 virtual const Target
*getLLVMTarget() const;
50 /// Factory function to create a MCTargetOptions instance. Returns an
51 /// empty one by default.
52 virtual MCTargetOptions
getMCTargetOptions() { return MCTargetOptions(); }
54 const Target
*TheTarget
;
55 const Triple TheTriple
;
60 std::unique_ptr
<MCSubtargetInfo
> STI
;
61 std::unique_ptr
<MCRegisterInfo
> MRI
;
62 std::unique_ptr
<MCAsmInfo
> MAI
;
63 std::unique_ptr
<MCObjectFileInfo
> MOFI
;
64 std::unique_ptr
<MCContext
> Ctx
;
65 std::unique_ptr
<MCInstrInfo
> MCII
;
66 std::unique_ptr
<MCInstrAnalysis
> MCIA
;
67 std::unique_ptr
<MCInstPrinter
> IP
;
69 static mca::PipelineOptions
getDefaultPipelineOptions();
71 void SetUp() override
;
73 /// Utility function to run MCA with (nearly) the same configuration as the
74 /// `llvm-mca` tool to verify result correctness.
75 /// This function only displays on SummaryView by default.
76 virtual Error
runBaselineMCA(json::Object
&Result
, ArrayRef
<MCInst
> Insts
,
77 ArrayRef
<mca::View
*> Views
= {},
78 const mca::PipelineOptions
*PO
= nullptr);
81 } // end namespace mca
82 } // end namespace llvm