# source:docs/Working/icGrep/architecture.tex@4468

Last change on this file since 4468 was 4466, checked in by cameron, 4 years ago

Evaluation of optimization; diagram tweaks

File size: 5.6 KB
Line
1\section{Architecture}\label{sec:architecture}
2\subsection{Regular Expression Preprocessing}
3
4\input{fig-compiler}
5
6As show in Figure \ref{fig:compiler},
7icGrep is composed of three logical layers: \RegularExpression{}, \Pablo{} and the LLVM layer, each with their own intermediate representation
8(IR), transformation and compilation modules.
9%
10As we traverse the layers, the IR becomes significantly more complex as it begins to mirror the final machine code.
11%
12The \REParser{} validates and transforms the input \RegularExpression{} into an abstract syntax tree (AST).
13%
14The AST is a minimalistic representation that, unlike traditional \RegularExpression{}, is not converted into a NFA or DFA for further processing.
15%
16Instead, icGrep passes the AST into the transformation module, which includes a set of \RegularExpression{} specific optimization passes.
17%
18The initial \emph{Nullable} pass, determines whether the \RegularExpression{} contains any prefixes or suffixes that may be removed or
19modified whilst still providing the same number of matches as the original expression.
20%
21For example, \verb|a*bc+|'' is equivalent to \verb|bc|'' because the Kleene Star (Plus) operator matches zero (one) or more instances of a
22specific character.
23%
24The \emph{toUTF8} pass converts the characters in the input \RegularExpression{} into the equivalent expression(s) that represent the sequences
25of 8-bit code units necessary to identify the presence of a particular character.
26%
27Since some characters have multiple logically equivalent representations, such as \textcolor{red}{\textbf{????}}, this may produce nested sequences or alternations.
28%
29This is described in more detail in \S\ref{sec:Unicode:toUTF8}.
30%
31To alleviate this, the final \emph{Simplification} pass flattens nested sequences and alternations into their simplest legal form.
32%
33For example, \verba(b((c|d)|e))'' would become \verbab(c|d|e)'' and \verb([0-9]{3,5}){3,5}'', \verb[0-9]{9,25}''.
34%
35
36%% DISCUSS ANALYSIS MODULE?
37
38
39The \RegularExpression{} layer has two compilers: the \CodeUnit{} and \RegularExpressionCompiler{}, both of which produce \Pablo{} IR.
40%
41Recall that the \Pablo{} layer assumes a transposed view of the input data.
42%
43The \emph{\CodeUnitCompiler{}} transforms the input code unit classes, either extracted from the \RegularExpression{} or produced by the
44\emph{toUTF8} transformation, into a series of bit stream equations.
45%
46The \emph{\RegularExpressionCompiler{}} assumes that these have been calculated and transforms the \RegularExpression{} AST into
47a sequence of instructions.
48%
49For instance, it would convert any alternations into a sequence of calculations that are merged with \verb|OR|s.
50%
51The results of these passes are combined and transformed through a series of typical optimization passes, including dead code elimination
52(DCE), common subexpression elimination (CSE), and constant folding.
53%
54These are necessary at this stage because the \RegularExpression{} AST may include common subsequences that are costly to recognize in
55that form.
56%
57Similarly, to keep the \CodeUnitCompiler{} a linear time function, it may introduce redundant IR instructions as it applies traditional Boolean
58algebra transformations, such as de Morgan's law, to the computed streams.
59%
60An intended side-effect of these passes is that they eliminate the need to analyze the data-dependencies inherent in the carry-bit logic,
61which is necessary for some \Pablo{} instructions but problematic for optimizers to reason about non-conservatively.
62%
63The \PabloCompiler{} then converts the \Pablo{} IR into LLVM IR.
64%
65This is a relatively straightforward conversion:
66%
67the only complexities it introduces is the generation of Phi nodes, linking of statically-compiled functions, and assignment of carry variables.
68%
69It produces the dynamically-generated match function used by the icGrep.
70
71\subsection{Dynamic Grep Engine}
72\input{fig-executor}
73
74
75As shown in Figure \ref{fig:execution}, icGrep takes the input data and transposed it into 8 parallel bit streams through S2P module.
76The required streams, e.g. line break stream, can then be generated using the 8 basis bits streams.
77The JIT function retrieves the 8 basis bits and the required streams from their memory addresses and starts the matching process.
78Named Property Library that includes all the predefined Unicode categories is installed into JIT function and can be called during the matching process.
79JIT function returns one bitstream that marks all the matching positions.
80A match scanner will scan through this bitstream and calculate the total counts or write the context of each match position.
81
82We can also apply a pipeline parallelism strategy to further speed up the process of icGrep.
83S2P and Required Streams Generator can be process in a separate thread and start even before the dynamic compilation starts.
84The output of S2P and Required Streams Generator, that is the 8 basis bits streams and the required streams,
85needs to be stored in a shared memory space so that the JIT function can read from it.
86To be more efficient of memory space usage, we only allocate limit amount of space for the shared data.
87When each chunk of the shared space is filled up with the bitstream data,
88the thread will start writing to the first chunk if it is released by JIT function.
89Otherwise, it will wait for JIT function until it finishes processing that chunk.
90Therefore, the performance is depended on the slowest thread.
91In the case that the cost of transposition and required stream generation is more than the matching process,
92we can further divide up the work and assign two threads for S2P and Required Streams Generator.
93
94
Note: See TracBrowser for help on using the repository browser.