blob: 8b73aa44992e1ca05214b555b6a0385f48317bf0 [file] [log] [blame]
Misha Brukmana9f7f6e2003-05-30 20:17:33 +00001//===-- SparcV9CodeEmitter.h ------------------------------------*- C++ -*-===//
2//
3//
4//===----------------------------------------------------------------------===//
Misha Brukman0cc640e2003-05-27 21:45:05 +00005
6#ifndef SPARCV9CODEEMITTER_H
7#define SPARCV9CODEEMITTER_H
8
Misha Brukman0d603452003-05-27 22:41:44 +00009#include "llvm/BasicBlock.h"
Misha Brukman0cc640e2003-05-27 21:45:05 +000010#include "llvm/CodeGen/MachineCodeEmitter.h"
11#include "llvm/CodeGen/MachineFunctionPass.h"
Misha Brukmana9f7f6e2003-05-30 20:17:33 +000012#include "llvm/Target/TargetMachine.h"
Misha Brukman0cc640e2003-05-27 21:45:05 +000013
Misha Brukmanf86aaa82003-06-02 04:12:39 +000014class GlobalValue;
15class MachineInstr;
16class MachineOperand;
17
Misha Brukman0cc640e2003-05-27 21:45:05 +000018class SparcV9CodeEmitter : public MachineFunctionPass {
Misha Brukmana2196c12003-06-04 20:01:13 +000019 TargetMachine &TM;
20 MachineCodeEmitter &MCE;
Chris Lattner6856d112003-07-26 23:04:00 +000021 const BasicBlock *currBB;
Misha Brukman0cc640e2003-05-27 21:45:05 +000022
Misha Brukmanf86aaa82003-06-02 04:12:39 +000023 // Tracks which instruction references which BasicBlock
Chris Lattner6856d112003-07-26 23:04:00 +000024 std::vector<std::pair<const BasicBlock*,
Misha Brukmanf86aaa82003-06-02 04:12:39 +000025 std::pair<unsigned*,MachineInstr*> > > BBRefs;
26 // Tracks where each BasicBlock starts
Chris Lattner6856d112003-07-26 23:04:00 +000027 std::map<const BasicBlock*, long> BBLocations;
Misha Brukmana2196c12003-06-04 20:01:13 +000028
Misha Brukmanf86aaa82003-06-02 04:12:39 +000029 // Tracks locations of Constants which are laid out in memory (e.g. FP)
Misha Brukmana2196c12003-06-04 20:01:13 +000030 // But we also need to map Constants to ConstantPool indices
31 std::map<const Constant*, unsigned> ConstantMap;
Misha Brukmanf86aaa82003-06-02 04:12:39 +000032
Misha Brukman0cc640e2003-05-27 21:45:05 +000033public:
Misha Brukmana2196c12003-06-04 20:01:13 +000034 SparcV9CodeEmitter(TargetMachine &T, MachineCodeEmitter &M);
35 ~SparcV9CodeEmitter();
Misha Brukmana9f7f6e2003-05-30 20:17:33 +000036
Misha Brukmana21b8e82003-07-29 20:52:56 +000037 /// runOnMachineFunction - emits the given machine function to memory.
38 ///
Misha Brukman0cc640e2003-05-27 21:45:05 +000039 bool runOnMachineFunction(MachineFunction &F);
Misha Brukmana21b8e82003-07-29 20:52:56 +000040
41 /// emitWord - writes out the given 32-bit value to memory at the current PC.
42 ///
Misha Brukmana2196c12003-06-04 20:01:13 +000043 void emitWord(unsigned Val);
Misha Brukman0cc640e2003-05-27 21:45:05 +000044
Misha Brukmana21b8e82003-07-29 20:52:56 +000045 /// getBinaryCodeForInstr - This function, generated by the
46 /// CodeEmitterGenerator using TableGen, produces the binary encoding for
47 /// machine instructions.
Misha Brukman0cc640e2003-05-27 21:45:05 +000048 ///
Misha Brukmanf86aaa82003-06-02 04:12:39 +000049 unsigned getBinaryCodeForInstr(MachineInstr &MI);
Misha Brukman0cc640e2003-05-27 21:45:05 +000050
Misha Brukmana21b8e82003-07-29 20:52:56 +000051 /// 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.
Misha Brukman0897c602003-08-06 16:20:22 +000053 /// 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);
Misha Brukmana21b8e82003-07-29 20:52:56 +000056
Misha Brukman0cc640e2003-05-27 21:45:05 +000057private:
Misha Brukmana21b8e82003-07-29 20:52:56 +000058 /// getMachineOpValue -
59 ///
Misha Brukmanf86aaa82003-06-02 04:12:39 +000060 int64_t getMachineOpValue(MachineInstr &MI, MachineOperand &MO);
Misha Brukmana21b8e82003-07-29 20:52:56 +000061
62 /// emitBasicBlock -
63 ///
Misha Brukman0cc640e2003-05-27 21:45:05 +000064 void emitBasicBlock(MachineBasicBlock &MBB);
Misha Brukmana21b8e82003-07-29 20:52:56 +000065
66 /// getValueBit -
67 ///
68 unsigned getValueBit(int64_t Val, unsigned bit);
69
70 /// getGlobalAddress -
71 ///
Misha Brukmanf86aaa82003-06-02 04:12:39 +000072 void* getGlobalAddress(GlobalValue *V, MachineInstr &MI,
73 bool isPCRelative);
Misha Brukmana21b8e82003-07-29 20:52:56 +000074 /// emitFarCall -
75 ///
Misha Brukman173e2502003-07-14 23:26:03 +000076 unsigned getRealRegNum(unsigned fakeReg, MachineInstr &MI);
Misha Brukman07d45162003-07-15 19:09:43 +000077
Misha Brukman0cc640e2003-05-27 21:45:05 +000078};
79
80#endif