LLVM API Documentation

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

SparcV9CodeEmitter.h

Go to the documentation of this file.
00001 //===-- SparcV9CodeEmitter.h ------------------------------------*- C++ -*-===//
00002 // 
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by the LLVM research group and is distributed under
00006 // the University of Illinois Open Source License. See LICENSE.TXT for details.
00007 // 
00008 //===----------------------------------------------------------------------===//
00009 // 
00010 // Target-specific portions of the machine code emitter for the SparcV9.
00011 // This class interfaces with the JIT's Emitter in order to turn MachineInstrs
00012 // into words of binary machine code. Its code is partially generated by
00013 // TableGen's CodeEmitterGenerator.
00014 //
00015 //===----------------------------------------------------------------------===//
00016 
00017 #ifndef SPARCV9CODEEMITTER_H
00018 #define SPARCV9CODEEMITTER_H
00019 
00020 #include "llvm/BasicBlock.h"
00021 #include "llvm/CodeGen/MachineCodeEmitter.h"
00022 #include "llvm/CodeGen/MachineFunctionPass.h"
00023 #include "llvm/Target/TargetMachine.h"
00024 
00025 namespace llvm {
00026 
00027 class GlobalValue;
00028 class MachineInstr;
00029 class MachineOperand;
00030 
00031 class SparcV9CodeEmitter : public MachineFunctionPass {
00032   TargetMachine &TM;
00033   MachineCodeEmitter &MCE;
00034   const BasicBlock *currBB;
00035 
00036   // Tracks which instruction references which BasicBlock
00037   std::vector<std::pair<const BasicBlock*,
00038                         std::pair<unsigned*,MachineInstr*> > > BBRefs;
00039   // Tracks where each BasicBlock starts
00040   std::map<const BasicBlock*, long> BBLocations;
00041 
00042 public:
00043   SparcV9CodeEmitter(TargetMachine &T, MachineCodeEmitter &M);
00044   ~SparcV9CodeEmitter() {}
00045 
00046   const char *getPassName() const { return "SparcV9 Machine Code Emitter"; }
00047 
00048   /// runOnMachineFunction - emits the given machine function to memory.
00049   ///
00050   bool runOnMachineFunction(MachineFunction &F);
00051 
00052   /// emitWord - writes out the given 32-bit value to memory at the current PC.
00053   ///
00054   void emitWord(unsigned Val);
00055     
00056   /// getBinaryCodeForInstr - This function, generated by the
00057   /// CodeEmitterGenerator using TableGen, produces the binary encoding for
00058   /// machine instructions.
00059   ///
00060   unsigned getBinaryCodeForInstr(MachineInstr &MI);
00061 
00062 private:    
00063   /// getMachineOpValue - 
00064   ///
00065   int64_t getMachineOpValue(MachineInstr &MI, MachineOperand &MO);
00066 
00067   /// emitBasicBlock - 
00068   ///
00069   void emitBasicBlock(MachineBasicBlock &MBB);
00070 
00071   /// getValueBit - 
00072   ///
00073   unsigned getValueBit(int64_t Val, unsigned bit);
00074 
00075   /// getGlobalAddress - 
00076   ///
00077   void* getGlobalAddress(GlobalValue *V, MachineInstr &MI,
00078                          bool isPCRelative);
00079   /// emitFarCall - 
00080   ///
00081   unsigned getRealRegNum(unsigned fakeReg, MachineInstr &MI);
00082 
00083 };
00084 
00085 } // End llvm namespace
00086 
00087 #endif