1 //===-- SparcV9CodeEmitter.h ------------------------------------*- C++ -*-===//
4 //===----------------------------------------------------------------------===//
6 #ifndef SPARCV9CODEEMITTER_H
7 #define SPARCV9CODEEMITTER_H
9 #include "llvm/BasicBlock.h"
10 #include "llvm/CodeGen/MachineCodeEmitter.h"
11 #include "llvm/CodeGen/MachineFunctionPass.h"
12 #include "llvm/Target/TargetMachine.h"
18 class SparcV9CodeEmitter : public MachineFunctionPass {
20 MachineCodeEmitter &MCE;
21 const BasicBlock *currBB;
23 // Tracks which instruction references which BasicBlock
24 std::vector<std::pair<const BasicBlock*,
25 std::pair<unsigned*,MachineInstr*> > > BBRefs;
26 // Tracks where each BasicBlock starts
27 std::map<const BasicBlock*, long> BBLocations;
29 // Tracks locations of Constants which are laid out in memory (e.g. FP)
30 // But we also need to map Constants to ConstantPool indices
31 std::map<const Constant*, unsigned> ConstantMap;
34 SparcV9CodeEmitter(TargetMachine &T, MachineCodeEmitter &M);
35 ~SparcV9CodeEmitter();
37 /// runOnMachineFunction - emits the given machine function to memory.
39 bool runOnMachineFunction(MachineFunction &F);
41 /// emitWord - writes out the given 32-bit value to memory at the current PC.
43 void emitWord(unsigned Val);
45 /// getBinaryCodeForInstr - This function, generated by the
46 /// CodeEmitterGenerator using TableGen, produces the binary encoding for
47 /// machine instructions.
49 unsigned getBinaryCodeForInstr(MachineInstr &MI);
51 /// emitFarCall - produces a code sequence to make a call to a destination
52 /// that does not fit in the 30 bits that a call instruction allows.
53 /// If the function F is non-null, this also saves the return address in
54 /// the LazyResolver map of the JITResolver.
55 void emitFarCall(uint64_t Addr, Function *F = 0);
58 /// getMachineOpValue -
60 int64_t getMachineOpValue(MachineInstr &MI, MachineOperand &MO);
64 void emitBasicBlock(MachineBasicBlock &MBB);
68 unsigned getValueBit(int64_t Val, unsigned bit);
70 /// getGlobalAddress -
72 void* getGlobalAddress(GlobalValue *V, MachineInstr &MI,
76 unsigned getRealRegNum(unsigned fakeReg, MachineInstr &MI);