From c7dac04c3480f3c20487f912f77343139fce2d99 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sun, 24 Dec 2017 01:00:08 +0000 Subject: Vendor import of llvm trunk r321414: https://llvm.org/svn/llvm-project/llvm/trunk@321414 --- unittests/CodeGen/MachineOperandTest.cpp | 63 ++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'unittests/CodeGen/MachineOperandTest.cpp') diff --git a/unittests/CodeGen/MachineOperandTest.cpp b/unittests/CodeGen/MachineOperandTest.cpp index e51207b95716..78a20b836486 100644 --- a/unittests/CodeGen/MachineOperandTest.cpp +++ b/unittests/CodeGen/MachineOperandTest.cpp @@ -10,6 +10,7 @@ #include "llvm/CodeGen/MachineOperand.h" #include "llvm/ADT/ilist_node.h" #include "llvm/IR/Constants.h" +#include "llvm/IR/InstrTypes.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" #include "llvm/IR/ModuleSlotTracker.h" @@ -336,4 +337,66 @@ TEST(MachineOperandTest, PrintMCSymbol) { ASSERT_TRUE(OS.str() == ""); } +TEST(MachineOperandTest, PrintCFI) { + // Create a MachineOperand with a CFI index but no function and print it. + MachineOperand MO = MachineOperand::CreateCFIIndex(8); + + // Checking some preconditions on the newly created + // MachineOperand. + ASSERT_TRUE(MO.isCFIIndex()); + ASSERT_TRUE(MO.getCFIIndex() == 8); + + std::string str; + // Print a MachineOperand containing a CFI Index node but no machine function + // attached to it. + raw_string_ostream OS(str); + MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr); + ASSERT_TRUE(OS.str() == ""); +} + +TEST(MachineOperandTest, PrintIntrinsicID) { + // Create a MachineOperand with a generic intrinsic ID. + MachineOperand MO = MachineOperand::CreateIntrinsicID(Intrinsic::bswap); + + // Checking some preconditions on the newly created + // MachineOperand. + ASSERT_TRUE(MO.isIntrinsicID()); + ASSERT_TRUE(MO.getIntrinsicID() == Intrinsic::bswap); + + std::string str; + { + // Print a MachineOperand containing a generic intrinsic ID. + raw_string_ostream OS(str); + MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr); + ASSERT_TRUE(OS.str() == "intrinsic(@llvm.bswap)"); + } + + str.clear(); + // Set a target-specific intrinsic. + MO = MachineOperand::CreateIntrinsicID((Intrinsic::ID)-1); + { + // Print a MachineOperand containing a target-specific intrinsic ID but not + // IntrinsicInfo. + raw_string_ostream OS(str); + MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr); + ASSERT_TRUE(OS.str() == "intrinsic(4294967295)"); + } +} + +TEST(MachineOperandTest, PrintPredicate) { + // Create a MachineOperand with a generic intrinsic ID. + MachineOperand MO = MachineOperand::CreatePredicate(CmpInst::ICMP_EQ); + + // Checking some preconditions on the newly created + // MachineOperand. + ASSERT_TRUE(MO.isPredicate()); + ASSERT_TRUE(MO.getPredicate() == CmpInst::ICMP_EQ); + + std::string str; + // Print a MachineOperand containing a int predicate ICMP_EQ. + raw_string_ostream OS(str); + MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr); + ASSERT_TRUE(OS.str() == "intpred(eq)"); +} + } // end namespace -- cgit v1.2.3