LLVM  10.0.0
MipsRegisterBankInfo.cpp
Go to the documentation of this file.
1 //===- MipsRegisterBankInfo.cpp ---------------------------------*- C++ -*-===//
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 /// \file
9 /// This file implements the targeting of the RegisterBankInfo class for Mips.
10 /// \todo This should be generated by TableGen.
11 //===----------------------------------------------------------------------===//
12 
13 #include "MipsRegisterBankInfo.h"
14 #include "MipsInstrInfo.h"
15 #include "MipsTargetMachine.h"
20 
21 #define GET_TARGET_REGBANK_IMPL
22 
23 #include "MipsGenRegisterBank.inc"
24 
25 namespace llvm {
26 namespace Mips {
33 };
34 
36  {0, 32, GPRBRegBank},
37  {0, 32, FPRBRegBank},
38  {0, 64, FPRBRegBank},
39  {0, 128, FPRBRegBank}
40 };
41 
44  GPRIdx = 1,
45  SPRIdx = 4,
46  DPRIdx = 7,
47  MSAIdx = 10
48 };
49 
51  // invalid
52  {nullptr, 0},
53  // up to 3 operands in GPRs
54  {&PartMappings[PMI_GPR - PMI_Min], 1},
55  {&PartMappings[PMI_GPR - PMI_Min], 1},
56  {&PartMappings[PMI_GPR - PMI_Min], 1},
57  // up to 3 operands in FPRs - single precission
58  {&PartMappings[PMI_SPR - PMI_Min], 1},
59  {&PartMappings[PMI_SPR - PMI_Min], 1},
60  {&PartMappings[PMI_SPR - PMI_Min], 1},
61  // up to 3 operands in FPRs - double precission
62  {&PartMappings[PMI_DPR - PMI_Min], 1},
63  {&PartMappings[PMI_DPR - PMI_Min], 1},
64  {&PartMappings[PMI_DPR - PMI_Min], 1},
65  // up to 3 operands in FPRs - MSA
66  {&PartMappings[PMI_MSA - PMI_Min], 1},
67  {&PartMappings[PMI_MSA - PMI_Min], 1},
69 };
70 
71 } // end namespace Mips
72 } // end namespace llvm
73 
74 using namespace llvm;
75 
78 
79 const RegisterBank &
81  LLT) const {
82  using namespace Mips;
83 
84  switch (RC.getID()) {
85  case Mips::GPR32RegClassID:
86  case Mips::CPU16Regs_and_GPRMM16ZeroRegClassID:
87  case Mips::GPRMM16MovePPairFirstRegClassID:
88  case Mips::CPU16Regs_and_GPRMM16MovePPairSecondRegClassID:
89  case Mips::GPRMM16MoveP_and_CPU16Regs_and_GPRMM16ZeroRegClassID:
90  case Mips::GPRMM16MovePPairFirst_and_GPRMM16MovePPairSecondRegClassID:
91  case Mips::SP32RegClassID:
92  case Mips::GP32RegClassID:
93  return getRegBank(Mips::GPRBRegBankID);
94  case Mips::FGRCCRegClassID:
95  case Mips::FGR32RegClassID:
96  case Mips::FGR64RegClassID:
97  case Mips::AFGR64RegClassID:
98  case Mips::MSA128BRegClassID:
99  case Mips::MSA128HRegClassID:
100  case Mips::MSA128WRegClassID:
101  case Mips::MSA128DRegClassID:
102  return getRegBank(Mips::FPRBRegBankID);
103  default:
104  llvm_unreachable("Register class not supported");
105  }
106 }
107 
108 // Instructions where all register operands are floating point.
109 static bool isFloatingPointOpcode(unsigned Opc) {
110  switch (Opc) {
111  case TargetOpcode::G_FCONSTANT:
112  case TargetOpcode::G_FADD:
113  case TargetOpcode::G_FSUB:
114  case TargetOpcode::G_FMUL:
115  case TargetOpcode::G_FDIV:
116  case TargetOpcode::G_FABS:
117  case TargetOpcode::G_FSQRT:
118  case TargetOpcode::G_FCEIL:
119  case TargetOpcode::G_FFLOOR:
120  case TargetOpcode::G_FPEXT:
121  case TargetOpcode::G_FPTRUNC:
122  return true;
123  default:
124  return false;
125  }
126 }
127 
128 // Instructions where use operands are floating point registers.
129 // Def operands are general purpose.
130 static bool isFloatingPointOpcodeUse(unsigned Opc) {
131  switch (Opc) {
132  case TargetOpcode::G_FPTOSI:
133  case TargetOpcode::G_FPTOUI:
134  case TargetOpcode::G_FCMP:
135  case Mips::MFC1:
137  case Mips::ExtractElementF64_64:
138  return true;
139  default:
140  return isFloatingPointOpcode(Opc);
141  }
142 }
143 
144 // Instructions where def operands are floating point registers.
145 // Use operands are general purpose.
146 static bool isFloatingPointOpcodeDef(unsigned Opc) {
147  switch (Opc) {
148  case TargetOpcode::G_SITOFP:
149  case TargetOpcode::G_UITOFP:
150  case Mips::MTC1:
151  case Mips::BuildPairF64:
152  case Mips::BuildPairF64_64:
153  return true;
154  default:
155  return isFloatingPointOpcode(Opc);
156  }
157 }
158 
159 static bool isAmbiguous(unsigned Opc) {
160  switch (Opc) {
161  case TargetOpcode::G_LOAD:
162  case TargetOpcode::G_STORE:
163  case TargetOpcode::G_PHI:
164  case TargetOpcode::G_SELECT:
165  case TargetOpcode::G_IMPLICIT_DEF:
166  return true;
167  default:
168  return false;
169  }
170 }
171 
172 void MipsRegisterBankInfo::AmbiguousRegDefUseContainer::addDefUses(
174  assert(!MRI.getType(Reg).isPointer() &&
175  "Pointers are gprb, they should not be considered as ambiguous.\n");
176  for (MachineInstr &UseMI : MRI.use_instructions(Reg)) {
177  MachineInstr *NonCopyInstr = skipCopiesOutgoing(&UseMI);
178  // Copy with many uses.
179  if (NonCopyInstr->getOpcode() == TargetOpcode::COPY &&
180  !Register::isPhysicalRegister(NonCopyInstr->getOperand(0).getReg()))
181  addDefUses(NonCopyInstr->getOperand(0).getReg(), MRI);
182  else
183  DefUses.push_back(skipCopiesOutgoing(&UseMI));
184  }
185 }
186 
187 void MipsRegisterBankInfo::AmbiguousRegDefUseContainer::addUseDef(
188  Register Reg, const MachineRegisterInfo &MRI) {
189  assert(!MRI.getType(Reg).isPointer() &&
190  "Pointers are gprb, they should not be considered as ambiguous.\n");
191  MachineInstr *DefMI = MRI.getVRegDef(Reg);
192  UseDefs.push_back(skipCopiesIncoming(DefMI));
193 }
194 
195 MachineInstr *
196 MipsRegisterBankInfo::AmbiguousRegDefUseContainer::skipCopiesOutgoing(
197  MachineInstr *MI) const {
198  const MachineFunction &MF = *MI->getParent()->getParent();
199  const MachineRegisterInfo &MRI = MF.getRegInfo();
200  MachineInstr *Ret = MI;
201  while (Ret->getOpcode() == TargetOpcode::COPY &&
203  MRI.hasOneUse(Ret->getOperand(0).getReg())) {
204  Ret = &(*MRI.use_instr_begin(Ret->getOperand(0).getReg()));
205  }
206  return Ret;
207 }
208 
209 MachineInstr *
210 MipsRegisterBankInfo::AmbiguousRegDefUseContainer::skipCopiesIncoming(
211  MachineInstr *MI) const {
212  const MachineFunction &MF = *MI->getParent()->getParent();
213  const MachineRegisterInfo &MRI = MF.getRegInfo();
214  MachineInstr *Ret = MI;
215  while (Ret->getOpcode() == TargetOpcode::COPY &&
217  Ret = MRI.getVRegDef(Ret->getOperand(1).getReg());
218  return Ret;
219 }
220 
221 MipsRegisterBankInfo::AmbiguousRegDefUseContainer::AmbiguousRegDefUseContainer(
222  const MachineInstr *MI) {
223  assert(isAmbiguous(MI->getOpcode()) &&
224  "Not implemented for non Ambiguous opcode.\n");
225 
226  const MachineRegisterInfo &MRI = MI->getMF()->getRegInfo();
227 
228  if (MI->getOpcode() == TargetOpcode::G_LOAD)
229  addDefUses(MI->getOperand(0).getReg(), MRI);
230 
231  if (MI->getOpcode() == TargetOpcode::G_STORE)
232  addUseDef(MI->getOperand(0).getReg(), MRI);
233 
234  if (MI->getOpcode() == TargetOpcode::G_PHI) {
235  addDefUses(MI->getOperand(0).getReg(), MRI);
236 
237  for (unsigned i = 1; i < MI->getNumOperands(); i += 2)
238  addUseDef(MI->getOperand(i).getReg(), MRI);
239  }
240 
241  if (MI->getOpcode() == TargetOpcode::G_SELECT) {
242  addDefUses(MI->getOperand(0).getReg(), MRI);
243 
244  addUseDef(MI->getOperand(2).getReg(), MRI);
245  addUseDef(MI->getOperand(3).getReg(), MRI);
246  }
247 
248  if (MI->getOpcode() == TargetOpcode::G_IMPLICIT_DEF)
249  addDefUses(MI->getOperand(0).getReg(), MRI);
250 }
251 
252 bool MipsRegisterBankInfo::TypeInfoForMF::visit(
253  const MachineInstr *MI, const MachineInstr *WaitingForTypeOfMI) {
254  assert(isAmbiguous(MI->getOpcode()) && "Visiting non-Ambiguous opcode.\n");
255  if (wasVisited(MI))
256  return true; // InstType has already been determined for MI.
257 
258  startVisit(MI);
259  AmbiguousRegDefUseContainer DefUseContainer(MI);
260 
261  // Visit instructions where MI's DEF operands are USED.
262  if (visitAdjacentInstrs(MI, DefUseContainer.getDefUses(), true))
263  return true;
264 
265  // Visit instructions that DEFINE MI's USE operands.
266  if (visitAdjacentInstrs(MI, DefUseContainer.getUseDefs(), false))
267  return true;
268 
269  // All MI's adjacent instructions, are ambiguous.
270  if (!WaitingForTypeOfMI) {
271  // This is chain of ambiguous instructions.
272  setTypes(MI, InstType::Ambiguous);
273  return true;
274  }
275  // Excluding WaitingForTypeOfMI, MI is either connected to chains of ambiguous
276  // instructions or has no other adjacent instructions. Anyway InstType could
277  // not be determined. There could be unexplored path from some of
278  // WaitingForTypeOfMI's adjacent instructions to an instruction with only one
279  // mapping available.
280  // We are done with this branch, add MI to WaitingForTypeOfMI's WaitingQueue,
281  // this way when WaitingForTypeOfMI figures out its InstType same InstType
282  // will be assigned to all instructions in this branch.
283  addToWaitingQueue(WaitingForTypeOfMI, MI);
284  return false;
285 }
286 
287 bool MipsRegisterBankInfo::TypeInfoForMF::visitAdjacentInstrs(
288  const MachineInstr *MI, SmallVectorImpl<MachineInstr *> &AdjacentInstrs,
289  bool isDefUse) {
290  while (!AdjacentInstrs.empty()) {
291  MachineInstr *AdjMI = AdjacentInstrs.pop_back_val();
292 
293  if (isDefUse ? isFloatingPointOpcodeUse(AdjMI->getOpcode())
294  : isFloatingPointOpcodeDef(AdjMI->getOpcode())) {
295  setTypes(MI, InstType::FloatingPoint);
296  return true;
297  }
298 
299  // Determine InstType from register bank of phys register that is
300  // 'isDefUse ? def : use' of this copy.
301  if (AdjMI->getOpcode() == TargetOpcode::COPY) {
302  setTypesAccordingToPhysicalRegister(MI, AdjMI, isDefUse ? 0 : 1);
303  return true;
304  }
305 
306  // Defaults to integer instruction. Includes G_MERGE_VALUES and
307  // G_UNMERGE_VALUES.
308  if (!isAmbiguous(AdjMI->getOpcode())) {
309  setTypes(MI, InstType::Integer);
310  return true;
311  }
312 
313  // When AdjMI was visited first, MI has to continue to explore remaining
314  // adjacent instructions and determine InstType without visiting AdjMI.
315  if (!wasVisited(AdjMI) ||
316  getRecordedTypeForInstr(AdjMI) != InstType::NotDetermined) {
317  if (visit(AdjMI, MI)) {
318  // InstType is successfully determined and is same as for AdjMI.
319  setTypes(MI, getRecordedTypeForInstr(AdjMI));
320  return true;
321  }
322  }
323  }
324  return false;
325 }
326 
327 void MipsRegisterBankInfo::TypeInfoForMF::setTypes(const MachineInstr *MI,
328  InstType InstTy) {
329  changeRecordedTypeForInstr(MI, InstTy);
330  for (const MachineInstr *WaitingInstr : getWaitingQueueFor(MI)) {
331  setTypes(WaitingInstr, InstTy);
332  }
333 }
334 
335 void MipsRegisterBankInfo::TypeInfoForMF::setTypesAccordingToPhysicalRegister(
336  const MachineInstr *MI, const MachineInstr *CopyInst, unsigned Op) {
338  "Copies of non physical registers should not be considered here.\n");
339 
340  const MachineFunction &MF = *CopyInst->getMF();
341  const MachineRegisterInfo &MRI = MF.getRegInfo();
342  const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo();
343  const RegisterBankInfo &RBI =
344  *CopyInst->getMF()->getSubtarget().getRegBankInfo();
345  const RegisterBank *Bank =
346  RBI.getRegBank(CopyInst->getOperand(Op).getReg(), MRI, TRI);
347 
348  if (Bank == &Mips::FPRBRegBank)
349  setTypes(MI, InstType::FloatingPoint);
350  else if (Bank == &Mips::GPRBRegBank)
351  setTypes(MI, InstType::Integer);
352  else
353  llvm_unreachable("Unsupported register bank.\n");
354 }
355 
356 MipsRegisterBankInfo::InstType
357 MipsRegisterBankInfo::TypeInfoForMF::determineInstType(const MachineInstr *MI) {
358  visit(MI, nullptr);
359  return getRecordedTypeForInstr(MI);
360 }
361 
362 void MipsRegisterBankInfo::TypeInfoForMF::cleanupIfNewFunction(
363  llvm::StringRef FunctionName) {
364  if (MFName != FunctionName) {
365  MFName = FunctionName;
366  WaitingQueues.clear();
367  Types.clear();
368  }
369 }
370 
371 static const MipsRegisterBankInfo::ValueMapping *
373  assert(static_cast<const MipsSubtarget &>(MF.getSubtarget()).hasMSA() &&
374  "MSA mapping not available on target without MSA.");
376 }
377 
378 static const MipsRegisterBankInfo::ValueMapping *getFprbMapping(unsigned Size) {
379  return Size == 32 ? &Mips::ValueMappings[Mips::SPRIdx]
381 }
382 
383 static const unsigned CustomMappingID = 1;
384 
385 // Only 64 bit mapping is available in fprb and will be marked as custom, i.e.
386 // will be split into two 32 bit registers in gprb.
387 static const MipsRegisterBankInfo::ValueMapping *
388 getGprbOrCustomMapping(unsigned Size, unsigned &MappingID) {
389  if (Size == 32)
391 
392  MappingID = CustomMappingID;
394 }
395 
398 
399  static TypeInfoForMF TI;
400 
401  // Reset TI internal data when MF changes.
402  TI.cleanupIfNewFunction(MI.getMF()->getName());
403 
404  unsigned Opc = MI.getOpcode();
405  const MachineFunction &MF = *MI.getParent()->getParent();
406  const MachineRegisterInfo &MRI = MF.getRegInfo();
407 
408  if (MI.getOpcode() != TargetOpcode::G_PHI) {
409  const RegisterBankInfo::InstructionMapping &Mapping =
411  if (Mapping.isValid())
412  return Mapping;
413  }
414 
415  using namespace TargetOpcode;
416 
417  unsigned NumOperands = MI.getNumOperands();
418  const ValueMapping *OperandsMapping = &Mips::ValueMappings[Mips::GPRIdx];
419  unsigned MappingID = DefaultMappingID;
420 
421  // Check if LLT sizes match sizes of available register banks.
422  for (const MachineOperand &Op : MI.operands()) {
423  if (Op.isReg()) {
424  LLT RegTy = MRI.getType(Op.getReg());
425 
426  if (RegTy.isScalar() &&
427  (RegTy.getSizeInBits() != 32 && RegTy.getSizeInBits() != 64))
429 
430  if (RegTy.isVector() && RegTy.getSizeInBits() != 128)
432  }
433  }
434 
435  const LLT Op0Ty = MRI.getType(MI.getOperand(0).getReg());
436  unsigned Op0Size = Op0Ty.getSizeInBits();
437  InstType InstTy = InstType::Integer;
438 
439  switch (Opc) {
440  case G_TRUNC:
441  case G_UMULH:
442  case G_ZEXTLOAD:
443  case G_SEXTLOAD:
444  case G_PTR_ADD:
445  case G_INTTOPTR:
446  case G_PTRTOINT:
447  case G_AND:
448  case G_OR:
449  case G_XOR:
450  case G_SHL:
451  case G_ASHR:
452  case G_LSHR:
453  case G_BRINDIRECT:
454  case G_VASTART:
455  case G_BSWAP:
456  OperandsMapping = &Mips::ValueMappings[Mips::GPRIdx];
457  break;
458  case G_ADD:
459  case G_SUB:
460  case G_MUL:
461  case G_SDIV:
462  case G_SREM:
463  case G_UDIV:
464  case G_UREM:
465  OperandsMapping = &Mips::ValueMappings[Mips::GPRIdx];
466  if (Op0Size == 128)
467  OperandsMapping = getMSAMapping(MF);
468  break;
469  case G_STORE:
470  case G_LOAD:
471  if (Op0Size == 128) {
472  OperandsMapping = getOperandsMapping(
474  break;
475  }
476 
477  if (!Op0Ty.isPointer())
478  InstTy = TI.determineInstType(&MI);
479 
480  if (InstTy == InstType::FloatingPoint ||
481  (Op0Size == 64 && InstTy == InstType::Ambiguous))
482  OperandsMapping = getOperandsMapping(
484  else
485  OperandsMapping =
486  getOperandsMapping({getGprbOrCustomMapping(Op0Size, MappingID),
488 
489  break;
490  case G_PHI:
491  if (!Op0Ty.isPointer())
492  InstTy = TI.determineInstType(&MI);
493 
494  // PHI is copylike and should have one regbank in mapping for def register.
495  if (InstTy == InstType::Integer && Op0Size == 64) {
496  OperandsMapping =
498  return getInstructionMapping(CustomMappingID, /*Cost=*/1, OperandsMapping,
499  /*NumOperands=*/1);
500  }
501  // Use default handling for PHI, i.e. set reg bank of def operand to match
502  // register banks of use operands.
503  return getInstrMappingImpl(MI);
504  case G_SELECT: {
505  if (!Op0Ty.isPointer())
506  InstTy = TI.determineInstType(&MI);
507 
508  if (InstTy == InstType::FloatingPoint ||
509  (Op0Size == 64 && InstTy == InstType::Ambiguous)) {
510  const RegisterBankInfo::ValueMapping *Bank = getFprbMapping(Op0Size);
511  OperandsMapping = getOperandsMapping(
512  {Bank, &Mips::ValueMappings[Mips::GPRIdx], Bank, Bank});
513  break;
514  } else {
515  const RegisterBankInfo::ValueMapping *Bank =
516  getGprbOrCustomMapping(Op0Size, MappingID);
517  OperandsMapping = getOperandsMapping(
518  {Bank, &Mips::ValueMappings[Mips::GPRIdx], Bank, Bank});
519  }
520  break;
521  }
522  case G_IMPLICIT_DEF:
523  if (!Op0Ty.isPointer())
524  InstTy = TI.determineInstType(&MI);
525 
526  if (InstTy == InstType::FloatingPoint)
527  OperandsMapping = getFprbMapping(Op0Size);
528  else
529  OperandsMapping = getGprbOrCustomMapping(Op0Size, MappingID);
530 
531  break;
532  case G_UNMERGE_VALUES:
535  &Mips::ValueMappings[Mips::DPRIdx]});
536  MappingID = CustomMappingID;
537  break;
538  case G_MERGE_VALUES:
541  &Mips::ValueMappings[Mips::GPRIdx]});
542  MappingID = CustomMappingID;
543  break;
544  case G_FADD:
545  case G_FSUB:
546  case G_FMUL:
547  case G_FDIV:
548  case G_FABS:
549  case G_FSQRT:
550  OperandsMapping = getFprbMapping(Op0Size);
551  if (Op0Size == 128)
552  OperandsMapping = getMSAMapping(MF);
553  break;
554  case G_FCONSTANT:
555  OperandsMapping = getOperandsMapping({getFprbMapping(Op0Size), nullptr});
556  break;
557  case G_FCMP: {
558  unsigned Op2Size = MRI.getType(MI.getOperand(2).getReg()).getSizeInBits();
559  OperandsMapping =
561  getFprbMapping(Op2Size), getFprbMapping(Op2Size)});
562  break;
563  }
564  case G_FPEXT:
567  break;
568  case G_FPTRUNC:
571  break;
572  case G_FPTOSI: {
573  assert((Op0Size == 32) && "Unsupported integer size");
574  unsigned SizeFP = MRI.getType(MI.getOperand(1).getReg()).getSizeInBits();
575  OperandsMapping = getOperandsMapping(
577  break;
578  }
579  case G_SITOFP:
580  assert((MRI.getType(MI.getOperand(1).getReg()).getSizeInBits() == 32) &&
581  "Unsupported integer size");
582  OperandsMapping = getOperandsMapping(
584  break;
585  case G_CONSTANT:
586  case G_FRAME_INDEX:
587  case G_GLOBAL_VALUE:
588  case G_JUMP_TABLE:
589  case G_BRCOND:
590  OperandsMapping =
592  break;
593  case G_BRJT:
594  OperandsMapping =
597  break;
598  case G_ICMP:
599  OperandsMapping =
602  &Mips::ValueMappings[Mips::GPRIdx]});
603  break;
604  default:
606  }
607 
608  return getInstructionMapping(MappingID, /*Cost=*/1, OperandsMapping,
609  NumOperands);
610 }
611 
613 namespace {
614 class InstManager : public GISelChangeObserver {
615  InstListTy &InstList;
616 
617 public:
618  InstManager(InstListTy &Insts) : InstList(Insts) {}
619 
620  void createdInstr(MachineInstr &MI) override { InstList.insert(&MI); }
621  void erasingInstr(MachineInstr &MI) override {}
622  void changingInstr(MachineInstr &MI) override {}
623  void changedInstr(MachineInstr &MI) override {}
624 };
625 } // end anonymous namespace
626 
628  MachineRegisterInfo &MRI) const {
629  Register Dest = MI.getOperand(0).getReg();
630  switch (MI.getOpcode()) {
631  case TargetOpcode::G_STORE:
632  // No def operands, skip this instruction.
633  break;
634  case TargetOpcode::G_CONSTANT:
635  case TargetOpcode::G_LOAD:
636  case TargetOpcode::G_SELECT:
637  case TargetOpcode::G_PHI:
638  case TargetOpcode::G_IMPLICIT_DEF: {
639  assert(MRI.getType(Dest) == LLT::scalar(32) && "Unexpected operand type.");
640  MRI.setRegBank(Dest, getRegBank(Mips::GPRBRegBankID));
641  break;
642  }
643  case TargetOpcode::G_PTR_ADD: {
644  assert(MRI.getType(Dest).isPointer() && "Unexpected operand type.");
645  MRI.setRegBank(Dest, getRegBank(Mips::GPRBRegBankID));
646  break;
647  }
648  default:
649  llvm_unreachable("Unexpected opcode.");
650  }
651 }
652 
653 static void
655  MachineInstr &MI) {
656  SmallVector<Register, 4> UpdatedDefs;
658  ArtCombiner.tryCombineMerges(MI, DeadInstrs, UpdatedDefs);
659  for (MachineInstr *DeadMI : DeadInstrs)
660  DeadMI->eraseFromParent();
661 }
662 
664  const OperandsMapper &OpdMapper) const {
665  MachineInstr &MI = OpdMapper.getMI();
666  InstListTy NewInstrs;
667  MachineIRBuilder B(MI);
668  MachineFunction *MF = MI.getMF();
669  MachineRegisterInfo &MRI = OpdMapper.getMRI();
670  const LegalizerInfo &LegInfo = *MF->getSubtarget().getLegalizerInfo();
671 
672  InstManager NewInstrObserver(NewInstrs);
673  GISelObserverWrapper WrapperObserver(&NewInstrObserver);
674  LegalizerHelper Helper(*MF, WrapperObserver, B);
675  LegalizationArtifactCombiner ArtCombiner(B, MF->getRegInfo(), LegInfo);
676 
677  switch (MI.getOpcode()) {
678  case TargetOpcode::G_LOAD:
679  case TargetOpcode::G_STORE:
680  case TargetOpcode::G_PHI:
681  case TargetOpcode::G_SELECT:
682  case TargetOpcode::G_IMPLICIT_DEF: {
683  Helper.narrowScalar(MI, 0, LLT::scalar(32));
684  // Handle new instructions.
685  while (!NewInstrs.empty()) {
686  MachineInstr *NewMI = NewInstrs.pop_back_val();
687  // This is new G_UNMERGE that was created during narrowScalar and will
688  // not be considered for regbank selection. RegBankSelect for mips
689  // visits/makes corresponding G_MERGE first. Combine them here.
690  if (NewMI->getOpcode() == TargetOpcode::G_UNMERGE_VALUES)
691  combineAwayG_UNMERGE_VALUES(ArtCombiner, *NewMI);
692  // This G_MERGE will be combined away when its corresponding G_UNMERGE
693  // gets regBankSelected.
694  else if (NewMI->getOpcode() == TargetOpcode::G_MERGE_VALUES)
695  continue;
696  else
697  // Manually set register banks for def operands to 32 bit gprb.
698  setRegBank(*NewMI, MRI);
699  }
700  return;
701  }
702  case TargetOpcode::G_UNMERGE_VALUES:
703  combineAwayG_UNMERGE_VALUES(ArtCombiner, MI);
704  return;
705  default:
706  break;
707  }
708 
709  return applyDefaultMapping(OpdMapper);
710 }
const ValueMapping * getOperandsMapping(Iterator Begin, Iterator End) const
Get the uniquely generated array of ValueMapping for the elements of between Begin and End...
void setRegBank(MachineInstr &MI, MachineRegisterInfo &MRI) const
RegBankSelect determined that s64 operand is better to be split into two s32 operands in gprb...
static const MipsRegisterBankInfo::ValueMapping * getGprbOrCustomMapping(unsigned Size, unsigned &MappingID)
const MachineFunction * getMF() const
Return the function that contains the basic block that this instruction belongs to.
This class represents lattice values for constants.
Definition: AllocatorList.h:23
const InstructionMapping & getInstructionMapping(unsigned ID, unsigned Cost, const ValueMapping *OperandsMapping, unsigned NumOperands) const
Method to get a uniquely generated InstructionMapping.
RegisterBankInfo::ValueMapping ValueMappings[]
unsigned getSizeInBits(Register Reg, const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI) const
Get the size in bits of Reg.
Helper class that represents how the value of an instruction may be mapped and what is the related co...
bool isScalar() const
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
Definition: Register.h:63
bool empty() const
Definition: GISelWorkList.h:42
unsigned Reg
MachineRegisterInfo & getMRI() const
The MachineRegisterInfo we used to realize the mapping.
LLT getType(unsigned Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register...
static const MipsRegisterBankInfo::ValueMapping * getMSAMapping(const MachineFunction &MF)
Helper class used to get/create the virtual registers that will be used to replace the MachineOperand...
virtual const RegisterBankInfo * getRegBankInfo() const
If the information for the register banks is available, return it.
unsigned const TargetRegisterInfo * TRI
void setRegBank(unsigned Reg, const RegisterBank &RegBank)
Set the register bank to RegBank for Reg.
iterator_range< mop_iterator > operands()
Definition: MachineInstr.h:492
static const unsigned CustomMappingID
static bool isFloatingPointOpcodeUse(unsigned Opc)
bool isVector() const
static bool isFloatingPointOpcode(unsigned Opc)
Holds all the information related to register banks.
const RegisterBank & getRegBankFromRegClass(const TargetRegisterClass &RC, LLT) const override
Get a register bank that covers RC.
unsigned getNumOperands() const
Retuns the total number of operands.
Definition: MachineInstr.h:429
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:426
const InstructionMapping & getInstrMapping(const MachineInstr &MI) const override
Get the mapping of the different operands of MI on the register bank.
static bool isFloatingPointOpcodeDef(unsigned Opc)
unsigned getID() const
Return the register class ID number.
static bool isAmbiguous(unsigned Opc)
MachineInstr * getVRegDef(unsigned Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
This file declares the targeting of the RegisterBankInfo class for Mips.
static LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
virtual const LegalizerInfo * getLegalizerInfo() const
Abstract class that contains various methods for clients to notify about changes. ...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
unsigned const MachineRegisterInfo * MRI
const InstructionMapping & getInvalidInstructionMapping() const
Method to get a uniquely generated invalid InstructionMapping.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineInstrBuilder & UseMI
Helper struct that represents how a value is partially mapped into a register.
Helper class to build MachineInstr.
use_instr_iterator use_instr_begin(unsigned RegNo) const
RegisterBankInfo::PartialMapping PartMappings[]
void applyMappingImpl(const OperandsMapper &OpdMapper) const override
Here we have to narrowScalar s64 operands to s32, combine away G_MERGE or G_UNMERGE and erase instruc...
static const unsigned DefaultMappingID
Identifier used when the related instruction mapping instance is generated by target independent code...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
static const MipsRegisterBankInfo::ValueMapping * getFprbMapping(unsigned Size)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool isValid() const
Check whether this object is valid.
RegisterBank & getRegBank(unsigned ID)
Get the register bank identified by ID.
MachineOperand class - Representation of each machine instruction operand.
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:837
static void applyDefaultMapping(const OperandsMapper &OpdMapper)
Helper method to apply something that is like the default mapping.
MachineInstrBuilder MachineInstrBuilder & DefMI
unsigned getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
LLVM_NODISCARD T pop_back_val()
Definition: SmallVector.h:374
MachineInstr * pop_back_val()
void insert(MachineInstr *I)
Add the specified instruction to the worklist if it isn&#39;t already in it.
Definition: GISelWorkList.h:78
This class implements the register bank concept.
Definition: RegisterBank.h:28
Helper struct that represents how a value is mapped through different register banks.
bool isPointer() const
const MachineBasicBlock * getParent() const
Definition: MachineInstr.h:271
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
Definition: MachineInstr.h:63
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
bool hasOneUse(unsigned RegNo) const
hasOneUse - Return true if there is exactly one instruction using the specified register.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:55
const InstructionMapping & getInstrMappingImpl(const MachineInstr &MI) const
Try to get the mapping of MI.
uint32_t Size
Definition: Profile.cpp:46
bool tryCombineMerges(MachineInstr &MI, SmallVectorImpl< MachineInstr *> &DeadInsts, SmallVectorImpl< Register > &UpdatedDefs)
iterator_range< use_instr_iterator > use_instructions(unsigned Reg) const
LegalizeResult narrowScalar(MachineInstr &MI, unsigned TypeIdx, LLT NarrowTy)
Legalize an instruction by reducing the width of the underlying scalar type.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MipsRegisterBankInfo(const TargetRegisterInfo &TRI)
static void combineAwayG_UNMERGE_VALUES(LegalizationArtifactCombiner &ArtCombiner, MachineInstr &MI)
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:54
Simple wrapper observer that takes several observers, and calls each one for each event...
Register getReg() const
getReg - Returns the register number.
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:431
Wrapper class representing virtual and physical registers.
Definition: Register.h:19