blob: 84f54803a6361a228d6cab2aaaf11da41dcf802b [file] [log] [blame]
Misha Brukman2a8350a2005-02-05 02:24:26 +00001//===- AlphaInstrInfo.cpp - Alpha Instruction Information -------*- C++ -*-===//
Misha Brukman4633f1c2005-04-21 23:13:11 +00002//
Andrew Lenharth304d0f32005-01-22 23:41:55 +00003// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
Misha Brukman4633f1c2005-04-21 23:13:11 +00007//
Andrew Lenharth304d0f32005-01-22 23:41:55 +00008//===----------------------------------------------------------------------===//
9//
10// This file contains the Alpha implementation of the TargetInstrInfo class.
11//
12//===----------------------------------------------------------------------===//
13
14#include "Alpha.h"
15#include "AlphaInstrInfo.h"
16#include "AlphaGenInstrInfo.inc"
17#include "llvm/CodeGen/MachineInstrBuilder.h"
18#include <iostream>
19using namespace llvm;
20
21AlphaInstrInfo::AlphaInstrInfo()
22 : TargetInstrInfo(AlphaInsts, sizeof(AlphaInsts)/sizeof(AlphaInsts[0])) { }
23
24
25bool AlphaInstrInfo::isMoveInstr(const MachineInstr& MI,
26 unsigned& sourceReg,
27 unsigned& destReg) const {
Andrew Lenharth304d0f32005-01-22 23:41:55 +000028 MachineOpCode oc = MI.getOpcode();
Andrew Lenharthddc877c2006-03-09 18:18:51 +000029 if (oc == Alpha::BIS ||
30 oc == Alpha::CPYSS ||
31 oc == Alpha::CPYST ||
32 oc == Alpha::CPYSSt ||
33 oc == Alpha::CPYSTs) {
Andrew Lenharth5cefc5e2005-11-09 19:17:08 +000034 // or r1, r2, r2
35 // cpys(s|t) r1 r2 r2
Andrew Lenharth304d0f32005-01-22 23:41:55 +000036 assert(MI.getNumOperands() == 3 &&
37 MI.getOperand(0).isRegister() &&
38 MI.getOperand(1).isRegister() &&
39 MI.getOperand(2).isRegister() &&
40 "invalid Alpha BIS instruction!");
41 if (MI.getOperand(1).getReg() == MI.getOperand(2).getReg()) {
42 sourceReg = MI.getOperand(1).getReg();
43 destReg = MI.getOperand(0).getReg();
44 return true;
45 }
46 }
47 return false;
48}
Chris Lattner40839602006-02-02 20:12:32 +000049
50unsigned
51AlphaInstrInfo::isLoadFromStackSlot(MachineInstr *MI, int &FrameIndex) const {
52 switch (MI->getOpcode()) {
53 case Alpha::LDL:
54 case Alpha::LDQ:
55 case Alpha::LDBU:
56 case Alpha::LDWU:
57 case Alpha::LDS:
58 case Alpha::LDT:
59 if (MI->getOperand(1).isFrameIndex()) {
60 FrameIndex = MI->getOperand(1).getFrameIndex();
61 return MI->getOperand(0).getReg();
62 }
63 break;
64 }
65 return 0;
66}
67
Andrew Lenharth133d3102006-02-03 03:07:37 +000068unsigned
69AlphaInstrInfo::isStoreToStackSlot(MachineInstr *MI, int &FrameIndex) const {
70 switch (MI->getOpcode()) {
71 case Alpha::STL:
72 case Alpha::STQ:
73 case Alpha::STB:
74 case Alpha::STW:
75 case Alpha::STS:
76 case Alpha::STT:
77 if (MI->getOperand(1).isFrameIndex()) {
78 FrameIndex = MI->getOperand(1).getFrameIndex();
79 return MI->getOperand(0).getReg();
80 }
81 break;
82 }
83 return 0;
84}
85
Chris Lattner0476b282006-10-24 16:41:36 +000086void AlphaInstrInfo::InsertBranch(MachineBasicBlock &MBB,MachineBasicBlock *TBB,
87 MachineBasicBlock *FBB,
88 const std::vector<MachineOperand> &Cond)const{
89 // Can only insert uncond branches so far.
90 assert(Cond.empty() && !FBB && TBB && "Can only handle uncond branches!");
91 BuildMI(&MBB, Alpha::BR, 1).addMBB(TBB);
92}