11c3f7f17SFangrui Song //===- X86RegisterBankInfo ---------------------------------------*- C++ -*-==// 21c3f7f17SFangrui Song // 31c3f7f17SFangrui Song // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 41c3f7f17SFangrui Song // See https://llvm.org/LICENSE.txt for license information. 51c3f7f17SFangrui Song // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 61c3f7f17SFangrui Song // 71c3f7f17SFangrui Song //===----------------------------------------------------------------------===// 81c3f7f17SFangrui Song /// \file 91c3f7f17SFangrui Song /// This file declares the targeting of the RegisterBankInfo class for X86. 101c3f7f17SFangrui Song /// \todo This should be generated by TableGen. 111c3f7f17SFangrui Song //===----------------------------------------------------------------------===// 121c3f7f17SFangrui Song 131c3f7f17SFangrui Song #ifndef LLVM_LIB_TARGET_X86_X86REGISTERBANKINFO_H 141c3f7f17SFangrui Song #define LLVM_LIB_TARGET_X86_X86REGISTERBANKINFO_H 151c3f7f17SFangrui Song 161c3f7f17SFangrui Song #include "llvm/CodeGen/RegisterBankInfo.h" 171c3f7f17SFangrui Song 181c3f7f17SFangrui Song #define GET_REGBANK_DECLARATIONS 191c3f7f17SFangrui Song #include "X86GenRegisterBank.inc" 201c3f7f17SFangrui Song 211c3f7f17SFangrui Song namespace llvm { 221c3f7f17SFangrui Song 231c3f7f17SFangrui Song class LLT; 241c3f7f17SFangrui Song 251c3f7f17SFangrui Song class X86GenRegisterBankInfo : public RegisterBankInfo { 261c3f7f17SFangrui Song protected: 271c3f7f17SFangrui Song #define GET_TARGET_REGBANK_CLASS 281c3f7f17SFangrui Song #include "X86GenRegisterBank.inc" 291c3f7f17SFangrui Song #define GET_TARGET_REGBANK_INFO_CLASS 301c3f7f17SFangrui Song #include "X86GenRegisterBankInfo.def" 311c3f7f17SFangrui Song 321c3f7f17SFangrui Song static RegisterBankInfo::PartialMapping PartMappings[]; 331c3f7f17SFangrui Song static RegisterBankInfo::ValueMapping ValMappings[]; 341c3f7f17SFangrui Song 35564b81dbSMalaySanghiIntel static PartialMappingIdx getPartialMappingIdx(const MachineInstr &MI, 36564b81dbSMalaySanghiIntel const LLT &Ty, bool isFP); 371c3f7f17SFangrui Song static const RegisterBankInfo::ValueMapping * 381c3f7f17SFangrui Song getValueMapping(PartialMappingIdx Idx, unsigned NumOperands); 391c3f7f17SFangrui Song }; 401c3f7f17SFangrui Song 411c3f7f17SFangrui Song class TargetRegisterInfo; 421c3f7f17SFangrui Song 431c3f7f17SFangrui Song /// This class provides the information for the target register banks. 441c3f7f17SFangrui Song class X86RegisterBankInfo final : public X86GenRegisterBankInfo { 451c3f7f17SFangrui Song private: 461c3f7f17SFangrui Song /// Get an instruction mapping. 471c3f7f17SFangrui Song /// \return An InstructionMappings with a statically allocated 481c3f7f17SFangrui Song /// OperandsMapping. 491c3f7f17SFangrui Song const InstructionMapping &getSameOperandsMapping(const MachineInstr &MI, 501c3f7f17SFangrui Song bool isFP) const; 511c3f7f17SFangrui Song 521c3f7f17SFangrui Song /// Track the bank of each instruction operand(register) 531c3f7f17SFangrui Song static void 541c3f7f17SFangrui Song getInstrPartialMappingIdxs(const MachineInstr &MI, 551c3f7f17SFangrui Song const MachineRegisterInfo &MRI, const bool isFP, 561c3f7f17SFangrui Song SmallVectorImpl<PartialMappingIdx> &OpRegBankIdx); 571c3f7f17SFangrui Song 581c3f7f17SFangrui Song /// Construct the instruction ValueMapping from PartialMappingIdxs 591c3f7f17SFangrui Song /// \return true if mapping succeeded. 601c3f7f17SFangrui Song static bool 611c3f7f17SFangrui Song getInstrValueMapping(const MachineInstr &MI, 621c3f7f17SFangrui Song const SmallVectorImpl<PartialMappingIdx> &OpRegBankIdx, 631c3f7f17SFangrui Song SmallVectorImpl<const ValueMapping *> &OpdsMapping); 641c3f7f17SFangrui Song 65*92e96c7bSMalay Sanghi // Maximum recursion depth for hasFPConstraints. 66*92e96c7bSMalay Sanghi const unsigned MaxFPRSearchDepth = 2; 67*92e96c7bSMalay Sanghi 68*92e96c7bSMalay Sanghi /// \returns true if \p MI only uses and defines FPRs. 69*92e96c7bSMalay Sanghi bool hasFPConstraints(const MachineInstr &MI, const MachineRegisterInfo &MRI, 70*92e96c7bSMalay Sanghi const TargetRegisterInfo &TRI, 71*92e96c7bSMalay Sanghi unsigned Depth = 0) const; 72*92e96c7bSMalay Sanghi 73*92e96c7bSMalay Sanghi /// \returns true if \p MI only uses FPRs. 74*92e96c7bSMalay Sanghi bool onlyUsesFP(const MachineInstr &MI, const MachineRegisterInfo &MRI, 75*92e96c7bSMalay Sanghi const TargetRegisterInfo &TRI, unsigned Depth = 0) const; 76*92e96c7bSMalay Sanghi 77*92e96c7bSMalay Sanghi /// \returns true if \p MI only defines FPRs. 78*92e96c7bSMalay Sanghi bool onlyDefinesFP(const MachineInstr &MI, const MachineRegisterInfo &MRI, 79*92e96c7bSMalay Sanghi const TargetRegisterInfo &TRI, unsigned Depth = 0) const; 80*92e96c7bSMalay Sanghi 811c3f7f17SFangrui Song public: 821c3f7f17SFangrui Song X86RegisterBankInfo(const TargetRegisterInfo &TRI); 831c3f7f17SFangrui Song 841c3f7f17SFangrui Song InstructionMappings 851c3f7f17SFangrui Song getInstrAlternativeMappings(const MachineInstr &MI) const override; 861c3f7f17SFangrui Song 871c3f7f17SFangrui Song /// See RegisterBankInfo::applyMapping. 881c3f7f17SFangrui Song void applyMappingImpl(MachineIRBuilder &Builder, 891c3f7f17SFangrui Song const OperandsMapper &OpdMapper) const override; 901c3f7f17SFangrui Song 911c3f7f17SFangrui Song const InstructionMapping & 921c3f7f17SFangrui Song getInstrMapping(const MachineInstr &MI) const override; 931c3f7f17SFangrui Song }; 941c3f7f17SFangrui Song 951c3f7f17SFangrui Song } // namespace llvm 961c3f7f17SFangrui Song #endif 97