Skip to content

Commit 619b06e

Browse files
ptersilievext01
andcommitted
Add control point patching pass.
This change adds a LLVM pass which replaces a call to a dummy control (`yk_control_point`) point with a call to a dynamically generated control point (`yk_new_control_point`) containing all of the necessary logic to start and stop tracing, and to jump to machine code etc. The logic is *very* simplified for now, but this should be a good starting point. In order for LLVM to not optimise away some of the control point logic (e.g. the IOStruct) this pass has to run very late in the pipeline. The pass is also only enabled when `--yk-patch-control-point` is passed. See the comment at the top of ControlPoint.cpp for more details. Co-authored-by: Edd Barrett <[email protected]>
1 parent 6d85f07 commit 619b06e

File tree

11 files changed

+425
-0
lines changed

11 files changed

+425
-0
lines changed

.buildbot.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ make -j `nproc` install
2121
make -j `nproc` check-all
2222
cd ..
2323

24+
# clang-format any new files that we've introduced ourselves.
25+
PATH=${INST_DIR}/bin:${PATH}
26+
sh yk_format_new_files.sh
27+
git diff --exit-code
28+
2429
# FIXME The commented code below should run the `test-suite` tests, as
2530
# described at https://llvm.org/docs/TestSuiteGuide.html.
2631
#
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef LLVM_TRANSFORMS_YK_CONTROLPOINT_H
2+
#define LLVM_TRANSFORMS_YK_CONTROLPOINT_H
3+
4+
#include "llvm/IR/PassManager.h"
5+
6+
// The name of the "dummy function" that the user puts in their interpreter
7+
// implementation and that we will replace with our own code.
8+
#define YK_DUMMY_CONTROL_POINT "yk_control_point"
9+
10+
// The name of the new control point replacing the user's dummy control point.
11+
#define YK_NEW_CONTROL_POINT "yk_new_control_point"
12+
13+
namespace llvm {
14+
class ModulePass;
15+
ModulePass *createYkControlPointPass();
16+
} // namespace llvm
17+
18+
#endif

llvm/lib/CodeGen/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ add_llvm_component_library(LLVMCodeGen
216216
Support
217217
Target
218218
TransformUtils
219+
YkControlPoint
219220
)
220221

221222
add_subdirectory(SelectionDAG)

llvm/lib/Passes/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ add_llvm_component_library(LLVMPasses
2525
TransformUtils
2626
Vectorize
2727
Instrumentation
28+
YkControlPoint
2829
)

llvm/lib/Transforms/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ add_subdirectory(Hello)
99
add_subdirectory(ObjCARC)
1010
add_subdirectory(Coroutines)
1111
add_subdirectory(CFGuard)
12+
add_subdirectory(Yk)

llvm/lib/Transforms/IPO/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,5 @@ add_llvm_component_library(LLVMipo
7171
TransformUtils
7272
Vectorize
7373
Instrumentation
74+
YkControlPoint
7475
)

llvm/lib/Transforms/IPO/PassManagerBuilder.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include "llvm/Transforms/Vectorize/LoopVectorize.h"
5252
#include "llvm/Transforms/Vectorize/SLPVectorizer.h"
5353
#include "llvm/Transforms/Vectorize/VectorCombine.h"
54+
#include "llvm/Transforms/Yk/ControlPoint.h"
5455

5556
using namespace llvm;
5657

@@ -188,6 +189,11 @@ cl::opt<AttributorRunOption> AttributorRun(
188189
clEnumValN(AttributorRunOption::NONE, "none",
189190
"disable attributor runs")));
190191

192+
static cl::opt<bool>
193+
YkPatchCtrlPoint("yk-patch-control-point",
194+
cl::init(false), cl::NotHidden,
195+
cl::desc("Patch yk_control_point()"));
196+
191197
extern cl::opt<bool> EnableKnowledgeRetention;
192198
} // namespace llvm
193199

@@ -1240,6 +1246,13 @@ void PassManagerBuilder::populateLTOPassManager(legacy::PassManagerBase &PM) {
12401246

12411247
PM.add(createAnnotationRemarksLegacyPass());
12421248

1249+
// We add the yk control point pass late in the pipeline (after all
1250+
// optimisation and just before verification and codegen) so that no IR
1251+
// optimisation passes have a chance to change the interface to the control
1252+
// point. The JIT runtime relies on the signature not being changed.
1253+
if (YkPatchCtrlPoint)
1254+
PM.add(createYkControlPointPass());
1255+
12431256
if (VerifyOutput)
12441257
PM.add(createVerifierPass());
12451258
}

llvm/lib/Transforms/Yk/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
add_llvm_component_library(LLVMYkControlPoint
2+
ControlPoint.cpp
3+
4+
DEPENDS
5+
intrinsics_gen
6+
7+
LINK_COMPONENTS
8+
Core
9+
Support
10+
)

0 commit comments

Comments
 (0)