LLVM API Documentation

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

TargetMachine.h

Go to the documentation of this file.
00001 //===-- llvm/Target/TargetMachine.h - Target Information --------*- 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 // This file describes the general parts of a Target machine.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_TARGET_TARGETMACHINE_H
00015 #define LLVM_TARGET_TARGETMACHINE_H
00016 
00017 #include "llvm/Target/TargetData.h"
00018 #include <cassert>
00019 
00020 namespace llvm {
00021 
00022 class TargetInstrInfo;
00023 class TargetInstrDescriptor;
00024 class TargetJITInfo;
00025 class TargetSchedInfo;
00026 class SparcV9RegInfo;
00027 class TargetFrameInfo;
00028 class MachineCodeEmitter;
00029 class MRegisterInfo;
00030 class FunctionPassManager;
00031 class PassManager;
00032 class Pass;
00033 class IntrinsicLowering;
00034 
00035 //===----------------------------------------------------------------------===//
00036 ///
00037 /// TargetMachine - Primary interface to the complete machine description for
00038 /// the target machine.  All target-specific information should be accessible
00039 /// through this interface.
00040 /// 
00041 class TargetMachine {
00042   const std::string Name;
00043   const TargetData DataLayout;       // Calculates type size & alignment
00044   IntrinsicLowering *IL;             // Specifies how to lower intrinsic calls
00045   
00046   TargetMachine(const TargetMachine&);   // DO NOT IMPLEMENT
00047   void operator=(const TargetMachine&);  // DO NOT IMPLEMENT
00048 protected: // Can only create subclasses...
00049   TargetMachine(const std::string &name, IntrinsicLowering *IL,                
00050                 bool LittleEndian = false,
00051                 unsigned char PtrSize = 8, unsigned char PtrAl = 8,
00052                 unsigned char DoubleAl = 8, unsigned char FloatAl = 4,
00053                 unsigned char LongAl = 8, unsigned char IntAl = 4,
00054                 unsigned char ShortAl = 2, unsigned char ByteAl = 1,
00055                 unsigned char BoolAl = 1);
00056 
00057   TargetMachine(const std::string &name, IntrinsicLowering *IL, 
00058                 const TargetData &TD);
00059 
00060   /// This constructor is used for targets that support arbitrary TargetData
00061   /// layouts, like the C backend.  It initializes the TargetData to match that
00062   /// of the specified module.
00063   ///
00064   TargetMachine(const std::string &name, IntrinsicLowering *IL,
00065                 const Module &M);
00066 public:
00067   virtual ~TargetMachine();
00068 
00069   /// getModuleMatchQuality - This static method should be implemented by
00070   /// targets to indicate how closely they match the specified module.  This is
00071   /// used by the LLC tool to determine which target to use when an explicit
00072   /// -march option is not specified.  If a target returns zero, it will never
00073   /// be chosen without an explicit -march option.
00074   static unsigned getModuleMatchQuality(const Module &M) { return 0; }
00075 
00076   /// getJITMatchQuality - This static method should be implemented by targets
00077   /// that provide JIT capabilities to indicate how suitable they are for
00078   /// execution on the current host.  If a value of 0 is returned, the target
00079   /// will not be used unless an explicit -march option is used.
00080   static unsigned getJITMatchQuality() { return 0; }
00081 
00082 
00083   const std::string &getName() const { return Name; }
00084 
00085   /// getIntrinsicLowering - This method returns a reference to an
00086   /// IntrinsicLowering instance which should be used by the code generator to
00087   /// lower unknown intrinsic functions to the equivalent LLVM expansion.
00088   ///
00089   IntrinsicLowering &getIntrinsicLowering() const { return *IL; }
00090   
00091   // Interfaces to the major aspects of target machine information:
00092   // -- Instruction opcode and operand information
00093   // -- Pipelines and scheduling information
00094   // -- Stack frame information
00095   // 
00096   virtual const TargetInstrInfo        *getInstrInfo() const { return 0; }
00097   virtual const TargetFrameInfo        *getFrameInfo() const { return 0; }
00098   const TargetData &getTargetData() const { return DataLayout; }
00099 
00100   /// getRegisterInfo - If register information is available, return it.  If
00101   /// not, return null.  This is kept separate from RegInfo until RegInfo has
00102   /// details of graph coloring register allocation removed from it.
00103   ///
00104   virtual const MRegisterInfo*          getRegisterInfo() const { return 0; }
00105 
00106   /// getJITInfo - If this target supports a JIT, return information for it,
00107   /// otherwise return null.
00108   ///
00109   virtual TargetJITInfo *getJITInfo() { return 0; }
00110 
00111   // These are deprecated interfaces.
00112   virtual const TargetSchedInfo        *getSchedInfo() const { return 0; }
00113   virtual const SparcV9RegInfo         *getRegInfo()   const { return 0; }
00114 
00115   /// addPassesToEmitAssembly - Add passes to the specified pass manager to get
00116   /// assembly langage code emitted.  Typically this will involve several steps
00117   /// of code generation.  This method should return true if assembly emission
00118   /// is not supported.
00119   ///
00120   virtual bool addPassesToEmitAssembly(PassManager &PM, std::ostream &Out) {
00121     return true;
00122   }
00123 
00124   /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
00125   /// get machine code emitted.  This uses a MachineCodeEmitter object to handle
00126   /// actually outputting the machine code and resolving things like the address
00127   /// of functions.  This method should returns true if machine code emission is
00128   /// not supported.
00129   ///
00130   virtual bool addPassesToEmitMachineCode(FunctionPassManager &PM,
00131                                           MachineCodeEmitter &MCE) {
00132     return true;
00133   }
00134 };
00135 
00136 } // End llvm namespace
00137 
00138 #endif