Skip to content

[DirectX] initialize registers properties by calling addRegisterClass and computeRegisterProperties #128818

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion llvm/lib/Target/DirectX/DirectXTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,7 @@ DirectXTargetMachine::getTargetTransformInfo(const Function &F) const {

DirectXTargetLowering::DirectXTargetLowering(const DirectXTargetMachine &TM,
const DirectXSubtarget &STI)
: TargetLowering(TM) {}
: TargetLowering(TM) {
addRegisterClass(MVT::i32, &dxil::DXILClassRegClass);
computeRegisterProperties(STI.getRegisterInfo());
}
1 change: 1 addition & 0 deletions llvm/unittests/Target/DirectX/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ add_llvm_target_unittest(DirectXTests
CBufferDataLayoutTests.cpp
PointerTypeAnalysisTests.cpp
UniqueResourceFromUseTests.cpp
RegisterCostTests.cpp
)
65 changes: 65 additions & 0 deletions llvm/unittests/Target/DirectX/RegisterCostTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//===- llvm/unittests/Target/DirectX/RegisterCostTests.cpp ----------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "DirectXInstrInfo.h"
#include "DirectXTargetLowering.h"
#include "DirectXTargetMachine.h"
#include "TargetInfo/DirectXTargetInfo.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/MC/MCTargetOptions.h"
#include "llvm/MC/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"

#include "gtest/gtest.h"

using namespace llvm;
using namespace llvm::dxil;

namespace {
class RegisterCostTests : public testing::Test {
protected:
DirectXInstrInfo DXInstInfo;
DirectXRegisterInfo RI;
DirectXTargetLowering *DL;

virtual void SetUp() {
LLVMInitializeDirectXTargetMC();
Target T = getTheDirectXTarget();
RegisterTargetMachine<DirectXTargetMachine> X(T);
Triple TT("dxil-pc-shadermodel6.3-library");
StringRef CPU = "";
StringRef FS = "";
DirectXTargetMachine TM(T, TT, CPU, FS, TargetOptions(), Reloc::Static,
CodeModel::Small, CodeGenOptLevel::Default, false);
LLVMContext Context;
Function *F =
Function::Create(FunctionType::get(Type::getVoidTy(Context), false),
Function::ExternalLinkage, 0);
DL = new DirectXTargetLowering(TM, *TM.getSubtargetImpl(*F));
delete F;
}
virtual void TearDown() { delete DL; }
};

TEST_F(RegisterCostTests, TestRepRegClassForVTSet) {
const TargetRegisterClass *RC = DL->getRepRegClassFor(MVT::i32);
EXPECT_EQ(&dxil::DXILClassRegClass, RC);
}

TEST_F(RegisterCostTests, TestTrivialCopyCostGetter) {

const TargetRegisterClass *RC = DXInstInfo.getRegisterInfo().getRegClass(0);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DirectXTargetLowering does not expose DirectXRegisterInfo so just testing it seperately to confirm we can fetch costing data off of it.

unsigned Cost = RC->getCopyCost();
EXPECT_EQ(1u, Cost);

RC = RI.getRegClass(0);
Cost = RC->getCopyCost();
EXPECT_EQ(1u, Cost);
}
} // namespace
Loading