blob: 639527bbe353b0a729942850d183da55352139a2 [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
15#include "lld/Core/Instrumentation.h"
Shankar Easwaran34ab70f2013-02-07 20:16:12 +000016
Michael J. Spencer7f09a3d2013-02-26 01:35:30 +000017#include "llvm/Support/Debug.h"
18
Shankar Easwaran34ab70f2013-02-07 20:16:12 +000019using namespace lld;
20
21/// The function compares atoms by sorting atoms in the following order
22/// a) Sorts atoms with the same permissions
23/// b) Sorts atoms with the same content Type
24/// c) Sorts atoms by Section position preference
25/// d) Sorts atoms by how they follow / precede each atom
26/// e) Sorts atoms on how they appear using File Ordinality
27/// f) Sorts atoms on how they appear within the File
28bool LayoutPass::CompareAtoms::operator()(const DefinedAtom *left,
29 const DefinedAtom *right) {
Michael J. Spencer7f09a3d2013-02-26 01:35:30 +000030 DEBUG(llvm::dbgs() << "Sorting " << left->name() << " " << right->name() << "\n");
Shankar Easwaran34ab70f2013-02-07 20:16:12 +000031 if (left == right)
32 return false;
33
34 // Sort same permissions together.
35 DefinedAtom::ContentPermissions leftPerms = left->permissions();
36 DefinedAtom::ContentPermissions rightPerms = right->permissions();
Shankar Easwaran8c256852013-03-13 04:05:38 +000037
38 DEBUG(llvm::dbgs() << "Sorting by contentPerms"
39 << "(" << leftPerms << "," << rightPerms << ")\n");
40
Shankar Easwaran34ab70f2013-02-07 20:16:12 +000041 if (leftPerms != rightPerms)
42 return leftPerms < rightPerms;
43
44 // Sort same content types together.
45 DefinedAtom::ContentType leftType = left->contentType();
46 DefinedAtom::ContentType rightType = right->contentType();
Shankar Easwaran8c256852013-03-13 04:05:38 +000047
48 DEBUG(llvm::dbgs() << "Sorting by contentType"
49 << "(" << leftType << "," << rightType << ")\n");
50
Shankar Easwaran34ab70f2013-02-07 20:16:12 +000051 if (leftType != rightType)
52 return leftType < rightType;
53
54 // TO DO: Sort atoms in customs sections together.
55
56 // Sort by section position preference.
57 DefinedAtom::SectionPosition leftPos = left->sectionPosition();
58 DefinedAtom::SectionPosition rightPos = right->sectionPosition();
Shankar Easwaran8c256852013-03-13 04:05:38 +000059
60 DEBUG(llvm::dbgs() << "Sorting by sectionPos"
61 << "(" << leftPos << "," << rightPos << ")\n");
62
Shankar Easwaran34ab70f2013-02-07 20:16:12 +000063 bool leftSpecialPos = (leftPos != DefinedAtom::sectionPositionAny);
64 bool rightSpecialPos = (rightPos != DefinedAtom::sectionPositionAny);
65 if (leftSpecialPos || rightSpecialPos) {
66 if (leftPos != rightPos)
67 return leftPos < rightPos;
68 }
69
Michael J. Spencer7f09a3d2013-02-26 01:35:30 +000070 DEBUG(llvm::dbgs() << "Sorting by override\n");
71
Shankar Easwaran34ab70f2013-02-07 20:16:12 +000072 AtomToOrdinalT::const_iterator lPos = _layout._ordinalOverrideMap.find(left);
73 AtomToOrdinalT::const_iterator rPos = _layout._ordinalOverrideMap.find(right);
74 AtomToOrdinalT::const_iterator end = _layout._ordinalOverrideMap.end();
75 if (lPos != end) {
76 if (rPos != end) {
77 // both left and right are overridden, so compare overridden ordinals
Michael J. Spencer7f09a3d2013-02-26 01:35:30 +000078 if (lPos->second != rPos->second)
79 return lPos->second < rPos->second;
Shankar Easwaran34ab70f2013-02-07 20:16:12 +000080 } else {
81 // left is overridden and right is not, so left < right
82 return true;
83 }
84 } else {
85 if (rPos != end) {
86 // right is overridden and left is not, so right < left
87 return false;
88 } else {
Shankar Easwaran8962feb2013-03-14 16:09:49 +000089 // neither are overridden,
Shankar Easwaran34ab70f2013-02-07 20:16:12 +000090 // fall into default sorting below
91 }
92 }
93
94 // Sort by .o order.
95 const File *leftFile = &left->file();
96 const File *rightFile = &right->file();
Shankar Easwaran8c256852013-03-13 04:05:38 +000097
98 DEBUG(llvm::dbgs()
99 << "Sorting by .o order("
100 << "(" << leftFile->ordinal() << "," << rightFile->ordinal() << ")"
101 << "[" << leftFile->path() << "," << rightFile->path() << "]\n");
102
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000103 if (leftFile != rightFile)
104 return leftFile->ordinal() < rightFile->ordinal();
105
106 // Sort by atom order with .o file.
107 uint64_t leftOrdinal = left->ordinal();
108 uint64_t rightOrdinal = right->ordinal();
Shankar Easwaran8c256852013-03-13 04:05:38 +0000109
110 DEBUG(llvm::dbgs() << "Sorting by ordinal(" << left->ordinal() << ","
111 << right->ordinal() << ")\n");
112
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000113 if (leftOrdinal != rightOrdinal)
114 return leftOrdinal < rightOrdinal;
115
Michael J. Spencer7f09a3d2013-02-26 01:35:30 +0000116 DEBUG(llvm::dbgs() << "Unordered\n");
117
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000118 return false;
119}
120
121/// This pass builds the followon tables described by two DenseMaps
122/// followOnRoots and followonNexts.
123/// The followOnRoots map contains a mapping of a DefinedAtom to its root
124/// The followOnNexts map contains a mapping of what DefinedAtom follows the
125/// current Atom
126/// The algorithm follows a very simple approach
127/// a) If the atom is first seen, then make that as the root atom
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000128/// b) The targetAtom which this Atom contains, has the root thats set to the
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000129/// root of the current atom
130/// c) If the targetAtom is part of a different tree and the root of the
131/// targetAtom is itself, Chain all the atoms that are contained in the tree
132/// to the current Tree
133/// d) If the targetAtom is part of a different chain and the root of the
134/// targetAtom until the targetAtom has all atoms of size 0, then chain the
135/// targetAtoms and its tree to the current chain
136void LayoutPass::buildFollowOnTable(MutableFile::DefinedAtomRange &range) {
Michael J. Spencerd4eb47c2013-04-06 00:56:40 +0000137 ScopedTask task(getDefaultDomain(), "LayoutPass::buildFollowOnTable");
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000138 for (auto ai : range) {
139 for (const Reference *r : *ai) {
140 if (r->kind() == lld::Reference::kindLayoutAfter) {
141 const DefinedAtom *targetAtom = llvm::dyn_cast<DefinedAtom>(r->target());
142 _followOnNexts[ai] = targetAtom;
143 // If we find a followon for the first time, lets make that
144 // atom as the root atom
145 if (_followOnRoots.count(ai) == 0) {
146 _followOnRoots[ai] = ai;
147 }
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000148 // If the targetAtom is not a root of any chain, lets make
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000149 // the root of the targetAtom to the root of the current chain
150 auto iter = _followOnRoots.find(targetAtom);
151 if (iter == _followOnRoots.end()) {
Michael J. Spencer52fdb8b2013-03-09 01:41:27 +0000152 auto tmp = _followOnRoots[ai];
153 _followOnRoots[targetAtom] = tmp;
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000154 } else {
155 // The followon is part of another chain
156 if (iter->second == targetAtom) {
157 const DefinedAtom *a = targetAtom;
158 while (true) {
159 _followOnRoots[a] = _followOnRoots[ai];
160 // Set all the follow on's for the targetAtom to be
161 // the current root
162 AtomToAtomT::iterator targetFollowOnAtomsIter =
163 _followOnNexts.find(a);
164
165 if (targetFollowOnAtomsIter != _followOnNexts.end())
166 a = targetFollowOnAtomsIter->second;
167 else
168 break;
169 } // while true
170 } else { // the atom could be part of chain already
171 // Get to the root of the chain
172 const DefinedAtom *a = _followOnRoots[targetAtom];
Shankar Easwaranc44bc342013-03-06 21:59:27 +0000173 const DefinedAtom *targetPrevAtom = nullptr;
174
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000175 // If the size of the atom is 0, and the target
Shankar Easwaranc44bc342013-03-06 21:59:27 +0000176 // is already part of a chain, lets bring the current
177 // atom into the chain
178 size_t currentAtomSize = (*ai).size();
179
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000180 // Lets add to the chain only if the atoms that
181 // appear before the targetAtom in the chain
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000182 // are of size 0
183 bool foundNonZeroSizeAtom = false;
184 while (true) {
Shankar Easwaranc44bc342013-03-06 21:59:27 +0000185 targetPrevAtom = a;
186
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000187 // Set all the follow on's for the targetAtom to be
188 // the current root
189 AtomToAtomT::iterator targetFollowOnAtomsIter =
190 _followOnNexts.find(a);
191
192 if (targetFollowOnAtomsIter != _followOnNexts.end())
193 a = targetFollowOnAtomsIter->second;
194 else
195 break;
196
Shankar Easwaranc44bc342013-03-06 21:59:27 +0000197 if ((a->size() != 0) && (currentAtomSize != 0)) {
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000198 foundNonZeroSizeAtom = true;
199 break;
200 }
Shankar Easwaranc44bc342013-03-06 21:59:27 +0000201
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000202 if (a == targetAtom)
203 break;
Shankar Easwaranc44bc342013-03-06 21:59:27 +0000204
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000205 } // while true
206 if (foundNonZeroSizeAtom) {
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000207 // TODO: print warning that an impossible layout
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000208 // is being desired by the user
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000209 // Continue to the next atom
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000210 break;
211 }
212
Shankar Easwaranc44bc342013-03-06 21:59:27 +0000213 // If the atom is a zero sized atom, then make the target
214 // follow the zero sized atom, as the zero sized atom may be
215 // a weak symbol
216 if ((currentAtomSize == 0) && (targetPrevAtom)) {
217 _followOnNexts[targetPrevAtom] = ai;
218 _followOnRoots[ai] = _followOnRoots[targetPrevAtom];
219 _followOnNexts[ai] = targetAtom;
220 } else {
221 _followOnNexts[ai] = _followOnRoots[targetAtom];
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000222 // Set the root of all atoms in the
Shankar Easwaranc44bc342013-03-06 21:59:27 +0000223 a = _followOnRoots[targetAtom];
224 while (true) {
225 _followOnRoots[a] = _followOnRoots[ai];
226 // Set all the follow on's for the targetAtom to be
227 // the current root
228 AtomToAtomT::iterator targetFollowOnAtomsIter =
229 _followOnNexts.find(a);
230 if (targetFollowOnAtomsIter != _followOnNexts.end())
231 a = targetFollowOnAtomsIter->second;
232 else
233 break;
234 } // while true
235 } // end else (currentAtomSize != 0)
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000236 } // end else
237 } // else
238 } // kindLayoutAfter
239 } // Reference
240 } // range
241}
242
243/// This pass builds the followon tables using InGroup relationships
244/// The algorithm follows a very simple approach
245/// a) If the rootAtom is not part of any root, create a new root with the
246/// as the head
247/// b) If the current Atom root is not found, then make the current atoms root
248/// point to the rootAtom
249/// c) If the root of the current Atom is itself a root of some other tree
250/// make all the atoms in the chain point to the ingroup reference
251/// d) Check to see if the current atom is part of the chain from the rootAtom
252/// if not add the atom to the chain, so that the current atom is part of the
253/// the chain where the rootAtom is in
254void LayoutPass::buildInGroupTable(MutableFile::DefinedAtomRange &range) {
Michael J. Spencerd4eb47c2013-04-06 00:56:40 +0000255 ScopedTask task(getDefaultDomain(), "LayoutPass::buildInGroupTable");
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000256 // This table would convert precededby references to follow on
257 // references so that we have only one table
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000258 for (auto ai : range) {
259 for (const Reference *r : *ai) {
260 if (r->kind() == lld::Reference::kindInGroup) {
261 const DefinedAtom *rootAtom = llvm::dyn_cast<DefinedAtom>(r->target());
262 // If the root atom is not part of any root
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000263 // create a new root
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000264 if (_followOnRoots.count(rootAtom) == 0) {
265 _followOnRoots[rootAtom] = rootAtom;
266 }
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000267 // If the current Atom has not been seen yet and there is no root
268 // that has been set, set the root of the atom to the targetAtom
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000269 // as the targetAtom points to the ingroup root
270 auto iter = _followOnRoots.find(ai);
271 if (iter == _followOnRoots.end()) {
272 _followOnRoots[ai] = rootAtom;
273 }
274 else if (iter->second == ai) {
275 if (iter->second != rootAtom) {
276 const DefinedAtom *a = iter->second;
277 // Change all the followon next references to the ingroup reference root
278 while (true) {
279 _followOnRoots[a] = rootAtom;
280 // Set all the follow on's for the targetAtom to be
281 // the current root
282 AtomToAtomT::iterator targetFollowOnAtomsIter =
283 _followOnNexts.find(a);
284 if (targetFollowOnAtomsIter != _followOnNexts.end())
285 a = targetFollowOnAtomsIter->second;
286 else
287 break;
288 } // while true
289 }
290 }
291 else {
292 // TODO : Flag an error that the root of the tree
293 // is different, Here is an example
294 // Say there are atoms
295 // chain 1 : a->b->c
296 // chain 2 : d->e->f
297 // and e,f have their ingroup reference as a
298 // this could happen only if the root of e,f that is d
299 // has root as 'a'
300 continue;
301 }
302
303 // Check if the current atom is part of the chain
304 bool isAtomInChain = false;
305 const DefinedAtom *lastAtom = rootAtom;
306 while (true) {
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000307 AtomToAtomT::iterator followOnAtomsIter =
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000308 _followOnNexts.find(lastAtom);
309 if (followOnAtomsIter != _followOnNexts.end()) {
310 lastAtom = followOnAtomsIter->second;
311 if (lastAtom == ai) {
312 isAtomInChain = true;
313 break;
314 }
315 }
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000316 else
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000317 break;
318 } // findAtomInChain
319
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000320 if (!isAtomInChain)
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000321 _followOnNexts[lastAtom] = ai;
322 }
323 }
324 }
325}
326
327/// This pass builds the followon tables using Preceded By relationships
328/// The algorithm follows a very simple approach
329/// a) If the targetAtom is not part of any root and the current atom is not
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000330/// part of any root, create a chain with the current atom as root and
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000331/// the targetAtom as following the current atom
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000332/// b) Chain the targetAtom to the current Atom if the targetAtom is not part
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000333/// of any chain and the currentAtom has no followOn's
334/// c) If the targetAtom is part of a different tree and the root of the
335/// targetAtom is itself, and if the current atom is not part of any root
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000336/// chain all the atoms together
337/// d) If the current atom has no followon and the root of the targetAtom is
338/// not equal to the root of the current atom(the targetAtom is not in the
339/// same chain), chain all the atoms that are lead by the targetAtom into
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000340/// the current chain
341void LayoutPass::buildPrecededByTable(MutableFile::DefinedAtomRange &range) {
Michael J. Spencerd4eb47c2013-04-06 00:56:40 +0000342 ScopedTask task(getDefaultDomain(), "LayoutPass::buildPrecededByTable");
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000343 // This table would convert precededby references to follow on
344 // references so that we have only one table
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000345 for (auto ai : range) {
346 for (const Reference *r : *ai) {
347 if (r->kind() == lld::Reference::kindLayoutBefore) {
348 const DefinedAtom *targetAtom = llvm::dyn_cast<DefinedAtom>(r->target());
349 // Is the targetAtom not chained
350 if (_followOnRoots.count(targetAtom) == 0) {
351 // Is the current atom not part of any root ?
352 if (_followOnRoots.count(ai) == 0) {
353 _followOnRoots[ai] = ai;
354 _followOnNexts[ai] = targetAtom;
355 _followOnRoots[targetAtom] = _followOnRoots[ai];
356 } else if (_followOnNexts.count(ai) == 0) {
357 // Chain the targetAtom to the current Atom
358 // if the currentAtom has no followon references
359 _followOnNexts[ai] = targetAtom;
360 _followOnRoots[targetAtom] = _followOnRoots[ai];
361 }
362 } else if (_followOnRoots.find(targetAtom)->second == targetAtom) {
363 // Is the targetAtom in chain with the targetAtom as the root ?
364 bool changeRoots = false;
365 if (_followOnRoots.count(ai) == 0) {
366 _followOnRoots[ai] = ai;
367 _followOnNexts[ai] = targetAtom;
368 _followOnRoots[targetAtom] = _followOnRoots[ai];
369 changeRoots = true;
370 } else if (_followOnNexts.count(ai) == 0) {
371 // Chain the targetAtom to the current Atom
372 // if the currentAtom has no followon references
373 if (_followOnRoots[ai] != _followOnRoots[targetAtom]) {
374 _followOnNexts[ai] = targetAtom;
375 _followOnRoots[targetAtom] = _followOnRoots[ai];
376 changeRoots = true;
377 }
378 }
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000379 // Change the roots of the targetAtom and its chain to
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000380 // the current atoms root
381 if (changeRoots) {
382 const DefinedAtom *a = _followOnRoots[targetAtom];
383 while (true) {
384 _followOnRoots[a] = _followOnRoots[ai];
385 // Set all the follow on's for the targetAtom to be
386 // the current root
387 AtomToAtomT::iterator targetFollowOnAtomsIter =
388 _followOnNexts.find(a);
389 if (targetFollowOnAtomsIter != _followOnNexts.end())
390 a = targetFollowOnAtomsIter->second;
391 else
392 break;
393 }
394 } // changeRoots
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000395 } // Is targetAtom root
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000396 } // kindLayoutBefore
397 } // Reference
398 } // atom iteration
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000399} // end function
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000400
401
402/// Build an ordinal override map by traversing the followon chain, and
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000403/// assigning ordinals to each atom, if the atoms have their ordinals
404/// already assigned skip the atom and move to the next. This is the
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000405/// main map thats used to sort the atoms while comparing two atoms together
406void LayoutPass::buildOrdinalOverrideMap(MutableFile::DefinedAtomRange &range) {
Michael J. Spencerd4eb47c2013-04-06 00:56:40 +0000407 ScopedTask task(getDefaultDomain(), "LayoutPass::buildOrdinalOverrideMap");
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000408 uint64_t index = 0;
409 for (auto ai : range) {
410 const DefinedAtom *atom = ai;
Michael J. Spencer1ecf8902013-03-12 00:10:00 +0000411 if (_ordinalOverrideMap.find(atom) != _ordinalOverrideMap.end())
412 continue;
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000413 AtomToAtomT::iterator start = _followOnRoots.find(atom);
414 if (start != _followOnRoots.end()) {
415 for (const DefinedAtom *nextAtom = start->second; nextAtom != NULL;
416 nextAtom = _followOnNexts[nextAtom]) {
417 AtomToOrdinalT::iterator pos = _ordinalOverrideMap.find(nextAtom);
418 if (pos == _ordinalOverrideMap.end()) {
419 _ordinalOverrideMap[nextAtom] = index++;
420 }
421 }
422 } else {
423 _ordinalOverrideMap[atom] = index;
424 }
425 }
426}
427
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000428/// Perform the actual pass
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000429void LayoutPass::perform(MutableFile &mergedFile) {
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000430 MutableFile::DefinedAtomRange atomRange = mergedFile.definedAtoms();
431
432 // Build follow on tables
433 buildFollowOnTable(atomRange);
434
435 // Build Ingroup reference table
436 buildInGroupTable(atomRange);
437
438 // Build preceded by tables
439 buildPrecededByTable(atomRange);
440
441 // Build override maps
442 buildOrdinalOverrideMap(atomRange);
443
Nick Kledzikf4fa8c02013-04-04 20:32:18 +0000444 DEBUG_WITH_TYPE("layout", {
445 llvm::dbgs() << "unsorted atoms:\n";
446 for (const DefinedAtom *atom : atomRange) {
447 llvm::dbgs() << " file=" << atom->file().path()
Nick Kledzikc314b462013-04-04 18:59:24 +0000448 << ", name=" << atom->name()
449 << ", size=" << atom->size()
450 << ", type=" << atom->contentType()
451 << ", ordinal=" << atom->ordinal()
Nick Kledzikf4fa8c02013-04-04 20:32:18 +0000452 << "\n";
453 }
454 });
455
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000456 // sort the atoms
457 std::sort(atomRange.begin(), atomRange.end(), _compareAtoms);
Nick Kledzikc314b462013-04-04 18:59:24 +0000458
Nick Kledzikf4fa8c02013-04-04 20:32:18 +0000459 DEBUG_WITH_TYPE("layout", {
460 llvm::dbgs() << "sorted atoms:\n";
461 for (const DefinedAtom *atom : atomRange) {
462 llvm::dbgs() << " file=" << atom->file().path()
Nick Kledzikc314b462013-04-04 18:59:24 +0000463 << ", name=" << atom->name()
464 << ", size=" << atom->size()
465 << ", type=" << atom->contentType()
466 << ", ordinal=" << atom->ordinal()
Nick Kledzikf4fa8c02013-04-04 20:32:18 +0000467 << "\n";
468 }
469 });
470
Nick Kledzikc314b462013-04-04 18:59:24 +0000471
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000472}