summaryrefslogtreecommitdiff
path: root/lib/Target/ARM/Thumb2HazardRecognizer.cpp
blob: 172908da228a852414abe6c99d504712e19561de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//===-- Thumb2HazardRecognizer.cpp - Thumb2 postra hazard recognizer ------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "ARM.h"
#include "Thumb2HazardRecognizer.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/ScheduleDAG.h"
using namespace llvm;

ScheduleHazardRecognizer::HazardType
Thumb2HazardRecognizer::getHazardType(SUnit *SU) {
  if (ITBlockSize) {
    MachineInstr *MI = SU->getInstr();
    if (!MI->isDebugValue() && MI != ITBlockMIs[ITBlockSize-1])
      return Hazard;
  }

  return PostRAHazardRecognizer::getHazardType(SU);
}

void Thumb2HazardRecognizer::Reset() {
  ITBlockSize = 0;
  PostRAHazardRecognizer::Reset();
}

void Thumb2HazardRecognizer::EmitInstruction(SUnit *SU) {
  MachineInstr *MI = SU->getInstr();
  unsigned Opcode = MI->getOpcode();
  if (ITBlockSize) {
    --ITBlockSize;
  } else if (Opcode == ARM::t2IT) {
    unsigned Mask = MI->getOperand(1).getImm();
    unsigned NumTZ = CountTrailingZeros_32(Mask);
    assert(NumTZ <= 3 && "Invalid IT mask!");
    ITBlockSize = 4 - NumTZ;
    MachineBasicBlock::iterator I = MI;
    for (unsigned i = 0; i < ITBlockSize; ++i) {
      // Advance to the next instruction, skipping any dbg_value instructions.
      do {
        ++I;
      } while (I->isDebugValue());
      ITBlockMIs[ITBlockSize-1-i] = &*I;
    }
  }

  PostRAHazardRecognizer::EmitInstruction(SU);
}