|
7 | 7 | //
|
8 | 8 | //===----------------------------------------------------------------------===//
|
9 | 9 | //
|
10 |
| -// This file describes the general parts of a Target machine. |
| 10 | +// This file defines the TargetMachine and LLVMTargetMachine classes. |
11 | 11 | //
|
12 | 12 | //===----------------------------------------------------------------------===//
|
13 | 13 |
|
@@ -62,8 +62,8 @@ namespace CodeModel {
|
62 | 62 | /// through this interface.
|
63 | 63 | ///
|
64 | 64 | class TargetMachine {
|
65 |
| - TargetMachine(const TargetMachine&); // DO NOT IMPLEMENT |
66 |
| - void operator=(const TargetMachine&); // DO NOT IMPLEMENT |
| 65 | + TargetMachine(const TargetMachine &); // DO NOT IMPLEMENT |
| 66 | + void operator=(const TargetMachine &); // DO NOT IMPLEMENT |
67 | 67 | protected: // Can only create subclasses.
|
68 | 68 | TargetMachine() { }
|
69 | 69 |
|
@@ -151,19 +151,109 @@ class TargetMachine {
|
151 | 151 | /// code as fast as possible, without regard for compile time. This method
|
152 | 152 | /// should return true if emission of this file type is not supported.
|
153 | 153 | ///
|
154 |
| - virtual bool addPassesToEmitFile(PassManager &PM, std::ostream &Out, |
| 154 | + virtual bool addPassesToEmitFile(FunctionPassManager &PM, std::ostream &Out, |
155 | 155 | CodeGenFileType FileType, bool Fast) {
|
156 | 156 | return true;
|
157 | 157 | }
|
| 158 | + |
| 159 | + /// addPassesToEmitMachineCode - Add passes to the specified pass manager to |
| 160 | + /// get machine code emitted. This uses a MachineCodeEmitter object to handle |
| 161 | + /// actually outputting the machine code and resolving things like the address |
| 162 | + /// of functions. This method returns true if machine code emission is |
| 163 | + /// not supported. |
| 164 | + /// |
| 165 | + virtual bool addPassesToEmitMachineCode(FunctionPassManager &PM, |
| 166 | + MachineCodeEmitter &MCE, bool Fast) { |
| 167 | + return true; |
| 168 | + } |
| 169 | + |
158 | 170 |
|
| 171 | + /// addPassesToEmitWholeFile - This method can be implemented by targets that |
| 172 | + /// require having the entire module at once. This is not recommended, do not |
| 173 | + /// use this. |
| 174 | + virtual bool WantsWholeFile() const { return false; } |
| 175 | + virtual bool addPassesToEmitWholeFile(PassManager &PM, std::ostream &Out, |
| 176 | + CodeGenFileType FileType, bool Fast) { |
| 177 | + return true; |
| 178 | + } |
| 179 | +}; |
| 180 | + |
| 181 | +/// LLVMTargetMachine - This class describes a target machine that is |
| 182 | +/// implemented with the LLVM target-independent code generator. |
| 183 | +/// |
| 184 | +class LLVMTargetMachine : public TargetMachine { |
| 185 | +protected: // Can only create subclasses. |
| 186 | + LLVMTargetMachine() { } |
| 187 | +public: |
| 188 | + |
| 189 | + /// addPassesToEmitFile - Add passes to the specified pass manager to get |
| 190 | + /// the specified file emitted. Typically this will involve several steps of |
| 191 | + /// code generation. If Fast is set to true, the code generator should emit |
| 192 | + /// code as fast as possible, without regard for compile time. This method |
| 193 | + /// should return true if emission of this file type is not supported. |
| 194 | + /// |
| 195 | + /// The default implementation of this method adds components from the |
| 196 | + /// LLVM retargetable code generator, invoking the methods below to get |
| 197 | + /// target-specific passes in standard locations. |
| 198 | + /// |
| 199 | + virtual bool addPassesToEmitFile(FunctionPassManager &PM, std::ostream &Out, |
| 200 | + CodeGenFileType FileType, bool Fast); |
| 201 | + |
159 | 202 | /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
|
160 | 203 | /// get machine code emitted. This uses a MachineCodeEmitter object to handle
|
161 | 204 | /// actually outputting the machine code and resolving things like the address
|
162 |
| - /// of functions. This method should returns true if machine code emission is |
| 205 | + /// of functions. This method returns true if machine code emission is |
163 | 206 | /// not supported.
|
164 | 207 | ///
|
165 | 208 | virtual bool addPassesToEmitMachineCode(FunctionPassManager &PM,
|
166 |
| - MachineCodeEmitter &MCE) { |
| 209 | + MachineCodeEmitter &MCE, bool Fast); |
| 210 | + |
| 211 | + /// Target-Independent Code Generator Pass Configuration Options. |
| 212 | + |
| 213 | + /// addInstSelector - This method should add any "last minute" LLVM->LLVM |
| 214 | + /// passes, then install an instruction selector pass, which converts from |
| 215 | + /// LLVM code to machine instructions. |
| 216 | + virtual bool addInstSelector(FunctionPassManager &PM, bool Fast) { |
| 217 | + return true; |
| 218 | + } |
| 219 | + |
| 220 | + /// addPostRegAllocPasses - This method may be implemented by targets that |
| 221 | + /// want to run passes after register allocation but before prolog-epilog |
| 222 | + /// insertion. This should return true if -print-machineinstrs should print |
| 223 | + /// after these passes. |
| 224 | + virtual bool addPostRegAlloc(FunctionPassManager &PM, bool Fast) { |
| 225 | + return false; |
| 226 | + } |
| 227 | + |
| 228 | + /// addPreEmitPass - This pass may be implemented by targets that want to run |
| 229 | + /// passes immediately before machine code is emitted. This should return |
| 230 | + /// true if -print-machineinstrs should print out the code after the passes. |
| 231 | + virtual bool addPreEmitPass(FunctionPassManager &PM, bool Fast) { |
| 232 | + return false; |
| 233 | + } |
| 234 | + |
| 235 | + |
| 236 | + /// addAssemblyEmitter - This pass should be overridden by the target to add |
| 237 | + /// the asmprinter, if asm emission is supported. If this is not supported, |
| 238 | + /// 'true' should be returned. |
| 239 | + virtual bool addAssemblyEmitter(FunctionPassManager &PM, bool Fast, |
| 240 | + std::ostream &Out) { |
| 241 | + return true; |
| 242 | + } |
| 243 | + |
| 244 | + /// addObjectWriter - This pass should be overridden by the target to add |
| 245 | + /// the object-file writer, if supported. If this is not supported, |
| 246 | + /// 'true' should be returned. |
| 247 | + virtual bool addObjectWriter(FunctionPassManager &PM, bool Fast, |
| 248 | + std::ostream &Out) { |
| 249 | + return true; |
| 250 | + } |
| 251 | + |
| 252 | + /// addCodeEmitter - This pass should be overridden by the target to add a |
| 253 | + /// code emitter, if supported. If this is not supported, 'true' should be |
| 254 | + /// returned. |
| 255 | + virtual bool addCodeEmitter(FunctionPassManager &PM, bool Fast, |
| 256 | + MachineCodeEmitter &MCE) { |
167 | 257 | return true;
|
168 | 258 | }
|
169 | 259 | };
|
|
0 commit comments