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 | d90183d | 2009-08-02 05:20:37 +0000 | [diff] [blame^] | 15 | #include "llvm/Target/TargetAsmInfo.h" |
Evan Cheng | d923fc6 | 2009-05-05 00:30:09 +0000 | [diff] [blame] | 16 | #include "llvm/Target/TargetRegisterInfo.h" |
Chris Lattner | b6bbfebd | 2009-08-02 04:58:19 +0000 | [diff] [blame] | 17 | #include "llvm/Support/ErrorHandling.h" |
Chris Lattner | 167b10c | 2005-01-19 06:53:34 +0000 | [diff] [blame] | 18 | using namespace llvm; |
Chris Lattner | 93fa705 | 2002-10-28 23:55:33 +0000 | [diff] [blame] | 19 | |
Chris Lattner | d90183d | 2009-08-02 05:20:37 +0000 | [diff] [blame^] | 20 | //===----------------------------------------------------------------------===// |
| 21 | // TargetOperandInfo |
| 22 | //===----------------------------------------------------------------------===// |
| 23 | |
| 24 | /// getRegClass - Get the register class for the operand, handling resolution |
| 25 | /// of "symbolic" pointer register classes etc. If this is not a register |
| 26 | /// operand, this returns null. |
| 27 | const TargetRegisterClass * |
| 28 | TargetOperandInfo::getRegClass(const TargetRegisterInfo *TRI) const { |
| 29 | if (isLookupPtrRegClass()) |
| 30 | return TRI->getPointerRegClass(RegClass); |
| 31 | return TRI->getRegClass(RegClass); |
| 32 | } |
| 33 | |
| 34 | //===----------------------------------------------------------------------===// |
| 35 | // TargetInstrInfo |
| 36 | //===----------------------------------------------------------------------===// |
| 37 | |
Chris Lattner | 749c6f6 | 2008-01-07 07:27:27 +0000 | [diff] [blame] | 38 | TargetInstrInfo::TargetInstrInfo(const TargetInstrDesc* Desc, |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 39 | unsigned numOpcodes) |
Chris Lattner | 749c6f6 | 2008-01-07 07:27:27 +0000 | [diff] [blame] | 40 | : Descriptors(Desc), NumOpcodes(numOpcodes) { |
Chris Lattner | 93fa705 | 2002-10-28 23:55:33 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Chris Lattner | 0808414 | 2003-01-13 00:26:36 +0000 | [diff] [blame] | 43 | TargetInstrInfo::~TargetInstrInfo() { |
Chris Lattner | 93fa705 | 2002-10-28 23:55:33 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Chris Lattner | b6bbfebd | 2009-08-02 04:58:19 +0000 | [diff] [blame] | 46 | /// insertNoop - Insert a noop into the instruction stream at the specified |
| 47 | /// point. |
| 48 | void TargetInstrInfo::insertNoop(MachineBasicBlock &MBB, |
| 49 | MachineBasicBlock::iterator MI) const { |
| 50 | llvm_unreachable("Target didn't implement insertNoop!"); |
| 51 | } |
| 52 | |
| 53 | |
Evan Cheng | bfd2ec4 | 2007-06-08 21:59:56 +0000 | [diff] [blame] | 54 | bool TargetInstrInfo::isUnpredicatedTerminator(const MachineInstr *MI) const { |
Chris Lattner | 749c6f6 | 2008-01-07 07:27:27 +0000 | [diff] [blame] | 55 | const TargetInstrDesc &TID = MI->getDesc(); |
| 56 | if (!TID.isTerminator()) return false; |
Chris Lattner | 6924430 | 2008-01-07 01:56:04 +0000 | [diff] [blame] | 57 | |
| 58 | // Conditional branch is a special case. |
Chris Lattner | 749c6f6 | 2008-01-07 07:27:27 +0000 | [diff] [blame] | 59 | if (TID.isBranch() && !TID.isBarrier()) |
Chris Lattner | 6924430 | 2008-01-07 01:56:04 +0000 | [diff] [blame] | 60 | return true; |
Chris Lattner | 749c6f6 | 2008-01-07 07:27:27 +0000 | [diff] [blame] | 61 | if (!TID.isPredicable()) |
Chris Lattner | 6924430 | 2008-01-07 01:56:04 +0000 | [diff] [blame] | 62 | return true; |
| 63 | return !isPredicated(MI); |
Evan Cheng | bfd2ec4 | 2007-06-08 21:59:56 +0000 | [diff] [blame] | 64 | } |
Evan Cheng | d923fc6 | 2009-05-05 00:30:09 +0000 | [diff] [blame] | 65 | |
Chris Lattner | cb778a8 | 2009-07-29 21:10:12 +0000 | [diff] [blame] | 66 | |
Chris Lattner | d90183d | 2009-08-02 05:20:37 +0000 | [diff] [blame^] | 67 | /// Measure the specified inline asm to determine an approximation of its |
| 68 | /// length. |
| 69 | /// Comments (which run till the next SeparatorChar or newline) do not |
| 70 | /// count as an instruction. |
| 71 | /// Any other non-whitespace text is considered an instruction, with |
| 72 | /// multiple instructions separated by SeparatorChar or newlines. |
| 73 | /// Variable-length instructions are not handled here; this function |
| 74 | /// may be overloaded in the target code to do that. |
| 75 | unsigned TargetInstrInfo::getInlineAsmLength(const char *Str, |
| 76 | const TargetAsmInfo &TAI) const { |
| 77 | |
| 78 | |
| 79 | // Count the number of instructions in the asm. |
| 80 | bool atInsnStart = true; |
| 81 | unsigned Length = 0; |
| 82 | for (; *Str; ++Str) { |
| 83 | if (*Str == '\n' || *Str == TAI.getSeparatorChar()) |
| 84 | atInsnStart = true; |
| 85 | if (atInsnStart && !isspace(*Str)) { |
| 86 | Length += TAI.getMaxInstLength(); |
| 87 | atInsnStart = false; |
| 88 | } |
| 89 | if (atInsnStart && strncmp(Str, TAI.getCommentString(), |
| 90 | strlen(TAI.getCommentString())) == 0) |
| 91 | atInsnStart = false; |
| 92 | } |
| 93 | |
| 94 | return Length; |
| 95 | } |