Skip to content

Commit 3ad692c

Browse files
committed
chore: add more docs
1 parent cda67f7 commit 3ad692c

File tree

4 files changed

+68
-17
lines changed

4 files changed

+68
-17
lines changed

immix/llvm/memory_manager.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/*
2+
LLVM memory manager for Pivot Lang
3+
4+
This is very muck a work in progress.
5+
We are using this to get immix working with JIT.
6+
*/
7+
18
#include "llvm-c/ExecutionEngine.h"
29
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
310
#include "llvm-c/Core.h"

immix/llvm/plimmix.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,20 @@
44
#include "llvm/Support/Compiler.h"
55
#include "plimmixprinter.cpp"
66
#include "plimmix_pass.cpp"
7+
#include "llvm/Passes/PassBuilder.h"
8+
#include "llvm/Passes/PassPlugin.h"
9+
10+
#include "llvm-c/Types.h"
11+
#include "llvm-c/Transforms/PassBuilder.h"
712

813
using namespace llvm;
914

1015
namespace
1116
{
17+
/*
18+
This is the GC strategy for immix.
19+
It is used to register our immix GC with LLVM.
20+
*/
1221
class LLVM_LIBRARY_VISIBILITY PLImmixGC : public GCStrategy
1322
{
1423
public:
@@ -29,17 +38,16 @@ extern "C" void LLVMLinkPLImmixGC()
2938
}
3039
#include "llvm-c/Transforms/PassManagerBuilder.h"
3140

32-
extern "C" void add_module_pass(llvm::legacy::PassManagerBase * PB) {
41+
extern "C" void add_module_pass(llvm::legacy::PassManagerBase *PB) {
3342
PB->add(new ImmixLegacy());
3443

3544
}
36-
#include "llvm/Passes/PassBuilder.h"
37-
#include "llvm/Passes/PassPlugin.h"
38-
39-
#include "llvm-c/Types.h"
40-
#include "llvm-c/Transforms/PassBuilder.h"
45+
/*
46+
param: opt opt level
4147
42-
// param: opt opt level
48+
The new LLVM Pass Manager does not have official C bindings yet.
49+
So we have to write one ourselves.
50+
*/
4351
extern "C" void run_module_pass(LLVMModuleRef M, int opt) {
4452
// These must be declared in this order so that they are destroyed in the
4553
// correct order due to inter-analysis-manager references.
@@ -92,6 +100,9 @@ extern "C" void run_module_pass(LLVMModuleRef M, int opt) {
92100
}
93101

94102

103+
/*
104+
Shadow stack implementation for immix. (used in JIT mode, but may not work now)
105+
*/
95106
extern "C"
96107
{
97108
/// The map for a single function's stack frame. One of these is

immix/llvm/plimmix_pass.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
Some LLVM passes helpful for
3+
integrating immix with LLVM
4+
*/
5+
16
#include "llvm/IR/PassManager.h"
27
#include "llvm/IR/IRBuilder.h"
38
#include "llvm/Transforms/Utils/ModuleUtils.h"
@@ -10,6 +15,7 @@ using namespace llvm;
1015
namespace
1116
{
1217
void immixPassLogic(Module &M);
18+
// The new pass manager plugin
1319
class ImmixPass : public PassInfoMixin<ImmixPass>
1420
{
1521
static char ID;
@@ -23,6 +29,24 @@ namespace
2329
return PreservedAnalyses::all();
2430
}
2531

32+
/*
33+
This pass helps integrate immix with LLVM.
34+
35+
It does the following:
36+
- Sets the GC name to "plimmix" for all functions
37+
- Adds a call to immix_gc_init in the global constructor
38+
- Adds a global variable declaration for the module stack map
39+
40+
However, it does not generate the stack map. This is done by the
41+
immix compiler plugin.
42+
43+
Also note that mauch more work is needed to get immix working with
44+
LLVM. Besides the pass, you need to:
45+
- Implement visit functions for all complex types
46+
- insert stack roots for all heap pointers
47+
- replace all malloc calls with immix::alloc
48+
...
49+
*/
2650
void immixPassLogic(Module &M)
2751
{
2852
for (auto FB = M.functions().begin(), FE = M.functions().end(); FB != FE; ++FB)
@@ -51,6 +75,8 @@ namespace
5175
// appendToCompilerUsed(M, gc_init_f);
5276
appendToGlobalCtors(M, gc_init_f, 1000);
5377
}
78+
79+
// The old pass manager plugin
5480
struct ImmixLegacy : public ModulePass
5581
{
5682
static char ID;

immix/llvm/plimmixprinter.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
#include "llvm/CodeGen/GCMetadataPrinter.h"
22
#include "llvm/Support/Compiler.h"
3+
#include "llvm/CodeGen/AsmPrinter.h"
4+
#include "llvm/IR/Function.h"
5+
#include "llvm/IR/DataLayout.h"
6+
// #include "llvm/Target/TargetAsmInfo.h"
7+
#include "llvm/Target/TargetMachine.h"
8+
#include "llvm/IR/GCStrategy.h"
9+
#include "llvm/CodeGen/GCMetadata.h"
10+
#include "llvm/MC/MCStreamer.h"
11+
#include "llvm/Target/TargetLoweringObjectFile.h"
12+
#include "llvm/MC/MCAsmInfo.h"
313
using namespace llvm;
414

515
namespace
616
{
17+
/*
18+
Stackmap printer for immix.
19+
*/
720
class LLVM_LIBRARY_VISIBILITY PLImmixGCPrinter : public GCMetadataPrinter
821
{
922
public:
@@ -17,22 +30,16 @@ namespace
1730
P("plimmix", "pivot-lang immix garbage collector.");
1831
}
1932

20-
#include "llvm/CodeGen/AsmPrinter.h"
21-
#include "llvm/IR/Function.h"
22-
#include "llvm/IR/DataLayout.h"
23-
// #include "llvm/Target/TargetAsmInfo.h"
24-
#include "llvm/Target/TargetMachine.h"
25-
#include "llvm/IR/GCStrategy.h"
26-
#include "llvm/CodeGen/GCMetadata.h"
27-
#include "llvm/MC/MCStreamer.h"
28-
#include "llvm/Target/TargetLoweringObjectFile.h"
29-
#include "llvm/MC/MCAsmInfo.h"
3033

3134
void PLImmixGCPrinter::beginAssembly(Module &M, GCModuleInfo &Info, AsmPrinter &AP)
3235
{
3336
// Nothing to do.
3437
}
3538

39+
40+
/*
41+
We need to emit the stack map in the data section.
42+
*/
3643
void PLImmixGCPrinter::finishAssembly(Module &M, GCModuleInfo &Info, AsmPrinter &AP)
3744
{
3845
unsigned IntPtrSize = AP.getPointerSize();

0 commit comments

Comments
 (0)