blob: 7e19c44ce03f4e6aad0bd1b9ed66020cd0e6831c [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//
10// TODO: Need a description here.
Misha Brukman5bf351c2003-05-30 20:17:33 +000011//
12//===----------------------------------------------------------------------===//
Misha Brukmane195b7c2003-05-27 21:45:05 +000013
14#ifndef SPARCV9CODEEMITTER_H
15#define SPARCV9CODEEMITTER_H
16
Misha Brukman79756612003-05-27 22:41:44 +000017#include "llvm/BasicBlock.h"
Misha Brukmane195b7c2003-05-27 21:45:05 +000018#include "llvm/CodeGen/MachineCodeEmitter.h"
19#include "llvm/CodeGen/MachineFunctionPass.h"
Misha Brukman5bf351c2003-05-30 20:17:33 +000020#include "llvm/Target/TargetMachine.h"
Misha Brukmane195b7c2003-05-27 21:45:05 +000021
Misha Brukmance62d362003-06-02 04:12:39 +000022class GlobalValue;
23class MachineInstr;
24class MachineOperand;
25
Misha Brukmane195b7c2003-05-27 21:45:05 +000026class SparcV9CodeEmitter : public MachineFunctionPass {
Misha Brukmanefafdf82003-06-04 20:01:13 +000027 TargetMachine &TM;
28 MachineCodeEmitter &MCE;
Chris Lattner99dbdf72003-07-26 23:04:00 +000029 const BasicBlock *currBB;
Misha Brukmane195b7c2003-05-27 21:45:05 +000030
Misha Brukmance62d362003-06-02 04:12:39 +000031 // Tracks which instruction references which BasicBlock
Chris Lattner99dbdf72003-07-26 23:04:00 +000032 std::vector<std::pair<const BasicBlock*,
Misha Brukmance62d362003-06-02 04:12:39 +000033 std::pair<unsigned*,MachineInstr*> > > BBRefs;
34 // Tracks where each BasicBlock starts
Chris Lattner99dbdf72003-07-26 23:04:00 +000035 std::map<const BasicBlock*, long> BBLocations;
Misha Brukmanefafdf82003-06-04 20:01:13 +000036
Misha Brukmane195b7c2003-05-27 21:45:05 +000037public:
Misha Brukmanefafdf82003-06-04 20:01:13 +000038 SparcV9CodeEmitter(TargetMachine &T, MachineCodeEmitter &M);
39 ~SparcV9CodeEmitter();
Misha Brukman5bf351c2003-05-30 20:17:33 +000040
Misha Brukmanfb8f64a2003-07-29 20:52:56 +000041 /// runOnMachineFunction - emits the given machine function to memory.
42 ///
Misha Brukmane195b7c2003-05-27 21:45:05 +000043 bool runOnMachineFunction(MachineFunction &F);
Misha Brukmanfb8f64a2003-07-29 20:52:56 +000044
45 /// emitWord - writes out the given 32-bit value to memory at the current PC.
46 ///
Misha Brukmanefafdf82003-06-04 20:01:13 +000047 void emitWord(unsigned Val);
Misha Brukmane195b7c2003-05-27 21:45:05 +000048
Misha Brukmanfb8f64a2003-07-29 20:52:56 +000049 /// getBinaryCodeForInstr - This function, generated by the
50 /// CodeEmitterGenerator using TableGen, produces the binary encoding for
51 /// machine instructions.
Misha Brukmane195b7c2003-05-27 21:45:05 +000052 ///
Misha Brukmance62d362003-06-02 04:12:39 +000053 unsigned getBinaryCodeForInstr(MachineInstr &MI);
Misha Brukmane195b7c2003-05-27 21:45:05 +000054
Misha Brukmanfb8f64a2003-07-29 20:52:56 +000055 /// emitFarCall - produces a code sequence to make a call to a destination
56 /// that does not fit in the 30 bits that a call instruction allows.
Misha Brukman45106982003-08-06 16:20:22 +000057 /// If the function F is non-null, this also saves the return address in
58 /// the LazyResolver map of the JITResolver.
59 void emitFarCall(uint64_t Addr, Function *F = 0);
Misha Brukmanfb8f64a2003-07-29 20:52:56 +000060
Misha Brukmane195b7c2003-05-27 21:45:05 +000061private:
Misha Brukmanfb8f64a2003-07-29 20:52:56 +000062 /// getMachineOpValue -
63 ///
Misha Brukmance62d362003-06-02 04:12:39 +000064 int64_t getMachineOpValue(MachineInstr &MI, MachineOperand &MO);
Misha Brukmanfb8f64a2003-07-29 20:52:56 +000065
66 /// emitBasicBlock -
67 ///
Misha Brukmane195b7c2003-05-27 21:45:05 +000068 void emitBasicBlock(MachineBasicBlock &MBB);
Misha Brukmanfb8f64a2003-07-29 20:52:56 +000069
70 /// getValueBit -
71 ///
72 unsigned getValueBit(int64_t Val, unsigned bit);
73
74 /// getGlobalAddress -
75 ///
Misha Brukmance62d362003-06-02 04:12:39 +000076 void* getGlobalAddress(GlobalValue *V, MachineInstr &MI,
77 bool isPCRelative);
Misha Brukmanfb8f64a2003-07-29 20:52:56 +000078 /// emitFarCall -
79 ///
Misha Brukmanb4028192003-07-14 23:26:03 +000080 unsigned getRealRegNum(unsigned fakeReg, MachineInstr &MI);
Misha Brukman384cb5d2003-07-15 19:09:43 +000081
Misha Brukmane195b7c2003-05-27 21:45:05 +000082};
83
84#endif