comparison unittests/CodeGen/MachineInstrTest.cpp @ 134:3a76565eade5 LLVM5.0.1

update 5.0.1
author mir3636
date Sat, 17 Feb 2018 09:57:20 +0900
parents 803732b1fca8
children c2174574ed3a
comparison
equal deleted inserted replaced
133:c60214abe0e8 134:3a76565eade5
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 9
10 #include "llvm/CodeGen/MachineInstr.h" 10 #include "llvm/CodeGen/MachineInstr.h"
11 #include "llvm/CodeGen/MachineFunction.h" 11 #include "llvm/CodeGen/MachineFunction.h"
12 #include "llvm/CodeGen/MachineModuleInfo.h" 12 #include "llvm/CodeGen/MachineModuleInfo.h"
13 #include "llvm/CodeGen/TargetFrameLowering.h"
14 #include "llvm/CodeGen/TargetInstrInfo.h"
15 #include "llvm/CodeGen/TargetLowering.h"
16 #include "llvm/CodeGen/TargetSubtargetInfo.h"
17 #include "llvm/IR/DebugInfoMetadata.h"
18 #include "llvm/IR/ModuleSlotTracker.h"
13 #include "llvm/Support/TargetRegistry.h" 19 #include "llvm/Support/TargetRegistry.h"
14 #include "llvm/Support/TargetSelect.h" 20 #include "llvm/Support/TargetSelect.h"
15 #include "llvm/Target/TargetFrameLowering.h"
16 #include "llvm/Target/TargetInstrInfo.h"
17 #include "llvm/Target/TargetLowering.h"
18 #include "llvm/Target/TargetMachine.h" 21 #include "llvm/Target/TargetMachine.h"
19 #include "llvm/Target/TargetOptions.h" 22 #include "llvm/Target/TargetOptions.h"
20 #include "llvm/Target/TargetSubtargetInfo.h"
21 #include "gtest/gtest.h" 23 #include "gtest/gtest.h"
22 24
23 using namespace llvm; 25 using namespace llvm;
24 26
25 namespace { 27 namespace {
89 auto F = Function::Create(Type, GlobalValue::ExternalLinkage, "Test", &M); 91 auto F = Function::Create(Type, GlobalValue::ExternalLinkage, "Test", &M);
90 92
91 auto TM = createTargetMachine(); 93 auto TM = createTargetMachine();
92 unsigned FunctionNum = 42; 94 unsigned FunctionNum = 42;
93 MachineModuleInfo MMI(TM.get()); 95 MachineModuleInfo MMI(TM.get());
94 96 const TargetSubtargetInfo &STI = *TM->getSubtargetImpl(*F);
95 return llvm::make_unique<MachineFunction>(F, *TM, FunctionNum, MMI); 97
98 return llvm::make_unique<MachineFunction>(*F, *TM, STI, FunctionNum, MMI);
96 } 99 }
97 100
98 // This test makes sure that MachineInstr::isIdenticalTo handles Defs correctly 101 // This test makes sure that MachineInstr::isIdenticalTo handles Defs correctly
99 // for various combinations of IgnoreDefs, and also that it is symmetrical. 102 // for various combinations of IgnoreDefs, and also that it is symmetrical.
100 TEST(IsIdenticalToTest, DifferentDefs) { 103 TEST(IsIdenticalToTest, DifferentDefs) {
241 checkHashAndIsEqualMatch(VD1SD, VD2PU); 244 checkHashAndIsEqualMatch(VD1SD, VD2PU);
242 checkHashAndIsEqualMatch(VD1SD, VD2PD); 245 checkHashAndIsEqualMatch(VD1SD, VD2PD);
243 246
244 checkHashAndIsEqualMatch(VD2PU, VD2PD); 247 checkHashAndIsEqualMatch(VD2PU, VD2PD);
245 } 248 }
249
250 TEST(MachineInstrPrintingTest, DebugLocPrinting) {
251 auto MF = createMachineFunction();
252
253 MCOperandInfo OpInfo{0, 0, MCOI::OPERAND_REGISTER, 0};
254 MCInstrDesc MCID = {0, 1, 1, 0, 0, 0,
255 0, nullptr, nullptr, &OpInfo, 0, nullptr};
256
257 LLVMContext Ctx;
258 DILocation *DIL = DILocation::get(Ctx, 1, 5, (Metadata *)nullptr, nullptr);
259 DebugLoc DL(DIL);
260 MachineInstr *MI = MF->CreateMachineInstr(MCID, DL);
261 MI->addOperand(*MF, MachineOperand::CreateReg(0, /*isDef*/ true));
262
263 std::string str;
264 raw_string_ostream OS(str);
265 MI->print(OS);
266 ASSERT_TRUE(
267 StringRef(OS.str()).startswith("$noreg = UNKNOWN debug-location "));
268 }
269
246 } // end namespace 270 } // end namespace