blob: 66b3b5740a91d300552ff02e31e431aae086e17f [file] [log] [blame]
Shankar Easwaran34ab70f2013-02-07 20:16:12 +00001//===- Passes/LayoutPass.cpp - Layout atoms -------------------------------===//
2//
3// The LLVM Linker
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//===----------------------------------------------------------------------===//
10
Michael J. Spencer7f09a3d2013-02-26 01:35:30 +000011#define DEBUG_TYPE "LayoutPass"
12
Shankar Easwaran34ab70f2013-02-07 20:16:12 +000013#include "lld/Passes/LayoutPass.h"
Michael J. Spencerd4eb47c2013-04-06 00:56:40 +000014#include "lld/Core/Instrumentation.h"
Michael J. Spencer0d9d3112013-05-28 19:03:29 +000015#include "lld/Core/Parallel.h"
Michael J. Spencer7f09a3d2013-02-26 01:35:30 +000016#include "llvm/Support/Debug.h"
17
Shankar Easwaran34ab70f2013-02-07 20:16:12 +000018using namespace lld;
19
20/// The function compares atoms by sorting atoms in the following order
21/// a) Sorts atoms with the same permissions
22/// b) Sorts atoms with the same content Type
23/// c) Sorts atoms by Section position preference
24/// d) Sorts atoms by how they follow / precede each atom
25/// e) Sorts atoms on how they appear using File Ordinality
26/// f) Sorts atoms on how they appear within the File
27bool LayoutPass::CompareAtoms::operator()(const DefinedAtom *left,
Michael J. Spencer0d9d3112013-05-28 19:03:29 +000028 const DefinedAtom *right) const {
Michael J. Spencer7f09a3d2013-02-26 01:35:30 +000029 DEBUG(llvm::dbgs() << "Sorting " << left->name() << " " << right->name() << "\n");
Shankar Easwaran34ab70f2013-02-07 20:16:12 +000030 if (left == right)
31 return false;
32
Shankar Easwarand8da9892013-05-22 17:41:04 +000033 // Sort by section position preference.
34 DefinedAtom::SectionPosition leftPos = left->sectionPosition();
35 DefinedAtom::SectionPosition rightPos = right->sectionPosition();
36
37 DEBUG(llvm::dbgs() << "Sorting by sectionPos"
38 << "(" << leftPos << "," << rightPos << ")\n");
39
40 bool leftSpecialPos = (leftPos != DefinedAtom::sectionPositionAny);
41 bool rightSpecialPos = (rightPos != DefinedAtom::sectionPositionAny);
42 if (leftSpecialPos || rightSpecialPos) {
43 if (leftPos != rightPos)
44 return leftPos < rightPos;
45 }
46
Shankar Easwaran3c5d2c82013-05-10 16:44:02 +000047 DEBUG(llvm::dbgs() << "Sorting by override\n");
48
49 AtomToOrdinalT::const_iterator lPos = _layout._ordinalOverrideMap.find(left);
50 AtomToOrdinalT::const_iterator rPos = _layout._ordinalOverrideMap.find(right);
51 AtomToOrdinalT::const_iterator end = _layout._ordinalOverrideMap.end();
52 if (lPos != end) {
53 if (rPos != end) {
54 // both left and right are overridden, so compare overridden ordinals
55 if (lPos->second != rPos->second)
56 return lPos->second < rPos->second;
57 } else {
58 // left is overridden and right is not, so left < right
59 return true;
60 }
61 } else {
62 if (rPos != end) {
63 // right is overridden and left is not, so right < left
64 return false;
65 } else {
66 // neither are overridden,
67 // fall into default sorting below
68 }
69 }
70
Shankar Easwaran34ab70f2013-02-07 20:16:12 +000071 // Sort same permissions together.
72 DefinedAtom::ContentPermissions leftPerms = left->permissions();
73 DefinedAtom::ContentPermissions rightPerms = right->permissions();
Shankar Easwaran8c256852013-03-13 04:05:38 +000074
75 DEBUG(llvm::dbgs() << "Sorting by contentPerms"
76 << "(" << leftPerms << "," << rightPerms << ")\n");
77
Shankar Easwaran34ab70f2013-02-07 20:16:12 +000078 if (leftPerms != rightPerms)
79 return leftPerms < rightPerms;
80
81 // Sort same content types together.
82 DefinedAtom::ContentType leftType = left->contentType();
83 DefinedAtom::ContentType rightType = right->contentType();
Shankar Easwaran8c256852013-03-13 04:05:38 +000084
85 DEBUG(llvm::dbgs() << "Sorting by contentType"
86 << "(" << leftType << "," << rightType << ")\n");
87
Shankar Easwaran34ab70f2013-02-07 20:16:12 +000088 if (leftType != rightType)
89 return leftType < rightType;
90
91 // TO DO: Sort atoms in customs sections together.
92
Shankar Easwaran34ab70f2013-02-07 20:16:12 +000093 // Sort by .o order.
94 const File *leftFile = &left->file();
95 const File *rightFile = &right->file();
Shankar Easwaran8c256852013-03-13 04:05:38 +000096
97 DEBUG(llvm::dbgs()
98 << "Sorting by .o order("
99 << "(" << leftFile->ordinal() << "," << rightFile->ordinal() << ")"
100 << "[" << leftFile->path() << "," << rightFile->path() << "]\n");
101
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000102 if (leftFile != rightFile)
103 return leftFile->ordinal() < rightFile->ordinal();
104
105 // Sort by atom order with .o file.
106 uint64_t leftOrdinal = left->ordinal();
107 uint64_t rightOrdinal = right->ordinal();
Shankar Easwaran8c256852013-03-13 04:05:38 +0000108
109 DEBUG(llvm::dbgs() << "Sorting by ordinal(" << left->ordinal() << ","
110 << right->ordinal() << ")\n");
111
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000112 if (leftOrdinal != rightOrdinal)
113 return leftOrdinal < rightOrdinal;
114
Michael J. Spencer7f09a3d2013-02-26 01:35:30 +0000115 DEBUG(llvm::dbgs() << "Unordered\n");
116
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000117 return false;
118}
119
Rui Ueyamaca8ca552013-05-14 00:41:52 +0000120// Returns the atom immediately followed by the given atom in the followon
121// chain.
122const DefinedAtom *LayoutPass::findAtomFollowedBy(
123 const DefinedAtom *targetAtom) {
124 // Start from the beginning of the chain and follow the chain until
125 // we find the targetChain.
126 const DefinedAtom *atom = _followOnRoots[targetAtom];
127 while (true) {
128 const DefinedAtom *prevAtom = atom;
129 AtomToAtomT::iterator targetFollowOnAtomsIter = _followOnNexts.find(atom);
130 // The target atom must be in the chain of its root.
131 assert(targetFollowOnAtomsIter != _followOnNexts.end());
132 atom = targetFollowOnAtomsIter->second;
133 if (atom == targetAtom)
134 return prevAtom;
135 }
136}
137
138// Check if all the atoms followed by the given target atom are of size zero.
139// When this method is called, an atom being added is not of size zero and
140// will be added to the head of the followon chain. All the atoms between the
141// atom and the targetAtom (specified by layout-after) need to be of size zero
142// in this case. Otherwise the desired layout is impossible.
143bool LayoutPass::checkAllPrevAtomsZeroSize(const DefinedAtom *targetAtom) {
144 const DefinedAtom *atom = _followOnRoots[targetAtom];
145 while (true) {
Rui Ueyamaca8ca552013-05-14 00:41:52 +0000146 if (atom == targetAtom)
147 return true;
Rui Ueyama0196d1062013-05-14 16:53:59 +0000148 if (atom->size() != 0)
Rui Ueyamaca8ca552013-05-14 00:41:52 +0000149 // TODO: print warning that an impossible layout is being desired by the
150 // user.
151 return false;
Rui Ueyama5ec6d1a2013-05-14 01:51:56 +0000152 AtomToAtomT::iterator targetFollowOnAtomsIter = _followOnNexts.find(atom);
153 // The target atom must be in the chain of its root.
154 assert(targetFollowOnAtomsIter != _followOnNexts.end());
155 atom = targetFollowOnAtomsIter->second;
Rui Ueyamaca8ca552013-05-14 00:41:52 +0000156 }
157}
158
159// Set the root of all atoms in targetAtom's chain to the given root.
160void LayoutPass::setChainRoot(const DefinedAtom *targetAtom,
161 const DefinedAtom *root) {
162 // Walk through the followon chain and override each node's root.
163 while (true) {
164 _followOnRoots[targetAtom] = root;
165 AtomToAtomT::iterator targetFollowOnAtomsIter =
166 _followOnNexts.find(targetAtom);
167 if (targetFollowOnAtomsIter == _followOnNexts.end())
168 return;
169 targetAtom = targetFollowOnAtomsIter->second;
170 }
171}
172
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000173/// This pass builds the followon tables described by two DenseMaps
174/// followOnRoots and followonNexts.
175/// The followOnRoots map contains a mapping of a DefinedAtom to its root
176/// The followOnNexts map contains a mapping of what DefinedAtom follows the
177/// current Atom
178/// The algorithm follows a very simple approach
179/// a) If the atom is first seen, then make that as the root atom
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000180/// b) The targetAtom which this Atom contains, has the root thats set to the
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000181/// root of the current atom
182/// c) If the targetAtom is part of a different tree and the root of the
183/// targetAtom is itself, Chain all the atoms that are contained in the tree
184/// to the current Tree
185/// d) If the targetAtom is part of a different chain and the root of the
186/// targetAtom until the targetAtom has all atoms of size 0, then chain the
187/// targetAtoms and its tree to the current chain
188void LayoutPass::buildFollowOnTable(MutableFile::DefinedAtomRange &range) {
Michael J. Spencerd4eb47c2013-04-06 00:56:40 +0000189 ScopedTask task(getDefaultDomain(), "LayoutPass::buildFollowOnTable");
Rui Ueyamaca8ca552013-05-14 00:41:52 +0000190 // Set the initial size of the followon and the followonNext hash to the
191 // number of atoms that we have.
Shankar Easwaran45a5f932013-04-29 03:27:57 +0000192 _followOnRoots.resize(range.size());
193 _followOnNexts.resize(range.size());
Rui Ueyama0196d1062013-05-14 16:53:59 +0000194 for (const DefinedAtom *ai : range) {
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000195 for (const Reference *r : *ai) {
Rui Ueyamaca8ca552013-05-14 00:41:52 +0000196 if (r->kind() != lld::Reference::kindLayoutAfter)
197 continue;
198 const DefinedAtom *targetAtom = llvm::dyn_cast<DefinedAtom>(r->target());
199 _followOnNexts[ai] = targetAtom;
200
201 // If we find a followon for the first time, lets make that atom as the
202 // root atom.
203 if (_followOnRoots.count(ai) == 0)
204 _followOnRoots[ai] = ai;
205
206 auto iter = _followOnRoots.find(targetAtom);
207 if (iter == _followOnRoots.end()) {
208 // If the targetAtom is not a root of any chain, lets make the root of
209 // the targetAtom to the root of the current chain.
210 _followOnRoots[targetAtom] = _followOnRoots[ai];
211 } else if (iter->second == targetAtom) {
212 // If the targetAtom is the root of a chain, the chain becomes part of
213 // the current chain. Rewrite the subchain's root to the current
214 // chain's root.
215 setChainRoot(targetAtom, _followOnRoots[ai]);
216 } else {
217 // The targetAtom is already a part of a chain. If the current atom is
218 // of size zero, we can insert it in the middle of the chain just
219 // before the target atom, while not breaking other atom's followon
220 // relationships. If it's not, we can only insert the current atom at
221 // the beginning of the chain. All the atoms followed by the target
222 // atom must be of size zero in that case to satisfy the followon
223 // relationships.
Rui Ueyama0196d1062013-05-14 16:53:59 +0000224 size_t currentAtomSize = ai->size();
Rui Ueyamaca8ca552013-05-14 00:41:52 +0000225 if (currentAtomSize == 0) {
226 const DefinedAtom *targetPrevAtom = findAtomFollowedBy(targetAtom);
227 _followOnNexts[targetPrevAtom] = ai;
228 _followOnRoots[ai] = _followOnRoots[targetPrevAtom];
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000229 } else {
Rui Ueyamaca8ca552013-05-14 00:41:52 +0000230 if (!checkAllPrevAtomsZeroSize(targetAtom))
231 break;
232 _followOnNexts[ai] = _followOnRoots[targetAtom];
233 setChainRoot(_followOnRoots[targetAtom], _followOnRoots[ai]);
234 }
235 }
236 }
237 }
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000238}
239
240/// This pass builds the followon tables using InGroup relationships
241/// The algorithm follows a very simple approach
242/// a) If the rootAtom is not part of any root, create a new root with the
243/// as the head
244/// b) If the current Atom root is not found, then make the current atoms root
245/// point to the rootAtom
246/// c) If the root of the current Atom is itself a root of some other tree
247/// make all the atoms in the chain point to the ingroup reference
248/// d) Check to see if the current atom is part of the chain from the rootAtom
249/// if not add the atom to the chain, so that the current atom is part of the
250/// the chain where the rootAtom is in
251void LayoutPass::buildInGroupTable(MutableFile::DefinedAtomRange &range) {
Michael J. Spencerd4eb47c2013-04-06 00:56:40 +0000252 ScopedTask task(getDefaultDomain(), "LayoutPass::buildInGroupTable");
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000253 // This table would convert precededby references to follow on
254 // references so that we have only one table
Rui Ueyama0196d1062013-05-14 16:53:59 +0000255 for (const DefinedAtom *ai : range) {
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000256 for (const Reference *r : *ai) {
257 if (r->kind() == lld::Reference::kindInGroup) {
258 const DefinedAtom *rootAtom = llvm::dyn_cast<DefinedAtom>(r->target());
259 // If the root atom is not part of any root
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000260 // create a new root
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000261 if (_followOnRoots.count(rootAtom) == 0) {
262 _followOnRoots[rootAtom] = rootAtom;
263 }
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000264 // If the current Atom has not been seen yet and there is no root
265 // that has been set, set the root of the atom to the targetAtom
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000266 // as the targetAtom points to the ingroup root
267 auto iter = _followOnRoots.find(ai);
268 if (iter == _followOnRoots.end()) {
269 _followOnRoots[ai] = rootAtom;
Rui Ueyamaca8ca552013-05-14 00:41:52 +0000270 } else if (iter->second == ai) {
271 if (iter->second != rootAtom)
272 setChainRoot(iter->second, rootAtom);
273 } else {
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000274 // TODO : Flag an error that the root of the tree
275 // is different, Here is an example
276 // Say there are atoms
277 // chain 1 : a->b->c
278 // chain 2 : d->e->f
279 // and e,f have their ingroup reference as a
280 // this could happen only if the root of e,f that is d
281 // has root as 'a'
282 continue;
283 }
284
285 // Check if the current atom is part of the chain
286 bool isAtomInChain = false;
287 const DefinedAtom *lastAtom = rootAtom;
288 while (true) {
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000289 AtomToAtomT::iterator followOnAtomsIter =
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000290 _followOnNexts.find(lastAtom);
291 if (followOnAtomsIter != _followOnNexts.end()) {
292 lastAtom = followOnAtomsIter->second;
293 if (lastAtom == ai) {
294 isAtomInChain = true;
295 break;
296 }
297 }
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000298 else
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000299 break;
300 } // findAtomInChain
301
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000302 if (!isAtomInChain)
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000303 _followOnNexts[lastAtom] = ai;
304 }
305 }
306 }
307}
308
309/// This pass builds the followon tables using Preceded By relationships
310/// The algorithm follows a very simple approach
311/// a) If the targetAtom is not part of any root and the current atom is not
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000312/// part of any root, create a chain with the current atom as root and
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000313/// the targetAtom as following the current atom
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000314/// b) Chain the targetAtom to the current Atom if the targetAtom is not part
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000315/// of any chain and the currentAtom has no followOn's
316/// c) If the targetAtom is part of a different tree and the root of the
317/// targetAtom is itself, and if the current atom is not part of any root
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000318/// chain all the atoms together
319/// d) If the current atom has no followon and the root of the targetAtom is
320/// not equal to the root of the current atom(the targetAtom is not in the
321/// same chain), chain all the atoms that are lead by the targetAtom into
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000322/// the current chain
323void LayoutPass::buildPrecededByTable(MutableFile::DefinedAtomRange &range) {
Michael J. Spencerd4eb47c2013-04-06 00:56:40 +0000324 ScopedTask task(getDefaultDomain(), "LayoutPass::buildPrecededByTable");
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000325 // This table would convert precededby references to follow on
326 // references so that we have only one table
Rui Ueyama0196d1062013-05-14 16:53:59 +0000327 for (const DefinedAtom *ai : range) {
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000328 for (const Reference *r : *ai) {
329 if (r->kind() == lld::Reference::kindLayoutBefore) {
330 const DefinedAtom *targetAtom = llvm::dyn_cast<DefinedAtom>(r->target());
331 // Is the targetAtom not chained
332 if (_followOnRoots.count(targetAtom) == 0) {
333 // Is the current atom not part of any root ?
334 if (_followOnRoots.count(ai) == 0) {
335 _followOnRoots[ai] = ai;
336 _followOnNexts[ai] = targetAtom;
337 _followOnRoots[targetAtom] = _followOnRoots[ai];
338 } else if (_followOnNexts.count(ai) == 0) {
339 // Chain the targetAtom to the current Atom
340 // if the currentAtom has no followon references
341 _followOnNexts[ai] = targetAtom;
342 _followOnRoots[targetAtom] = _followOnRoots[ai];
343 }
344 } else if (_followOnRoots.find(targetAtom)->second == targetAtom) {
345 // Is the targetAtom in chain with the targetAtom as the root ?
346 bool changeRoots = false;
347 if (_followOnRoots.count(ai) == 0) {
348 _followOnRoots[ai] = ai;
349 _followOnNexts[ai] = targetAtom;
350 _followOnRoots[targetAtom] = _followOnRoots[ai];
351 changeRoots = true;
352 } else if (_followOnNexts.count(ai) == 0) {
353 // Chain the targetAtom to the current Atom
354 // if the currentAtom has no followon references
355 if (_followOnRoots[ai] != _followOnRoots[targetAtom]) {
356 _followOnNexts[ai] = targetAtom;
357 _followOnRoots[targetAtom] = _followOnRoots[ai];
358 changeRoots = true;
359 }
360 }
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000361 // Change the roots of the targetAtom and its chain to
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000362 // the current atoms root
363 if (changeRoots) {
Rui Ueyamaca8ca552013-05-14 00:41:52 +0000364 setChainRoot(_followOnRoots[targetAtom], _followOnRoots[ai]);
365 }
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000366 } // Is targetAtom root
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000367 } // kindLayoutBefore
Rui Ueyamaca8ca552013-05-14 00:41:52 +0000368 } // Reference
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000369 } // atom iteration
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000370} // end function
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000371
372
373/// Build an ordinal override map by traversing the followon chain, and
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000374/// assigning ordinals to each atom, if the atoms have their ordinals
375/// already assigned skip the atom and move to the next. This is the
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000376/// main map thats used to sort the atoms while comparing two atoms together
377void LayoutPass::buildOrdinalOverrideMap(MutableFile::DefinedAtomRange &range) {
Michael J. Spencerd4eb47c2013-04-06 00:56:40 +0000378 ScopedTask task(getDefaultDomain(), "LayoutPass::buildOrdinalOverrideMap");
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000379 uint64_t index = 0;
Rui Ueyama0196d1062013-05-14 16:53:59 +0000380 for (const DefinedAtom *ai : range) {
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000381 const DefinedAtom *atom = ai;
Michael J. Spencer1ecf8902013-03-12 00:10:00 +0000382 if (_ordinalOverrideMap.find(atom) != _ordinalOverrideMap.end())
383 continue;
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000384 AtomToAtomT::iterator start = _followOnRoots.find(atom);
385 if (start != _followOnRoots.end()) {
386 for (const DefinedAtom *nextAtom = start->second; nextAtom != NULL;
387 nextAtom = _followOnNexts[nextAtom]) {
388 AtomToOrdinalT::iterator pos = _ordinalOverrideMap.find(nextAtom);
389 if (pos == _ordinalOverrideMap.end()) {
390 _ordinalOverrideMap[nextAtom] = index++;
391 }
392 }
393 } else {
Shankar Easwarand8da9892013-05-22 17:41:04 +0000394 _ordinalOverrideMap[atom] = index++;
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000395 }
396 }
397}
398
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000399/// Perform the actual pass
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000400void LayoutPass::perform(MutableFile &mergedFile) {
Michael J. Spencerbd66d042013-05-28 18:55:39 +0000401 ScopedTask task(getDefaultDomain(), "LayoutPass");
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000402 MutableFile::DefinedAtomRange atomRange = mergedFile.definedAtoms();
403
404 // Build follow on tables
405 buildFollowOnTable(atomRange);
406
407 // Build Ingroup reference table
408 buildInGroupTable(atomRange);
409
410 // Build preceded by tables
411 buildPrecededByTable(atomRange);
412
413 // Build override maps
414 buildOrdinalOverrideMap(atomRange);
415
Rui Ueyama9c4f89a2013-05-23 01:31:25 +0000416 DEBUG({
Nick Kledzikf4fa8c02013-04-04 20:32:18 +0000417 llvm::dbgs() << "unsorted atoms:\n";
418 for (const DefinedAtom *atom : atomRange) {
Shankar Easwaran45a5f932013-04-29 03:27:57 +0000419 llvm::dbgs() << " file=" << atom->file().path()
420 << ", name=" << atom->name()
421 << ", size=" << atom->size()
422 << ", type=" << atom->contentType()
423 << ", ordinal=" << atom->ordinal()
424 << "\n";
Nick Kledzikf4fa8c02013-04-04 20:32:18 +0000425 }
426 });
Shankar Easwaran45a5f932013-04-29 03:27:57 +0000427
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000428 // sort the atoms
Michael J. Spencer0d9d3112013-05-28 19:03:29 +0000429 parallel_sort(atomRange.begin(), atomRange.end(), _compareAtoms);
Shankar Easwaran45a5f932013-04-29 03:27:57 +0000430
Rui Ueyama9c4f89a2013-05-23 01:31:25 +0000431 DEBUG({
Nick Kledzikf4fa8c02013-04-04 20:32:18 +0000432 llvm::dbgs() << "sorted atoms:\n";
433 for (const DefinedAtom *atom : atomRange) {
Shankar Easwaran45a5f932013-04-29 03:27:57 +0000434 llvm::dbgs() << " file=" << atom->file().path()
435 << ", name=" << atom->name()
436 << ", size=" << atom->size()
437 << ", type=" << atom->contentType()
438 << ", ordinal=" << atom->ordinal()
439 << "\n";
Nick Kledzikf4fa8c02013-04-04 20:32:18 +0000440 }
441 });
Nick Kledzikc314b462013-04-04 18:59:24 +0000442
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000443}