diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2017-12-24 01:00:08 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2017-12-24 01:00:08 +0000 | 
| commit | c7dac04c3480f3c20487f912f77343139fce2d99 (patch) | |
| tree | 21a09bce0171e27bd1e92649db9df797fa097cea /unittests/CodeGen/MachineOperandTest.cpp | |
| parent | 044eb2f6afba375a914ac9d8024f8f5142bb912e (diff) | |
Notes
Diffstat (limited to 'unittests/CodeGen/MachineOperandTest.cpp')
| -rw-r--r-- | unittests/CodeGen/MachineOperandTest.cpp | 63 | 
1 files changed, 63 insertions, 0 deletions
| diff --git a/unittests/CodeGen/MachineOperandTest.cpp b/unittests/CodeGen/MachineOperandTest.cpp index e51207b957168..78a20b836486d 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() == "<mcsymbol foo>");  } +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() == "<cfi directive>"); +} + +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 | 
