Skip to content

Commit e491ffe

Browse files
[llvm] Proofread MergeFunctions.rst
1 parent 0ba7bfc commit e491ffe

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

llvm/docs/MergeFunctions.rst

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ MergeFunctions pass, how it works
88
Introduction
99
============
1010
Sometimes code contains equal functions, or functions that do exactly the same
11-
thing even though they are non-equal on the IR level (e.g.: multiplication on 2
12-
and 'shl 1'). This can happen for several reasons: mainly, the usage of
13-
templates and automatic code generators. Though, sometimes the user itself could
11+
thing even though they are non-equal on the IR level (e.g.,: multiplication on 2
12+
and ``shl 1``). This can happen for several reasons: mainly, the usage of
13+
templates and automatic code generators. However, sometimes the user itself could
1414
write the same thing twice :-)
1515

1616
The main purpose of this pass is to recognize such functions and merge them.
@@ -20,21 +20,21 @@ describes the algorithm used to compare functions and
2020
explains how we could combine equal functions correctly to keep the module
2121
valid.
2222

23-
Material is brought in a top-down form, so the reader could start to learn pass
23+
The material is presented in a top-down form, so the reader could start to learn pass
2424
from high level ideas and end with low-level algorithm details, thus preparing
2525
him or her for reading the sources.
2626

2727
The main goal is to describe the algorithm and logic here and the concept. If
2828
you *don't want* to read the source code, but want to understand pass
2929
algorithms, this document is good for you. The author tries not to repeat the
30-
source-code and covers only common cases to avoid the cases of needing to
30+
source code and covers only common cases to avoid the cases of needing to
3131
update this document after any minor code changes.
3232

3333

3434
What should I know to be able to follow along with this document?
3535
-----------------------------------------------------------------
3636

37-
The reader should be familiar with common compile-engineering principles and
37+
The reader should be familiar with common compiler-engineering principles and
3838
LLVM code fundamentals. In this article, we assume the reader is familiar with
3939
`Single Static Assignment
4040
<http://en.wikipedia.org/wiki/Static_single_assignment_form>`_
@@ -99,7 +99,7 @@ and a ``void*`` as equal.
9999
This is just an example; more possible details are described a bit below.
100100

101101
As another example, the reader may imagine two more functions. The first
102-
function performs a multiplication by 2, while the second one performs an
102+
function performs a multiplication by 2, while the second one performs a
103103
logical left shift by 1.
104104

105105
Possible solutions
@@ -131,7 +131,7 @@ access lookup? The answer is: "yes".
131131
Random-access
132132
"""""""""""""
133133
How can this be done? Just convert each function to a number, and gather
134-
all of them in a special hash-table. Functions with equal hashes are equal.
134+
all of them in a special hash table. Functions with equal hashes are equal.
135135
Good hashing means, that every function part must be taken into account. That
136136
means we have to convert every function part into some number, and then add it
137137
into the hash. The lookup-up time would be small, but such an approach adds some
@@ -175,7 +175,7 @@ merged with each other. It is defined as:
175175

176176
``std::set<FunctionNode> FnTree;``
177177

178-
Here ``FunctionNode`` is a wrapper for ``llvm::Function`` class, with
178+
Here, ``FunctionNode`` is a wrapper for ``llvm::Function`` class, with an
179179
implemented “<” operator among the functions set (below we explain how it works
180180
exactly; this is a key point in fast functions comparison).
181181

@@ -207,7 +207,7 @@ from method.
207207
Comparison and logarithmical search
208208
"""""""""""""""""""""""""""""""""""
209209
Let's recall our task: for every function *F* from module *M*, we have to find
210-
equal functions *F`* in the shortest time possible , and merge them into a
210+
equal functions *F`* in the shortest time possible and merge them into a
211211
single function.
212212

213213
Defining total ordering among the functions set allows us to organize
@@ -225,7 +225,7 @@ possible values:
225225

226226
1, left is *greater* than right.
227227

228-
Of course it means, that we have to maintain
228+
Of course, it means that we have to maintain
229229
*strict and non-strict order relation properties*:
230230

231231
* reflexivity (``a <= a``, ``a == a``, ``a >= a``),
@@ -235,7 +235,7 @@ Of course it means, that we have to maintain
235235

236236
As mentioned before, the comparison routine consists of
237237
"sub-comparison-routines", with each of them also consisting of
238-
"sub-comparison-routines", and so on. Finally, it ends up with primitive
238+
"sub-comparison-routines", and so on. Finally, it ends up with a primitive
239239
comparison.
240240

241241
Below, we will use the following operations:
@@ -275,7 +275,7 @@ A brief look at the source code tells us that the comparison starts in the
275275
“``int FunctionComparator::compare(void)``” method.
276276

277277
1. The first parts to be compared are the function's attributes and some
278-
properties that is outside the “attributes” term, but still could make the
278+
properties that are outside the “attributes” term, but still could make the
279279
function different without changing its body. This part of the comparison is
280280
usually done within simple *cmpNumbers* or *cmpFlags* operations (e.g.
281281
``cmpFlags(F1->hasGC(), F2->hasGC())``). Below is a full list of function's
@@ -365,7 +365,7 @@ comparing them as numbers.
365365
7. Complex types (structures, arrays, etc.). Follow complex objects comparison
366366
technique (see the very first paragraph of this chapter). Both *left* and
367367
*right* are to be expanded and their element types will be checked the same
368-
way. If we get -1 or 1 on some stage, return it. Otherwise return 0.
368+
way. If we get -1 or 1 on some stage, return it. Otherwise, return 0.
369369

370370
8. Steps 1-6 describe all the possible cases, if we passed steps 1-6 and didn't
371371
get any conclusions, then invoke ``llvm_unreachable``, since it's quite an
@@ -445,7 +445,7 @@ How to implement cmpValues?
445445
but, in general, we need to implement antisymmetric relation. As mentioned
446446
above, to understand what is *less*, we can use order in which we
447447
meet values. If both values have the same order in a function (met at the same
448-
time), we then treat values as *associated*. Otherwise it depends on who was
448+
time), we then treat values as *associated*. Otherwise, it depends on who was
449449
first.
450450

451451
Every time we run the top-level compare method, we initialize two identical
@@ -623,7 +623,7 @@ to use ``accumulateConstantOffset`` method.
623623
So, if we get constant offset for both left and right *GEPs*, then compare it as
624624
numbers, and return comparison result.
625625

626-
Otherwise treat it like a regular operation (see previous paragraph).
626+
Otherwise, treat it like a regular operation (see previous paragraph).
627627

628628
cmpOperation
629629
------------
@@ -742,7 +742,7 @@ We call ``writeThunkOrAlias(Function *F, Function *G)``. Here we try to replace
742742
referenced anywhere,
743743
* function should come with external, local or weak linkage.
744744

745-
Otherwise we write thunk: some wrapper that has *G's* interface and calls *F*,
745+
Otherwise, we write thunk: some wrapper that has *G's* interface and calls *F*,
746746
so *G* could be replaced with this wrapper.
747747

748748
*writeAlias*
@@ -772,7 +772,7 @@ As it written in method comments:
772772
“Replace G with a simple tail call to bitcast(F). Also replace direct uses of G
773773
with bitcast(F). Deletes G.”
774774

775-
In general it does the same as usual when we want to replace callee, except the
775+
In general, it does the same as usual when we want to replace callee, except the
776776
first point:
777777

778778
1. We generate tail call wrapper around *F*, but with an interface that allows using

0 commit comments

Comments
 (0)