diff options
Diffstat (limited to 'llvm/unittests')
-rw-r--r-- | llvm/unittests/Analysis/IR2VecTest.cpp | 6 | ||||
-rw-r--r-- | llvm/unittests/CodeGen/CMakeLists.txt | 1 | ||||
-rw-r--r-- | llvm/unittests/CodeGen/DroppedVariableStatsMIRTest.cpp | 3 | ||||
-rw-r--r-- | llvm/unittests/CodeGen/GlobalISel/LegalizerTest.cpp | 4 | ||||
-rw-r--r-- | llvm/unittests/CodeGen/SelectionDAGAddressAnalysisTest.cpp | 95 | ||||
-rw-r--r-- | llvm/unittests/CodeGen/SelectionDAGNodeConstructionTest.cpp | 317 | ||||
-rw-r--r-- | llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp | 94 | ||||
-rw-r--r-- | llvm/unittests/CodeGen/SelectionDAGTestBase.h | 99 | ||||
-rw-r--r-- | llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp | 18 | ||||
-rw-r--r-- | llvm/unittests/Frontend/OpenMPDecompositionTest.cpp | 16 | ||||
-rw-r--r-- | llvm/unittests/Support/CMakeLists.txt | 1 | ||||
-rw-r--r-- | llvm/unittests/Support/DebugLogTest.cpp | 139 | ||||
-rw-r--r-- | llvm/unittests/TargetParser/TripleTest.cpp | 6 | ||||
-rw-r--r-- | llvm/unittests/Transforms/Vectorize/VPlanTest.cpp | 2 | ||||
-rw-r--r-- | llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp | 2 |
15 files changed, 593 insertions, 210 deletions
diff --git a/llvm/unittests/Analysis/IR2VecTest.cpp b/llvm/unittests/Analysis/IR2VecTest.cpp index 7c9a546..e288585 100644 --- a/llvm/unittests/Analysis/IR2VecTest.cpp +++ b/llvm/unittests/Analysis/IR2VecTest.cpp @@ -364,9 +364,9 @@ TEST_F(IR2VecTestFixture, GetFunctionVector) { EXPECT_TRUE(FuncVec.approximatelyEquals(Embedding(2, 44.4))); } -static constexpr unsigned MaxOpcodes = 67; -static constexpr unsigned MaxTypeIDs = 21; -static constexpr unsigned MaxOperands = 4; +static constexpr unsigned MaxOpcodes = Vocabulary::MaxOpcodes; +static constexpr unsigned MaxTypeIDs = Vocabulary::MaxTypeIDs; +static constexpr unsigned MaxOperands = Vocabulary::MaxOperandKinds; TEST(IR2VecVocabularyTest, DummyVocabTest) { for (unsigned Dim = 1; Dim <= 10; ++Dim) { diff --git a/llvm/unittests/CodeGen/CMakeLists.txt b/llvm/unittests/CodeGen/CMakeLists.txt index d19b122..22dbdaa 100644 --- a/llvm/unittests/CodeGen/CMakeLists.txt +++ b/llvm/unittests/CodeGen/CMakeLists.txt @@ -42,6 +42,7 @@ add_llvm_unittest(CodeGenTests ScalableVectorMVTsTest.cpp SchedBoundary.cpp SelectionDAGAddressAnalysisTest.cpp + SelectionDAGNodeConstructionTest.cpp SelectionDAGPatternMatchTest.cpp TypeTraitsTest.cpp TargetOptionsTest.cpp diff --git a/llvm/unittests/CodeGen/DroppedVariableStatsMIRTest.cpp b/llvm/unittests/CodeGen/DroppedVariableStatsMIRTest.cpp index 36504f5..e72b4e4 100644 --- a/llvm/unittests/CodeGen/DroppedVariableStatsMIRTest.cpp +++ b/llvm/unittests/CodeGen/DroppedVariableStatsMIRTest.cpp @@ -39,8 +39,7 @@ createTargetMachine(std::string TargetStr, StringRef CPU, StringRef FS) { return nullptr; TargetOptions Options; return std::unique_ptr<TargetMachine>( - static_cast<TargetMachine *>(T->createTargetMachine( - TT, CPU, FS, Options, std::nullopt, std::nullopt))); + T->createTargetMachine(TT, CPU, FS, Options, std::nullopt, std::nullopt)); } std::unique_ptr<Module> parseMIR(const TargetMachine &TM, StringRef MIRCode, diff --git a/llvm/unittests/CodeGen/GlobalISel/LegalizerTest.cpp b/llvm/unittests/CodeGen/GlobalISel/LegalizerTest.cpp index 7928c91..c5992eb 100644 --- a/llvm/unittests/CodeGen/GlobalISel/LegalizerTest.cpp +++ b/llvm/unittests/CodeGen/GlobalISel/LegalizerTest.cpp @@ -78,7 +78,7 @@ TEST_F(AArch64GISelMITest, BasicLegalizerTest) { CHECK: %vptr:_(p0) = COPY $x4 CHECK-NEXT: [[LOAD_0:%[0-9]+]]:_(s16) = G_LOAD %vptr:_(p0) :: (load (s8)) CHECK-NEXT: [[OFFSET_1:%[0-9]+]]:_(s64) = G_CONSTANT i64 1 - CHECK-NEXT: [[VPTR_1:%[0-9]+]]:_(p0) = G_PTR_ADD %vptr:_, [[OFFSET_1]]:_(s64) + CHECK-NEXT: [[VPTR_1:%[0-9]+]]:_(p0) = nuw inbounds G_PTR_ADD %vptr:_, [[OFFSET_1]]:_(s64) CHECK-NEXT: [[LOAD_1:%[0-9]+]]:_(s16) = G_LOAD [[VPTR_1]]:_(p0) :: (load (s8) from unknown-address + 1) CHECK-NEXT: %v:_(<2 x s8>) = G_BUILD_VECTOR_TRUNC [[LOAD_0]]:_(s16), [[LOAD_1]]:_(s16) CHECK-NEXT: $h4 = COPY %v:_(<2 x s8>) @@ -210,7 +210,7 @@ TEST_F(AArch64GISelMITest, UnorderedArtifactCombiningManyCopiesTest) { CHECK: %vptr:_(p0) = COPY $x4 CHECK-NEXT: [[LOAD_0:%[0-9]+]]:_(s16) = G_LOAD %vptr:_(p0) :: (load (s8)) CHECK-NEXT: [[OFFSET_1:%[0-9]+]]:_(s64) = G_CONSTANT i64 1 - CHECK-NEXT: [[VPTR_1:%[0-9]+]]:_(p0) = G_PTR_ADD %vptr:_, [[OFFSET_1]]:_(s64) + CHECK-NEXT: [[VPTR_1:%[0-9]+]]:_(p0) = nuw inbounds G_PTR_ADD %vptr:_, [[OFFSET_1]]:_(s64) CHECK-NEXT: [[LOAD_1:%[0-9]+]]:_(s16) = G_LOAD [[VPTR_1]]:_(p0) :: (load (s8) from unknown-address + 1) CHECK-NEXT: [[V0_EXT:%[0-9]+]]:_(s32) = G_ANYEXT [[LOAD_0]]:_(s16) CHECK-NEXT: [[FF_MASK:%[0-9]+]]:_(s32) = G_CONSTANT i32 255 diff --git a/llvm/unittests/CodeGen/SelectionDAGAddressAnalysisTest.cpp b/llvm/unittests/CodeGen/SelectionDAGAddressAnalysisTest.cpp index 0058daf..7ad7a51 100644 --- a/llvm/unittests/CodeGen/SelectionDAGAddressAnalysisTest.cpp +++ b/llvm/unittests/CodeGen/SelectionDAGAddressAnalysisTest.cpp @@ -7,103 +7,12 @@ //===----------------------------------------------------------------------===// #include "llvm/CodeGen/SelectionDAGAddressAnalysis.h" +#include "SelectionDAGTestBase.h" #include "llvm/Analysis/MemoryLocation.h" -#include "llvm/Analysis/OptimizationRemarkEmitter.h" -#include "llvm/Analysis/TargetTransformInfo.h" -#include "llvm/AsmParser/Parser.h" -#include "llvm/CodeGen/MachineModuleInfo.h" -#include "llvm/CodeGen/SelectionDAG.h" -#include "llvm/CodeGen/TargetLowering.h" -#include "llvm/IR/Module.h" -#include "llvm/MC/TargetRegistry.h" -#include "llvm/Support/SourceMgr.h" -#include "llvm/Support/TargetSelect.h" -#include "llvm/Target/TargetMachine.h" -#include "gtest/gtest.h" namespace llvm { -class SelectionDAGAddressAnalysisTest : public testing::Test { -protected: - static void SetUpTestCase() { - InitializeAllTargets(); - InitializeAllTargetMCs(); - } - - void SetUp() override { - StringRef Assembly = "@g = global i32 0\n" - "@g_alias = alias i32, i32* @g\n" - "define i32 @f() {\n" - " %1 = load i32, i32* @g\n" - " ret i32 %1\n" - "}"; - - Triple TargetTriple("aarch64--"); - std::string Error; - const Target *T = TargetRegistry::lookupTarget("", TargetTriple, Error); - // FIXME: These tests do not depend on AArch64 specifically, but we have to - // initialize a target. A skeleton Target for unittests would allow us to - // always run these tests. - if (!T) - GTEST_SKIP(); - - TargetOptions Options; - TM = std::unique_ptr<TargetMachine>( - T->createTargetMachine(TargetTriple, "", "+sve", Options, std::nullopt, - std::nullopt, CodeGenOptLevel::Aggressive)); - if (!TM) - GTEST_SKIP(); - - SMDiagnostic SMError; - M = parseAssemblyString(Assembly, SMError, Context); - if (!M) - report_fatal_error(SMError.getMessage()); - M->setDataLayout(TM->createDataLayout()); - - F = M->getFunction("f"); - if (!F) - report_fatal_error("F?"); - G = M->getGlobalVariable("g"); - if (!G) - report_fatal_error("G?"); - AliasedG = M->getNamedAlias("g_alias"); - if (!AliasedG) - report_fatal_error("AliasedG?"); - - MachineModuleInfo MMI(TM.get()); - - MF = std::make_unique<MachineFunction>(*F, *TM, *TM->getSubtargetImpl(*F), - MMI.getContext(), 0); - - DAG = std::make_unique<SelectionDAG>(*TM, CodeGenOptLevel::None); - if (!DAG) - report_fatal_error("DAG?"); - OptimizationRemarkEmitter ORE(F); - FunctionAnalysisManager FAM; - FAM.registerPass([&] { return TM->getTargetIRAnalysis(); }); - - TargetTransformInfo TTI = TM->getTargetIRAnalysis().run(*F, FAM); - DAG->init(*MF, ORE, nullptr, nullptr, nullptr, nullptr, nullptr, MMI, - nullptr, TTI.hasBranchDivergence(F)); - } - - TargetLoweringBase::LegalizeTypeAction getTypeAction(EVT VT) { - return DAG->getTargetLoweringInfo().getTypeAction(Context, VT); - } - - EVT getTypeToTransformTo(EVT VT) { - return DAG->getTargetLoweringInfo().getTypeToTransformTo(Context, VT); - } - - LLVMContext Context; - std::unique_ptr<TargetMachine> TM; - std::unique_ptr<Module> M; - Function *F; - GlobalVariable *G; - GlobalAlias *AliasedG; - std::unique_ptr<MachineFunction> MF; - std::unique_ptr<SelectionDAG> DAG; -}; +class SelectionDAGAddressAnalysisTest : public SelectionDAGTestBase {}; TEST_F(SelectionDAGAddressAnalysisTest, sameFrameObject) { SDLoc Loc; diff --git a/llvm/unittests/CodeGen/SelectionDAGNodeConstructionTest.cpp b/llvm/unittests/CodeGen/SelectionDAGNodeConstructionTest.cpp new file mode 100644 index 0000000..b2c1420 --- /dev/null +++ b/llvm/unittests/CodeGen/SelectionDAGNodeConstructionTest.cpp @@ -0,0 +1,317 @@ +//===---- llvm/unittest/CodeGen/SelectionDAGPatternMatchTest.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 +// +//===----------------------------------------------------------------------===// + +#include "SelectionDAGTestBase.h" + +using namespace llvm; + +class SelectionDAGNodeConstructionTest : public SelectionDAGTestBase {}; + +TEST_F(SelectionDAGNodeConstructionTest, ADD) { + SDLoc DL; + SDValue Poison = DAG->getPOISON(MVT::i32); + SDValue Undef = DAG->getUNDEF(MVT::i32); + SDValue Op = DAG->getCopyFromReg(DAG->getEntryNode(), DL, 1, MVT::i32); + + EXPECT_EQ(DAG->getNode(ISD::ADD, DL, MVT::i32, Op, Poison), Poison); + EXPECT_EQ(DAG->getNode(ISD::ADD, DL, MVT::i32, Poison, Op), Poison); + EXPECT_EQ(DAG->getNode(ISD::ADD, DL, MVT::i32, Poison, Undef), Poison); + EXPECT_EQ(DAG->getNode(ISD::ADD, DL, MVT::i32, Undef, Poison), Poison); + + EXPECT_EQ(DAG->getNode(ISD::ADD, DL, MVT::i32, Op, Undef), Undef); + EXPECT_EQ(DAG->getNode(ISD::ADD, DL, MVT::i32, Undef, Op), Undef); + EXPECT_EQ(DAG->getNode(ISD::ADD, DL, MVT::i32, Undef, Undef), Undef); +} + +TEST_F(SelectionDAGNodeConstructionTest, AND) { + SDLoc DL; + SDValue Op = DAG->getCopyFromReg(DAG->getEntryNode(), DL, 1, MVT::i32); + SDValue Poison = DAG->getPOISON(MVT::i32); + SDValue Undef = DAG->getUNDEF(MVT::i32); + SDValue Zero = DAG->getConstant(0, DL, MVT::i32); + + EXPECT_EQ(DAG->getNode(ISD::AND, DL, MVT::i32, Op, Poison), Poison); + EXPECT_EQ(DAG->getNode(ISD::AND, DL, MVT::i32, Poison, Op), Poison); + EXPECT_EQ(DAG->getNode(ISD::AND, DL, MVT::i32, Poison, Undef), Poison); + EXPECT_EQ(DAG->getNode(ISD::AND, DL, MVT::i32, Undef, Poison), Poison); + + EXPECT_EQ(DAG->getNode(ISD::AND, DL, MVT::i32, Op, Undef), Zero); + EXPECT_EQ(DAG->getNode(ISD::AND, DL, MVT::i32, Undef, Op), Zero); + EXPECT_EQ(DAG->getNode(ISD::AND, DL, MVT::i32, Undef, Undef), Undef); +} + +TEST_F(SelectionDAGNodeConstructionTest, MUL) { + SDLoc DL; + SDValue Op = DAG->getCopyFromReg(DAG->getEntryNode(), DL, 1, MVT::i32); + SDValue Poison = DAG->getPOISON(MVT::i32); + SDValue Undef = DAG->getUNDEF(MVT::i32); + SDValue Zero = DAG->getConstant(0, DL, MVT::i32); + + EXPECT_EQ(DAG->getNode(ISD::MUL, DL, MVT::i32, Op, Poison), Poison); + EXPECT_EQ(DAG->getNode(ISD::MUL, DL, MVT::i32, Poison, Op), Poison); + EXPECT_EQ(DAG->getNode(ISD::MUL, DL, MVT::i32, Poison, Undef), Poison); + EXPECT_EQ(DAG->getNode(ISD::MUL, DL, MVT::i32, Undef, Poison), Poison); + + EXPECT_EQ(DAG->getNode(ISD::MUL, DL, MVT::i32, Op, Undef), Zero); + EXPECT_EQ(DAG->getNode(ISD::MUL, DL, MVT::i32, Undef, Op), Zero); + EXPECT_EQ(DAG->getNode(ISD::MUL, DL, MVT::i32, Undef, Undef), Undef); +} + +TEST_F(SelectionDAGNodeConstructionTest, OR) { + SDLoc DL; + SDValue Op = DAG->getCopyFromReg(DAG->getEntryNode(), DL, 1, MVT::i32); + SDValue Poison = DAG->getPOISON(MVT::i32); + SDValue Undef = DAG->getUNDEF(MVT::i32); + SDValue AllOnes = DAG->getAllOnesConstant(DL, MVT::i32); + + EXPECT_EQ(DAG->getNode(ISD::OR, DL, MVT::i32, Op, Poison), Poison); + EXPECT_EQ(DAG->getNode(ISD::OR, DL, MVT::i32, Poison, Op), Poison); + EXPECT_EQ(DAG->getNode(ISD::OR, DL, MVT::i32, Poison, Undef), Poison); + EXPECT_EQ(DAG->getNode(ISD::OR, DL, MVT::i32, Undef, Poison), Poison); + + EXPECT_EQ(DAG->getNode(ISD::OR, DL, MVT::i32, Op, Undef), AllOnes); + EXPECT_EQ(DAG->getNode(ISD::OR, DL, MVT::i32, Undef, Op), AllOnes); + EXPECT_EQ(DAG->getNode(ISD::OR, DL, MVT::i32, Undef, Undef), Undef); +} + +TEST_F(SelectionDAGNodeConstructionTest, SADDSAT) { + SDLoc DL; + SDValue Op = DAG->getCopyFromReg(DAG->getEntryNode(), DL, 1, MVT::i32); + SDValue Poison = DAG->getPOISON(MVT::i32); + SDValue Undef = DAG->getUNDEF(MVT::i32); + SDValue AllOnes = DAG->getAllOnesConstant(DL, MVT::i32); + + EXPECT_EQ(DAG->getNode(ISD::SADDSAT, DL, MVT::i32, Op, Poison), Poison); + EXPECT_EQ(DAG->getNode(ISD::SADDSAT, DL, MVT::i32, Poison, Op), Poison); + EXPECT_EQ(DAG->getNode(ISD::SADDSAT, DL, MVT::i32, Poison, Undef), Poison); + EXPECT_EQ(DAG->getNode(ISD::SADDSAT, DL, MVT::i32, Undef, Poison), Poison); + + EXPECT_EQ(DAG->getNode(ISD::SADDSAT, DL, MVT::i32, Op, Undef), AllOnes); + EXPECT_EQ(DAG->getNode(ISD::SADDSAT, DL, MVT::i32, Undef, Op), AllOnes); + EXPECT_EQ(DAG->getNode(ISD::SADDSAT, DL, MVT::i32, Undef, Undef), Undef); +} + +TEST_F(SelectionDAGNodeConstructionTest, SDIV) { + SDLoc DL; + SDValue Op = DAG->getCopyFromReg(DAG->getEntryNode(), DL, 1, MVT::i32); + SDValue Poison = DAG->getPOISON(MVT::i32); + SDValue Undef = DAG->getUNDEF(MVT::i32); + SDValue Zero = DAG->getConstant(0, DL, MVT::i32); + + EXPECT_EQ(DAG->getNode(ISD::SDIV, DL, MVT::i32, Op, Poison), Poison); + EXPECT_EQ(DAG->getNode(ISD::SDIV, DL, MVT::i32, Poison, Op), Poison); + EXPECT_EQ(DAG->getNode(ISD::SDIV, DL, MVT::i32, Poison, Undef), Poison); + EXPECT_EQ(DAG->getNode(ISD::SDIV, DL, MVT::i32, Undef, Poison), Poison); + + EXPECT_EQ(DAG->getNode(ISD::SDIV, DL, MVT::i32, Op, Undef), Poison); + EXPECT_EQ(DAG->getNode(ISD::SDIV, DL, MVT::i32, Undef, Op), Zero); + EXPECT_EQ(DAG->getNode(ISD::SDIV, DL, MVT::i32, Undef, Undef), Poison); +} + +TEST_F(SelectionDAGNodeConstructionTest, SMAX) { + SDLoc DL; + SDValue Op = DAG->getCopyFromReg(DAG->getEntryNode(), DL, 1, MVT::i32); + SDValue Poison = DAG->getPOISON(MVT::i32); + SDValue Undef = DAG->getUNDEF(MVT::i32); + SDValue MaxInt = DAG->getConstant(APInt::getSignedMaxValue(32), DL, MVT::i32); + + EXPECT_EQ(DAG->getNode(ISD::SMAX, DL, MVT::i32, Op, Poison), Poison); + EXPECT_EQ(DAG->getNode(ISD::SMAX, DL, MVT::i32, Poison, Op), Poison); + EXPECT_EQ(DAG->getNode(ISD::SMAX, DL, MVT::i32, Poison, Undef), Poison); + EXPECT_EQ(DAG->getNode(ISD::SMAX, DL, MVT::i32, Undef, Poison), Poison); + + EXPECT_EQ(DAG->getNode(ISD::SMAX, DL, MVT::i32, Op, Undef), MaxInt); + EXPECT_EQ(DAG->getNode(ISD::SMAX, DL, MVT::i32, Undef, Op), MaxInt); + EXPECT_EQ(DAG->getNode(ISD::SMAX, DL, MVT::i32, Undef, Undef), Undef); +} + +TEST_F(SelectionDAGNodeConstructionTest, SMIN) { + SDLoc DL; + SDValue Op = DAG->getCopyFromReg(DAG->getEntryNode(), DL, 1, MVT::i32); + SDValue Poison = DAG->getPOISON(MVT::i32); + SDValue Undef = DAG->getUNDEF(MVT::i32); + SDValue MinInt = DAG->getConstant(APInt::getSignedMinValue(32), DL, MVT::i32); + + EXPECT_EQ(DAG->getNode(ISD::SMIN, DL, MVT::i32, Op, Poison), Poison); + EXPECT_EQ(DAG->getNode(ISD::SMIN, DL, MVT::i32, Poison, Op), Poison); + EXPECT_EQ(DAG->getNode(ISD::SMIN, DL, MVT::i32, Poison, Undef), Poison); + EXPECT_EQ(DAG->getNode(ISD::SMIN, DL, MVT::i32, Undef, Poison), Poison); + + EXPECT_EQ(DAG->getNode(ISD::SMIN, DL, MVT::i32, Op, Undef), MinInt); + EXPECT_EQ(DAG->getNode(ISD::SMIN, DL, MVT::i32, Undef, Op), MinInt); + EXPECT_EQ(DAG->getNode(ISD::SMIN, DL, MVT::i32, Undef, Undef), Undef); +} + +TEST_F(SelectionDAGNodeConstructionTest, SREM) { + SDLoc DL; + SDValue Op = DAG->getCopyFromReg(DAG->getEntryNode(), DL, 1, MVT::i32); + SDValue Poison = DAG->getPOISON(MVT::i32); + SDValue Undef = DAG->getUNDEF(MVT::i32); + SDValue Zero = DAG->getConstant(0, DL, MVT::i32); + + EXPECT_EQ(DAG->getNode(ISD::SREM, DL, MVT::i32, Op, Poison), Poison); + EXPECT_EQ(DAG->getNode(ISD::SREM, DL, MVT::i32, Poison, Op), Poison); + EXPECT_EQ(DAG->getNode(ISD::SREM, DL, MVT::i32, Poison, Undef), Poison); + EXPECT_EQ(DAG->getNode(ISD::SREM, DL, MVT::i32, Undef, Poison), Poison); + + EXPECT_EQ(DAG->getNode(ISD::SREM, DL, MVT::i32, Op, Undef), Poison); + EXPECT_EQ(DAG->getNode(ISD::SREM, DL, MVT::i32, Undef, Op), Zero); + EXPECT_EQ(DAG->getNode(ISD::SREM, DL, MVT::i32, Undef, Undef), Poison); +} + +TEST_F(SelectionDAGNodeConstructionTest, SSUBSAT) { + SDLoc DL; + SDValue Op = DAG->getCopyFromReg(DAG->getEntryNode(), DL, 1, MVT::i32); + SDValue Poison = DAG->getPOISON(MVT::i32); + SDValue Undef = DAG->getUNDEF(MVT::i32); + SDValue Zero = DAG->getConstant(0, DL, MVT::i32); + + EXPECT_EQ(DAG->getNode(ISD::SSUBSAT, DL, MVT::i32, Op, Poison), Poison); + EXPECT_EQ(DAG->getNode(ISD::SSUBSAT, DL, MVT::i32, Poison, Op), Poison); + EXPECT_EQ(DAG->getNode(ISD::SSUBSAT, DL, MVT::i32, Poison, Undef), Poison); + EXPECT_EQ(DAG->getNode(ISD::SSUBSAT, DL, MVT::i32, Undef, Poison), Poison); + + EXPECT_EQ(DAG->getNode(ISD::SSUBSAT, DL, MVT::i32, Op, Undef), Zero); + EXPECT_EQ(DAG->getNode(ISD::SSUBSAT, DL, MVT::i32, Undef, Op), Zero); + EXPECT_EQ(DAG->getNode(ISD::SSUBSAT, DL, MVT::i32, Undef, Undef), Undef); +} + +TEST_F(SelectionDAGNodeConstructionTest, SUB) { + SDLoc DL; + SDValue Op = DAG->getCopyFromReg(DAG->getEntryNode(), DL, 1, MVT::i32); + SDValue Poison = DAG->getPOISON(MVT::i32); + SDValue Undef = DAG->getUNDEF(MVT::i32); + + EXPECT_EQ(DAG->getNode(ISD::SUB, DL, MVT::i32, Op, Poison), Poison); + EXPECT_EQ(DAG->getNode(ISD::SUB, DL, MVT::i32, Poison, Op), Poison); + EXPECT_EQ(DAG->getNode(ISD::SUB, DL, MVT::i32, Poison, Undef), Poison); + EXPECT_EQ(DAG->getNode(ISD::SUB, DL, MVT::i32, Undef, Poison), Poison); + + EXPECT_EQ(DAG->getNode(ISD::SUB, DL, MVT::i32, Op, Undef), Undef); + EXPECT_EQ(DAG->getNode(ISD::SUB, DL, MVT::i32, Undef, Op), Undef); + EXPECT_EQ(DAG->getNode(ISD::SUB, DL, MVT::i32, Undef, Undef), Undef); +} + +TEST_F(SelectionDAGNodeConstructionTest, UADDSAT) { + SDLoc DL; + SDValue Op = DAG->getCopyFromReg(DAG->getEntryNode(), DL, 1, MVT::i32); + SDValue Poison = DAG->getPOISON(MVT::i32); + SDValue Undef = DAG->getUNDEF(MVT::i32); + SDValue AllOnes = DAG->getAllOnesConstant(DL, MVT::i32); + + EXPECT_EQ(DAG->getNode(ISD::UADDSAT, DL, MVT::i32, Op, Poison), Poison); + EXPECT_EQ(DAG->getNode(ISD::UADDSAT, DL, MVT::i32, Poison, Op), Poison); + EXPECT_EQ(DAG->getNode(ISD::UADDSAT, DL, MVT::i32, Poison, Undef), Poison); + EXPECT_EQ(DAG->getNode(ISD::UADDSAT, DL, MVT::i32, Undef, Poison), Poison); + + EXPECT_EQ(DAG->getNode(ISD::UADDSAT, DL, MVT::i32, Op, Undef), AllOnes); + EXPECT_EQ(DAG->getNode(ISD::UADDSAT, DL, MVT::i32, Undef, Op), AllOnes); + EXPECT_EQ(DAG->getNode(ISD::UADDSAT, DL, MVT::i32, Undef, Undef), Undef); +} + +TEST_F(SelectionDAGNodeConstructionTest, UDIV) { + SDLoc DL; + SDValue Op = DAG->getCopyFromReg(DAG->getEntryNode(), DL, 1, MVT::i32); + SDValue Poison = DAG->getPOISON(MVT::i32); + SDValue Undef = DAG->getUNDEF(MVT::i32); + SDValue Zero = DAG->getConstant(0, DL, MVT::i32); + + EXPECT_EQ(DAG->getNode(ISD::UDIV, DL, MVT::i32, Op, Poison), Poison); + EXPECT_EQ(DAG->getNode(ISD::UDIV, DL, MVT::i32, Poison, Op), Poison); + EXPECT_EQ(DAG->getNode(ISD::UDIV, DL, MVT::i32, Poison, Undef), Poison); + EXPECT_EQ(DAG->getNode(ISD::UDIV, DL, MVT::i32, Undef, Poison), Poison); + + EXPECT_EQ(DAG->getNode(ISD::UDIV, DL, MVT::i32, Op, Undef), Poison); + EXPECT_EQ(DAG->getNode(ISD::UDIV, DL, MVT::i32, Undef, Op), Zero); + EXPECT_EQ(DAG->getNode(ISD::UDIV, DL, MVT::i32, Undef, Undef), Poison); +} + +TEST_F(SelectionDAGNodeConstructionTest, UMAX) { + SDLoc DL; + SDValue Op = DAG->getCopyFromReg(DAG->getEntryNode(), DL, 1, MVT::i32); + SDValue Poison = DAG->getPOISON(MVT::i32); + SDValue Undef = DAG->getUNDEF(MVT::i32); + SDValue AllOnes = DAG->getAllOnesConstant(DL, MVT::i32); + + EXPECT_EQ(DAG->getNode(ISD::UMAX, DL, MVT::i32, Op, Poison), Poison); + EXPECT_EQ(DAG->getNode(ISD::UMAX, DL, MVT::i32, Poison, Op), Poison); + EXPECT_EQ(DAG->getNode(ISD::UMAX, DL, MVT::i32, Poison, Undef), Poison); + EXPECT_EQ(DAG->getNode(ISD::UMAX, DL, MVT::i32, Undef, Poison), Poison); + + EXPECT_EQ(DAG->getNode(ISD::UMAX, DL, MVT::i32, Op, Undef), AllOnes); + EXPECT_EQ(DAG->getNode(ISD::UMAX, DL, MVT::i32, Undef, Op), AllOnes); + EXPECT_EQ(DAG->getNode(ISD::UMAX, DL, MVT::i32, Undef, Undef), Undef); +} + +TEST_F(SelectionDAGNodeConstructionTest, UMIN) { + SDLoc DL; + SDValue Op = DAG->getCopyFromReg(DAG->getEntryNode(), DL, 1, MVT::i32); + SDValue Poison = DAG->getPOISON(MVT::i32); + SDValue Undef = DAG->getUNDEF(MVT::i32); + SDValue Zero = DAG->getConstant(0, DL, MVT::i32); + + EXPECT_EQ(DAG->getNode(ISD::UMIN, DL, MVT::i32, Op, Poison), Poison); + EXPECT_EQ(DAG->getNode(ISD::UMIN, DL, MVT::i32, Poison, Op), Poison); + EXPECT_EQ(DAG->getNode(ISD::UMIN, DL, MVT::i32, Poison, Undef), Poison); + EXPECT_EQ(DAG->getNode(ISD::UMIN, DL, MVT::i32, Undef, Poison), Poison); + + EXPECT_EQ(DAG->getNode(ISD::UMIN, DL, MVT::i32, Op, Undef), Zero); + EXPECT_EQ(DAG->getNode(ISD::UMIN, DL, MVT::i32, Undef, Op), Zero); + EXPECT_EQ(DAG->getNode(ISD::UMIN, DL, MVT::i32, Undef, Undef), Undef); +} + +TEST_F(SelectionDAGNodeConstructionTest, UREM) { + SDLoc DL; + SDValue Op = DAG->getCopyFromReg(DAG->getEntryNode(), DL, 1, MVT::i32); + SDValue Poison = DAG->getPOISON(MVT::i32); + SDValue Undef = DAG->getUNDEF(MVT::i32); + SDValue Zero = DAG->getConstant(0, DL, MVT::i32); + + EXPECT_EQ(DAG->getNode(ISD::UREM, DL, MVT::i32, Op, Poison), Poison); + EXPECT_EQ(DAG->getNode(ISD::UREM, DL, MVT::i32, Poison, Op), Poison); + EXPECT_EQ(DAG->getNode(ISD::UREM, DL, MVT::i32, Poison, Undef), Poison); + EXPECT_EQ(DAG->getNode(ISD::UREM, DL, MVT::i32, Undef, Poison), Poison); + + EXPECT_EQ(DAG->getNode(ISD::UREM, DL, MVT::i32, Op, Undef), Poison); + EXPECT_EQ(DAG->getNode(ISD::UREM, DL, MVT::i32, Undef, Op), Zero); + EXPECT_EQ(DAG->getNode(ISD::UREM, DL, MVT::i32, Undef, Undef), Poison); +} + +TEST_F(SelectionDAGNodeConstructionTest, USUBSAT) { + SDLoc DL; + SDValue Op = DAG->getCopyFromReg(DAG->getEntryNode(), DL, 1, MVT::i32); + SDValue Poison = DAG->getPOISON(MVT::i32); + SDValue Undef = DAG->getUNDEF(MVT::i32); + SDValue Zero = DAG->getConstant(0, DL, MVT::i32); + + EXPECT_EQ(DAG->getNode(ISD::USUBSAT, DL, MVT::i32, Op, Poison), Poison); + EXPECT_EQ(DAG->getNode(ISD::USUBSAT, DL, MVT::i32, Poison, Op), Poison); + EXPECT_EQ(DAG->getNode(ISD::USUBSAT, DL, MVT::i32, Poison, Undef), Poison); + EXPECT_EQ(DAG->getNode(ISD::USUBSAT, DL, MVT::i32, Undef, Poison), Poison); + + EXPECT_EQ(DAG->getNode(ISD::USUBSAT, DL, MVT::i32, Op, Undef), Zero); + EXPECT_EQ(DAG->getNode(ISD::USUBSAT, DL, MVT::i32, Undef, Op), Zero); + EXPECT_EQ(DAG->getNode(ISD::USUBSAT, DL, MVT::i32, Undef, Undef), Undef); +} + +TEST_F(SelectionDAGNodeConstructionTest, XOR) { + SDLoc DL; + SDValue Op = DAG->getCopyFromReg(DAG->getEntryNode(), DL, 1, MVT::i32); + SDValue Poison = DAG->getPOISON(MVT::i32); + SDValue Undef = DAG->getUNDEF(MVT::i32); + SDValue Zero = DAG->getConstant(0, DL, MVT::i32); + + EXPECT_EQ(DAG->getNode(ISD::XOR, DL, MVT::i32, Op, Poison), Poison); + EXPECT_EQ(DAG->getNode(ISD::XOR, DL, MVT::i32, Poison, Op), Poison); + EXPECT_EQ(DAG->getNode(ISD::XOR, DL, MVT::i32, Poison, Undef), Poison); + EXPECT_EQ(DAG->getNode(ISD::XOR, DL, MVT::i32, Undef, Poison), Poison); + + EXPECT_EQ(DAG->getNode(ISD::XOR, DL, MVT::i32, Op, Undef), Undef); + EXPECT_EQ(DAG->getNode(ISD::XOR, DL, MVT::i32, Undef, Op), Undef); + EXPECT_EQ(DAG->getNode(ISD::XOR, DL, MVT::i32, Undef, Undef), Zero); +} diff --git a/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp b/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp index 30a1406..4e0bf38 100644 --- a/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp +++ b/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp @@ -6,102 +6,12 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Analysis/OptimizationRemarkEmitter.h" -#include "llvm/Analysis/TargetTransformInfo.h" -#include "llvm/AsmParser/Parser.h" -#include "llvm/CodeGen/MachineModuleInfo.h" +#include "SelectionDAGTestBase.h" #include "llvm/CodeGen/SDPatternMatch.h" -#include "llvm/CodeGen/TargetLowering.h" -#include "llvm/IR/Module.h" -#include "llvm/MC/TargetRegistry.h" -#include "llvm/Support/SourceMgr.h" -#include "llvm/Support/TargetSelect.h" -#include "llvm/Target/TargetMachine.h" -#include "gtest/gtest.h" using namespace llvm; -class SelectionDAGPatternMatchTest : public testing::Test { -protected: - static void SetUpTestCase() { - InitializeAllTargets(); - InitializeAllTargetMCs(); - } - - void SetUp() override { - StringRef Assembly = "@g = global i32 0\n" - "@g_alias = alias i32, i32* @g\n" - "define i32 @f() {\n" - " %1 = load i32, i32* @g\n" - " ret i32 %1\n" - "}"; - - Triple TargetTriple("riscv64--"); - std::string Error; - const Target *T = TargetRegistry::lookupTarget("", TargetTriple, Error); - // FIXME: These tests do not depend on RISCV specifically, but we have to - // initialize a target. A skeleton Target for unittests would allow us to - // always run these tests. - if (!T) - GTEST_SKIP(); - - TargetOptions Options; - TM = std::unique_ptr<TargetMachine>(T->createTargetMachine( - TargetTriple, "", "+m,+f,+d,+v", Options, std::nullopt, std::nullopt, - CodeGenOptLevel::Aggressive)); - if (!TM) - GTEST_SKIP(); - - SMDiagnostic SMError; - M = parseAssemblyString(Assembly, SMError, Context); - if (!M) - report_fatal_error(SMError.getMessage()); - M->setDataLayout(TM->createDataLayout()); - - F = M->getFunction("f"); - if (!F) - report_fatal_error("F?"); - G = M->getGlobalVariable("g"); - if (!G) - report_fatal_error("G?"); - AliasedG = M->getNamedAlias("g_alias"); - if (!AliasedG) - report_fatal_error("AliasedG?"); - - MachineModuleInfo MMI(TM.get()); - - MF = std::make_unique<MachineFunction>(*F, *TM, *TM->getSubtargetImpl(*F), - MMI.getContext(), 0); - - DAG = std::make_unique<SelectionDAG>(*TM, CodeGenOptLevel::None); - if (!DAG) - report_fatal_error("DAG?"); - OptimizationRemarkEmitter ORE(F); - FunctionAnalysisManager FAM; - FAM.registerPass([&] { return TM->getTargetIRAnalysis(); }); - - TargetTransformInfo TTI = TM->getTargetIRAnalysis().run(*F, FAM); - DAG->init(*MF, ORE, nullptr, nullptr, nullptr, nullptr, nullptr, MMI, - nullptr, TTI.hasBranchDivergence(F)); - } - - TargetLoweringBase::LegalizeTypeAction getTypeAction(EVT VT) { - return DAG->getTargetLoweringInfo().getTypeAction(Context, VT); - } - - EVT getTypeToTransformTo(EVT VT) { - return DAG->getTargetLoweringInfo().getTypeToTransformTo(Context, VT); - } - - LLVMContext Context; - std::unique_ptr<TargetMachine> TM; - std::unique_ptr<Module> M; - Function *F; - GlobalVariable *G; - GlobalAlias *AliasedG; - std::unique_ptr<MachineFunction> MF; - std::unique_ptr<SelectionDAG> DAG; -}; +class SelectionDAGPatternMatchTest : public SelectionDAGTestBase {}; TEST_F(SelectionDAGPatternMatchTest, matchValueType) { SDLoc DL; diff --git a/llvm/unittests/CodeGen/SelectionDAGTestBase.h b/llvm/unittests/CodeGen/SelectionDAGTestBase.h new file mode 100644 index 0000000..edc730d --- /dev/null +++ b/llvm/unittests/CodeGen/SelectionDAGTestBase.h @@ -0,0 +1,99 @@ +//===---- llvm/unittest/CodeGen/SelectionDAGTestBase.h --------------------===// +// +// 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/Analysis/OptimizationRemarkEmitter.h" +#include "llvm/Analysis/TargetTransformInfo.h" +#include "llvm/AsmParser/Parser.h" +#include "llvm/CodeGen/MachineModuleInfo.h" +#include "llvm/CodeGen/TargetLowering.h" +#include "llvm/IR/Module.h" +#include "llvm/MC/TargetRegistry.h" +#include "llvm/Support/SourceMgr.h" +#include "llvm/Support/TargetSelect.h" +#include "llvm/Target/TargetMachine.h" +#include "gtest/gtest.h" + +using namespace llvm; + +class SelectionDAGTestBase : public testing::Test { +protected: + static void SetUpTestCase() { + InitializeAllTargets(); + InitializeAllTargetMCs(); + } + + void SetUp() override { + StringRef Assembly = "@g = global i32 0\n" + "@g_alias = alias i32, i32* @g\n" + "define i32 @f() {\n" + " %1 = load i32, i32* @g\n" + " ret i32 %1\n" + "}"; + + Triple TargetTriple("aarch64--"); + std::string Error; + const Target *T = TargetRegistry::lookupTarget("", TargetTriple, Error); + // FIXME: These tests do not depend on AArch64 specifically, but we have to + // initialize a target. A skeleton Target for unittests would allow us to + // always run these tests. + if (!T) + GTEST_SKIP(); + + TargetOptions Options; + TM = std::unique_ptr<TargetMachine>( + T->createTargetMachine(TargetTriple, "", "+sve", Options, std::nullopt, + std::nullopt, CodeGenOptLevel::Aggressive)); + if (!TM) + GTEST_SKIP(); + + SMDiagnostic SMError; + M = parseAssemblyString(Assembly, SMError, Context); + ASSERT_TRUE(M && "Could not parse module!"); + M->setDataLayout(TM->createDataLayout()); + + F = M->getFunction("f"); + ASSERT_TRUE(F && "Could not get function f!"); + G = M->getGlobalVariable("g"); + ASSERT_TRUE(G && "Could not get global g!"); + AliasedG = M->getNamedAlias("g_alias"); + ASSERT_TRUE(AliasedG && "Could not get alias g_alias!"); + + MachineModuleInfo MMI(TM.get()); + + MF = std::make_unique<MachineFunction>(*F, *TM, *TM->getSubtargetImpl(*F), + MMI.getContext(), 0); + + DAG = std::make_unique<SelectionDAG>(*TM, CodeGenOptLevel::None); + if (!DAG) + reportFatalUsageError("Failed to create SelectionDAG?"); + OptimizationRemarkEmitter ORE(F); + FunctionAnalysisManager FAM; + FAM.registerPass([&] { return TM->getTargetIRAnalysis(); }); + + TargetTransformInfo TTI = TM->getTargetIRAnalysis().run(*F, FAM); + DAG->init(*MF, ORE, nullptr, nullptr, nullptr, nullptr, nullptr, MMI, + nullptr, TTI.hasBranchDivergence(F)); + } + + TargetLoweringBase::LegalizeTypeAction getTypeAction(EVT VT) { + return DAG->getTargetLoweringInfo().getTypeAction(Context, VT); + } + + EVT getTypeToTransformTo(EVT VT) { + return DAG->getTargetLoweringInfo().getTypeToTransformTo(Context, VT); + } + + LLVMContext Context; + std::unique_ptr<TargetMachine> TM; + std::unique_ptr<Module> M; + Function *F; + GlobalVariable *G; + GlobalAlias *AliasedG; + std::unique_ptr<MachineFunction> MF; + std::unique_ptr<SelectionDAG> DAG; +}; diff --git a/llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp b/llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp index 4a05a29..ec94083 100644 --- a/llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp +++ b/llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp @@ -1559,16 +1559,11 @@ TEST_F(CoreAPIsStandardTest, TestLookupWithThreadedMaterialization) { #if LLVM_ENABLE_THREADS std::mutex WorkThreadsMutex; - std::vector<std::thread> WorkThreads; + SmallVector<std::thread, 0> WorkThreads; DispatchOverride = [&](std::unique_ptr<Task> T) { - std::promise<void> WaitP; std::lock_guard<std::mutex> Lock(WorkThreadsMutex); WorkThreads.push_back( - std::thread([T = std::move(T), WaitF = WaitP.get_future()]() mutable { - WaitF.get(); - T->run(); - })); - WaitP.set_value(); + std::thread([T = std::move(T)]() mutable { T->run(); })); }; cantFail(JD.define(absoluteSymbols({{Foo, FooSym}}))); @@ -1580,8 +1575,15 @@ TEST_F(CoreAPIsStandardTest, TestLookupWithThreadedMaterialization) { EXPECT_EQ(FooLookupResult.getFlags(), FooSym.getFlags()) << "lookup returned incorrect flags"; - for (auto &WT : WorkThreads) + std::unique_lock<std::mutex> Lock(WorkThreadsMutex); + // This works because every child thread that is allowed to use WorkThreads + // must either be in WorkThreads or its parent must be in WorkThreads. + while (!WorkThreads.empty()) { + auto WT = WorkThreads.pop_back_val(); + Lock.unlock(); WT.join(); + Lock.lock(); + } #endif } diff --git a/llvm/unittests/Frontend/OpenMPDecompositionTest.cpp b/llvm/unittests/Frontend/OpenMPDecompositionTest.cpp index 6189d09..95c26b1 100644 --- a/llvm/unittests/Frontend/OpenMPDecompositionTest.cpp +++ b/llvm/unittests/Frontend/OpenMPDecompositionTest.cpp @@ -431,8 +431,8 @@ TEST_F(OpenMPDecompositionTest, Firstprivate3) { std::string Dir0 = stringify(Dec.output[0]); std::string Dir1 = stringify(Dec.output[1]); std::string Dir2 = stringify(Dec.output[2]); - ASSERT_EQ(Dir0, "target map(2, , , , (x))"); // (12), (27) - ASSERT_EQ(Dir1, "teams shared(x)"); // (6), (17) + ASSERT_EQ(Dir0, "target map(2, , , , , (x))"); // (12), (27) + ASSERT_EQ(Dir1, "teams shared(x)"); // (6), (17) ASSERT_EQ(Dir2, "distribute firstprivate(x) lastprivate(, (x))"); // (5), (21) } @@ -574,9 +574,9 @@ TEST_F(OpenMPDecompositionTest, Lastprivate3) { std::string Dir0 = stringify(Dec.output[0]); std::string Dir1 = stringify(Dec.output[1]); std::string Dir2 = stringify(Dec.output[2]); - ASSERT_EQ(Dir0, "target map(2, , , , (x))"); // (21), (27) - ASSERT_EQ(Dir1, "parallel shared(x)"); // (22) - ASSERT_EQ(Dir2, "do lastprivate(, (x))"); // (21) + ASSERT_EQ(Dir0, "target map(2, , , , , (x))"); // (21), (27) + ASSERT_EQ(Dir1, "parallel shared(x)"); // (22) + ASSERT_EQ(Dir2, "do lastprivate(, (x))"); // (21) } // SHARED @@ -984,9 +984,9 @@ TEST_F(OpenMPDecompositionTest, Reduction7) { std::string Dir0 = stringify(Dec.output[0]); std::string Dir1 = stringify(Dec.output[1]); std::string Dir2 = stringify(Dec.output[2]); - ASSERT_EQ(Dir0, "target map(2, , , , (x))"); // (36), (10) - ASSERT_EQ(Dir1, "parallel shared(x)"); // (36), (1), (4) - ASSERT_EQ(Dir2, "do reduction(, (3), (x))"); // (36) + ASSERT_EQ(Dir0, "target map(2, , , , , (x))"); // (36), (10) + ASSERT_EQ(Dir1, "parallel shared(x)"); // (36), (1), (4) + ASSERT_EQ(Dir2, "do reduction(, (3), (x))"); // (36) } // IF diff --git a/llvm/unittests/Support/CMakeLists.txt b/llvm/unittests/Support/CMakeLists.txt index d048e87..868c40b 100644 --- a/llvm/unittests/Support/CMakeLists.txt +++ b/llvm/unittests/Support/CMakeLists.txt @@ -31,6 +31,7 @@ add_llvm_unittest(SupportTests DataExtractorTest.cpp DebugCounterTest.cpp DebugTest.cpp + DebugLogTest.cpp DivisionByConstantTest.cpp DJBTest.cpp EndianStreamTest.cpp diff --git a/llvm/unittests/Support/DebugLogTest.cpp b/llvm/unittests/Support/DebugLogTest.cpp new file mode 100644 index 0000000..0c464c1 --- /dev/null +++ b/llvm/unittests/Support/DebugLogTest.cpp @@ -0,0 +1,139 @@ +//===- llvm/unittest/Support/DebugLogTest.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 +// +//===----------------------------------------------------------------------===// + +// This macro is defined in the LLVM build system, but we undefine it here +// so that we test at least once in-tree the case where __SHORT_FILE__ is not +// defined. +#undef __SHORT_FILE__ + +#include "llvm/Support/DebugLog.h" +#include "llvm/ADT/Sequence.h" +#include "llvm/Support/raw_ostream.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include <string> +using namespace llvm; +using testing::Eq; +using testing::HasSubstr; + +#ifndef NDEBUG +TEST(DebugLogTest, Basic) { + llvm::DebugFlag = true; + static const char *DT[] = {"A", "B"}; + + // Clear debug types. + setCurrentDebugTypes(DT, 0); + { + std::string str; + raw_string_ostream os(str); + DEBUGLOG_WITH_STREAM_AND_TYPE(os, 0, nullptr) << "NoType"; + EXPECT_FALSE(StringRef(os.str()).starts_with('[')); + EXPECT_TRUE(StringRef(os.str()).ends_with("NoType\n")); + } + + setCurrentDebugTypes(DT, 2); + { + std::string str; + raw_string_ostream os(str); + DEBUGLOG_WITH_STREAM_AND_TYPE(os, 0, "A") << "A"; + DEBUGLOG_WITH_STREAM_AND_TYPE(os, 0, "B") << "B"; + EXPECT_TRUE(StringRef(os.str()).starts_with('[')); + EXPECT_THAT(os.str(), AllOf(HasSubstr("A\n"), HasSubstr("B\n"))); + } + + setCurrentDebugType("A"); + { + std::string str; + raw_string_ostream os(str); + // Just check that the macro doesn't result in dangling else. + if (true) + DEBUGLOG_WITH_STREAM_AND_TYPE(os, 0, "A") << "A"; + else + DEBUGLOG_WITH_STREAM_AND_TYPE(os, 0, "A") << "B"; + DEBUGLOG_WITH_STREAM_AND_TYPE(os, 0, "B") << "B"; + EXPECT_THAT(os.str(), AllOf(HasSubstr("A\n"), Not(HasSubstr("B\n")))); + + int count = 0; + auto inc = [&]() { return ++count; }; + EXPECT_THAT(count, Eq(0)); + DEBUGLOG_WITH_STREAM_AND_TYPE(os, 0, "A") << inc(); + EXPECT_THAT(count, Eq(1)); + DEBUGLOG_WITH_STREAM_AND_TYPE(os, 0, "B") << inc(); + EXPECT_THAT(count, Eq(1)); + } +} + +TEST(DebugLogTest, BasicWithLevel) { + llvm::DebugFlag = true; + // We expect A to be always printed, B to be printed only when level is 1 or + // below, and C to be printed only when level is 0 or below. + static const char *DT[] = {"A", "B:1", "C:"}; + + setCurrentDebugTypes(DT, sizeof(DT) / sizeof(DT[0])); + std::string str; + raw_string_ostream os(str); + for (auto type : {"A", "B", "C", "D"}) + for (int level : llvm::seq<int>(0, 4)) + DEBUGLOG_WITH_STREAM_TYPE_FILE_AND_LINE(os, level, type, type, level) + << level; + EXPECT_EQ(os.str(), "[A:0] A:0 0\n[A:1] A:1 1\n[A:2] A:2 2\n[A:3] A:3 " + "3\n[B:0] B:0 0\n[B:1] B:1 1\n[C:0] C:0 0\n"); +} + +TEST(DebugLogTest, NegativeLevel) { + llvm::DebugFlag = true; + // Test the special behavior when all the levels are 0. + // In this case we expect all the debug types to be printed. + static const char *DT[] = {"A:"}; + + setCurrentDebugTypes(DT, sizeof(DT) / sizeof(DT[0])); + std::string str; + raw_string_ostream os(str); + for (auto type : {"A", "B"}) + for (int level : llvm::seq<int>(0, 2)) + DEBUGLOG_WITH_STREAM_TYPE_FILE_AND_LINE(os, level, type, type, level) + << level; + EXPECT_EQ(os.str(), "[A:0] A:0 0\n[B:0] B:0 0\n[B:1] B:1 1\n"); +} + +TEST(DebugLogTest, StreamPrefix) { + llvm::DebugFlag = true; + static const char *DT[] = {"A", "B"}; + setCurrentDebugTypes(DT, 2); + + std::string str; + raw_string_ostream os(str); + std::string expected = "PrefixA 1\nPrefixA 2\nPrefixA \nPrefixB " + "3\nPrefixB 4\nPrefixA 5"; + { + llvm::impl::raw_ldbg_ostream ldbg_osB("PrefixB ", os); + llvm::impl::raw_ldbg_ostream ldbg_osA("PrefixA ", os); + ldbg_osA << "1\n2"; + ldbg_osA << "\n\n"; + ldbg_osB << "3\n4\n"; + ldbg_osA << "5"; + EXPECT_EQ(os.str(), expected); + } + // After destructors, there was a pending newline for stream B. + EXPECT_EQ(os.str(), expected + "\nPrefixB \n"); +} +#else +TEST(DebugLogTest, Basic) { + // LDBG should be compiled out in NDEBUG, so just check it compiles and has + // no effect. + llvm::DebugFlag = true; + static const char *DT[] = {"A"}; + setCurrentDebugTypes(DT, 0); + int count = 0; + auto inc = [&]() { return ++count; }; + EXPECT_THAT(count, Eq(0)); + LDBG() << inc(); + EXPECT_THAT(count, Eq(0)); +} +#endif diff --git a/llvm/unittests/TargetParser/TripleTest.cpp b/llvm/unittests/TargetParser/TripleTest.cpp index 36408de..35927e3 100644 --- a/llvm/unittests/TargetParser/TripleTest.cpp +++ b/llvm/unittests/TargetParser/TripleTest.cpp @@ -758,6 +758,12 @@ TEST(TripleTest, ParsedIDs) { EXPECT_EQ(Triple::UnknownOS, T.getOS()); EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment()); + T = Triple("riscv64-meta-unknown-mtia"); + EXPECT_EQ(Triple::riscv64, T.getArch()); + EXPECT_EQ(Triple::Meta, T.getVendor()); + EXPECT_EQ(Triple::UnknownOS, T.getOS()); + EXPECT_EQ(Triple::MTIA, T.getEnvironment()); + T = Triple("riscv64-unknown-linux"); EXPECT_EQ(Triple::riscv64, T.getArch()); EXPECT_EQ(Triple::UnknownVendor, T.getVendor()); diff --git a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp index 8012d9e..94b74d2 100644 --- a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp +++ b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp @@ -1075,7 +1075,7 @@ TEST_F(VPRecipeTest, CastVPBlendRecipeToVPUser) { Args.push_back(I1); Args.push_back(I2); Args.push_back(M2); - VPBlendRecipe Recipe(Phi, Args); + VPBlendRecipe Recipe(Phi, Args, {}); EXPECT_TRUE(isa<VPUser>(&Recipe)); VPRecipeBase *BaseR = &Recipe; EXPECT_TRUE(isa<VPUser>(BaseR)); diff --git a/llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp b/llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp index 5394472..6214ea3 100644 --- a/llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp +++ b/llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp @@ -103,7 +103,7 @@ TEST_F(VPVerifierTest, VPBlendUseBeforeDefDifferentBB) { auto *CanIV = new VPCanonicalIVPHIRecipe(Zero, {}); VPInstruction *BranchOnCond = new VPInstruction(VPInstruction::BranchOnCond, {CanIV}); - auto *Blend = new VPBlendRecipe(Phi, {DefI}); + auto *Blend = new VPBlendRecipe(Phi, {DefI}, {}); VPBasicBlock *VPBB1 = Plan.getEntry(); VPBasicBlock *VPBB2 = Plan.createVPBasicBlock(""); |