blob: 48bb6734dd54302308b558d6006ee0ced7b8ad2e [file] [log] [blame]
Misha Brukman5bf351c2003-05-30 20:17:33 +00001//===-- SparcV9CodeEmitter.h ------------------------------------*- C++ -*-===//
2//
John Criswell29265fe2003-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//
10// TODO: Need a description here.
Misha Brukman5bf351c2003-05-30 20:17:33 +000011//
12//===----------------------------------------------------------------------===//
Misha Brukmane195b7c2003-05-27 21:45:05 +000013
14#ifndef SPARCV9CODEEMITTER_H
15#define SPARCV9CODEEMITTER_H
16
Misha Brukman79756612003-05-27 22:41:44 +000017#include "llvm/BasicBlock.h"
Misha Brukmane195b7c2003-05-27 21:45:05 +000018#include "llvm/CodeGen/MachineCodeEmitter.h"
19#include "llvm/CodeGen/MachineFunctionPass.h"
Misha Brukman5bf351c2003-05-30 20:17:33 +000020#include "llvm/Target/TargetMachine.h"
Misha Brukmane195b7c2003-05-27 21:45:05 +000021
Misha Brukmance62d362003-06-02 04:12:39 +000022class GlobalValue;
23class MachineInstr;
24class MachineOperand;
25
Misha Brukmane195b7c2003-05-27 21:45:05 +000026class SparcV9CodeEmitter : public MachineFunctionPass {
Misha Brukmanefafdf82003-06-04 20:01:13 +000027 TargetMachine &TM;
28 MachineCodeEmitter &MCE;
Chris Lattner99dbdf72003-07-26 23:04:00 +000029 const BasicBlock *currBB;
Misha Brukmane195b7c2003-05-27 21:45:05 +000030
Misha Brukmance62d362003-06-02 04:12:39 +000031 // Tracks which instruction references which BasicBlock
Chris Lattner99dbdf72003-07-26 23:04:00 +000032 std::vector<std::pair<const BasicBlock*,
Misha Brukmance62d362003-06-02 04:12:39 +000033 std::pair<unsigned*,MachineInstr*> > > BBRefs;
34 // Tracks where each BasicBlock starts
Chris Lattner99dbdf72003-07-26 23:04:00 +000035 std::map<const BasicBlock*, long> BBLocations;
Misha Brukmanefafdf82003-06-04 20:01:13 +000036
Misha Brukmance62d362003-06-02 04:12:39 +000037 // Tracks locations of Constants which are laid out in memory (e.g. FP)
Misha Brukmanefafdf82003-06-04 20:01:13 +000038 // But we also need to map Constants to ConstantPool indices
39 std::map<const Constant*, unsigned> ConstantMap;
Misha Brukmance62d362003-06-02 04:12:39 +000040
Misha Brukmane195b7c2003-05-27 21:45:05 +000041public:
Misha Brukmanefafdf82003-06-04 20:01:13 +000042 SparcV9CodeEmitter(TargetMachine &T, MachineCodeEmitter &M);
43 ~SparcV9CodeEmitter();
Misha Brukman5bf351c2003-05-30 20:17:33 +000044
Misha Brukmanfb8f64a2003-07-29 20:52:56 +000045 /// runOnMachineFunction - emits the given machine function to memory.
46 ///
Misha Brukmane195b7c2003-05-27 21:45:05 +000047 bool runOnMachineFunction(MachineFunction &F);
Misha Brukmanfb8f64a2003-07-29 20:52:56 +000048
49 /// emitWord - writes out the given 32-bit value to memory at the current PC.
50 ///
Misha Brukmanefafdf82003-06-04 20:01:13 +000051 void emitWord(unsigned Val);
Misha Brukmane195b7c2003-05-27 21:45:05 +000052
Misha Brukmanfb8f64a2003-07-29 20:52:56 +000053 /// getBinaryCodeForInstr - This function, generated by the
54 /// CodeEmitterGenerator using TableGen, produces the binary encoding for
55 /// machine instructions.
Misha Brukmane195b7c2003-05-27 21:45:05 +000056 ///
Misha Brukmance62d362003-06-02 04:12:39 +000057 unsigned getBinaryCodeForInstr(MachineInstr &MI);
Misha Brukmane195b7c2003-05-27 21:45:05 +000058
Misha Brukmanfb8f64a2003-07-29 20:52:56 +000059 /// 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.
Misha Brukman45106982003-08-06 16:20:22 +000061 /// 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);
Misha Brukmanfb8f64a2003-07-29 20:52:56 +000064
Misha Brukmane195b7c2003-05-27 21:45:05 +000065private:
Misha Brukmanfb8f64a2003-07-29 20:52:56 +000066 /// getMachineOpValue -
67 ///
Misha Brukmance62d362003-06-02 04:12:39 +000068 int64_t getMachineOpValue(MachineInstr &MI, MachineOperand &MO);
Misha Brukmanfb8f64a2003-07-29 20:52:56 +000069
70 /// emitBasicBlock -
71 ///
Misha Brukmane195b7c2003-05-27 21:45:05 +000072 void emitBasicBlock(MachineBasicBlock &MBB);
Misha Brukmanfb8f64a2003-07-29 20:52:56 +000073
74 /// getValueBit -
75 ///
76 unsigned getValueBit(int64_t Val, unsigned bit);
77
78 /// getGlobalAddress -
79 ///
Misha Brukmance62d362003-06-02 04:12:39 +000080 void* getGlobalAddress(GlobalValue *V, MachineInstr &MI,
81 bool isPCRelative);
Misha Brukmanfb8f64a2003-07-29 20:52:56 +000082 /// emitFarCall -
83 ///
Misha Brukmanb4028192003-07-14 23:26:03 +000084 unsigned getRealRegNum(unsigned fakeReg, MachineInstr &MI);
Misha Brukman384cb5d2003-07-15 19:09:43 +000085
Misha Brukmane195b7c2003-05-27 21:45:05 +000086};
87
88#endif