blob: af8ef6ec1feaf09dbab31d1dd2363d4483b78af5 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===-- TargetInstrInfo.cpp - Target Instruction Information --------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the TargetInstrInfo class.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/Target/TargetInstrInfo.h"
Chris Lattner621c44d2009-08-22 20:48:53 +000015#include "llvm/MC/MCAsmInfo.h"
Evan Cheng8058d702009-05-05 00:30:09 +000016#include "llvm/Target/TargetRegisterInfo.h"
Chris Lattner1a6ef242009-08-02 04:58:19 +000017#include "llvm/Support/ErrorHandling.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000018using namespace llvm;
19
Chris Lattner5f1fdb32009-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);
31 return TRI->getRegClass(RegClass);
32}
33
34//===----------------------------------------------------------------------===//
35// TargetInstrInfo
36//===----------------------------------------------------------------------===//
37
Chris Lattner5b930372008-01-07 07:27:27 +000038TargetInstrInfo::TargetInstrInfo(const TargetInstrDesc* Desc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +000039 unsigned numOpcodes)
Chris Lattner5b930372008-01-07 07:27:27 +000040 : Descriptors(Desc), NumOpcodes(numOpcodes) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000041}
42
43TargetInstrInfo::~TargetInstrInfo() {
44}
45
Chris Lattner1a6ef242009-08-02 04:58:19 +000046/// insertNoop - Insert a noop into the instruction stream at the specified
47/// point.
48void TargetInstrInfo::insertNoop(MachineBasicBlock &MBB,
49 MachineBasicBlock::iterator MI) const {
50 llvm_unreachable("Target didn't implement insertNoop!");
51}
52
53
Dan Gohmanf17a25c2007-07-18 16:29:46 +000054bool TargetInstrInfo::isUnpredicatedTerminator(const MachineInstr *MI) const {
Chris Lattner5b930372008-01-07 07:27:27 +000055 const TargetInstrDesc &TID = MI->getDesc();
56 if (!TID.isTerminator()) return false;
Chris Lattner62327602008-01-07 01:56:04 +000057
58 // Conditional branch is a special case.
Chris Lattner5b930372008-01-07 07:27:27 +000059 if (TID.isBranch() && !TID.isBarrier())
Chris Lattner62327602008-01-07 01:56:04 +000060 return true;
Chris Lattner5b930372008-01-07 07:27:27 +000061 if (!TID.isPredicable())
Chris Lattner62327602008-01-07 01:56:04 +000062 return true;
63 return !isPredicated(MI);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000064}
Evan Cheng8058d702009-05-05 00:30:09 +000065
Chris Lattner6a66b292009-07-29 21:10:12 +000066
Chris Lattner5f1fdb32009-08-02 05:20:37 +000067/// 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.
75unsigned TargetInstrInfo::getInlineAsmLength(const char *Str,
Chris Lattner621c44d2009-08-22 20:48:53 +000076 const MCAsmInfo &TAI) const {
Chris Lattner5f1fdb32009-08-02 05:20:37 +000077
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}