blob: 8add7225f3ceddda85be421eed45af0b1fdc0327 [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. Spencer7f09a3d2013-02-26 01:35:30 +000015#include "llvm/Support/Debug.h"
16
Shankar Easwaran34ab70f2013-02-07 20:16:12 +000017using namespace lld;
18
19/// The function compares atoms by sorting atoms in the following order
20/// a) Sorts atoms with the same permissions
21/// b) Sorts atoms with the same content Type
22/// c) Sorts atoms by Section position preference
23/// d) Sorts atoms by how they follow / precede each atom
24/// e) Sorts atoms on how they appear using File Ordinality
25/// f) Sorts atoms on how they appear within the File
26bool LayoutPass::CompareAtoms::operator()(const DefinedAtom *left,
27 const DefinedAtom *right) {
Michael J. Spencer7f09a3d2013-02-26 01:35:30 +000028 DEBUG(llvm::dbgs() << "Sorting " << left->name() << " " << right->name() << "\n");
Shankar Easwaran34ab70f2013-02-07 20:16:12 +000029 if (left == right)
30 return false;
31
Shankar Easwarand8da9892013-05-22 17:41:04 +000032 // Sort by section position preference.
33 DefinedAtom::SectionPosition leftPos = left->sectionPosition();
34 DefinedAtom::SectionPosition rightPos = right->sectionPosition();
35
36 DEBUG(llvm::dbgs() << "Sorting by sectionPos"
37 << "(" << leftPos << "," << rightPos << ")\n");
38
39 bool leftSpecialPos = (leftPos != DefinedAtom::sectionPositionAny);
40 bool rightSpecialPos = (rightPos != DefinedAtom::sectionPositionAny);
41 if (leftSpecialPos || rightSpecialPos) {
42 if (leftPos != rightPos)
43 return leftPos < rightPos;
44 }
45
Shankar Easwaran3c5d2c82013-05-10 16:44:02 +000046 DEBUG(llvm::dbgs() << "Sorting by override\n");
47
48 AtomToOrdinalT::const_iterator lPos = _layout._ordinalOverrideMap.find(left);
49 AtomToOrdinalT::const_iterator rPos = _layout._ordinalOverrideMap.find(right);
50 AtomToOrdinalT::const_iterator end = _layout._ordinalOverrideMap.end();
51 if (lPos != end) {
52 if (rPos != end) {
53 // both left and right are overridden, so compare overridden ordinals
54 if (lPos->second != rPos->second)
55 return lPos->second < rPos->second;
56 } else {
57 // left is overridden and right is not, so left < right
58 return true;
59 }
60 } else {
61 if (rPos != end) {
62 // right is overridden and left is not, so right < left
63 return false;
64 } else {
65 // neither are overridden,
66 // fall into default sorting below
67 }
68 }
69
Shankar Easwaran34ab70f2013-02-07 20:16:12 +000070 // Sort same permissions together.
71 DefinedAtom::ContentPermissions leftPerms = left->permissions();
72 DefinedAtom::ContentPermissions rightPerms = right->permissions();
Shankar Easwaran8c256852013-03-13 04:05:38 +000073
74 DEBUG(llvm::dbgs() << "Sorting by contentPerms"
75 << "(" << leftPerms << "," << rightPerms << ")\n");
76
Shankar Easwaran34ab70f2013-02-07 20:16:12 +000077 if (leftPerms != rightPerms)
78 return leftPerms < rightPerms;
79
80 // Sort same content types together.
81 DefinedAtom::ContentType leftType = left->contentType();
82 DefinedAtom::ContentType rightType = right->contentType();
Shankar Easwaran8c256852013-03-13 04:05:38 +000083
84 DEBUG(llvm::dbgs() << "Sorting by contentType"
85 << "(" << leftType << "," << rightType << ")\n");
86
Shankar Easwaran34ab70f2013-02-07 20:16:12 +000087 if (leftType != rightType)
88 return leftType < rightType;
89
90 // TO DO: Sort atoms in customs sections together.
91
Shankar Easwaran34ab70f2013-02-07 20:16:12 +000092 // Sort by .o order.
93 const File *leftFile = &left->file();
94 const File *rightFile = &right->file();
Shankar Easwaran8c256852013-03-13 04:05:38 +000095
96 DEBUG(llvm::dbgs()
97 << "Sorting by .o order("
98 << "(" << leftFile->ordinal() << "," << rightFile->ordinal() << ")"
99 << "[" << leftFile->path() << "," << rightFile->path() << "]\n");
100
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000101 if (leftFile != rightFile)
102 return leftFile->ordinal() < rightFile->ordinal();
103
104 // Sort by atom order with .o file.
105 uint64_t leftOrdinal = left->ordinal();
106 uint64_t rightOrdinal = right->ordinal();
Shankar Easwaran8c256852013-03-13 04:05:38 +0000107
108 DEBUG(llvm::dbgs() << "Sorting by ordinal(" << left->ordinal() << ","
109 << right->ordinal() << ")\n");
110
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000111 if (leftOrdinal != rightOrdinal)
112 return leftOrdinal < rightOrdinal;
113
Michael J. Spencer7f09a3d2013-02-26 01:35:30 +0000114 DEBUG(llvm::dbgs() << "Unordered\n");
115
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000116 return false;
117}
118
Rui Ueyamaca8ca552013-05-14 00:41:52 +0000119// Returns the atom immediately followed by the given atom in the followon
120// chain.
121const DefinedAtom *LayoutPass::findAtomFollowedBy(
122 const DefinedAtom *targetAtom) {
123 // Start from the beginning of the chain and follow the chain until
124 // we find the targetChain.
125 const DefinedAtom *atom = _followOnRoots[targetAtom];
126 while (true) {
127 const DefinedAtom *prevAtom = atom;
128 AtomToAtomT::iterator targetFollowOnAtomsIter = _followOnNexts.find(atom);
129 // The target atom must be in the chain of its root.
130 assert(targetFollowOnAtomsIter != _followOnNexts.end());
131 atom = targetFollowOnAtomsIter->second;
132 if (atom == targetAtom)
133 return prevAtom;
134 }
135}
136
137// Check if all the atoms followed by the given target atom are of size zero.
138// When this method is called, an atom being added is not of size zero and
139// will be added to the head of the followon chain. All the atoms between the
140// atom and the targetAtom (specified by layout-after) need to be of size zero
141// in this case. Otherwise the desired layout is impossible.
142bool LayoutPass::checkAllPrevAtomsZeroSize(const DefinedAtom *targetAtom) {
143 const DefinedAtom *atom = _followOnRoots[targetAtom];
144 while (true) {
Rui Ueyamaca8ca552013-05-14 00:41:52 +0000145 if (atom == targetAtom)
146 return true;
Rui Ueyama0196d1062013-05-14 16:53:59 +0000147 if (atom->size() != 0)
Rui Ueyamaca8ca552013-05-14 00:41:52 +0000148 // TODO: print warning that an impossible layout is being desired by the
149 // user.
150 return false;
Rui Ueyama5ec6d1a2013-05-14 01:51:56 +0000151 AtomToAtomT::iterator targetFollowOnAtomsIter = _followOnNexts.find(atom);
152 // The target atom must be in the chain of its root.
153 assert(targetFollowOnAtomsIter != _followOnNexts.end());
154 atom = targetFollowOnAtomsIter->second;
Rui Ueyamaca8ca552013-05-14 00:41:52 +0000155 }
156}
157
158// Set the root of all atoms in targetAtom's chain to the given root.
159void LayoutPass::setChainRoot(const DefinedAtom *targetAtom,
160 const DefinedAtom *root) {
161 // Walk through the followon chain and override each node's root.
162 while (true) {
163 _followOnRoots[targetAtom] = root;
164 AtomToAtomT::iterator targetFollowOnAtomsIter =
165 _followOnNexts.find(targetAtom);
166 if (targetFollowOnAtomsIter == _followOnNexts.end())
167 return;
168 targetAtom = targetFollowOnAtomsIter->second;
169 }
170}
171
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000172/// This pass builds the followon tables described by two DenseMaps
173/// followOnRoots and followonNexts.
174/// The followOnRoots map contains a mapping of a DefinedAtom to its root
175/// The followOnNexts map contains a mapping of what DefinedAtom follows the
176/// current Atom
177/// The algorithm follows a very simple approach
178/// a) If the atom is first seen, then make that as the root atom
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000179/// b) The targetAtom which this Atom contains, has the root thats set to the
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000180/// root of the current atom
181/// c) If the targetAtom is part of a different tree and the root of the
182/// targetAtom is itself, Chain all the atoms that are contained in the tree
183/// to the current Tree
184/// d) If the targetAtom is part of a different chain and the root of the
185/// targetAtom until the targetAtom has all atoms of size 0, then chain the
186/// targetAtoms and its tree to the current chain
187void LayoutPass::buildFollowOnTable(MutableFile::DefinedAtomRange &range) {
Michael J. Spencerd4eb47c2013-04-06 00:56:40 +0000188 ScopedTask task(getDefaultDomain(), "LayoutPass::buildFollowOnTable");
Rui Ueyamaca8ca552013-05-14 00:41:52 +0000189 // Set the initial size of the followon and the followonNext hash to the
190 // number of atoms that we have.
Shankar Easwaran45a5f932013-04-29 03:27:57 +0000191 _followOnRoots.resize(range.size());
192 _followOnNexts.resize(range.size());
Rui Ueyama0196d1062013-05-14 16:53:59 +0000193 for (const DefinedAtom *ai : range) {
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000194 for (const Reference *r : *ai) {
Rui Ueyamaca8ca552013-05-14 00:41:52 +0000195 if (r->kind() != lld::Reference::kindLayoutAfter)
196 continue;
197 const DefinedAtom *targetAtom = llvm::dyn_cast<DefinedAtom>(r->target());
198 _followOnNexts[ai] = targetAtom;
199
200 // If we find a followon for the first time, lets make that atom as the
201 // root atom.
202 if (_followOnRoots.count(ai) == 0)
203 _followOnRoots[ai] = ai;
204
205 auto iter = _followOnRoots.find(targetAtom);
206 if (iter == _followOnRoots.end()) {
207 // If the targetAtom is not a root of any chain, lets make the root of
208 // the targetAtom to the root of the current chain.
209 _followOnRoots[targetAtom] = _followOnRoots[ai];
210 } else if (iter->second == targetAtom) {
211 // If the targetAtom is the root of a chain, the chain becomes part of
212 // the current chain. Rewrite the subchain's root to the current
213 // chain's root.
214 setChainRoot(targetAtom, _followOnRoots[ai]);
215 } else {
216 // The targetAtom is already a part of a chain. If the current atom is
217 // of size zero, we can insert it in the middle of the chain just
218 // before the target atom, while not breaking other atom's followon
219 // relationships. If it's not, we can only insert the current atom at
220 // the beginning of the chain. All the atoms followed by the target
221 // atom must be of size zero in that case to satisfy the followon
222 // relationships.
Rui Ueyama0196d1062013-05-14 16:53:59 +0000223 size_t currentAtomSize = ai->size();
Rui Ueyamaca8ca552013-05-14 00:41:52 +0000224 if (currentAtomSize == 0) {
225 const DefinedAtom *targetPrevAtom = findAtomFollowedBy(targetAtom);
226 _followOnNexts[targetPrevAtom] = ai;
227 _followOnRoots[ai] = _followOnRoots[targetPrevAtom];
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000228 } else {
Rui Ueyamaca8ca552013-05-14 00:41:52 +0000229 if (!checkAllPrevAtomsZeroSize(targetAtom))
230 break;
231 _followOnNexts[ai] = _followOnRoots[targetAtom];
232 setChainRoot(_followOnRoots[targetAtom], _followOnRoots[ai]);
233 }
234 }
235 }
236 }
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000237}
238
239/// This pass builds the followon tables using InGroup relationships
240/// The algorithm follows a very simple approach
241/// a) If the rootAtom is not part of any root, create a new root with the
242/// as the head
243/// b) If the current Atom root is not found, then make the current atoms root
244/// point to the rootAtom
245/// c) If the root of the current Atom is itself a root of some other tree
246/// make all the atoms in the chain point to the ingroup reference
247/// d) Check to see if the current atom is part of the chain from the rootAtom
248/// if not add the atom to the chain, so that the current atom is part of the
249/// the chain where the rootAtom is in
250void LayoutPass::buildInGroupTable(MutableFile::DefinedAtomRange &range) {
Michael J. Spencerd4eb47c2013-04-06 00:56:40 +0000251 ScopedTask task(getDefaultDomain(), "LayoutPass::buildInGroupTable");
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000252 // This table would convert precededby references to follow on
253 // references so that we have only one table
Rui Ueyama0196d1062013-05-14 16:53:59 +0000254 for (const DefinedAtom *ai : range) {
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000255 for (const Reference *r : *ai) {
256 if (r->kind() == lld::Reference::kindInGroup) {
257 const DefinedAtom *rootAtom = llvm::dyn_cast<DefinedAtom>(r->target());
258 // If the root atom is not part of any root
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000259 // create a new root
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000260 if (_followOnRoots.count(rootAtom) == 0) {
261 _followOnRoots[rootAtom] = rootAtom;
262 }
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000263 // If the current Atom has not been seen yet and there is no root
264 // that has been set, set the root of the atom to the targetAtom
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000265 // as the targetAtom points to the ingroup root
266 auto iter = _followOnRoots.find(ai);
267 if (iter == _followOnRoots.end()) {
268 _followOnRoots[ai] = rootAtom;
Rui Ueyamaca8ca552013-05-14 00:41:52 +0000269 } else if (iter->second == ai) {
270 if (iter->second != rootAtom)
271 setChainRoot(iter->second, rootAtom);
272 } else {
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000273 // TODO : Flag an error that the root of the tree
274 // is different, Here is an example
275 // Say there are atoms
276 // chain 1 : a->b->c
277 // chain 2 : d->e->f
278 // and e,f have their ingroup reference as a
279 // this could happen only if the root of e,f that is d
280 // has root as 'a'
281 continue;
282 }
283
284 // Check if the current atom is part of the chain
285 bool isAtomInChain = false;
286 const DefinedAtom *lastAtom = rootAtom;
287 while (true) {
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000288 AtomToAtomT::iterator followOnAtomsIter =
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000289 _followOnNexts.find(lastAtom);
290 if (followOnAtomsIter != _followOnNexts.end()) {
291 lastAtom = followOnAtomsIter->second;
292 if (lastAtom == ai) {
293 isAtomInChain = true;
294 break;
295 }
296 }
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000297 else
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000298 break;
299 } // findAtomInChain
300
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000301 if (!isAtomInChain)
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000302 _followOnNexts[lastAtom] = ai;
303 }
304 }
305 }
306}
307
308/// This pass builds the followon tables using Preceded By relationships
309/// The algorithm follows a very simple approach
310/// a) If the targetAtom is not part of any root and the current atom is not
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000311/// part of any root, create a chain with the current atom as root and
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000312/// the targetAtom as following the current atom
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000313/// b) Chain the targetAtom to the current Atom if the targetAtom is not part
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000314/// of any chain and the currentAtom has no followOn's
315/// c) If the targetAtom is part of a different tree and the root of the
316/// targetAtom is itself, and if the current atom is not part of any root
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000317/// chain all the atoms together
318/// d) If the current atom has no followon and the root of the targetAtom is
319/// not equal to the root of the current atom(the targetAtom is not in the
320/// same chain), chain all the atoms that are lead by the targetAtom into
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000321/// the current chain
322void LayoutPass::buildPrecededByTable(MutableFile::DefinedAtomRange &range) {
Michael J. Spencerd4eb47c2013-04-06 00:56:40 +0000323 ScopedTask task(getDefaultDomain(), "LayoutPass::buildPrecededByTable");
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000324 // This table would convert precededby references to follow on
325 // references so that we have only one table
Rui Ueyama0196d1062013-05-14 16:53:59 +0000326 for (const DefinedAtom *ai : range) {
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000327 for (const Reference *r : *ai) {
328 if (r->kind() == lld::Reference::kindLayoutBefore) {
329 const DefinedAtom *targetAtom = llvm::dyn_cast<DefinedAtom>(r->target());
330 // Is the targetAtom not chained
331 if (_followOnRoots.count(targetAtom) == 0) {
332 // Is the current atom not part of any root ?
333 if (_followOnRoots.count(ai) == 0) {
334 _followOnRoots[ai] = ai;
335 _followOnNexts[ai] = targetAtom;
336 _followOnRoots[targetAtom] = _followOnRoots[ai];
337 } else if (_followOnNexts.count(ai) == 0) {
338 // Chain the targetAtom to the current Atom
339 // if the currentAtom has no followon references
340 _followOnNexts[ai] = targetAtom;
341 _followOnRoots[targetAtom] = _followOnRoots[ai];
342 }
343 } else if (_followOnRoots.find(targetAtom)->second == targetAtom) {
344 // Is the targetAtom in chain with the targetAtom as the root ?
345 bool changeRoots = false;
346 if (_followOnRoots.count(ai) == 0) {
347 _followOnRoots[ai] = ai;
348 _followOnNexts[ai] = targetAtom;
349 _followOnRoots[targetAtom] = _followOnRoots[ai];
350 changeRoots = true;
351 } else if (_followOnNexts.count(ai) == 0) {
352 // Chain the targetAtom to the current Atom
353 // if the currentAtom has no followon references
354 if (_followOnRoots[ai] != _followOnRoots[targetAtom]) {
355 _followOnNexts[ai] = targetAtom;
356 _followOnRoots[targetAtom] = _followOnRoots[ai];
357 changeRoots = true;
358 }
359 }
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000360 // Change the roots of the targetAtom and its chain to
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000361 // the current atoms root
362 if (changeRoots) {
Rui Ueyamaca8ca552013-05-14 00:41:52 +0000363 setChainRoot(_followOnRoots[targetAtom], _followOnRoots[ai]);
364 }
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000365 } // Is targetAtom root
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000366 } // kindLayoutBefore
Rui Ueyamaca8ca552013-05-14 00:41:52 +0000367 } // Reference
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000368 } // atom iteration
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000369} // end function
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000370
371
372/// Build an ordinal override map by traversing the followon chain, and
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000373/// assigning ordinals to each atom, if the atoms have their ordinals
374/// already assigned skip the atom and move to the next. This is the
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000375/// main map thats used to sort the atoms while comparing two atoms together
376void LayoutPass::buildOrdinalOverrideMap(MutableFile::DefinedAtomRange &range) {
Michael J. Spencerd4eb47c2013-04-06 00:56:40 +0000377 ScopedTask task(getDefaultDomain(), "LayoutPass::buildOrdinalOverrideMap");
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000378 uint64_t index = 0;
Rui Ueyama0196d1062013-05-14 16:53:59 +0000379 for (const DefinedAtom *ai : range) {
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000380 const DefinedAtom *atom = ai;
Michael J. Spencer1ecf8902013-03-12 00:10:00 +0000381 if (_ordinalOverrideMap.find(atom) != _ordinalOverrideMap.end())
382 continue;
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000383 AtomToAtomT::iterator start = _followOnRoots.find(atom);
384 if (start != _followOnRoots.end()) {
385 for (const DefinedAtom *nextAtom = start->second; nextAtom != NULL;
386 nextAtom = _followOnNexts[nextAtom]) {
387 AtomToOrdinalT::iterator pos = _ordinalOverrideMap.find(nextAtom);
388 if (pos == _ordinalOverrideMap.end()) {
389 _ordinalOverrideMap[nextAtom] = index++;
390 }
391 }
392 } else {
Shankar Easwarand8da9892013-05-22 17:41:04 +0000393 _ordinalOverrideMap[atom] = index++;
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000394 }
395 }
396}
397
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000398/// Perform the actual pass
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000399void LayoutPass::perform(MutableFile &mergedFile) {
Michael J. Spencerbd66d042013-05-28 18:55:39 +0000400 ScopedTask task(getDefaultDomain(), "LayoutPass");
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000401 MutableFile::DefinedAtomRange atomRange = mergedFile.definedAtoms();
402
403 // Build follow on tables
404 buildFollowOnTable(atomRange);
405
406 // Build Ingroup reference table
407 buildInGroupTable(atomRange);
408
409 // Build preceded by tables
410 buildPrecededByTable(atomRange);
411
412 // Build override maps
413 buildOrdinalOverrideMap(atomRange);
414
Rui Ueyama9c4f89a2013-05-23 01:31:25 +0000415 DEBUG({
Nick Kledzikf4fa8c02013-04-04 20:32:18 +0000416 llvm::dbgs() << "unsorted atoms:\n";
417 for (const DefinedAtom *atom : atomRange) {
Shankar Easwaran45a5f932013-04-29 03:27:57 +0000418 llvm::dbgs() << " file=" << atom->file().path()
419 << ", name=" << atom->name()
420 << ", size=" << atom->size()
421 << ", type=" << atom->contentType()
422 << ", ordinal=" << atom->ordinal()
423 << "\n";
Nick Kledzikf4fa8c02013-04-04 20:32:18 +0000424 }
425 });
Shankar Easwaran45a5f932013-04-29 03:27:57 +0000426
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000427 // sort the atoms
428 std::sort(atomRange.begin(), atomRange.end(), _compareAtoms);
Shankar Easwaran45a5f932013-04-29 03:27:57 +0000429
Rui Ueyama9c4f89a2013-05-23 01:31:25 +0000430 DEBUG({
Nick Kledzikf4fa8c02013-04-04 20:32:18 +0000431 llvm::dbgs() << "sorted atoms:\n";
432 for (const DefinedAtom *atom : atomRange) {
Shankar Easwaran45a5f932013-04-29 03:27:57 +0000433 llvm::dbgs() << " file=" << atom->file().path()
434 << ", name=" << atom->name()
435 << ", size=" << atom->size()
436 << ", type=" << atom->contentType()
437 << ", ordinal=" << atom->ordinal()
438 << "\n";
Nick Kledzikf4fa8c02013-04-04 20:32:18 +0000439 }
440 });
Nick Kledzikc314b462013-04-04 18:59:24 +0000441
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000442}