1 //===-- llvm/Target/TargetMachine.h - Target Information --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This file describes the general parts of a Target machine.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_TARGET_TARGETMACHINE_H
15 #define LLVM_TARGET_TARGETMACHINE_H
17 #include "llvm/Target/TargetData.h"
22 class TargetSubtarget;
23 class TargetInstrInfo;
24 class TargetInstrDescriptor;
26 class TargetSchedInfo;
28 class TargetFrameInfo;
29 class MachineCodeEmitter;
31 class FunctionPassManager;
34 class IntrinsicLowering;
36 //===----------------------------------------------------------------------===//
38 /// TargetMachine - Primary interface to the complete machine description for
39 /// the target machine. All target-specific information should be accessible
40 /// through this interface.
43 const std::string Name;
44 const TargetData DataLayout; // Calculates type size & alignment
45 IntrinsicLowering *IL; // Specifies how to lower intrinsic calls
47 TargetMachine(const TargetMachine&); // DO NOT IMPLEMENT
48 void operator=(const TargetMachine&); // DO NOT IMPLEMENT
49 protected: // Can only create subclasses...
50 TargetMachine(const std::string &name, IntrinsicLowering *IL,
51 bool LittleEndian = false,
52 unsigned char PtrSize = 8, unsigned char PtrAl = 8,
53 unsigned char DoubleAl = 8, unsigned char FloatAl = 4,
54 unsigned char LongAl = 8, unsigned char IntAl = 4,
55 unsigned char ShortAl = 2, unsigned char ByteAl = 1,
56 unsigned char BoolAl = 1);
58 TargetMachine(const std::string &name, IntrinsicLowering *IL,
59 const TargetData &TD);
61 /// This constructor is used for targets that support arbitrary TargetData
62 /// layouts, like the C backend. It initializes the TargetData to match that
63 /// of the specified module.
65 TargetMachine(const std::string &name, IntrinsicLowering *IL,
68 virtual ~TargetMachine();
70 /// getModuleMatchQuality - This static method should be implemented by
71 /// targets to indicate how closely they match the specified module. This is
72 /// used by the LLC tool to determine which target to use when an explicit
73 /// -march option is not specified. If a target returns zero, it will never
74 /// be chosen without an explicit -march option.
75 static unsigned getModuleMatchQuality(const Module &M) { return 0; }
77 /// getJITMatchQuality - This static method should be implemented by targets
78 /// that provide JIT capabilities to indicate how suitable they are for
79 /// execution on the current host. If a value of 0 is returned, the target
80 /// will not be used unless an explicit -march option is used.
81 static unsigned getJITMatchQuality() { return 0; }
84 const std::string &getName() const { return Name; }
86 /// getIntrinsicLowering - This method returns a reference to an
87 /// IntrinsicLowering instance which should be used by the code generator to
88 /// lower unknown intrinsic functions to the equivalent LLVM expansion.
90 IntrinsicLowering &getIntrinsicLowering() const { return *IL; }
92 // Interfaces to the major aspects of target machine information:
93 // -- Instruction opcode and operand information
94 // -- Pipelines and scheduling information
95 // -- Stack frame information
97 virtual const TargetInstrInfo *getInstrInfo() const { return 0; }
98 virtual const TargetFrameInfo *getFrameInfo() const { return 0; }
99 const TargetData &getTargetData() const { return DataLayout; }
101 virtual const TargetSubtarget *getSubtargetImpl() const { return 0; }
102 template<typename STC> STC *getSubtarget() const {
103 assert(getSubtargetImpl() && dynamic_cast<STC*>(getSubtargetImpl()) &&
104 "Not the right kind of subtarget!");
105 return (STC*)getSubtargetImpl();
108 /// getRegisterInfo - If register information is available, return it. If
109 /// not, return null. This is kept separate from RegInfo until RegInfo has
110 /// details of graph coloring register allocation removed from it.
112 virtual const MRegisterInfo* getRegisterInfo() const { return 0; }
114 /// getJITInfo - If this target supports a JIT, return information for it,
115 /// otherwise return null.
117 virtual TargetJITInfo *getJITInfo() { return 0; }
119 // These are deprecated interfaces.
120 virtual const TargetSchedInfo *getSchedInfo() const { return 0; }
121 virtual const SparcV9RegInfo *getRegInfo() const { return 0; }
123 /// CodeGenFileType - These enums are meant to be passed into
124 /// addPassesToEmitFile to indicate what type of file to emit.
125 enum CodeGenFileType {
126 AssemblyFile, ObjectFile, DynamicLibrary
129 /// addPassesToEmitFile - Add passes to the specified pass manager to get
130 /// the specified file emitted. Typically this will involve several steps of
131 /// code generation. This method should return true if emission of this file
132 /// type is not supported.
134 virtual bool addPassesToEmitFile(PassManager &PM, std::ostream &Out,
135 CodeGenFileType FileType) {
139 /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
140 /// get machine code emitted. This uses a MachineCodeEmitter object to handle
141 /// actually outputting the machine code and resolving things like the address
142 /// of functions. This method should returns true if machine code emission is
145 virtual bool addPassesToEmitMachineCode(FunctionPassManager &PM,
146 MachineCodeEmitter &MCE) {
151 } // End llvm namespace