Skip to content

Commit 53dd594

Browse files
kazutakahirataakadutta
authored andcommitted
[llvm] Proofread MergeFunctions.rst (llvm#162596)
1 parent d5d107d commit 53dd594

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

llvm/docs/MergeFunctions.rst

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ Introduction
99
============
1010
Sometimes code contains equal functions, or functions that do exactly the same
1111
thing even though they are non-equal on the IR level (e.g.: multiplication on 2
12-
and 'shl 1'). It could happen due to several reasons: mainly, the usage of
12+
and 'shl 1'). This can happen for several reasons: mainly, the usage of
1313
templates and automatic code generators. Though, 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.
1717

18-
This document is the extension to pass comments and describes the pass logic. It
18+
This document is an extension to pass comments and describes the pass logic. It
1919
describes the algorithm used to compare functions and
2020
explains how we could combine equal functions correctly to keep the module
2121
valid.
@@ -54,7 +54,7 @@ As a good starting point, the Kaleidoscope tutorial can be used:
5454

5555
:doc:`tutorial/index`
5656

57-
It's especially important to understand chapter 3 of tutorial:
57+
It's especially important to understand Chapter 3 of the tutorial:
5858

5959
:doc:`tutorial/LangImpl03`
6060

@@ -314,7 +314,7 @@ list is immaterial. Our walk starts at the entry block for both functions, then
314314
takes each block from each terminator in order. As an artifact, this also means
315315
that unreachable blocks are ignored.”
316316

317-
So, using this walk we get BBs from *left* and *right* in the same order, and
317+
So, using this walk, we get BBs from *left* and *right* in the same order, and
318318
compare them by “``FunctionComparator::compare(const BasicBlock*, const
319319
BasicBlock*)``” method.
320320

@@ -325,17 +325,17 @@ FunctionComparator::cmpType
325325
---------------------------
326326
Consider how type comparison works.
327327

328-
1. Coerce pointer to integer. If left type is a pointer, try to coerce it to the
328+
1. Coerce pointer to integer. If the left type is a pointer, try to coerce it to the
329329
integer type. It could be done if its address space is 0, or if address spaces
330330
are ignored at all. Do the same thing for the right type.
331331

332-
2. If left and right types are equal, return 0. Otherwise we need to give
332+
2. If the left and right types are equal, return 0. Otherwise, we need to give
333333
preference to one of them. So proceed to the next step.
334334

335-
3. If types are of different kind (different type IDs). Return result of type
335+
3. If the types are of different kind (different type IDs). Return result of type
336336
IDs comparison, treating them as numbers (use ``cmpNumbers`` operation).
337337

338-
4. If types are vectors or integers, return result of their pointers comparison,
338+
4. If the types are vectors or integers, return result of their pointers comparison,
339339
comparing them as numbers.
340340

341341
5. Check whether type ID belongs to the next group (call it equivalent-group):
@@ -391,7 +391,7 @@ equal to the corresponding part of *right* place, and (!) both parts use
391391
392392
So, now our conclusion depends on *Value* instances comparison.
393393

394-
The main purpose of this method is to determine relation between such values.
394+
The main purpose of this method is to determine the relation between such values.
395395

396396
What can we expect from equal functions? At the same place, in functions
397397
"*FL*" and "*FR*" we expect to see *equal* values, or values *defined* at
@@ -453,17 +453,17 @@ maps (one for the left side, another one for the right side):
453453

454454
``map<Value, int> sn_mapL, sn_mapR;``
455455

456-
The key of the map is the *Value* itself, the *value* – is its order (call it
456+
The key of the map is the *Value* itself; the *value* – is its order (call it
457457
*serial number*).
458458

459459
To add value *V* we need to perform the next procedure:
460460

461461
``sn_map.insert(std::make_pair(V, sn_map.size()));``
462462

463-
For the first *Value*, map will return *0*, for the second *Value* map will
463+
For the first *Value*, the map will return *0*, for the second *Value*, the map will
464464
return *1*, and so on.
465465

466-
We can then check whether left and right values met at the same time with
466+
We can then check whether the left and right values met at the same time with
467467
a simple comparison:
468468

469469
``cmpNumbers(sn_mapL[Left], sn_mapR[Right]);``
@@ -525,7 +525,7 @@ and finish comparison procedure.
525525

526526
cmpConstants
527527
------------
528-
Performs constants comparison as follows:
528+
Performs a constant comparison as follows:
529529

530530
1. Compare constant types using ``cmpType`` method. If the result is -1 or 1,
531531
goto step 2, otherwise proceed to step 3.
@@ -655,10 +655,10 @@ O(N*N) to O(log(N)).
655655
Merging process, mergeTwoFunctions
656656
==================================
657657
Once *MergeFunctions* detects that current function (*G*) is equal to one that
658-
were analyzed before (function *F*) it calls ``mergeTwoFunctions(Function*,
658+
was analyzed before (function *F*) it calls ``mergeTwoFunctions(Function*,
659659
Function*)``.
660660

661-
Operation affects ``FnTree`` contents with next way: *F* will stay in
661+
Operation affects ``FnTree`` contents in the following way: *F* will stay in
662662
``FnTree``. *G* being equal to *F* will not be added to ``FnTree``. Calls of
663663
*G* would be replaced with something else. It changes bodies of callers. So,
664664
functions that calls *G* would be put into ``Deferred`` set and removed from
@@ -692,19 +692,19 @@ ok: we can use alias to *F* instead of *G* or change call instructions itself.
692692
HasGlobalAliases, removeUsers
693693
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
694694
First, consider the case when we have global aliases of one function name to
695-
another. Our purpose is make both of them with aliases to the third strong
696-
function. Though if we keep *F* alive and without major changes we can leave it
695+
another. Our purpose is to make both of them with aliases to the third strong
696+
function. However, if we keep *F* alive and without major changes, we can leave it
697697
in ``FnTree``. Try to combine these two goals.
698698

699699
Do a stub replacement of *F* itself with an alias to *F*.
700700

701701
1. Create stub function *H*, with the same name and attributes like function
702702
*F*. It takes maximum alignment of *F* and *G*.
703703

704-
2. Replace all uses of function *F* with uses of function *H*. It is the two
705-
steps procedure instead. First of all, we must take into account, all functions
706-
from whom *F* is called would be changed: since we change the call argument
707-
(from *F* to *H*). If so we must to review these caller functions again after
704+
2. Replace all uses of function *F* with uses of function *H*. It is a
705+
two-step procedure instead. First of all, we must take into account that all functions
706+
that call *F* would be changed because we change the call argument
707+
(from *F* to *H*). If so, we must review these caller functions again after
708708
this procedure. We remove callers from ``FnTree``, method with name
709709
``removeUsers(F)`` does that (don't confuse with ``replaceAllUsesWith``):
710710

@@ -735,7 +735,7 @@ If “F” could not be overridden, fix it!
735735
"""""""""""""""""""""""""""""""""""""""
736736

737737
We call ``writeThunkOrAlias(Function *F, Function *G)``. Here we try to replace
738-
*G* with alias to *F* first. The next conditions are essential:
738+
*G* with an alias to *F* first. The next conditions are essential:
739739

740740
* target should support global aliases,
741741
* the address itself of *G* should be not significant, not named and not
@@ -775,7 +775,7 @@ with bitcast(F). Deletes G.”
775775
In general it does the same as usual when we want to replace callee, except the
776776
first point:
777777

778-
1. We generate tail call wrapper around *F*, but with interface that allows use
778+
1. We generate tail call wrapper around *F*, but with an interface that allows using
779779
it instead of *G*.
780780

781781
2. “As-usual”: ``removeUsers`` and ``replaceAllUsesWith`` then.

0 commit comments

Comments
 (0)