Shankar Easwaran | 2bc2492 | 2013-10-29 05:12:14 +0000 | [diff] [blame] | 1 | //===--Passes/LayoutPass.cpp - Layout atoms -------------------------------===// |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 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 | //===----------------------------------------------------------------------===// |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 9 | |
Michael J. Spencer | 7f09a3d | 2013-02-26 01:35:30 +0000 | [diff] [blame] | 10 | #define DEBUG_TYPE "LayoutPass" |
| 11 | |
Rui Ueyama | 37c43e9f | 2013-12-08 03:12:08 +0000 | [diff] [blame] | 12 | #include <algorithm> |
Rui Ueyama | a6b71ca | 2013-06-07 20:18:39 +0000 | [diff] [blame] | 13 | #include <set> |
| 14 | |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 15 | #include "lld/Passes/LayoutPass.h" |
Michael J. Spencer | d4eb47c | 2013-04-06 00:56:40 +0000 | [diff] [blame] | 16 | #include "lld/Core/Instrumentation.h" |
Rui Ueyama | a6b71ca | 2013-06-07 20:18:39 +0000 | [diff] [blame] | 17 | |
| 18 | #include "llvm/ADT/Twine.h" |
Michael J. Spencer | 7f09a3d | 2013-02-26 01:35:30 +0000 | [diff] [blame] | 19 | #include "llvm/Support/Debug.h" |
| 20 | |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 21 | using namespace lld; |
| 22 | |
Rui Ueyama | 5af4622 | 2013-12-08 03:24:09 +0000 | [diff] [blame] | 23 | static bool compareAtoms(const LayoutPass::SortKey &, |
| 24 | const LayoutPass::SortKey &); |
| 25 | |
Rui Ueyama | 2994f6f | 2013-12-08 03:37:58 +0000 | [diff] [blame] | 26 | #ifndef NDEBUG |
Rui Ueyama | 6a607b6 | 2013-10-18 02:56:31 +0000 | [diff] [blame] | 27 | // Return "reason (leftval, rightval)" |
Rui Ueyama | 5af4622 | 2013-12-08 03:24:09 +0000 | [diff] [blame] | 28 | static std::string formatReason(StringRef reason, int leftVal, int rightVal) { |
Rui Ueyama | 6a607b6 | 2013-10-18 02:56:31 +0000 | [diff] [blame] | 29 | Twine msg = |
| 30 | Twine(reason) + " (" + Twine(leftVal) + ", " + Twine(rightVal) + ")"; |
Rui Ueyama | c74157c | 2013-11-01 20:40:33 +0000 | [diff] [blame] | 31 | return msg.str(); |
Rui Ueyama | 6a607b6 | 2013-10-18 02:56:31 +0000 | [diff] [blame] | 32 | } |
Rui Ueyama | 46bf828 | 2013-10-19 03:18:18 +0000 | [diff] [blame] | 33 | |
| 34 | // Less-than relationship of two atoms must be transitive, which is, if a < b |
| 35 | // and b < c, a < c must be true. This function checks the transitivity by |
| 36 | // checking the sort results. |
Rui Ueyama | 5af4622 | 2013-12-08 03:24:09 +0000 | [diff] [blame] | 37 | static void checkTransitivity(std::vector<LayoutPass::SortKey> &vec) { |
Rui Ueyama | 37c43e9f | 2013-12-08 03:12:08 +0000 | [diff] [blame] | 38 | for (auto i = vec.begin(), e = vec.end(); (i + 1) != e; ++i) { |
| 39 | for (auto j = i + 1; j != e; ++j) { |
| 40 | assert(compareAtoms(*i, *j)); |
| 41 | assert(!compareAtoms(*j, *i)); |
Rui Ueyama | 46bf828 | 2013-10-19 03:18:18 +0000 | [diff] [blame] | 42 | } |
| 43 | } |
Rui Ueyama | 6a607b6 | 2013-10-18 02:56:31 +0000 | [diff] [blame] | 44 | } |
Rui Ueyama | a930d12 | 2013-12-09 00:37:19 +0000 | [diff] [blame] | 45 | |
| 46 | // Helper functions to check follow-on graph. |
| 47 | typedef llvm::DenseMap<const DefinedAtom *, const DefinedAtom *> AtomToAtomT; |
| 48 | |
| 49 | static std::string atomToDebugString(const Atom *atom) { |
| 50 | const DefinedAtom *definedAtom = dyn_cast<DefinedAtom>(atom); |
| 51 | std::string str; |
| 52 | llvm::raw_string_ostream s(str); |
| 53 | if (definedAtom->name().empty()) |
| 54 | s << "<anonymous " << definedAtom << ">"; |
| 55 | else |
| 56 | s << definedAtom->name(); |
| 57 | s << " in "; |
| 58 | if (definedAtom->customSectionName().empty()) |
| 59 | s << "<anonymous>"; |
| 60 | else |
| 61 | s << definedAtom->customSectionName(); |
| 62 | s.flush(); |
| 63 | return str; |
| 64 | } |
| 65 | |
Nico Rieck | b9d84f4 | 2014-02-24 21:14:37 +0000 | [diff] [blame^] | 66 | static void showCycleDetectedError(const Registry ®istry, |
| 67 | AtomToAtomT &followOnNexts, |
Rui Ueyama | a930d12 | 2013-12-09 00:37:19 +0000 | [diff] [blame] | 68 | const DefinedAtom *atom) { |
| 69 | const DefinedAtom *start = atom; |
| 70 | llvm::dbgs() << "There's a cycle in a follow-on chain!\n"; |
| 71 | do { |
| 72 | llvm::dbgs() << " " << atomToDebugString(atom) << "\n"; |
| 73 | for (const Reference *ref : *atom) { |
Nico Rieck | b9d84f4 | 2014-02-24 21:14:37 +0000 | [diff] [blame^] | 74 | StringRef kindValStr; |
| 75 | if (!registry.referenceKindToString(ref->kindNamespace(), ref->kindArch(), |
| 76 | ref->kindValue(), kindValStr)) { |
| 77 | kindValStr = "<unknown>"; |
| 78 | } |
| 79 | llvm::dbgs() << " " << kindValStr |
| 80 | << ": " << atomToDebugString(ref->target()) << "\n"; |
Rui Ueyama | a930d12 | 2013-12-09 00:37:19 +0000 | [diff] [blame] | 81 | } |
| 82 | atom = followOnNexts[atom]; |
| 83 | } while (atom != start); |
| 84 | llvm::report_fatal_error("Cycle detected"); |
| 85 | } |
| 86 | |
| 87 | /// Exit if there's a cycle in a followon chain reachable from the |
| 88 | /// given root atom. Uses the tortoise and hare algorithm to detect a |
| 89 | /// cycle. |
Nico Rieck | b9d84f4 | 2014-02-24 21:14:37 +0000 | [diff] [blame^] | 90 | static void checkNoCycleInFollowonChain(const Registry ®istry, |
| 91 | AtomToAtomT &followOnNexts, |
Rui Ueyama | a930d12 | 2013-12-09 00:37:19 +0000 | [diff] [blame] | 92 | const DefinedAtom *root) { |
| 93 | const DefinedAtom *tortoise = root; |
| 94 | const DefinedAtom *hare = followOnNexts[root]; |
| 95 | while (true) { |
| 96 | if (!tortoise || !hare) |
| 97 | return; |
| 98 | if (tortoise == hare) |
Nico Rieck | b9d84f4 | 2014-02-24 21:14:37 +0000 | [diff] [blame^] | 99 | showCycleDetectedError(registry, followOnNexts, tortoise); |
Rui Ueyama | a930d12 | 2013-12-09 00:37:19 +0000 | [diff] [blame] | 100 | tortoise = followOnNexts[tortoise]; |
| 101 | hare = followOnNexts[followOnNexts[hare]]; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | static void checkReachabilityFromRoot(AtomToAtomT &followOnRoots, |
| 106 | const DefinedAtom *atom) { |
| 107 | if (!atom) return; |
| 108 | auto i = followOnRoots.find(atom); |
| 109 | if (i == followOnRoots.end()) { |
| 110 | Twine msg(Twine("Atom <") + atomToDebugString(atom) |
| 111 | + "> has no follow-on root!"); |
| 112 | llvm_unreachable(msg.str().c_str()); |
| 113 | } |
| 114 | const DefinedAtom *ap = i->second; |
| 115 | while (true) { |
| 116 | const DefinedAtom *next = followOnRoots[ap]; |
| 117 | if (!next) { |
| 118 | Twine msg(Twine("Atom <" + atomToDebugString(atom) |
| 119 | + "> is not reachable from its root!")); |
| 120 | llvm_unreachable(msg.str().c_str()); |
| 121 | } |
| 122 | if (next == ap) |
| 123 | return; |
| 124 | ap = next; |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | static void printDefinedAtoms(const MutableFile::DefinedAtomRange &atomRange) { |
| 129 | for (const DefinedAtom *atom : atomRange) { |
| 130 | llvm::dbgs() << " file=" << atom->file().path() |
| 131 | << ", name=" << atom->name() |
| 132 | << ", size=" << atom->size() |
| 133 | << ", type=" << atom->contentType() |
| 134 | << ", ordinal=" << atom->ordinal() |
| 135 | << "\n"; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | /// Verify that the followon chain is sane. Should not be called in |
| 140 | /// release binary. |
| 141 | void LayoutPass::checkFollowonChain(MutableFile::DefinedAtomRange &range) { |
| 142 | ScopedTask task(getDefaultDomain(), "LayoutPass::checkFollowonChain"); |
| 143 | |
| 144 | // Verify that there's no cycle in follow-on chain. |
| 145 | std::set<const DefinedAtom *> roots; |
| 146 | for (const auto &ai : _followOnRoots) |
| 147 | roots.insert(ai.second); |
| 148 | for (const DefinedAtom *root : roots) |
Nico Rieck | b9d84f4 | 2014-02-24 21:14:37 +0000 | [diff] [blame^] | 149 | checkNoCycleInFollowonChain(_registry, _followOnNexts, root); |
Rui Ueyama | a930d12 | 2013-12-09 00:37:19 +0000 | [diff] [blame] | 150 | |
| 151 | // Verify that all the atoms in followOnNexts have references to |
| 152 | // their roots. |
| 153 | for (const auto &ai : _followOnNexts) { |
| 154 | checkReachabilityFromRoot(_followOnRoots, ai.first); |
| 155 | checkReachabilityFromRoot(_followOnRoots, ai.second); |
| 156 | } |
| 157 | } |
Rui Ueyama | 2994f6f | 2013-12-08 03:37:58 +0000 | [diff] [blame] | 158 | #endif // #ifndef NDEBUG |
Rui Ueyama | 37c43e9f | 2013-12-08 03:12:08 +0000 | [diff] [blame] | 159 | |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 160 | /// The function compares atoms by sorting atoms in the following order |
Shankar Easwaran | d6d1b52 | 2013-09-12 15:59:34 +0000 | [diff] [blame] | 161 | /// a) Sorts atoms by Section position preference |
| 162 | /// b) Sorts atoms by their ordinal overrides |
| 163 | /// (layout-after/layout-before/ingroup) |
| 164 | /// c) Sorts atoms by their permissions |
| 165 | /// d) Sorts atoms by their content |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 166 | /// e) Sorts atoms on how they appear using File Ordinality |
| 167 | /// f) Sorts atoms on how they appear within the File |
Rui Ueyama | 5af4622 | 2013-12-08 03:24:09 +0000 | [diff] [blame] | 168 | static bool compareAtomsSub(const LayoutPass::SortKey &lc, |
| 169 | const LayoutPass::SortKey &rc, |
| 170 | std::string &reason) { |
Rui Ueyama | 37c43e9f | 2013-12-08 03:12:08 +0000 | [diff] [blame] | 171 | const DefinedAtom *left = lc._atom; |
| 172 | const DefinedAtom *right = rc._atom; |
Rui Ueyama | 6a607b6 | 2013-10-18 02:56:31 +0000 | [diff] [blame] | 173 | if (left == right) { |
| 174 | reason = "same"; |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 175 | return false; |
Rui Ueyama | 6a607b6 | 2013-10-18 02:56:31 +0000 | [diff] [blame] | 176 | } |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 177 | |
Shankar Easwaran | d8da989 | 2013-05-22 17:41:04 +0000 | [diff] [blame] | 178 | // Sort by section position preference. |
| 179 | DefinedAtom::SectionPosition leftPos = left->sectionPosition(); |
| 180 | DefinedAtom::SectionPosition rightPos = right->sectionPosition(); |
| 181 | |
Shankar Easwaran | d8da989 | 2013-05-22 17:41:04 +0000 | [diff] [blame] | 182 | bool leftSpecialPos = (leftPos != DefinedAtom::sectionPositionAny); |
| 183 | bool rightSpecialPos = (rightPos != DefinedAtom::sectionPositionAny); |
| 184 | if (leftSpecialPos || rightSpecialPos) { |
Rui Ueyama | 6a607b6 | 2013-10-18 02:56:31 +0000 | [diff] [blame] | 185 | if (leftPos != rightPos) { |
| 186 | DEBUG(reason = formatReason("sectionPos", (int)leftPos, (int)rightPos)); |
Shankar Easwaran | d8da989 | 2013-05-22 17:41:04 +0000 | [diff] [blame] | 187 | return leftPos < rightPos; |
Rui Ueyama | 6a607b6 | 2013-10-18 02:56:31 +0000 | [diff] [blame] | 188 | } |
Shankar Easwaran | d8da989 | 2013-05-22 17:41:04 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Rui Ueyama | 46bf828 | 2013-10-19 03:18:18 +0000 | [diff] [blame] | 191 | // Find the root of the chain if it is a part of a follow-on chain. |
Rui Ueyama | 37c43e9f | 2013-12-08 03:12:08 +0000 | [diff] [blame] | 192 | const DefinedAtom *leftRoot = lc._root; |
| 193 | const DefinedAtom *rightRoot = rc._root; |
Shankar Easwaran | f1b341c | 2013-09-12 15:43:09 +0000 | [diff] [blame] | 194 | |
| 195 | // Sort atoms by their ordinal overrides only if they fall in the same |
| 196 | // chain. |
Rui Ueyama | 37c43e9f | 2013-12-08 03:12:08 +0000 | [diff] [blame] | 197 | if (leftRoot == rightRoot) { |
| 198 | DEBUG(reason = formatReason("override", lc._override, rc._override)); |
| 199 | return lc._override < rc._override; |
Shankar Easwaran | 3c5d2c8 | 2013-05-10 16:44:02 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 202 | // Sort same permissions together. |
Rui Ueyama | 46bf828 | 2013-10-19 03:18:18 +0000 | [diff] [blame] | 203 | DefinedAtom::ContentPermissions leftPerms = leftRoot->permissions(); |
| 204 | DefinedAtom::ContentPermissions rightPerms = rightRoot->permissions(); |
Shankar Easwaran | 8c25685 | 2013-03-13 04:05:38 +0000 | [diff] [blame] | 205 | |
Rui Ueyama | 6a607b6 | 2013-10-18 02:56:31 +0000 | [diff] [blame] | 206 | if (leftPerms != rightPerms) { |
| 207 | DEBUG(reason = |
| 208 | formatReason("contentPerms", (int)leftPerms, (int)rightPerms)); |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 209 | return leftPerms < rightPerms; |
Rui Ueyama | 6a607b6 | 2013-10-18 02:56:31 +0000 | [diff] [blame] | 210 | } |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 211 | |
| 212 | // Sort same content types together. |
Rui Ueyama | 46bf828 | 2013-10-19 03:18:18 +0000 | [diff] [blame] | 213 | DefinedAtom::ContentType leftType = leftRoot->contentType(); |
| 214 | DefinedAtom::ContentType rightType = rightRoot->contentType(); |
Shankar Easwaran | 8c25685 | 2013-03-13 04:05:38 +0000 | [diff] [blame] | 215 | |
Rui Ueyama | 6a607b6 | 2013-10-18 02:56:31 +0000 | [diff] [blame] | 216 | if (leftType != rightType) { |
| 217 | DEBUG(reason = formatReason("contentType", (int)leftType, (int)rightType)); |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 218 | return leftType < rightType; |
Rui Ueyama | 6a607b6 | 2013-10-18 02:56:31 +0000 | [diff] [blame] | 219 | } |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 220 | |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 221 | // Sort by .o order. |
Rui Ueyama | 46bf828 | 2013-10-19 03:18:18 +0000 | [diff] [blame] | 222 | const File *leftFile = &leftRoot->file(); |
| 223 | const File *rightFile = &rightRoot->file(); |
Shankar Easwaran | 8c25685 | 2013-03-13 04:05:38 +0000 | [diff] [blame] | 224 | |
Rui Ueyama | 6a607b6 | 2013-10-18 02:56:31 +0000 | [diff] [blame] | 225 | if (leftFile != rightFile) { |
| 226 | DEBUG(reason = formatReason(".o order", (int)leftFile->ordinal(), |
| 227 | (int)rightFile->ordinal())); |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 228 | return leftFile->ordinal() < rightFile->ordinal(); |
Rui Ueyama | 6a607b6 | 2013-10-18 02:56:31 +0000 | [diff] [blame] | 229 | } |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 230 | |
| 231 | // Sort by atom order with .o file. |
Rui Ueyama | 46bf828 | 2013-10-19 03:18:18 +0000 | [diff] [blame] | 232 | uint64_t leftOrdinal = leftRoot->ordinal(); |
| 233 | uint64_t rightOrdinal = rightRoot->ordinal(); |
Shankar Easwaran | 8c25685 | 2013-03-13 04:05:38 +0000 | [diff] [blame] | 234 | |
Rui Ueyama | 6a607b6 | 2013-10-18 02:56:31 +0000 | [diff] [blame] | 235 | if (leftOrdinal != rightOrdinal) { |
Rui Ueyama | 46bf828 | 2013-10-19 03:18:18 +0000 | [diff] [blame] | 236 | DEBUG(reason = formatReason("ordinal", (int)leftRoot->ordinal(), |
| 237 | (int)rightRoot->ordinal())); |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 238 | return leftOrdinal < rightOrdinal; |
Rui Ueyama | 6a607b6 | 2013-10-18 02:56:31 +0000 | [diff] [blame] | 239 | } |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 240 | |
Rui Ueyama | cd48075 | 2013-11-27 01:33:42 +0000 | [diff] [blame] | 241 | llvm::errs() << "Unordered: <" << left->name() << "> <" |
| 242 | << right->name() << ">\n"; |
Shankar Easwaran | bcf3656 | 2013-10-11 01:50:04 +0000 | [diff] [blame] | 243 | llvm_unreachable("Atoms with Same Ordinal!"); |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 244 | } |
| 245 | |
Rui Ueyama | 5af4622 | 2013-12-08 03:24:09 +0000 | [diff] [blame] | 246 | static bool compareAtoms(const LayoutPass::SortKey &lc, |
| 247 | const LayoutPass::SortKey &rc) { |
Rui Ueyama | 6a607b6 | 2013-10-18 02:56:31 +0000 | [diff] [blame] | 248 | std::string reason; |
Rui Ueyama | 37c43e9f | 2013-12-08 03:12:08 +0000 | [diff] [blame] | 249 | bool result = compareAtomsSub(lc, rc, reason); |
Rui Ueyama | 6a607b6 | 2013-10-18 02:56:31 +0000 | [diff] [blame] | 250 | DEBUG({ |
Rui Ueyama | 4050b20 | 2013-10-18 03:18:52 +0000 | [diff] [blame] | 251 | StringRef comp = result ? "<" : ">="; |
Rui Ueyama | 37c43e9f | 2013-12-08 03:12:08 +0000 | [diff] [blame] | 252 | llvm::dbgs() << "Layout: '" << lc._atom->name() << "' " << comp << " '" |
| 253 | << rc._atom->name() << "' (" << reason << ")\n"; |
Rui Ueyama | 6a607b6 | 2013-10-18 02:56:31 +0000 | [diff] [blame] | 254 | }); |
| 255 | return result; |
| 256 | } |
| 257 | |
Nico Rieck | b9d84f4 | 2014-02-24 21:14:37 +0000 | [diff] [blame^] | 258 | LayoutPass::LayoutPass(const Registry ®istry) : _registry(registry) {} |
| 259 | |
Rui Ueyama | ca8ca55 | 2013-05-14 00:41:52 +0000 | [diff] [blame] | 260 | // Returns the atom immediately followed by the given atom in the followon |
| 261 | // chain. |
| 262 | const DefinedAtom *LayoutPass::findAtomFollowedBy( |
| 263 | const DefinedAtom *targetAtom) { |
| 264 | // Start from the beginning of the chain and follow the chain until |
| 265 | // we find the targetChain. |
| 266 | const DefinedAtom *atom = _followOnRoots[targetAtom]; |
| 267 | while (true) { |
| 268 | const DefinedAtom *prevAtom = atom; |
| 269 | AtomToAtomT::iterator targetFollowOnAtomsIter = _followOnNexts.find(atom); |
| 270 | // The target atom must be in the chain of its root. |
| 271 | assert(targetFollowOnAtomsIter != _followOnNexts.end()); |
| 272 | atom = targetFollowOnAtomsIter->second; |
| 273 | if (atom == targetAtom) |
| 274 | return prevAtom; |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | // Check if all the atoms followed by the given target atom are of size zero. |
| 279 | // When this method is called, an atom being added is not of size zero and |
| 280 | // will be added to the head of the followon chain. All the atoms between the |
| 281 | // atom and the targetAtom (specified by layout-after) need to be of size zero |
| 282 | // in this case. Otherwise the desired layout is impossible. |
| 283 | bool LayoutPass::checkAllPrevAtomsZeroSize(const DefinedAtom *targetAtom) { |
| 284 | const DefinedAtom *atom = _followOnRoots[targetAtom]; |
| 285 | while (true) { |
Rui Ueyama | ca8ca55 | 2013-05-14 00:41:52 +0000 | [diff] [blame] | 286 | if (atom == targetAtom) |
| 287 | return true; |
Rui Ueyama | 0196d106 | 2013-05-14 16:53:59 +0000 | [diff] [blame] | 288 | if (atom->size() != 0) |
Rui Ueyama | ca8ca55 | 2013-05-14 00:41:52 +0000 | [diff] [blame] | 289 | // TODO: print warning that an impossible layout is being desired by the |
| 290 | // user. |
| 291 | return false; |
Rui Ueyama | 5ec6d1a | 2013-05-14 01:51:56 +0000 | [diff] [blame] | 292 | AtomToAtomT::iterator targetFollowOnAtomsIter = _followOnNexts.find(atom); |
| 293 | // The target atom must be in the chain of its root. |
| 294 | assert(targetFollowOnAtomsIter != _followOnNexts.end()); |
| 295 | atom = targetFollowOnAtomsIter->second; |
Rui Ueyama | ca8ca55 | 2013-05-14 00:41:52 +0000 | [diff] [blame] | 296 | } |
| 297 | } |
| 298 | |
| 299 | // Set the root of all atoms in targetAtom's chain to the given root. |
| 300 | void LayoutPass::setChainRoot(const DefinedAtom *targetAtom, |
| 301 | const DefinedAtom *root) { |
| 302 | // Walk through the followon chain and override each node's root. |
| 303 | while (true) { |
| 304 | _followOnRoots[targetAtom] = root; |
| 305 | AtomToAtomT::iterator targetFollowOnAtomsIter = |
| 306 | _followOnNexts.find(targetAtom); |
| 307 | if (targetFollowOnAtomsIter == _followOnNexts.end()) |
| 308 | return; |
| 309 | targetAtom = targetFollowOnAtomsIter->second; |
| 310 | } |
| 311 | } |
| 312 | |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 313 | /// This pass builds the followon tables described by two DenseMaps |
| 314 | /// followOnRoots and followonNexts. |
| 315 | /// The followOnRoots map contains a mapping of a DefinedAtom to its root |
| 316 | /// The followOnNexts map contains a mapping of what DefinedAtom follows the |
| 317 | /// current Atom |
| 318 | /// The algorithm follows a very simple approach |
| 319 | /// a) If the atom is first seen, then make that as the root atom |
Shankar Easwaran | 8962feb | 2013-03-14 16:09:49 +0000 | [diff] [blame] | 320 | /// b) The targetAtom which this Atom contains, has the root thats set to the |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 321 | /// root of the current atom |
| 322 | /// c) If the targetAtom is part of a different tree and the root of the |
| 323 | /// targetAtom is itself, Chain all the atoms that are contained in the tree |
| 324 | /// to the current Tree |
| 325 | /// d) If the targetAtom is part of a different chain and the root of the |
| 326 | /// targetAtom until the targetAtom has all atoms of size 0, then chain the |
| 327 | /// targetAtoms and its tree to the current chain |
| 328 | void LayoutPass::buildFollowOnTable(MutableFile::DefinedAtomRange &range) { |
Michael J. Spencer | d4eb47c | 2013-04-06 00:56:40 +0000 | [diff] [blame] | 329 | ScopedTask task(getDefaultDomain(), "LayoutPass::buildFollowOnTable"); |
Rui Ueyama | ca8ca55 | 2013-05-14 00:41:52 +0000 | [diff] [blame] | 330 | // Set the initial size of the followon and the followonNext hash to the |
| 331 | // number of atoms that we have. |
Shankar Easwaran | 45a5f93 | 2013-04-29 03:27:57 +0000 | [diff] [blame] | 332 | _followOnRoots.resize(range.size()); |
| 333 | _followOnNexts.resize(range.size()); |
Rui Ueyama | 0196d106 | 2013-05-14 16:53:59 +0000 | [diff] [blame] | 334 | for (const DefinedAtom *ai : range) { |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 335 | for (const Reference *r : *ai) { |
Nick Kledzik | e555277 | 2013-12-19 21:58:00 +0000 | [diff] [blame] | 336 | if (r->kindNamespace() != lld::Reference::KindNamespace::all) |
| 337 | continue; |
| 338 | if (r->kindValue() != lld::Reference::kindLayoutAfter) |
Rui Ueyama | ca8ca55 | 2013-05-14 00:41:52 +0000 | [diff] [blame] | 339 | continue; |
Rui Ueyama | c1800be | 2013-11-05 01:37:40 +0000 | [diff] [blame] | 340 | const DefinedAtom *targetAtom = dyn_cast<DefinedAtom>(r->target()); |
Rui Ueyama | ca8ca55 | 2013-05-14 00:41:52 +0000 | [diff] [blame] | 341 | _followOnNexts[ai] = targetAtom; |
| 342 | |
Alp Toker | 2259376 | 2013-12-02 01:28:14 +0000 | [diff] [blame] | 343 | // If we find a followon for the first time, let's make that atom as the |
Rui Ueyama | ca8ca55 | 2013-05-14 00:41:52 +0000 | [diff] [blame] | 344 | // root atom. |
| 345 | if (_followOnRoots.count(ai) == 0) |
| 346 | _followOnRoots[ai] = ai; |
| 347 | |
| 348 | auto iter = _followOnRoots.find(targetAtom); |
| 349 | if (iter == _followOnRoots.end()) { |
Alp Toker | 2259376 | 2013-12-02 01:28:14 +0000 | [diff] [blame] | 350 | // If the targetAtom is not a root of any chain, let's make the root of |
Rui Ueyama | ca8ca55 | 2013-05-14 00:41:52 +0000 | [diff] [blame] | 351 | // the targetAtom to the root of the current chain. |
| 352 | _followOnRoots[targetAtom] = _followOnRoots[ai]; |
| 353 | } else if (iter->second == targetAtom) { |
| 354 | // If the targetAtom is the root of a chain, the chain becomes part of |
| 355 | // the current chain. Rewrite the subchain's root to the current |
| 356 | // chain's root. |
| 357 | setChainRoot(targetAtom, _followOnRoots[ai]); |
| 358 | } else { |
| 359 | // The targetAtom is already a part of a chain. If the current atom is |
| 360 | // of size zero, we can insert it in the middle of the chain just |
| 361 | // before the target atom, while not breaking other atom's followon |
| 362 | // relationships. If it's not, we can only insert the current atom at |
| 363 | // the beginning of the chain. All the atoms followed by the target |
| 364 | // atom must be of size zero in that case to satisfy the followon |
| 365 | // relationships. |
Rui Ueyama | 0196d106 | 2013-05-14 16:53:59 +0000 | [diff] [blame] | 366 | size_t currentAtomSize = ai->size(); |
Rui Ueyama | ca8ca55 | 2013-05-14 00:41:52 +0000 | [diff] [blame] | 367 | if (currentAtomSize == 0) { |
| 368 | const DefinedAtom *targetPrevAtom = findAtomFollowedBy(targetAtom); |
| 369 | _followOnNexts[targetPrevAtom] = ai; |
| 370 | _followOnRoots[ai] = _followOnRoots[targetPrevAtom]; |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 371 | } else { |
Rui Ueyama | ca8ca55 | 2013-05-14 00:41:52 +0000 | [diff] [blame] | 372 | if (!checkAllPrevAtomsZeroSize(targetAtom)) |
| 373 | break; |
| 374 | _followOnNexts[ai] = _followOnRoots[targetAtom]; |
| 375 | setChainRoot(_followOnRoots[targetAtom], _followOnRoots[ai]); |
| 376 | } |
| 377 | } |
| 378 | } |
| 379 | } |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | /// This pass builds the followon tables using InGroup relationships |
| 383 | /// The algorithm follows a very simple approach |
| 384 | /// a) If the rootAtom is not part of any root, create a new root with the |
| 385 | /// as the head |
| 386 | /// b) If the current Atom root is not found, then make the current atoms root |
| 387 | /// point to the rootAtom |
| 388 | /// c) If the root of the current Atom is itself a root of some other tree |
| 389 | /// make all the atoms in the chain point to the ingroup reference |
| 390 | /// d) Check to see if the current atom is part of the chain from the rootAtom |
| 391 | /// if not add the atom to the chain, so that the current atom is part of the |
| 392 | /// the chain where the rootAtom is in |
| 393 | void LayoutPass::buildInGroupTable(MutableFile::DefinedAtomRange &range) { |
Michael J. Spencer | d4eb47c | 2013-04-06 00:56:40 +0000 | [diff] [blame] | 394 | ScopedTask task(getDefaultDomain(), "LayoutPass::buildInGroupTable"); |
Shankar Easwaran | 8962feb | 2013-03-14 16:09:49 +0000 | [diff] [blame] | 395 | // This table would convert precededby references to follow on |
| 396 | // references so that we have only one table |
Rui Ueyama | 0196d106 | 2013-05-14 16:53:59 +0000 | [diff] [blame] | 397 | for (const DefinedAtom *ai : range) { |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 398 | for (const Reference *r : *ai) { |
Nick Kledzik | e555277 | 2013-12-19 21:58:00 +0000 | [diff] [blame] | 399 | if (r->kindNamespace() != lld::Reference::KindNamespace::all) |
| 400 | continue; |
| 401 | if (r->kindValue() == lld::Reference::kindInGroup) { |
Rui Ueyama | c1800be | 2013-11-05 01:37:40 +0000 | [diff] [blame] | 402 | const DefinedAtom *rootAtom = dyn_cast<DefinedAtom>(r->target()); |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 403 | // If the root atom is not part of any root |
Shankar Easwaran | 8962feb | 2013-03-14 16:09:49 +0000 | [diff] [blame] | 404 | // create a new root |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 405 | if (_followOnRoots.count(rootAtom) == 0) { |
| 406 | _followOnRoots[rootAtom] = rootAtom; |
| 407 | } |
Shankar Easwaran | 8962feb | 2013-03-14 16:09:49 +0000 | [diff] [blame] | 408 | // If the current Atom has not been seen yet and there is no root |
| 409 | // that has been set, set the root of the atom to the targetAtom |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 410 | // as the targetAtom points to the ingroup root |
| 411 | auto iter = _followOnRoots.find(ai); |
| 412 | if (iter == _followOnRoots.end()) { |
| 413 | _followOnRoots[ai] = rootAtom; |
Rui Ueyama | ca8ca55 | 2013-05-14 00:41:52 +0000 | [diff] [blame] | 414 | } else if (iter->second == ai) { |
| 415 | if (iter->second != rootAtom) |
| 416 | setChainRoot(iter->second, rootAtom); |
| 417 | } else { |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 418 | // TODO : Flag an error that the root of the tree |
| 419 | // is different, Here is an example |
| 420 | // Say there are atoms |
| 421 | // chain 1 : a->b->c |
| 422 | // chain 2 : d->e->f |
| 423 | // and e,f have their ingroup reference as a |
| 424 | // this could happen only if the root of e,f that is d |
| 425 | // has root as 'a' |
| 426 | continue; |
| 427 | } |
| 428 | |
| 429 | // Check if the current atom is part of the chain |
| 430 | bool isAtomInChain = false; |
| 431 | const DefinedAtom *lastAtom = rootAtom; |
Rui Ueyama | c53b3b0 | 2013-12-10 06:19:09 +0000 | [diff] [blame] | 432 | for (;;) { |
Shankar Easwaran | 8962feb | 2013-03-14 16:09:49 +0000 | [diff] [blame] | 433 | AtomToAtomT::iterator followOnAtomsIter = |
Rui Ueyama | c53b3b0 | 2013-12-10 06:19:09 +0000 | [diff] [blame] | 434 | _followOnNexts.find(lastAtom); |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 435 | if (followOnAtomsIter != _followOnNexts.end()) { |
| 436 | lastAtom = followOnAtomsIter->second; |
Rui Ueyama | c53b3b0 | 2013-12-10 06:19:09 +0000 | [diff] [blame] | 437 | if (lastAtom != ai) |
| 438 | continue; |
| 439 | isAtomInChain = true; |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 440 | } |
Rui Ueyama | c53b3b0 | 2013-12-10 06:19:09 +0000 | [diff] [blame] | 441 | break; |
| 442 | } |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 443 | |
Shankar Easwaran | 8962feb | 2013-03-14 16:09:49 +0000 | [diff] [blame] | 444 | if (!isAtomInChain) |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 445 | _followOnNexts[lastAtom] = ai; |
| 446 | } |
| 447 | } |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | /// This pass builds the followon tables using Preceded By relationships |
| 452 | /// The algorithm follows a very simple approach |
| 453 | /// a) If the targetAtom is not part of any root and the current atom is not |
Shankar Easwaran | 8962feb | 2013-03-14 16:09:49 +0000 | [diff] [blame] | 454 | /// part of any root, create a chain with the current atom as root and |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 455 | /// the targetAtom as following the current atom |
Shankar Easwaran | 8962feb | 2013-03-14 16:09:49 +0000 | [diff] [blame] | 456 | /// b) Chain the targetAtom to the current Atom if the targetAtom is not part |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 457 | /// of any chain and the currentAtom has no followOn's |
| 458 | /// c) If the targetAtom is part of a different tree and the root of the |
| 459 | /// targetAtom is itself, and if the current atom is not part of any root |
Shankar Easwaran | 8962feb | 2013-03-14 16:09:49 +0000 | [diff] [blame] | 460 | /// chain all the atoms together |
| 461 | /// d) If the current atom has no followon and the root of the targetAtom is |
| 462 | /// not equal to the root of the current atom(the targetAtom is not in the |
| 463 | /// same chain), chain all the atoms that are lead by the targetAtom into |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 464 | /// the current chain |
| 465 | void LayoutPass::buildPrecededByTable(MutableFile::DefinedAtomRange &range) { |
Michael J. Spencer | d4eb47c | 2013-04-06 00:56:40 +0000 | [diff] [blame] | 466 | ScopedTask task(getDefaultDomain(), "LayoutPass::buildPrecededByTable"); |
Shankar Easwaran | 8962feb | 2013-03-14 16:09:49 +0000 | [diff] [blame] | 467 | // This table would convert precededby references to follow on |
| 468 | // references so that we have only one table |
Rui Ueyama | 0196d106 | 2013-05-14 16:53:59 +0000 | [diff] [blame] | 469 | for (const DefinedAtom *ai : range) { |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 470 | for (const Reference *r : *ai) { |
Nick Kledzik | e555277 | 2013-12-19 21:58:00 +0000 | [diff] [blame] | 471 | if (r->kindNamespace() != lld::Reference::KindNamespace::all) |
| 472 | continue; |
| 473 | if (r->kindValue() == lld::Reference::kindLayoutBefore) { |
Rui Ueyama | c1800be | 2013-11-05 01:37:40 +0000 | [diff] [blame] | 474 | const DefinedAtom *targetAtom = dyn_cast<DefinedAtom>(r->target()); |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 475 | // Is the targetAtom not chained |
| 476 | if (_followOnRoots.count(targetAtom) == 0) { |
| 477 | // Is the current atom not part of any root ? |
| 478 | if (_followOnRoots.count(ai) == 0) { |
| 479 | _followOnRoots[ai] = ai; |
| 480 | _followOnNexts[ai] = targetAtom; |
| 481 | _followOnRoots[targetAtom] = _followOnRoots[ai]; |
| 482 | } else if (_followOnNexts.count(ai) == 0) { |
| 483 | // Chain the targetAtom to the current Atom |
| 484 | // if the currentAtom has no followon references |
| 485 | _followOnNexts[ai] = targetAtom; |
| 486 | _followOnRoots[targetAtom] = _followOnRoots[ai]; |
| 487 | } |
| 488 | } else if (_followOnRoots.find(targetAtom)->second == targetAtom) { |
| 489 | // Is the targetAtom in chain with the targetAtom as the root ? |
| 490 | bool changeRoots = false; |
| 491 | if (_followOnRoots.count(ai) == 0) { |
| 492 | _followOnRoots[ai] = ai; |
| 493 | _followOnNexts[ai] = targetAtom; |
| 494 | _followOnRoots[targetAtom] = _followOnRoots[ai]; |
| 495 | changeRoots = true; |
| 496 | } else if (_followOnNexts.count(ai) == 0) { |
| 497 | // Chain the targetAtom to the current Atom |
| 498 | // if the currentAtom has no followon references |
| 499 | if (_followOnRoots[ai] != _followOnRoots[targetAtom]) { |
| 500 | _followOnNexts[ai] = targetAtom; |
| 501 | _followOnRoots[targetAtom] = _followOnRoots[ai]; |
| 502 | changeRoots = true; |
| 503 | } |
| 504 | } |
Shankar Easwaran | 8962feb | 2013-03-14 16:09:49 +0000 | [diff] [blame] | 505 | // Change the roots of the targetAtom and its chain to |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 506 | // the current atoms root |
| 507 | if (changeRoots) { |
Rui Ueyama | ca8ca55 | 2013-05-14 00:41:52 +0000 | [diff] [blame] | 508 | setChainRoot(_followOnRoots[targetAtom], _followOnRoots[ai]); |
| 509 | } |
Shankar Easwaran | 8962feb | 2013-03-14 16:09:49 +0000 | [diff] [blame] | 510 | } // Is targetAtom root |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 511 | } // kindLayoutBefore |
Rui Ueyama | ca8ca55 | 2013-05-14 00:41:52 +0000 | [diff] [blame] | 512 | } // Reference |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 513 | } // atom iteration |
Shankar Easwaran | 8962feb | 2013-03-14 16:09:49 +0000 | [diff] [blame] | 514 | } // end function |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 515 | |
| 516 | |
| 517 | /// Build an ordinal override map by traversing the followon chain, and |
Shankar Easwaran | 8962feb | 2013-03-14 16:09:49 +0000 | [diff] [blame] | 518 | /// assigning ordinals to each atom, if the atoms have their ordinals |
| 519 | /// already assigned skip the atom and move to the next. This is the |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 520 | /// main map thats used to sort the atoms while comparing two atoms together |
| 521 | void LayoutPass::buildOrdinalOverrideMap(MutableFile::DefinedAtomRange &range) { |
Michael J. Spencer | d4eb47c | 2013-04-06 00:56:40 +0000 | [diff] [blame] | 522 | ScopedTask task(getDefaultDomain(), "LayoutPass::buildOrdinalOverrideMap"); |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 523 | uint64_t index = 0; |
Rui Ueyama | 0196d106 | 2013-05-14 16:53:59 +0000 | [diff] [blame] | 524 | for (const DefinedAtom *ai : range) { |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 525 | const DefinedAtom *atom = ai; |
Michael J. Spencer | 1ecf890 | 2013-03-12 00:10:00 +0000 | [diff] [blame] | 526 | if (_ordinalOverrideMap.find(atom) != _ordinalOverrideMap.end()) |
| 527 | continue; |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 528 | AtomToAtomT::iterator start = _followOnRoots.find(atom); |
| 529 | if (start != _followOnRoots.end()) { |
| 530 | for (const DefinedAtom *nextAtom = start->second; nextAtom != NULL; |
| 531 | nextAtom = _followOnNexts[nextAtom]) { |
| 532 | AtomToOrdinalT::iterator pos = _ordinalOverrideMap.find(nextAtom); |
Rui Ueyama | c53b3b0 | 2013-12-10 06:19:09 +0000 | [diff] [blame] | 533 | if (pos == _ordinalOverrideMap.end()) |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 534 | _ordinalOverrideMap[nextAtom] = index++; |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 535 | } |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 536 | } |
| 537 | } |
| 538 | } |
| 539 | |
Rui Ueyama | 37c43e9f | 2013-12-08 03:12:08 +0000 | [diff] [blame] | 540 | std::vector<LayoutPass::SortKey> |
| 541 | LayoutPass::decorate(MutableFile::DefinedAtomRange &atomRange) const { |
| 542 | std::vector<SortKey> ret; |
| 543 | for (const DefinedAtom *atom : atomRange) { |
| 544 | auto ri = _followOnRoots.find(atom); |
| 545 | auto oi = _ordinalOverrideMap.find(atom); |
| 546 | const DefinedAtom *root = (ri == _followOnRoots.end()) ? atom : ri->second; |
| 547 | uint64_t override = (oi == _ordinalOverrideMap.end()) ? 0 : oi->second; |
| 548 | ret.push_back(SortKey(atom, root, override)); |
| 549 | } |
| 550 | return ret; |
| 551 | } |
| 552 | |
| 553 | void LayoutPass::undecorate(MutableFile::DefinedAtomRange &atomRange, |
| 554 | std::vector<SortKey> &keys) const { |
| 555 | size_t i = 0; |
| 556 | for (SortKey &k : keys) |
| 557 | atomRange[i++] = k._atom; |
| 558 | } |
| 559 | |
Shankar Easwaran | 8962feb | 2013-03-14 16:09:49 +0000 | [diff] [blame] | 560 | /// Perform the actual pass |
Shankar Easwaran | 2bc2492 | 2013-10-29 05:12:14 +0000 | [diff] [blame] | 561 | void LayoutPass::perform(std::unique_ptr<MutableFile> &mergedFile) { |
Rui Ueyama | 37c43e9f | 2013-12-08 03:12:08 +0000 | [diff] [blame] | 562 | // sort the atoms |
Michael J. Spencer | bd66d04 | 2013-05-28 18:55:39 +0000 | [diff] [blame] | 563 | ScopedTask task(getDefaultDomain(), "LayoutPass"); |
Shankar Easwaran | 2bc2492 | 2013-10-29 05:12:14 +0000 | [diff] [blame] | 564 | MutableFile::DefinedAtomRange atomRange = mergedFile->definedAtoms(); |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 565 | |
| 566 | // Build follow on tables |
| 567 | buildFollowOnTable(atomRange); |
| 568 | |
| 569 | // Build Ingroup reference table |
| 570 | buildInGroupTable(atomRange); |
| 571 | |
| 572 | // Build preceded by tables |
| 573 | buildPrecededByTable(atomRange); |
| 574 | |
Rui Ueyama | a6b71ca | 2013-06-07 20:18:39 +0000 | [diff] [blame] | 575 | // Check the structure of followon graph if running in debug mode. |
| 576 | DEBUG(checkFollowonChain(atomRange)); |
| 577 | |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 578 | // Build override maps |
| 579 | buildOrdinalOverrideMap(atomRange); |
| 580 | |
Rui Ueyama | 9c4f89a | 2013-05-23 01:31:25 +0000 | [diff] [blame] | 581 | DEBUG({ |
Nick Kledzik | f4fa8c0 | 2013-04-04 20:32:18 +0000 | [diff] [blame] | 582 | llvm::dbgs() << "unsorted atoms:\n"; |
Rui Ueyama | a6b71ca | 2013-06-07 20:18:39 +0000 | [diff] [blame] | 583 | printDefinedAtoms(atomRange); |
Nick Kledzik | f4fa8c0 | 2013-04-04 20:32:18 +0000 | [diff] [blame] | 584 | }); |
Shankar Easwaran | 45a5f93 | 2013-04-29 03:27:57 +0000 | [diff] [blame] | 585 | |
Rui Ueyama | 37c43e9f | 2013-12-08 03:12:08 +0000 | [diff] [blame] | 586 | std::vector<LayoutPass::SortKey> vec = decorate(atomRange); |
| 587 | std::sort(vec.begin(), vec.end(), compareAtoms); |
| 588 | DEBUG(checkTransitivity(vec)); |
| 589 | undecorate(atomRange, vec); |
Rui Ueyama | 46bf828 | 2013-10-19 03:18:18 +0000 | [diff] [blame] | 590 | |
Rui Ueyama | 9c4f89a | 2013-05-23 01:31:25 +0000 | [diff] [blame] | 591 | DEBUG({ |
Nick Kledzik | f4fa8c0 | 2013-04-04 20:32:18 +0000 | [diff] [blame] | 592 | llvm::dbgs() << "sorted atoms:\n"; |
Rui Ueyama | a6b71ca | 2013-06-07 20:18:39 +0000 | [diff] [blame] | 593 | printDefinedAtoms(atomRange); |
Nick Kledzik | f4fa8c0 | 2013-04-04 20:32:18 +0000 | [diff] [blame] | 594 | }); |
Shankar Easwaran | 34ab70f | 2013-02-07 20:16:12 +0000 | [diff] [blame] | 595 | } |