llvm.org GIT mirror llvm / 6aec298
MCJIT: Stub out MCJIT implementation, still doesn't do anything useful. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119509 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Dunbar 9 years ago
9 changed file(s) with 309 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
0 //===-- MCJIT.h - MC-Based Just-In-Time Execution Engine --------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file forces the MCJIT to link in on certain operating systems.
10 // (Windows).
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_EXECUTION_ENGINE_MCJIT_H
15 #define LLVM_EXECUTION_ENGINE_MCJIT_H
16
17 #include "llvm/ExecutionEngine/ExecutionEngine.h"
18 #include
19
20 extern "C" void LLVMLinkInMCJIT();
21
22 namespace {
23 struct ForceMCJITLinking {
24 ForceMCJITLinking() {
25 // We must reference the passes in such a way that compilers will not
26 // delete it all as dead code, even with whole program optimization,
27 // yet is effectively a NO-OP. As the compiler isn't smart enough
28 // to know that getenv() never returns -1, this will do the job.
29 if (std::getenv("bar") != (char*) -1)
30 return;
31
32 LLVMLinkInMCJIT();
33 }
34 } ForceMCJITLinking;
35 }
36
37 #endif
0 add_llvm_library(LLVMMCJIT
1 MCJIT.cpp
2 TargetSelect.cpp
3 )
0 //===-- JIT.cpp - MC-based Just-in-Time Compiler --------------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "MCJIT.h"
10 #include "llvm/ExecutionEngine/GenericValue.h"
11 #include "llvm/ExecutionEngine/MCJIT.h"
12 #include "llvm/Support/ErrorHandling.h"
13 #include "llvm/System/DynamicLibrary.h"
14
15 using namespace llvm;
16
17 namespace {
18
19 static struct RegisterJIT {
20 RegisterJIT() { MCJIT::Register(); }
21 } JITRegistrator;
22
23 }
24
25 extern "C" void LLVMLinkInMCJIT() {
26 }
27
28 ExecutionEngine *MCJIT::createJIT(Module *M,
29 std::string *ErrorStr,
30 JITMemoryManager *JMM,
31 CodeGenOpt::Level OptLevel,
32 bool GVsWithCode,
33 CodeModel::Model CMM,
34 StringRef MArch,
35 StringRef MCPU,
36 const SmallVectorImpl& MAttrs) {
37 // Try to register the program as a source of symbols to resolve against.
38 //
39 // FIXME: Don't do this here.
40 sys::DynamicLibrary::LoadLibraryPermanently(0, NULL);
41
42 // Pick a target either via -march or by guessing the native arch.
43 //
44 // FIXME: This should be lifted out of here, it isn't something which should
45 // be part of the JIT policy, rather the burden for this selection should be
46 // pushed to clients.
47 TargetMachine *TM = MCJIT::selectTarget(M, MArch, MCPU, MAttrs, ErrorStr);
48 if (!TM || (ErrorStr && ErrorStr->length() > 0)) return 0;
49 TM->setCodeModel(CMM);
50
51 // If the target supports JIT code generation, create the JIT.
52 if (TargetJITInfo *TJ = TM->getJITInfo())
53 return new MCJIT(M, *TM, *TJ, JMM, OptLevel, GVsWithCode);
54
55 if (ErrorStr)
56 *ErrorStr = "target does not support JIT code generation";
57 return 0;
58 }
59
60 MCJIT::MCJIT(Module *M, TargetMachine &tm, TargetJITInfo &tji,
61 JITMemoryManager *JMM, CodeGenOpt::Level OptLevel,
62 bool AllocateGVsWithCode)
63 : ExecutionEngine(M) {
64 }
65
66 MCJIT::~MCJIT() {
67 }
68
69 void *MCJIT::getPointerToBasicBlock(BasicBlock *BB) {
70 report_fatal_error("not yet implemented");
71 return 0;
72 }
73
74 void *MCJIT::getPointerToFunction(Function *F) {
75 report_fatal_error("not yet implemented");
76 return 0;
77 }
78
79 void *MCJIT::recompileAndRelinkFunction(Function *F) {
80 report_fatal_error("not yet implemented");
81 }
82
83 void MCJIT::freeMachineCodeForFunction(Function *F) {
84 report_fatal_error("not yet implemented");
85 }
86
87 GenericValue MCJIT::runFunction(Function *F,
88 const std::vector &ArgValues) {
89 report_fatal_error("not yet implemented");
90 return GenericValue();
91 }
0 //===-- MCJIT.h - Class definition for the MCJIT ----------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_LIB_EXECUTIONENGINE_MCJIT_H
10 #define LLVM_LIB_EXECUTIONENGINE_MCJIT_H
11
12 #include "llvm/ExecutionEngine/ExecutionEngine.h"
13
14 namespace llvm {
15
16 class MCJIT : public ExecutionEngine {
17 MCJIT(Module *M, TargetMachine &tm, TargetJITInfo &tji,
18 JITMemoryManager *JMM, CodeGenOpt::Level OptLevel,
19 bool AllocateGVsWithCode);
20 public:
21 ~MCJIT();
22
23 /// @name ExecutionEngine interface implementation
24 /// @{
25
26 virtual void *getPointerToBasicBlock(BasicBlock *BB);
27
28 virtual void *getPointerToFunction(Function *F);
29
30 virtual void *recompileAndRelinkFunction(Function *F);
31
32 virtual void freeMachineCodeForFunction(Function *F);
33
34 virtual GenericValue runFunction(Function *F,
35 const std::vector &ArgValues);
36
37 /// @}
38 /// @name (Private) Registration Interfaces
39 /// @{
40
41 static void Register() {
42 MCJITCtor = createJIT;
43 }
44
45 // FIXME: This routine is scheduled for termination. Do not use it.
46 static TargetMachine *selectTarget(Module *M,
47 StringRef MArch,
48 StringRef MCPU,
49 const SmallVectorImpl& MAttrs,
50 std::string *Err);
51
52 static ExecutionEngine *createJIT(Module *M,
53 std::string *ErrorStr,
54 JITMemoryManager *JMM,
55 CodeGenOpt::Level OptLevel,
56 bool GVsWithCode,
57 CodeModel::Model CMM,
58 StringRef MArch,
59 StringRef MCPU,
60 const SmallVectorImpl& MAttrs);
61
62 // @}
63 };
64
65 } // End llvm namespace
66
67 #endif
0 ##===- lib/ExecutionEngine/MCJIT/Makefile ------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open Source
5 # License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8
9 LEVEL = ../../..
10 LIBRARYNAME = LLVMMCJIT
11
12 include $(LEVEL)/Makefile.common
0 //===-- TargetSelect.cpp - Target Chooser Code ----------------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This just asks the TargetRegistry for the appropriate JIT to use, and allows
10 // the user to specify a specific one on the commandline with -march=x. Clients
11 // should initialize targets prior to calling createJIT.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "MCJIT.h"
16 #include "llvm/Module.h"
17 #include "llvm/ADT/Triple.h"
18 #include "llvm/Support/CommandLine.h"
19 #include "llvm/Support/raw_ostream.h"
20 #include "llvm/System/Host.h"
21 #include "llvm/Target/SubtargetFeature.h"
22 #include "llvm/Target/TargetMachine.h"
23 #include "llvm/Target/TargetRegistry.h"
24 using namespace llvm;
25
26 /// selectTarget - Pick a target either via -march or by guessing the native
27 /// arch. Add any CPU features specified via -mcpu or -mattr.
28 TargetMachine *MCJIT::selectTarget(Module *Mod,
29 StringRef MArch,
30 StringRef MCPU,
31 const SmallVectorImpl& MAttrs,
32 std::string *ErrorStr) {
33 Triple TheTriple(Mod->getTargetTriple());
34 if (TheTriple.getTriple().empty())
35 TheTriple.setTriple(sys::getHostTriple());
36
37 // Adjust the triple to match what the user requested.
38 const Target *TheTarget = 0;
39 if (!MArch.empty()) {
40 for (TargetRegistry::iterator it = TargetRegistry::begin(),
41 ie = TargetRegistry::end(); it != ie; ++it) {
42 if (MArch == it->getName()) {
43 TheTarget = &*it;
44 break;
45 }
46 }
47
48 if (!TheTarget) {
49 *ErrorStr = "No available targets are compatible with this -march, "
50 "see -version for the available targets.\n";
51 return 0;
52 }
53
54 // Adjust the triple to match (if known), otherwise stick with the
55 // module/host triple.
56 Triple::ArchType Type = Triple::getArchTypeForLLVMName(MArch);
57 if (Type != Triple::UnknownArch)
58 TheTriple.setArch(Type);
59 } else {
60 std::string Error;
61 TheTarget = TargetRegistry::lookupTarget(TheTriple.getTriple(), Error);
62 if (TheTarget == 0) {
63 if (ErrorStr)
64 *ErrorStr = Error;
65 return 0;
66 }
67 }
68
69 if (!TheTarget->hasJIT()) {
70 errs() << "WARNING: This target JIT is not designed for the host you are"
71 << " running. If bad things happen, please choose a different "
72 << "-march switch.\n";
73 }
74
75 // Package up features to be passed to target/subtarget
76 std::string FeaturesStr;
77 if (!MCPU.empty() || !MAttrs.empty()) {
78 SubtargetFeatures Features;
79 Features.setCPU(MCPU);
80 for (unsigned i = 0; i != MAttrs.size(); ++i)
81 Features.AddFeature(MAttrs[i]);
82 FeaturesStr = Features.getString();
83 }
84
85 // Allocate a target...
86 TargetMachine *Target =
87 TheTarget->createTargetMachine(TheTriple.getTriple(), FeaturesStr);
88 assert(Target && "Could not allocate target machine!");
89 return Target;
90 }
77 ##===----------------------------------------------------------------------===##
88 LEVEL = ../..
99 LIBRARYNAME = LLVMExecutionEngine
10 PARALLEL_DIRS = Interpreter JIT
10 PARALLEL_DIRS = Interpreter JIT MCJIT
1111
1212 include $(LEVEL)/Makefile.common
88
99 LEVEL := ../..
1010 TOOLNAME := lli
11 LINK_COMPONENTS := jit interpreter nativecodegen bitreader asmparser selectiondag
11 LINK_COMPONENTS := mcjit jit interpreter nativecodegen bitreader asmparser selectiondag
1212
1313 # Enable JIT support
1414 include $(LEVEL)/Makefile.common
2222 #include "llvm/ExecutionEngine/Interpreter.h"
2323 #include "llvm/ExecutionEngine/JIT.h"
2424 #include "llvm/ExecutionEngine/JITEventListener.h"
25 #include "llvm/ExecutionEngine/MCJIT.h"
2526 #include "llvm/Support/CommandLine.h"
2627 #include "llvm/Support/IRReader.h"
2728 #include "llvm/Support/ManagedStatic.h"