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 // Target-specific portions of the machine code emitter for the SparcV9.
11 // This class interfaces with the JIT's Emitter in order to turn MachineInstrs
12 // into words of binary machine code. Its code is partially generated by
13 // TableGen's CodeEmitterGenerator.
15 //===----------------------------------------------------------------------===//
17 #ifndef SPARCV9CODEEMITTER_H
18 #define SPARCV9CODEEMITTER_H
20 #include "llvm/BasicBlock.h"
21 #include "llvm/CodeGen/MachineCodeEmitter.h"
22 #include "llvm/CodeGen/MachineFunctionPass.h"
23 #include "llvm/Target/TargetMachine.h"
31 class SparcV9CodeEmitter : public MachineFunctionPass {
33 MachineCodeEmitter &MCE;
34 const BasicBlock *currBB;
36 // Tracks which instruction references which BasicBlock
37 std::vector<std::pair<const BasicBlock*,
38 std::pair<unsigned*,MachineInstr*> > > BBRefs;
39 // Tracks where each BasicBlock starts
40 std::map<const BasicBlock*, long> BBLocations;
43 SparcV9CodeEmitter(TargetMachine &T, MachineCodeEmitter &M);
44 ~SparcV9CodeEmitter();
46 const char *getPassName() const { return "SparcV9 Machine Code Emitter"; }
48 /// runOnMachineFunction - emits the given machine function to memory.
50 bool runOnMachineFunction(MachineFunction &F);
52 /// emitWord - writes out the given 32-bit value to memory at the current PC.
54 void emitWord(unsigned Val);
56 /// getBinaryCodeForInstr - This function, generated by the
57 /// CodeEmitterGenerator using TableGen, produces the binary encoding for
58 /// machine instructions.
60 unsigned getBinaryCodeForInstr(MachineInstr &MI);
62 /// emitFarCall - produces a code sequence to make a call to a destination
63 /// that does not fit in the 30 bits that a call instruction allows.
64 /// If the function F is non-null, this also saves the return address in
65 /// the LazyResolver map of the JITResolver.
66 void emitFarCall(uint64_t Addr, Function *F = 0);
69 /// getMachineOpValue -
71 int64_t getMachineOpValue(MachineInstr &MI, MachineOperand &MO);
75 void emitBasicBlock(MachineBasicBlock &MBB);
79 unsigned getValueBit(int64_t Val, unsigned bit);
81 /// getGlobalAddress -
83 void* getGlobalAddress(GlobalValue *V, MachineInstr &MI,
87 unsigned getRealRegNum(unsigned fakeReg, MachineInstr &MI);
91 } // End llvm namespace