LLVM  7.0.0
Combiner.cpp
Go to the documentation of this file.
1 //===-- lib/CodeGen/GlobalISel/GICombiner.cpp -----------------------===//
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 // This file constains common code to combine machine functions at generic
11 // level.
12 //===----------------------------------------------------------------------===//
13 
22 #include "llvm/Support/Debug.h"
23 
24 #define DEBUG_TYPE "gi-combiner"
25 
26 using namespace llvm;
27 
29  : CInfo(Info), TPC(TPC) {
30  (void)this->TPC; // FIXME: Remove when used.
31 }
32 
34  // If the ISel pipeline failed, do not bother running this pass.
35  // FIXME: Should this be here or in individual combiner passes.
36  if (MF.getProperties().hasProperty(
38  return false;
39 
40  MRI = &MF.getRegInfo();
41  Builder.setMF(MF);
42 
43  LLVM_DEBUG(dbgs() << "Generic MI Combiner for: " << MF.getName() << '\n');
44 
45  MachineOptimizationRemarkEmitter MORE(MF, /*MBFI=*/nullptr);
46 
47  bool MFChanged = false;
48  bool Changed;
49 
50  do {
51  // Collect all instructions. Do a post order traversal for basic blocks and
52  // insert with list bottom up, so while we pop_back_val, we'll traverse top
53  // down RPOT.
54  Changed = false;
55  GISelWorkList<512> WorkList;
56  for (MachineBasicBlock *MBB : post_order(&MF)) {
57  if (MBB->empty())
58  continue;
59  for (auto MII = MBB->rbegin(), MIE = MBB->rend(); MII != MIE;) {
60  MachineInstr *CurMI = &*MII;
61  ++MII;
62  // Erase dead insts before even adding to the list.
63  if (isTriviallyDead(*CurMI, *MRI)) {
64  LLVM_DEBUG(dbgs() << *CurMI << "Is dead; erasing.\n");
66  continue;
67  }
68  WorkList.insert(CurMI);
69  }
70  }
71  // Main Loop. Process the instructions here.
72  while (!WorkList.empty()) {
73  MachineInstr *CurrInst = WorkList.pop_back_val();
74  LLVM_DEBUG(dbgs() << "Try combining " << *CurrInst << "\n";);
75  Changed |= CInfo.combine(*CurrInst, Builder);
76  }
77  MFChanged |= Changed;
78  } while (Changed);
79 
80  return MFChanged;
81 }
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
const MachineFunctionProperties & getProperties() const
Get the function properties.
bool empty() const
Definition: GISelWorkList.h:33
Combiner(CombinerInfo &CombinerInfo, const TargetPassConfig *TPC)
Definition: Combiner.cpp:28
void setMF(MachineFunction &)
Target-Independent Code Generator Pass Configuration Options.
void eraseFromParentAndMarkDBGValuesForRemoval()
Unlink &#39;this&#39; from the containing basic block and delete it.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
===- MachineOptimizationRemarkEmitter.h - Opt Diagnostics -*- C++ -*-—===//
CombinerInfo & CInfo
Definition: Combiner.h:34
iterator_range< po_iterator< T > > post_order(const T &G)
bool combineMachineInstrs(MachineFunction &MF)
Definition: Combiner.cpp:33
The optimization diagnostic interface.
#define MORE()
Definition: regcomp.c:251
MachineInstr * pop_back_val()
Definition: GISelWorkList.h:56
void insert(MachineInstr *I)
Add - Add the specified instruction to the worklist if it isn&#39;t already in it.
Definition: GISelWorkList.h:39
This file declares the MachineIRBuilder class.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:133
MachineRegisterInfo * MRI
Definition: Combiner.h:36
bool isTriviallyDead(const MachineInstr &MI, const MachineRegisterInfo &MRI)
Check whether an instruction MI is dead: it only defines dead virtual registers, and doesn&#39;t have oth...
Definition: Utils.cpp:135
Representation of each machine instruction.
Definition: MachineInstr.h:60
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
MachineIRBuilder Builder
Definition: Combiner.h:38
bool hasProperty(Property P) const
virtual bool combine(MachineInstr &MI, MachineIRBuilder &B) const =0
#define LLVM_DEBUG(X)
Definition: Debug.h:119