blob: 5a932a843d401de91a44699a9fc44ba67caa3902 [file] [log] [blame]
Misha Brukmana9f7f6e2003-05-30 20:17:33 +00001//===-- SparcV9CodeEmitter.h ------------------------------------*- C++ -*-===//
2//
John Criswell856ba762003-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//
Brian Gaekeb75a3162004-04-15 20:23:13 +000010// 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.
Misha Brukmana9f7f6e2003-05-30 20:17:33 +000014//
15//===----------------------------------------------------------------------===//
Misha Brukman0cc640e2003-05-27 21:45:05 +000016
17#ifndef SPARCV9CODEEMITTER_H
18#define SPARCV9CODEEMITTER_H
19
Misha Brukman0d603452003-05-27 22:41:44 +000020#include "llvm/BasicBlock.h"
Misha Brukman0cc640e2003-05-27 21:45:05 +000021#include "llvm/CodeGen/MachineCodeEmitter.h"
22#include "llvm/CodeGen/MachineFunctionPass.h"
Misha Brukmana9f7f6e2003-05-30 20:17:33 +000023#include "llvm/Target/TargetMachine.h"
Misha Brukman0cc640e2003-05-27 21:45:05 +000024
Brian Gaeked0fde302003-11-11 22:41:34 +000025namespace llvm {
26
Misha Brukmanf86aaa82003-06-02 04:12:39 +000027class GlobalValue;
28class MachineInstr;
29class MachineOperand;
30
Misha Brukman0cc640e2003-05-27 21:45:05 +000031class SparcV9CodeEmitter : public MachineFunctionPass {
Misha Brukmana2196c12003-06-04 20:01:13 +000032 TargetMachine &TM;
33 MachineCodeEmitter &MCE;
Chris Lattner6856d112003-07-26 23:04:00 +000034 const BasicBlock *currBB;
Misha Brukman0cc640e2003-05-27 21:45:05 +000035
Misha Brukmanf86aaa82003-06-02 04:12:39 +000036 // Tracks which instruction references which BasicBlock
Chris Lattner6856d112003-07-26 23:04:00 +000037 std::vector<std::pair<const BasicBlock*,
Misha Brukmanf86aaa82003-06-02 04:12:39 +000038 std::pair<unsigned*,MachineInstr*> > > BBRefs;
39 // Tracks where each BasicBlock starts
Chris Lattner6856d112003-07-26 23:04:00 +000040 std::map<const BasicBlock*, long> BBLocations;
Misha Brukmana2196c12003-06-04 20:01:13 +000041
Misha Brukman0cc640e2003-05-27 21:45:05 +000042public:
Misha Brukmana2196c12003-06-04 20:01:13 +000043 SparcV9CodeEmitter(TargetMachine &T, MachineCodeEmitter &M);
44 ~SparcV9CodeEmitter();
Misha Brukmana9f7f6e2003-05-30 20:17:33 +000045
Brian Gaekeb75a3162004-04-15 20:23:13 +000046 const char *getPassName() const { return "SparcV9 Machine Code Emitter"; }
47
Misha Brukmana21b8e82003-07-29 20:52:56 +000048 /// runOnMachineFunction - emits the given machine function to memory.
49 ///
Misha Brukman0cc640e2003-05-27 21:45:05 +000050 bool runOnMachineFunction(MachineFunction &F);
Misha Brukmana21b8e82003-07-29 20:52:56 +000051
52 /// emitWord - writes out the given 32-bit value to memory at the current PC.
53 ///
Misha Brukmana2196c12003-06-04 20:01:13 +000054 void emitWord(unsigned Val);
Misha Brukman0cc640e2003-05-27 21:45:05 +000055
Misha Brukmana21b8e82003-07-29 20:52:56 +000056 /// getBinaryCodeForInstr - This function, generated by the
57 /// CodeEmitterGenerator using TableGen, produces the binary encoding for
58 /// machine instructions.
Misha Brukman0cc640e2003-05-27 21:45:05 +000059 ///
Misha Brukmanf86aaa82003-06-02 04:12:39 +000060 unsigned getBinaryCodeForInstr(MachineInstr &MI);
Misha Brukman0cc640e2003-05-27 21:45:05 +000061
Misha Brukmana21b8e82003-07-29 20:52:56 +000062 /// 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.
Misha Brukman0897c602003-08-06 16:20:22 +000064 /// 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);
Misha Brukmana21b8e82003-07-29 20:52:56 +000067
Misha Brukman0cc640e2003-05-27 21:45:05 +000068private:
Misha Brukmana21b8e82003-07-29 20:52:56 +000069 /// getMachineOpValue -
70 ///
Misha Brukmanf86aaa82003-06-02 04:12:39 +000071 int64_t getMachineOpValue(MachineInstr &MI, MachineOperand &MO);
Misha Brukmana21b8e82003-07-29 20:52:56 +000072
73 /// emitBasicBlock -
74 ///
Misha Brukman0cc640e2003-05-27 21:45:05 +000075 void emitBasicBlock(MachineBasicBlock &MBB);
Misha Brukmana21b8e82003-07-29 20:52:56 +000076
77 /// getValueBit -
78 ///
79 unsigned getValueBit(int64_t Val, unsigned bit);
80
81 /// getGlobalAddress -
82 ///
Misha Brukmanf86aaa82003-06-02 04:12:39 +000083 void* getGlobalAddress(GlobalValue *V, MachineInstr &MI,
84 bool isPCRelative);
Misha Brukmana21b8e82003-07-29 20:52:56 +000085 /// emitFarCall -
86 ///
Misha Brukman173e2502003-07-14 23:26:03 +000087 unsigned getRealRegNum(unsigned fakeReg, MachineInstr &MI);
Misha Brukman07d45162003-07-15 19:09:43 +000088
Misha Brukman0cc640e2003-05-27 21:45:05 +000089};
90
Brian Gaeked0fde302003-11-11 22:41:34 +000091} // End llvm namespace
92
Misha Brukman0cc640e2003-05-27 21:45:05 +000093#endif