LLVM  8.0.1
SIFixVGPRCopies.cpp
Go to the documentation of this file.
1 //===-- SIFixVGPRCopies.cpp - Fix VGPR Copies after regalloc --------------===//
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
11 /// Add implicit use of exec to vector register copies.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #include "AMDGPU.h"
16 #include "AMDGPUSubtarget.h"
17 #include "SIInstrInfo.h"
20 
21 using namespace llvm;
22 
23 #define DEBUG_TYPE "si-fix-vgpr-copies"
24 
25 namespace {
26 
27 class SIFixVGPRCopies : public MachineFunctionPass {
28 public:
29  static char ID;
30 
31 public:
32  SIFixVGPRCopies() : MachineFunctionPass(ID) {
34  }
35 
36  bool runOnMachineFunction(MachineFunction &MF) override;
37 
38  StringRef getPassName() const override { return "SI Fix VGPR copies"; }
39 };
40 
41 } // End anonymous namespace.
42 
43 INITIALIZE_PASS(SIFixVGPRCopies, DEBUG_TYPE, "SI Fix VGPR copies", false, false)
44 
45 char SIFixVGPRCopies::ID = 0;
46 
48 
49 bool SIFixVGPRCopies::runOnMachineFunction(MachineFunction &MF) {
51  const SIRegisterInfo *TRI = ST.getRegisterInfo();
52  const SIInstrInfo *TII = ST.getInstrInfo();
53  bool Changed = false;
54 
55  for (MachineBasicBlock &MBB : MF) {
56  for (MachineInstr &MI : MBB) {
57  switch (MI.getOpcode()) {
58  case AMDGPU::COPY:
59  if (TII->isVGPRCopy(MI) && !MI.readsRegister(AMDGPU::EXEC, TRI)) {
60  MI.addOperand(MF,
61  MachineOperand::CreateReg(AMDGPU::EXEC, false, true));
62  LLVM_DEBUG(dbgs() << "Add exec use to " << MI);
63  Changed = true;
64  }
65  break;
66  default:
67  break;
68  }
69  }
70  }
71 
72  return Changed;
73 }
#define DEBUG_TYPE
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
AMDGPU specific subclass of TargetSubtarget.
bool isVGPRCopy(const MachineInstr &MI) const
Definition: SIInstrInfo.h:617
This class represents lattice values for constants.
Definition: AllocatorList.h:24
void initializeSIFixVGPRCopiesPass(PassRegistry &)
const SIInstrInfo * getInstrInfo() const override
unsigned const TargetRegisterInfo * TRI
static MachineOperand CreateReg(unsigned Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isEarlyClobber=false, unsigned SubReg=0, bool isDebug=false, bool isInternalRead=false, bool isRenamable=false)
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:34
char & SIFixVGPRCopiesID
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:133
Provides AMDGPU specific target descriptions.
Representation of each machine instruction.
Definition: MachineInstr.h:64
Interface definition for SIInstrInfo.
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
#define LLVM_DEBUG(X)
Definition: Debug.h:123
const SIRegisterInfo * getRegisterInfo() const override