blob: 2e9ff16dc831813373923edca6ccb783a794329b [file] [log] [blame]
Misha Brukman5bf351c2003-05-30 20:17:33 +00001//===-- SparcV9CodeEmitter.h ------------------------------------*- C++ -*-===//
2//
John Criswell29265fe2003-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 Gaeke5bee0f32004-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 Brukman5bf351c2003-05-30 20:17:33 +000014//
15//===----------------------------------------------------------------------===//
Misha Brukmane195b7c2003-05-27 21:45:05 +000016
17#ifndef SPARCV9CODEEMITTER_H
18#define SPARCV9CODEEMITTER_H
19
Misha Brukman79756612003-05-27 22:41:44 +000020#include "llvm/BasicBlock.h"
Misha Brukmane195b7c2003-05-27 21:45:05 +000021#include "llvm/CodeGen/MachineCodeEmitter.h"
22#include "llvm/CodeGen/MachineFunctionPass.h"
Misha Brukman5bf351c2003-05-30 20:17:33 +000023#include "llvm/Target/TargetMachine.h"
Misha Brukmane195b7c2003-05-27 21:45:05 +000024
Brian Gaeke960707c2003-11-11 22:41:34 +000025namespace llvm {
26
Misha Brukmance62d362003-06-02 04:12:39 +000027class GlobalValue;
28class MachineInstr;
29class MachineOperand;
30
Misha Brukmane195b7c2003-05-27 21:45:05 +000031class SparcV9CodeEmitter : public MachineFunctionPass {
Misha Brukmanefafdf82003-06-04 20:01:13 +000032 TargetMachine &TM;
33 MachineCodeEmitter &MCE;
Chris Lattner99dbdf72003-07-26 23:04:00 +000034 const BasicBlock *currBB;
Misha Brukmane195b7c2003-05-27 21:45:05 +000035
Misha Brukmance62d362003-06-02 04:12:39 +000036 // Tracks which instruction references which BasicBlock
Chris Lattner99dbdf72003-07-26 23:04:00 +000037 std::vector<std::pair<const BasicBlock*,
Misha Brukmance62d362003-06-02 04:12:39 +000038 std::pair<unsigned*,MachineInstr*> > > BBRefs;
39 // Tracks where each BasicBlock starts
Chris Lattner99dbdf72003-07-26 23:04:00 +000040 std::map<const BasicBlock*, long> BBLocations;
Misha Brukmanefafdf82003-06-04 20:01:13 +000041
Misha Brukmane195b7c2003-05-27 21:45:05 +000042public:
Misha Brukmanefafdf82003-06-04 20:01:13 +000043 SparcV9CodeEmitter(TargetMachine &T, MachineCodeEmitter &M);
Chris Lattnerc15c1202004-11-22 20:25:10 +000044 ~SparcV9CodeEmitter() {}
Misha Brukman5bf351c2003-05-30 20:17:33 +000045
Brian Gaeke5bee0f32004-04-15 20:23:13 +000046 const char *getPassName() const { return "SparcV9 Machine Code Emitter"; }
47
Misha Brukmanfb8f64a2003-07-29 20:52:56 +000048 /// runOnMachineFunction - emits the given machine function to memory.
49 ///
Misha Brukmane195b7c2003-05-27 21:45:05 +000050 bool runOnMachineFunction(MachineFunction &F);
Misha Brukmanfb8f64a2003-07-29 20:52:56 +000051
52 /// emitWord - writes out the given 32-bit value to memory at the current PC.
53 ///
Misha Brukmanefafdf82003-06-04 20:01:13 +000054 void emitWord(unsigned Val);
Misha Brukmane195b7c2003-05-27 21:45:05 +000055
Misha Brukmanfb8f64a2003-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 Brukmane195b7c2003-05-27 21:45:05 +000059 ///
Misha Brukmance62d362003-06-02 04:12:39 +000060 unsigned getBinaryCodeForInstr(MachineInstr &MI);
Misha Brukmane195b7c2003-05-27 21:45:05 +000061
62private:
Misha Brukmanfb8f64a2003-07-29 20:52:56 +000063 /// getMachineOpValue -
64 ///
Misha Brukmance62d362003-06-02 04:12:39 +000065 int64_t getMachineOpValue(MachineInstr &MI, MachineOperand &MO);
Misha Brukmanfb8f64a2003-07-29 20:52:56 +000066
67 /// emitBasicBlock -
68 ///
Misha Brukmane195b7c2003-05-27 21:45:05 +000069 void emitBasicBlock(MachineBasicBlock &MBB);
Misha Brukmanfb8f64a2003-07-29 20:52:56 +000070
71 /// getValueBit -
72 ///
73 unsigned getValueBit(int64_t Val, unsigned bit);
74
75 /// getGlobalAddress -
76 ///
Misha Brukmance62d362003-06-02 04:12:39 +000077 void* getGlobalAddress(GlobalValue *V, MachineInstr &MI,
78 bool isPCRelative);
Misha Brukmanfb8f64a2003-07-29 20:52:56 +000079 /// emitFarCall -
80 ///
Misha Brukmanb4028192003-07-14 23:26:03 +000081 unsigned getRealRegNum(unsigned fakeReg, MachineInstr &MI);
Misha Brukman384cb5d2003-07-15 19:09:43 +000082
Misha Brukmane195b7c2003-05-27 21:45:05 +000083};
84
Brian Gaeke960707c2003-11-11 22:41:34 +000085} // End llvm namespace
86
Misha Brukmane195b7c2003-05-27 21:45:05 +000087#endif