1 //===-- llvm/Target/Machine.h - General Target Information -------*- C++ -*-==//
3 // This file describes the general parts of a Target machine.
5 //===----------------------------------------------------------------------===//
7 #ifndef LLVM_TARGET_TARGETMACHINE_H
8 #define LLVM_TARGET_TARGETMACHINE_H
10 #include "llvm/Target/TargetData.h"
11 #include "Support/NonCopyable.h"
13 class MachineInstrInfo;
14 class MachineInstrDescriptor;
15 class MachineSchedInfo;
17 class MachineFrameInfo;
18 class MachineCacheInfo;
23 //---------------------------------------------------------------------------
24 // class TargetMachine
27 // Primary interface to the complete machine description for the
28 // target machine. All target-specific information should be
29 // accessible through this interface.
31 //---------------------------------------------------------------------------
33 class TargetMachine : public NonCopyableV {
34 const std::string Name;
36 const TargetData DataLayout; // Calculates type size & alignment
39 TargetMachine(const std::string &name, // Can only create subclasses...
40 unsigned char SubWordSize = 1, unsigned char IntRegSize = 8,
41 unsigned char PtrSize = 8, unsigned char PtrAl = 8,
42 unsigned char DoubleAl = 8, unsigned char FloatAl = 4,
43 unsigned char LongAl = 8, unsigned char IntAl = 4,
44 unsigned char ShortAl = 2, unsigned char ByteAl = 1)
45 : Name(name), DataLayout(name, SubWordSize, IntRegSize, PtrSize, PtrAl,
46 DoubleAl, FloatAl, LongAl,
47 IntAl, ShortAl, ByteAl) {}
49 virtual ~TargetMachine() {}
51 const std::string &getName() const { return Name; }
54 // Interfaces to the major aspects of target machine information:
55 // -- Instruction opcode and operand information
56 // -- Pipelines and scheduling information
57 // -- Register information
58 // -- Stack frame information
59 // -- Cache hierarchy information
60 // -- Machine-level optimization information (peephole only)
62 virtual const MachineInstrInfo& getInstrInfo() const = 0;
63 virtual const MachineSchedInfo& getSchedInfo() const = 0;
64 virtual const MachineRegInfo& getRegInfo() const = 0;
65 virtual const MachineFrameInfo& getFrameInfo() const = 0;
66 virtual const MachineCacheInfo& getCacheInfo() const = 0;
67 virtual const MachineOptInfo& getOptInfo() const = 0;
69 // Data storage information
71 virtual unsigned findOptimalStorageSize(const Type* ty) const;
73 /// addPassesToEmitAssembly - Add passes to the specified pass manager to get
74 /// assembly langage code emited. Typically this will involve several steps
75 /// of code generation. This method should return true if code generation is
78 virtual bool addPassesToEmitAssembly(PassManager &PM, std::ostream &Out) {
82 /// addPassesToJITCompile - Add passes to the specified pass manager to
83 /// implement a fast dynamic compiler for this target. Return true if this is
84 /// not supported for this target.
86 virtual bool addPassesToJITCompile(PassManager &PM) { return true; }
88 /// getPrologEpilogCodeInserter - Create pass to insert prolog/epilog code.
90 virtual Pass* getPrologEpilogInsertionPass() = 0;
92 /// getFunctionAsmPrinterPass - Create a pass to write out the generated
93 /// machine code for a single function to the generated assembly file.
95 virtual Pass* getFunctionAsmPrinterPass(std::ostream &Out) = 0;
97 /// getModuleAsmPrinterPass - Create a pass to write out module-level
98 /// information to the generated assembly file.
100 virtual Pass* getModuleAsmPrinterPass(std::ostream &Out) = 0;
102 /// getEmitBytecodeToAsmPass - Create a pass to emit the final LLVM bytecode
103 /// to the generated assembly file.
105 virtual Pass* getEmitBytecodeToAsmPass(std::ostream &Out) = 0;