1 //===------------------------------------------------------------*- C++ -*-===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "GISelMITest.h" 10 11 namespace llvm { 12 std::ostream & 13 operator<<(std::ostream &OS, const LLT Ty) { 14 std::string Repr; 15 raw_string_ostream SS{Repr}; 16 Ty.print(SS); 17 OS << Repr; 18 return OS; 19 } 20 21 std::ostream & 22 operator<<(std::ostream &OS, const MachineFunction &MF) { 23 std::string Repr; 24 raw_string_ostream SS{Repr}; 25 MF.print(SS); 26 OS << Repr; 27 return OS; 28 } 29 30 } 31 32 std::unique_ptr<TargetMachine> AArch64GISelMITest::createTargetMachine() const { 33 Triple TargetTriple("aarch64--"); 34 std::string Error; 35 const Target *T = TargetRegistry::lookupTarget("", TargetTriple, Error); 36 if (!T) 37 return nullptr; 38 39 TargetOptions Options; 40 return std::unique_ptr<TargetMachine>( 41 T->createTargetMachine("AArch64", "", "", Options, std::nullopt, 42 std::nullopt, CodeGenOptLevel::Aggressive)); 43 } 44 45 void AArch64GISelMITest::getTargetTestModuleString(SmallString<512> &S, 46 StringRef MIRFunc) const { 47 (Twine(R"MIR( 48 --- 49 ... 50 name: func 51 tracksRegLiveness: true 52 registers: 53 - { id: 0, class: _ } 54 - { id: 1, class: _ } 55 - { id: 2, class: _ } 56 - { id: 3, class: _ } 57 body: | 58 bb.1: 59 liveins: $x0, $x1, $x2, $x4 60 61 %0(s64) = COPY $x0 62 %1(s64) = COPY $x1 63 %2(s64) = COPY $x2 64 )MIR") + 65 Twine(MIRFunc) + Twine("...\n")) 66 .toNullTerminatedStringRef(S); 67 } 68 69 std::unique_ptr<TargetMachine> AMDGPUGISelMITest::createTargetMachine() const { 70 Triple TargetTriple("amdgcn-amd-amdhsa"); 71 std::string Error; 72 const Target *T = TargetRegistry::lookupTarget("", TargetTriple, Error); 73 if (!T) 74 return nullptr; 75 76 TargetOptions Options; 77 return std::unique_ptr<TargetMachine>(T->createTargetMachine( 78 "amdgcn-amd-amdhsa", "gfx900", "", Options, std::nullopt, std::nullopt, 79 CodeGenOptLevel::Aggressive)); 80 } 81 82 void AMDGPUGISelMITest::getTargetTestModuleString( 83 SmallString<512> &S, StringRef MIRFunc) const { 84 (Twine(R"MIR( 85 --- 86 ... 87 name: func 88 tracksRegLiveness: true 89 registers: 90 - { id: 0, class: _ } 91 - { id: 1, class: _ } 92 - { id: 2, class: _ } 93 - { id: 3, class: _ } 94 body: | 95 bb.1: 96 liveins: $vgpr0, $vgpr1, $vgpr2 97 98 %0(s32) = COPY $vgpr0 99 %1(s32) = COPY $vgpr1 100 %2(s32) = COPY $vgpr2 101 )MIR") + Twine(MIRFunc) + Twine("...\n")) 102 .toNullTerminatedStringRef(S); 103 } 104