blob: 9c8a2e17e2ddf7d33415c3e330dba397fd4c8229 [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
Shankar Easwarand8da9892013-05-22 17:41:04 +000034 // Sort by section position preference.
35 DefinedAtom::SectionPosition leftPos = left->sectionPosition();
36 DefinedAtom::SectionPosition rightPos = right->sectionPosition();
37
38 DEBUG(llvm::dbgs() << "Sorting by sectionPos"
39 << "(" << leftPos << "," << rightPos << ")\n");
40
41 bool leftSpecialPos = (leftPos != DefinedAtom::sectionPositionAny);
42 bool rightSpecialPos = (rightPos != DefinedAtom::sectionPositionAny);
43 if (leftSpecialPos || rightSpecialPos) {
44 if (leftPos != rightPos)
45 return leftPos < rightPos;
46 }
47
Shankar Easwaran3c5d2c82013-05-10 16:44:02 +000048 DEBUG(llvm::dbgs() << "Sorting by override\n");
49
50 AtomToOrdinalT::const_iterator lPos = _layout._ordinalOverrideMap.find(left);
51 AtomToOrdinalT::const_iterator rPos = _layout._ordinalOverrideMap.find(right);
52 AtomToOrdinalT::const_iterator end = _layout._ordinalOverrideMap.end();
53 if (lPos != end) {
54 if (rPos != end) {
55 // both left and right are overridden, so compare overridden ordinals
56 if (lPos->second != rPos->second)
57 return lPos->second < rPos->second;
58 } else {
59 // left is overridden and right is not, so left < right
60 return true;
61 }
62 } else {
63 if (rPos != end) {
64 // right is overridden and left is not, so right < left
65 return false;
66 } else {
67 // neither are overridden,
68 // fall into default sorting below
69 }
70 }
71
Shankar Easwaran34ab70f2013-02-07 20:16:12 +000072 // Sort same permissions together.
73 DefinedAtom::ContentPermissions leftPerms = left->permissions();
74 DefinedAtom::ContentPermissions rightPerms = right->permissions();
Shankar Easwaran8c256852013-03-13 04:05:38 +000075
76 DEBUG(llvm::dbgs() << "Sorting by contentPerms"
77 << "(" << leftPerms << "," << rightPerms << ")\n");
78
Shankar Easwaran34ab70f2013-02-07 20:16:12 +000079 if (leftPerms != rightPerms)
80 return leftPerms < rightPerms;
81
82 // Sort same content types together.
83 DefinedAtom::ContentType leftType = left->contentType();
84 DefinedAtom::ContentType rightType = right->contentType();
Shankar Easwaran8c256852013-03-13 04:05:38 +000085
86 DEBUG(llvm::dbgs() << "Sorting by contentType"
87 << "(" << leftType << "," << rightType << ")\n");
88
Shankar Easwaran34ab70f2013-02-07 20:16:12 +000089 if (leftType != rightType)
90 return leftType < rightType;
91
92 // TO DO: Sort atoms in customs sections together.
93
Shankar Easwaran34ab70f2013-02-07 20:16:12 +000094 // 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
Rui Ueyamaca8ca552013-05-14 00:41:52 +0000121// Returns the atom immediately followed by the given atom in the followon
122// chain.
123const DefinedAtom *LayoutPass::findAtomFollowedBy(
124 const DefinedAtom *targetAtom) {
125 // Start from the beginning of the chain and follow the chain until
126 // we find the targetChain.
127 const DefinedAtom *atom = _followOnRoots[targetAtom];
128 while (true) {
129 const DefinedAtom *prevAtom = atom;
130 AtomToAtomT::iterator targetFollowOnAtomsIter = _followOnNexts.find(atom);
131 // The target atom must be in the chain of its root.
132 assert(targetFollowOnAtomsIter != _followOnNexts.end());
133 atom = targetFollowOnAtomsIter->second;
134 if (atom == targetAtom)
135 return prevAtom;
136 }
137}
138
139// Check if all the atoms followed by the given target atom are of size zero.
140// When this method is called, an atom being added is not of size zero and
141// will be added to the head of the followon chain. All the atoms between the
142// atom and the targetAtom (specified by layout-after) need to be of size zero
143// in this case. Otherwise the desired layout is impossible.
144bool LayoutPass::checkAllPrevAtomsZeroSize(const DefinedAtom *targetAtom) {
145 const DefinedAtom *atom = _followOnRoots[targetAtom];
146 while (true) {
Rui Ueyamaca8ca552013-05-14 00:41:52 +0000147 if (atom == targetAtom)
148 return true;
Rui Ueyama0196d1062013-05-14 16:53:59 +0000149 if (atom->size() != 0)
Rui Ueyamaca8ca552013-05-14 00:41:52 +0000150 // TODO: print warning that an impossible layout is being desired by the
151 // user.
152 return false;
Rui Ueyama5ec6d1a2013-05-14 01:51:56 +0000153 AtomToAtomT::iterator targetFollowOnAtomsIter = _followOnNexts.find(atom);
154 // The target atom must be in the chain of its root.
155 assert(targetFollowOnAtomsIter != _followOnNexts.end());
156 atom = targetFollowOnAtomsIter->second;
Rui Ueyamaca8ca552013-05-14 00:41:52 +0000157 }
158}
159
160// Set the root of all atoms in targetAtom's chain to the given root.
161void LayoutPass::setChainRoot(const DefinedAtom *targetAtom,
162 const DefinedAtom *root) {
163 // Walk through the followon chain and override each node's root.
164 while (true) {
165 _followOnRoots[targetAtom] = root;
166 AtomToAtomT::iterator targetFollowOnAtomsIter =
167 _followOnNexts.find(targetAtom);
168 if (targetFollowOnAtomsIter == _followOnNexts.end())
169 return;
170 targetAtom = targetFollowOnAtomsIter->second;
171 }
172}
173
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000174/// This pass builds the followon tables described by two DenseMaps
175/// followOnRoots and followonNexts.
176/// The followOnRoots map contains a mapping of a DefinedAtom to its root
177/// The followOnNexts map contains a mapping of what DefinedAtom follows the
178/// current Atom
179/// The algorithm follows a very simple approach
180/// a) If the atom is first seen, then make that as the root atom
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000181/// b) The targetAtom which this Atom contains, has the root thats set to the
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000182/// root of the current atom
183/// c) If the targetAtom is part of a different tree and the root of the
184/// targetAtom is itself, Chain all the atoms that are contained in the tree
185/// to the current Tree
186/// d) If the targetAtom is part of a different chain and the root of the
187/// targetAtom until the targetAtom has all atoms of size 0, then chain the
188/// targetAtoms and its tree to the current chain
189void LayoutPass::buildFollowOnTable(MutableFile::DefinedAtomRange &range) {
Michael J. Spencerd4eb47c2013-04-06 00:56:40 +0000190 ScopedTask task(getDefaultDomain(), "LayoutPass::buildFollowOnTable");
Rui Ueyamaca8ca552013-05-14 00:41:52 +0000191 // Set the initial size of the followon and the followonNext hash to the
192 // number of atoms that we have.
Shankar Easwaran45a5f932013-04-29 03:27:57 +0000193 _followOnRoots.resize(range.size());
194 _followOnNexts.resize(range.size());
Rui Ueyama0196d1062013-05-14 16:53:59 +0000195 for (const DefinedAtom *ai : range) {
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000196 for (const Reference *r : *ai) {
Rui Ueyamaca8ca552013-05-14 00:41:52 +0000197 if (r->kind() != lld::Reference::kindLayoutAfter)
198 continue;
199 const DefinedAtom *targetAtom = llvm::dyn_cast<DefinedAtom>(r->target());
200 _followOnNexts[ai] = targetAtom;
201
202 // If we find a followon for the first time, lets make that atom as the
203 // root atom.
204 if (_followOnRoots.count(ai) == 0)
205 _followOnRoots[ai] = ai;
206
207 auto iter = _followOnRoots.find(targetAtom);
208 if (iter == _followOnRoots.end()) {
209 // If the targetAtom is not a root of any chain, lets make the root of
210 // the targetAtom to the root of the current chain.
211 _followOnRoots[targetAtom] = _followOnRoots[ai];
212 } else if (iter->second == targetAtom) {
213 // If the targetAtom is the root of a chain, the chain becomes part of
214 // the current chain. Rewrite the subchain's root to the current
215 // chain's root.
216 setChainRoot(targetAtom, _followOnRoots[ai]);
217 } else {
218 // The targetAtom is already a part of a chain. If the current atom is
219 // of size zero, we can insert it in the middle of the chain just
220 // before the target atom, while not breaking other atom's followon
221 // relationships. If it's not, we can only insert the current atom at
222 // the beginning of the chain. All the atoms followed by the target
223 // atom must be of size zero in that case to satisfy the followon
224 // relationships.
Rui Ueyama0196d1062013-05-14 16:53:59 +0000225 size_t currentAtomSize = ai->size();
Rui Ueyamaca8ca552013-05-14 00:41:52 +0000226 if (currentAtomSize == 0) {
227 const DefinedAtom *targetPrevAtom = findAtomFollowedBy(targetAtom);
228 _followOnNexts[targetPrevAtom] = ai;
229 _followOnRoots[ai] = _followOnRoots[targetPrevAtom];
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000230 } else {
Rui Ueyamaca8ca552013-05-14 00:41:52 +0000231 if (!checkAllPrevAtomsZeroSize(targetAtom))
232 break;
233 _followOnNexts[ai] = _followOnRoots[targetAtom];
234 setChainRoot(_followOnRoots[targetAtom], _followOnRoots[ai]);
235 }
236 }
237 }
238 }
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000239}
240
241/// This pass builds the followon tables using InGroup relationships
242/// The algorithm follows a very simple approach
243/// a) If the rootAtom is not part of any root, create a new root with the
244/// as the head
245/// b) If the current Atom root is not found, then make the current atoms root
246/// point to the rootAtom
247/// c) If the root of the current Atom is itself a root of some other tree
248/// make all the atoms in the chain point to the ingroup reference
249/// d) Check to see if the current atom is part of the chain from the rootAtom
250/// if not add the atom to the chain, so that the current atom is part of the
251/// the chain where the rootAtom is in
252void LayoutPass::buildInGroupTable(MutableFile::DefinedAtomRange &range) {
Michael J. Spencerd4eb47c2013-04-06 00:56:40 +0000253 ScopedTask task(getDefaultDomain(), "LayoutPass::buildInGroupTable");
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000254 // This table would convert precededby references to follow on
255 // references so that we have only one table
Rui Ueyama0196d1062013-05-14 16:53:59 +0000256 for (const DefinedAtom *ai : range) {
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000257 for (const Reference *r : *ai) {
258 if (r->kind() == lld::Reference::kindInGroup) {
259 const DefinedAtom *rootAtom = llvm::dyn_cast<DefinedAtom>(r->target());
260 // If the root atom is not part of any root
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000261 // create a new root
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000262 if (_followOnRoots.count(rootAtom) == 0) {
263 _followOnRoots[rootAtom] = rootAtom;
264 }
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000265 // If the current Atom has not been seen yet and there is no root
266 // that has been set, set the root of the atom to the targetAtom
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000267 // as the targetAtom points to the ingroup root
268 auto iter = _followOnRoots.find(ai);
269 if (iter == _followOnRoots.end()) {
270 _followOnRoots[ai] = rootAtom;
Rui Ueyamaca8ca552013-05-14 00:41:52 +0000271 } else if (iter->second == ai) {
272 if (iter->second != rootAtom)
273 setChainRoot(iter->second, rootAtom);
274 } else {
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000275 // TODO : Flag an error that the root of the tree
276 // is different, Here is an example
277 // Say there are atoms
278 // chain 1 : a->b->c
279 // chain 2 : d->e->f
280 // and e,f have their ingroup reference as a
281 // this could happen only if the root of e,f that is d
282 // has root as 'a'
283 continue;
284 }
285
286 // Check if the current atom is part of the chain
287 bool isAtomInChain = false;
288 const DefinedAtom *lastAtom = rootAtom;
289 while (true) {
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000290 AtomToAtomT::iterator followOnAtomsIter =
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000291 _followOnNexts.find(lastAtom);
292 if (followOnAtomsIter != _followOnNexts.end()) {
293 lastAtom = followOnAtomsIter->second;
294 if (lastAtom == ai) {
295 isAtomInChain = true;
296 break;
297 }
298 }
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000299 else
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000300 break;
301 } // findAtomInChain
302
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000303 if (!isAtomInChain)
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000304 _followOnNexts[lastAtom] = ai;
305 }
306 }
307 }
308}
309
310/// This pass builds the followon tables using Preceded By relationships
311/// The algorithm follows a very simple approach
312/// a) If the targetAtom is not part of any root and the current atom is not
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000313/// part of any root, create a chain with the current atom as root and
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000314/// the targetAtom as following the current atom
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000315/// b) Chain the targetAtom to the current Atom if the targetAtom is not part
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000316/// of any chain and the currentAtom has no followOn's
317/// c) If the targetAtom is part of a different tree and the root of the
318/// targetAtom is itself, and if the current atom is not part of any root
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000319/// chain all the atoms together
320/// d) If the current atom has no followon and the root of the targetAtom is
321/// not equal to the root of the current atom(the targetAtom is not in the
322/// same chain), chain all the atoms that are lead by the targetAtom into
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000323/// the current chain
324void LayoutPass::buildPrecededByTable(MutableFile::DefinedAtomRange &range) {
Michael J. Spencerd4eb47c2013-04-06 00:56:40 +0000325 ScopedTask task(getDefaultDomain(), "LayoutPass::buildPrecededByTable");
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000326 // This table would convert precededby references to follow on
327 // references so that we have only one table
Rui Ueyama0196d1062013-05-14 16:53:59 +0000328 for (const DefinedAtom *ai : range) {
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000329 for (const Reference *r : *ai) {
330 if (r->kind() == lld::Reference::kindLayoutBefore) {
331 const DefinedAtom *targetAtom = llvm::dyn_cast<DefinedAtom>(r->target());
332 // Is the targetAtom not chained
333 if (_followOnRoots.count(targetAtom) == 0) {
334 // Is the current atom not part of any root ?
335 if (_followOnRoots.count(ai) == 0) {
336 _followOnRoots[ai] = ai;
337 _followOnNexts[ai] = targetAtom;
338 _followOnRoots[targetAtom] = _followOnRoots[ai];
339 } else if (_followOnNexts.count(ai) == 0) {
340 // Chain the targetAtom to the current Atom
341 // if the currentAtom has no followon references
342 _followOnNexts[ai] = targetAtom;
343 _followOnRoots[targetAtom] = _followOnRoots[ai];
344 }
345 } else if (_followOnRoots.find(targetAtom)->second == targetAtom) {
346 // Is the targetAtom in chain with the targetAtom as the root ?
347 bool changeRoots = false;
348 if (_followOnRoots.count(ai) == 0) {
349 _followOnRoots[ai] = ai;
350 _followOnNexts[ai] = targetAtom;
351 _followOnRoots[targetAtom] = _followOnRoots[ai];
352 changeRoots = true;
353 } else if (_followOnNexts.count(ai) == 0) {
354 // Chain the targetAtom to the current Atom
355 // if the currentAtom has no followon references
356 if (_followOnRoots[ai] != _followOnRoots[targetAtom]) {
357 _followOnNexts[ai] = targetAtom;
358 _followOnRoots[targetAtom] = _followOnRoots[ai];
359 changeRoots = true;
360 }
361 }
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000362 // Change the roots of the targetAtom and its chain to
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000363 // the current atoms root
364 if (changeRoots) {
Rui Ueyamaca8ca552013-05-14 00:41:52 +0000365 setChainRoot(_followOnRoots[targetAtom], _followOnRoots[ai]);
366 }
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000367 } // Is targetAtom root
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000368 } // kindLayoutBefore
Rui Ueyamaca8ca552013-05-14 00:41:52 +0000369 } // Reference
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000370 } // atom iteration
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000371} // end function
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000372
373
374/// Build an ordinal override map by traversing the followon chain, and
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000375/// assigning ordinals to each atom, if the atoms have their ordinals
376/// already assigned skip the atom and move to the next. This is the
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000377/// main map thats used to sort the atoms while comparing two atoms together
378void LayoutPass::buildOrdinalOverrideMap(MutableFile::DefinedAtomRange &range) {
Michael J. Spencerd4eb47c2013-04-06 00:56:40 +0000379 ScopedTask task(getDefaultDomain(), "LayoutPass::buildOrdinalOverrideMap");
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000380 uint64_t index = 0;
Rui Ueyama0196d1062013-05-14 16:53:59 +0000381 for (const DefinedAtom *ai : range) {
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000382 const DefinedAtom *atom = ai;
Michael J. Spencer1ecf8902013-03-12 00:10:00 +0000383 if (_ordinalOverrideMap.find(atom) != _ordinalOverrideMap.end())
384 continue;
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000385 AtomToAtomT::iterator start = _followOnRoots.find(atom);
386 if (start != _followOnRoots.end()) {
387 for (const DefinedAtom *nextAtom = start->second; nextAtom != NULL;
388 nextAtom = _followOnNexts[nextAtom]) {
389 AtomToOrdinalT::iterator pos = _ordinalOverrideMap.find(nextAtom);
390 if (pos == _ordinalOverrideMap.end()) {
391 _ordinalOverrideMap[nextAtom] = index++;
392 }
393 }
394 } else {
Shankar Easwarand8da9892013-05-22 17:41:04 +0000395 _ordinalOverrideMap[atom] = index++;
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000396 }
397 }
398}
399
Shankar Easwaran8962feb2013-03-14 16:09:49 +0000400/// Perform the actual pass
Shankar Easwaran34ab70f2013-02-07 20:16:12 +0000401void LayoutPass::perform(MutableFile &mergedFile) {
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
Shankar Easwaran45a5f932013-04-29 03:27:57 +0000416 DEBUG_WITH_TYPE("layout", {
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
429 std::sort(atomRange.begin(), atomRange.end(), _compareAtoms);
Shankar Easwaran45a5f932013-04-29 03:27:57 +0000430
431 DEBUG_WITH_TYPE("layout", {
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}