blob: 172908da228a852414abe6c99d504712e19561de [file] [log] [blame]
Evan Cheng88645942010-06-18 23:11:35 +00001//===-- Thumb2HazardRecognizer.cpp - Thumb2 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 "ARM.h"
11#include "Thumb2HazardRecognizer.h"
12#include "llvm/CodeGen/MachineInstr.h"
13#include "llvm/CodeGen/ScheduleDAG.h"
14using namespace llvm;
15
16ScheduleHazardRecognizer::HazardType
17Thumb2HazardRecognizer::getHazardType(SUnit *SU) {
18 if (ITBlockSize) {
19 MachineInstr *MI = SU->getInstr();
Evan Cheng02ba9e12010-06-19 02:36:21 +000020 if (!MI->isDebugValue() && MI != ITBlockMIs[ITBlockSize-1])
Evan Cheng88645942010-06-18 23:11:35 +000021 return Hazard;
22 }
23
24 return PostRAHazardRecognizer::getHazardType(SU);
25}
26
27void Thumb2HazardRecognizer::Reset() {
28 ITBlockSize = 0;
29 PostRAHazardRecognizer::Reset();
30}
31
32void Thumb2HazardRecognizer::EmitInstruction(SUnit *SU) {
33 MachineInstr *MI = SU->getInstr();
34 unsigned Opcode = MI->getOpcode();
35 if (ITBlockSize) {
36 --ITBlockSize;
37 } else if (Opcode == ARM::t2IT) {
38 unsigned Mask = MI->getOperand(1).getImm();
39 unsigned NumTZ = CountTrailingZeros_32(Mask);
40 assert(NumTZ <= 3 && "Invalid IT mask!");
41 ITBlockSize = 4 - NumTZ;
42 MachineBasicBlock::iterator I = MI;
43 for (unsigned i = 0; i < ITBlockSize; ++i) {
Jim Grosbache89c5e52010-06-28 21:29:17 +000044 // Advance to the next instruction, skipping any dbg_value instructions.
45 do {
Evan Cheng02ba9e12010-06-19 02:36:21 +000046 ++I;
Jim Grosbache89c5e52010-06-28 21:29:17 +000047 } while (I->isDebugValue());
Evan Cheng88645942010-06-18 23:11:35 +000048 ITBlockMIs[ITBlockSize-1-i] = &*I;
49 }
50 }
51
52 PostRAHazardRecognizer::EmitInstruction(SU);
53}