1212
1313#include " X86RegisterBankInfo.h"
1414#include " X86InstrInfo.h"
15+ #include " X86Subtarget.h"
1516#include " llvm/CodeGen/MachineRegisterInfo.h"
1617#include " llvm/CodeGen/RegisterBank.h"
1718#include " llvm/CodeGen/RegisterBankInfo.h"
@@ -59,11 +60,24 @@ X86RegisterBankInfo::getRegBankFromRegClass(const TargetRegisterClass &RC,
5960 X86::VR512RegClass.hasSubClassEq (&RC))
6061 return getRegBank (X86::VECRRegBankID);
6162
63+ if (X86::RFP80RegClass.hasSubClassEq (&RC) ||
64+ X86::RFP32RegClass.hasSubClassEq (&RC) ||
65+ X86::RFP64RegClass.hasSubClassEq (&RC))
66+ return getRegBank (X86::PSRRegBankID);
67+
6268 llvm_unreachable (" Unsupported register kind yet." );
6369}
6470
6571X86GenRegisterBankInfo::PartialMappingIdx
66- X86GenRegisterBankInfo::getPartialMappingIdx (const LLT &Ty, bool isFP) {
72+ X86GenRegisterBankInfo::getPartialMappingIdx (const MachineInstr &MI,
73+ const LLT &Ty, bool isFP) {
74+ const MachineFunction *MF = MI.getMF ();
75+ const X86Subtarget *ST = &MF->getSubtarget <X86Subtarget>();
76+ bool HasSSE1 = ST->hasSSE1 ();
77+ bool HasSSE2 = ST->hasSSE2 ();
78+ // 80 bits is only generated for X87 floating points.
79+ if (Ty.getSizeInBits () == 80 )
80+ isFP = true ;
6781 if ((Ty.isScalar () && !isFP) || Ty.isPointer ()) {
6882 switch (Ty.getSizeInBits ()) {
6983 case 1 :
@@ -84,11 +98,13 @@ X86GenRegisterBankInfo::getPartialMappingIdx(const LLT &Ty, bool isFP) {
8498 } else if (Ty.isScalar ()) {
8599 switch (Ty.getSizeInBits ()) {
86100 case 32 :
87- return PMI_FP32;
101+ return HasSSE1 ? PMI_FP32 : PMI_PSR32 ;
88102 case 64 :
89- return PMI_FP64;
103+ return HasSSE2 ? PMI_FP64 : PMI_PSR64 ;
90104 case 128 :
91105 return PMI_VEC128;
106+ case 80 :
107+ return PMI_PSR80;
92108 default :
93109 llvm_unreachable (" Unsupported register size." );
94110 }
@@ -118,7 +134,8 @@ void X86RegisterBankInfo::getInstrPartialMappingIdxs(
118134 if (!MO.isReg () || !MO.getReg ())
119135 OpRegBankIdx[Idx] = PMI_None;
120136 else
121- OpRegBankIdx[Idx] = getPartialMappingIdx (MRI.getType (MO.getReg ()), isFP);
137+ OpRegBankIdx[Idx] =
138+ getPartialMappingIdx (MI, MRI.getType (MO.getReg ()), isFP);
122139 }
123140}
124141
@@ -156,7 +173,7 @@ X86RegisterBankInfo::getSameOperandsMapping(const MachineInstr &MI,
156173 (Ty != MRI.getType (MI.getOperand (2 ).getReg ())))
157174 llvm_unreachable (" Unsupported operand mapping yet." );
158175
159- auto Mapping = getValueMapping (getPartialMappingIdx (Ty, isFP), 3 );
176+ auto Mapping = getValueMapping (getPartialMappingIdx (MI, Ty, isFP), 3 );
160177 return getInstructionMapping (DefaultMappingID, 1 , Mapping, NumOperands);
161178}
162179
@@ -190,9 +207,8 @@ X86RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
190207 unsigned NumOperands = MI.getNumOperands ();
191208 LLT Ty = MRI.getType (MI.getOperand (0 ).getReg ());
192209
193- auto Mapping = getValueMapping (getPartialMappingIdx (Ty, false ), 3 );
210+ auto Mapping = getValueMapping (getPartialMappingIdx (MI, Ty, false ), 3 );
194211 return getInstructionMapping (DefaultMappingID, 1 , Mapping, NumOperands);
195-
196212 }
197213 default :
198214 break ;
@@ -206,7 +222,7 @@ X86RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
206222 case TargetOpcode::G_FPTRUNC:
207223 case TargetOpcode::G_FCONSTANT:
208224 // Instruction having only floating-point operands (all scalars in VECRReg)
209- getInstrPartialMappingIdxs (MI, MRI, /* isFP */ true , OpRegBankIdx);
225+ getInstrPartialMappingIdxs (MI, MRI, /* isFP= */ true , OpRegBankIdx);
210226 break ;
211227 case TargetOpcode::G_SITOFP:
212228 case TargetOpcode::G_FPTOSI: {
@@ -219,8 +235,8 @@ X86RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
219235
220236 bool FirstArgIsFP = Opc == TargetOpcode::G_SITOFP;
221237 bool SecondArgIsFP = Opc == TargetOpcode::G_FPTOSI;
222- OpRegBankIdx[0 ] = getPartialMappingIdx (Ty0, /* isFP */ FirstArgIsFP);
223- OpRegBankIdx[1 ] = getPartialMappingIdx (Ty1, /* isFP */ SecondArgIsFP);
238+ OpRegBankIdx[0 ] = getPartialMappingIdx (MI, Ty0, /* isFP= */ FirstArgIsFP);
239+ OpRegBankIdx[1 ] = getPartialMappingIdx (MI, Ty1, /* isFP= */ SecondArgIsFP);
224240 break ;
225241 }
226242 case TargetOpcode::G_FCMP: {
@@ -234,7 +250,7 @@ X86RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
234250 (void )Size;
235251 assert ((Size == 32 || Size == 64 ) && " Unsupported size for G_FCMP" );
236252
237- auto FpRegBank = getPartialMappingIdx (Ty1, /* isFP */ true );
253+ auto FpRegBank = getPartialMappingIdx (MI, Ty1, /* isFP= */ true );
238254 OpRegBankIdx = {PMI_GPR8,
239255 /* Predicate */ PMI_None, FpRegBank, FpRegBank};
240256 break ;
@@ -253,12 +269,12 @@ X86RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
253269 (Ty1.getSizeInBits () == 32 || Ty1.getSizeInBits () == 64 ) &&
254270 Opc == TargetOpcode::G_ANYEXT;
255271
256- getInstrPartialMappingIdxs (MI, MRI, /* isFP */ isFPTrunc || isFPAnyExt,
272+ getInstrPartialMappingIdxs (MI, MRI, /* isFP= */ isFPTrunc || isFPAnyExt,
257273 OpRegBankIdx);
258274 } break ;
259275 default :
260276 // Track the bank of each register, use NotFP mapping (all scalars in GPRs)
261- getInstrPartialMappingIdxs (MI, MRI, /* isFP */ false , OpRegBankIdx);
277+ getInstrPartialMappingIdxs (MI, MRI, /* isFP= */ false , OpRegBankIdx);
262278 break ;
263279 }
264280
@@ -288,16 +304,16 @@ X86RegisterBankInfo::getInstrAlternativeMappings(const MachineInstr &MI) const {
288304 case TargetOpcode::G_LOAD:
289305 case TargetOpcode::G_STORE:
290306 case TargetOpcode::G_IMPLICIT_DEF: {
291- // we going to try to map 32/64 bit to PMI_FP32/PMI_FP64
307+ // we going to try to map 32/64/80 bit to PMI_FP32/PMI_FP64/PMI_FP80
292308 unsigned Size = getSizeInBits (MI.getOperand (0 ).getReg (), MRI, TRI);
293- if (Size != 32 && Size != 64 )
309+ if (Size != 32 && Size != 64 && Size != 80 )
294310 break ;
295311
296312 unsigned NumOperands = MI.getNumOperands ();
297313
298314 // Track the bank of each register, use FP mapping (all scalars in VEC)
299315 SmallVector<PartialMappingIdx, 4 > OpRegBankIdx (NumOperands);
300- getInstrPartialMappingIdxs (MI, MRI, /* isFP */ true , OpRegBankIdx);
316+ getInstrPartialMappingIdxs (MI, MRI, /* isFP= */ true , OpRegBankIdx);
301317
302318 // Finally construct the computed mapping.
303319 SmallVector<const ValueMapping *, 8 > OpdsMapping (NumOperands);
0 commit comments