Evan Cheng | 8864594 | 2010-06-18 23:11:35 +0000 | [diff] [blame] | 1 | //===-- 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" |
| 14 | using namespace llvm; |
| 15 | |
| 16 | ScheduleHazardRecognizer::HazardType |
| 17 | Thumb2HazardRecognizer::getHazardType(SUnit *SU) { |
| 18 | if (ITBlockSize) { |
| 19 | MachineInstr *MI = SU->getInstr(); |
Evan Cheng | 02ba9e1 | 2010-06-19 02:36:21 +0000 | [diff] [blame^] | 20 | if (!MI->isDebugValue() && MI != ITBlockMIs[ITBlockSize-1]) |
Evan Cheng | 8864594 | 2010-06-18 23:11:35 +0000 | [diff] [blame] | 21 | return Hazard; |
| 22 | } |
| 23 | |
| 24 | return PostRAHazardRecognizer::getHazardType(SU); |
| 25 | } |
| 26 | |
| 27 | void Thumb2HazardRecognizer::Reset() { |
| 28 | ITBlockSize = 0; |
| 29 | PostRAHazardRecognizer::Reset(); |
| 30 | } |
| 31 | |
| 32 | void 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) { |
| 44 | ++I; |
Evan Cheng | 02ba9e1 | 2010-06-19 02:36:21 +0000 | [diff] [blame^] | 45 | while (I->isDebugValue()) |
| 46 | ++I; |
Evan Cheng | 8864594 | 2010-06-18 23:11:35 +0000 | [diff] [blame] | 47 | ITBlockMIs[ITBlockSize-1-i] = &*I; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | PostRAHazardRecognizer::EmitInstruction(SU); |
| 52 | } |