Chris Lattner | 0808414 | 2003-01-13 00:26:36 +0000 | [diff] [blame] | 1 | //===-- TargetInstrInfo.cpp - Target Instruction Information --------------===// |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 2 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 7 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 93fa705 | 2002-10-28 23:55:33 +0000 | [diff] [blame] | 9 | // |
Chris Lattner | 167b10c | 2005-01-19 06:53:34 +0000 | [diff] [blame] | 10 | // This file implements the TargetInstrInfo class. |
Chris Lattner | 93fa705 | 2002-10-28 23:55:33 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chris Lattner | 3501fea | 2003-01-14 22:00:31 +0000 | [diff] [blame] | 14 | #include "llvm/Target/TargetInstrInfo.h" |
Chris Lattner | af76e59 | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 15 | #include "llvm/MC/MCAsmInfo.h" |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 16 | #include "llvm/Target/TargetInstrItineraries.h" |
Evan Cheng | d923fc6 | 2009-05-05 00:30:09 +0000 | [diff] [blame] | 17 | #include "llvm/Target/TargetRegisterInfo.h" |
Chris Lattner | b6bbfebd | 2009-08-02 04:58:19 +0000 | [diff] [blame] | 18 | #include "llvm/Support/ErrorHandling.h" |
Chris Lattner | 167b10c | 2005-01-19 06:53:34 +0000 | [diff] [blame] | 19 | using namespace llvm; |
Chris Lattner | 93fa705 | 2002-10-28 23:55:33 +0000 | [diff] [blame] | 20 | |
Chris Lattner | d90183d | 2009-08-02 05:20:37 +0000 | [diff] [blame] | 21 | //===----------------------------------------------------------------------===// |
| 22 | // TargetOperandInfo |
| 23 | //===----------------------------------------------------------------------===// |
| 24 | |
| 25 | /// getRegClass - Get the register class for the operand, handling resolution |
| 26 | /// of "symbolic" pointer register classes etc. If this is not a register |
| 27 | /// operand, this returns null. |
| 28 | const TargetRegisterClass * |
| 29 | TargetOperandInfo::getRegClass(const TargetRegisterInfo *TRI) const { |
| 30 | if (isLookupPtrRegClass()) |
| 31 | return TRI->getPointerRegClass(RegClass); |
Dan Gohman | a606d95 | 2010-06-18 18:13:55 +0000 | [diff] [blame] | 32 | // Instructions like INSERT_SUBREG do not have fixed register classes. |
| 33 | if (RegClass < 0) |
| 34 | return 0; |
| 35 | // Otherwise just look it up normally. |
Chris Lattner | d90183d | 2009-08-02 05:20:37 +0000 | [diff] [blame] | 36 | return TRI->getRegClass(RegClass); |
| 37 | } |
| 38 | |
| 39 | //===----------------------------------------------------------------------===// |
| 40 | // TargetInstrInfo |
| 41 | //===----------------------------------------------------------------------===// |
| 42 | |
Chris Lattner | 749c6f6 | 2008-01-07 07:27:27 +0000 | [diff] [blame] | 43 | TargetInstrInfo::TargetInstrInfo(const TargetInstrDesc* Desc, |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 44 | unsigned numOpcodes) |
Chris Lattner | 749c6f6 | 2008-01-07 07:27:27 +0000 | [diff] [blame] | 45 | : Descriptors(Desc), NumOpcodes(numOpcodes) { |
Chris Lattner | 93fa705 | 2002-10-28 23:55:33 +0000 | [diff] [blame] | 46 | } |
| 47 | |
Chris Lattner | 0808414 | 2003-01-13 00:26:36 +0000 | [diff] [blame] | 48 | TargetInstrInfo::~TargetInstrInfo() { |
Chris Lattner | 93fa705 | 2002-10-28 23:55:33 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 51 | unsigned |
| 52 | TargetInstrInfo::getNumMicroOps(const MachineInstr *MI, |
Evan Cheng | 3ef1c87 | 2010-09-10 01:29:16 +0000 | [diff] [blame] | 53 | const InstrItineraryData *ItinData) const { |
| 54 | if (!ItinData || ItinData->isEmpty()) |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 55 | return 1; |
| 56 | |
| 57 | unsigned Class = MI->getDesc().getSchedClass(); |
Bob Wilson | 064312d | 2010-09-15 16:28:21 +0000 | [diff] [blame] | 58 | unsigned UOps = ItinData->Itineraries[Class].NumMicroOps; |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 59 | if (UOps) |
| 60 | return UOps; |
| 61 | |
| 62 | // The # of u-ops is dynamically determined. The specific target should |
| 63 | // override this function to return the right number. |
| 64 | return 1; |
| 65 | } |
| 66 | |
Chris Lattner | b6bbfebd | 2009-08-02 04:58:19 +0000 | [diff] [blame] | 67 | /// insertNoop - Insert a noop into the instruction stream at the specified |
| 68 | /// point. |
| 69 | void TargetInstrInfo::insertNoop(MachineBasicBlock &MBB, |
| 70 | MachineBasicBlock::iterator MI) const { |
| 71 | llvm_unreachable("Target didn't implement insertNoop!"); |
| 72 | } |
| 73 | |
| 74 | |
Evan Cheng | bfd2ec4 | 2007-06-08 21:59:56 +0000 | [diff] [blame] | 75 | bool TargetInstrInfo::isUnpredicatedTerminator(const MachineInstr *MI) const { |
Chris Lattner | 749c6f6 | 2008-01-07 07:27:27 +0000 | [diff] [blame] | 76 | const TargetInstrDesc &TID = MI->getDesc(); |
| 77 | if (!TID.isTerminator()) return false; |
Chris Lattner | 6924430 | 2008-01-07 01:56:04 +0000 | [diff] [blame] | 78 | |
| 79 | // Conditional branch is a special case. |
Chris Lattner | 749c6f6 | 2008-01-07 07:27:27 +0000 | [diff] [blame] | 80 | if (TID.isBranch() && !TID.isBarrier()) |
Chris Lattner | 6924430 | 2008-01-07 01:56:04 +0000 | [diff] [blame] | 81 | return true; |
Chris Lattner | 749c6f6 | 2008-01-07 07:27:27 +0000 | [diff] [blame] | 82 | if (!TID.isPredicable()) |
Chris Lattner | 6924430 | 2008-01-07 01:56:04 +0000 | [diff] [blame] | 83 | return true; |
| 84 | return !isPredicated(MI); |
Evan Cheng | bfd2ec4 | 2007-06-08 21:59:56 +0000 | [diff] [blame] | 85 | } |
Evan Cheng | d923fc6 | 2009-05-05 00:30:09 +0000 | [diff] [blame] | 86 | |
Chris Lattner | cb778a8 | 2009-07-29 21:10:12 +0000 | [diff] [blame] | 87 | |
Chris Lattner | d90183d | 2009-08-02 05:20:37 +0000 | [diff] [blame] | 88 | /// Measure the specified inline asm to determine an approximation of its |
| 89 | /// length. |
| 90 | /// Comments (which run till the next SeparatorChar or newline) do not |
| 91 | /// count as an instruction. |
| 92 | /// Any other non-whitespace text is considered an instruction, with |
| 93 | /// multiple instructions separated by SeparatorChar or newlines. |
| 94 | /// Variable-length instructions are not handled here; this function |
| 95 | /// may be overloaded in the target code to do that. |
| 96 | unsigned TargetInstrInfo::getInlineAsmLength(const char *Str, |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 97 | const MCAsmInfo &MAI) const { |
Chris Lattner | d90183d | 2009-08-02 05:20:37 +0000 | [diff] [blame] | 98 | |
| 99 | |
| 100 | // Count the number of instructions in the asm. |
| 101 | bool atInsnStart = true; |
| 102 | unsigned Length = 0; |
| 103 | for (; *Str; ++Str) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 104 | if (*Str == '\n' || *Str == MAI.getSeparatorChar()) |
Chris Lattner | d90183d | 2009-08-02 05:20:37 +0000 | [diff] [blame] | 105 | atInsnStart = true; |
| 106 | if (atInsnStart && !isspace(*Str)) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 107 | Length += MAI.getMaxInstLength(); |
Chris Lattner | d90183d | 2009-08-02 05:20:37 +0000 | [diff] [blame] | 108 | atInsnStart = false; |
| 109 | } |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 110 | if (atInsnStart && strncmp(Str, MAI.getCommentString(), |
| 111 | strlen(MAI.getCommentString())) == 0) |
Chris Lattner | d90183d | 2009-08-02 05:20:37 +0000 | [diff] [blame] | 112 | atInsnStart = false; |
| 113 | } |
| 114 | |
| 115 | return Length; |
| 116 | } |