Chris Lattner | 0d5644b | 2003-01-13 00:26:36 +0000 | [diff] [blame] | 1 | //===-- TargetInstrInfo.cpp - Target Instruction Information --------------===// |
Misha Brukman | 10468d8 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 2 | // |
John Criswell | 482202a | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 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 | 10468d8 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 7 | // |
John Criswell | 482202a | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 910b82f | 2002-10-28 23:55:33 +0000 | [diff] [blame] | 9 | // |
Chris Lattner | f6932b7 | 2005-01-19 06:53:34 +0000 | [diff] [blame] | 10 | // This file implements the TargetInstrInfo class. |
Chris Lattner | 910b82f | 2002-10-28 23:55:33 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chris Lattner | b4d58d7 | 2003-01-14 22:00:31 +0000 | [diff] [blame] | 14 | #include "llvm/Target/TargetInstrInfo.h" |
Evan Cheng | 1ff2727 | 2009-05-05 00:30:09 +0000 | [diff] [blame] | 15 | #include "llvm/Target/TargetRegisterInfo.h" |
Evan Cheng | 49d4c0b | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 16 | #include "llvm/MC/MCAsmInfo.h" |
Evan Cheng | 8264e27 | 2011-06-29 01:14:12 +0000 | [diff] [blame] | 17 | #include "llvm/MC/MCInstrItineraries.h" |
Chris Lattner | 0161419 | 2009-08-02 04:58:19 +0000 | [diff] [blame] | 18 | #include "llvm/Support/ErrorHandling.h" |
Nick Lewycky | 0de20af | 2010-12-19 20:43:38 +0000 | [diff] [blame] | 19 | #include <cctype> |
Chris Lattner | f6932b7 | 2005-01-19 06:53:34 +0000 | [diff] [blame] | 20 | using namespace llvm; |
Chris Lattner | 910b82f | 2002-10-28 23:55:33 +0000 | [diff] [blame] | 21 | |
Chris Lattner | e98a3c3 | 2009-08-02 05:20:37 +0000 | [diff] [blame] | 22 | //===----------------------------------------------------------------------===// |
Chris Lattner | e98a3c3 | 2009-08-02 05:20:37 +0000 | [diff] [blame] | 23 | // TargetInstrInfo |
Andrew Trick | 596af1b | 2012-06-08 17:23:27 +0000 | [diff] [blame] | 24 | // |
| 25 | // Methods that depend on CodeGen are implemented in |
| 26 | // TargetInstrInfoImpl.cpp. Invoking them without linking libCodeGen raises a |
| 27 | // link error. |
| 28 | // ===----------------------------------------------------------------------===// |
Chris Lattner | e98a3c3 | 2009-08-02 05:20:37 +0000 | [diff] [blame] | 29 | |
Chris Lattner | 0d5644b | 2003-01-13 00:26:36 +0000 | [diff] [blame] | 30 | TargetInstrInfo::~TargetInstrInfo() { |
Chris Lattner | 910b82f | 2002-10-28 23:55:33 +0000 | [diff] [blame] | 31 | } |
| 32 | |
Evan Cheng | 8d71a75 | 2011-06-27 21:26:13 +0000 | [diff] [blame] | 33 | const TargetRegisterClass* |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 34 | TargetInstrInfo::getRegClass(const MCInstrDesc &MCID, unsigned OpNum, |
Jakob Stoklund Olesen | 3c52f02 | 2012-05-07 22:10:26 +0000 | [diff] [blame] | 35 | const TargetRegisterInfo *TRI, |
| 36 | const MachineFunction &MF) const { |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 37 | if (OpNum >= MCID.getNumOperands()) |
Evan Cheng | 8d71a75 | 2011-06-27 21:26:13 +0000 | [diff] [blame] | 38 | return 0; |
| 39 | |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 40 | short RegClass = MCID.OpInfo[OpNum].RegClass; |
| 41 | if (MCID.OpInfo[OpNum].isLookupPtrRegClass()) |
Jakob Stoklund Olesen | 3c52f02 | 2012-05-07 22:10:26 +0000 | [diff] [blame] | 42 | return TRI->getPointerRegClass(MF, RegClass); |
Evan Cheng | 8d71a75 | 2011-06-27 21:26:13 +0000 | [diff] [blame] | 43 | |
| 44 | // Instructions like INSERT_SUBREG do not have fixed register classes. |
| 45 | if (RegClass < 0) |
| 46 | return 0; |
| 47 | |
| 48 | // Otherwise just look it up normally. |
| 49 | return TRI->getRegClass(RegClass); |
| 50 | } |
| 51 | |
Chris Lattner | 0161419 | 2009-08-02 04:58:19 +0000 | [diff] [blame] | 52 | /// insertNoop - Insert a noop into the instruction stream at the specified |
| 53 | /// point. |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 54 | void TargetInstrInfo::insertNoop(MachineBasicBlock &MBB, |
Chris Lattner | 0161419 | 2009-08-02 04:58:19 +0000 | [diff] [blame] | 55 | MachineBasicBlock::iterator MI) const { |
| 56 | llvm_unreachable("Target didn't implement insertNoop!"); |
| 57 | } |
| 58 | |
Chris Lattner | e98a3c3 | 2009-08-02 05:20:37 +0000 | [diff] [blame] | 59 | /// Measure the specified inline asm to determine an approximation of its |
| 60 | /// length. |
Jim Grosbach | a3df87f | 2011-03-24 18:46:34 +0000 | [diff] [blame] | 61 | /// Comments (which run till the next SeparatorString or newline) do not |
Chris Lattner | e98a3c3 | 2009-08-02 05:20:37 +0000 | [diff] [blame] | 62 | /// count as an instruction. |
| 63 | /// Any other non-whitespace text is considered an instruction, with |
Jim Grosbach | a3df87f | 2011-03-24 18:46:34 +0000 | [diff] [blame] | 64 | /// multiple instructions separated by SeparatorString or newlines. |
Chris Lattner | e98a3c3 | 2009-08-02 05:20:37 +0000 | [diff] [blame] | 65 | /// Variable-length instructions are not handled here; this function |
| 66 | /// may be overloaded in the target code to do that. |
| 67 | unsigned TargetInstrInfo::getInlineAsmLength(const char *Str, |
Chris Lattner | e9a75a6 | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 68 | const MCAsmInfo &MAI) const { |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 69 | |
| 70 | |
Chris Lattner | e98a3c3 | 2009-08-02 05:20:37 +0000 | [diff] [blame] | 71 | // Count the number of instructions in the asm. |
| 72 | bool atInsnStart = true; |
| 73 | unsigned Length = 0; |
| 74 | for (; *Str; ++Str) { |
Jim Grosbach | a3df87f | 2011-03-24 18:46:34 +0000 | [diff] [blame] | 75 | if (*Str == '\n' || strncmp(Str, MAI.getSeparatorString(), |
| 76 | strlen(MAI.getSeparatorString())) == 0) |
Chris Lattner | e98a3c3 | 2009-08-02 05:20:37 +0000 | [diff] [blame] | 77 | atInsnStart = true; |
Nick Lewycky | b71afe8 | 2010-12-19 20:42:43 +0000 | [diff] [blame] | 78 | if (atInsnStart && !std::isspace(*Str)) { |
Chris Lattner | e9a75a6 | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 79 | Length += MAI.getMaxInstLength(); |
Chris Lattner | e98a3c3 | 2009-08-02 05:20:37 +0000 | [diff] [blame] | 80 | atInsnStart = false; |
| 81 | } |
Chris Lattner | e9a75a6 | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 82 | if (atInsnStart && strncmp(Str, MAI.getCommentString(), |
| 83 | strlen(MAI.getCommentString())) == 0) |
Chris Lattner | e98a3c3 | 2009-08-02 05:20:37 +0000 | [diff] [blame] | 84 | atInsnStart = false; |
| 85 | } |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 86 | |
Chris Lattner | e98a3c3 | 2009-08-02 05:20:37 +0000 | [diff] [blame] | 87 | return Length; |
| 88 | } |