LLVM  7.0.0
HexagonGatherPacketize.cpp
Go to the documentation of this file.
1 //===- HexagonGatherPacketize.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 // This pass ensures that producer and consumer of VTMP are paired in a bundle.
10 //===----------------------------------------------------------------------===//
11 
12 #define DEBUG_TYPE "gather-packetize"
13 
14 #include "HexagonTargetMachine.h"
18 #include "llvm/Support/Debug.h"
19 using namespace llvm;
20 
22  "hexagon-enable-gather-packetize", cl::Hidden, cl::init(true),
23  cl::desc("Generate gather packets before packetization"));
24 
25 namespace llvm {
28 }
29 
30 namespace {
31 class HexagonGatherPacketize : public MachineFunctionPass {
32 public:
33  static char ID;
34  HexagonGatherPacketize() : MachineFunctionPass(ID) {
37  }
38 
39  StringRef getPassName() const override {
40  return "Hexagon Gather Packetize Code";
41  }
42  bool runOnMachineFunction(MachineFunction &Fn) override;
43 };
44 
46 
47 static inline bool isVtmpDef(const MachineInstr &MI) {
48  for (const MachineOperand &MO : MI.operands())
49  if (MO.isReg() && MO.isDef() && MO.isImplicit() &&
50  (MO.getReg() == Hexagon::VTMP)) {
51  return true;
52  }
53  return false;
54 }
55 
56 static inline bool isVtmpUse(const MachineInstr &MI) {
57  return (MI.mayStore() && (MI.getOperand(2)).isReg() &&
58  ((MI.getOperand(2)).getReg() == Hexagon::VTMP));
59 }
60 
61 bool HexagonGatherPacketize::runOnMachineFunction(MachineFunction &Fn) {
63  return false;
64  auto &ST = Fn.getSubtarget<HexagonSubtarget>();
65  bool HasV65 = ST.hasV65Ops();
66  bool UseHVX = ST.useHVXOps();
67  if (!(HasV65 & UseHVX))
68  return false;
69 
70  for (auto &MBB : Fn) {
71  bool VtmpDef = false;
72  MachineBasicBlock::iterator MII, MIE, DefMII;
73  for (MII = MBB.begin(), MIE = MBB.end(); MII != MIE; ++MII) {
74  MachineInstr &MI = *MII;
75  if (VtmpDef) {
76  if (!isVtmpUse(MI))
77  continue;
78  MBB.splice(std::next(DefMII), &MBB, MII);
79  finalizeBundle(MBB, DefMII.getInstrIterator(),
80  std::next(MII).getInstrIterator());
81  VtmpDef = false;
82  continue;
83  }
84  if (!(isVtmpDef(MI)))
85  continue;
86  VtmpDef = true;
87  DefMII = MII;
88  }
89  assert(!VtmpDef && "VTMP producer and consumer not in same block");
90  }
91  return true;
92 }
93 }
94 
95 //===----------------------------------------------------------------------===//
96 // Public Constructor Functions
97 //===----------------------------------------------------------------------===//
98 
99 INITIALIZE_PASS(HexagonGatherPacketize, "hexagon-gather-packetize",
100  "Hexagon gather packetize Code", false, false)
101 
103  return new HexagonGatherPacketize();
104 }
static bool isReg(const MCInst &MI, unsigned OpNo)
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
A global registry used in conjunction with static constructors to make pluggable components (like tar...
Definition: Registry.h:45
iterator_range< mop_iterator > operands()
Definition: MachineInstr.h:361
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
bool mayStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly modify memory.
Definition: MachineInstr.h:672
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:410
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
INITIALIZE_PASS(HexagonGatherPacketize, "hexagon-gather-packetize", "Hexagon gather packetize Code", false, false) FunctionPass *llvm
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:285
MachineOperand class - Representation of each machine instruction operand.
FunctionPass * createHexagonGatherPacketize()
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
Representation of each machine instruction.
Definition: MachineInstr.h:60
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
cl::opt< bool > EnableGatherPacketize("hexagon-enable-gather-packetize", cl::Hidden, cl::init(true), cl::desc("Generate gather packets before packetization"))
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Definition: PassRegistry.h:39
void initializeHexagonGatherPacketizePass(PassRegistry &)
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:316
void finalizeBundle(MachineBasicBlock &MBB, MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
finalizeBundle - Finalize a machine instruction bundle which includes a sequence of instructions star...