| 1 |
//===- llvm/unittests/Target/DirectX/RegisterCostTests.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 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
#include "DirectXInstrInfo.h" |
| 10 |
#include "DirectXTargetLowering.h" |
| 11 |
#include "DirectXTargetMachine.h" |
| 12 |
#include "TargetInfo/DirectXTargetInfo.h" |
| 13 |
#include "llvm/IR/DerivedTypes.h" |
| 14 |
#include "llvm/IR/Function.h" |
| 15 |
#include "llvm/MC/MCTargetOptions.h" |
| 16 |
#include "llvm/MC/TargetRegistry.h" |
| 17 |
#include "llvm/Support/TargetSelect.h" |
| 18 |
|
| 19 |
#include "gtest/gtest.h" |
| 20 |
|
| 21 |
using namespace llvm; |
| 22 |
using namespace llvm::dxil; |
| 23 |
|
| 24 |
namespace { |
| 25 |
class RegisterCostTests : public testing::Test { |
| 26 |
protected: |
| 27 |
DirectXInstrInfo DXInstInfo; |
| 28 |
DirectXRegisterInfo RI; |
| 29 |
DirectXTargetLowering *DL; |
| 30 |
|
| 31 |
virtual void SetUp() { |
| 32 |
LLVMInitializeDirectXTargetMC(); |
| 33 |
Target T = getTheDirectXTarget(); |
| 34 |
RegisterTargetMachine<DirectXTargetMachine> X(T); |
| 35 |
Triple TT("dxil-pc-shadermodel6.3-library"); |
| 36 |
StringRef CPU = ""; |
| 37 |
StringRef FS = ""; |
| 38 |
DirectXTargetMachine TM(T, TT, CPU, FS, TargetOptions(), Reloc::Static, |
| 39 |
CodeModel::Small, CodeGenOptLevel::Default, false); |
| 40 |
LLVMContext Context; |
| 41 |
Function *F = |
| 42 |
Function::Create(FunctionType::get(Type::getVoidTy(Context), false), |
| 43 |
Function::ExternalLinkage, 0); |
| 44 |
DL = new DirectXTargetLowering(TM, *TM.getSubtargetImpl(*F)); |
| 45 |
delete F; |
| 46 |
} |
| 47 |
virtual void TearDown() { delete DL; } |
| 48 |
}; |
| 49 |
|
| 50 |
TEST_F(RegisterCostTests, TestRepRegClassForVTSet) { |
| 51 |
const TargetRegisterClass *RC = DL->getRepRegClassFor(MVT::i32); |
| 52 |
EXPECT_EQ(&dxil::DXILClassRegClass, RC); |
| 53 |
} |
| 54 |
|
| 55 |
TEST_F(RegisterCostTests, TestTrivialCopyCostGetter) { |
| 56 |
|
| 57 |
const TargetRegisterClass *RC = DXInstInfo.getRegisterInfo().getRegClass(0); |
| 58 |
unsigned Cost = RC->getCopyCost(); |
| 59 |
EXPECT_EQ(1u, Cost); |
| 60 |
|
| 61 |
RC = RI.getRegClass(0); |
| 62 |
Cost = RC->getCopyCost(); |
| 63 |
EXPECT_EQ(1u, Cost); |
| 64 |
} |
| 65 |
} // namespace |