This repository was archived by the owner on Jul 3, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 7 files changed +47
-3
lines changed
Expand file tree Collapse file tree 7 files changed +47
-3
lines changed Original file line number Diff line number Diff line change @@ -108,8 +108,13 @@ dump_target_properties(JitFromScratch COMPILE_DEFINITIONS)
108108dump_target_properties(JitFromScratch LINK_LIBRARIES )
109109dump_target_properties(JitFromScratch LINK_FLAGS )
110110
111+ # Only LLVM Debug builds can parse debug arguments
112+ if (${LLVM_BUILD_TYPE} STREQUAL "Debug" AND CMAKE_BUILD_TYPE STREQUAL "Debug" )
113+ set (debug_args -debug -debug-only=jitfromscratch)
114+ endif ()
115+
111116add_custom_target (run
112- COMMAND $<TARGET_FILE:JitFromScratch>
117+ COMMAND $<TARGET_FILE:JitFromScratch> ${debug_args}
113118 COMMENT "Running JitFromScratch"
114119)
115120
Original file line number Diff line number Diff line change 11#include " JitFromScratch.h"
22
33#include < llvm/ExecutionEngine/Orc/ThreadSafeModule.h>
4+ #include < llvm/Support/Debug.h>
5+
6+ #define DEBUG_TYPE " jitfromscratch"
47
58using namespace llvm ;
69using namespace llvm ::orc;
710
8- JitFromScratch::JitFromScratch (ExitOnError ExitOnErr)
9- : LLJIT(ExitOnErr(LLJITBuilder().create())) {}
11+ JitFromScratch::JitFromScratch (ExitOnError ExitOnErr) {
12+ LLJITBuilder Builder;
13+ ExitOnErr (Builder.prepareForConstruction ());
14+ TT = Builder.JTMB ->getTargetTriple ();
15+ LLJIT = ExitOnErr (Builder.create ());
16+ }
1017
1118Error JitFromScratch::submitModule (std::unique_ptr<Module> M,
1219 std::unique_ptr<LLVMContext> C) {
20+ LLVM_DEBUG (dbgs () << " Submit IR module:\n\n " << *M << " \n\n " );
1321 return LLJIT->addIRModule (ThreadSafeModule (std::move (M), std::move (C)));
1422}
Original file line number Diff line number Diff line change 11#pragma once
22
3+ #include < llvm/ADT/Triple.h>
34#include < llvm/ExecutionEngine/Orc/LLJIT.h>
45#include < llvm/IR/DataLayout.h>
56#include < llvm/IR/LLVMContext.h>
@@ -22,8 +23,13 @@ class JitFromScratch {
2223 return LLJIT->getDataLayout ();
2324 }
2425
26+ const llvm::Triple &getTargetTriple () const {
27+ return TT;
28+ }
29+
2530 llvm::Error submitModule (std::unique_ptr<llvm::Module> M,
2631 std::unique_ptr<llvm::LLVMContext> C);
2732private:
2833 std::unique_ptr<llvm::orc::LLJIT> LLJIT;
34+ llvm::Triple TT;
2935};
Original file line number Diff line number Diff line change 22#include < llvm/IR/DataLayout.h>
33#include < llvm/IR/LLVMContext.h>
44#include < llvm/IR/Module.h>
5+ #include < llvm/Support/CommandLine.h>
6+ #include < llvm/Support/Debug.h>
57#include < llvm/Support/Error.h>
68#include < llvm/Support/Format.h>
79#include < llvm/Support/InitLLVM.h>
1214
1315#include " JitFromScratch.h"
1416
17+ #define DEBUG_TYPE " jitfromscratch"
18+
1519using namespace llvm ;
1620
1721Expected<std::string> codegenIR (Module &module , unsigned items) {
@@ -61,11 +65,17 @@ int main(int argc, char **argv) {
6165 InitializeNativeTargetAsmPrinter ();
6266 InitializeNativeTargetAsmParser ();
6367
68+ // Parse implicit -debug and -debug-only options.
69+ cl::ParseCommandLineOptions (argc, argv, " JitFromScratch example project\n " );
70+
6471 int x[]{0 , 1 , 2 };
6572 int y[]{3 , 1 , -1 };
6673
6774 JitFromScratch Jit (ExitOnErr);
6875
76+ LLVM_DEBUG (dbgs () << " JITing for host target: "
77+ << Jit.getTargetTriple ().normalize () << " \n\n " );
78+
6979 auto C = std::make_unique<LLVMContext>();
7080 auto M = std::make_unique<Module>(" JitFromScratch" , *C);
7181 M->setDataLayout (Jit.getDataLayout ());
Original file line number Diff line number Diff line change 1010config .test_source_root = os .path .dirname (__file__ )
1111config .suffixes = ['.test' ]
1212
13+ if config .build_type .lower () == "debug" :
14+ config .suffixes .append ('.test-debug' )
15+
1316# Add binary directories for JitFromScratch and FileCheck executables
1417llvm_config .with_environment ('PATH' , config .jitfromscratch_build_dir , append_path = True )
1518llvm_config .with_environment ('PATH' , config .llvm_tools_dir , append_path = True )
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
66config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@"
77config.python_executable = "@PYTHON_EXECUTABLE@"
88config.jitfromscratch_build_dir = "@CMAKE_BINARY_DIR@/@CMAKE_CFG_INTDIR@"
9+ config.build_type = "@CMAKE_BUILD_TYPE@"
910
1011import lit.llvm
1112lit.llvm.initialize(lit_config, config)
Original file line number Diff line number Diff line change 1+ # Check that output from LLVM_DEBUG is printed in Debug mode (dumps to stderr)
2+ # RUN: JitFromScratch -debug -debug-only=jitfromscratch 2>&1 | FileCheck %s
3+
4+ # CHECK: JITing for host target: {{.*}}
5+ # CHECK-EMPTY:
6+ # CHECK-NEXT: Submit IR module:
7+ # CHECK-EMPTY:
8+ # CHECK-NEXT: ; ModuleID = 'JitFromScratch'
9+ # CHECK-NEXT: source_filename = "JitFromScratch"
10+
11+ # CHECK: Integer Distances: 3, 0, 3
You can’t perform that action at this time.
0 commit comments