Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1 | //===-- TargetInstrInfo.cpp - Target Instruction Information --------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 081ce94 | 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. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the TargetInstrInfo class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "llvm/Target/TargetInstrInfo.h" |
Chris Lattner | 621c44d | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 15 | #include "llvm/MC/MCAsmInfo.h" |
Evan Cheng | 8058d70 | 2009-05-05 00:30:09 +0000 | [diff] [blame] | 16 | #include "llvm/Target/TargetRegisterInfo.h" |
Chris Lattner | 1a6ef24 | 2009-08-02 04:58:19 +0000 | [diff] [blame] | 17 | #include "llvm/Support/ErrorHandling.h" |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 18 | using namespace llvm; |
| 19 | |
Chris Lattner | 5f1fdb3 | 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); |
Dan Gohman | 05bf7d1 | 2010-06-18 18:13:55 +0000 | [diff] [blame] | 31 | // Instructions like INSERT_SUBREG do not have fixed register classes. |
| 32 | if (RegClass < 0) |
| 33 | return 0; |
| 34 | // Otherwise just look it up normally. |
Chris Lattner | 5f1fdb3 | 2009-08-02 05:20:37 +0000 | [diff] [blame] | 35 | return TRI->getRegClass(RegClass); |
| 36 | } |
| 37 | |
| 38 | //===----------------------------------------------------------------------===// |
| 39 | // TargetInstrInfo |
| 40 | //===----------------------------------------------------------------------===// |
| 41 | |
Chris Lattner | 5b93037 | 2008-01-07 07:27:27 +0000 | [diff] [blame] | 42 | TargetInstrInfo::TargetInstrInfo(const TargetInstrDesc* Desc, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 43 | unsigned numOpcodes) |
Chris Lattner | 5b93037 | 2008-01-07 07:27:27 +0000 | [diff] [blame] | 44 | : Descriptors(Desc), NumOpcodes(numOpcodes) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | TargetInstrInfo::~TargetInstrInfo() { |
| 48 | } |
| 49 | |
Chris Lattner | 1a6ef24 | 2009-08-02 04:58:19 +0000 | [diff] [blame] | 50 | /// insertNoop - Insert a noop into the instruction stream at the specified |
| 51 | /// point. |
| 52 | void TargetInstrInfo::insertNoop(MachineBasicBlock &MBB, |
| 53 | MachineBasicBlock::iterator MI) const { |
| 54 | llvm_unreachable("Target didn't implement insertNoop!"); |
| 55 | } |
| 56 | |
| 57 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 58 | bool TargetInstrInfo::isUnpredicatedTerminator(const MachineInstr *MI) const { |
Chris Lattner | 5b93037 | 2008-01-07 07:27:27 +0000 | [diff] [blame] | 59 | const TargetInstrDesc &TID = MI->getDesc(); |
| 60 | if (!TID.isTerminator()) return false; |
Chris Lattner | 6232760 | 2008-01-07 01:56:04 +0000 | [diff] [blame] | 61 | |
| 62 | // Conditional branch is a special case. |
Chris Lattner | 5b93037 | 2008-01-07 07:27:27 +0000 | [diff] [blame] | 63 | if (TID.isBranch() && !TID.isBarrier()) |
Chris Lattner | 6232760 | 2008-01-07 01:56:04 +0000 | [diff] [blame] | 64 | return true; |
Chris Lattner | 5b93037 | 2008-01-07 07:27:27 +0000 | [diff] [blame] | 65 | if (!TID.isPredicable()) |
Chris Lattner | 6232760 | 2008-01-07 01:56:04 +0000 | [diff] [blame] | 66 | return true; |
| 67 | return !isPredicated(MI); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 68 | } |
Evan Cheng | 8058d70 | 2009-05-05 00:30:09 +0000 | [diff] [blame] | 69 | |
Chris Lattner | 6a66b29 | 2009-07-29 21:10:12 +0000 | [diff] [blame] | 70 | |
Chris Lattner | 5f1fdb3 | 2009-08-02 05:20:37 +0000 | [diff] [blame] | 71 | /// Measure the specified inline asm to determine an approximation of its |
| 72 | /// length. |
| 73 | /// Comments (which run till the next SeparatorChar or newline) do not |
| 74 | /// count as an instruction. |
| 75 | /// Any other non-whitespace text is considered an instruction, with |
| 76 | /// multiple instructions separated by SeparatorChar or newlines. |
| 77 | /// Variable-length instructions are not handled here; this function |
| 78 | /// may be overloaded in the target code to do that. |
| 79 | unsigned TargetInstrInfo::getInlineAsmLength(const char *Str, |
Chris Lattner | a5ef4d3 | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 80 | const MCAsmInfo &MAI) const { |
Chris Lattner | 5f1fdb3 | 2009-08-02 05:20:37 +0000 | [diff] [blame] | 81 | |
| 82 | |
| 83 | // Count the number of instructions in the asm. |
| 84 | bool atInsnStart = true; |
| 85 | unsigned Length = 0; |
| 86 | for (; *Str; ++Str) { |
Chris Lattner | a5ef4d3 | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 87 | if (*Str == '\n' || *Str == MAI.getSeparatorChar()) |
Chris Lattner | 5f1fdb3 | 2009-08-02 05:20:37 +0000 | [diff] [blame] | 88 | atInsnStart = true; |
| 89 | if (atInsnStart && !isspace(*Str)) { |
Chris Lattner | a5ef4d3 | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 90 | Length += MAI.getMaxInstLength(); |
Chris Lattner | 5f1fdb3 | 2009-08-02 05:20:37 +0000 | [diff] [blame] | 91 | atInsnStart = false; |
| 92 | } |
Chris Lattner | a5ef4d3 | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 93 | if (atInsnStart && strncmp(Str, MAI.getCommentString(), |
| 94 | strlen(MAI.getCommentString())) == 0) |
Chris Lattner | 5f1fdb3 | 2009-08-02 05:20:37 +0000 | [diff] [blame] | 95 | atInsnStart = false; |
| 96 | } |
| 97 | |
| 98 | return Length; |
| 99 | } |