blob: d21345ec041b03ee50b22eaba0e0c216a39c72c1 [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
Brian Gaeke960707c2003-11-11 22:41:34 +000022namespace llvm {
23
Misha Brukmance62d362003-06-02 04:12:39 +000024class GlobalValue;
25class MachineInstr;
26class MachineOperand;
27
Misha Brukmane195b7c2003-05-27 21:45:05 +000028class SparcV9CodeEmitter : public MachineFunctionPass {
Misha Brukmanefafdf82003-06-04 20:01:13 +000029 TargetMachine &TM;
30 MachineCodeEmitter &MCE;
Chris Lattner99dbdf72003-07-26 23:04:00 +000031 const BasicBlock *currBB;
Misha Brukmane195b7c2003-05-27 21:45:05 +000032
Misha Brukmance62d362003-06-02 04:12:39 +000033 // Tracks which instruction references which BasicBlock
Chris Lattner99dbdf72003-07-26 23:04:00 +000034 std::vector<std::pair<const BasicBlock*,
Misha Brukmance62d362003-06-02 04:12:39 +000035 std::pair<unsigned*,MachineInstr*> > > BBRefs;
36 // Tracks where each BasicBlock starts
Chris Lattner99dbdf72003-07-26 23:04:00 +000037 std::map<const BasicBlock*, long> BBLocations;
Misha Brukmanefafdf82003-06-04 20:01:13 +000038
Misha Brukmane195b7c2003-05-27 21:45:05 +000039public:
Misha Brukmanefafdf82003-06-04 20:01:13 +000040 SparcV9CodeEmitter(TargetMachine &T, MachineCodeEmitter &M);
41 ~SparcV9CodeEmitter();
Misha Brukman5bf351c2003-05-30 20:17:33 +000042
Misha Brukmanfb8f64a2003-07-29 20:52:56 +000043 /// runOnMachineFunction - emits the given machine function to memory.
44 ///
Misha Brukmane195b7c2003-05-27 21:45:05 +000045 bool runOnMachineFunction(MachineFunction &F);
Misha Brukmanfb8f64a2003-07-29 20:52:56 +000046
47 /// emitWord - writes out the given 32-bit value to memory at the current PC.
48 ///
Misha Brukmanefafdf82003-06-04 20:01:13 +000049 void emitWord(unsigned Val);
Misha Brukmane195b7c2003-05-27 21:45:05 +000050
Misha Brukmanfb8f64a2003-07-29 20:52:56 +000051 /// getBinaryCodeForInstr - This function, generated by the
52 /// CodeEmitterGenerator using TableGen, produces the binary encoding for
53 /// machine instructions.
Misha Brukmane195b7c2003-05-27 21:45:05 +000054 ///
Misha Brukmance62d362003-06-02 04:12:39 +000055 unsigned getBinaryCodeForInstr(MachineInstr &MI);
Misha Brukmane195b7c2003-05-27 21:45:05 +000056
Misha Brukmanfb8f64a2003-07-29 20:52:56 +000057 /// emitFarCall - produces a code sequence to make a call to a destination
58 /// that does not fit in the 30 bits that a call instruction allows.
Misha Brukman45106982003-08-06 16:20:22 +000059 /// If the function F is non-null, this also saves the return address in
60 /// the LazyResolver map of the JITResolver.
61 void emitFarCall(uint64_t Addr, Function *F = 0);
Misha Brukmanfb8f64a2003-07-29 20:52:56 +000062
Misha Brukmane195b7c2003-05-27 21:45:05 +000063private:
Misha Brukmanfb8f64a2003-07-29 20:52:56 +000064 /// getMachineOpValue -
65 ///
Misha Brukmance62d362003-06-02 04:12:39 +000066 int64_t getMachineOpValue(MachineInstr &MI, MachineOperand &MO);
Misha Brukmanfb8f64a2003-07-29 20:52:56 +000067
68 /// emitBasicBlock -
69 ///
Misha Brukmane195b7c2003-05-27 21:45:05 +000070 void emitBasicBlock(MachineBasicBlock &MBB);
Misha Brukmanfb8f64a2003-07-29 20:52:56 +000071
72 /// getValueBit -
73 ///
74 unsigned getValueBit(int64_t Val, unsigned bit);
75
76 /// getGlobalAddress -
77 ///
Misha Brukmance62d362003-06-02 04:12:39 +000078 void* getGlobalAddress(GlobalValue *V, MachineInstr &MI,
79 bool isPCRelative);
Misha Brukmanfb8f64a2003-07-29 20:52:56 +000080 /// emitFarCall -
81 ///
Misha Brukmanb4028192003-07-14 23:26:03 +000082 unsigned getRealRegNum(unsigned fakeReg, MachineInstr &MI);
Misha Brukman384cb5d2003-07-15 19:09:43 +000083
Misha Brukmane195b7c2003-05-27 21:45:05 +000084};
85
Brian Gaeke960707c2003-11-11 22:41:34 +000086} // End llvm namespace
87
Misha Brukmane195b7c2003-05-27 21:45:05 +000088#endif