From edb4f7c12a2606f2949b40cec7ec096745d58ad0 Mon Sep 17 00:00:00 2001 From: Quentin Colombet Date: Wed, 8 Jun 2016 01:11:03 +0000 Subject: [PATCH] [RegisterBankInfo] Add a size argument for the cost of copy. The cost of a copy may be different based on how many bits we have to copy around. E.g., a 8-bit copy may be different than a 32-bit copy. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272084 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h | 10 +++++++--- lib/CodeGen/GlobalISel/RegBankSelect.cpp | 4 +++- lib/Target/AArch64/AArch64RegisterBankInfo.cpp | 3 ++- lib/Target/AArch64/AArch64RegisterBankInfo.h | 10 +++++++--- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h b/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h index 7ab2fa14a4b..cc2c80d186c 100644 --- a/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h +++ b/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h @@ -352,9 +352,13 @@ public: } /// Get the cost of a copy from \p B to \p A, or put differently, - /// get the cost of A = COPY B. - virtual unsigned copyCost(const RegisterBank &A, - const RegisterBank &B) const { + /// get the cost of A = COPY B. Since register banks may cover + /// different size, \p Size specifies what will be the size in bits + /// that will be copied around. + /// + /// \note Since this is a copy, both registers have the same size. + virtual unsigned copyCost(const RegisterBank &A, const RegisterBank &B, + unsigned Size) const { return 0; } diff --git a/lib/CodeGen/GlobalISel/RegBankSelect.cpp b/lib/CodeGen/GlobalISel/RegBankSelect.cpp index fc04f4e8a55..4890d45a6d3 100644 --- a/lib/CodeGen/GlobalISel/RegBankSelect.cpp +++ b/lib/CodeGen/GlobalISel/RegBankSelect.cpp @@ -163,7 +163,9 @@ uint64_t RegBankSelect::getRepairCost( // the repairing. if (MO.isDef()) std::swap(CurRegBank, DesiredRegBrank); - unsigned Cost = RBI->copyCost(*DesiredRegBrank, *CurRegBank); + unsigned Cost = + RBI->copyCost(*DesiredRegBrank, *CurRegBank, + RegisterBankInfo::getSizeInBits(MO.getReg(), *MRI, *TRI)); // TODO: use a dedicated constant for ImpossibleCost. if (Cost != UINT_MAX) return Cost; diff --git a/lib/Target/AArch64/AArch64RegisterBankInfo.cpp b/lib/Target/AArch64/AArch64RegisterBankInfo.cpp index a877b79c078..72097a9bbd8 100644 --- a/lib/Target/AArch64/AArch64RegisterBankInfo.cpp +++ b/lib/Target/AArch64/AArch64RegisterBankInfo.cpp @@ -64,7 +64,8 @@ AArch64RegisterBankInfo::AArch64RegisterBankInfo(const TargetRegisterInfo &TRI) } unsigned AArch64RegisterBankInfo::copyCost(const RegisterBank &A, - const RegisterBank &B) const { + const RegisterBank &B, + unsigned Size) const { // What do we do with different size? // copy are same size. // Will introduce other hooks for different size: diff --git a/lib/Target/AArch64/AArch64RegisterBankInfo.h b/lib/Target/AArch64/AArch64RegisterBankInfo.h index 156f9a0b7d5..69a21ec82cf 100644 --- a/lib/Target/AArch64/AArch64RegisterBankInfo.h +++ b/lib/Target/AArch64/AArch64RegisterBankInfo.h @@ -34,9 +34,13 @@ class AArch64RegisterBankInfo : public RegisterBankInfo { public: AArch64RegisterBankInfo(const TargetRegisterInfo &TRI); /// Get the cost of a copy from \p B to \p A, or put differently, - /// get the cost of A = COPY B. - unsigned copyCost(const RegisterBank &A, - const RegisterBank &B) const override; + /// get the cost of A = COPY B. Since register banks may cover + /// different size, \p Size specifies what will be the size in bits + /// that will be copied around. + /// + /// \note Since this is a copy, both registers have the same size. + unsigned copyCost(const RegisterBank &A, const RegisterBank &B, + unsigned Size) const override; /// Get a register bank that covers \p RC. /// -- 2.11.0