[Clang][MIPS] Send correct architecture for MinGW toolchains (#121042)
[llvm-project.git] / llvm / unittests / Target / AMDGPU / ExecMayBeModifiedBeforeAnyUse.cpp
blob5ac4edae5f0dfaee04887e0b7daee0705e9e333d
1 //===- llvm/unittests/Target/AMDGPU/ExecMayBeModifiedBeforeAnyUse.cpp -----===//
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 //===----------------------------------------------------------------------===//
9 #include "AMDGPUTargetMachine.h"
10 #include "AMDGPUUnitTests.h"
11 #include "llvm/CodeGen/MachineModuleInfo.h"
12 #include "gtest/gtest.h"
14 using namespace llvm;
16 TEST(AMDGPU, ExecMayBeModifiedBeforeAnyUse) {
17 auto TM = createAMDGPUTargetMachine("amdgcn-amd-", "gfx906", "");
18 if (!TM)
19 GTEST_SKIP();
21 GCNSubtarget ST(TM->getTargetTriple(), std::string(TM->getTargetCPU()),
22 std::string(TM->getTargetFeatureString()), *TM);
24 LLVMContext Ctx;
25 Module Mod("Module", Ctx);
26 Mod.setDataLayout(TM->createDataLayout());
28 auto *Type = FunctionType::get(Type::getVoidTy(Ctx), false);
29 auto *F = Function::Create(Type, GlobalValue::ExternalLinkage, "Test", &Mod);
31 MachineModuleInfo MMI(TM.get());
32 auto MF =
33 std::make_unique<MachineFunction>(*F, *TM, ST, MMI.getContext(), 42);
34 auto *BB = MF->CreateMachineBasicBlock();
35 MF->push_back(BB);
37 auto E = BB->end();
38 DebugLoc DL;
39 const auto &TII = *ST.getInstrInfo();
40 auto &MRI = MF->getRegInfo();
42 // create machine IR
43 Register R = MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
45 MachineInstr *DefMI =
46 BuildMI(*BB, E, DL, TII.get(AMDGPU::S_MOV_B32), R).addImm(42).getInstr();
48 auto First =
49 BuildMI(*BB, E, DL, TII.get(AMDGPU::S_NOP)).addReg(R, RegState::Implicit);
51 BuildMI(*BB, E, DL, TII.get(AMDGPU::S_NOP)).addReg(R, RegState::Implicit);
53 // this violates the continuous sequence of R's uses for the first S_NOP
54 First.addReg(R, RegState::Implicit);
56 #ifdef DEBUG_THIS_TEST
57 MF->dump();
58 MRI.dumpUses(R);
59 #endif
61 // make sure execMayBeModifiedBeforeAnyUse doesn't crash
62 ASSERT_FALSE(execMayBeModifiedBeforeAnyUse(MRI, R, *DefMI));