blob: c099a7eaefe7ec6b67187f6259d24a8e577c9a37 [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 Cheng1ff27272009-05-05 00:30:09 +000016#include "llvm/Target/TargetRegisterInfo.h"
Chris Lattner01614192009-08-02 04:58:19 +000017#include "llvm/Support/ErrorHandling.h"
Chris Lattnerf6932b72005-01-19 06:53:34 +000018using namespace llvm;
Chris Lattner910b82f2002-10-28 23:55:33 +000019
Chris Lattnere98a3c32009-08-02 05:20:37 +000020//===----------------------------------------------------------------------===//
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.
27const TargetRegisterClass *
28TargetOperandInfo::getRegClass(const TargetRegisterInfo *TRI) const {
29 if (isLookupPtrRegClass())
30 return TRI->getPointerRegClass(RegClass);
Dan Gohman882bb292010-06-18 18:13:55 +000031 // 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 Lattnere98a3c32009-08-02 05:20:37 +000035 return TRI->getRegClass(RegClass);
36}
37
38//===----------------------------------------------------------------------===//
39// TargetInstrInfo
40//===----------------------------------------------------------------------===//
41
Chris Lattner03ad8852008-01-07 07:27:27 +000042TargetInstrInfo::TargetInstrInfo(const TargetInstrDesc* Desc,
Misha Brukmane73e76d2005-04-22 17:54:37 +000043 unsigned numOpcodes)
Chris Lattner03ad8852008-01-07 07:27:27 +000044 : Descriptors(Desc), NumOpcodes(numOpcodes) {
Chris Lattner910b82f2002-10-28 23:55:33 +000045}
46
Chris Lattner0d5644b2003-01-13 00:26:36 +000047TargetInstrInfo::~TargetInstrInfo() {
Chris Lattner910b82f2002-10-28 23:55:33 +000048}
49
Chris Lattner01614192009-08-02 04:58:19 +000050/// insertNoop - Insert a noop into the instruction stream at the specified
51/// point.
52void TargetInstrInfo::insertNoop(MachineBasicBlock &MBB,
53 MachineBasicBlock::iterator MI) const {
54 llvm_unreachable("Target didn't implement insertNoop!");
55}
56
57
Evan Cheng5514bbe2007-06-08 21:59:56 +000058bool TargetInstrInfo::isUnpredicatedTerminator(const MachineInstr *MI) const {
Chris Lattner03ad8852008-01-07 07:27:27 +000059 const TargetInstrDesc &TID = MI->getDesc();
60 if (!TID.isTerminator()) return false;
Chris Lattnera98c6792008-01-07 01:56:04 +000061
62 // Conditional branch is a special case.
Chris Lattner03ad8852008-01-07 07:27:27 +000063 if (TID.isBranch() && !TID.isBarrier())
Chris Lattnera98c6792008-01-07 01:56:04 +000064 return true;
Chris Lattner03ad8852008-01-07 07:27:27 +000065 if (!TID.isPredicable())
Chris Lattnera98c6792008-01-07 01:56:04 +000066 return true;
67 return !isPredicated(MI);
Evan Cheng5514bbe2007-06-08 21:59:56 +000068}
Evan Cheng1ff27272009-05-05 00:30:09 +000069
Chris Lattnerf3239532009-07-29 21:10:12 +000070
Chris Lattnere98a3c32009-08-02 05:20:37 +000071/// 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.
79unsigned TargetInstrInfo::getInlineAsmLength(const char *Str,
Chris Lattnere9a75a62009-08-22 21:43:10 +000080 const MCAsmInfo &MAI) const {
Chris Lattnere98a3c32009-08-02 05:20:37 +000081
82
83 // Count the number of instructions in the asm.
84 bool atInsnStart = true;
85 unsigned Length = 0;
86 for (; *Str; ++Str) {
Chris Lattnere9a75a62009-08-22 21:43:10 +000087 if (*Str == '\n' || *Str == MAI.getSeparatorChar())
Chris Lattnere98a3c32009-08-02 05:20:37 +000088 atInsnStart = true;
89 if (atInsnStart && !isspace(*Str)) {
Chris Lattnere9a75a62009-08-22 21:43:10 +000090 Length += MAI.getMaxInstLength();
Chris Lattnere98a3c32009-08-02 05:20:37 +000091 atInsnStart = false;
92 }
Chris Lattnere9a75a62009-08-22 21:43:10 +000093 if (atInsnStart && strncmp(Str, MAI.getCommentString(),
94 strlen(MAI.getCommentString())) == 0)
Chris Lattnere98a3c32009-08-02 05:20:37 +000095 atInsnStart = false;
96 }
97
98 return Length;
99}