blob: b1c01910f6f1b5c41bae03430150247236cc2b88 [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.
53 ///
54 void emitFarCall(uint64_t Addr);
55
Misha Brukman0cc640e2003-05-27 21:45:05 +000056private:
Misha Brukmana21b8e82003-07-29 20:52:56 +000057 /// getMachineOpValue -
58 ///
Misha Brukmanf86aaa82003-06-02 04:12:39 +000059 int64_t getMachineOpValue(MachineInstr &MI, MachineOperand &MO);
Misha Brukmana21b8e82003-07-29 20:52:56 +000060
61 /// emitBasicBlock -
62 ///
Misha Brukman0cc640e2003-05-27 21:45:05 +000063 void emitBasicBlock(MachineBasicBlock &MBB);
Misha Brukmana21b8e82003-07-29 20:52:56 +000064
65 /// getValueBit -
66 ///
67 unsigned getValueBit(int64_t Val, unsigned bit);
68
69 /// getGlobalAddress -
70 ///
Misha Brukmanf86aaa82003-06-02 04:12:39 +000071 void* getGlobalAddress(GlobalValue *V, MachineInstr &MI,
72 bool isPCRelative);
Misha Brukmana21b8e82003-07-29 20:52:56 +000073 /// emitFarCall -
74 ///
Misha Brukman173e2502003-07-14 23:26:03 +000075 unsigned getRealRegNum(unsigned fakeReg, MachineInstr &MI);
Misha Brukman07d45162003-07-15 19:09:43 +000076
Misha Brukman0cc640e2003-05-27 21:45:05 +000077};
78
79#endif