Skip to content

Commit 5c2d4ff

Browse files
author
Vasileios Porpodas
committed
[SandboxIR][Doc] Add Quick start notes
1 parent 4089314 commit 5c2d4ff

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

llvm/docs/SandboxIR.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,41 @@
22

33
Sandbox IR is an IR layer on top of LLVM IR that allows you to save/restore its state.
44

5+
# Quick Start Notes
6+
7+
Within your LLVM pass:
8+
9+
```
10+
// 1. Include the necessary Sandbox IR header files.
11+
#include "llvm/SandboxIR/Context.h
12+
#include "llvm/SandboxIR/Function.h
13+
14+
// 2. Create a sandboxir::Context using LLVMContext `LLVMCtx`.
15+
sandboxir::Context Ctx(LLVMCtx);
16+
17+
// 3. Create a sandboxir::Function using LLVM IR Function `LLVMF`.
18+
auto *F = Ctx.createFunction(LLVMF);
19+
20+
// ... Use Sandbox IR in `F` as usual, e.g., iterating, modifying it etc. ...
21+
22+
// 4. Save state when needed.
23+
Ctx.save();
24+
25+
// ... Modify Sandbox IR ...
26+
27+
// 5. Revert to the saved state.
28+
Ctx.revert();
29+
```
30+
31+
Make sure you link against `SandboxIR` in `CMakeLists.txt`:
32+
33+
```
34+
LINK_COMPONENTS
35+
...
36+
SandboxIR
37+
...
38+
```
39+
540
# API
641
The Sandbox IR API is designed to feel like LLVM, replicating many common API classes and functions to mirror the LLVM API.
742
The class hierarchy is similar (but in the `llvm::sandboxir` namespace).

0 commit comments

Comments
 (0)