TargetMachine.h revision a69571c7991813c93cba64e88eced6899ce93d81
148486893f46d2e12e926682a3ecb908716bc66c4Chris Lattner//===-- llvm/Target/TargetMachine.h - Target Information --------*- C++ -*-===// 234695381d626485a560594f162701088079589dfMisha Brukman// 36fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell// The LLVM Compiler Infrastructure 46fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell// 56fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell// This file was developed by the LLVM research group and is distributed under 66fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell// the University of Illinois Open Source License. See LICENSE.TXT for details. 734695381d626485a560594f162701088079589dfMisha Brukman// 86fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//===----------------------------------------------------------------------===// 9a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve// 10a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve// This file describes the general parts of a Target machine. 11a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve// 12a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve//===----------------------------------------------------------------------===// 13a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve 14a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve#ifndef LLVM_TARGET_TARGETMACHINE_H 15a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve#define LLVM_TARGET_TARGETMACHINE_H 16a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve 17a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve#include "llvm/Target/TargetData.h" 186cee630070b1a7183ed56a8404e812629f5ca538Jim Laskey#include "llvm/Target/TargetInstrItineraries.h" 19a42649e3dd4c8be2d45451429a41f2b13dbeeb78Brian Gaeke#include <cassert> 20a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve 21d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm { 22d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 23fb5792f416089d8d8d0c6ee62c1f41a55d2cf75dNate Begemanclass TargetSubtarget; 242584ba5867c06e676519d5c7cccbcd59eb7641bcChris Lattnerclass TargetInstrInfo; 252584ba5867c06e676519d5c7cccbcd59eb7641bcChris Lattnerclass TargetInstrDescriptor; 261e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattnerclass TargetJITInfo; 27a84b1c7c4efdba050cbf308eb9ac4fd8392b69d9Evan Chengclass TargetLowering; 285b927c790ed3baa9b555057c9c0904fc34990ba8Chris Lattnerclass TargetFrameInfo; 299f729a30b2e0648209f864da9da8aaa6a4be5e38Chris Lattnerclass MachineCodeEmitter; 30478df7a7ae3c9aaa753948712d894fade36a8195Chris Lattnerclass MRegisterInfo; 318844a0ba898a3a1db7f5fd91ecf6a5402e3d51a0Brian Gaekeclass FunctionPassManager; 32b6dcbfc6d1d18e9b3a5dcd0df5f00f7ac3d0100fChris Lattnerclass PassManager; 33ebc7511e8688f2ec23915570377dd4aaf167560eVikram S. Adveclass Pass; 34a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve 354c1aa866578f7a358407a22fe55b454f52a24325Evan Cheng// Relocation model types. 364c1aa866578f7a358407a22fe55b454f52a24325Evan Chengnamespace Reloc { 374c1aa866578f7a358407a22fe55b454f52a24325Evan Cheng enum Model { 384c1aa866578f7a358407a22fe55b454f52a24325Evan Cheng Default, 394c1aa866578f7a358407a22fe55b454f52a24325Evan Cheng Static, 404c1aa866578f7a358407a22fe55b454f52a24325Evan Cheng PIC, 414c1aa866578f7a358407a22fe55b454f52a24325Evan Cheng DynamicNoPIC 424c1aa866578f7a358407a22fe55b454f52a24325Evan Cheng }; 434c1aa866578f7a358407a22fe55b454f52a24325Evan Cheng} 444c1aa866578f7a358407a22fe55b454f52a24325Evan Cheng 455b927c790ed3baa9b555057c9c0904fc34990ba8Chris Lattner//===----------------------------------------------------------------------===// 465b927c790ed3baa9b555057c9c0904fc34990ba8Chris Lattner/// 475b927c790ed3baa9b555057c9c0904fc34990ba8Chris Lattner/// TargetMachine - Primary interface to the complete machine description for 485b927c790ed3baa9b555057c9c0904fc34990ba8Chris Lattner/// the target machine. All target-specific information should be accessible 495b927c790ed3baa9b555057c9c0904fc34990ba8Chris Lattner/// through this interface. 5034695381d626485a560594f162701088079589dfMisha Brukman/// 5117035c0edf5463fd9edb8496502f4c5a0dc1d7abChris Lattnerclass TargetMachine { 52c56406c236478f718a2257c2b660561ebc855f16Chris Lattner const std::string Name; 5334695381d626485a560594f162701088079589dfMisha Brukman 5417035c0edf5463fd9edb8496502f4c5a0dc1d7abChris Lattner TargetMachine(const TargetMachine&); // DO NOT IMPLEMENT 5517035c0edf5463fd9edb8496502f4c5a0dc1d7abChris Lattner void operator=(const TargetMachine&); // DO NOT IMPLEMENT 56f70e0c216c074bd2ae2b08178f5512849545db4eChris Lattnerprotected: // Can only create subclasses... 57a69571c7991813c93cba64e88eced6899ce93d81Owen Anderson TargetMachine(const std::string &name) : Name(name) { }; 5880b90cd1914ced00a58ed9ac4b9dce06e573c8ebMisha Brukman 59992dce13ece1748aef8a6fdeef0f4e271165258cMisha Brukman /// This constructor is used for targets that support arbitrary TargetData 60992dce13ece1748aef8a6fdeef0f4e271165258cMisha Brukman /// layouts, like the C backend. It initializes the TargetData to match that 61992dce13ece1748aef8a6fdeef0f4e271165258cMisha Brukman /// of the specified module. 62992dce13ece1748aef8a6fdeef0f4e271165258cMisha Brukman /// 63475c010366da9788b5f87d6a453d5eed6053ef46Chris Lattner TargetMachine(const std::string &name, const Module &M); 648d2623d49a7b53f2bb25f2b61c14aecb91e19154Nate Begeman 658d2623d49a7b53f2bb25f2b61c14aecb91e19154Nate Begeman /// getSubtargetImpl - virtual method implemented by subclasses that returns 668d2623d49a7b53f2bb25f2b61c14aecb91e19154Nate Begeman /// a reference to that target's TargetSubtarget-derived member variable. 678d2623d49a7b53f2bb25f2b61c14aecb91e19154Nate Begeman virtual const TargetSubtarget *getSubtargetImpl() const { return 0; } 68a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Advepublic: 69f70e0c216c074bd2ae2b08178f5512849545db4eChris Lattner virtual ~TargetMachine(); 706334205cb5c626d2b35e42dd4c710b857bf0a126Chris Lattner 71a51e273a764b2a3e8fe856c3bd47b09f9446f380Chris Lattner /// getModuleMatchQuality - This static method should be implemented by 72a51e273a764b2a3e8fe856c3bd47b09f9446f380Chris Lattner /// targets to indicate how closely they match the specified module. This is 73a51e273a764b2a3e8fe856c3bd47b09f9446f380Chris Lattner /// used by the LLC tool to determine which target to use when an explicit 74a51e273a764b2a3e8fe856c3bd47b09f9446f380Chris Lattner /// -march option is not specified. If a target returns zero, it will never 75a51e273a764b2a3e8fe856c3bd47b09f9446f380Chris Lattner /// be chosen without an explicit -march option. 76a51e273a764b2a3e8fe856c3bd47b09f9446f380Chris Lattner static unsigned getModuleMatchQuality(const Module &M) { return 0; } 77a51e273a764b2a3e8fe856c3bd47b09f9446f380Chris Lattner 78a51e273a764b2a3e8fe856c3bd47b09f9446f380Chris Lattner /// getJITMatchQuality - This static method should be implemented by targets 79a51e273a764b2a3e8fe856c3bd47b09f9446f380Chris Lattner /// that provide JIT capabilities to indicate how suitable they are for 80a51e273a764b2a3e8fe856c3bd47b09f9446f380Chris Lattner /// execution on the current host. If a value of 0 is returned, the target 81a51e273a764b2a3e8fe856c3bd47b09f9446f380Chris Lattner /// will not be used unless an explicit -march option is used. 82a51e273a764b2a3e8fe856c3bd47b09f9446f380Chris Lattner static unsigned getJITMatchQuality() { return 0; } 83a51e273a764b2a3e8fe856c3bd47b09f9446f380Chris Lattner 84a51e273a764b2a3e8fe856c3bd47b09f9446f380Chris Lattner 85c56406c236478f718a2257c2b660561ebc855f16Chris Lattner const std::string &getName() const { return Name; } 86f70e0c216c074bd2ae2b08178f5512849545db4eChris Lattner 87a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve // Interfaces to the major aspects of target machine information: 88a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve // -- Instruction opcode and operand information 89a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve // -- Pipelines and scheduling information 90d55697cf136150b697b9bbddce9088e87a1be963Vikram S. Adve // -- Stack frame information 91a84b1c7c4efdba050cbf308eb9ac4fd8392b69d9Evan Cheng // -- Selection DAG lowering information 9234695381d626485a560594f162701088079589dfMisha Brukman // 9336c2a0593509da714bea6457dd1b00a7417ce342Chris Lattner virtual const TargetInstrInfo *getInstrInfo() const { return 0; } 9436c2a0593509da714bea6457dd1b00a7417ce342Chris Lattner virtual const TargetFrameInfo *getFrameInfo() const { return 0; } 95a84b1c7c4efdba050cbf308eb9ac4fd8392b69d9Evan Cheng virtual TargetLowering *getTargetLowering() const { return 0; } 96a69571c7991813c93cba64e88eced6899ce93d81Owen Anderson virtual const TargetData *getTargetData() const { return 0; } 97d55697cf136150b697b9bbddce9088e87a1be963Vikram S. Adve 989eb59ec548b861d6ede05b4e6dc22aabf645e665Jeff Cohen /// getSubtarget - This method returns a pointer to the specified type of 998d2623d49a7b53f2bb25f2b61c14aecb91e19154Nate Begeman /// TargetSubtarget. In debug builds, it verifies that the object being 1008d2623d49a7b53f2bb25f2b61c14aecb91e19154Nate Begeman /// returned is of the correct type. 1015ab83632066071413841af43bc5d1edcced18076Chris Lattner template<typename STC> const STC &getSubtarget() const { 1028d2623d49a7b53f2bb25f2b61c14aecb91e19154Nate Begeman const TargetSubtarget *TST = getSubtargetImpl(); 1035ab83632066071413841af43bc5d1edcced18076Chris Lattner assert(TST && dynamic_cast<const STC*>(TST) && 104fb5792f416089d8d8d0c6ee62c1f41a55d2cf75dNate Begeman "Not the right kind of subtarget!"); 1055ab83632066071413841af43bc5d1edcced18076Chris Lattner return *static_cast<const STC*>(TST); 106fb5792f416089d8d8d0c6ee62c1f41a55d2cf75dNate Begeman } 107fb5792f416089d8d8d0c6ee62c1f41a55d2cf75dNate Begeman 108478df7a7ae3c9aaa753948712d894fade36a8195Chris Lattner /// getRegisterInfo - If register information is available, return it. If 1095b927c790ed3baa9b555057c9c0904fc34990ba8Chris Lattner /// not, return null. This is kept separate from RegInfo until RegInfo has 1105b927c790ed3baa9b555057c9c0904fc34990ba8Chris Lattner /// details of graph coloring register allocation removed from it. 111478df7a7ae3c9aaa753948712d894fade36a8195Chris Lattner /// 112478df7a7ae3c9aaa753948712d894fade36a8195Chris Lattner virtual const MRegisterInfo* getRegisterInfo() const { return 0; } 113478df7a7ae3c9aaa753948712d894fade36a8195Chris Lattner 1141e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner /// getJITInfo - If this target supports a JIT, return information for it, 1151e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner /// otherwise return null. 1161e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner /// 1171e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner virtual TargetJITInfo *getJITInfo() { return 0; } 1186cee630070b1a7183ed56a8404e812629f5ca538Jim Laskey 1196cee630070b1a7183ed56a8404e812629f5ca538Jim Laskey /// getInstrItineraryData - Returns instruction itinerary data for the target 1206cee630070b1a7183ed56a8404e812629f5ca538Jim Laskey /// or specific subtarget. 1216cee630070b1a7183ed56a8404e812629f5ca538Jim Laskey /// 1226cee630070b1a7183ed56a8404e812629f5ca538Jim Laskey virtual const InstrItineraryData getInstrItineraryData() const { 1236cee630070b1a7183ed56a8404e812629f5ca538Jim Laskey return InstrItineraryData(); 1246cee630070b1a7183ed56a8404e812629f5ca538Jim Laskey } 1251e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner 1264c1aa866578f7a358407a22fe55b454f52a24325Evan Cheng /// getRelocationModel - Returns the code generation relocation model. The 1274c1aa866578f7a358407a22fe55b454f52a24325Evan Cheng /// choices are static, PIC, and dynamic-no-pic, and target default. 1284c1aa866578f7a358407a22fe55b454f52a24325Evan Cheng static Reloc::Model getRelocationModel(); 1294c1aa866578f7a358407a22fe55b454f52a24325Evan Cheng 1304c1aa866578f7a358407a22fe55b454f52a24325Evan Cheng /// setRelocationModel - Sets the code generation relocation model. 1314c1aa866578f7a358407a22fe55b454f52a24325Evan Cheng static void setRelocationModel(Reloc::Model Model); 1324c1aa866578f7a358407a22fe55b454f52a24325Evan Cheng 13311f14c8be0946a8fb95189156ff1d64a01ff7da3Chris Lattner /// CodeGenFileType - These enums are meant to be passed into 13411f14c8be0946a8fb95189156ff1d64a01ff7da3Chris Lattner /// addPassesToEmitFile to indicate what type of file to emit. 13511f14c8be0946a8fb95189156ff1d64a01ff7da3Chris Lattner enum CodeGenFileType { 13633f80a87230f61b85f62cbc956b6f521b6e2063cChris Lattner AssemblyFile, ObjectFile, DynamicLibrary 13711f14c8be0946a8fb95189156ff1d64a01ff7da3Chris Lattner }; 13811f14c8be0946a8fb95189156ff1d64a01ff7da3Chris Lattner 13911f14c8be0946a8fb95189156ff1d64a01ff7da3Chris Lattner /// addPassesToEmitFile - Add passes to the specified pass manager to get 14011f14c8be0946a8fb95189156ff1d64a01ff7da3Chris Lattner /// the specified file emitted. Typically this will involve several steps of 141df2e425f2a3b64eb17be927539cd39cb1f1c5f77Chris Lattner /// code generation. If Fast is set to true, the code generator should emit 142df2e425f2a3b64eb17be927539cd39cb1f1c5f77Chris Lattner /// code as fast as possible, without regard for compile time. This method 143df2e425f2a3b64eb17be927539cd39cb1f1c5f77Chris Lattner /// should return true if emission of this file type is not supported. 144ebb1af16bea8f163cbb74c55ae41885c396f72cbChris Lattner /// 14511f14c8be0946a8fb95189156ff1d64a01ff7da3Chris Lattner virtual bool addPassesToEmitFile(PassManager &PM, std::ostream &Out, 146df2e425f2a3b64eb17be927539cd39cb1f1c5f77Chris Lattner CodeGenFileType FileType, bool Fast) { 1476334205cb5c626d2b35e42dd4c710b857bf0a126Chris Lattner return true; 1486334205cb5c626d2b35e42dd4c710b857bf0a126Chris Lattner } 149ebc7511e8688f2ec23915570377dd4aaf167560eVikram S. Adve 1509f729a30b2e0648209f864da9da8aaa6a4be5e38Chris Lattner /// addPassesToEmitMachineCode - Add passes to the specified pass manager to 1518844a0ba898a3a1db7f5fd91ecf6a5402e3d51a0Brian Gaeke /// get machine code emitted. This uses a MachineCodeEmitter object to handle 1529f729a30b2e0648209f864da9da8aaa6a4be5e38Chris Lattner /// actually outputting the machine code and resolving things like the address 1539f729a30b2e0648209f864da9da8aaa6a4be5e38Chris Lattner /// of functions. This method should returns true if machine code emission is 154b7a2d2256fede467c7f50444eb3cddadcd7d34c9Chris Lattner /// not supported. 1555c1b5244b956a28667bc2a9e7a84fa39697ba715Chris Lattner /// 1568844a0ba898a3a1db7f5fd91ecf6a5402e3d51a0Brian Gaeke virtual bool addPassesToEmitMachineCode(FunctionPassManager &PM, 157b7a2d2256fede467c7f50444eb3cddadcd7d34c9Chris Lattner MachineCodeEmitter &MCE) { 1589f729a30b2e0648209f864da9da8aaa6a4be5e38Chris Lattner return true; 1599f729a30b2e0648209f864da9da8aaa6a4be5e38Chris Lattner } 160a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve}; 161a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve 162d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke} // End llvm namespace 163d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 164a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve#endif 165