Add new getJITStubForFunction method, which may optionally be implemented by
[oota-llvm.git] / include / llvm / Target / TargetMachine.h
1 //===-- llvm/Target/TargetMachine.h - Target Information --------*- C++ -*-===//
2 // 
3 //                     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 // This file describes the general parts of a Target machine.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_TARGET_TARGETMACHINE_H
15 #define LLVM_TARGET_TARGETMACHINE_H
16
17 #include "llvm/Target/TargetData.h"
18 #include <cassert>
19
20 namespace llvm {
21
22 class TargetInstrInfo;
23 class TargetInstrDescriptor;
24 class TargetSchedInfo;
25 class TargetRegInfo;
26 class TargetFrameInfo;
27 class TargetCacheInfo;
28 class MachineCodeEmitter;
29 class MRegisterInfo;
30 class FunctionPassManager;
31 class PassManager;
32 class Pass;
33
34 //===----------------------------------------------------------------------===//
35 ///
36 /// TargetMachine - Primary interface to the complete machine description for
37 /// the target machine.  All target-specific information should be accessible
38 /// through this interface.
39 /// 
40 class TargetMachine {
41   const std::string Name;
42   const TargetData DataLayout;           // Calculates type size & alignment
43   
44   TargetMachine(const TargetMachine&);   // DO NOT IMPLEMENT
45   void operator=(const TargetMachine&);  // DO NOT IMPLEMENT
46 protected:
47   TargetMachine(const std::string &name, // Can only create subclasses...
48                 bool LittleEndian = false,
49                 unsigned char PtrSize = 8, unsigned char PtrAl = 8,
50                 unsigned char DoubleAl = 8, unsigned char FloatAl = 4,
51                 unsigned char LongAl = 8, unsigned char IntAl = 4,
52                 unsigned char ShortAl = 2, unsigned char ByteAl = 1)
53     : Name(name), DataLayout(name, LittleEndian,
54                              PtrSize, PtrAl, DoubleAl, FloatAl, LongAl,
55                              IntAl, ShortAl, ByteAl) {}
56 public:
57   virtual ~TargetMachine() {}
58
59   const std::string &getName() const { return Name; }
60   
61   // Interfaces to the major aspects of target machine information:
62   // -- Instruction opcode and operand information
63   // -- Pipelines and scheduling information
64   // -- Register information
65   // -- Stack frame information
66   // -- Cache hierarchy information
67   // -- Machine-level optimization information (peephole only)
68   // 
69   virtual const TargetInstrInfo&        getInstrInfo() const = 0;
70   virtual const TargetSchedInfo&        getSchedInfo() const = 0;
71   virtual const TargetRegInfo&          getRegInfo()   const = 0;
72   virtual const TargetFrameInfo&        getFrameInfo() const = 0;
73   virtual const TargetCacheInfo&        getCacheInfo() const = 0;
74   const TargetData &getTargetData() const { return DataLayout; }
75
76   /// getRegisterInfo - If register information is available, return it.  If
77   /// not, return null.  This is kept separate from RegInfo until RegInfo has
78   /// details of graph coloring register allocation removed from it.
79   ///
80   virtual const MRegisterInfo*          getRegisterInfo() const { return 0; }
81
82   // Data storage information
83   // 
84   virtual unsigned findOptimalStorageSize(const Type* ty) const;
85   
86   /// addPassesToJITCompile - Add passes to the specified pass manager to
87   /// implement a fast dynamic compiler for this target.  Return true if this is
88   /// not supported for this target.
89   ///
90   virtual bool addPassesToJITCompile(FunctionPassManager &PM) { return true; }
91
92   /// addPassesToEmitAssembly - Add passes to the specified pass manager to get
93   /// assembly langage code emitted.  Typically this will involve several steps
94   /// of code generation.  This method should return true if assembly emission
95   /// is not supported.
96   ///
97   virtual bool addPassesToEmitAssembly(PassManager &PM, std::ostream &Out) {
98     return true;
99   }
100
101   /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
102   /// get machine code emitted.  This uses a MachineCodeEmitter object to handle
103   /// actually outputting the machine code and resolving things like the address
104   /// of functions.  This method should returns true if machine code emission is
105   /// not supported.
106   ///
107   virtual bool addPassesToEmitMachineCode(FunctionPassManager &PM,
108                                           MachineCodeEmitter &MCE) {
109     return true;
110   }
111
112   /// replaceMachineCodeForFunction - Make it so that calling the
113   /// function whose machine code is at OLD turns into a call to NEW,
114   /// perhaps by overwriting OLD with a branch to NEW.
115   ///
116   /// FIXME: this is JIT-specific.
117   ///
118   virtual void replaceMachineCodeForFunction (void *Old, void *New) {
119     assert (0 && "Current target cannot replace machine code for functions");
120   }
121
122   /// getJITStubForFunction - Create or return a stub for the specified
123   /// function.  This stub acts just like the specified function, except that it
124   /// allows the "address" of the function to be taken without having to
125   /// generate code for it.
126   virtual void *getJITStubForFunction(Function *F, MachineCodeEmitter &MCE) {
127     return 0;
128   }
129 };
130
131 } // End llvm namespace
132
133 #endif