blob: 47cd0fbe163369f0e95707c5aff6835ba617e30f [file] [log] [blame]
Chris Lattner0d5644b2003-01-13 00:26:36 +00001//===-- TargetInstrInfo.cpp - Target Instruction Information --------------===//
Misha Brukman10468d82005-04-21 22:55:34 +00002//
John Criswell482202a2003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukman10468d82005-04-21 22:55:34 +00007//
John Criswell482202a2003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Chris Lattner910b82f2002-10-28 23:55:33 +00009//
Chris Lattnerf6932b72005-01-19 06:53:34 +000010// This file implements the TargetInstrInfo class.
Chris Lattner910b82f2002-10-28 23:55:33 +000011//
12//===----------------------------------------------------------------------===//
13
Chris Lattnerb4d58d72003-01-14 22:00:31 +000014#include "llvm/Target/TargetInstrInfo.h"
Chris Lattner7b26fce2009-08-22 20:48:53 +000015#include "llvm/MC/MCAsmInfo.h"
Evan Cheng367a5df2010-09-09 18:18:55 +000016#include "llvm/Target/TargetInstrItineraries.h"
Evan Cheng1ff27272009-05-05 00:30:09 +000017#include "llvm/Target/TargetRegisterInfo.h"
Chris Lattner01614192009-08-02 04:58:19 +000018#include "llvm/Support/ErrorHandling.h"
Chris Lattnerf6932b72005-01-19 06:53:34 +000019using namespace llvm;
Chris Lattner910b82f2002-10-28 23:55:33 +000020
Chris Lattnere98a3c32009-08-02 05:20:37 +000021//===----------------------------------------------------------------------===//
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.
28const TargetRegisterClass *
29TargetOperandInfo::getRegClass(const TargetRegisterInfo *TRI) const {
30 if (isLookupPtrRegClass())
31 return TRI->getPointerRegClass(RegClass);
Dan Gohman882bb292010-06-18 18:13:55 +000032 // 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 Lattnere98a3c32009-08-02 05:20:37 +000036 return TRI->getRegClass(RegClass);
37}
38
39//===----------------------------------------------------------------------===//
40// TargetInstrInfo
41//===----------------------------------------------------------------------===//
42
Chris Lattner03ad8852008-01-07 07:27:27 +000043TargetInstrInfo::TargetInstrInfo(const TargetInstrDesc* Desc,
Misha Brukmane73e76d2005-04-22 17:54:37 +000044 unsigned numOpcodes)
Chris Lattner03ad8852008-01-07 07:27:27 +000045 : Descriptors(Desc), NumOpcodes(numOpcodes) {
Chris Lattner910b82f2002-10-28 23:55:33 +000046}
47
Chris Lattner0d5644b2003-01-13 00:26:36 +000048TargetInstrInfo::~TargetInstrInfo() {
Chris Lattner910b82f2002-10-28 23:55:33 +000049}
50
Evan Cheng367a5df2010-09-09 18:18:55 +000051unsigned
52TargetInstrInfo::getNumMicroOps(const MachineInstr *MI,
Evan Chengbf407072010-09-10 01:29:16 +000053 const InstrItineraryData *ItinData) const {
54 if (!ItinData || ItinData->isEmpty())
Evan Cheng367a5df2010-09-09 18:18:55 +000055 return 1;
56
57 unsigned Class = MI->getDesc().getSchedClass();
Evan Chengbf407072010-09-10 01:29:16 +000058 unsigned UOps = ItinData->Itineratries[Class].NumMicroOps;
Evan Cheng367a5df2010-09-09 18:18:55 +000059 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 Lattner01614192009-08-02 04:58:19 +000067/// insertNoop - Insert a noop into the instruction stream at the specified
68/// point.
69void TargetInstrInfo::insertNoop(MachineBasicBlock &MBB,
70 MachineBasicBlock::iterator MI) const {
71 llvm_unreachable("Target didn't implement insertNoop!");
72}
73
74
Evan Cheng5514bbe2007-06-08 21:59:56 +000075bool TargetInstrInfo::isUnpredicatedTerminator(const MachineInstr *MI) const {
Chris Lattner03ad8852008-01-07 07:27:27 +000076 const TargetInstrDesc &TID = MI->getDesc();
77 if (!TID.isTerminator()) return false;
Chris Lattnera98c6792008-01-07 01:56:04 +000078
79 // Conditional branch is a special case.
Chris Lattner03ad8852008-01-07 07:27:27 +000080 if (TID.isBranch() && !TID.isBarrier())
Chris Lattnera98c6792008-01-07 01:56:04 +000081 return true;
Chris Lattner03ad8852008-01-07 07:27:27 +000082 if (!TID.isPredicable())
Chris Lattnera98c6792008-01-07 01:56:04 +000083 return true;
84 return !isPredicated(MI);
Evan Cheng5514bbe2007-06-08 21:59:56 +000085}
Evan Cheng1ff27272009-05-05 00:30:09 +000086
Chris Lattnerf3239532009-07-29 21:10:12 +000087
Chris Lattnere98a3c32009-08-02 05:20:37 +000088/// 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.
96unsigned TargetInstrInfo::getInlineAsmLength(const char *Str,
Chris Lattnere9a75a62009-08-22 21:43:10 +000097 const MCAsmInfo &MAI) const {
Chris Lattnere98a3c32009-08-02 05:20:37 +000098
99
100 // Count the number of instructions in the asm.
101 bool atInsnStart = true;
102 unsigned Length = 0;
103 for (; *Str; ++Str) {
Chris Lattnere9a75a62009-08-22 21:43:10 +0000104 if (*Str == '\n' || *Str == MAI.getSeparatorChar())
Chris Lattnere98a3c32009-08-02 05:20:37 +0000105 atInsnStart = true;
106 if (atInsnStart && !isspace(*Str)) {
Chris Lattnere9a75a62009-08-22 21:43:10 +0000107 Length += MAI.getMaxInstLength();
Chris Lattnere98a3c32009-08-02 05:20:37 +0000108 atInsnStart = false;
109 }
Chris Lattnere9a75a62009-08-22 21:43:10 +0000110 if (atInsnStart && strncmp(Str, MAI.getCommentString(),
111 strlen(MAI.getCommentString())) == 0)
Chris Lattnere98a3c32009-08-02 05:20:37 +0000112 atInsnStart = false;
113 }
114
115 return Length;
116}