LLVM  7.0.0
CombinerHelper.cpp
Go to the documentation of this file.
1 //== ---lib/CodeGen/GlobalISel/GICombinerHelper.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 //===----------------------------------------------------------------------===//
14 
15 #define DEBUG_TYPE "gi-combine"
16 
17 using namespace llvm;
18 
20  Builder(B), MRI(Builder.getMF().getRegInfo()) {}
21 
23  if (MI.getOpcode() != TargetOpcode::COPY)
24  return false;
25  unsigned DstReg = MI.getOperand(0).getReg();
26  unsigned SrcReg = MI.getOperand(1).getReg();
27  LLT DstTy = MRI.getType(DstReg);
28  LLT SrcTy = MRI.getType(SrcReg);
29  // Simple Copy Propagation.
30  // a(sx) = COPY b(sx) -> Replace all uses of a with b.
31  if (DstTy.isValid() && SrcTy.isValid() && DstTy == SrcTy) {
32  MI.eraseFromParent();
33  MRI.replaceRegWith(DstReg, SrcReg);
34  return true;
35  }
36  return false;
37 }
38 
40  return tryCombineCopy(MI);
41 }
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
unsigned getReg() const
getReg - Returns the register number.
bool tryCombine(MachineInstr &MI)
Try to transform MI by using all of the above combine functions.
LLT getType(unsigned Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register...
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:311
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
unsigned const MachineRegisterInfo * MRI
bool isValid() const
bool tryCombineCopy(MachineInstr &MI)
If MI is COPY, try to combine it.
This file declares the MachineIRBuilder class.
void replaceRegWith(unsigned FromReg, unsigned ToReg)
replaceRegWith - Replace all instances of FromReg with ToReg in the machine function.
Representation of each machine instruction.
Definition: MachineInstr.h:60
CombinerHelper(MachineIRBuilder &B)
IRTranslator LLVM IR MI
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:316