@@ -8,9 +8,9 @@ MergeFunctions pass, how it works
88Introduction
99============
1010Sometimes 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
1414write the same thing twice :-)
1515
1616The 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
2020explains how we could combine equal functions correctly to keep the module
2121valid.
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
2424from high level ideas and end with low-level algorithm details, thus preparing
2525him or her for reading the sources.
2626
2727The main goal is to describe the algorithm and logic here and the concept. If
2828you *don't want * to read the source code, but want to understand pass
2929algorithms, 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
3131update this document after any minor code changes.
3232
3333
3434What 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
3838LLVM 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.
9999This is just an example; more possible details are described a bit below.
100100
101101As 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
103103logical left shift by 1.
104104
105105Possible solutions
@@ -131,7 +131,7 @@ access lookup? The answer is: "yes".
131131Random-access
132132"""""""""""""
133133How 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.
135135Good hashing means, that every function part must be taken into account. That
136136means we have to convert every function part into some number, and then add it
137137into 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
179179implemented “<” operator among the functions set (below we explain how it works
180180exactly; this is a key point in fast functions comparison).
181181
@@ -207,7 +207,7 @@ from method.
207207Comparison and logarithmical search
208208"""""""""""""""""""""""""""""""""""
209209Let'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
211211single function.
212212
213213Defining total ordering among the functions set allows us to organize
@@ -225,7 +225,7 @@ possible values:
225225
2262261, 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
236236As 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
239239comparison.
240240
241241Below, 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
2772771. 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
279279function different without changing its body. This part of the comparison is
280280usually 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.
3653657. Complex types (structures, arrays, etc.). Follow complex objects comparison
366366technique (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
3703708. Steps 1-6 describe all the possible cases, if we passed steps 1-6 and didn't
371371get any conclusions, then invoke ``llvm_unreachable ``, since it's quite an
@@ -445,7 +445,7 @@ How to implement cmpValues?
445445but, in general, we need to implement antisymmetric relation. As mentioned
446446above, to understand what is *less *, we can use order in which we
447447meet 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
449449first.
450450
451451Every time we run the top-level compare method, we initialize two identical
@@ -623,7 +623,7 @@ to use ``accumulateConstantOffset`` method.
623623So, if we get constant offset for both left and right *GEPs *, then compare it as
624624numbers, 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
628628cmpOperation
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 *,
746746so *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
773773with 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
776776first point:
777777
7787781. We generate tail call wrapper around *F *, but with an interface that allows using
0 commit comments