# aakri0/prescient architecture

> Architecture diagram of the GitHub repository aakri0/prescient, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aakri0/prescient
- Repository: https://github.com/aakri0/prescient

## Overview

Prescient is an LLVM 17 plugin and Python model that predicts per-function compile cost from unoptimised IR features, then selects a lighter or full optimisation pipeline. Its main workflow runs from C/C++ input through feature extraction and prediction to adaptive optimisation; a separate corpus-and-timing path trains the model. The web UI exposes analysis results and predictions. Some subsystem links are based on the README because their source was not sampled.

Main entry points: [`src/model/predict.py`](https://github.com/aakri0/prescient/blob/main/src/model/predict.py) (Cost Prediction), [`frontend/server.py`](https://github.com/aakri0/prescient/blob/main/frontend/server.py) (Analysis API), [`src/model/train_model.py`](https://github.com/aakri0/prescient/blob/main/src/model/train_model.py) (Model Training), [`scripts/generate_corpus.py`](https://github.com/aakri0/prescient/blob/main/scripts/generate_corpus.py) (Training Corpus)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_llvm["LLVM Analysis"]
  node_features["IR Feature Extractor"]
  node_feature_json["Feature Records"]
end

subgraph group_model["Prediction Model"]
  node_train["Model Training<br/>[train_model.py]"]
  node_trained_models[("Trained Models")]
  node_importance["Feature Importance"]
  node_predict["Cost Prediction<br/>[predict.py]"]
  node_render["Table Rendering<br/>[_render.py]"]
  node_show_features["Feature Display<br/>[show_features.py]"]
  node_predictions["Prediction Records"]
end

subgraph group_training["Training And Evaluation"]
  node_timing["Pass Timing Hooks"]
  node_timings_csv["Pass Timings"]
  node_corpus["Training Corpus<br/>[generate_corpus.py]"]
  node_evaluation["Evaluation Suite<br/>[evaluate.py]"]
  node_savings["Savings Report"]
end

subgraph group_runtime["Adaptive Optimisation"]
  node_adaptive["Adaptive Pipeline"]
  node_optimized["Optimized IR"]
end

subgraph group_web["Web Interface"]
  node_browser["Browser UI<br/>[app.js]"]
  node_server["Analysis API<br/>[server.py]"]
end

node_user(("User"))
node_source["C/C++ Source"]
node_llvm_tools["LLVM Tools"]

node_source -->|"analyzes IR"| node_features
node_features -->|"writes features"| node_feature_json
node_source -->|"supplies programs"| node_corpus
node_corpus -->|"collects timings"| node_timing
node_timing -->|"records pass times"| node_timings_csv
node_corpus -->|"provides training data"| node_train
node_timings_csv -->|"labels training data"| node_train
node_train -->|"fits and saves"| node_trained_models
node_train -->|"generates report"| node_importance
node_feature_json -->|"provides features"| node_predict
node_trained_models -->|"loads models"| node_predict
node_predict -->|"writes predictions"| node_predictions
node_predict -->|"renders tables"| node_render
node_show_features -->|"renders table"| node_render
node_predictions -->|"selects tiers"| node_adaptive
node_adaptive -->|"runs pipeline"| node_optimized
node_user -->|"submits code"| node_browser
node_browser -->|"posts analysis"| node_server
node_server -->|"invokes compilation"| node_llvm_tools
node_server -->|"runs feature pass"| node_features
node_server -->|"runs prediction"| node_predict
node_evaluation -->|"evaluates cases"| node_source
node_savings -.->|"reports savings"| node_timings_csv

click node_features "https://github.com/aakri0/prescient/blob/main/src/passes/IRComplexityPass.cpp"
click node_timing "https://github.com/aakri0/prescient/blob/main/src/timing/PassTimingWrapper.cpp"
click node_corpus "https://github.com/aakri0/prescient/blob/main/scripts/generate_corpus.py"
click node_train "https://github.com/aakri0/prescient/blob/main/src/model/train_model.py"
click node_importance "https://github.com/aakri0/prescient/blob/main/src/model/feature_importance.py"
click node_predict "https://github.com/aakri0/prescient/blob/main/src/model/predict.py"
click node_render "https://github.com/aakri0/prescient/blob/main/src/model/_render.py"
click node_show_features "https://github.com/aakri0/prescient/blob/main/src/model/show_features.py"
click node_adaptive "https://github.com/aakri0/prescient/blob/main/src/passes/AdaptivePipeline.cpp"
click node_evaluation "https://github.com/aakri0/prescient/blob/main/scripts/evaluate.py"
click node_savings "https://github.com/aakri0/prescient/blob/main/scripts/generate_savings_report.py"
click node_browser "https://github.com/aakri0/prescient/blob/main/frontend/app.js"
click node_server "https://github.com/aakri0/prescient/blob/main/frontend/server.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_features,node_feature_json,node_user toneBlue
class node_train,node_trained_models,node_importance,node_predict,node_render,node_show_features,node_predictions toneAmber
class node_timing,node_timings_csv,node_corpus,node_evaluation,node_savings toneMint
class node_adaptive,node_optimized toneRose
class node_browser,node_server,node_source,node_llvm_tools toneIndigo
```

## Components

### LLVM Analysis

- [IR Feature Extractor](https://github.com/aakri0/prescient/blob/main/src/passes/IRComplexityPass.cpp): `src/passes/IRComplexityPass.cpp`
- **Feature Records**

### Prediction Model

- [Model Training](https://github.com/aakri0/prescient/blob/main/src/model/train_model.py): `src/model/train_model.py`
- **Trained Models**
- [Feature Importance](https://github.com/aakri0/prescient/blob/main/src/model/feature_importance.py): `src/model/feature_importance.py`
- [Cost Prediction](https://github.com/aakri0/prescient/blob/main/src/model/predict.py): `src/model/predict.py`
- [Table Rendering](https://github.com/aakri0/prescient/blob/main/src/model/_render.py): `src/model/_render.py`
- [Feature Display](https://github.com/aakri0/prescient/blob/main/src/model/show_features.py): `src/model/show_features.py`
- **Prediction Records**

### Training And Evaluation

- [Pass Timing Hooks](https://github.com/aakri0/prescient/blob/main/src/timing/PassTimingWrapper.cpp): `src/timing/PassTimingWrapper.cpp`
- **Pass Timings**
- [Training Corpus](https://github.com/aakri0/prescient/blob/main/scripts/generate_corpus.py): `scripts/generate_corpus.py`
- [Evaluation Suite](https://github.com/aakri0/prescient/blob/main/scripts/evaluate.py): `scripts/evaluate.py`
- [Savings Report](https://github.com/aakri0/prescient/blob/main/scripts/generate_savings_report.py): `scripts/generate_savings_report.py`

### Adaptive Optimisation

- [Adaptive Pipeline](https://github.com/aakri0/prescient/blob/main/src/passes/AdaptivePipeline.cpp): `src/passes/AdaptivePipeline.cpp`
- **Optimized IR**

### Web Interface

- [Browser UI](https://github.com/aakri0/prescient/blob/main/frontend/app.js): `frontend/app.js`
- [Analysis API](https://github.com/aakri0/prescient/blob/main/frontend/server.py): `frontend/server.py`

### Other components

- **User**
- **C/C++ Source**
- **LLVM Tools**

## Connections

- C/C++ Source → IR Feature Extractor: analyzes IR
- IR Feature Extractor → Feature Records: writes features
- C/C++ Source → Training Corpus: supplies programs
- Training Corpus → Pass Timing Hooks: collects timings
- Pass Timing Hooks → Pass Timings: records pass times
- Training Corpus → Model Training: provides training data
- Pass Timings → Model Training: labels training data
- Model Training → Trained Models: fits and saves (evidence: `src/model/train_model.py`)
- Model Training → Feature Importance: generates report (evidence: `src/model/train_model.py`)
- Feature Records → Cost Prediction: provides features
- Trained Models → Cost Prediction: loads models (evidence: `src/model/predict.py`)
- Cost Prediction → Prediction Records: writes predictions
- Cost Prediction → Table Rendering: renders tables (evidence: `src/model/predict.py`)
- Feature Display → Table Rendering: renders table (evidence: `src/model/show_features.py`)
- Prediction Records → Adaptive Pipeline: selects tiers
- Adaptive Pipeline → Optimized IR: runs pipeline
- User → Browser UI: submits code
- Browser UI → Analysis API: posts analysis (evidence: `frontend/app.js`)
- Analysis API → LLVM Tools: invokes compilation (evidence: `frontend/server.py`)
- Analysis API → IR Feature Extractor: runs feature pass (evidence: `frontend/server.py`)
- Analysis API → Cost Prediction: runs prediction (evidence: `frontend/server.py`)
- Evaluation Suite → C/C++ Source: evaluates cases
- Savings Report → Pass Timings: reports savings
