1bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner//===- ExecutionEngine.h - Abstract Execution Engine Interface --*- C++ -*-===// 2ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman// 36fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell// The LLVM Compiler Infrastructure 46fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell// 57ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// This file is distributed under the University of Illinois Open Source 67ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// License. See LICENSE.TXT for details. 7ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman// 86fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//===----------------------------------------------------------------------===// 9bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner// 10bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner// This file defines the abstract interface that implements execution support 11bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner// for LLVM. 12bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner// 13bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner//===----------------------------------------------------------------------===// 14bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner 15674be02d525d4e24bc6943ed9274958c580bcfbcJakub Staszak#ifndef LLVM_EXECUTIONENGINE_EXECUTIONENGINE_H 16674be02d525d4e24bc6943ed9274958c580bcfbcJakub Staszak#define LLVM_EXECUTIONENGINE_EXECUTIONENGINE_H 17bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner 180c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar#include "RuntimeDyld.h" 1943dfffe890f58468e2fe01f312978d7aa5303801Eric Christopher#include "llvm-c/ExecutionEngine.h" 20fe854034677f59baca1e38075e71f6efca247a03Chris Lattner#include "llvm/ADT/SmallVector.h" 214688261c20735f5ead2f08695acdeb727db31894Jeffrey Yasskin#include "llvm/ADT/StringRef.h" 2237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines#include "llvm/IR/Module.h" 2336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#include "llvm/IR/ValueHandle.h" 2436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#include "llvm/IR/ValueMap.h" 2537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines#include "llvm/Object/Binary.h" 2650bee42b54cd9aec5f49566307df2b0cf23afcf6Craig Topper#include "llvm/Support/ErrorHandling.h" 271f6efa3996dd1929fbc129203ce5009b620e6969Michael J. Spencer#include "llvm/Support/Mutex.h" 2898a366d547772010e94609e4584489b3e5ce0043Bill Wendling#include "llvm/Target/TargetMachine.h" 29d40e103ea5bca8a223fc8261b3322b9454e9af12Peter Collingbourne#include "llvm/Target/TargetOptions.h" 3050bee42b54cd9aec5f49566307df2b0cf23afcf6Craig Topper#include <map> 3150bee42b54cd9aec5f49566307df2b0cf23afcf6Craig Topper#include <string> 32255f89faee13dc491cb64fbeae3c763e7e2ea4e6Chandler Carruth#include <vector> 33f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar#include <functional> 34d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 35d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm { 36d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 379d87eb19be82b28d288e38eab3bbe145060a0701Reid Spencerstruct GenericValue; 38bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattnerclass Constant; 3913a3cf192887233fb9452ec5b7f841e4652c33c7Filip Pizloclass DataLayout; 404c5b23b24f230607fa18a162519875a91a5e89e0Jeffrey Yasskinclass ExecutionEngine; 41bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattnerclass Function; 423ddc05bdde6ed65f93340ea467d362e80c0ceb9cChris Lattnerclass GlobalVariable; 43b6c54ed8f50a351989993a5ef88507abc6d63e2dMisha Brukmanclass GlobalValue; 44df5a7daff9c7664bff8b713e8ed5155319bc6041Jeffrey Yasskinclass JITEventListener; 45df5a7daff9c7664bff8b713e8ed5155319bc6041Jeffrey Yasskinclass MachineCodeInfo; 460c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainarclass MCJITMemoryManager; 47df5a7daff9c7664bff8b713e8ed5155319bc6041Jeffrey Yasskinclass MutexGuard; 481c489455ea5fac43a5f20911dfb5486630eb0160Andrew Kaylorclass ObjectCache; 4913a3cf192887233fb9452ec5b7f841e4652c33c7Filip Pizloclass RTDyldMemoryManager; 509ea47179e647e806a2c67639bfead9d254514e59Dylan Noblesmithclass Triple; 51b6c54ed8f50a351989993a5ef88507abc6d63e2dMisha Brukmanclass Type; 52bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner 5336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesnamespace object { 5436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines class Archive; 5536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines class ObjectFile; 5636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines} 5736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 5848dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar/// \brief Helper class for helping synchronize access to the global address map 59c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines/// table. Access to this class should be serialized under a mutex. 60ee448630bdf7eb6037fe2c50518d32010c433ca3Reid Spencerclass ExecutionEngineState { 614c5b23b24f230607fa18a162519875a91a5e89e0Jeffrey Yasskinpublic: 620c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar typedef StringMap<uint64_t> GlobalAddressMapTy; 6323e5fcfec4640955fec41dc8348f467adf1a3e56Jeffrey Yasskin 64ee448630bdf7eb6037fe2c50518d32010c433ca3Reid Spencerprivate: 654c5b23b24f230607fa18a162519875a91a5e89e0Jeffrey Yasskin 660c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar /// GlobalAddressMap - A mapping between LLVM global symbol names values and 670c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar /// their actualized version... 6823e5fcfec4640955fec41dc8348f467adf1a3e56Jeffrey Yasskin GlobalAddressMapTy GlobalAddressMap; 69c8a07d7378699b8d11ce2a1549b984d84706da19Chris Lattner 70c8a07d7378699b8d11ce2a1549b984d84706da19Chris Lattner /// GlobalAddressReverseMap - This is the reverse mapping of GlobalAddressMap, 71c8a07d7378699b8d11ce2a1549b984d84706da19Chris Lattner /// used to convert raw addresses into the LLVM global value that is emitted 72c8a07d7378699b8d11ce2a1549b984d84706da19Chris Lattner /// at the address. This map is not computed unless getGlobalValueAtAddress 73c8a07d7378699b8d11ce2a1549b984d84706da19Chris Lattner /// is called at some point. 740c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar std::map<uint64_t, std::string> GlobalAddressReverseMap; 75ee448630bdf7eb6037fe2c50518d32010c433ca3Reid Spencer 76ee448630bdf7eb6037fe2c50518d32010c433ca3Reid Spencerpublic: 774c5b23b24f230607fa18a162519875a91a5e89e0Jeffrey Yasskin 78c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines GlobalAddressMapTy &getGlobalAddressMap() { 79ee448630bdf7eb6037fe2c50518d32010c433ca3Reid Spencer return GlobalAddressMap; 80ee448630bdf7eb6037fe2c50518d32010c433ca3Reid Spencer } 81ee448630bdf7eb6037fe2c50518d32010c433ca3Reid Spencer 820c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar std::map<uint64_t, std::string> &getGlobalAddressReverseMap() { 83ee448630bdf7eb6037fe2c50518d32010c433ca3Reid Spencer return GlobalAddressReverseMap; 84ee448630bdf7eb6037fe2c50518d32010c433ca3Reid Spencer } 85c89d27a440370455336202b2a8f25eb9c73e67bcJeffrey Yasskin 8648dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar /// \brief Erase an entry from the mapping table. 8748dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar /// 88c5252da873d547a19069eaf9030fec203f128f66Dmitri Gribenko /// \returns The address that \p ToUnmap was happed to. 890c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar uint64_t RemoveMapping(StringRef Name); 90ee448630bdf7eb6037fe2c50518d32010c433ca3Reid Spencer}; 91ee448630bdf7eb6037fe2c50518d32010c433ca3Reid Spencer 92f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainarusing FunctionCreator = std::function<void *(const std::string &)>; 93f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar 9448dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar/// \brief Abstract interface for implementation execution of LLVM modules, 9548dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar/// designed to support both interpreter and just-in-time (JIT) compiler 9648dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar/// implementations. 97ee448630bdf7eb6037fe2c50518d32010c433ca3Reid Spencerclass ExecutionEngine { 9848dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar /// The state object holding the global address mapping, which must be 9948dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar /// accessed synchronously. 10048dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar // 10148dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar // FIXME: There is no particular need the entire map needs to be 10248dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar // synchronized. Wouldn't a reader-writer design be better here? 1034c5b23b24f230607fa18a162519875a91a5e89e0Jeffrey Yasskin ExecutionEngineState EEState; 10448dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar 10548dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar /// The target data for the platform for which execution is being performed. 106f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// 107f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// Note: the DataLayout is LLVMContext specific because it has an 108f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// internal cache based on type pointers. It makes unsafe to reuse the 109f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// ExecutionEngine across context, we don't enforce this rule but undefined 110f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// behavior can occurs if the user tries to do it. 111f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar const DataLayout DL; 11248dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar 11348dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar /// Whether lazy JIT compilation is enabled. 114dc85724f703bddf6988b6b3f20203beab775f32bJeffrey Yasskin bool CompilingLazily; 11548dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar 11648dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar /// Whether JIT compilation of external global variables is allowed. 117446531e7bb4355117b070493ca8e81e4b123ef18Evan Cheng bool GVCompilationDisabled; 11848dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar 11948dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar /// Whether the JIT should perform lookups of external symbols (e.g., 12048dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar /// using dlsym). 121e846db667529eeeae531ce3b7382e18888d1eba0Chris Lattner bool SymbolSearchingDisabled; 122d958a5a9feea7239a73c2068f43f237db550f46eChris Lattner 123dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines /// Whether the JIT should verify IR modules during compilation. 124dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines bool VerifyModules; 125dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines 1264b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner friend class EngineBuilder; // To allow access to JITCtor and InterpCtor. 1274b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner 1281514b5b334c72e1e190fe1ce2bce7bf7d8a91c1aChris Lattnerprotected: 12948dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar /// The list of Modules that we are JIT'ing from. We use a SmallVector to 13048dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar /// optimize for the case where there is only one module. 13137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines SmallVector<std::unique_ptr<Module>, 1> Modules; 132f5b23368d27ef7dd44b2c45b5c08812ac99c7661Jim Grosbach 13346fa139e26be6ebc00be2fb45820c2560dd22a32Nicolas Geoffray /// getMemoryforGV - Allocate memory for a global variable. 13448dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar virtual char *getMemoryForGV(const GlobalVariable *GV); 135b6c54ed8f50a351989993a5ef88507abc6d63e2dMisha Brukman 136ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines static ExecutionEngine *(*MCJITCtor)( 1370c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar std::unique_ptr<Module> M, 1380c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar std::string *ErrorStr, 1390c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar std::shared_ptr<MCJITMemoryManager> MM, 1400c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar std::shared_ptr<RuntimeDyld::SymbolResolver> SR, 1410c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar std::unique_ptr<TargetMachine> TM); 142ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines 143ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines static ExecutionEngine *(*OrcMCJITReplacementCtor)( 1440c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar std::string *ErrorStr, 1450c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar std::shared_ptr<MCJITMemoryManager> MM, 1460c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar std::shared_ptr<RuntimeDyld::SymbolResolver> SR, 1470c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar std::unique_ptr<TargetMachine> TM); 148ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines 14937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines static ExecutionEngine *(*InterpCtor)(std::unique_ptr<Module> M, 15037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines std::string *ErrorStr); 151d958a5a9feea7239a73c2068f43f237db550f46eChris Lattner 152d958a5a9feea7239a73c2068f43f237db550f46eChris Lattner /// LazyFunctionCreator - If an unknown function is needed, this function 15348dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar /// pointer is invoked to create it. If this returns null, the JIT will 15448dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar /// abort. 155f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar FunctionCreator LazyFunctionCreator; 156f5b23368d27ef7dd44b2c45b5c08812ac99c7661Jim Grosbach 1570c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar /// getMangledName - Get mangled name. 1580c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar std::string getMangledName(const GlobalValue *GV); 1590c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar 160bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattnerpublic: 16137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines /// lock - This lock protects the ExecutionEngine and MCJIT classes. It must 16237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines /// be held while changing the internal state of any of those classes. 16348dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar sys::Mutex lock; 164ee448630bdf7eb6037fe2c50518d32010c433ca3Reid Spencer 165f4cc3096fd893cdef5b5c2664ebff8c13a07ad51Chris Lattner //===--------------------------------------------------------------------===// 1669f2f142d255bc96f109dd5c6524a485937b1f3a1Chris Lattner // ExecutionEngine Startup 167f4cc3096fd893cdef5b5c2664ebff8c13a07ad51Chris Lattner //===--------------------------------------------------------------------===// 168ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman 1699f2f142d255bc96f109dd5c6524a485937b1f3a1Chris Lattner virtual ~ExecutionEngine(); 170bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner 17137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines /// Add a Module to the list of modules that we can JIT from. 17237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines virtual void addModule(std::unique_ptr<Module> M) { 17337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines Modules.push_back(std::move(M)); 1742e40ae4de67ba37d02281d51e7dfd629205e1e30Chris Lattner } 175f5b23368d27ef7dd44b2c45b5c08812ac99c7661Jim Grosbach 17636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// addObjectFile - Add an ObjectFile to the execution engine. 17736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// 17836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// This method is only supported by MCJIT. MCJIT will immediately load the 17936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// object into memory and adds its symbols to the list used to resolve 18036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// external symbols while preparing other objects for execution. 18136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// 18236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// Objects added using this function will not be made executable until 18336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// needed by another object. 18436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// 18536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// MCJIT will take ownership of the ObjectFile. 186dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines virtual void addObjectFile(std::unique_ptr<object::ObjectFile> O); 18737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines virtual void addObjectFile(object::OwningBinary<object::ObjectFile> O); 18836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 18936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// addArchive - Add an Archive to the execution engine. 19036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// 19136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// This method is only supported by MCJIT. MCJIT will use the archive to 19236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// resolve external symbols in objects it is loading. If a symbol is found 19336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// in the Archive the contained object file will be extracted (in memory) 19436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// and loaded for possible execution. 19537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines virtual void addArchive(object::OwningBinary<object::Archive> A); 19636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 19748dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar //===--------------------------------------------------------------------===// 1989f2f142d255bc96f109dd5c6524a485937b1f3a1Chris Lattner 199f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar const DataLayout &getDataLayout() const { return DL; } 2009f2f142d255bc96f109dd5c6524a485937b1f3a1Chris Lattner 201f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin /// removeModule - Remove a Module from the list of modules. Returns true if 202f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin /// M is found. 203f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin virtual bool removeModule(Module *M); 20460789e419e04c260e36af9a1add5ad316313e490Nate Begeman 205f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// FindFunctionNamed - Search all of the active modules to find the function that 206fe854034677f59baca1e38075e71f6efca247a03Chris Lattner /// defines FnName. This is very slow operation and shouldn't be used for 207fe854034677f59baca1e38075e71f6efca247a03Chris Lattner /// general code. 2082ad18efdc73bc2356aa7fbf811d5ecbbaac0f2c9Andrew Kaylor virtual Function *FindFunctionNamed(const char *FnName); 209f5b23368d27ef7dd44b2c45b5c08812ac99c7661Jim Grosbach 210f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// FindGlobalVariableNamed - Search all of the active modules to find the global variable 211f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// that defines Name. This is very slow operation and shouldn't be used for 212f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// general code. 213f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar virtual GlobalVariable *FindGlobalVariableNamed(const char *Name, bool AllowInternal = false); 214f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar 215ff65e36be0f4fbe776ee6bb39b7ab14ebe3895ebChris Lattner /// runFunction - Execute the specified function with the specified arguments, 216ff65e36be0f4fbe776ee6bb39b7ab14ebe3895ebChris Lattner /// and return the result. 217ff65e36be0f4fbe776ee6bb39b7ab14ebe3895ebChris Lattner virtual GenericValue runFunction(Function *F, 2186948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar ArrayRef<GenericValue> ArgValues) = 0; 219ff65e36be0f4fbe776ee6bb39b7ab14ebe3895ebChris Lattner 22045a93d6eb4c55876e94f91b471657f23fe2149aaDanil Malyshev /// getPointerToNamedFunction - This method returns the address of the 22145a93d6eb4c55876e94f91b471657f23fe2149aaDanil Malyshev /// specified function by using the dlsym function call. As such it is only 22245a93d6eb4c55876e94f91b471657f23fe2149aaDanil Malyshev /// useful for resolving library symbols, not code generated symbols. 22345a93d6eb4c55876e94f91b471657f23fe2149aaDanil Malyshev /// 22445a93d6eb4c55876e94f91b471657f23fe2149aaDanil Malyshev /// If AbortOnFailure is false and no function with the given name is 22545a93d6eb4c55876e94f91b471657f23fe2149aaDanil Malyshev /// found, this function silently returns a null pointer. Otherwise, 22645a93d6eb4c55876e94f91b471657f23fe2149aaDanil Malyshev /// it prints a message to stderr and aborts. 22745a93d6eb4c55876e94f91b471657f23fe2149aaDanil Malyshev /// 2288e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor /// This function is deprecated for the MCJIT execution engine. 22937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines virtual void *getPointerToNamedFunction(StringRef Name, 23045a93d6eb4c55876e94f91b471657f23fe2149aaDanil Malyshev bool AbortOnFailure = true) = 0; 23145a93d6eb4c55876e94f91b471657f23fe2149aaDanil Malyshev 232020f4e861a9a32059f76377e787703c92ba55a98Jim Grosbach /// mapSectionAddress - map a section to its target address space value. 233020f4e861a9a32059f76377e787703c92ba55a98Jim Grosbach /// Map the address of a JIT section as returned from the memory manager 234020f4e861a9a32059f76377e787703c92ba55a98Jim Grosbach /// to the address in the target process as the running code will see it. 235020f4e861a9a32059f76377e787703c92ba55a98Jim Grosbach /// This is the address which will be used for relocation resolution. 2360c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar virtual void mapSectionAddress(const void *LocalAddress, 2370c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar uint64_t TargetAddress) { 23850bee42b54cd9aec5f49566307df2b0cf23afcf6Craig Topper llvm_unreachable("Re-mapping of section addresses not supported with this " 23950bee42b54cd9aec5f49566307df2b0cf23afcf6Craig Topper "EE!"); 240020f4e861a9a32059f76377e787703c92ba55a98Jim Grosbach } 241020f4e861a9a32059f76377e787703c92ba55a98Jim Grosbach 24237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines /// generateCodeForModule - Run code generation for the specified module and 2438e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor /// load it into memory. 2448e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor /// 2458e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor /// When this function has completed, all code and data for the specified 2468e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor /// module, and any module on which this module depends, will be generated 2478e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor /// and loaded into memory, but relocations will not yet have been applied 2488e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor /// and all memory will be readable and writable but not executable. 2498e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor /// 2508e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor /// This function is primarily useful when generating code for an external 2518e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor /// target, allowing the client an opportunity to remap section addresses 2528e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor /// before relocations are applied. Clients that intend to execute code 2538e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor /// locally can use the getFunctionAddress call, which will generate code 2548e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor /// and apply final preparations all in one step. 2558e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor /// 25637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines /// This method has no effect for the interpeter. 2578e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor virtual void generateCodeForModule(Module *M) {} 2588e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor 259abb38fe8dec11b1ea7535f84fac8ad0f0af70addDavid Tweed /// finalizeObject - ensure the module is fully processed and is usable. 260abb38fe8dec11b1ea7535f84fac8ad0f0af70addDavid Tweed /// 261abb38fe8dec11b1ea7535f84fac8ad0f0af70addDavid Tweed /// It is the user-level function for completing the process of making the 262abb38fe8dec11b1ea7535f84fac8ad0f0af70addDavid Tweed /// object usable for execution. It should be called after sections within an 263abb38fe8dec11b1ea7535f84fac8ad0f0af70addDavid Tweed /// object have been relocated using mapSectionAddress. When this method is 264abb38fe8dec11b1ea7535f84fac8ad0f0af70addDavid Tweed /// called the MCJIT execution engine will reapply relocations for a loaded 26537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines /// object. This method has no effect for the interpeter. 26628989889bf3aa3314562d438aece245b71176ec4Andrew Kaylor virtual void finalizeObject() {} 26728989889bf3aa3314562d438aece245b71176ec4Andrew Kaylor 2689ca6cdaee91fddcd3ea57dedcd624c14c7a40f65Chris Lattner /// runStaticConstructorsDestructors - This method is used to execute all of 26948dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar /// the static constructors or destructors for a program. 27048dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar /// 27148dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar /// \param isDtors - Run the destructors instead of constructors. 2722ad18efdc73bc2356aa7fbf811d5ecbbaac0f2c9Andrew Kaylor virtual void runStaticConstructorsDestructors(bool isDtors); 27348dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar 27437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines /// This method is used to execute all of the static constructors or 27537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines /// destructors for a particular module. 27648dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar /// 27748dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar /// \param isDtors - Run the destructors instead of constructors. 27837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines void runStaticConstructorsDestructors(Module &module, bool isDtors); 279f5b23368d27ef7dd44b2c45b5c08812ac99c7661Jim Grosbach 280f5b23368d27ef7dd44b2c45b5c08812ac99c7661Jim Grosbach 281e5dbbf2bddf7fc28d9f63a5e978af12184c80adaChris Lattner /// runFunctionAsMain - This is a helper function which wraps runFunction to 282e5dbbf2bddf7fc28d9f63a5e978af12184c80adaChris Lattner /// handle the common task of starting up main with the specified argc, argv, 283e5dbbf2bddf7fc28d9f63a5e978af12184c80adaChris Lattner /// and envp parameters. 284e5dbbf2bddf7fc28d9f63a5e978af12184c80adaChris Lattner int runFunctionAsMain(Function *Fn, const std::vector<std::string> &argv, 285e5dbbf2bddf7fc28d9f63a5e978af12184c80adaChris Lattner const char * const * envp); 286e5dbbf2bddf7fc28d9f63a5e978af12184c80adaChris Lattner 287e5dbbf2bddf7fc28d9f63a5e978af12184c80adaChris Lattner 288683d1bb712d8f8fc2d727a160da029c9cf40a423Chris Lattner /// addGlobalMapping - Tell the execution engine that the specified global is 289683d1bb712d8f8fc2d727a160da029c9cf40a423Chris Lattner /// at the specified location. This is used internally as functions are JIT'd 290683d1bb712d8f8fc2d727a160da029c9cf40a423Chris Lattner /// and as global variables are laid out in memory. It can and should also be 291683d1bb712d8f8fc2d727a160da029c9cf40a423Chris Lattner /// used by clients of the EE that want to have an LLVM global overlay 292de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar /// existing data in memory. Values to be mapped should be named, and have 293de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar /// external or weak linkage. Mappings are automatically removed when their 2944c5b23b24f230607fa18a162519875a91a5e89e0Jeffrey Yasskin /// GlobalValue is destroyed. 295683d1bb712d8f8fc2d727a160da029c9cf40a423Chris Lattner void addGlobalMapping(const GlobalValue *GV, void *Addr); 2960c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar void addGlobalMapping(StringRef Name, uint64_t Addr); 297f5b23368d27ef7dd44b2c45b5c08812ac99c7661Jim Grosbach 29848dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar /// clearAllGlobalMappings - Clear all global mappings and start over again, 29948dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar /// for use in dynamic compilation scenarios to move globals. 300683d1bb712d8f8fc2d727a160da029c9cf40a423Chris Lattner void clearAllGlobalMappings(); 301f5b23368d27ef7dd44b2c45b5c08812ac99c7661Jim Grosbach 302f049e07eb8930214941c72f8e4409df394de1567Nate Begeman /// clearGlobalMappingsFromModule - Clear all global mappings that came from a 303f049e07eb8930214941c72f8e4409df394de1567Nate Begeman /// particular module, because it has been removed from the JIT. 304f049e07eb8930214941c72f8e4409df394de1567Nate Begeman void clearGlobalMappingsFromModule(Module *M); 305f5b23368d27ef7dd44b2c45b5c08812ac99c7661Jim Grosbach 306f5feaf4fe381476b0ea567d7837c64b6590133e9Chris Lattner /// updateGlobalMapping - Replace an existing mapping for GV with a new 307683d1bb712d8f8fc2d727a160da029c9cf40a423Chris Lattner /// address. This updates both maps as required. If "Addr" is null, the 308f4cc3096fd893cdef5b5c2664ebff8c13a07ad51Chris Lattner /// entry for the global is removed from the mappings. This returns the old 309f4cc3096fd893cdef5b5c2664ebff8c13a07ad51Chris Lattner /// value of the pointer, or null if it was not in the map. 3100c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar uint64_t updateGlobalMapping(const GlobalValue *GV, void *Addr); 3110c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar uint64_t updateGlobalMapping(StringRef Name, uint64_t Addr); 3120c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar 3130c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar /// getAddressToGlobalIfAvailable - This returns the address of the specified 3140c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar /// global symbol. 3150c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar uint64_t getAddressToGlobalIfAvailable(StringRef S); 316f5b23368d27ef7dd44b2c45b5c08812ac99c7661Jim Grosbach 317895be4bae2c4f9a2fd2234f0329f618274e67eabChris Lattner /// getPointerToGlobalIfAvailable - This returns the address of the specified 318683d1bb712d8f8fc2d727a160da029c9cf40a423Chris Lattner /// global value if it is has already been codegen'd, otherwise it returns 319683d1bb712d8f8fc2d727a160da029c9cf40a423Chris Lattner /// null. 3200c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar void *getPointerToGlobalIfAvailable(StringRef S); 321683d1bb712d8f8fc2d727a160da029c9cf40a423Chris Lattner void *getPointerToGlobalIfAvailable(const GlobalValue *GV); 32270bca51f92871c7f9d3eac9ab68292c149fab53cChris Lattner 323895be4bae2c4f9a2fd2234f0329f618274e67eabChris Lattner /// getPointerToGlobal - This returns the address of the specified global 32448dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar /// value. This may involve code generation if it's a function. 3258e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor /// 3268e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor /// This function is deprecated for the MCJIT execution engine. Use 3278e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor /// getGlobalValueAddress instead. 328bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner void *getPointerToGlobal(const GlobalValue *GV); 329bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner 330895be4bae2c4f9a2fd2234f0329f618274e67eabChris Lattner /// getPointerToFunction - The different EE's represent function bodies in 331895be4bae2c4f9a2fd2234f0329f618274e67eabChris Lattner /// different ways. They should each implement this to say what a function 3324c5b23b24f230607fa18a162519875a91a5e89e0Jeffrey Yasskin /// pointer should look like. When F is destroyed, the ExecutionEngine will 3337a9034c4db248fe8b8cb82762881b51b221988d3Jeffrey Yasskin /// remove its global mapping and free any machine code. Be sure no threads 3347a9034c4db248fe8b8cb82762881b51b221988d3Jeffrey Yasskin /// are running inside F when that happens. 3358e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor /// 3368e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor /// This function is deprecated for the MCJIT execution engine. Use 3378e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor /// getFunctionAddress instead. 338fb0ef2e82cb2e80983c097100ae168af68ee8e7bBrian Gaeke virtual void *getPointerToFunction(Function *F) = 0; 339bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner 340895be4bae2c4f9a2fd2234f0329f618274e67eabChris Lattner /// getPointerToFunctionOrStub - If the specified function has been 341895be4bae2c4f9a2fd2234f0329f618274e67eabChris Lattner /// code-gen'd, return a pointer to the function. If not, compile it, or use 3424c5b23b24f230607fa18a162519875a91a5e89e0Jeffrey Yasskin /// a stub to implement lazy compilation if available. See 3434c5b23b24f230607fa18a162519875a91a5e89e0Jeffrey Yasskin /// getPointerToFunction for the requirements on destroying F. 3448e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor /// 3458e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor /// This function is deprecated for the MCJIT execution engine. Use 3468e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor /// getFunctionAddress instead. 34718cb4c3c747ac2439ca9fb1218edd8993df69d7aChris Lattner virtual void *getPointerToFunctionOrStub(Function *F) { 34818cb4c3c747ac2439ca9fb1218edd8993df69d7aChris Lattner // Default implementation, just codegen the function. 34918cb4c3c747ac2439ca9fb1218edd8993df69d7aChris Lattner return getPointerToFunction(F); 35018cb4c3c747ac2439ca9fb1218edd8993df69d7aChris Lattner } 35118cb4c3c747ac2439ca9fb1218edd8993df69d7aChris Lattner 3528e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor /// getGlobalValueAddress - Return the address of the specified global 3538e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor /// value. This may involve code generation. 3548e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor /// 35537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines /// This function should not be called with the interpreter engine. 3568e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor virtual uint64_t getGlobalValueAddress(const std::string &Name) { 35737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines // Default implementation for the interpreter. MCJIT will override this. 3588e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor // JIT and interpreter clients should use getPointerToGlobal instead. 3598e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor return 0; 3608e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor } 3618e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor 3628e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor /// getFunctionAddress - Return the address of the specified function. 3638e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor /// This may involve code generation. 3648e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor virtual uint64_t getFunctionAddress(const std::string &Name) { 36537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines // Default implementation for the interpreter. MCJIT will override this. 36637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines // Interpreter clients should use getPointerToFunction instead. 3678e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor return 0; 3688e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor } 3698e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor 370c8a07d7378699b8d11ce2a1549b984d84706da19Chris Lattner /// getGlobalValueAtAddress - Return the LLVM global value object that starts 371c8a07d7378699b8d11ce2a1549b984d84706da19Chris Lattner /// at the specified address. 372c8a07d7378699b8d11ce2a1549b984d84706da19Chris Lattner /// 373c8a07d7378699b8d11ce2a1549b984d84706da19Chris Lattner const GlobalValue *getGlobalValueAtAddress(void *Addr); 374c8a07d7378699b8d11ce2a1549b984d84706da19Chris Lattner 37548dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar /// StoreValueToMemory - Stores the data in Val of type Ty at address Ptr. 37648dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar /// Ptr is the address of the memory at which to store Val, cast to 37748dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar /// GenericValue *. It is not a pointer to a GenericValue containing the 37848dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar /// address at which to store Val. 379f4cc3096fd893cdef5b5c2664ebff8c13a07ad51Chris Lattner void StoreValueToMemory(const GenericValue &Val, GenericValue *Ptr, 380db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner Type *Ty); 38148dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbar 38229794cba810ec249a9ede5ea77333a71579fd182Brian Gaeke void InitializeMemory(const Constant *Init, void *Addr); 38329794cba810ec249a9ede5ea77333a71579fd182Brian Gaeke 3841514b5b334c72e1e190fe1ce2bce7bf7d8a91c1aChris Lattner /// getOrEmitGlobalVariable - Return the address of the specified global 3851514b5b334c72e1e190fe1ce2bce7bf7d8a91c1aChris Lattner /// variable, possibly emitting it to memory if needed. This is used by the 3864c5b23b24f230607fa18a162519875a91a5e89e0Jeffrey Yasskin /// Emitter. 3878e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor /// 3888e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor /// This function is deprecated for the MCJIT execution engine. Use 3898e9ec015348c5419b905c2ca6e39534429eda073Andrew Kaylor /// getGlobalValueAddress instead. 3901514b5b334c72e1e190fe1ce2bce7bf7d8a91c1aChris Lattner virtual void *getOrEmitGlobalVariable(const GlobalVariable *GV) { 39172ea0c9ffaa1700730c8ce36e9b73aef4b914988Galina Kistanova return getPointerToGlobal((const GlobalValue *)GV); 3921514b5b334c72e1e190fe1ce2bce7bf7d8a91c1aChris Lattner } 393df5a7daff9c7664bff8b713e8ed5155319bc6041Jeffrey Yasskin 394df5a7daff9c7664bff8b713e8ed5155319bc6041Jeffrey Yasskin /// Registers a listener to be called back on various events within 395df5a7daff9c7664bff8b713e8ed5155319bc6041Jeffrey Yasskin /// the JIT. See JITEventListener.h for more details. Does not 396df5a7daff9c7664bff8b713e8ed5155319bc6041Jeffrey Yasskin /// take ownership of the argument. The argument may be NULL, in 397df5a7daff9c7664bff8b713e8ed5155319bc6041Jeffrey Yasskin /// which case these functions do nothing. 398df225c0253aa987830fbd3dfcb5d9f8f7f973336Bill Wendling virtual void RegisterJITEventListener(JITEventListener *) {} 399df225c0253aa987830fbd3dfcb5d9f8f7f973336Bill Wendling virtual void UnregisterJITEventListener(JITEventListener *) {} 400df5a7daff9c7664bff8b713e8ed5155319bc6041Jeffrey Yasskin 4011c489455ea5fac43a5f20911dfb5486630eb0160Andrew Kaylor /// Sets the pre-compiled object cache. The ownership of the ObjectCache is 40237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines /// not changed. Supported by MCJIT but not the interpreter. 4031c489455ea5fac43a5f20911dfb5486630eb0160Andrew Kaylor virtual void setObjectCache(ObjectCache *) { 4041c489455ea5fac43a5f20911dfb5486630eb0160Andrew Kaylor llvm_unreachable("No support for an object cache"); 4051c489455ea5fac43a5f20911dfb5486630eb0160Andrew Kaylor } 4061c489455ea5fac43a5f20911dfb5486630eb0160Andrew Kaylor 40736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// setProcessAllSections (MCJIT Only): By default, only sections that are 40836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// "required for execution" are passed to the RTDyldMemoryManager, and other 40936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// sections are discarded. Passing 'true' to this method will cause 41036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// RuntimeDyld to pass all sections to its RTDyldMemoryManager regardless 41136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// of whether they are "required to execute" in the usual sense. 41236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// 41336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// Rationale: Some MCJIT clients want to be able to inspect metadata 41436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// sections (e.g. Dwarf, Stack-maps) to enable functionality or analyze 41536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// performance. Passing these sections to the memory manager allows the 41636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// client to make policy about the relevant sections, rather than having 41736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// MCJIT do it. 41836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines virtual void setProcessAllSections(bool ProcessAllSections) { 41936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines llvm_unreachable("No support for ProcessAllSections option"); 42036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines } 42136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 42236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// Return the target machine (if available). 423dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines virtual TargetMachine *getTargetMachine() { return nullptr; } 42436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 42518fec73e29d68b9c7473720507f51de39b0873b1Jeffrey Yasskin /// DisableLazyCompilation - When lazy compilation is off (the default), the 426dc85724f703bddf6988b6b3f20203beab775f32bJeffrey Yasskin /// JIT will eagerly compile every function reachable from the argument to 427dc85724f703bddf6988b6b3f20203beab775f32bJeffrey Yasskin /// getPointerToFunction. If lazy compilation is turned on, the JIT will only 428dc85724f703bddf6988b6b3f20203beab775f32bJeffrey Yasskin /// compile the one function and emit stubs to compile the rest when they're 429dc85724f703bddf6988b6b3f20203beab775f32bJeffrey Yasskin /// first called. If lazy compilation is turned off again while some lazy 430dc85724f703bddf6988b6b3f20203beab775f32bJeffrey Yasskin /// stubs are still around, and one of those stubs is called, the program will 431dc85724f703bddf6988b6b3f20203beab775f32bJeffrey Yasskin /// abort. 432dc85724f703bddf6988b6b3f20203beab775f32bJeffrey Yasskin /// 433dc85724f703bddf6988b6b3f20203beab775f32bJeffrey Yasskin /// In order to safely compile lazily in a threaded program, the user must 434dc85724f703bddf6988b6b3f20203beab775f32bJeffrey Yasskin /// ensure that 1) only one thread at a time can call any particular lazy 435dc85724f703bddf6988b6b3f20203beab775f32bJeffrey Yasskin /// stub, and 2) any thread modifying LLVM IR must hold the JIT's lock 436dc85724f703bddf6988b6b3f20203beab775f32bJeffrey Yasskin /// (ExecutionEngine::lock) or otherwise ensure that no other thread calls a 437dc85724f703bddf6988b6b3f20203beab775f32bJeffrey Yasskin /// lazy stub. See http://llvm.org/PR5184 for details. 43818fec73e29d68b9c7473720507f51de39b0873b1Jeffrey Yasskin void DisableLazyCompilation(bool Disabled = true) { 43918fec73e29d68b9c7473720507f51de39b0873b1Jeffrey Yasskin CompilingLazily = !Disabled; 4401c1a44699049cf56713a46ccaef7c747e4a888a3Chris Lattner } 441dc85724f703bddf6988b6b3f20203beab775f32bJeffrey Yasskin bool isCompilingLazily() const { 442dc85724f703bddf6988b6b3f20203beab775f32bJeffrey Yasskin return CompilingLazily; 4431c1a44699049cf56713a46ccaef7c747e4a888a3Chris Lattner } 444446531e7bb4355117b070493ca8e81e4b123ef18Evan Cheng 44577f86ad08775e0ed2a704ef09ffff3dbd6e04583Evan Cheng /// DisableGVCompilation - If called, the JIT will abort if it's asked to 44677f86ad08775e0ed2a704ef09ffff3dbd6e04583Evan Cheng /// allocate space and populate a GlobalVariable that is not internal to 44777f86ad08775e0ed2a704ef09ffff3dbd6e04583Evan Cheng /// the module. 448446531e7bb4355117b070493ca8e81e4b123ef18Evan Cheng void DisableGVCompilation(bool Disabled = true) { 449446531e7bb4355117b070493ca8e81e4b123ef18Evan Cheng GVCompilationDisabled = Disabled; 450446531e7bb4355117b070493ca8e81e4b123ef18Evan Cheng } 451446531e7bb4355117b070493ca8e81e4b123ef18Evan Cheng bool isGVCompilationDisabled() const { 452446531e7bb4355117b070493ca8e81e4b123ef18Evan Cheng return GVCompilationDisabled; 453446531e7bb4355117b070493ca8e81e4b123ef18Evan Cheng } 454446531e7bb4355117b070493ca8e81e4b123ef18Evan Cheng 455e846db667529eeeae531ce3b7382e18888d1eba0Chris Lattner /// DisableSymbolSearching - If called, the JIT will not try to lookup unknown 456e846db667529eeeae531ce3b7382e18888d1eba0Chris Lattner /// symbols with dlsym. A client can still use InstallLazyFunctionCreator to 457e846db667529eeeae531ce3b7382e18888d1eba0Chris Lattner /// resolve symbols in a custom way. 458e846db667529eeeae531ce3b7382e18888d1eba0Chris Lattner void DisableSymbolSearching(bool Disabled = true) { 459e846db667529eeeae531ce3b7382e18888d1eba0Chris Lattner SymbolSearchingDisabled = Disabled; 460e846db667529eeeae531ce3b7382e18888d1eba0Chris Lattner } 461e846db667529eeeae531ce3b7382e18888d1eba0Chris Lattner bool isSymbolSearchingDisabled() const { 462e846db667529eeeae531ce3b7382e18888d1eba0Chris Lattner return SymbolSearchingDisabled; 463e846db667529eeeae531ce3b7382e18888d1eba0Chris Lattner } 4646f348e458660063a40052b208bab96895c822877Jeffrey Yasskin 465dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines /// Enable/Disable IR module verification. 466dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines /// 467dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines /// Note: Module verification is enabled by default in Debug builds, and 468dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines /// disabled by default in Release. Use this method to override the default. 469dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines void setVerifyModules(bool Verify) { 470dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines VerifyModules = Verify; 471dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines } 472dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines bool getVerifyModules() const { 473dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines return VerifyModules; 474dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines } 475dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines 476d958a5a9feea7239a73c2068f43f237db550f46eChris Lattner /// InstallLazyFunctionCreator - If an unknown function is needed, the 477d958a5a9feea7239a73c2068f43f237db550f46eChris Lattner /// specified function pointer is invoked to create it. If it returns null, 478d958a5a9feea7239a73c2068f43f237db550f46eChris Lattner /// the JIT will abort. 479f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar void InstallLazyFunctionCreator(FunctionCreator C) { 480de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar LazyFunctionCreator = std::move(C); 481d958a5a9feea7239a73c2068f43f237db550f46eChris Lattner } 482f5b23368d27ef7dd44b2c45b5c08812ac99c7661Jim Grosbach 48356adf152f6354a9b5609e059050fd2315ad5960cChris Lattnerprotected: 484de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar ExecutionEngine(DataLayout DL) : DL(std::move(DL)) {} 485f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar explicit ExecutionEngine(DataLayout DL, std::unique_ptr<Module> M); 48637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines explicit ExecutionEngine(std::unique_ptr<Module> M); 4879f2f142d255bc96f109dd5c6524a485937b1f3a1Chris Lattner 488bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner void emitGlobals(); 4893ddc05bdde6ed65f93340ea467d362e80c0ceb9cChris Lattner 4901514b5b334c72e1e190fe1ce2bce7bf7d8a91c1aChris Lattner void EmitGlobalVariable(const GlobalVariable *GV); 4913ddc05bdde6ed65f93340ea467d362e80c0ceb9cChris Lattner 492bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner GenericValue getConstantValue(const Constant *C); 493f5b23368d27ef7dd44b2c45b5c08812ac99c7661Jim Grosbach void LoadValueFromMemory(GenericValue &Result, GenericValue *Ptr, 494db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner Type *Ty); 495f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar 496f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainarprivate: 497f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar void Init(std::unique_ptr<Module> M); 498bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner}; 499bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner 5004b1511b027ce0b648b3379f2891816c25b46f515Reid Klecknernamespace EngineKind { 5014b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner // These are actually bitmasks that get or-ed together. 5024b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner enum Kind { 5034b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner JIT = 0x1, 5044b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner Interpreter = 0x2 5054b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner }; 5064b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner const static Kind Either = (Kind)(JIT | Interpreter); 5074b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner} 5084b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner 50937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines/// Builder class for ExecutionEngines. Use this by stack-allocating a builder, 51037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines/// chaining the various set* methods, and terminating it with a .create() 51137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines/// call. 5124b1511b027ce0b648b3379f2891816c25b46f515Reid Klecknerclass EngineBuilder { 51348dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbarprivate: 51437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines std::unique_ptr<Module> M; 5154b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner EngineKind::Kind WhichEngine; 5164b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner std::string *ErrorStr; 5174b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner CodeGenOpt::Level OptLevel; 5180c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar std::shared_ptr<MCJITMemoryManager> MemMgr; 5190c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar std::shared_ptr<RuntimeDyld::SymbolResolver> Resolver; 520d40e103ea5bca8a223fc8261b3322b9454e9af12Peter Collingbourne TargetOptions Options; 521de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar Optional<Reloc::Model> RelocModel; 52288b5aca20a6dd0a8b15ff620bdee59aae567d245Eric Christopher CodeModel::Model CMModel; 5234688261c20735f5ead2f08695acdeb727db31894Jeffrey Yasskin std::string MArch; 5244688261c20735f5ead2f08695acdeb727db31894Jeffrey Yasskin std::string MCPU; 5254688261c20735f5ead2f08695acdeb727db31894Jeffrey Yasskin SmallVector<std::string, 4> MAttrs; 526dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines bool VerifyModules; 527ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines bool UseOrcMCJITReplacement; 5284b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner 52948dd875be12006060260526e4a1df0bae48dd5c9Daniel Dunbarpublic: 530ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines /// Default constructor for EngineBuilder. 531ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines EngineBuilder(); 532ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines 53337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines /// Constructor for EngineBuilder. 534ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines EngineBuilder(std::unique_ptr<Module> M); 535ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines 536ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines // Out-of-line since we don't have the def'n of RTDyldMemoryManager here. 537ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines ~EngineBuilder(); 5384b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner 5394b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner /// setEngineKind - Controls whether the user wants the interpreter, the JIT, 5404b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner /// or whichever engine works. This option defaults to EngineKind::Either. 5414b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner EngineBuilder &setEngineKind(EngineKind::Kind w) { 5424b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner WhichEngine = w; 5434b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner return *this; 5444b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner } 54536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 54613a3cf192887233fb9452ec5b7f841e4652c33c7Filip Pizlo /// setMCJITMemoryManager - Sets the MCJIT memory manager to use. This allows 54713a3cf192887233fb9452ec5b7f841e4652c33c7Filip Pizlo /// clients to customize their memory allocation policies for the MCJIT. This 54813a3cf192887233fb9452ec5b7f841e4652c33c7Filip Pizlo /// is only appropriate for the MCJIT; setting this and configuring the builder 54913a3cf192887233fb9452ec5b7f841e4652c33c7Filip Pizlo /// to create anything other than MCJIT will cause a runtime error. If create() 55013a3cf192887233fb9452ec5b7f841e4652c33c7Filip Pizlo /// is called and is successful, the created engine takes ownership of the 55137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines /// memory manager. This option defaults to NULL. 552ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines EngineBuilder &setMCJITMemoryManager(std::unique_ptr<RTDyldMemoryManager> mcjmm); 5534b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner 5540c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar EngineBuilder& 5550c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar setMemoryManager(std::unique_ptr<MCJITMemoryManager> MM); 5560c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar 5570c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar EngineBuilder& 5580c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar setSymbolResolver(std::unique_ptr<RuntimeDyld::SymbolResolver> SR); 5590c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar 5604b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner /// setErrorStr - Set the error string to write to on error. This option 5614b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner /// defaults to NULL. 5624b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner EngineBuilder &setErrorStr(std::string *e) { 5634b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner ErrorStr = e; 5644b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner return *this; 5654b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner } 5664b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner 5674b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner /// setOptLevel - Set the optimization level for the JIT. This option 5684b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner /// defaults to CodeGenOpt::Default. 5694b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner EngineBuilder &setOptLevel(CodeGenOpt::Level l) { 5704b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner OptLevel = l; 5714b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner return *this; 5724b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner } 5734b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner 574d40e103ea5bca8a223fc8261b3322b9454e9af12Peter Collingbourne /// setTargetOptions - Set the target options that the ExecutionEngine 575d40e103ea5bca8a223fc8261b3322b9454e9af12Peter Collingbourne /// target is using. Defaults to TargetOptions(). 576d40e103ea5bca8a223fc8261b3322b9454e9af12Peter Collingbourne EngineBuilder &setTargetOptions(const TargetOptions &Opts) { 577d40e103ea5bca8a223fc8261b3322b9454e9af12Peter Collingbourne Options = Opts; 578d40e103ea5bca8a223fc8261b3322b9454e9af12Peter Collingbourne return *this; 579d40e103ea5bca8a223fc8261b3322b9454e9af12Peter Collingbourne } 580d40e103ea5bca8a223fc8261b3322b9454e9af12Peter Collingbourne 581439661395fd2a2a832dba01c65bc88718528313cEvan Cheng /// setRelocationModel - Set the relocation model that the ExecutionEngine 582439661395fd2a2a832dba01c65bc88718528313cEvan Cheng /// target is using. Defaults to target specific default "Reloc::Default". 583439661395fd2a2a832dba01c65bc88718528313cEvan Cheng EngineBuilder &setRelocationModel(Reloc::Model RM) { 584439661395fd2a2a832dba01c65bc88718528313cEvan Cheng RelocModel = RM; 585439661395fd2a2a832dba01c65bc88718528313cEvan Cheng return *this; 586439661395fd2a2a832dba01c65bc88718528313cEvan Cheng } 587439661395fd2a2a832dba01c65bc88718528313cEvan Cheng 58888b5aca20a6dd0a8b15ff620bdee59aae567d245Eric Christopher /// setCodeModel - Set the CodeModel that the ExecutionEngine target 58934ad6db8b958fdc0d38e122edf753b5326e69b03Evan Cheng /// data is using. Defaults to target specific default 59034ad6db8b958fdc0d38e122edf753b5326e69b03Evan Cheng /// "CodeModel::JITDefault". 59188b5aca20a6dd0a8b15ff620bdee59aae567d245Eric Christopher EngineBuilder &setCodeModel(CodeModel::Model M) { 59288b5aca20a6dd0a8b15ff620bdee59aae567d245Eric Christopher CMModel = M; 59388b5aca20a6dd0a8b15ff620bdee59aae567d245Eric Christopher return *this; 59488b5aca20a6dd0a8b15ff620bdee59aae567d245Eric Christopher } 59588b5aca20a6dd0a8b15ff620bdee59aae567d245Eric Christopher 5964688261c20735f5ead2f08695acdeb727db31894Jeffrey Yasskin /// setMArch - Override the architecture set by the Module's triple. 5974688261c20735f5ead2f08695acdeb727db31894Jeffrey Yasskin EngineBuilder &setMArch(StringRef march) { 5984688261c20735f5ead2f08695acdeb727db31894Jeffrey Yasskin MArch.assign(march.begin(), march.end()); 5994688261c20735f5ead2f08695acdeb727db31894Jeffrey Yasskin return *this; 6004688261c20735f5ead2f08695acdeb727db31894Jeffrey Yasskin } 6014688261c20735f5ead2f08695acdeb727db31894Jeffrey Yasskin 6024688261c20735f5ead2f08695acdeb727db31894Jeffrey Yasskin /// setMCPU - Target a specific cpu type. 6034688261c20735f5ead2f08695acdeb727db31894Jeffrey Yasskin EngineBuilder &setMCPU(StringRef mcpu) { 6044688261c20735f5ead2f08695acdeb727db31894Jeffrey Yasskin MCPU.assign(mcpu.begin(), mcpu.end()); 6054688261c20735f5ead2f08695acdeb727db31894Jeffrey Yasskin return *this; 6064688261c20735f5ead2f08695acdeb727db31894Jeffrey Yasskin } 6074688261c20735f5ead2f08695acdeb727db31894Jeffrey Yasskin 608dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines /// setVerifyModules - Set whether the JIT implementation should verify 609dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines /// IR modules during compilation. 610dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines EngineBuilder &setVerifyModules(bool Verify) { 611dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines VerifyModules = Verify; 612dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines return *this; 613dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines } 614dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines 6154688261c20735f5ead2f08695acdeb727db31894Jeffrey Yasskin /// setMAttrs - Set cpu-specific attributes. 6164688261c20735f5ead2f08695acdeb727db31894Jeffrey Yasskin template<typename StringSequence> 6174688261c20735f5ead2f08695acdeb727db31894Jeffrey Yasskin EngineBuilder &setMAttrs(const StringSequence &mattrs) { 6184688261c20735f5ead2f08695acdeb727db31894Jeffrey Yasskin MAttrs.clear(); 6194688261c20735f5ead2f08695acdeb727db31894Jeffrey Yasskin MAttrs.append(mattrs.begin(), mattrs.end()); 6204688261c20735f5ead2f08695acdeb727db31894Jeffrey Yasskin return *this; 6214688261c20735f5ead2f08695acdeb727db31894Jeffrey Yasskin } 6224688261c20735f5ead2f08695acdeb727db31894Jeffrey Yasskin 623ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines // \brief Use OrcMCJITReplacement instead of MCJIT. Off by default. 624ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines void setUseOrcMCJITReplacement(bool UseOrcMCJITReplacement) { 625ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines this->UseOrcMCJITReplacement = UseOrcMCJITReplacement; 626ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines } 627ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines 6288e1fc56b2496270d1d6040cb648eef5d5aeb6079Owen Anderson TargetMachine *selectTarget(); 6298e1fc56b2496270d1d6040cb648eef5d5aeb6079Owen Anderson 6302ea29ba2a8ddd7ba4b946eb754f1a39304d9fc09Dylan Noblesmith /// selectTarget - Pick a target either via -march or by guessing the native 6312ea29ba2a8ddd7ba4b946eb754f1a39304d9fc09Dylan Noblesmith /// arch. Add any CPU features specified via -mcpu or -mattr. 6328e1fc56b2496270d1d6040cb648eef5d5aeb6079Owen Anderson TargetMachine *selectTarget(const Triple &TargetTriple, 6338e1fc56b2496270d1d6040cb648eef5d5aeb6079Owen Anderson StringRef MArch, 6348e1fc56b2496270d1d6040cb648eef5d5aeb6079Owen Anderson StringRef MCPU, 6358e1fc56b2496270d1d6040cb648eef5d5aeb6079Owen Anderson const SmallVectorImpl<std::string>& MAttrs); 6368e1fc56b2496270d1d6040cb648eef5d5aeb6079Owen Anderson 6378e1fc56b2496270d1d6040cb648eef5d5aeb6079Owen Anderson ExecutionEngine *create() { 6388e1fc56b2496270d1d6040cb648eef5d5aeb6079Owen Anderson return create(selectTarget()); 6398e1fc56b2496270d1d6040cb648eef5d5aeb6079Owen Anderson } 6408e1fc56b2496270d1d6040cb648eef5d5aeb6079Owen Anderson 6418e1fc56b2496270d1d6040cb648eef5d5aeb6079Owen Anderson ExecutionEngine *create(TargetMachine *TM); 6424b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner}; 6434b1511b027ce0b648b3379f2891816c25b46f515Reid Kleckner 64440be1e85665d10f5444186f0e7106e368dd735b8Filip Pizlo// Create wrappers for C Binding types (see CBindingWrapping.h). 64540be1e85665d10f5444186f0e7106e368dd735b8Filip PizloDEFINE_SIMPLE_CONVERSION_FUNCTIONS(ExecutionEngine, LLVMExecutionEngineRef) 64643dfffe890f58468e2fe01f312978d7aa5303801Eric Christopher 647d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke} // End llvm namespace 648d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 649bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner#endif 650