Added LLVM copyright notice.
[oota-llvm.git] / lib / Target / SparcV9 / SparcV9CodeEmitter.h
1 //===-- SparcV9CodeEmitter.h ------------------------------------*- C++ -*-===//
2 // 
3 //                     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.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef SPARCV9CODEEMITTER_H
15 #define SPARCV9CODEEMITTER_H
16
17 #include "llvm/BasicBlock.h"
18 #include "llvm/CodeGen/MachineCodeEmitter.h"
19 #include "llvm/CodeGen/MachineFunctionPass.h"
20 #include "llvm/Target/TargetMachine.h"
21
22 class GlobalValue;
23 class MachineInstr;
24 class MachineOperand;
25
26 class SparcV9CodeEmitter : public MachineFunctionPass {
27   TargetMachine &TM;
28   MachineCodeEmitter &MCE;
29   const BasicBlock *currBB;
30
31   // Tracks which instruction references which BasicBlock
32   std::vector<std::pair<const BasicBlock*,
33                         std::pair<unsigned*,MachineInstr*> > > BBRefs;
34   // Tracks where each BasicBlock starts
35   std::map<const BasicBlock*, long> BBLocations;
36
37   // Tracks locations of Constants which are laid out in memory (e.g. FP)
38   // But we also need to map Constants to ConstantPool indices
39   std::map<const Constant*, unsigned> ConstantMap;
40
41 public:
42   SparcV9CodeEmitter(TargetMachine &T, MachineCodeEmitter &M);
43   ~SparcV9CodeEmitter();
44
45   /// runOnMachineFunction - emits the given machine function to memory.
46   ///
47   bool runOnMachineFunction(MachineFunction &F);
48
49   /// emitWord - writes out the given 32-bit value to memory at the current PC.
50   ///
51   void emitWord(unsigned Val);
52     
53   /// getBinaryCodeForInstr - This function, generated by the
54   /// CodeEmitterGenerator using TableGen, produces the binary encoding for
55   /// machine instructions.
56   ///
57   unsigned getBinaryCodeForInstr(MachineInstr &MI);
58
59   /// emitFarCall - produces a code sequence to make a call to a destination
60   /// that does not fit in the 30 bits that a call instruction allows.
61   /// If the function F is non-null, this also saves the return address in
62   /// the LazyResolver map of the JITResolver.
63   void emitFarCall(uint64_t Addr, Function *F = 0);
64
65 private:    
66   /// getMachineOpValue - 
67   ///
68   int64_t getMachineOpValue(MachineInstr &MI, MachineOperand &MO);
69
70   /// emitBasicBlock - 
71   ///
72   void emitBasicBlock(MachineBasicBlock &MBB);
73
74   /// getValueBit - 
75   ///
76   unsigned getValueBit(int64_t Val, unsigned bit);
77
78   /// getGlobalAddress - 
79   ///
80   void* getGlobalAddress(GlobalValue *V, MachineInstr &MI,
81                          bool isPCRelative);
82   /// emitFarCall - 
83   ///
84   unsigned getRealRegNum(unsigned fakeReg, MachineInstr &MI);
85
86 };
87
88 #endif