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