blob: 2e9ff16dc831813373923edca6ccb783a794329b [file] [log] [blame]
Misha Brukmana9f7f6e2003-05-30 20:17:33 +00001//===-- SparcV9CodeEmitter.h ------------------------------------*- C++ -*-===//
2//
John Criswell856ba762003-10-21 15:17:13 +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.
7//
8//===----------------------------------------------------------------------===//
9//
Brian Gaekeb75a3162004-04-15 20:23:13 +000010// Target-specific portions of the machine code emitter for the SparcV9.
11// This class interfaces with the JIT's Emitter in order to turn MachineInstrs
12// into words of binary machine code. Its code is partially generated by
13// TableGen's CodeEmitterGenerator.
Misha Brukmana9f7f6e2003-05-30 20:17:33 +000014//
15//===----------------------------------------------------------------------===//
Misha Brukman0cc640e2003-05-27 21:45:05 +000016
17#ifndef SPARCV9CODEEMITTER_H
18#define SPARCV9CODEEMITTER_H
19
Misha Brukman0d603452003-05-27 22:41:44 +000020#include "llvm/BasicBlock.h"
Misha Brukman0cc640e2003-05-27 21:45:05 +000021#include "llvm/CodeGen/MachineCodeEmitter.h"
22#include "llvm/CodeGen/MachineFunctionPass.h"
Misha Brukmana9f7f6e2003-05-30 20:17:33 +000023#include "llvm/Target/TargetMachine.h"
Misha Brukman0cc640e2003-05-27 21:45:05 +000024
Brian Gaeked0fde302003-11-11 22:41:34 +000025namespace llvm {
26
Misha Brukmanf86aaa82003-06-02 04:12:39 +000027class GlobalValue;
28class MachineInstr;
29class MachineOperand;
30
Misha Brukman0cc640e2003-05-27 21:45:05 +000031class SparcV9CodeEmitter : public MachineFunctionPass {
Misha Brukmana2196c12003-06-04 20:01:13 +000032 TargetMachine &TM;
33 MachineCodeEmitter &MCE;
Chris Lattner6856d112003-07-26 23:04:00 +000034 const BasicBlock *currBB;
Misha Brukman0cc640e2003-05-27 21:45:05 +000035
Misha Brukmanf86aaa82003-06-02 04:12:39 +000036 // Tracks which instruction references which BasicBlock
Chris Lattner6856d112003-07-26 23:04:00 +000037 std::vector<std::pair<const BasicBlock*,
Misha Brukmanf86aaa82003-06-02 04:12:39 +000038 std::pair<unsigned*,MachineInstr*> > > BBRefs;
39 // Tracks where each BasicBlock starts
Chris Lattner6856d112003-07-26 23:04:00 +000040 std::map<const BasicBlock*, long> BBLocations;
Misha Brukmana2196c12003-06-04 20:01:13 +000041
Misha Brukman0cc640e2003-05-27 21:45:05 +000042public:
Misha Brukmana2196c12003-06-04 20:01:13 +000043 SparcV9CodeEmitter(TargetMachine &T, MachineCodeEmitter &M);
Chris Lattner54a4d6a32004-11-22 20:25:10 +000044 ~SparcV9CodeEmitter() {}
Misha Brukmana9f7f6e2003-05-30 20:17:33 +000045
Brian Gaekeb75a3162004-04-15 20:23:13 +000046 const char *getPassName() const { return "SparcV9 Machine Code Emitter"; }
47
Misha Brukmana21b8e82003-07-29 20:52:56 +000048 /// runOnMachineFunction - emits the given machine function to memory.
49 ///
Misha Brukman0cc640e2003-05-27 21:45:05 +000050 bool runOnMachineFunction(MachineFunction &F);
Misha Brukmana21b8e82003-07-29 20:52:56 +000051
52 /// emitWord - writes out the given 32-bit value to memory at the current PC.
53 ///
Misha Brukmana2196c12003-06-04 20:01:13 +000054 void emitWord(unsigned Val);
Misha Brukman0cc640e2003-05-27 21:45:05 +000055
Misha Brukmana21b8e82003-07-29 20:52:56 +000056 /// getBinaryCodeForInstr - This function, generated by the
57 /// CodeEmitterGenerator using TableGen, produces the binary encoding for
58 /// machine instructions.
Misha Brukman0cc640e2003-05-27 21:45:05 +000059 ///
Misha Brukmanf86aaa82003-06-02 04:12:39 +000060 unsigned getBinaryCodeForInstr(MachineInstr &MI);
Misha Brukman0cc640e2003-05-27 21:45:05 +000061
62private:
Misha Brukmana21b8e82003-07-29 20:52:56 +000063 /// getMachineOpValue -
64 ///
Misha Brukmanf86aaa82003-06-02 04:12:39 +000065 int64_t getMachineOpValue(MachineInstr &MI, MachineOperand &MO);
Misha Brukmana21b8e82003-07-29 20:52:56 +000066
67 /// emitBasicBlock -
68 ///
Misha Brukman0cc640e2003-05-27 21:45:05 +000069 void emitBasicBlock(MachineBasicBlock &MBB);
Misha Brukmana21b8e82003-07-29 20:52:56 +000070
71 /// getValueBit -
72 ///
73 unsigned getValueBit(int64_t Val, unsigned bit);
74
75 /// getGlobalAddress -
76 ///
Misha Brukmanf86aaa82003-06-02 04:12:39 +000077 void* getGlobalAddress(GlobalValue *V, MachineInstr &MI,
78 bool isPCRelative);
Misha Brukmana21b8e82003-07-29 20:52:56 +000079 /// emitFarCall -
80 ///
Misha Brukman173e2502003-07-14 23:26:03 +000081 unsigned getRealRegNum(unsigned fakeReg, MachineInstr &MI);
Misha Brukman07d45162003-07-15 19:09:43 +000082
Misha Brukman0cc640e2003-05-27 21:45:05 +000083};
84
Brian Gaeked0fde302003-11-11 22:41:34 +000085} // End llvm namespace
86
Misha Brukman0cc640e2003-05-27 21:45:05 +000087#endif