LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ARMHazardRecognizer.cpp
Go to the documentation of this file.
1 //===-- ARMHazardRecognizer.cpp - ARM postra hazard recognizer ------------===//
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 #include "ARMHazardRecognizer.h"
11 #include "ARMBaseInstrInfo.h"
12 #include "ARMBaseRegisterInfo.h"
13 #include "ARMSubtarget.h"
17 using namespace llvm;
18 
20  const TargetRegisterInfo &TRI) {
21  // FIXME: Detect integer instructions properly.
22  const MCInstrDesc &MCID = MI->getDesc();
23  unsigned Domain = MCID.TSFlags & ARMII::DomainMask;
24  if (MI->mayStore())
25  return false;
26  unsigned Opcode = MCID.getOpcode();
27  if (Opcode == ARM::VMOVRS || Opcode == ARM::VMOVRRD)
28  return false;
29  if ((Domain & ARMII::DomainVFP) || (Domain & ARMII::DomainNEON))
30  return MI->readsRegister(DefMI->getOperand(0).getReg(), &TRI);
31  return false;
32 }
33 
36  assert(Stalls == 0 && "ARM hazards don't support scoreboard lookahead");
37 
38  MachineInstr *MI = SU->getInstr();
39 
40  if (!MI->isDebugValue()) {
41  // Look for special VMLA / VMLS hazards. A VMUL / VADD / VSUB following
42  // a VMLA / VMLS will cause 4 cycle stall.
43  const MCInstrDesc &MCID = MI->getDesc();
44  if (LastMI && (MCID.TSFlags & ARMII::DomainMask) != ARMII::DomainGeneral) {
45  MachineInstr *DefMI = LastMI;
46  const MCInstrDesc &LastMCID = LastMI->getDesc();
47  const TargetMachine &TM =
48  MI->getParent()->getParent()->getTarget();
49  const ARMBaseInstrInfo &TII =
50  *static_cast<const ARMBaseInstrInfo*>(TM.getInstrInfo());
51 
52  // Skip over one non-VFP / NEON instruction.
53  if (!LastMI->isBarrier() &&
54  // On A9, AGU and NEON/FPU are muxed.
55  !(TII.getSubtarget().isLikeA9() &&
56  (LastMI->mayLoad() || LastMI->mayStore())) &&
59  if (I != LastMI->getParent()->begin()) {
60  I = llvm::prior(I);
61  DefMI = &*I;
62  }
63  }
64 
65  if (TII.isFpMLxInstruction(DefMI->getOpcode()) &&
66  (TII.canCauseFpMLxStall(MI->getOpcode()) ||
67  hasRAWHazard(DefMI, MI, TII.getRegisterInfo()))) {
68  // Try to schedule another instruction for the next 4 cycles.
69  if (FpMLxStalls == 0)
70  FpMLxStalls = 4;
71  return Hazard;
72  }
73  }
74  }
75 
77 }
78 
80  LastMI = 0;
81  FpMLxStalls = 0;
83 }
84 
86  MachineInstr *MI = SU->getInstr();
87  if (!MI->isDebugValue()) {
88  LastMI = MI;
89  FpMLxStalls = 0;
90  }
91 
93 }
94 
96  if (FpMLxStalls && --FpMLxStalls == 0)
97  // Stalled for 4 cycles but still can't schedule any other instructions.
98  LastMI = 0;
100 }
101 
103  llvm_unreachable("reverse ARM hazard checking unsupported");
104 }
const MachineFunction * getParent() const
bool mayStore(QueryType Type=AnyInBundle) const
Definition: MachineInstr.h:479
MachineInstr * getInstr() const
Definition: ScheduleDAG.h:386
virtual HazardType getHazardType(SUnit *SU, int Stalls)
virtual void EmitInstruction(SUnit *SU)
const MCInstrDesc & getDesc() const
Definition: MachineInstr.h:257
const HexagonInstrInfo * TII
#define llvm_unreachable(msg)
bool mayLoad(QueryType Type=AnyInBundle) const
Definition: MachineInstr.h:465
bool isFpMLxInstruction(unsigned Opcode) const
bool canCauseFpMLxStall(unsigned Opcode) const
bool readsRegister(unsigned Reg, const TargetRegisterInfo *TRI=NULL) const
Definition: MachineInstr.h:724
int getOpcode() const
Definition: MachineInstr.h:261
const MachineBasicBlock * getParent() const
Definition: MachineInstr.h:119
bool isDebugValue() const
Definition: MachineInstr.h:639
bundle_iterator< MachineInstr, instr_iterator > iterator
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:267
unsigned getOpcode() const
Return the opcode number for this descriptor.
Definition: MCInstrDesc.h:181
virtual const TargetInstrInfo * getInstrInfo() const
static bool hasRAWHazard(MachineInstr *DefMI, MachineInstr *MI, const TargetRegisterInfo &TRI)
#define I(x, y, z)
Definition: MD5.cpp:54
const TargetMachine & getTarget() const
virtual HazardType getHazardType(SUnit *SU, int Stalls)
unsigned getReg() const
getReg - Returns the register number.
bool isLikeA9() const
Definition: ARMSubtarget.h:259
virtual const ARMBaseRegisterInfo & getRegisterInfo() const =0
ItTy prior(ItTy it, Dist n)
Definition: STLExtras.h:167
const ARMSubtarget & getSubtarget() const
bool isBarrier(QueryType Type=AnyInBundle) const
Definition: MachineInstr.h:356
SUnit - Scheduling unit. This is a node in the scheduling DAG.
Definition: ScheduleDAG.h:249