LLVM  5.0.0
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 /// \brief Add implicit use of exec to vector register copies.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #include "AMDGPU.h"
16 #include "AMDGPUSubtarget.h"
17 #include "SIInstrInfo.h"
19 
20 using namespace llvm;
21 
22 #define DEBUG_TYPE "si-fix-vgpr-copies"
23 
24 namespace {
25 
26 class SIFixVGPRCopies : public MachineFunctionPass {
27 public:
28  static char ID;
29 
30 public:
31  SIFixVGPRCopies() : MachineFunctionPass(ID) {
33  }
34 
35  bool runOnMachineFunction(MachineFunction &MF) override;
36 
37  StringRef getPassName() const override { return "SI Fix VGPR copies"; }
38 };
39 
40 } // End anonymous namespace.
41 
42 INITIALIZE_PASS(SIFixVGPRCopies, DEBUG_TYPE, "SI Fix VGPR copies", false, false)
43 
44 char SIFixVGPRCopies::ID = 0;
45 
46 char &llvm::SIFixVGPRCopiesID = SIFixVGPRCopies::ID;
47 
48 bool SIFixVGPRCopies::runOnMachineFunction(MachineFunction &MF) {
49  const SISubtarget &ST = MF.getSubtarget<SISubtarget>();
50  const SIRegisterInfo *TRI = ST.getRegisterInfo();
51  const SIInstrInfo *TII = ST.getInstrInfo();
52  bool Changed = false;
53 
54  for (MachineBasicBlock &MBB : MF) {
55  for (MachineInstr &MI : MBB) {
56  switch (MI.getOpcode()) {
57  case AMDGPU::COPY:
58  if (TII->isVGPRCopy(MI) && !MI.readsRegister(AMDGPU::EXEC, TRI)) {
59  MI.addOperand(MF,
60  MachineOperand::CreateReg(AMDGPU::EXEC, false, true));
61  DEBUG(dbgs() << "Add exec use to " << MI);
62  Changed = true;
63  }
64  break;
65  default:
66  break;
67  }
68  }
69  }
70 
71  return Changed;
72 }
#define DEBUG_TYPE
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
AMDGPU specific subclass of TargetSubtarget.
void initializeSIFixVGPRCopiesPass(PassRegistry &)
const SIInstrInfo * getInstrInfo() const override
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
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)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:34
const SIRegisterInfo * getRegisterInfo() const override
char & SIFixVGPRCopiesID
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
Representation of each machine instruction.
Definition: MachineInstr.h:59
Interface definition for SIInstrInfo.
bool isVGPRCopy(const MachineInstr &MI) const
Definition: SIInstrInfo.h:533
#define DEBUG(X)
Definition: Debug.h:118
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49