LLVM  4.0.0
RegBankSelect.h
Go to the documentation of this file.
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 
70 
71 namespace llvm {
72 // Forward declarations.
73 class BlockFrequency;
74 class MachineBranchProbabilityInfo;
75 class MachineBlockFrequencyInfo;
76 class MachineRegisterInfo;
77 class TargetPassConfig;
78 class TargetRegisterInfo;
79 class raw_ostream;
80 
81 /// This pass implements the reg bank selector pass used in the GlobalISel
82 /// pipeline. At the end of this pass, all register operands have been assigned
84 public:
85  static char ID;
86 
87  /// List of the modes supported by the RegBankSelect pass.
88  enum Mode {
89  /// Assign the register banks as fast as possible (default).
91  /// Greedily minimize the cost of assigning register banks.
92  /// This should produce code of greater quality, but will
93  /// require more compile time.
95  };
96 
97  /// Abstract class used to represent an insertion point in a CFG.
98  /// This class records an insertion point and materializes it on
99  /// demand.
100  /// It allows to reason about the frequency of this insertion point,
101  /// without having to logically materialize it (e.g., on an edge),
102  /// before we actually need to insert something.
103  class InsertPoint {
104  protected:
105  /// Tell if the insert point has already been materialized.
106  bool WasMaterialized = false;
107  /// Materialize the insertion point.
108  ///
109  /// If isSplit() is true, this involves actually splitting
110  /// the block or edge.
111  ///
112  /// \post getPointImpl() returns a valid iterator.
113  /// \post getInsertMBBImpl() returns a valid basic block.
114  /// \post isSplit() == false ; no more splitting should be required.
115  virtual void materialize() = 0;
116 
117  /// Return the materialized insertion basic block.
118  /// Code will be inserted into that basic block.
119  ///
120  /// \pre ::materialize has been called.
121  virtual MachineBasicBlock &getInsertMBBImpl() = 0;
122 
123  /// Return the materialized insertion point.
124  /// Code will be inserted before that point.
125  ///
126  /// \pre ::materialize has been called.
128 
129  public:
130  virtual ~InsertPoint() {}
131 
132  /// The first call to this method will cause the splitting to
133  /// happen if need be, then sub sequent calls just return
134  /// the iterator to that point. I.e., no more splitting will
135  /// occur.
136  ///
137  /// \return The iterator that should be used with
138  /// MachineBasicBlock::insert. I.e., additional code happens
139  /// before that point.
141  if (!WasMaterialized) {
142  WasMaterialized = true;
143  assert(canMaterialize() && "Impossible to materialize this point");
144  materialize();
145  }
146  // When we materialized the point we should have done the splitting.
147  assert(!isSplit() && "Wrong pre-condition");
148  return getPointImpl();
149  }
150 
151  /// The first call to this method will cause the splitting to
152  /// happen if need be, then sub sequent calls just return
153  /// the basic block that contains the insertion point.
154  /// I.e., no more splitting will occur.
155  ///
156  /// \return The basic block should be used with
157  /// MachineBasicBlock::insert and ::getPoint. The new code should
158  /// happen before that point.
160  if (!WasMaterialized) {
161  WasMaterialized = true;
162  assert(canMaterialize() && "Impossible to materialize this point");
163  materialize();
164  }
165  // When we materialized the point we should have done the splitting.
166  assert(!isSplit() && "Wrong pre-condition");
167  return getInsertMBBImpl();
168  }
169 
170  /// Insert \p MI in the just before ::getPoint()
172  return getInsertMBB().insert(getPoint(), &MI);
173  }
174 
175  /// Does this point involve splitting an edge or block?
176  /// As soon as ::getPoint is called and thus, the point
177  /// materialized, the point will not require splitting anymore,
178  /// i.e., this will return false.
179  virtual bool isSplit() const { return false; }
180 
181  /// Frequency of the insertion point.
182  /// \p P is used to access the various analysis that will help to
183  /// get that information, like MachineBlockFrequencyInfo. If \p P
184  /// does not contain enough enough to return the actual frequency,
185  /// this returns 1.
186  virtual uint64_t frequency(const Pass &P) const { return 1; }
187 
188  /// Check whether this insertion point can be materialized.
189  /// As soon as ::getPoint is called and thus, the point materialized
190  /// calling this method does not make sense.
191  virtual bool canMaterialize() const { return false; }
192  };
193 
194  /// Insertion point before or after an instruction.
195  class InstrInsertPoint : public InsertPoint {
196  private:
197  /// Insertion point.
198  MachineInstr &Instr;
199  /// Does the insertion point is before or after Instr.
200  bool Before;
201 
202  void materialize() override;
203 
204  MachineBasicBlock::iterator getPointImpl() override {
205  if (Before)
206  return Instr;
207  return Instr.getNextNode() ? *Instr.getNextNode()
208  : Instr.getParent()->end();
209  }
210 
211  MachineBasicBlock &getInsertMBBImpl() override {
212  return *Instr.getParent();
213  }
214 
215  public:
216  /// Create an insertion point before (\p Before=true) or after \p Instr.
217  InstrInsertPoint(MachineInstr &Instr, bool Before = true);
218  bool isSplit() const override;
219  uint64_t frequency(const Pass &P) const override;
220 
221  // Worst case, we need to slice the basic block, but that is still doable.
222  bool canMaterialize() const override { return true; }
223  };
224 
225  /// Insertion point at the beginning or end of a basic block.
226  class MBBInsertPoint : public InsertPoint {
227  private:
228  /// Insertion point.
229  MachineBasicBlock &MBB;
230  /// Does the insertion point is at the beginning or end of MBB.
231  bool Beginning;
232 
233  void materialize() override { /*Nothing to do to materialize*/
234  }
235 
236  MachineBasicBlock::iterator getPointImpl() override {
237  return Beginning ? MBB.begin() : MBB.end();
238  }
239 
240  MachineBasicBlock &getInsertMBBImpl() override { return MBB; }
241 
242  public:
243  MBBInsertPoint(MachineBasicBlock &MBB, bool Beginning = true)
244  : InsertPoint(), MBB(MBB), Beginning(Beginning) {
245  // If we try to insert before phis, we should use the insertion
246  // points on the incoming edges.
247  assert((!Beginning || MBB.getFirstNonPHI() == MBB.begin()) &&
248  "Invalid beginning point");
249  // If we try to insert after the terminators, we should use the
250  // points on the outcoming edges.
251  assert((Beginning || MBB.getFirstTerminator() == MBB.end()) &&
252  "Invalid end point");
253  }
254  bool isSplit() const override { return false; }
255  uint64_t frequency(const Pass &P) const override;
256  bool canMaterialize() const override { return true; };
257  };
258 
259  /// Insertion point on an edge.
260  class EdgeInsertPoint : public InsertPoint {
261  private:
262  /// Source of the edge.
263  MachineBasicBlock &Src;
264  /// Destination of the edge.
265  /// After the materialization is done, this hold the basic block
266  /// that resulted from the splitting.
267  MachineBasicBlock *DstOrSplit;
268  /// P is used to update the analysis passes as applicable.
269  Pass &P;
270 
271  void materialize() override;
272 
273  MachineBasicBlock::iterator getPointImpl() override {
274  // DstOrSplit should be the Split block at this point.
275  // I.e., it should have one predecessor, Src, and one successor,
276  // the original Dst.
277  assert(DstOrSplit && DstOrSplit->isPredecessor(&Src) &&
278  DstOrSplit->pred_size() == 1 && DstOrSplit->succ_size() == 1 &&
279  "Did not split?!");
280  return DstOrSplit->begin();
281  }
282 
283  MachineBasicBlock &getInsertMBBImpl() override { return *DstOrSplit; }
284 
285  public:
287  : InsertPoint(), Src(Src), DstOrSplit(&Dst), P(P) {}
288  bool isSplit() const override {
289  return Src.succ_size() > 1 && DstOrSplit->pred_size() > 1;
290  }
291  uint64_t frequency(const Pass &P) const override;
292  bool canMaterialize() const override;
293  };
294 
295  /// Struct used to represent the placement of a repairing point for
296  /// a given operand.
298  public:
299  /// Define the kind of action this repairing needs.
301  /// Nothing to repair, just drop this action.
303  /// Reparing code needs to happen before InsertPoints.
305  /// (Re)assign the register bank of the operand.
307  /// Mark this repairing placement as impossible.
309  };
310 
311  /// Convenient types for a list of insertion points.
312  /// @{
316  /// @}
317 
318  private:
319  /// Kind of repairing.
320  RepairingKind Kind;
321  /// Index of the operand that will be repaired.
322  unsigned OpIdx;
323  /// Are all the insert points materializeable?
324  bool CanMaterialize;
325  /// Is there any of the insert points needing splitting?
326  bool HasSplit;
327  /// Insertion point for the repair code.
328  /// The repairing code needs to happen just before these points.
329  InsertionPoints InsertPoints;
330  /// Some insertion points may need to update the liveness and such.
331  Pass &P;
332 
333  public:
334  /// Create a repairing placement for the \p OpIdx-th operand of
335  /// \p MI. \p TRI is used to make some checks on the register aliases
336  /// if the machine operand is a physical register. \p P is used to
337  /// to update liveness information and such when materializing the
338  /// points.
339  RepairingPlacement(MachineInstr &MI, unsigned OpIdx,
340  const TargetRegisterInfo &TRI, Pass &P,
341  RepairingKind Kind = RepairingKind::Insert);
342 
343  /// Getters.
344  /// @{
345  RepairingKind getKind() const { return Kind; }
346  unsigned getOpIdx() const { return OpIdx; }
347  bool canMaterialize() const { return CanMaterialize; }
348  bool hasSplit() { return HasSplit; }
349  /// @}
350 
351  /// Overloaded methods to add an insertion point.
352  /// @{
353  /// Add a MBBInsertionPoint to the list of InsertPoints.
354  void addInsertPoint(MachineBasicBlock &MBB, bool Beginning);
355  /// Add a InstrInsertionPoint to the list of InsertPoints.
356  void addInsertPoint(MachineInstr &MI, bool Before);
357  /// Add an EdgeInsertionPoint (\p Src, \p Dst) to the list of InsertPoints.
359  /// Add an InsertPoint to the list of insert points.
360  /// This method takes the ownership of &\p Point.
361  void addInsertPoint(InsertPoint &Point);
362  /// @}
363 
364  /// Accessors related to the insertion points.
365  /// @{
366  insertpt_iterator begin() { return InsertPoints.begin(); }
367  insertpt_iterator end() { return InsertPoints.end(); }
368 
369  const_insertpt_iterator begin() const { return InsertPoints.begin(); }
370  const_insertpt_iterator end() const { return InsertPoints.end(); }
371 
372  unsigned getNumInsertPoints() const { return InsertPoints.size(); }
373  /// @}
374 
375  /// Change the type of this repairing placement to \p NewKind.
376  /// It is not possible to switch a repairing placement to the
377  /// RepairingKind::Insert. There is no fundamental problem with
378  /// that, but no uses as well, so do not support it for now.
379  ///
380  /// \pre NewKind != RepairingKind::Insert
381  /// \post getKind() == NewKind
382  void switchTo(RepairingKind NewKind) {
383  assert(NewKind != Kind && "Already of the right Kind");
384  Kind = NewKind;
385  InsertPoints.clear();
386  CanMaterialize = NewKind != RepairingKind::Impossible;
387  HasSplit = false;
388  assert(NewKind != RepairingKind::Insert &&
389  "We would need more MI to switch to Insert");
390  }
391  };
392 
393 private:
394  /// Helper class used to represent the cost for mapping an instruction.
395  /// When mapping an instruction, we may introduce some repairing code.
396  /// In most cases, the repairing code is local to the instruction,
397  /// thus, we can omit the basic block frequency from the cost.
398  /// However, some alternatives may produce non-local cost, e.g., when
399  /// repairing a phi, and thus we then need to scale the local cost
400  /// to the non-local cost. This class does this for us.
401  /// \note: We could simply always scale the cost. The problem is that
402  /// there are higher chances that we saturate the cost easier and end
403  /// up having the same cost for actually different alternatives.
404  /// Another option would be to use APInt everywhere.
405  class MappingCost {
406  private:
407  /// Cost of the local instructions.
408  /// This cost is free of basic block frequency.
409  uint64_t LocalCost;
410  /// Cost of the non-local instructions.
411  /// This cost should include the frequency of the related blocks.
412  uint64_t NonLocalCost;
413  /// Frequency of the block where the local instructions live.
414  uint64_t LocalFreq;
415 
416  MappingCost(uint64_t LocalCost, uint64_t NonLocalCost, uint64_t LocalFreq)
417  : LocalCost(LocalCost), NonLocalCost(NonLocalCost),
418  LocalFreq(LocalFreq) {}
419 
420  /// Check if this cost is saturated.
421  bool isSaturated() const;
422 
423  public:
424  /// Create a MappingCost assuming that most of the instructions
425  /// will occur in a basic block with \p LocalFreq frequency.
426  MappingCost(const BlockFrequency &LocalFreq);
427 
428  /// Add \p Cost to the local cost.
429  /// \return true if this cost is saturated, false otherwise.
430  bool addLocalCost(uint64_t Cost);
431 
432  /// Add \p Cost to the non-local cost.
433  /// Non-local cost should reflect the frequency of their placement.
434  /// \return true if this cost is saturated, false otherwise.
435  bool addNonLocalCost(uint64_t Cost);
436 
437  /// Saturate the cost to the maximal representable value.
438  void saturate();
439 
440  /// Return an instance of MappingCost that represents an
441  /// impossible mapping.
442  static MappingCost ImpossibleCost();
443 
444  /// Check if this is less than \p Cost.
445  bool operator<(const MappingCost &Cost) const;
446  /// Check if this is equal to \p Cost.
447  bool operator==(const MappingCost &Cost) const;
448  /// Check if this is not equal to \p Cost.
449  bool operator!=(const MappingCost &Cost) const { return !(*this == Cost); }
450  /// Check if this is greater than \p Cost.
451  bool operator>(const MappingCost &Cost) const {
452  return *this != Cost && Cost < *this;
453  }
454 
455  /// Print this on dbgs() stream.
456  void dump() const;
457 
458  /// Print this on \p OS;
459  void print(raw_ostream &OS) const;
460 
461  /// Overload the stream operator for easy debug printing.
462  friend raw_ostream &operator<<(raw_ostream &OS, const MappingCost &Cost) {
463  Cost.print(OS);
464  return OS;
465  }
466  };
467 
468  /// Interface to the target lowering info related
469  /// to register banks.
470  const RegisterBankInfo *RBI;
471 
472  /// MRI contains all the register class/bank information that this
473  /// pass uses and updates.
474  MachineRegisterInfo *MRI;
475 
476  /// Information on the register classes for the current function.
477  const TargetRegisterInfo *TRI;
478 
479  /// Get the frequency of blocks.
480  /// This is required for non-fast mode.
481  MachineBlockFrequencyInfo *MBFI;
482 
483  /// Get the frequency of the edges.
484  /// This is required for non-fast mode.
485  MachineBranchProbabilityInfo *MBPI;
486 
487  /// Helper class used for every code morphing.
488  MachineIRBuilder MIRBuilder;
489 
490  /// Optimization mode of the pass.
491  Mode OptMode;
492 
493  /// Current target configuration. Controls how the pass handles errors.
494  const TargetPassConfig *TPC;
495 
496  /// Assign the register bank of each operand of \p MI.
497  /// \return True on success, false otherwise.
498  bool assignInstr(MachineInstr &MI);
499 
500  /// Initialize the field members using \p MF.
501  void init(MachineFunction &MF);
502 
503  /// Check if \p Reg is already assigned what is described by \p ValMapping.
504  /// \p OnlyAssign == true means that \p Reg just needs to be assigned a
505  /// register bank. I.e., no repairing is necessary to have the
506  /// assignment match.
507  bool assignmentMatch(unsigned Reg,
508  const RegisterBankInfo::ValueMapping &ValMapping,
509  bool &OnlyAssign) const;
510 
511  /// Insert repairing code for \p Reg as specified by \p ValMapping.
512  /// The repairing placement is specified by \p RepairPt.
513  /// \p NewVRegs contains all the registers required to remap \p Reg.
514  /// In other words, the number of registers in NewVRegs must be equal
515  /// to ValMapping.BreakDown.size().
516  ///
517  /// The transformation could be sketched as:
518  /// \code
519  /// ... = op Reg
520  /// \endcode
521  /// Becomes
522  /// \code
523  /// <NewRegs> = COPY or extract Reg
524  /// ... = op Reg
525  /// \endcode
526  ///
527  /// and
528  /// \code
529  /// Reg = op ...
530  /// \endcode
531  /// Becomes
532  /// \code
533  /// Reg = op ...
534  /// Reg = COPY or build_sequence <NewRegs>
535  /// \endcode
536  ///
537  /// \pre NewVRegs.size() == ValMapping.BreakDown.size()
538  ///
539  /// \note The caller is supposed to do the rewriting of op if need be.
540  /// I.e., Reg = op ... => <NewRegs> = NewOp ...
541  ///
542  /// \return True if the repairing worked, false otherwise.
543  bool repairReg(MachineOperand &MO,
544  const RegisterBankInfo::ValueMapping &ValMapping,
545  RegBankSelect::RepairingPlacement &RepairPt,
546  const iterator_range<SmallVectorImpl<unsigned>::const_iterator>
547  &NewVRegs);
548 
549  /// Return the cost of the instruction needed to map \p MO to \p ValMapping.
550  /// The cost is free of basic block frequencies.
551  /// \pre MO.isReg()
552  /// \pre MO is assigned to a register bank.
553  /// \pre ValMapping is a valid mapping for MO.
554  uint64_t
555  getRepairCost(const MachineOperand &MO,
556  const RegisterBankInfo::ValueMapping &ValMapping) const;
557 
558  /// Find the best mapping for \p MI from \p PossibleMappings.
559  /// \return a reference on the best mapping in \p PossibleMappings.
560  RegisterBankInfo::InstructionMapping &
561  findBestMapping(MachineInstr &MI,
562  RegisterBankInfo::InstructionMappings &PossibleMappings,
563  SmallVectorImpl<RepairingPlacement> &RepairPts);
564 
565  /// Compute the cost of mapping \p MI with \p InstrMapping and
566  /// compute the repairing placement for such mapping in \p
567  /// RepairPts.
568  /// \p BestCost is used to specify when the cost becomes too high
569  /// and thus it is not worth computing the RepairPts. Moreover if
570  /// \p BestCost == nullptr, the mapping cost is actually not
571  /// computed.
572  MappingCost
573  computeMapping(MachineInstr &MI,
574  const RegisterBankInfo::InstructionMapping &InstrMapping,
575  SmallVectorImpl<RepairingPlacement> &RepairPts,
576  const MappingCost *BestCost = nullptr);
577 
578  /// When \p RepairPt involves splitting to repair \p MO for the
579  /// given \p ValMapping, try to change the way we repair such that
580  /// the splitting is not required anymore.
581  ///
582  /// \pre \p RepairPt.hasSplit()
583  /// \pre \p MO == MO.getParent()->getOperand(\p RepairPt.getOpIdx())
584  /// \pre \p ValMapping is the mapping of \p MO for MO.getParent()
585  /// that implied \p RepairPt.
586  void tryAvoidingSplit(RegBankSelect::RepairingPlacement &RepairPt,
587  const MachineOperand &MO,
588  const RegisterBankInfo::ValueMapping &ValMapping) const;
589 
590  /// Apply \p Mapping to \p MI. \p RepairPts represents the different
591  /// mapping action that need to happen for the mapping to be
592  /// applied.
593  /// \return True if the mapping was applied sucessfully, false otherwise.
594  bool applyMapping(MachineInstr &MI,
595  const RegisterBankInfo::InstructionMapping &InstrMapping,
596  SmallVectorImpl<RepairingPlacement> &RepairPts);
597 
598 public:
599  /// Create a RegBankSelect pass with the specified \p RunningMode.
600  RegBankSelect(Mode RunningMode = Fast);
601 
602  StringRef getPassName() const override { return "RegBankSelect"; }
603 
604  void getAnalysisUsage(AnalysisUsage &AU) const override;
605 
610  }
611 
615  }
616 
617  /// Walk through \p MF and assign a register bank to every virtual register
618  /// that are still mapped to nothing.
619  /// The target needs to provide a RegisterBankInfo and in particular
620  /// override RegisterBankInfo::getInstrMapping.
621  ///
622  /// Simplified algo:
623  /// \code
624  /// RBI = MF.subtarget.getRegBankInfo()
625  /// MIRBuilder.setMF(MF)
626  /// for each bb in MF
627  /// for each inst in bb
628  /// MIRBuilder.setInstr(inst)
629  /// MappingCosts = RBI.getMapping(inst);
630  /// Idx = findIdxOfMinCost(MappingCosts)
631  /// CurRegBank = MappingCosts[Idx].RegBank
632  /// MRI.setRegBank(inst.getOperand(0).getReg(), CurRegBank)
633  /// for each argument in inst
634  /// if (CurRegBank != argument.RegBank)
635  /// ArgReg = argument.getReg()
636  /// Tmp = MRI.createNewVirtual(MRI.getSize(ArgReg), CurRegBank)
637  /// MIRBuilder.buildInstr(COPY, Tmp, ArgReg)
638  /// inst.getOperand(argument.getOperandNo()).setReg(Tmp)
639  /// \endcode
640  bool runOnMachineFunction(MachineFunction &MF) override;
641 };
642 
643 } // End namespace llvm.
644 
645 #endif
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:81
unsigned succ_size() const
bool canMaterialize() const override
Check whether this insertion point can be materialized.
Assign the register banks as fast as possible (default).
Definition: RegBankSelect.h:90
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
Definition: ilist_node.h:274
virtual MachineBasicBlock & getInsertMBBImpl()=0
Return the materialized insertion basic block.
insertpt_iterator begin()
Accessors related to the insertion points.
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
bool operator>(int64_t V1, const APSInt &V2)
Definition: APSInt.h:327
Reparing code needs to happen before InsertPoints.
bool isSplit() const override
Does this point involve splitting an edge or block? As soon as ::getPoint is called and thus...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Mode
List of the modes supported by the RegBankSelect pass.
Definition: RegBankSelect.h:88
void dump() const
Definition: Pass.cpp:122
void switchTo(RepairingKind NewKind)
Change the type of this repairing placement to NewKind.
MachineBasicBlock::iterator getPoint()
The first call to this method will cause the splitting to happen if need be, then sub sequent calls j...
Mark this repairing placement as impossible.
bool canMaterialize() const override
Check whether this insertion point can be materialized.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Abstract class used to represent an insertion point in a CFG.
Reg
All possible values of the reg field in the ModR/M byte.
RepairingKind
Define the kind of action this repairing needs.
const_insertpt_iterator end() const
MachineBasicBlock * MBB
virtual bool isSplit() const
Does this point involve splitting an edge or block? As soon as ::getPoint is called and thus...
virtual bool canMaterialize() const
Check whether this insertion point can be materialized.
RepairingPlacement(MachineInstr &MI, unsigned OpIdx, const TargetRegisterInfo &TRI, Pass &P, RepairingKind Kind=RepairingKind::Insert)
Create a repairing placement for the OpIdx-th operand of MI.
const MachineBasicBlock * getParent() const
Definition: MachineInstr.h:131
InsertionPoints::const_iterator const_insertpt_iterator
uint64_t frequency(const Pass &P) const override
Frequency of the insertion point.
#define P(N)
This pass implements the reg bank selector pass used in the GlobalISel pipeline.
Definition: RegBankSelect.h:83
Insertion point on an edge.
SmallVector< InstructionMapping, 4 > InstructionMappings
Convenient type to represent the alternatives for mapping an instruction.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
Definition: SmallVector.h:115
RegBankSelect(Mode RunningMode=Fast)
Create a RegBankSelect pass with the specified RunningMode.
Represent the analysis usage information of a pass.
RepairingKind getKind() const
Getters.
virtual void materialize()=0
Materialize the insertion point.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual MachineBasicBlock::iterator getPointImpl()=0
Return the materialized insertion point.
SmallVector< std::unique_ptr< InsertPoint >, 2 > InsertionPoints
Convenient types for a list of insertion points.
MBBInsertPoint(MachineBasicBlock &MBB, bool Beginning=true)
Struct used to represent the placement of a repairing point for a given operand.
SuperClass::const_iterator const_iterator
Definition: SmallVector.h:326
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:843
virtual uint64_t frequency(const Pass &P) const
Frequency of the insertion point.
MachineBasicBlock & getInsertMBB()
The first call to this method will cause the splitting to happen if need be, then sub sequent calls j...
This file declares the MachineIRBuilder class.
InsertionPoints::iterator insertpt_iterator
MachineFunctionProperties getSetProperties() const override
RegisterBankInfo(RegisterBank **RegBanks, unsigned NumRegBanks)
Create a RegisterBankInfo that can accomodate up to NumRegBanks RegisterBank instances.
MachineFunctionProperties & set(Property P)
bool operator!=(uint64_t V1, const APInt &V2)
Definition: APInt.h:1724
const_insertpt_iterator begin() const
Representation of each machine instruction.
Definition: MachineInstr.h:52
bool canMaterialize() const override
Check whether this insertion point can be materialized.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Definition: SmallVector.h:119
bool isSplit() const override
Does this point involve splitting an edge or block? As soon as ::getPoint is called and thus...
Insertion point before or after an instruction.
EdgeInsertPoint(MachineBasicBlock &Src, MachineBasicBlock &Dst, Pass &P)
InstrInsertPoint(MachineInstr &Instr, bool Before=true)
Create an insertion point before (Before=true) or after Instr.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Definition: SmallVector.h:135
uint64_t frequency(const Pass &P) const override
Frequency of the insertion point.
bool WasMaterialized
Tell if the insert point has already been materialized.
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
void addInsertPoint(MachineBasicBlock &MBB, bool Beginning)
Overloaded methods to add an insertion point.
iterator getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
bool runOnMachineFunction(MachineFunction &MF) override
Walk through MF and assign a register bank to every virtual register that are still mapped to nothing...
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
Definition: APInt.h:1726
MachineFunctionProperties getRequiredProperties() const override
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool operator<(int64_t V1, const APSInt &V2)
Definition: APSInt.h:326
(Re)assign the register bank of the operand.
IRTranslator LLVM IR MI
bool isPredecessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a predecessor of this block.
virtual void print(raw_ostream &O, const Module *M) const
print - Print out the internal state of the pass.
Definition: Pass.cpp:117
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
bool operator==(uint64_t V1, const APInt &V2)
Definition: APInt.h:1722
uint64_t frequency(const Pass &P) const override
Frequency of the insertion point.
Greedily minimize the cost of assigning register banks.
Definition: RegBankSelect.h:94
unsigned pred_size() const
Insertion point at the beginning or end of a basic block.
MachineBasicBlock::iterator insert(MachineInstr &MI)
Insert MI in the just before ::getPoint()
Nothing to repair, just drop this action.
Properties which a MachineFunction may have at a given point in time.
bool isSplit() const override
Does this point involve splitting an edge or block? As soon as ::getPoint is called and thus...