1 //===-- SparcV9CodeEmitter.h ------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // TODO: Need a description here.
12 //===----------------------------------------------------------------------===//
14 #ifndef SPARCV9CODEEMITTER_H
15 #define SPARCV9CODEEMITTER_H
17 #include "llvm/BasicBlock.h"
18 #include "llvm/CodeGen/MachineCodeEmitter.h"
19 #include "llvm/CodeGen/MachineFunctionPass.h"
20 #include "llvm/Target/TargetMachine.h"
26 class SparcV9CodeEmitter : public MachineFunctionPass {
28 MachineCodeEmitter &MCE;
29 const BasicBlock *currBB;
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;
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;
42 SparcV9CodeEmitter(TargetMachine &T, MachineCodeEmitter &M);
43 ~SparcV9CodeEmitter();
45 /// runOnMachineFunction - emits the given machine function to memory.
47 bool runOnMachineFunction(MachineFunction &F);
49 /// emitWord - writes out the given 32-bit value to memory at the current PC.
51 void emitWord(unsigned Val);
53 /// getBinaryCodeForInstr - This function, generated by the
54 /// CodeEmitterGenerator using TableGen, produces the binary encoding for
55 /// machine instructions.
57 unsigned getBinaryCodeForInstr(MachineInstr &MI);
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);
66 /// getMachineOpValue -
68 int64_t getMachineOpValue(MachineInstr &MI, MachineOperand &MO);
72 void emitBasicBlock(MachineBasicBlock &MBB);
76 unsigned getValueBit(int64_t Val, unsigned bit);
78 /// getGlobalAddress -
80 void* getGlobalAddress(GlobalValue *V, MachineInstr &MI,
84 unsigned getRealRegNum(unsigned fakeReg, MachineInstr &MI);