• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //== llvm/CodeGen/GlobalISel/RegBankSelect.h - Reg Bank Selector -*- C++ -*-==//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 /// \file This file describes the interface of the MachineFunctionPass
11 /// responsible for assigning the generic virtual registers to register bank.
12 
13 /// By default, the reg bank selector relies on local decisions to
14 /// assign the register bank. In other words, it looks at one instruction
15 /// at a time to decide where the operand of that instruction should live.
16 ///
17 /// At higher optimization level, we could imagine that the reg bank selector
18 /// would use more global analysis and do crazier thing like duplicating
19 /// instructions and so on. This is future work.
20 ///
21 /// For now, the pass uses a greedy algorithm to decide where the operand
22 /// of an instruction should live. It asks the target which banks may be
23 /// used for each operand of the instruction and what is the cost. Then,
24 /// it chooses the solution which minimize the cost of the instruction plus
25 /// the cost of any move that may be needed to to the values into the right
26 /// register bank.
27 /// In other words, the cost for an instruction on a register bank RegBank
28 /// is: Cost of I on RegBank plus the sum of the cost for bringing the
29 /// input operands from their current register bank to RegBank.
30 /// Thus, the following formula:
31 /// cost(I, RegBank) = cost(I.Opcode, RegBank) +
32 ///    sum(for each arg in I.arguments: costCrossCopy(arg.RegBank, RegBank))
33 ///
34 /// E.g., Let say we are assigning the register bank for the instruction
35 /// defining v2.
36 /// v0(A_REGBANK) = ...
37 /// v1(A_REGBANK) = ...
38 /// v2 = G_ADD i32 v0, v1 <-- MI
39 ///
40 /// The target may say it can generate G_ADD i32 on register bank A and B
41 /// with a cost of respectively 5 and 1.
42 /// Then, let say the cost of a cross register bank copies from A to B is 1.
43 /// The reg bank selector would compare the following two costs:
44 /// cost(MI, A_REGBANK) = cost(G_ADD, A_REGBANK) + cost(v0.RegBank, A_REGBANK) +
45 ///    cost(v1.RegBank, A_REGBANK)
46 ///                     = 5 + cost(A_REGBANK, A_REGBANK) + cost(A_REGBANK,
47 ///                                                             A_REGBANK)
48 ///                     = 5 + 0 + 0 = 5
49 /// cost(MI, B_REGBANK) = cost(G_ADD, B_REGBANK) + cost(v0.RegBank, B_REGBANK) +
50 ///    cost(v1.RegBank, B_REGBANK)
51 ///                     = 1 + cost(A_REGBANK, B_REGBANK) + cost(A_REGBANK,
52 ///                                                             B_REGBANK)
53 ///                     = 1 + 1 + 1 = 3
54 /// Therefore, in this specific example, the reg bank selector would choose
55 /// bank B for MI.
56 /// v0(A_REGBANK) = ...
57 /// v1(A_REGBANK) = ...
58 /// tmp0(B_REGBANK) = COPY v0
59 /// tmp1(B_REGBANK) = COPY v1
60 /// v2(B_REGBANK) = G_ADD i32 tmp0, tmp1
61 //
62 //===----------------------------------------------------------------------===//
63 
64 #ifndef LLVM_CODEGEN_GLOBALISEL_REGBANKSELECT_H
65 #define LLVM_CODEGEN_GLOBALISEL_REGBANKSELECT_H
66 
67 #include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h"
68 #include "llvm/CodeGen/GlobalISel/RegisterBankInfo.h"
69 #include "llvm/CodeGen/MachineFunctionPass.h"
70 
71 namespace llvm {
72 // Forward declarations.
73 class BlockFrequency;
74 class MachineBranchProbabilityInfo;
75 class MachineBlockFrequencyInfo;
76 class MachineRegisterInfo;
77 class TargetRegisterInfo;
78 
79 /// This pass implements the reg bank selector pass used in the GlobalISel
80 /// pipeline. At the end of this pass, all register operands have been assigned
81 class RegBankSelect : public MachineFunctionPass {
82 public:
83   static char ID;
84 
85   /// List of the modes supported by the RegBankSelect pass.
86   enum Mode {
87     /// Assign the register banks as fast as possible (default).
88     Fast,
89     /// Greedily minimize the cost of assigning register banks.
90     /// This should produce code of greater quality, but will
91     /// require more compile time.
92     Greedy
93   };
94 
95   /// Abstract class used to represent an insertion point in a CFG.
96   /// This class records an insertion point and materializes it on
97   /// demand.
98   /// It allows to reason about the frequency of this insertion point,
99   /// without having to logically materialize it (e.g., on an edge),
100   /// before we actually need to insert something.
101   class InsertPoint {
102   protected:
103     /// Tell if the insert point has already been materialized.
104     bool WasMaterialized = false;
105     /// Materialize the insertion point.
106     ///
107     /// If isSplit() is true, this involves actually splitting
108     /// the block or edge.
109     ///
110     /// \post getPointImpl() returns a valid iterator.
111     /// \post getInsertMBBImpl() returns a valid basic block.
112     /// \post isSplit() == false ; no more splitting should be required.
113     virtual void materialize() = 0;
114 
115     /// Return the materialized insertion basic block.
116     /// Code will be inserted into that basic block.
117     ///
118     /// \pre ::materialize has been called.
119     virtual MachineBasicBlock &getInsertMBBImpl() = 0;
120 
121     /// Return the materialized insertion point.
122     /// Code will be inserted before that point.
123     ///
124     /// \pre ::materialize has been called.
125     virtual MachineBasicBlock::iterator getPointImpl() = 0;
126 
127   public:
~InsertPoint()128     virtual ~InsertPoint() {}
129 
130     /// The first call to this method will cause the splitting to
131     /// happen if need be, then sub sequent calls just return
132     /// the iterator to that point. I.e., no more splitting will
133     /// occur.
134     ///
135     /// \return The iterator that should be used with
136     /// MachineBasicBlock::insert. I.e., additional code happens
137     /// before that point.
getPoint()138     MachineBasicBlock::iterator getPoint() {
139       if (!WasMaterialized) {
140         WasMaterialized = true;
141         assert(canMaterialize() && "Impossible to materialize this point");
142         materialize();
143       }
144       // When we materialized the point we should have done the splitting.
145       assert(!isSplit() && "Wrong pre-condition");
146       return getPointImpl();
147     }
148 
149     /// The first call to this method will cause the splitting to
150     /// happen if need be, then sub sequent calls just return
151     /// the basic block that contains the insertion point.
152     /// I.e., no more splitting will occur.
153     ///
154     /// \return The basic block should be used with
155     /// MachineBasicBlock::insert and ::getPoint. The new code should
156     /// happen before that point.
getInsertMBB()157     MachineBasicBlock &getInsertMBB() {
158       if (!WasMaterialized) {
159         WasMaterialized = true;
160         assert(canMaterialize() && "Impossible to materialize this point");
161         materialize();
162       }
163       // When we materialized the point we should have done the splitting.
164       assert(!isSplit() && "Wrong pre-condition");
165       return getInsertMBBImpl();
166     }
167 
168     /// Insert \p MI in the just before ::getPoint()
insert(MachineInstr & MI)169     MachineBasicBlock::iterator insert(MachineInstr &MI) {
170       return getInsertMBB().insert(getPoint(), &MI);
171     }
172 
173     /// Does this point involve splitting an edge or block?
174     /// As soon as ::getPoint is called and thus, the point
175     /// materialized, the point will not require splitting anymore,
176     /// i.e., this will return false.
isSplit()177     virtual bool isSplit() const { return false; }
178 
179     /// Frequency of the insertion point.
180     /// \p P is used to access the various analysis that will help to
181     /// get that information, like MachineBlockFrequencyInfo.  If \p P
182     /// does not contain enough enough to return the actual frequency,
183     /// this returns 1.
frequency(const Pass & P)184     virtual uint64_t frequency(const Pass &P) const { return 1; }
185 
186     /// Check whether this insertion point can be materialized.
187     /// As soon as ::getPoint is called and thus, the point materialized
188     /// calling this method does not make sense.
canMaterialize()189     virtual bool canMaterialize() const { return false; }
190   };
191 
192   /// Insertion point before or after an instruction.
193   class InstrInsertPoint : public InsertPoint {
194   private:
195     /// Insertion point.
196     MachineInstr &Instr;
197     /// Does the insertion point is before or after Instr.
198     bool Before;
199 
200     void materialize() override;
201 
getPointImpl()202     MachineBasicBlock::iterator getPointImpl() override {
203       if (Before)
204         return Instr;
205       return Instr.getNextNode() ? *Instr.getNextNode()
206                                  : Instr.getParent()->end();
207     }
208 
getInsertMBBImpl()209     MachineBasicBlock &getInsertMBBImpl() override {
210       return *Instr.getParent();
211     }
212 
213   public:
214     /// Create an insertion point before (\p Before=true) or after \p Instr.
215     InstrInsertPoint(MachineInstr &Instr, bool Before = true);
216     bool isSplit() const override;
217     uint64_t frequency(const Pass &P) const override;
218 
219     // Worst case, we need to slice the basic block, but that is still doable.
canMaterialize()220     bool canMaterialize() const override { return true; }
221   };
222 
223   /// Insertion point at the beginning or end of a basic block.
224   class MBBInsertPoint : public InsertPoint {
225   private:
226     /// Insertion point.
227     MachineBasicBlock &MBB;
228     /// Does the insertion point is at the beginning or end of MBB.
229     bool Beginning;
230 
materialize()231     void materialize() override { /*Nothing to do to materialize*/
232     }
233 
getPointImpl()234     MachineBasicBlock::iterator getPointImpl() override {
235       return Beginning ? MBB.begin() : MBB.end();
236     }
237 
getInsertMBBImpl()238     MachineBasicBlock &getInsertMBBImpl() override { return MBB; }
239 
240   public:
241     MBBInsertPoint(MachineBasicBlock &MBB, bool Beginning = true)
InsertPoint()242         : InsertPoint(), MBB(MBB), Beginning(Beginning) {
243       // If we try to insert before phis, we should use the insertion
244       // points on the incoming edges.
245       assert((!Beginning || MBB.getFirstNonPHI() == MBB.begin()) &&
246              "Invalid beginning point");
247       // If we try to insert after the terminators, we should use the
248       // points on the outcoming edges.
249       assert((Beginning || MBB.getFirstTerminator() == MBB.end()) &&
250              "Invalid end point");
251     }
isSplit()252     bool isSplit() const override { return false; }
253     uint64_t frequency(const Pass &P) const override;
canMaterialize()254     bool canMaterialize() const override { return true; };
255   };
256 
257   /// Insertion point on an edge.
258   class EdgeInsertPoint : public InsertPoint {
259   private:
260     /// Source of the edge.
261     MachineBasicBlock &Src;
262     /// Destination of the edge.
263     /// After the materialization is done, this hold the basic block
264     /// that resulted from the splitting.
265     MachineBasicBlock *DstOrSplit;
266     /// P is used to update the analysis passes as applicable.
267     Pass &P;
268 
269     void materialize() override;
270 
getPointImpl()271     MachineBasicBlock::iterator getPointImpl() override {
272       // DstOrSplit should be the Split block at this point.
273       // I.e., it should have one predecessor, Src, and one successor,
274       // the original Dst.
275       assert(DstOrSplit && DstOrSplit->isPredecessor(&Src) &&
276              DstOrSplit->pred_size() == 1 && DstOrSplit->succ_size() == 1 &&
277              "Did not split?!");
278       return DstOrSplit->begin();
279     }
280 
getInsertMBBImpl()281     MachineBasicBlock &getInsertMBBImpl() override { return *DstOrSplit; }
282 
283   public:
EdgeInsertPoint(MachineBasicBlock & Src,MachineBasicBlock & Dst,Pass & P)284     EdgeInsertPoint(MachineBasicBlock &Src, MachineBasicBlock &Dst, Pass &P)
285         : InsertPoint(), Src(Src), DstOrSplit(&Dst), P(P) {}
isSplit()286     bool isSplit() const override {
287       return Src.succ_size() > 1 && DstOrSplit->pred_size() > 1;
288     }
289     uint64_t frequency(const Pass &P) const override;
290     bool canMaterialize() const override;
291   };
292 
293   /// Struct used to represent the placement of a repairing point for
294   /// a given operand.
295   class RepairingPlacement {
296   public:
297     /// Define the kind of action this repairing needs.
298     enum RepairingKind {
299       /// Nothing to repair, just drop this action.
300       None,
301       /// Reparing code needs to happen before InsertPoints.
302       Insert,
303       /// (Re)assign the register bank of the operand.
304       Reassign,
305       /// Mark this repairing placement as impossible.
306       Impossible
307     };
308 
309     /// Convenient types for a list of insertion points.
310     /// @{
311     typedef SmallVector<std::unique_ptr<InsertPoint>, 2> InsertionPoints;
312     typedef InsertionPoints::iterator insertpt_iterator;
313     typedef InsertionPoints::const_iterator const_insertpt_iterator;
314     /// @}
315 
316   private:
317     /// Kind of repairing.
318     RepairingKind Kind;
319     /// Index of the operand that will be repaired.
320     unsigned OpIdx;
321     /// Are all the insert points materializeable?
322     bool CanMaterialize;
323     /// Is there any of the insert points needing splitting?
324     bool HasSplit;
325     /// Insertion point for the repair code.
326     /// The repairing code needs to happen just before these points.
327     InsertionPoints InsertPoints;
328     /// Some insertion points may need to update the liveness and such.
329     Pass &P;
330 
331   public:
332     /// Create a repairing placement for the \p OpIdx-th operand of
333     /// \p MI. \p TRI is used to make some checks on the register aliases
334     /// if the machine operand is a physical register. \p P is used to
335     /// to update liveness information and such when materializing the
336     /// points.
337     RepairingPlacement(MachineInstr &MI, unsigned OpIdx,
338                        const TargetRegisterInfo &TRI, Pass &P,
339                        RepairingKind Kind = RepairingKind::Insert);
340 
341     /// Getters.
342     /// @{
getKind()343     RepairingKind getKind() const { return Kind; }
getOpIdx()344     unsigned getOpIdx() const { return OpIdx; }
canMaterialize()345     bool canMaterialize() const { return CanMaterialize; }
hasSplit()346     bool hasSplit() { return HasSplit; }
347     /// @}
348 
349     /// Overloaded methods to add an insertion point.
350     /// @{
351     /// Add a MBBInsertionPoint to the list of InsertPoints.
352     void addInsertPoint(MachineBasicBlock &MBB, bool Beginning);
353     /// Add a InstrInsertionPoint to the list of InsertPoints.
354     void addInsertPoint(MachineInstr &MI, bool Before);
355     /// Add an EdgeInsertionPoint (\p Src, \p Dst) to the list of InsertPoints.
356     void addInsertPoint(MachineBasicBlock &Src, MachineBasicBlock &Dst);
357     /// Add an InsertPoint to the list of insert points.
358     /// This method takes the ownership of &\p Point.
359     void addInsertPoint(InsertPoint &Point);
360     /// @}
361 
362     /// Accessors related to the insertion points.
363     /// @{
begin()364     insertpt_iterator begin() { return InsertPoints.begin(); }
end()365     insertpt_iterator end() { return InsertPoints.end(); }
366 
begin()367     const_insertpt_iterator begin() const { return InsertPoints.begin(); }
end()368     const_insertpt_iterator end() const { return InsertPoints.end(); }
369 
getNumInsertPoints()370     unsigned getNumInsertPoints() const { return InsertPoints.size(); }
371     /// @}
372 
373     /// Change the type of this repairing placement to \p NewKind.
374     /// It is not possible to switch a repairing placement to the
375     /// RepairingKind::Insert. There is no fundamental problem with
376     /// that, but no uses as well, so do not support it for now.
377     ///
378     /// \pre NewKind != RepairingKind::Insert
379     /// \post getKind() == NewKind
switchTo(RepairingKind NewKind)380     void switchTo(RepairingKind NewKind) {
381       assert(NewKind != Kind && "Already of the right Kind");
382       Kind = NewKind;
383       InsertPoints.clear();
384       CanMaterialize = NewKind != RepairingKind::Impossible;
385       HasSplit = false;
386       assert(NewKind != RepairingKind::Insert &&
387              "We would need more MI to switch to Insert");
388     }
389   };
390 
391 private:
392   /// Helper class used to represent the cost for mapping an instruction.
393   /// When mapping an instruction, we may introduce some repairing code.
394   /// In most cases, the repairing code is local to the instruction,
395   /// thus, we can omit the basic block frequency from the cost.
396   /// However, some alternatives may produce non-local cost, e.g., when
397   /// repairing a phi, and thus we then need to scale the local cost
398   /// to the non-local cost. This class does this for us.
399   /// \note: We could simply always scale the cost. The problem is that
400   /// there are higher chances that we saturate the cost easier and end
401   /// up having the same cost for actually different alternatives.
402   /// Another option would be to use APInt everywhere.
403   class MappingCost {
404   private:
405     /// Cost of the local instructions.
406     /// This cost is free of basic block frequency.
407     uint64_t LocalCost;
408     /// Cost of the non-local instructions.
409     /// This cost should include the frequency of the related blocks.
410     uint64_t NonLocalCost;
411     /// Frequency of the block where the local instructions live.
412     uint64_t LocalFreq;
413 
MappingCost(uint64_t LocalCost,uint64_t NonLocalCost,uint64_t LocalFreq)414     MappingCost(uint64_t LocalCost, uint64_t NonLocalCost, uint64_t LocalFreq)
415         : LocalCost(LocalCost), NonLocalCost(NonLocalCost),
416           LocalFreq(LocalFreq) {}
417 
418     /// Check if this cost is saturated.
419     bool isSaturated() const;
420 
421   public:
422     /// Create a MappingCost assuming that most of the instructions
423     /// will occur in a basic block with \p LocalFreq frequency.
424     MappingCost(const BlockFrequency &LocalFreq);
425 
426     /// Add \p Cost to the local cost.
427     /// \return true if this cost is saturated, false otherwise.
428     bool addLocalCost(uint64_t Cost);
429 
430     /// Add \p Cost to the non-local cost.
431     /// Non-local cost should reflect the frequency of their placement.
432     /// \return true if this cost is saturated, false otherwise.
433     bool addNonLocalCost(uint64_t Cost);
434 
435     /// Saturate the cost to the maximal representable value.
436     void saturate();
437 
438     /// Return an instance of MappingCost that represents an
439     /// impossible mapping.
440     static MappingCost ImpossibleCost();
441 
442     /// Check if this is less than \p Cost.
443     bool operator<(const MappingCost &Cost) const;
444     /// Check if this is equal to \p Cost.
445     bool operator==(const MappingCost &Cost) const;
446     /// Check if this is not equal to \p Cost.
447     bool operator!=(const MappingCost &Cost) const { return !(*this == Cost); }
448     /// Check if this is greater than \p Cost.
449     bool operator>(const MappingCost &Cost) const {
450       return *this != Cost && Cost < *this;
451     }
452   };
453 
454   /// Interface to the target lowering info related
455   /// to register banks.
456   const RegisterBankInfo *RBI;
457 
458   /// MRI contains all the register class/bank information that this
459   /// pass uses and updates.
460   MachineRegisterInfo *MRI;
461 
462   /// Information on the register classes for the current function.
463   const TargetRegisterInfo *TRI;
464 
465   /// Get the frequency of blocks.
466   /// This is required for non-fast mode.
467   MachineBlockFrequencyInfo *MBFI;
468 
469   /// Get the frequency of the edges.
470   /// This is required for non-fast mode.
471   MachineBranchProbabilityInfo *MBPI;
472 
473   /// Helper class used for every code morphing.
474   MachineIRBuilder MIRBuilder;
475 
476   /// Optimization mode of the pass.
477   Mode OptMode;
478 
479   /// Assign the register bank of each operand of \p MI.
480   void assignInstr(MachineInstr &MI);
481 
482   /// Initialize the field members using \p MF.
483   void init(MachineFunction &MF);
484 
485   /// Check if \p Reg is already assigned what is described by \p ValMapping.
486   /// \p OnlyAssign == true means that \p Reg just needs to be assigned a
487   /// register bank.  I.e., no repairing is necessary to have the
488   /// assignment match.
489   bool assignmentMatch(unsigned Reg,
490                        const RegisterBankInfo::ValueMapping &ValMapping,
491                        bool &OnlyAssign) const;
492 
493   /// Insert repairing code for \p Reg as specified by \p ValMapping.
494   /// The repairing placement is specified by \p RepairPt.
495   /// \p NewVRegs contains all the registers required to remap \p Reg.
496   /// In other words, the number of registers in NewVRegs must be equal
497   /// to ValMapping.BreakDown.size().
498   ///
499   /// The transformation could be sketched as:
500   /// \code
501   /// ... = op Reg
502   /// \endcode
503   /// Becomes
504   /// \code
505   /// <NewRegs> = COPY or extract Reg
506   /// ... = op Reg
507   /// \endcode
508   ///
509   /// and
510   /// \code
511   /// Reg = op ...
512   /// \endcode
513   /// Becomes
514   /// \code
515   /// Reg = op ...
516   /// Reg = COPY or build_sequence <NewRegs>
517   /// \endcode
518   ///
519   /// \pre NewVRegs.size() == ValMapping.BreakDown.size()
520   ///
521   /// \note The caller is supposed to do the rewriting of op if need be.
522   /// I.e., Reg = op ... => <NewRegs> = NewOp ...
523   void repairReg(MachineOperand &MO,
524                  const RegisterBankInfo::ValueMapping &ValMapping,
525                  RegBankSelect::RepairingPlacement &RepairPt,
526                  const iterator_range<SmallVectorImpl<unsigned>::const_iterator>
527                      &NewVRegs);
528 
529   /// Return the cost of the instruction needed to map \p MO to \p ValMapping.
530   /// The cost is free of basic block frequencies.
531   /// \pre MO.isReg()
532   /// \pre MO is assigned to a register bank.
533   /// \pre ValMapping is a valid mapping for MO.
534   uint64_t
535   getRepairCost(const MachineOperand &MO,
536                 const RegisterBankInfo::ValueMapping &ValMapping) const;
537 
538   /// Find the best mapping for \p MI from \p PossibleMappings.
539   /// \return a reference on the best mapping in \p PossibleMappings.
540   RegisterBankInfo::InstructionMapping &
541   findBestMapping(MachineInstr &MI,
542                   RegisterBankInfo::InstructionMappings &PossibleMappings,
543                   SmallVectorImpl<RepairingPlacement> &RepairPts);
544 
545   /// Compute the cost of mapping \p MI with \p InstrMapping and
546   /// compute the repairing placement for such mapping in \p
547   /// RepairPts.
548   /// \p BestCost is used to specify when the cost becomes too high
549   /// and thus it is not worth computing the RepairPts.  Moreover if
550   /// \p BestCost == nullptr, the mapping cost is actually not
551   /// computed.
552   MappingCost
553   computeMapping(MachineInstr &MI,
554                  const RegisterBankInfo::InstructionMapping &InstrMapping,
555                  SmallVectorImpl<RepairingPlacement> &RepairPts,
556                  const MappingCost *BestCost = nullptr);
557 
558   /// When \p RepairPt involves splitting to repair \p MO for the
559   /// given \p ValMapping, try to change the way we repair such that
560   /// the splitting is not required anymore.
561   ///
562   /// \pre \p RepairPt.hasSplit()
563   /// \pre \p MO == MO.getParent()->getOperand(\p RepairPt.getOpIdx())
564   /// \pre \p ValMapping is the mapping of \p MO for MO.getParent()
565   ///      that implied \p RepairPt.
566   void tryAvoidingSplit(RegBankSelect::RepairingPlacement &RepairPt,
567                         const MachineOperand &MO,
568                         const RegisterBankInfo::ValueMapping &ValMapping) const;
569 
570   /// Apply \p Mapping to \p MI. \p RepairPts represents the different
571   /// mapping action that need to happen for the mapping to be
572   /// applied.
573   void applyMapping(MachineInstr &MI,
574                     const RegisterBankInfo::InstructionMapping &InstrMapping,
575                     SmallVectorImpl<RepairingPlacement> &RepairPts);
576 
577 public:
578   /// Create a RegBankSelect pass with the specified \p RunningMode.
579   RegBankSelect(Mode RunningMode = Fast);
580 
getPassName()581   const char *getPassName() const override {
582     return "RegBankSelect";
583   }
584 
585   void getAnalysisUsage(AnalysisUsage &AU) const override;
586 
587   /// Walk through \p MF and assign a register bank to every virtual register
588   /// that are still mapped to nothing.
589   /// The target needs to provide a RegisterBankInfo and in particular
590   /// override RegisterBankInfo::getInstrMapping.
591   ///
592   /// Simplified algo:
593   /// \code
594   ///   RBI = MF.subtarget.getRegBankInfo()
595   ///   MIRBuilder.setMF(MF)
596   ///   for each bb in MF
597   ///     for each inst in bb
598   ///       MIRBuilder.setInstr(inst)
599   ///       MappingCosts = RBI.getMapping(inst);
600   ///       Idx = findIdxOfMinCost(MappingCosts)
601   ///       CurRegBank = MappingCosts[Idx].RegBank
602   ///       MRI.setRegBank(inst.getOperand(0).getReg(), CurRegBank)
603   ///       for each argument in inst
604   ///         if (CurRegBank != argument.RegBank)
605   ///           ArgReg = argument.getReg()
606   ///           Tmp = MRI.createNewVirtual(MRI.getSize(ArgReg), CurRegBank)
607   ///           MIRBuilder.buildInstr(COPY, Tmp, ArgReg)
608   ///           inst.getOperand(argument.getOperandNo()).setReg(Tmp)
609   /// \endcode
610   bool runOnMachineFunction(MachineFunction &MF) override;
611 };
612 } // End namespace llvm.
613 
614 #endif
615