Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1 | //===- AsmWriter.cpp - Printing LLVM as an assembly file ------------------===// |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 2 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 7 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 9 | // |
Vlad Tsyrklevich | 1cd3240 | 2018-04-26 17:34:51 +0000 | [diff] [blame] | 10 | // This library implements `print` family of functions in classes like |
| 11 | // Module, Function, Value, etc. In-memory representation of those classes is |
| 12 | // converted to IR strings. |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 13 | // |
Chris Lattner | 02b9399 | 2002-04-12 18:21:53 +0000 | [diff] [blame] | 14 | // Note that these routines must be extremely tolerant of various errors in the |
Chris Lattner | 8f77dae | 2003-05-08 02:44:12 +0000 | [diff] [blame] | 15 | // LLVM code, because it can be used for debugging transformations. |
Chris Lattner | 02b9399 | 2002-04-12 18:21:53 +0000 | [diff] [blame] | 16 | // |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 17 | //===----------------------------------------------------------------------===// |
| 18 | |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/APFloat.h" |
| 20 | #include "llvm/ADT/APInt.h" |
| 21 | #include "llvm/ADT/ArrayRef.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/DenseMap.h" |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/None.h" |
| 24 | #include "llvm/ADT/Optional.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/STLExtras.h" |
Benjamin Kramer | 93920f0 | 2015-03-17 19:53:41 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/SetVector.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/SmallString.h" |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 28 | #include "llvm/ADT/SmallVector.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 29 | #include "llvm/ADT/StringExtras.h" |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 30 | #include "llvm/ADT/StringRef.h" |
| 31 | #include "llvm/ADT/iterator_range.h" |
Zachary Turner | 19ca2b0 | 2017-06-07 03:48:56 +0000 | [diff] [blame] | 32 | #include "llvm/BinaryFormat/Dwarf.h" |
Nico Weber | 0f38c60 | 2018-04-30 14:59:11 +0000 | [diff] [blame] | 33 | #include "llvm/Config/llvm-config.h" |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 34 | #include "llvm/IR/Argument.h" |
Chandler Carruth | bc65a8d | 2014-01-07 12:34:26 +0000 | [diff] [blame] | 35 | #include "llvm/IR/AssemblyAnnotationWriter.h" |
Reid Kleckner | 7dde8e8 | 2017-04-10 23:31:05 +0000 | [diff] [blame] | 36 | #include "llvm/IR/Attributes.h" |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 37 | #include "llvm/IR/BasicBlock.h" |
Chandler Carruth | 03e36d7 | 2014-03-04 11:45:46 +0000 | [diff] [blame] | 38 | #include "llvm/IR/CFG.h" |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 39 | #include "llvm/IR/CallingConv.h" |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 40 | #include "llvm/IR/Comdat.h" |
| 41 | #include "llvm/IR/Constant.h" |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 42 | #include "llvm/IR/Constants.h" |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 43 | #include "llvm/IR/DebugInfoMetadata.h" |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 44 | #include "llvm/IR/DerivedTypes.h" |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 45 | #include "llvm/IR/Function.h" |
| 46 | #include "llvm/IR/GlobalAlias.h" |
| 47 | #include "llvm/IR/GlobalIFunc.h" |
| 48 | #include "llvm/IR/GlobalIndirectSymbol.h" |
| 49 | #include "llvm/IR/GlobalObject.h" |
| 50 | #include "llvm/IR/GlobalValue.h" |
| 51 | #include "llvm/IR/GlobalVariable.h" |
Chandler Carruth | 8a5351f | 2014-01-12 11:10:32 +0000 | [diff] [blame] | 52 | #include "llvm/IR/IRPrintingPasses.h" |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 53 | #include "llvm/IR/InlineAsm.h" |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 54 | #include "llvm/IR/InstrTypes.h" |
| 55 | #include "llvm/IR/Instruction.h" |
| 56 | #include "llvm/IR/Instructions.h" |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 57 | #include "llvm/IR/LLVMContext.h" |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 58 | #include "llvm/IR/Metadata.h" |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 59 | #include "llvm/IR/Module.h" |
Duncan P. N. Exon Smith | 9a61a42 | 2015-06-26 22:04:20 +0000 | [diff] [blame] | 60 | #include "llvm/IR/ModuleSlotTracker.h" |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 61 | #include "llvm/IR/ModuleSummaryIndex.h" |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 62 | #include "llvm/IR/Operator.h" |
Igor Laevsky | a5f2faf | 2015-05-05 13:20:42 +0000 | [diff] [blame] | 63 | #include "llvm/IR/Statepoint.h" |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 64 | #include "llvm/IR/Type.h" |
Chandler Carruth | 4068e1a | 2013-01-07 15:43:51 +0000 | [diff] [blame] | 65 | #include "llvm/IR/TypeFinder.h" |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 66 | #include "llvm/IR/Use.h" |
Benjamin Kramer | 93920f0 | 2015-03-17 19:53:41 +0000 | [diff] [blame] | 67 | #include "llvm/IR/UseListOrder.h" |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 68 | #include "llvm/IR/User.h" |
| 69 | #include "llvm/IR/Value.h" |
| 70 | #include "llvm/Support/AtomicOrdering.h" |
| 71 | #include "llvm/Support/Casting.h" |
| 72 | #include "llvm/Support/Compiler.h" |
David Greene | d865e02 | 2010-01-05 01:29:26 +0000 | [diff] [blame] | 73 | #include "llvm/Support/Debug.h" |
Torok Edwin | ab7c09b | 2009-07-08 18:01:40 +0000 | [diff] [blame] | 74 | #include "llvm/Support/ErrorHandling.h" |
Justin Bogner | d8def4a | 2015-12-04 02:14:34 +0000 | [diff] [blame] | 75 | #include "llvm/Support/Format.h" |
Dan Gohman | 683e922 | 2009-08-12 17:23:50 +0000 | [diff] [blame] | 76 | #include "llvm/Support/FormattedStream.h" |
Benjamin Kramer | 1bfcd1f | 2015-03-23 19:32:43 +0000 | [diff] [blame] | 77 | #include "llvm/Support/raw_ostream.h" |
Chris Lattner | 007377f | 2001-09-07 16:36:04 +0000 | [diff] [blame] | 78 | #include <algorithm> |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 79 | #include <cassert> |
Reid Spencer | 4ad513c | 2007-05-22 19:27:35 +0000 | [diff] [blame] | 80 | #include <cctype> |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 81 | #include <cstddef> |
| 82 | #include <cstdint> |
| 83 | #include <iterator> |
| 84 | #include <memory> |
| 85 | #include <string> |
| 86 | #include <tuple> |
| 87 | #include <utility> |
| 88 | #include <vector> |
| 89 | |
Chris Lattner | 31f8499 | 2003-11-21 20:23:48 +0000 | [diff] [blame] | 90 | using namespace llvm; |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 91 | |
Reid Spencer | edd5d9e | 2005-05-15 16:13:11 +0000 | [diff] [blame] | 92 | // Make virtual table appear in this compilation unit. |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 93 | AssemblyAnnotationWriter::~AssemblyAnnotationWriter() = default; |
Reid Spencer | edd5d9e | 2005-05-15 16:13:11 +0000 | [diff] [blame] | 94 | |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 95 | //===----------------------------------------------------------------------===// |
| 96 | // Helper Functions |
| 97 | //===----------------------------------------------------------------------===// |
| 98 | |
Duncan P. N. Exon Smith | 7838818 | 2014-08-19 21:30:15 +0000 | [diff] [blame] | 99 | namespace { |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 100 | |
Duncan P. N. Exon Smith | 7838818 | 2014-08-19 21:30:15 +0000 | [diff] [blame] | 101 | struct OrderMap { |
| 102 | DenseMap<const Value *, std::pair<unsigned, bool>> IDs; |
| 103 | |
| 104 | unsigned size() const { return IDs.size(); } |
| 105 | std::pair<unsigned, bool> &operator[](const Value *V) { return IDs[V]; } |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 106 | |
Duncan P. N. Exon Smith | 7838818 | 2014-08-19 21:30:15 +0000 | [diff] [blame] | 107 | std::pair<unsigned, bool> lookup(const Value *V) const { |
| 108 | return IDs.lookup(V); |
| 109 | } |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 110 | |
Duncan P. N. Exon Smith | 7838818 | 2014-08-19 21:30:15 +0000 | [diff] [blame] | 111 | void index(const Value *V) { |
| 112 | // Explicitly sequence get-size and insert-value operations to avoid UB. |
| 113 | unsigned ID = IDs.size() + 1; |
| 114 | IDs[V].first = ID; |
| 115 | } |
| 116 | }; |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 117 | |
| 118 | } // end anonymous namespace |
Duncan P. N. Exon Smith | 7838818 | 2014-08-19 21:30:15 +0000 | [diff] [blame] | 119 | |
| 120 | static void orderValue(const Value *V, OrderMap &OM) { |
| 121 | if (OM.lookup(V).first) |
| 122 | return; |
| 123 | |
| 124 | if (const Constant *C = dyn_cast<Constant>(V)) |
| 125 | if (C->getNumOperands() && !isa<GlobalValue>(C)) |
| 126 | for (const Value *Op : C->operands()) |
| 127 | if (!isa<BasicBlock>(Op) && !isa<GlobalValue>(Op)) |
| 128 | orderValue(Op, OM); |
| 129 | |
| 130 | // Note: we cannot cache this lookup above, since inserting into the map |
| 131 | // changes the map's size, and thus affects the other IDs. |
| 132 | OM.index(V); |
| 133 | } |
| 134 | |
| 135 | static OrderMap orderModule(const Module *M) { |
| 136 | // This needs to match the order used by ValueEnumerator::ValueEnumerator() |
| 137 | // and ValueEnumerator::incorporateFunction(). |
| 138 | OrderMap OM; |
| 139 | |
| 140 | for (const GlobalVariable &G : M->globals()) { |
| 141 | if (G.hasInitializer()) |
| 142 | if (!isa<GlobalValue>(G.getInitializer())) |
| 143 | orderValue(G.getInitializer(), OM); |
| 144 | orderValue(&G, OM); |
| 145 | } |
| 146 | for (const GlobalAlias &A : M->aliases()) { |
| 147 | if (!isa<GlobalValue>(A.getAliasee())) |
| 148 | orderValue(A.getAliasee(), OM); |
| 149 | orderValue(&A, OM); |
| 150 | } |
Dmitry Polukhin | ba49223 | 2016-04-07 12:32:19 +0000 | [diff] [blame] | 151 | for (const GlobalIFunc &I : M->ifuncs()) { |
| 152 | if (!isa<GlobalValue>(I.getResolver())) |
| 153 | orderValue(I.getResolver(), OM); |
| 154 | orderValue(&I, OM); |
| 155 | } |
Duncan P. N. Exon Smith | 7838818 | 2014-08-19 21:30:15 +0000 | [diff] [blame] | 156 | for (const Function &F : *M) { |
Vedant Kumar | ef112d4 | 2015-12-19 08:52:49 +0000 | [diff] [blame] | 157 | for (const Use &U : F.operands()) |
| 158 | if (!isa<GlobalValue>(U.get())) |
| 159 | orderValue(U.get(), OM); |
David Majnemer | cc714e2 | 2015-06-17 20:52:32 +0000 | [diff] [blame] | 160 | |
Duncan P. N. Exon Smith | 7838818 | 2014-08-19 21:30:15 +0000 | [diff] [blame] | 161 | orderValue(&F, OM); |
| 162 | |
| 163 | if (F.isDeclaration()) |
| 164 | continue; |
| 165 | |
| 166 | for (const Argument &A : F.args()) |
| 167 | orderValue(&A, OM); |
| 168 | for (const BasicBlock &BB : F) { |
| 169 | orderValue(&BB, OM); |
| 170 | for (const Instruction &I : BB) { |
| 171 | for (const Value *Op : I.operands()) |
| 172 | if ((isa<Constant>(*Op) && !isa<GlobalValue>(*Op)) || |
| 173 | isa<InlineAsm>(*Op)) |
| 174 | orderValue(Op, OM); |
| 175 | orderValue(&I, OM); |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | return OM; |
| 180 | } |
| 181 | |
| 182 | static void predictValueUseListOrderImpl(const Value *V, const Function *F, |
| 183 | unsigned ID, const OrderMap &OM, |
| 184 | UseListOrderStack &Stack) { |
| 185 | // Predict use-list order for this one. |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 186 | using Entry = std::pair<const Use *, unsigned>; |
Duncan P. N. Exon Smith | 7838818 | 2014-08-19 21:30:15 +0000 | [diff] [blame] | 187 | SmallVector<Entry, 64> List; |
| 188 | for (const Use &U : V->uses()) |
| 189 | // Check if this user will be serialized. |
| 190 | if (OM.lookup(U.getUser()).first) |
| 191 | List.push_back(std::make_pair(&U, List.size())); |
| 192 | |
| 193 | if (List.size() < 2) |
| 194 | // We may have lost some users. |
| 195 | return; |
| 196 | |
| 197 | bool GetsReversed = |
| 198 | !isa<GlobalVariable>(V) && !isa<Function>(V) && !isa<BasicBlock>(V); |
| 199 | if (auto *BA = dyn_cast<BlockAddress>(V)) |
| 200 | ID = OM.lookup(BA->getBasicBlock()).first; |
Fangrui Song | 3b35e17 | 2018-09-27 02:13:45 +0000 | [diff] [blame] | 201 | llvm::sort(List, [&](const Entry &L, const Entry &R) { |
Duncan P. N. Exon Smith | 7838818 | 2014-08-19 21:30:15 +0000 | [diff] [blame] | 202 | const Use *LU = L.first; |
| 203 | const Use *RU = R.first; |
| 204 | if (LU == RU) |
| 205 | return false; |
| 206 | |
| 207 | auto LID = OM.lookup(LU->getUser()).first; |
| 208 | auto RID = OM.lookup(RU->getUser()).first; |
| 209 | |
| 210 | // If ID is 4, then expect: 7 6 5 1 2 3. |
| 211 | if (LID < RID) { |
| 212 | if (GetsReversed) |
| 213 | if (RID <= ID) |
| 214 | return true; |
| 215 | return false; |
| 216 | } |
| 217 | if (RID < LID) { |
| 218 | if (GetsReversed) |
| 219 | if (LID <= ID) |
| 220 | return false; |
| 221 | return true; |
| 222 | } |
| 223 | |
| 224 | // LID and RID are equal, so we have different operands of the same user. |
| 225 | // Assume operands are added in order for all instructions. |
| 226 | if (GetsReversed) |
| 227 | if (LID <= ID) |
| 228 | return LU->getOperandNo() < RU->getOperandNo(); |
| 229 | return LU->getOperandNo() > RU->getOperandNo(); |
| 230 | }); |
| 231 | |
| 232 | if (std::is_sorted( |
| 233 | List.begin(), List.end(), |
| 234 | [](const Entry &L, const Entry &R) { return L.second < R.second; })) |
| 235 | // Order is already correct. |
| 236 | return; |
| 237 | |
| 238 | // Store the shuffle. |
| 239 | Stack.emplace_back(V, F, List.size()); |
| 240 | assert(List.size() == Stack.back().Shuffle.size() && "Wrong size"); |
| 241 | for (size_t I = 0, E = List.size(); I != E; ++I) |
| 242 | Stack.back().Shuffle[I] = List[I].second; |
| 243 | } |
| 244 | |
| 245 | static void predictValueUseListOrder(const Value *V, const Function *F, |
| 246 | OrderMap &OM, UseListOrderStack &Stack) { |
| 247 | auto &IDPair = OM[V]; |
| 248 | assert(IDPair.first && "Unmapped value"); |
| 249 | if (IDPair.second) |
| 250 | // Already predicted. |
| 251 | return; |
| 252 | |
| 253 | // Do the actual prediction. |
| 254 | IDPair.second = true; |
| 255 | if (!V->use_empty() && std::next(V->use_begin()) != V->use_end()) |
| 256 | predictValueUseListOrderImpl(V, F, IDPair.first, OM, Stack); |
| 257 | |
| 258 | // Recursive descent into constants. |
| 259 | if (const Constant *C = dyn_cast<Constant>(V)) |
| 260 | if (C->getNumOperands()) // Visit GlobalValues. |
| 261 | for (const Value *Op : C->operands()) |
| 262 | if (isa<Constant>(Op)) // Visit GlobalValues. |
| 263 | predictValueUseListOrder(Op, F, OM, Stack); |
| 264 | } |
| 265 | |
| 266 | static UseListOrderStack predictUseListOrder(const Module *M) { |
| 267 | OrderMap OM = orderModule(M); |
| 268 | |
| 269 | // Use-list orders need to be serialized after all the users have been added |
| 270 | // to a value, or else the shuffles will be incomplete. Store them per |
| 271 | // function in a stack. |
| 272 | // |
| 273 | // Aside from function order, the order of values doesn't matter much here. |
| 274 | UseListOrderStack Stack; |
| 275 | |
| 276 | // We want to visit the functions backward now so we can list function-local |
| 277 | // constants in the last Function they're used in. Module-level constants |
| 278 | // have already been visited above. |
Pete Cooper | 9f2f165 | 2015-07-24 21:13:43 +0000 | [diff] [blame] | 279 | for (const Function &F : make_range(M->rbegin(), M->rend())) { |
Duncan P. N. Exon Smith | 7838818 | 2014-08-19 21:30:15 +0000 | [diff] [blame] | 280 | if (F.isDeclaration()) |
| 281 | continue; |
| 282 | for (const BasicBlock &BB : F) |
| 283 | predictValueUseListOrder(&BB, &F, OM, Stack); |
| 284 | for (const Argument &A : F.args()) |
| 285 | predictValueUseListOrder(&A, &F, OM, Stack); |
| 286 | for (const BasicBlock &BB : F) |
| 287 | for (const Instruction &I : BB) |
| 288 | for (const Value *Op : I.operands()) |
| 289 | if (isa<Constant>(*Op) || isa<InlineAsm>(*Op)) // Visit GlobalValues. |
| 290 | predictValueUseListOrder(Op, &F, OM, Stack); |
| 291 | for (const BasicBlock &BB : F) |
| 292 | for (const Instruction &I : BB) |
| 293 | predictValueUseListOrder(&I, &F, OM, Stack); |
| 294 | } |
| 295 | |
| 296 | // Visit globals last. |
| 297 | for (const GlobalVariable &G : M->globals()) |
| 298 | predictValueUseListOrder(&G, nullptr, OM, Stack); |
| 299 | for (const Function &F : *M) |
| 300 | predictValueUseListOrder(&F, nullptr, OM, Stack); |
| 301 | for (const GlobalAlias &A : M->aliases()) |
| 302 | predictValueUseListOrder(&A, nullptr, OM, Stack); |
Dmitry Polukhin | ba49223 | 2016-04-07 12:32:19 +0000 | [diff] [blame] | 303 | for (const GlobalIFunc &I : M->ifuncs()) |
| 304 | predictValueUseListOrder(&I, nullptr, OM, Stack); |
Duncan P. N. Exon Smith | 7838818 | 2014-08-19 21:30:15 +0000 | [diff] [blame] | 305 | for (const GlobalVariable &G : M->globals()) |
| 306 | if (G.hasInitializer()) |
| 307 | predictValueUseListOrder(G.getInitializer(), nullptr, OM, Stack); |
| 308 | for (const GlobalAlias &A : M->aliases()) |
| 309 | predictValueUseListOrder(A.getAliasee(), nullptr, OM, Stack); |
Dmitry Polukhin | ba49223 | 2016-04-07 12:32:19 +0000 | [diff] [blame] | 310 | for (const GlobalIFunc &I : M->ifuncs()) |
| 311 | predictValueUseListOrder(I.getResolver(), nullptr, OM, Stack); |
Duncan P. N. Exon Smith | 7838818 | 2014-08-19 21:30:15 +0000 | [diff] [blame] | 312 | for (const Function &F : *M) |
Vedant Kumar | ef112d4 | 2015-12-19 08:52:49 +0000 | [diff] [blame] | 313 | for (const Use &U : F.operands()) |
| 314 | predictValueUseListOrder(U.get(), nullptr, OM, Stack); |
Duncan P. N. Exon Smith | 7838818 | 2014-08-19 21:30:15 +0000 | [diff] [blame] | 315 | |
| 316 | return Stack; |
| 317 | } |
| 318 | |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 319 | static const Module *getModuleFromVal(const Value *V) { |
| 320 | if (const Argument *MA = dyn_cast<Argument>(V)) |
Craig Topper | ec0f0bc | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 321 | return MA->getParent() ? MA->getParent()->getParent() : nullptr; |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 322 | |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 323 | if (const BasicBlock *BB = dyn_cast<BasicBlock>(V)) |
Craig Topper | ec0f0bc | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 324 | return BB->getParent() ? BB->getParent()->getParent() : nullptr; |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 325 | |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 326 | if (const Instruction *I = dyn_cast<Instruction>(V)) { |
Craig Topper | ec0f0bc | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 327 | const Function *M = I->getParent() ? I->getParent()->getParent() : nullptr; |
| 328 | return M ? M->getParent() : nullptr; |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 329 | } |
Andrew Trick | 18801ec | 2011-09-30 19:48:58 +0000 | [diff] [blame] | 330 | |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 331 | if (const GlobalValue *GV = dyn_cast<GlobalValue>(V)) |
| 332 | return GV->getParent(); |
Duncan P. N. Exon Smith | f9f505e | 2015-03-14 20:19:36 +0000 | [diff] [blame] | 333 | |
| 334 | if (const auto *MAV = dyn_cast<MetadataAsValue>(V)) { |
| 335 | for (const User *U : MAV->users()) |
| 336 | if (isa<Instruction>(U)) |
| 337 | if (const Module *M = getModuleFromVal(U)) |
| 338 | return M; |
| 339 | return nullptr; |
| 340 | } |
| 341 | |
Craig Topper | ec0f0bc | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 342 | return nullptr; |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Bill Wendling | 7ab6c76 | 2013-02-20 07:21:42 +0000 | [diff] [blame] | 345 | static void PrintCallingConv(unsigned cc, raw_ostream &Out) { |
Micah Villmow | d3766df | 2012-09-13 15:11:12 +0000 | [diff] [blame] | 346 | switch (cc) { |
Bill Wendling | 7ab6c76 | 2013-02-20 07:21:42 +0000 | [diff] [blame] | 347 | default: Out << "cc" << cc; break; |
| 348 | case CallingConv::Fast: Out << "fastcc"; break; |
| 349 | case CallingConv::Cold: Out << "coldcc"; break; |
Andrew Trick | 5a34980 | 2013-11-11 22:40:22 +0000 | [diff] [blame] | 350 | case CallingConv::WebKit_JS: Out << "webkit_jscc"; break; |
| 351 | case CallingConv::AnyReg: Out << "anyregcc"; break; |
Juergen Ributzka | ceaf829 | 2014-01-17 19:47:03 +0000 | [diff] [blame] | 352 | case CallingConv::PreserveMost: Out << "preserve_mostcc"; break; |
| 353 | case CallingConv::PreserveAll: Out << "preserve_allcc"; break; |
Manman Ren | cd2103d | 2015-12-04 17:40:13 +0000 | [diff] [blame] | 354 | case CallingConv::CXX_FAST_TLS: Out << "cxx_fast_tlscc"; break; |
Reid Kleckner | 03c735b | 2014-12-01 21:04:44 +0000 | [diff] [blame] | 355 | case CallingConv::GHC: Out << "ghccc"; break; |
Bill Wendling | 7ab6c76 | 2013-02-20 07:21:42 +0000 | [diff] [blame] | 356 | case CallingConv::X86_StdCall: Out << "x86_stdcallcc"; break; |
| 357 | case CallingConv::X86_FastCall: Out << "x86_fastcallcc"; break; |
| 358 | case CallingConv::X86_ThisCall: Out << "x86_thiscallcc"; break; |
Oren Ben Simhon | 4b6c339 | 2016-10-13 07:53:43 +0000 | [diff] [blame] | 359 | case CallingConv::X86_RegCall: Out << "x86_regcallcc"; break; |
Reid Kleckner | d5de327 | 2014-10-28 01:29:26 +0000 | [diff] [blame] | 360 | case CallingConv::X86_VectorCall:Out << "x86_vectorcallcc"; break; |
Bill Wendling | 7ab6c76 | 2013-02-20 07:21:42 +0000 | [diff] [blame] | 361 | case CallingConv::Intel_OCL_BI: Out << "intel_ocl_bicc"; break; |
| 362 | case CallingConv::ARM_APCS: Out << "arm_apcscc"; break; |
| 363 | case CallingConv::ARM_AAPCS: Out << "arm_aapcscc"; break; |
| 364 | case CallingConv::ARM_AAPCS_VFP: Out << "arm_aapcs_vfpcc"; break; |
Sander de Smalen | 15889d4 | 2018-09-12 08:54:06 +0000 | [diff] [blame] | 365 | case CallingConv::AArch64_VectorCall: Out << "aarch64_vector_pcs"; break; |
Bill Wendling | 7ab6c76 | 2013-02-20 07:21:42 +0000 | [diff] [blame] | 366 | case CallingConv::MSP430_INTR: Out << "msp430_intrcc"; break; |
Dylan McKay | ca03902 | 2016-03-03 10:08:02 +0000 | [diff] [blame] | 367 | case CallingConv::AVR_INTR: Out << "avr_intrcc "; break; |
| 368 | case CallingConv::AVR_SIGNAL: Out << "avr_signalcc "; break; |
Bill Wendling | 7ab6c76 | 2013-02-20 07:21:42 +0000 | [diff] [blame] | 369 | case CallingConv::PTX_Kernel: Out << "ptx_kernel"; break; |
| 370 | case CallingConv::PTX_Device: Out << "ptx_device"; break; |
Charles Davis | ac226bb | 2013-07-12 06:02:35 +0000 | [diff] [blame] | 371 | case CallingConv::X86_64_SysV: Out << "x86_64_sysvcc"; break; |
Martin Storsjo | 6c132cb | 2017-07-17 20:05:19 +0000 | [diff] [blame] | 372 | case CallingConv::Win64: Out << "win64cc"; break; |
Michael Kuperstein | ef94f7e | 2013-12-15 10:01:20 +0000 | [diff] [blame] | 373 | case CallingConv::SPIR_FUNC: Out << "spir_func"; break; |
| 374 | case CallingConv::SPIR_KERNEL: Out << "spir_kernel"; break; |
Manman Ren | 1f7638e | 2016-04-05 22:41:47 +0000 | [diff] [blame] | 375 | case CallingConv::Swift: Out << "swiftcc"; break; |
Amjad Aboud | 9889174 | 2015-12-21 14:07:14 +0000 | [diff] [blame] | 376 | case CallingConv::X86_INTR: Out << "x86_intrcc"; break; |
Maksim Panchenko | 3b3752c | 2015-09-29 22:09:16 +0000 | [diff] [blame] | 377 | case CallingConv::HHVM: Out << "hhvmcc"; break; |
| 378 | case CallingConv::HHVM_C: Out << "hhvm_ccc"; break; |
Nicolai Haehnle | ea7a0c04 | 2016-04-06 19:40:20 +0000 | [diff] [blame] | 379 | case CallingConv::AMDGPU_VS: Out << "amdgpu_vs"; break; |
Tim Renouf | 8ba98f9 | 2017-09-29 09:51:22 +0000 | [diff] [blame] | 380 | case CallingConv::AMDGPU_LS: Out << "amdgpu_ls"; break; |
Marek Olsak | a205704 | 2017-05-02 15:41:10 +0000 | [diff] [blame] | 381 | case CallingConv::AMDGPU_HS: Out << "amdgpu_hs"; break; |
Tim Renouf | 8ba98f9 | 2017-09-29 09:51:22 +0000 | [diff] [blame] | 382 | case CallingConv::AMDGPU_ES: Out << "amdgpu_es"; break; |
Nicolai Haehnle | ea7a0c04 | 2016-04-06 19:40:20 +0000 | [diff] [blame] | 383 | case CallingConv::AMDGPU_GS: Out << "amdgpu_gs"; break; |
| 384 | case CallingConv::AMDGPU_PS: Out << "amdgpu_ps"; break; |
| 385 | case CallingConv::AMDGPU_CS: Out << "amdgpu_cs"; break; |
Nikolay Haustov | ac1dd29 | 2016-05-06 09:07:29 +0000 | [diff] [blame] | 386 | case CallingConv::AMDGPU_KERNEL: Out << "amdgpu_kernel"; break; |
Micah Villmow | d3766df | 2012-09-13 15:11:12 +0000 | [diff] [blame] | 387 | } |
| 388 | } |
Michael Ilseman | 407a616 | 2012-11-15 22:34:00 +0000 | [diff] [blame] | 389 | |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 390 | enum PrefixType { |
| 391 | GlobalPrefix, |
David Majnemer | c8a1169 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 392 | ComdatPrefix, |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 393 | LabelPrefix, |
Daniel Dunbar | cad3580 | 2008-10-14 23:28:09 +0000 | [diff] [blame] | 394 | LocalPrefix, |
| 395 | NoPrefix |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 396 | }; |
| 397 | |
Alex Lorenz | 476706e | 2015-07-21 16:50:35 +0000 | [diff] [blame] | 398 | void llvm::printLLVMNameWithoutPrefix(raw_ostream &OS, StringRef Name) { |
Jay Foad | 61717b3 | 2011-04-24 14:30:00 +0000 | [diff] [blame] | 399 | assert(!Name.empty() && "Cannot get empty name!"); |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 400 | |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 401 | // Scan the name to see if it needs quotes first. |
Guy Benyei | 87d0b9e | 2013-02-12 21:21:59 +0000 | [diff] [blame] | 402 | bool NeedsQuotes = isdigit(static_cast<unsigned char>(Name[0])); |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 403 | if (!NeedsQuotes) { |
Daniel Dunbar | 03d7651 | 2009-07-25 23:55:21 +0000 | [diff] [blame] | 404 | for (unsigned i = 0, e = Name.size(); i != e; ++i) { |
Aaron Ballman | 09dab82 | 2012-07-16 16:18:18 +0000 | [diff] [blame] | 405 | // By making this unsigned, the value passed in to isalnum will always be |
| 406 | // in the range 0-255. This is important when building with MSVC because |
| 407 | // its implementation will assert. This situation can arise when dealing |
| 408 | // with UTF-8 multibyte characters. |
| 409 | unsigned char C = Name[i]; |
Guy Benyei | 87d0b9e | 2013-02-12 21:21:59 +0000 | [diff] [blame] | 410 | if (!isalnum(static_cast<unsigned char>(C)) && C != '-' && C != '.' && |
| 411 | C != '_') { |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 412 | NeedsQuotes = true; |
| 413 | break; |
| 414 | } |
| 415 | } |
| 416 | } |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 417 | |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 418 | // If we didn't need any quotes, just write out the name in one blast. |
| 419 | if (!NeedsQuotes) { |
Daniel Dunbar | 03d7651 | 2009-07-25 23:55:21 +0000 | [diff] [blame] | 420 | OS << Name; |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 421 | return; |
| 422 | } |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 423 | |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 424 | // Okay, we need quotes. Output the quotes and escape any scary characters as |
| 425 | // needed. |
| 426 | OS << '"'; |
Jonas Devlieghere | 7eeba25 | 2018-05-31 17:01:42 +0000 | [diff] [blame] | 427 | printEscapedString(Name, OS); |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 428 | OS << '"'; |
| 429 | } |
| 430 | |
Alex Lorenz | 476706e | 2015-07-21 16:50:35 +0000 | [diff] [blame] | 431 | /// Turn the specified name into an 'LLVM name', which is either prefixed with % |
| 432 | /// (if the string only contains simple characters) or is surrounded with ""'s |
| 433 | /// (if it has special chars in it). Print it out. |
| 434 | static void PrintLLVMName(raw_ostream &OS, StringRef Name, PrefixType Prefix) { |
| 435 | switch (Prefix) { |
| 436 | case NoPrefix: |
| 437 | break; |
| 438 | case GlobalPrefix: |
| 439 | OS << '@'; |
| 440 | break; |
| 441 | case ComdatPrefix: |
| 442 | OS << '$'; |
| 443 | break; |
| 444 | case LabelPrefix: |
| 445 | break; |
| 446 | case LocalPrefix: |
| 447 | OS << '%'; |
| 448 | break; |
| 449 | } |
| 450 | printLLVMNameWithoutPrefix(OS, Name); |
| 451 | } |
| 452 | |
| 453 | /// Turn the specified name into an 'LLVM name', which is either prefixed with % |
| 454 | /// (if the string only contains simple characters) or is surrounded with ""'s |
| 455 | /// (if it has special chars in it). Print it out. |
Dan Gohman | 1220e10 | 2009-08-12 20:56:03 +0000 | [diff] [blame] | 456 | static void PrintLLVMName(raw_ostream &OS, const Value *V) { |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 457 | PrintLLVMName(OS, V->getName(), |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 458 | isa<GlobalValue>(V) ? GlobalPrefix : LocalPrefix); |
| 459 | } |
| 460 | |
Benjamin Kramer | 93920f0 | 2015-03-17 19:53:41 +0000 | [diff] [blame] | 461 | namespace { |
Benjamin Kramer | 93920f0 | 2015-03-17 19:53:41 +0000 | [diff] [blame] | 462 | |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 463 | class TypePrinting { |
| 464 | public: |
Roman Tereshin | 238a338 | 2018-03-22 21:29:07 +0000 | [diff] [blame] | 465 | TypePrinting(const Module *M = nullptr) : DeferredM(M) {} |
Benjamin Kramer | 93920f0 | 2015-03-17 19:53:41 +0000 | [diff] [blame] | 466 | |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 467 | TypePrinting(const TypePrinting &) = delete; |
| 468 | TypePrinting &operator=(const TypePrinting &) = delete; |
Benjamin Kramer | 93920f0 | 2015-03-17 19:53:41 +0000 | [diff] [blame] | 469 | |
Roman Tereshin | 238a338 | 2018-03-22 21:29:07 +0000 | [diff] [blame] | 470 | /// The named types that are used by the current module. |
| 471 | TypeFinder &getNamedTypes(); |
| 472 | |
| 473 | /// The numbered types, number to type mapping. |
| 474 | std::vector<StructType *> &getNumberedTypes(); |
| 475 | |
| 476 | bool empty(); |
Benjamin Kramer | 93920f0 | 2015-03-17 19:53:41 +0000 | [diff] [blame] | 477 | |
| 478 | void print(Type *Ty, raw_ostream &OS); |
| 479 | |
| 480 | void printStructBody(StructType *Ty, raw_ostream &OS); |
Roman Tereshin | 238a338 | 2018-03-22 21:29:07 +0000 | [diff] [blame] | 481 | |
| 482 | private: |
| 483 | void incorporateTypes(); |
| 484 | |
| 485 | /// A module to process lazily when needed. Set to nullptr as soon as used. |
| 486 | const Module *DeferredM; |
| 487 | |
| 488 | TypeFinder NamedTypes; |
| 489 | |
| 490 | // The numbered types, along with their value. |
| 491 | DenseMap<StructType *, unsigned> Type2Number; |
| 492 | |
| 493 | std::vector<StructType *> NumberedTypes; |
Benjamin Kramer | 93920f0 | 2015-03-17 19:53:41 +0000 | [diff] [blame] | 494 | }; |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 495 | |
| 496 | } // end anonymous namespace |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 497 | |
Roman Tereshin | 238a338 | 2018-03-22 21:29:07 +0000 | [diff] [blame] | 498 | TypeFinder &TypePrinting::getNamedTypes() { |
| 499 | incorporateTypes(); |
| 500 | return NamedTypes; |
| 501 | } |
| 502 | |
| 503 | std::vector<StructType *> &TypePrinting::getNumberedTypes() { |
| 504 | incorporateTypes(); |
| 505 | |
| 506 | // We know all the numbers that each type is used and we know that it is a |
| 507 | // dense assignment. Convert the map to an index table, if it's not done |
| 508 | // already (judging from the sizes): |
| 509 | if (NumberedTypes.size() == Type2Number.size()) |
| 510 | return NumberedTypes; |
| 511 | |
| 512 | NumberedTypes.resize(Type2Number.size()); |
| 513 | for (const auto &P : Type2Number) { |
| 514 | assert(P.second < NumberedTypes.size() && "Didn't get a dense numbering?"); |
| 515 | assert(!NumberedTypes[P.second] && "Didn't get a unique numbering?"); |
| 516 | NumberedTypes[P.second] = P.first; |
| 517 | } |
| 518 | return NumberedTypes; |
| 519 | } |
| 520 | |
| 521 | bool TypePrinting::empty() { |
| 522 | incorporateTypes(); |
| 523 | return NamedTypes.empty() && Type2Number.empty(); |
| 524 | } |
| 525 | |
| 526 | void TypePrinting::incorporateTypes() { |
| 527 | if (!DeferredM) |
| 528 | return; |
| 529 | |
| 530 | NamedTypes.run(*DeferredM, false); |
| 531 | DeferredM = nullptr; |
Andrew Trick | 18801ec | 2011-09-30 19:48:58 +0000 | [diff] [blame] | 532 | |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 533 | // The list of struct types we got back includes all the struct types, split |
| 534 | // the unnamed ones out to a numbering and remove the anonymous structs. |
| 535 | unsigned NextNumber = 0; |
Andrew Trick | 18801ec | 2011-09-30 19:48:58 +0000 | [diff] [blame] | 536 | |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 537 | std::vector<StructType*>::iterator NextToUse = NamedTypes.begin(), I, E; |
| 538 | for (I = NamedTypes.begin(), E = NamedTypes.end(); I != E; ++I) { |
| 539 | StructType *STy = *I; |
Andrew Trick | 18801ec | 2011-09-30 19:48:58 +0000 | [diff] [blame] | 540 | |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 541 | // Ignore anonymous types. |
Chris Lattner | c4d0e9f | 2011-08-12 18:07:07 +0000 | [diff] [blame] | 542 | if (STy->isLiteral()) |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 543 | continue; |
Andrew Trick | 18801ec | 2011-09-30 19:48:58 +0000 | [diff] [blame] | 544 | |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 545 | if (STy->getName().empty()) |
Roman Tereshin | 238a338 | 2018-03-22 21:29:07 +0000 | [diff] [blame] | 546 | Type2Number[STy] = NextNumber++; |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 547 | else |
| 548 | *NextToUse++ = STy; |
| 549 | } |
Andrew Trick | 18801ec | 2011-09-30 19:48:58 +0000 | [diff] [blame] | 550 | |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 551 | NamedTypes.erase(NextToUse, NamedTypes.end()); |
| 552 | } |
| 553 | |
Roman Tereshin | 238a338 | 2018-03-22 21:29:07 +0000 | [diff] [blame] | 554 | /// Write the specified type to the specified raw_ostream, making use of type |
| 555 | /// names or up references to shorten the type name where possible. |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 556 | void TypePrinting::print(Type *Ty, raw_ostream &OS) { |
Chris Lattner | 9cc3446 | 2009-02-28 20:25:14 +0000 | [diff] [blame] | 557 | switch (Ty->getTypeID()) { |
Rafael Espindola | 954b6b8 | 2013-12-07 02:27:52 +0000 | [diff] [blame] | 558 | case Type::VoidTyID: OS << "void"; return; |
| 559 | case Type::HalfTyID: OS << "half"; return; |
| 560 | case Type::FloatTyID: OS << "float"; return; |
| 561 | case Type::DoubleTyID: OS << "double"; return; |
| 562 | case Type::X86_FP80TyID: OS << "x86_fp80"; return; |
| 563 | case Type::FP128TyID: OS << "fp128"; return; |
| 564 | case Type::PPC_FP128TyID: OS << "ppc_fp128"; return; |
| 565 | case Type::LabelTyID: OS << "label"; return; |
| 566 | case Type::MetadataTyID: OS << "metadata"; return; |
| 567 | case Type::X86_MMXTyID: OS << "x86_mmx"; return; |
David Majnemer | 2dacece | 2015-08-14 05:09:07 +0000 | [diff] [blame] | 568 | case Type::TokenTyID: OS << "token"; return; |
Chris Lattner | 583ffd8 | 2009-02-28 21:18:43 +0000 | [diff] [blame] | 569 | case Type::IntegerTyID: |
Chris Lattner | 3079426 | 2009-02-28 21:27:31 +0000 | [diff] [blame] | 570 | OS << 'i' << cast<IntegerType>(Ty)->getBitWidth(); |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 571 | return; |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 572 | |
Chris Lattner | 36942d7 | 2009-02-28 20:35:42 +0000 | [diff] [blame] | 573 | case Type::FunctionTyID: { |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 574 | FunctionType *FTy = cast<FunctionType>(Ty); |
| 575 | print(FTy->getReturnType(), OS); |
Chris Lattner | 3079426 | 2009-02-28 21:27:31 +0000 | [diff] [blame] | 576 | OS << " ("; |
Chris Lattner | 36942d7 | 2009-02-28 20:35:42 +0000 | [diff] [blame] | 577 | for (FunctionType::param_iterator I = FTy->param_begin(), |
| 578 | E = FTy->param_end(); I != E; ++I) { |
| 579 | if (I != FTy->param_begin()) |
Chris Lattner | 3079426 | 2009-02-28 21:27:31 +0000 | [diff] [blame] | 580 | OS << ", "; |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 581 | print(*I, OS); |
Chris Lattner | 9cc3446 | 2009-02-28 20:25:14 +0000 | [diff] [blame] | 582 | } |
Chris Lattner | 36942d7 | 2009-02-28 20:35:42 +0000 | [diff] [blame] | 583 | if (FTy->isVarArg()) { |
Chris Lattner | 3079426 | 2009-02-28 21:27:31 +0000 | [diff] [blame] | 584 | if (FTy->getNumParams()) OS << ", "; |
| 585 | OS << "..."; |
Chris Lattner | 9cc3446 | 2009-02-28 20:25:14 +0000 | [diff] [blame] | 586 | } |
Chris Lattner | 3079426 | 2009-02-28 21:27:31 +0000 | [diff] [blame] | 587 | OS << ')'; |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 588 | return; |
Chris Lattner | 36942d7 | 2009-02-28 20:35:42 +0000 | [diff] [blame] | 589 | } |
| 590 | case Type::StructTyID: { |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 591 | StructType *STy = cast<StructType>(Ty); |
Andrew Trick | 18801ec | 2011-09-30 19:48:58 +0000 | [diff] [blame] | 592 | |
Chris Lattner | c4d0e9f | 2011-08-12 18:07:07 +0000 | [diff] [blame] | 593 | if (STy->isLiteral()) |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 594 | return printStructBody(STy, OS); |
| 595 | |
| 596 | if (!STy->getName().empty()) |
| 597 | return PrintLLVMName(OS, STy->getName(), LocalPrefix); |
Andrew Trick | 18801ec | 2011-09-30 19:48:58 +0000 | [diff] [blame] | 598 | |
Roman Tereshin | 238a338 | 2018-03-22 21:29:07 +0000 | [diff] [blame] | 599 | incorporateTypes(); |
| 600 | const auto I = Type2Number.find(STy); |
| 601 | if (I != Type2Number.end()) |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 602 | OS << '%' << I->second; |
| 603 | else // Not enumerated, print the hex address. |
Benjamin Kramer | 5a83264 | 2011-11-02 17:24:36 +0000 | [diff] [blame] | 604 | OS << "%\"type " << STy << '\"'; |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 605 | return; |
Chris Lattner | 36942d7 | 2009-02-28 20:35:42 +0000 | [diff] [blame] | 606 | } |
| 607 | case Type::PointerTyID: { |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 608 | PointerType *PTy = cast<PointerType>(Ty); |
| 609 | print(PTy->getElementType(), OS); |
Chris Lattner | 36942d7 | 2009-02-28 20:35:42 +0000 | [diff] [blame] | 610 | if (unsigned AddressSpace = PTy->getAddressSpace()) |
Chris Lattner | 3079426 | 2009-02-28 21:27:31 +0000 | [diff] [blame] | 611 | OS << " addrspace(" << AddressSpace << ')'; |
| 612 | OS << '*'; |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 613 | return; |
Chris Lattner | 36942d7 | 2009-02-28 20:35:42 +0000 | [diff] [blame] | 614 | } |
| 615 | case Type::ArrayTyID: { |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 616 | ArrayType *ATy = cast<ArrayType>(Ty); |
Chris Lattner | 3079426 | 2009-02-28 21:27:31 +0000 | [diff] [blame] | 617 | OS << '[' << ATy->getNumElements() << " x "; |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 618 | print(ATy->getElementType(), OS); |
Chris Lattner | 3079426 | 2009-02-28 21:27:31 +0000 | [diff] [blame] | 619 | OS << ']'; |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 620 | return; |
Chris Lattner | 36942d7 | 2009-02-28 20:35:42 +0000 | [diff] [blame] | 621 | } |
| 622 | case Type::VectorTyID: { |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 623 | VectorType *PTy = cast<VectorType>(Ty); |
Chris Lattner | 3079426 | 2009-02-28 21:27:31 +0000 | [diff] [blame] | 624 | OS << "<" << PTy->getNumElements() << " x "; |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 625 | print(PTy->getElementType(), OS); |
Chris Lattner | 3079426 | 2009-02-28 21:27:31 +0000 | [diff] [blame] | 626 | OS << '>'; |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 627 | return; |
Chris Lattner | 36942d7 | 2009-02-28 20:35:42 +0000 | [diff] [blame] | 628 | } |
Chris Lattner | 9cc3446 | 2009-02-28 20:25:14 +0000 | [diff] [blame] | 629 | } |
Rafael Espindola | 954b6b8 | 2013-12-07 02:27:52 +0000 | [diff] [blame] | 630 | llvm_unreachable("Invalid TypeID"); |
Chris Lattner | 9cc3446 | 2009-02-28 20:25:14 +0000 | [diff] [blame] | 631 | } |
| 632 | |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 633 | void TypePrinting::printStructBody(StructType *STy, raw_ostream &OS) { |
| 634 | if (STy->isOpaque()) { |
| 635 | OS << "opaque"; |
| 636 | return; |
Chris Lattner | 9cc3446 | 2009-02-28 20:25:14 +0000 | [diff] [blame] | 637 | } |
Andrew Trick | 18801ec | 2011-09-30 19:48:58 +0000 | [diff] [blame] | 638 | |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 639 | if (STy->isPacked()) |
| 640 | OS << '<'; |
Andrew Trick | 18801ec | 2011-09-30 19:48:58 +0000 | [diff] [blame] | 641 | |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 642 | if (STy->getNumElements() == 0) { |
| 643 | OS << "{}"; |
| 644 | } else { |
| 645 | StructType::element_iterator I = STy->element_begin(); |
| 646 | OS << "{ "; |
| 647 | print(*I++, OS); |
| 648 | for (StructType::element_iterator E = STy->element_end(); I != E; ++I) { |
| 649 | OS << ", "; |
| 650 | print(*I, OS); |
Chris Lattner | 413fd23 | 2009-03-01 00:03:38 +0000 | [diff] [blame] | 651 | } |
Andrew Trick | 18801ec | 2011-09-30 19:48:58 +0000 | [diff] [blame] | 652 | |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 653 | OS << " }"; |
Chris Lattner | e9fa33e | 2009-02-28 23:20:19 +0000 | [diff] [blame] | 654 | } |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 655 | if (STy->isPacked()) |
| 656 | OS << '>'; |
Chris Lattner | e9fa33e | 2009-02-28 23:20:19 +0000 | [diff] [blame] | 657 | } |
| 658 | |
Duncan P. N. Exon Smith | 9a61a42 | 2015-06-26 22:04:20 +0000 | [diff] [blame] | 659 | namespace llvm { |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 660 | |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 661 | //===----------------------------------------------------------------------===// |
| 662 | // SlotTracker Class: Enumerate slot numbers for unnamed values |
| 663 | //===----------------------------------------------------------------------===// |
Reid Spencer | 0d1b77e | 2004-05-26 07:18:52 +0000 | [diff] [blame] | 664 | /// This class provides computation of slot numbers for LLVM Assembly writing. |
Chris Lattner | 45d4c73 | 2008-08-17 04:17:45 +0000 | [diff] [blame] | 665 | /// |
Chris Lattner | 0d9574a | 2008-08-19 04:26:57 +0000 | [diff] [blame] | 666 | class SlotTracker { |
Reid Spencer | 0d1b77e | 2004-05-26 07:18:52 +0000 | [diff] [blame] | 667 | public: |
Devang Patel | 320671d | 2009-07-08 21:44:25 +0000 | [diff] [blame] | 668 | /// ValueMap - A mapping of Values to slot numbers. |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 669 | using ValueMap = DenseMap<const Value *, unsigned>; |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 670 | |
| 671 | private: |
Devang Patel | 320671d | 2009-07-08 21:44:25 +0000 | [diff] [blame] | 672 | /// TheModule - The module for which we are holding slot numbers. |
Chris Lattner | 45d4c73 | 2008-08-17 04:17:45 +0000 | [diff] [blame] | 673 | const Module* TheModule; |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 674 | |
Devang Patel | 320671d | 2009-07-08 21:44:25 +0000 | [diff] [blame] | 675 | /// TheFunction - The function for which we are holding slot numbers. |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 676 | const Function* TheFunction = nullptr; |
| 677 | bool FunctionProcessed = false; |
Duncan P. N. Exon Smith | f9f505e | 2015-03-14 20:19:36 +0000 | [diff] [blame] | 678 | bool ShouldInitializeAllMetadata; |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 679 | |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 680 | /// The summary index for which we are holding slot numbers. |
| 681 | const ModuleSummaryIndex *TheIndex = nullptr; |
| 682 | |
Jay Foad | 7f0ce34 | 2011-07-11 07:28:49 +0000 | [diff] [blame] | 683 | /// mMap - The slot map for the module level data. |
Chris Lattner | 45d4c73 | 2008-08-17 04:17:45 +0000 | [diff] [blame] | 684 | ValueMap mMap; |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 685 | unsigned mNext = 0; |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 686 | |
Jay Foad | 7f0ce34 | 2011-07-11 07:28:49 +0000 | [diff] [blame] | 687 | /// fMap - The slot map for the function level data. |
Chris Lattner | 45d4c73 | 2008-08-17 04:17:45 +0000 | [diff] [blame] | 688 | ValueMap fMap; |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 689 | unsigned fNext = 0; |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 690 | |
Devang Patel | 320671d | 2009-07-08 21:44:25 +0000 | [diff] [blame] | 691 | /// mdnMap - Map for MDNodes. |
Chris Lattner | 307c989 | 2009-12-31 02:20:11 +0000 | [diff] [blame] | 692 | DenseMap<const MDNode*, unsigned> mdnMap; |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 693 | unsigned mdnNext = 0; |
Bill Wendling | b29ce26 | 2013-02-11 08:43:33 +0000 | [diff] [blame] | 694 | |
| 695 | /// asMap - The slot map for attribute sets. |
Reid Kleckner | 0609040 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 696 | DenseMap<AttributeSet, unsigned> asMap; |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 697 | unsigned asNext = 0; |
| 698 | |
Teresa Johnson | 807ab958 | 2018-07-02 22:09:23 +0000 | [diff] [blame] | 699 | /// ModulePathMap - The slot map for Module paths used in the summary index. |
| 700 | StringMap<unsigned> ModulePathMap; |
| 701 | unsigned ModulePathNext = 0; |
| 702 | |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 703 | /// GUIDMap - The slot map for GUIDs used in the summary index. |
| 704 | DenseMap<GlobalValue::GUID, unsigned> GUIDMap; |
| 705 | unsigned GUIDNext = 0; |
| 706 | |
Teresa Johnson | 0d4dfd2 | 2018-09-25 20:14:40 +0000 | [diff] [blame] | 707 | /// TypeIdMap - The slot map for type ids used in the summary index. |
| 708 | StringMap<unsigned> TypeIdMap; |
| 709 | unsigned TypeIdNext = 0; |
| 710 | |
Reid Spencer | 0d1b77e | 2004-05-26 07:18:52 +0000 | [diff] [blame] | 711 | public: |
Duncan P. N. Exon Smith | f9f505e | 2015-03-14 20:19:36 +0000 | [diff] [blame] | 712 | /// Construct from a module. |
| 713 | /// |
| 714 | /// If \c ShouldInitializeAllMetadata, initializes all metadata in all |
| 715 | /// functions, giving correct numbering for metadata referenced only from |
| 716 | /// within a function (even if no functions have been initialized). |
| 717 | explicit SlotTracker(const Module *M, |
| 718 | bool ShouldInitializeAllMetadata = false); |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 719 | |
Chris Lattner | 45d4c73 | 2008-08-17 04:17:45 +0000 | [diff] [blame] | 720 | /// Construct from a function, starting out in incorp state. |
Duncan P. N. Exon Smith | f9f505e | 2015-03-14 20:19:36 +0000 | [diff] [blame] | 721 | /// |
| 722 | /// If \c ShouldInitializeAllMetadata, initializes all metadata in all |
| 723 | /// functions, giving correct numbering for metadata referenced only from |
| 724 | /// within a function (even if no functions have been initialized). |
| 725 | explicit SlotTracker(const Function *F, |
| 726 | bool ShouldInitializeAllMetadata = false); |
Reid Spencer | 0d1b77e | 2004-05-26 07:18:52 +0000 | [diff] [blame] | 727 | |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 728 | /// Construct from a module summary index. |
| 729 | explicit SlotTracker(const ModuleSummaryIndex *Index); |
| 730 | |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 731 | SlotTracker(const SlotTracker &) = delete; |
| 732 | SlotTracker &operator=(const SlotTracker &) = delete; |
| 733 | |
Reid Spencer | 0d1b77e | 2004-05-26 07:18:52 +0000 | [diff] [blame] | 734 | /// Return the slot number of the specified value in it's type |
Chris Lattner | 0d9574a | 2008-08-19 04:26:57 +0000 | [diff] [blame] | 735 | /// plane. If something is not in the SlotTracker, return -1. |
Chris Lattner | 22379bc | 2007-01-11 03:54:27 +0000 | [diff] [blame] | 736 | int getLocalSlot(const Value *V); |
| 737 | int getGlobalSlot(const GlobalValue *V); |
Duncan P. N. Exon Smith | 5bf8ade | 2014-11-11 21:30:22 +0000 | [diff] [blame] | 738 | int getMetadataSlot(const MDNode *N); |
Reid Kleckner | 0609040 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 739 | int getAttributeGroupSlot(AttributeSet AS); |
Teresa Johnson | 807ab958 | 2018-07-02 22:09:23 +0000 | [diff] [blame] | 740 | int getModulePathSlot(StringRef Path); |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 741 | int getGUIDSlot(GlobalValue::GUID GUID); |
Teresa Johnson | 0d4dfd2 | 2018-09-25 20:14:40 +0000 | [diff] [blame] | 742 | int getTypeIdSlot(StringRef Id); |
Reid Spencer | fc621e2 | 2004-06-09 15:26:53 +0000 | [diff] [blame] | 743 | |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 744 | /// If you'd like to deal with a function instead of just a module, use |
Chris Lattner | 0d9574a | 2008-08-19 04:26:57 +0000 | [diff] [blame] | 745 | /// this method to get its data into the SlotTracker. |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 746 | void incorporateFunction(const Function *F) { |
| 747 | TheFunction = F; |
Reid Spencer | 28531c7 | 2004-08-16 07:46:33 +0000 | [diff] [blame] | 748 | FunctionProcessed = false; |
| 749 | } |
Reid Spencer | 0d1b77e | 2004-05-26 07:18:52 +0000 | [diff] [blame] | 750 | |
Duncan P. N. Exon Smith | 7838818 | 2014-08-19 21:30:15 +0000 | [diff] [blame] | 751 | const Function *getFunction() const { return TheFunction; } |
| 752 | |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 753 | /// After calling incorporateFunction, use this method to remove the |
Chris Lattner | 0d9574a | 2008-08-19 04:26:57 +0000 | [diff] [blame] | 754 | /// most recently incorporated function from the SlotTracker. This |
Reid Spencer | 0d1b77e | 2004-05-26 07:18:52 +0000 | [diff] [blame] | 755 | /// will reset the state of the machine back to just the module contents. |
| 756 | void purgeFunction(); |
| 757 | |
Devang Patel | 320671d | 2009-07-08 21:44:25 +0000 | [diff] [blame] | 758 | /// MDNode map iterators. |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 759 | using mdn_iterator = DenseMap<const MDNode*, unsigned>::iterator; |
| 760 | |
Chris Lattner | 307c989 | 2009-12-31 02:20:11 +0000 | [diff] [blame] | 761 | mdn_iterator mdn_begin() { return mdnMap.begin(); } |
| 762 | mdn_iterator mdn_end() { return mdnMap.end(); } |
| 763 | unsigned mdn_size() const { return mdnMap.size(); } |
| 764 | bool mdn_empty() const { return mdnMap.empty(); } |
Devang Patel | 320671d | 2009-07-08 21:44:25 +0000 | [diff] [blame] | 765 | |
Reid Kleckner | 0609040 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 766 | /// AttributeSet map iterators. |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 767 | using as_iterator = DenseMap<AttributeSet, unsigned>::iterator; |
| 768 | |
Bill Wendling | b29ce26 | 2013-02-11 08:43:33 +0000 | [diff] [blame] | 769 | as_iterator as_begin() { return asMap.begin(); } |
| 770 | as_iterator as_end() { return asMap.end(); } |
| 771 | unsigned as_size() const { return asMap.size(); } |
| 772 | bool as_empty() const { return asMap.empty(); } |
| 773 | |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 774 | /// GUID map iterators. |
| 775 | using guid_iterator = DenseMap<GlobalValue::GUID, unsigned>::iterator; |
| 776 | |
| 777 | /// These functions do the actual initialization. |
Teresa Johnson | a9961f3 | 2018-07-03 15:52:57 +0000 | [diff] [blame] | 778 | inline void initializeIfNeeded(); |
| 779 | void initializeIndexIfNeeded(); |
Reid Spencer | b03de0c | 2004-05-26 21:56:09 +0000 | [diff] [blame] | 780 | |
Devang Patel | 320671d | 2009-07-08 21:44:25 +0000 | [diff] [blame] | 781 | // Implementation Details |
| 782 | private: |
Chris Lattner | 9446bbe | 2007-01-09 07:55:49 +0000 | [diff] [blame] | 783 | /// CreateModuleSlot - Insert the specified GlobalValue* into the slot table. |
| 784 | void CreateModuleSlot(const GlobalValue *V); |
Devang Patel | 320671d | 2009-07-08 21:44:25 +0000 | [diff] [blame] | 785 | |
| 786 | /// CreateMetadataSlot - Insert the specified MDNode* into the slot table. |
Duncan P. N. Exon Smith | 5bf8ade | 2014-11-11 21:30:22 +0000 | [diff] [blame] | 787 | void CreateMetadataSlot(const MDNode *N); |
Devang Patel | 320671d | 2009-07-08 21:44:25 +0000 | [diff] [blame] | 788 | |
Chris Lattner | 9446bbe | 2007-01-09 07:55:49 +0000 | [diff] [blame] | 789 | /// CreateFunctionSlot - Insert the specified Value* into the slot table. |
| 790 | void CreateFunctionSlot(const Value *V); |
Reid Spencer | 0d1b77e | 2004-05-26 07:18:52 +0000 | [diff] [blame] | 791 | |
Adrian Prantl | 26b584c | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 792 | /// Insert the specified AttributeSet into the slot table. |
Reid Kleckner | 0609040 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 793 | void CreateAttributeSetSlot(AttributeSet AS); |
Bill Wendling | b29ce26 | 2013-02-11 08:43:33 +0000 | [diff] [blame] | 794 | |
Teresa Johnson | 807ab958 | 2018-07-02 22:09:23 +0000 | [diff] [blame] | 795 | inline void CreateModulePathSlot(StringRef Path); |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 796 | void CreateGUIDSlot(GlobalValue::GUID GUID); |
Teresa Johnson | 0d4dfd2 | 2018-09-25 20:14:40 +0000 | [diff] [blame] | 797 | void CreateTypeIdSlot(StringRef Id); |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 798 | |
Reid Spencer | 0d1b77e | 2004-05-26 07:18:52 +0000 | [diff] [blame] | 799 | /// Add all of the module level global variables (and their initializers) |
| 800 | /// and function declarations, but not the contents of those functions. |
| 801 | void processModule(); |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 802 | void processIndex(); |
Reid Spencer | 0d1b77e | 2004-05-26 07:18:52 +0000 | [diff] [blame] | 803 | |
Devang Patel | 320671d | 2009-07-08 21:44:25 +0000 | [diff] [blame] | 804 | /// Add all of the functions arguments, basic blocks, and instructions. |
Reid Spencer | b03de0c | 2004-05-26 21:56:09 +0000 | [diff] [blame] | 805 | void processFunction(); |
| 806 | |
Peter Collingbourne | 6aef9f9 | 2016-05-31 23:01:54 +0000 | [diff] [blame] | 807 | /// Add the metadata directly attached to a GlobalObject. |
| 808 | void processGlobalObjectMetadata(const GlobalObject &GO); |
| 809 | |
Duncan P. N. Exon Smith | f9f505e | 2015-03-14 20:19:36 +0000 | [diff] [blame] | 810 | /// Add all of the metadata from a function. |
| 811 | void processFunctionMetadata(const Function &F); |
| 812 | |
Duncan P. N. Exon Smith | 81ebfb1 | 2015-03-14 19:48:31 +0000 | [diff] [blame] | 813 | /// Add all of the metadata from an instruction. |
| 814 | void processInstructionMetadata(const Instruction &I); |
Reid Spencer | 0d1b77e | 2004-05-26 07:18:52 +0000 | [diff] [blame] | 815 | }; |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 816 | |
| 817 | } // end namespace llvm |
Duncan P. N. Exon Smith | 9a61a42 | 2015-06-26 22:04:20 +0000 | [diff] [blame] | 818 | |
| 819 | ModuleSlotTracker::ModuleSlotTracker(SlotTracker &Machine, const Module *M, |
| 820 | const Function *F) |
| 821 | : M(M), F(F), Machine(&Machine) {} |
| 822 | |
Duncan P. N. Exon Smith | 8266df7 | 2015-06-26 22:28:47 +0000 | [diff] [blame] | 823 | ModuleSlotTracker::ModuleSlotTracker(const Module *M, |
| 824 | bool ShouldInitializeAllMetadata) |
Duncan P. N. Exon Smith | 1487a2e | 2016-04-20 19:05:59 +0000 | [diff] [blame] | 825 | : ShouldCreateStorage(M), |
| 826 | ShouldInitializeAllMetadata(ShouldInitializeAllMetadata), M(M) {} |
Duncan P. N. Exon Smith | 9a61a42 | 2015-06-26 22:04:20 +0000 | [diff] [blame] | 827 | |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 828 | ModuleSlotTracker::~ModuleSlotTracker() = default; |
Duncan P. N. Exon Smith | 9a61a42 | 2015-06-26 22:04:20 +0000 | [diff] [blame] | 829 | |
Duncan P. N. Exon Smith | 1487a2e | 2016-04-20 19:05:59 +0000 | [diff] [blame] | 830 | SlotTracker *ModuleSlotTracker::getMachine() { |
| 831 | if (!ShouldCreateStorage) |
| 832 | return Machine; |
| 833 | |
| 834 | ShouldCreateStorage = false; |
| 835 | MachineStorage = |
| 836 | llvm::make_unique<SlotTracker>(M, ShouldInitializeAllMetadata); |
| 837 | Machine = MachineStorage.get(); |
| 838 | return Machine; |
| 839 | } |
| 840 | |
Duncan P. N. Exon Smith | 9a61a42 | 2015-06-26 22:04:20 +0000 | [diff] [blame] | 841 | void ModuleSlotTracker::incorporateFunction(const Function &F) { |
Duncan P. N. Exon Smith | 1487a2e | 2016-04-20 19:05:59 +0000 | [diff] [blame] | 842 | // Using getMachine() may lazily create the slot tracker. |
| 843 | if (!getMachine()) |
Duncan P. N. Exon Smith | 9a61a42 | 2015-06-26 22:04:20 +0000 | [diff] [blame] | 844 | return; |
| 845 | |
| 846 | // Nothing to do if this is the right function already. |
| 847 | if (this->F == &F) |
| 848 | return; |
| 849 | if (this->F) |
| 850 | Machine->purgeFunction(); |
| 851 | Machine->incorporateFunction(&F); |
| 852 | this->F = &F; |
| 853 | } |
Reid Spencer | 0d1b77e | 2004-05-26 07:18:52 +0000 | [diff] [blame] | 854 | |
Alex Lorenz | 9adb212 | 2015-07-27 22:31:04 +0000 | [diff] [blame] | 855 | int ModuleSlotTracker::getLocalSlot(const Value *V) { |
| 856 | assert(F && "No function incorporated"); |
| 857 | return Machine->getLocalSlot(V); |
| 858 | } |
| 859 | |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 860 | static SlotTracker *createSlotTracker(const Value *V) { |
| 861 | if (const Argument *FA = dyn_cast<Argument>(V)) |
| 862 | return new SlotTracker(FA->getParent()); |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 863 | |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 864 | if (const Instruction *I = dyn_cast<Instruction>(V)) |
Andrew Trick | 62e0590 | 2011-09-30 19:50:40 +0000 | [diff] [blame] | 865 | if (I->getParent()) |
| 866 | return new SlotTracker(I->getParent()->getParent()); |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 867 | |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 868 | if (const BasicBlock *BB = dyn_cast<BasicBlock>(V)) |
| 869 | return new SlotTracker(BB->getParent()); |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 870 | |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 871 | if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) |
| 872 | return new SlotTracker(GV->getParent()); |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 873 | |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 874 | if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 875 | return new SlotTracker(GA->getParent()); |
| 876 | |
Dmitry Polukhin | ba49223 | 2016-04-07 12:32:19 +0000 | [diff] [blame] | 877 | if (const GlobalIFunc *GIF = dyn_cast<GlobalIFunc>(V)) |
| 878 | return new SlotTracker(GIF->getParent()); |
| 879 | |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 880 | if (const Function *Func = dyn_cast<Function>(V)) |
| 881 | return new SlotTracker(Func); |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 882 | |
Craig Topper | ec0f0bc | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 883 | return nullptr; |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | #if 0 |
David Greene | d865e02 | 2010-01-05 01:29:26 +0000 | [diff] [blame] | 887 | #define ST_DEBUG(X) dbgs() << X |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 888 | #else |
Chris Lattner | 2423303 | 2008-08-19 04:47:09 +0000 | [diff] [blame] | 889 | #define ST_DEBUG(X) |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 890 | #endif |
| 891 | |
| 892 | // Module level constructor. Causes the contents of the Module (sans functions) |
| 893 | // to be added to the slot table. |
Duncan P. N. Exon Smith | f9f505e | 2015-03-14 20:19:36 +0000 | [diff] [blame] | 894 | SlotTracker::SlotTracker(const Module *M, bool ShouldInitializeAllMetadata) |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 895 | : TheModule(M), ShouldInitializeAllMetadata(ShouldInitializeAllMetadata) {} |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 896 | |
| 897 | // Function level constructor. Causes the contents of the Module and the one |
| 898 | // function provided to be added to the slot table. |
Duncan P. N. Exon Smith | f9f505e | 2015-03-14 20:19:36 +0000 | [diff] [blame] | 899 | SlotTracker::SlotTracker(const Function *F, bool ShouldInitializeAllMetadata) |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 900 | : TheModule(F ? F->getParent() : nullptr), TheFunction(F), |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 901 | ShouldInitializeAllMetadata(ShouldInitializeAllMetadata) {} |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 902 | |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 903 | SlotTracker::SlotTracker(const ModuleSummaryIndex *Index) |
| 904 | : TheModule(nullptr), ShouldInitializeAllMetadata(false), TheIndex(Index) {} |
| 905 | |
Teresa Johnson | a9961f3 | 2018-07-03 15:52:57 +0000 | [diff] [blame] | 906 | inline void SlotTracker::initializeIfNeeded() { |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 907 | if (TheModule) { |
| 908 | processModule(); |
Craig Topper | ec0f0bc | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 909 | TheModule = nullptr; ///< Prevent re-processing next time we're called. |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 910 | } |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 911 | |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 912 | if (TheFunction && !FunctionProcessed) |
| 913 | processFunction(); |
| 914 | } |
| 915 | |
Teresa Johnson | a9961f3 | 2018-07-03 15:52:57 +0000 | [diff] [blame] | 916 | void SlotTracker::initializeIndexIfNeeded() { |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 917 | if (!TheIndex) |
| 918 | return; |
| 919 | processIndex(); |
| 920 | TheIndex = nullptr; ///< Prevent re-processing next time we're called. |
| 921 | } |
| 922 | |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 923 | // Iterate through all the global variables, functions, and global |
| 924 | // variable initializers and create slots for them. |
| 925 | void SlotTracker::processModule() { |
Chris Lattner | 2423303 | 2008-08-19 04:47:09 +0000 | [diff] [blame] | 926 | ST_DEBUG("begin processModule!\n"); |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 927 | |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 928 | // Add all of the unnamed global variables to the value table. |
Rafael Espindola | b200e2f | 2015-06-17 17:33:37 +0000 | [diff] [blame] | 929 | for (const GlobalVariable &Var : TheModule->globals()) { |
| 930 | if (!Var.hasName()) |
| 931 | CreateModuleSlot(&Var); |
Peter Collingbourne | 6aef9f9 | 2016-05-31 23:01:54 +0000 | [diff] [blame] | 932 | processGlobalObjectMetadata(Var); |
Javed Absar | a8ddcaa | 2017-05-11 12:28:08 +0000 | [diff] [blame] | 933 | auto Attrs = Var.getAttributes(); |
| 934 | if (Attrs.hasAttributes()) |
| 935 | CreateAttributeSetSlot(Attrs); |
Devang Patel | 320671d | 2009-07-08 21:44:25 +0000 | [diff] [blame] | 936 | } |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 937 | |
Rafael Espindola | 43e5349 | 2015-06-17 17:53:31 +0000 | [diff] [blame] | 938 | for (const GlobalAlias &A : TheModule->aliases()) { |
| 939 | if (!A.hasName()) |
| 940 | CreateModuleSlot(&A); |
| 941 | } |
| 942 | |
Dmitry Polukhin | ba49223 | 2016-04-07 12:32:19 +0000 | [diff] [blame] | 943 | for (const GlobalIFunc &I : TheModule->ifuncs()) { |
| 944 | if (!I.hasName()) |
| 945 | CreateModuleSlot(&I); |
| 946 | } |
| 947 | |
Devang Patel | 37c4a2d | 2009-07-29 22:04:47 +0000 | [diff] [blame] | 948 | // Add metadata used by named metadata. |
Rafael Espindola | b200e2f | 2015-06-17 17:33:37 +0000 | [diff] [blame] | 949 | for (const NamedMDNode &NMD : TheModule->named_metadata()) { |
| 950 | for (unsigned i = 0, e = NMD.getNumOperands(); i != e; ++i) |
| 951 | CreateMetadataSlot(NMD.getOperand(i)); |
Devang Patel | 37c4a2d | 2009-07-29 22:04:47 +0000 | [diff] [blame] | 952 | } |
| 953 | |
Rafael Espindola | b200e2f | 2015-06-17 17:33:37 +0000 | [diff] [blame] | 954 | for (const Function &F : *TheModule) { |
| 955 | if (!F.hasName()) |
Bill Wendling | b29ce26 | 2013-02-11 08:43:33 +0000 | [diff] [blame] | 956 | // Add all the unnamed functions to the table. |
Rafael Espindola | b200e2f | 2015-06-17 17:33:37 +0000 | [diff] [blame] | 957 | CreateModuleSlot(&F); |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 958 | |
Duncan P. N. Exon Smith | f9f505e | 2015-03-14 20:19:36 +0000 | [diff] [blame] | 959 | if (ShouldInitializeAllMetadata) |
Rafael Espindola | b200e2f | 2015-06-17 17:33:37 +0000 | [diff] [blame] | 960 | processFunctionMetadata(F); |
Duncan P. N. Exon Smith | f9f505e | 2015-03-14 20:19:36 +0000 | [diff] [blame] | 961 | |
Bill Wendling | b29ce26 | 2013-02-11 08:43:33 +0000 | [diff] [blame] | 962 | // Add all the function attributes to the table. |
Bill Wendling | 7ab6c76 | 2013-02-20 07:21:42 +0000 | [diff] [blame] | 963 | // FIXME: Add attributes of other objects? |
Reid Kleckner | 0609040 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 964 | AttributeSet FnAttrs = F.getAttributes().getFnAttributes(); |
| 965 | if (FnAttrs.hasAttributes()) |
Bill Wendling | b29ce26 | 2013-02-11 08:43:33 +0000 | [diff] [blame] | 966 | CreateAttributeSetSlot(FnAttrs); |
| 967 | } |
| 968 | |
Chris Lattner | 2423303 | 2008-08-19 04:47:09 +0000 | [diff] [blame] | 969 | ST_DEBUG("end processModule!\n"); |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 970 | } |
| 971 | |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 972 | // Process the arguments, basic blocks, and instructions of a function. |
| 973 | void SlotTracker::processFunction() { |
Chris Lattner | 2423303 | 2008-08-19 04:47:09 +0000 | [diff] [blame] | 974 | ST_DEBUG("begin processFunction!\n"); |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 975 | fNext = 0; |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 976 | |
Duncan P. N. Exon Smith | 812e1e4 | 2015-09-11 01:34:59 +0000 | [diff] [blame] | 977 | // Process function metadata if it wasn't hit at the module-level. |
| 978 | if (!ShouldInitializeAllMetadata) |
| 979 | processFunctionMetadata(*TheFunction); |
| 980 | |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 981 | // Add all the function arguments with no names. |
| 982 | for(Function::const_arg_iterator AI = TheFunction->arg_begin(), |
| 983 | AE = TheFunction->arg_end(); AI != AE; ++AI) |
| 984 | if (!AI->hasName()) |
Duncan P. N. Exon Smith | eac3095 | 2015-10-08 23:49:46 +0000 | [diff] [blame] | 985 | CreateFunctionSlot(&*AI); |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 986 | |
Chris Lattner | 2423303 | 2008-08-19 04:47:09 +0000 | [diff] [blame] | 987 | ST_DEBUG("Inserting Instructions:\n"); |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 988 | |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 989 | // Add all of the basic blocks and instructions with no names. |
Duncan P. N. Exon Smith | ff0e5a6 | 2015-03-14 19:44:01 +0000 | [diff] [blame] | 990 | for (auto &BB : *TheFunction) { |
| 991 | if (!BB.hasName()) |
| 992 | CreateFunctionSlot(&BB); |
Andrew Trick | 18801ec | 2011-09-30 19:48:58 +0000 | [diff] [blame] | 993 | |
Duncan P. N. Exon Smith | ff0e5a6 | 2015-03-14 19:44:01 +0000 | [diff] [blame] | 994 | for (auto &I : BB) { |
| 995 | if (!I.getType()->isVoidTy() && !I.hasName()) |
| 996 | CreateFunctionSlot(&I); |
Andrew Trick | 18801ec | 2011-09-30 19:48:58 +0000 | [diff] [blame] | 997 | |
Duncan P. N. Exon Smith | 81ebfb1 | 2015-03-14 19:48:31 +0000 | [diff] [blame] | 998 | // We allow direct calls to any llvm.foo function here, because the |
| 999 | // target may not be linked into the optimizer. |
Chandler Carruth | 9f32dc9 | 2019-01-07 07:31:49 +0000 | [diff] [blame] | 1000 | if (const auto *Call = dyn_cast<CallBase>(&I)) { |
Bill Wendling | 351b7a1 | 2013-02-22 09:09:42 +0000 | [diff] [blame] | 1001 | // Add all the call attributes to the table. |
Chandler Carruth | 9f32dc9 | 2019-01-07 07:31:49 +0000 | [diff] [blame] | 1002 | AttributeSet Attrs = Call->getAttributes().getFnAttributes(); |
Reid Kleckner | 0609040 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 1003 | if (Attrs.hasAttributes()) |
Bill Wendling | 351b7a1 | 2013-02-22 09:09:42 +0000 | [diff] [blame] | 1004 | CreateAttributeSetSlot(Attrs); |
Chris Lattner | fd450c0 | 2010-05-10 20:53:17 +0000 | [diff] [blame] | 1005 | } |
Devang Patel | 320671d | 2009-07-08 21:44:25 +0000 | [diff] [blame] | 1006 | } |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 1007 | } |
Devang Patel | 4321578 | 2009-09-16 20:21:17 +0000 | [diff] [blame] | 1008 | |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 1009 | FunctionProcessed = true; |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 1010 | |
Chris Lattner | 2423303 | 2008-08-19 04:47:09 +0000 | [diff] [blame] | 1011 | ST_DEBUG("end processFunction!\n"); |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 1012 | } |
| 1013 | |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 1014 | // Iterate through all the GUID in the index and create slots for them. |
| 1015 | void SlotTracker::processIndex() { |
| 1016 | ST_DEBUG("begin processIndex!\n"); |
| 1017 | assert(TheIndex); |
| 1018 | |
| 1019 | // The first block of slots are just the module ids, which start at 0 and are |
Teresa Johnson | 807ab958 | 2018-07-02 22:09:23 +0000 | [diff] [blame] | 1020 | // assigned consecutively. Since the StringMap iteration order isn't |
| 1021 | // guaranteed, use a std::map to order by module ID before assigning slots. |
| 1022 | std::map<uint64_t, StringRef> ModuleIdToPathMap; |
| 1023 | for (auto &ModPath : TheIndex->modulePaths()) |
| 1024 | ModuleIdToPathMap[ModPath.second.first] = ModPath.first(); |
| 1025 | for (auto &ModPair : ModuleIdToPathMap) |
| 1026 | CreateModulePathSlot(ModPair.second); |
| 1027 | |
| 1028 | // Start numbering the GUIDs after the module ids. |
| 1029 | GUIDNext = ModulePathNext; |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 1030 | |
| 1031 | for (auto &GlobalList : *TheIndex) |
| 1032 | CreateGUIDSlot(GlobalList.first); |
| 1033 | |
Teresa Johnson | 0d4dfd2 | 2018-09-25 20:14:40 +0000 | [diff] [blame] | 1034 | // Start numbering the TypeIds after the GUIDs. |
| 1035 | TypeIdNext = GUIDNext; |
| 1036 | |
| 1037 | for (auto TidIter = TheIndex->typeIds().begin(); |
| 1038 | TidIter != TheIndex->typeIds().end(); TidIter++) |
| 1039 | CreateTypeIdSlot(TidIter->second.first); |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 1040 | |
| 1041 | ST_DEBUG("end processIndex!\n"); |
| 1042 | } |
| 1043 | |
Peter Collingbourne | 6aef9f9 | 2016-05-31 23:01:54 +0000 | [diff] [blame] | 1044 | void SlotTracker::processGlobalObjectMetadata(const GlobalObject &GO) { |
Duncan P. N. Exon Smith | ae32114 | 2015-04-24 22:04:41 +0000 | [diff] [blame] | 1045 | SmallVector<std::pair<unsigned, MDNode *>, 4> MDs; |
Peter Collingbourne | 6aef9f9 | 2016-05-31 23:01:54 +0000 | [diff] [blame] | 1046 | GO.getAllMetadata(MDs); |
Duncan P. N. Exon Smith | 812e1e4 | 2015-09-11 01:34:59 +0000 | [diff] [blame] | 1047 | for (auto &MD : MDs) |
| 1048 | CreateMetadataSlot(MD.second); |
Peter Collingbourne | 6aef9f9 | 2016-05-31 23:01:54 +0000 | [diff] [blame] | 1049 | } |
Duncan P. N. Exon Smith | ae32114 | 2015-04-24 22:04:41 +0000 | [diff] [blame] | 1050 | |
Peter Collingbourne | 6aef9f9 | 2016-05-31 23:01:54 +0000 | [diff] [blame] | 1051 | void SlotTracker::processFunctionMetadata(const Function &F) { |
| 1052 | processGlobalObjectMetadata(F); |
Duncan P. N. Exon Smith | 812e1e4 | 2015-09-11 01:34:59 +0000 | [diff] [blame] | 1053 | for (auto &BB : F) { |
Duncan P. N. Exon Smith | f9f505e | 2015-03-14 20:19:36 +0000 | [diff] [blame] | 1054 | for (auto &I : BB) |
| 1055 | processInstructionMetadata(I); |
Duncan P. N. Exon Smith | ae32114 | 2015-04-24 22:04:41 +0000 | [diff] [blame] | 1056 | } |
Duncan P. N. Exon Smith | f9f505e | 2015-03-14 20:19:36 +0000 | [diff] [blame] | 1057 | } |
| 1058 | |
Duncan P. N. Exon Smith | 81ebfb1 | 2015-03-14 19:48:31 +0000 | [diff] [blame] | 1059 | void SlotTracker::processInstructionMetadata(const Instruction &I) { |
| 1060 | // Process metadata used directly by intrinsics. |
| 1061 | if (const CallInst *CI = dyn_cast<CallInst>(&I)) |
| 1062 | if (Function *F = CI->getCalledFunction()) |
Justin Lebar | 24dbd38 | 2016-07-28 23:58:15 +0000 | [diff] [blame] | 1063 | if (F->isIntrinsic()) |
Duncan P. N. Exon Smith | 81ebfb1 | 2015-03-14 19:48:31 +0000 | [diff] [blame] | 1064 | for (auto &Op : I.operands()) |
| 1065 | if (auto *V = dyn_cast_or_null<MetadataAsValue>(Op)) |
| 1066 | if (MDNode *N = dyn_cast<MDNode>(V->getMetadata())) |
| 1067 | CreateMetadataSlot(N); |
| 1068 | |
| 1069 | // Process metadata attached to this instruction. |
| 1070 | SmallVector<std::pair<unsigned, MDNode *>, 4> MDs; |
| 1071 | I.getAllMetadata(MDs); |
| 1072 | for (auto &MD : MDs) |
| 1073 | CreateMetadataSlot(MD.second); |
| 1074 | } |
| 1075 | |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 1076 | /// Clean up after incorporating a function. This is the only way to get out of |
| 1077 | /// the function incorporation state that affects get*Slot/Create*Slot. Function |
| 1078 | /// incorporation state is indicated by TheFunction != 0. |
| 1079 | void SlotTracker::purgeFunction() { |
Chris Lattner | 2423303 | 2008-08-19 04:47:09 +0000 | [diff] [blame] | 1080 | ST_DEBUG("begin purgeFunction!\n"); |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 1081 | fMap.clear(); // Simply discard the function level map |
Craig Topper | ec0f0bc | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 1082 | TheFunction = nullptr; |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 1083 | FunctionProcessed = false; |
Chris Lattner | 2423303 | 2008-08-19 04:47:09 +0000 | [diff] [blame] | 1084 | ST_DEBUG("end purgeFunction!\n"); |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | /// getGlobalSlot - Get the slot number of a global value. |
| 1088 | int SlotTracker::getGlobalSlot(const GlobalValue *V) { |
| 1089 | // Check for uninitialized state and do lazy initialization. |
Teresa Johnson | a9961f3 | 2018-07-03 15:52:57 +0000 | [diff] [blame] | 1090 | initializeIfNeeded(); |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 1091 | |
Jay Foad | 7f0ce34 | 2011-07-11 07:28:49 +0000 | [diff] [blame] | 1092 | // Find the value in the module map |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 1093 | ValueMap::iterator MI = mMap.find(V); |
Dan Gohman | aeaf245 | 2008-10-01 19:58:59 +0000 | [diff] [blame] | 1094 | return MI == mMap.end() ? -1 : (int)MI->second; |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 1095 | } |
| 1096 | |
Duncan P. N. Exon Smith | 5bf8ade | 2014-11-11 21:30:22 +0000 | [diff] [blame] | 1097 | /// getMetadataSlot - Get the slot number of a MDNode. |
| 1098 | int SlotTracker::getMetadataSlot(const MDNode *N) { |
Devang Patel | 320671d | 2009-07-08 21:44:25 +0000 | [diff] [blame] | 1099 | // Check for uninitialized state and do lazy initialization. |
Teresa Johnson | a9961f3 | 2018-07-03 15:52:57 +0000 | [diff] [blame] | 1100 | initializeIfNeeded(); |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 1101 | |
Jay Foad | 7f0ce34 | 2011-07-11 07:28:49 +0000 | [diff] [blame] | 1102 | // Find the MDNode in the module map |
Duncan P. N. Exon Smith | 5bf8ade | 2014-11-11 21:30:22 +0000 | [diff] [blame] | 1103 | mdn_iterator MI = mdnMap.find(N); |
Devang Patel | 320671d | 2009-07-08 21:44:25 +0000 | [diff] [blame] | 1104 | return MI == mdnMap.end() ? -1 : (int)MI->second; |
| 1105 | } |
| 1106 | |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 1107 | /// getLocalSlot - Get the slot number for a value that is local to a function. |
| 1108 | int SlotTracker::getLocalSlot(const Value *V) { |
| 1109 | assert(!isa<Constant>(V) && "Can't get a constant or global slot with this!"); |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 1110 | |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 1111 | // Check for uninitialized state and do lazy initialization. |
Teresa Johnson | a9961f3 | 2018-07-03 15:52:57 +0000 | [diff] [blame] | 1112 | initializeIfNeeded(); |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 1113 | |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 1114 | ValueMap::iterator FI = fMap.find(V); |
Dan Gohman | aeaf245 | 2008-10-01 19:58:59 +0000 | [diff] [blame] | 1115 | return FI == fMap.end() ? -1 : (int)FI->second; |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 1116 | } |
| 1117 | |
Reid Kleckner | 0609040 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 1118 | int SlotTracker::getAttributeGroupSlot(AttributeSet AS) { |
Bill Wendling | b29ce26 | 2013-02-11 08:43:33 +0000 | [diff] [blame] | 1119 | // Check for uninitialized state and do lazy initialization. |
Teresa Johnson | a9961f3 | 2018-07-03 15:52:57 +0000 | [diff] [blame] | 1120 | initializeIfNeeded(); |
Bill Wendling | b29ce26 | 2013-02-11 08:43:33 +0000 | [diff] [blame] | 1121 | |
Reid Kleckner | 0609040 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 1122 | // Find the AttributeSet in the module map. |
Bill Wendling | b29ce26 | 2013-02-11 08:43:33 +0000 | [diff] [blame] | 1123 | as_iterator AI = asMap.find(AS); |
| 1124 | return AI == asMap.end() ? -1 : (int)AI->second; |
| 1125 | } |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 1126 | |
Teresa Johnson | 807ab958 | 2018-07-02 22:09:23 +0000 | [diff] [blame] | 1127 | int SlotTracker::getModulePathSlot(StringRef Path) { |
| 1128 | // Check for uninitialized state and do lazy initialization. |
Teresa Johnson | a9961f3 | 2018-07-03 15:52:57 +0000 | [diff] [blame] | 1129 | initializeIndexIfNeeded(); |
Teresa Johnson | 807ab958 | 2018-07-02 22:09:23 +0000 | [diff] [blame] | 1130 | |
| 1131 | // Find the Module path in the map |
| 1132 | auto I = ModulePathMap.find(Path); |
| 1133 | return I == ModulePathMap.end() ? -1 : (int)I->second; |
| 1134 | } |
| 1135 | |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 1136 | int SlotTracker::getGUIDSlot(GlobalValue::GUID GUID) { |
| 1137 | // Check for uninitialized state and do lazy initialization. |
Teresa Johnson | a9961f3 | 2018-07-03 15:52:57 +0000 | [diff] [blame] | 1138 | initializeIndexIfNeeded(); |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 1139 | |
| 1140 | // Find the GUID in the map |
| 1141 | guid_iterator I = GUIDMap.find(GUID); |
| 1142 | return I == GUIDMap.end() ? -1 : (int)I->second; |
| 1143 | } |
| 1144 | |
Teresa Johnson | 0d4dfd2 | 2018-09-25 20:14:40 +0000 | [diff] [blame] | 1145 | int SlotTracker::getTypeIdSlot(StringRef Id) { |
| 1146 | // Check for uninitialized state and do lazy initialization. |
| 1147 | initializeIndexIfNeeded(); |
| 1148 | |
| 1149 | // Find the TypeId string in the map |
| 1150 | auto I = TypeIdMap.find(Id); |
| 1151 | return I == TypeIdMap.end() ? -1 : (int)I->second; |
| 1152 | } |
| 1153 | |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 1154 | /// CreateModuleSlot - Insert the specified GlobalValue* into the slot table. |
| 1155 | void SlotTracker::CreateModuleSlot(const GlobalValue *V) { |
| 1156 | assert(V && "Can't insert a null Value into SlotTracker!"); |
Chris Lattner | 4ee93c4 | 2009-12-29 07:25:48 +0000 | [diff] [blame] | 1157 | assert(!V->getType()->isVoidTy() && "Doesn't need a slot!"); |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 1158 | assert(!V->hasName() && "Doesn't need a slot!"); |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 1159 | |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 1160 | unsigned DestSlot = mNext++; |
| 1161 | mMap[V] = DestSlot; |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 1162 | |
Chris Lattner | 2423303 | 2008-08-19 04:47:09 +0000 | [diff] [blame] | 1163 | ST_DEBUG(" Inserting value [" << V->getType() << "] = " << V << " slot=" << |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 1164 | DestSlot << " ["); |
Dmitry Polukhin | ba49223 | 2016-04-07 12:32:19 +0000 | [diff] [blame] | 1165 | // G = Global, F = Function, A = Alias, I = IFunc, o = other |
Chris Lattner | 2423303 | 2008-08-19 04:47:09 +0000 | [diff] [blame] | 1166 | ST_DEBUG((isa<GlobalVariable>(V) ? 'G' : |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 1167 | (isa<Function>(V) ? 'F' : |
Dmitry Polukhin | ba49223 | 2016-04-07 12:32:19 +0000 | [diff] [blame] | 1168 | (isa<GlobalAlias>(V) ? 'A' : |
| 1169 | (isa<GlobalIFunc>(V) ? 'I' : 'o')))) << "]\n"); |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 1170 | } |
| 1171 | |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 1172 | /// CreateSlot - Create a new slot for the specified value if it has no name. |
| 1173 | void SlotTracker::CreateFunctionSlot(const Value *V) { |
Chris Lattner | 4ee93c4 | 2009-12-29 07:25:48 +0000 | [diff] [blame] | 1174 | assert(!V->getType()->isVoidTy() && !V->hasName() && "Doesn't need a slot!"); |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 1175 | |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 1176 | unsigned DestSlot = fNext++; |
| 1177 | fMap[V] = DestSlot; |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 1178 | |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 1179 | // G = Global, F = Function, o = other |
Chris Lattner | 2423303 | 2008-08-19 04:47:09 +0000 | [diff] [blame] | 1180 | ST_DEBUG(" Inserting value [" << V->getType() << "] = " << V << " slot=" << |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 1181 | DestSlot << " [o]\n"); |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 1182 | } |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 1183 | |
Duncan P. N. Exon Smith | 5bf8ade | 2014-11-11 21:30:22 +0000 | [diff] [blame] | 1184 | /// CreateModuleSlot - Insert the specified MDNode* into the slot table. |
| 1185 | void SlotTracker::CreateMetadataSlot(const MDNode *N) { |
| 1186 | assert(N && "Can't insert a null Value into SlotTracker!"); |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 1187 | |
Reid Kleckner | a5b2af0 | 2017-08-23 20:31:27 +0000 | [diff] [blame] | 1188 | // Don't make slots for DIExpressions. We just print them inline everywhere. |
| 1189 | if (isa<DIExpression>(N)) |
| 1190 | return; |
| 1191 | |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 1192 | unsigned DestSlot = mdnNext; |
| 1193 | if (!mdnMap.insert(std::make_pair(N, DestSlot)).second) |
| 1194 | return; |
| 1195 | ++mdnNext; |
Devang Patel | 320671d | 2009-07-08 21:44:25 +0000 | [diff] [blame] | 1196 | |
Chris Lattner | 2b4b1e2 | 2009-12-31 02:27:30 +0000 | [diff] [blame] | 1197 | // Recursively add any MDNodes referenced by operands. |
| 1198 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) |
| 1199 | if (const MDNode *Op = dyn_cast_or_null<MDNode>(N->getOperand(i))) |
| 1200 | CreateMetadataSlot(Op); |
Devang Patel | 320671d | 2009-07-08 21:44:25 +0000 | [diff] [blame] | 1201 | } |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 1202 | |
Reid Kleckner | 0609040 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 1203 | void SlotTracker::CreateAttributeSetSlot(AttributeSet AS) { |
| 1204 | assert(AS.hasAttributes() && "Doesn't need a slot!"); |
Bill Wendling | b29ce26 | 2013-02-11 08:43:33 +0000 | [diff] [blame] | 1205 | |
| 1206 | as_iterator I = asMap.find(AS); |
| 1207 | if (I != asMap.end()) |
| 1208 | return; |
| 1209 | |
| 1210 | unsigned DestSlot = asNext++; |
| 1211 | asMap[AS] = DestSlot; |
| 1212 | } |
| 1213 | |
Teresa Johnson | 807ab958 | 2018-07-02 22:09:23 +0000 | [diff] [blame] | 1214 | /// Create a new slot for the specified Module |
| 1215 | void SlotTracker::CreateModulePathSlot(StringRef Path) { |
| 1216 | ModulePathMap[Path] = ModulePathNext++; |
| 1217 | } |
| 1218 | |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 1219 | /// Create a new slot for the specified GUID |
| 1220 | void SlotTracker::CreateGUIDSlot(GlobalValue::GUID GUID) { |
| 1221 | GUIDMap[GUID] = GUIDNext++; |
| 1222 | } |
| 1223 | |
Teresa Johnson | 0d4dfd2 | 2018-09-25 20:14:40 +0000 | [diff] [blame] | 1224 | /// Create a new slot for the specified Id |
| 1225 | void SlotTracker::CreateTypeIdSlot(StringRef Id) { |
| 1226 | TypeIdMap[Id] = TypeIdNext++; |
| 1227 | } |
| 1228 | |
Chris Lattner | 6ab910b | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 1229 | //===----------------------------------------------------------------------===// |
| 1230 | // AsmWriter Implementation |
| 1231 | //===----------------------------------------------------------------------===// |
Chris Lattner | f082b80 | 2002-07-23 18:07:49 +0000 | [diff] [blame] | 1232 | |
Dan Gohman | 1220e10 | 2009-08-12 20:56:03 +0000 | [diff] [blame] | 1233 | static void WriteAsOperandInternal(raw_ostream &Out, const Value *V, |
Dan Gohman | d6c0f65 | 2009-08-13 15:27:57 +0000 | [diff] [blame] | 1234 | TypePrinting *TypePrinter, |
Dan Gohman | 3bdfbf5 | 2010-07-20 23:55:01 +0000 | [diff] [blame] | 1235 | SlotTracker *Machine, |
| 1236 | const Module *Context); |
Reid Spencer | 0e25e1c | 2004-07-04 11:50:43 +0000 | [diff] [blame] | 1237 | |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 1238 | static void WriteAsOperandInternal(raw_ostream &Out, const Metadata *MD, |
| 1239 | TypePrinting *TypePrinter, |
| 1240 | SlotTracker *Machine, const Module *Context, |
| 1241 | bool FromValue = false); |
| 1242 | |
Dan Gohman | 1220e10 | 2009-08-12 20:56:03 +0000 | [diff] [blame] | 1243 | static void WriteOptimizationInfo(raw_ostream &Out, const User *U) { |
Michael Ilseman | 15c13d3 | 2012-11-27 00:42:44 +0000 | [diff] [blame] | 1244 | if (const FPMathOperator *FPO = dyn_cast<const FPMathOperator>(U)) { |
Sanjay Patel | 00e900a | 2017-11-06 16:27:15 +0000 | [diff] [blame] | 1245 | // 'Fast' is an abbreviation for all fast-math-flags. |
| 1246 | if (FPO->isFast()) |
Michael Ilseman | 15c13d3 | 2012-11-27 00:42:44 +0000 | [diff] [blame] | 1247 | Out << " fast"; |
| 1248 | else { |
Sanjay Patel | 00e900a | 2017-11-06 16:27:15 +0000 | [diff] [blame] | 1249 | if (FPO->hasAllowReassoc()) |
| 1250 | Out << " reassoc"; |
Michael Ilseman | 15c13d3 | 2012-11-27 00:42:44 +0000 | [diff] [blame] | 1251 | if (FPO->hasNoNaNs()) |
| 1252 | Out << " nnan"; |
| 1253 | if (FPO->hasNoInfs()) |
| 1254 | Out << " ninf"; |
| 1255 | if (FPO->hasNoSignedZeros()) |
| 1256 | Out << " nsz"; |
| 1257 | if (FPO->hasAllowReciprocal()) |
| 1258 | Out << " arcp"; |
Adam Nemet | 5c57c11 | 2017-03-28 20:11:52 +0000 | [diff] [blame] | 1259 | if (FPO->hasAllowContract()) |
| 1260 | Out << " contract"; |
Sanjay Patel | 00e900a | 2017-11-06 16:27:15 +0000 | [diff] [blame] | 1261 | if (FPO->hasApproxFunc()) |
| 1262 | Out << " afn"; |
Michael Ilseman | 15c13d3 | 2012-11-27 00:42:44 +0000 | [diff] [blame] | 1263 | } |
| 1264 | } |
| 1265 | |
Dan Gohman | 1224c38 | 2009-07-20 21:19:07 +0000 | [diff] [blame] | 1266 | if (const OverflowingBinaryOperator *OBO = |
| 1267 | dyn_cast<OverflowingBinaryOperator>(U)) { |
Dan Gohman | 5078f84 | 2009-08-20 17:11:38 +0000 | [diff] [blame] | 1268 | if (OBO->hasNoUnsignedWrap()) |
Dan Gohman | 59858cf | 2009-07-27 16:11:46 +0000 | [diff] [blame] | 1269 | Out << " nuw"; |
Dan Gohman | 5078f84 | 2009-08-20 17:11:38 +0000 | [diff] [blame] | 1270 | if (OBO->hasNoSignedWrap()) |
Dan Gohman | 59858cf | 2009-07-27 16:11:46 +0000 | [diff] [blame] | 1271 | Out << " nsw"; |
Chris Lattner | 35bda89 | 2011-02-06 21:44:57 +0000 | [diff] [blame] | 1272 | } else if (const PossiblyExactOperator *Div = |
| 1273 | dyn_cast<PossiblyExactOperator>(U)) { |
Dan Gohman | 1224c38 | 2009-07-20 21:19:07 +0000 | [diff] [blame] | 1274 | if (Div->isExact()) |
Dan Gohman | 59858cf | 2009-07-27 16:11:46 +0000 | [diff] [blame] | 1275 | Out << " exact"; |
Dan Gohman | dd8004d | 2009-07-27 21:53:46 +0000 | [diff] [blame] | 1276 | } else if (const GEPOperator *GEP = dyn_cast<GEPOperator>(U)) { |
| 1277 | if (GEP->isInBounds()) |
| 1278 | Out << " inbounds"; |
Dan Gohman | 1224c38 | 2009-07-20 21:19:07 +0000 | [diff] [blame] | 1279 | } |
| 1280 | } |
| 1281 | |
Dan Gohman | 40cf12f | 2010-07-14 20:57:55 +0000 | [diff] [blame] | 1282 | static void WriteConstantInternal(raw_ostream &Out, const Constant *CV, |
| 1283 | TypePrinting &TypePrinter, |
Dan Gohman | 3bdfbf5 | 2010-07-20 23:55:01 +0000 | [diff] [blame] | 1284 | SlotTracker *Machine, |
| 1285 | const Module *Context) { |
Zhou Sheng | 6b6b6ef | 2007-01-11 12:24:14 +0000 | [diff] [blame] | 1286 | if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) { |
Duncan Sands | b0bc6c3 | 2010-02-15 16:12:20 +0000 | [diff] [blame] | 1287 | if (CI->getType()->isIntegerTy(1)) { |
Reid Spencer | 579dca1 | 2007-01-12 04:24:46 +0000 | [diff] [blame] | 1288 | Out << (CI->getZExtValue() ? "true" : "false"); |
Chris Lattner | fad86b0 | 2008-08-17 07:19:36 +0000 | [diff] [blame] | 1289 | return; |
| 1290 | } |
| 1291 | Out << CI->getValue(); |
| 1292 | return; |
| 1293 | } |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 1294 | |
Chris Lattner | fad86b0 | 2008-08-17 07:19:36 +0000 | [diff] [blame] | 1295 | if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) { |
Serguei Katkov | c849a0c | 2017-04-21 02:52:17 +0000 | [diff] [blame] | 1296 | const APFloat &APF = CFP->getValueAPF(); |
| 1297 | if (&APF.getSemantics() == &APFloat::IEEEsingle() || |
| 1298 | &APF.getSemantics() == &APFloat::IEEEdouble()) { |
Dale Johannesen | 9d5f456 | 2007-09-12 03:30:33 +0000 | [diff] [blame] | 1299 | // We would like to output the FP constant value in exponential notation, |
| 1300 | // but we cannot do this if doing so will lose precision. Check here to |
| 1301 | // make sure that we only output it in exponential format if we can parse |
| 1302 | // the value back and get the same value. |
| 1303 | // |
Dale Johannesen | 541ed9f | 2009-01-21 20:32:55 +0000 | [diff] [blame] | 1304 | bool ignored; |
Serguei Katkov | c849a0c | 2017-04-21 02:52:17 +0000 | [diff] [blame] | 1305 | bool isDouble = &APF.getSemantics() == &APFloat::IEEEdouble(); |
| 1306 | bool isInf = APF.isInfinity(); |
| 1307 | bool isNaN = APF.isNaN(); |
Justin Bogner | 2cb4621 | 2015-12-04 01:14:24 +0000 | [diff] [blame] | 1308 | if (!isInf && !isNaN) { |
Serguei Katkov | c849a0c | 2017-04-21 02:52:17 +0000 | [diff] [blame] | 1309 | double Val = isDouble ? APF.convertToDouble() : APF.convertToFloat(); |
Dan Gohman | ce16339 | 2011-12-17 00:04:22 +0000 | [diff] [blame] | 1310 | SmallString<128> StrVal; |
Serguei Katkov | c849a0c | 2017-04-21 02:52:17 +0000 | [diff] [blame] | 1311 | APF.toString(StrVal, 6, 0, false); |
Dan Gohman | ce16339 | 2011-12-17 00:04:22 +0000 | [diff] [blame] | 1312 | // Check to make sure that the stringized number is not some string like |
| 1313 | // "Inf" or NaN, that atof will accept, but the lexer will not. Check |
| 1314 | // that the string matches the "[-+]?[0-9]" regex. |
| 1315 | // |
Serguei Katkov | 9bb6c3a | 2017-04-21 06:14:38 +0000 | [diff] [blame] | 1316 | assert(((StrVal[0] >= '0' && StrVal[0] <= '9') || |
| 1317 | ((StrVal[0] == '-' || StrVal[0] == '+') && |
| 1318 | (StrVal[1] >= '0' && StrVal[1] <= '9'))) && |
| 1319 | "[-+]?[0-9] regex does not match!"); |
Serguei Katkov | c849a0c | 2017-04-21 02:52:17 +0000 | [diff] [blame] | 1320 | // Reparse stringized version! |
| 1321 | if (APFloat(APFloat::IEEEdouble(), StrVal).convertToDouble() == Val) { |
| 1322 | Out << StrVal; |
| 1323 | return; |
Dale Johannesen | 9d5f456 | 2007-09-12 03:30:33 +0000 | [diff] [blame] | 1324 | } |
Chris Lattner | 66e810b | 2002-04-18 18:53:13 +0000 | [diff] [blame] | 1325 | } |
Dale Johannesen | 9d5f456 | 2007-09-12 03:30:33 +0000 | [diff] [blame] | 1326 | // Otherwise we could not reparse it to exactly the same value, so we must |
Dale Johannesen | 541ed9f | 2009-01-21 20:32:55 +0000 | [diff] [blame] | 1327 | // output the string in hexadecimal format! Note that loading and storing |
| 1328 | // floating point types changes the bits of NaNs on some hosts, notably |
| 1329 | // x86, so we must not use these types. |
Benjamin Kramer | 571832b | 2014-03-15 18:47:07 +0000 | [diff] [blame] | 1330 | static_assert(sizeof(double) == sizeof(uint64_t), |
| 1331 | "assuming that double is 64 bits!"); |
Serguei Katkov | c849a0c | 2017-04-21 02:52:17 +0000 | [diff] [blame] | 1332 | APFloat apf = APF; |
Justin Bogner | 2cb4621 | 2015-12-04 01:14:24 +0000 | [diff] [blame] | 1333 | // Floats are represented in ASCII IR as double, convert. |
Dale Johannesen | 541ed9f | 2009-01-21 20:32:55 +0000 | [diff] [blame] | 1334 | if (!isDouble) |
Stephan Bergmann | 20a600c | 2016-12-14 11:57:17 +0000 | [diff] [blame] | 1335 | apf.convert(APFloat::IEEEdouble(), APFloat::rmNearestTiesToEven, |
Dale Johannesen | 541ed9f | 2009-01-21 20:32:55 +0000 | [diff] [blame] | 1336 | &ignored); |
Justin Bogner | d8def4a | 2015-12-04 02:14:34 +0000 | [diff] [blame] | 1337 | Out << format_hex(apf.bitcastToAPInt().getZExtValue(), 0, /*Upper=*/true); |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1338 | return; |
| 1339 | } |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 1340 | |
Tobias Grosser | 057beb8 | 2012-05-24 15:59:06 +0000 | [diff] [blame] | 1341 | // Either half, or some form of long double. |
| 1342 | // These appear as a magic letter identifying the type, then a |
| 1343 | // fixed number of hex digits. |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1344 | Out << "0x"; |
Serguei Katkov | c849a0c | 2017-04-21 02:52:17 +0000 | [diff] [blame] | 1345 | APInt API = APF.bitcastToAPInt(); |
| 1346 | if (&APF.getSemantics() == &APFloat::x87DoubleExtended()) { |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1347 | Out << 'K'; |
Justin Bogner | d8def4a | 2015-12-04 02:14:34 +0000 | [diff] [blame] | 1348 | Out << format_hex_no_prefix(API.getHiBits(16).getZExtValue(), 4, |
| 1349 | /*Upper=*/true); |
| 1350 | Out << format_hex_no_prefix(API.getLoBits(64).getZExtValue(), 16, |
| 1351 | /*Upper=*/true); |
Dale Johannesen | 1b25cb2 | 2009-03-23 21:16:53 +0000 | [diff] [blame] | 1352 | return; |
Serguei Katkov | c849a0c | 2017-04-21 02:52:17 +0000 | [diff] [blame] | 1353 | } else if (&APF.getSemantics() == &APFloat::IEEEquad()) { |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1354 | Out << 'L'; |
Justin Bogner | d8def4a | 2015-12-04 02:14:34 +0000 | [diff] [blame] | 1355 | Out << format_hex_no_prefix(API.getLoBits(64).getZExtValue(), 16, |
| 1356 | /*Upper=*/true); |
| 1357 | Out << format_hex_no_prefix(API.getHiBits(64).getZExtValue(), 16, |
| 1358 | /*Upper=*/true); |
Serguei Katkov | c849a0c | 2017-04-21 02:52:17 +0000 | [diff] [blame] | 1359 | } else if (&APF.getSemantics() == &APFloat::PPCDoubleDouble()) { |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1360 | Out << 'M'; |
Justin Bogner | d8def4a | 2015-12-04 02:14:34 +0000 | [diff] [blame] | 1361 | Out << format_hex_no_prefix(API.getLoBits(64).getZExtValue(), 16, |
| 1362 | /*Upper=*/true); |
| 1363 | Out << format_hex_no_prefix(API.getHiBits(64).getZExtValue(), 16, |
| 1364 | /*Upper=*/true); |
Serguei Katkov | c849a0c | 2017-04-21 02:52:17 +0000 | [diff] [blame] | 1365 | } else if (&APF.getSemantics() == &APFloat::IEEEhalf()) { |
Tobias Grosser | 057beb8 | 2012-05-24 15:59:06 +0000 | [diff] [blame] | 1366 | Out << 'H'; |
Justin Bogner | d8def4a | 2015-12-04 02:14:34 +0000 | [diff] [blame] | 1367 | Out << format_hex_no_prefix(API.getZExtValue(), 4, |
| 1368 | /*Upper=*/true); |
Tobias Grosser | 057beb8 | 2012-05-24 15:59:06 +0000 | [diff] [blame] | 1369 | } else |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1370 | llvm_unreachable("Unsupported floating point type"); |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1371 | return; |
| 1372 | } |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 1373 | |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1374 | if (isa<ConstantAggregateZero>(CV)) { |
Chris Lattner | de512b5 | 2004-02-15 05:55:15 +0000 | [diff] [blame] | 1375 | Out << "zeroinitializer"; |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1376 | return; |
| 1377 | } |
Andrew Trick | 18801ec | 2011-09-30 19:48:58 +0000 | [diff] [blame] | 1378 | |
Chris Lattner | 73050e1 | 2009-10-28 03:38:12 +0000 | [diff] [blame] | 1379 | if (const BlockAddress *BA = dyn_cast<BlockAddress>(CV)) { |
| 1380 | Out << "blockaddress("; |
Dan Gohman | 3bdfbf5 | 2010-07-20 23:55:01 +0000 | [diff] [blame] | 1381 | WriteAsOperandInternal(Out, BA->getFunction(), &TypePrinter, Machine, |
| 1382 | Context); |
Chris Lattner | 73050e1 | 2009-10-28 03:38:12 +0000 | [diff] [blame] | 1383 | Out << ", "; |
Dan Gohman | 3bdfbf5 | 2010-07-20 23:55:01 +0000 | [diff] [blame] | 1384 | WriteAsOperandInternal(Out, BA->getBasicBlock(), &TypePrinter, Machine, |
| 1385 | Context); |
Chris Lattner | 73050e1 | 2009-10-28 03:38:12 +0000 | [diff] [blame] | 1386 | Out << ")"; |
| 1387 | return; |
| 1388 | } |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 1389 | |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1390 | if (const ConstantArray *CA = dyn_cast<ConstantArray>(CV)) { |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 1391 | Type *ETy = CA->getType()->getElementType(); |
Chris Lattner | 18c7f80 | 2012-02-05 02:29:43 +0000 | [diff] [blame] | 1392 | Out << '['; |
| 1393 | TypePrinter.print(ETy, Out); |
| 1394 | Out << ' '; |
| 1395 | WriteAsOperandInternal(Out, CA->getOperand(0), |
| 1396 | &TypePrinter, Machine, |
| 1397 | Context); |
| 1398 | for (unsigned i = 1, e = CA->getNumOperands(); i != e; ++i) { |
| 1399 | Out << ", "; |
Chris Lattner | 8b10b69 | 2012-01-31 03:15:40 +0000 | [diff] [blame] | 1400 | TypePrinter.print(ETy, Out); |
| 1401 | Out << ' '; |
Chris Lattner | 18c7f80 | 2012-02-05 02:29:43 +0000 | [diff] [blame] | 1402 | WriteAsOperandInternal(Out, CA->getOperand(i), &TypePrinter, Machine, |
Chris Lattner | 8b10b69 | 2012-01-31 03:15:40 +0000 | [diff] [blame] | 1403 | Context); |
Chris Lattner | 7a716ad | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 1404 | } |
Chris Lattner | 18c7f80 | 2012-02-05 02:29:43 +0000 | [diff] [blame] | 1405 | Out << ']'; |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1406 | return; |
| 1407 | } |
Michael Ilseman | 407a616 | 2012-11-15 22:34:00 +0000 | [diff] [blame] | 1408 | |
Chris Lattner | d59ae90 | 2012-01-26 02:32:04 +0000 | [diff] [blame] | 1409 | if (const ConstantDataArray *CA = dyn_cast<ConstantDataArray>(CV)) { |
| 1410 | // As a special case, print the array as a string if it is an array of |
| 1411 | // i8 with ConstantInt values. |
| 1412 | if (CA->isString()) { |
| 1413 | Out << "c\""; |
Jonas Devlieghere | 7eeba25 | 2018-05-31 17:01:42 +0000 | [diff] [blame] | 1414 | printEscapedString(CA->getAsString(), Out); |
Chris Lattner | d59ae90 | 2012-01-26 02:32:04 +0000 | [diff] [blame] | 1415 | Out << '"'; |
| 1416 | return; |
| 1417 | } |
| 1418 | |
| 1419 | Type *ETy = CA->getType()->getElementType(); |
| 1420 | Out << '['; |
Chris Lattner | 8b10b69 | 2012-01-31 03:15:40 +0000 | [diff] [blame] | 1421 | TypePrinter.print(ETy, Out); |
| 1422 | Out << ' '; |
| 1423 | WriteAsOperandInternal(Out, CA->getElementAsConstant(0), |
| 1424 | &TypePrinter, Machine, |
| 1425 | Context); |
| 1426 | for (unsigned i = 1, e = CA->getNumElements(); i != e; ++i) { |
| 1427 | Out << ", "; |
Chris Lattner | d59ae90 | 2012-01-26 02:32:04 +0000 | [diff] [blame] | 1428 | TypePrinter.print(ETy, Out); |
| 1429 | Out << ' '; |
Chris Lattner | 8b10b69 | 2012-01-31 03:15:40 +0000 | [diff] [blame] | 1430 | WriteAsOperandInternal(Out, CA->getElementAsConstant(i), &TypePrinter, |
| 1431 | Machine, Context); |
Chris Lattner | d59ae90 | 2012-01-26 02:32:04 +0000 | [diff] [blame] | 1432 | } |
Chris Lattner | 8b10b69 | 2012-01-31 03:15:40 +0000 | [diff] [blame] | 1433 | Out << ']'; |
Chris Lattner | d59ae90 | 2012-01-26 02:32:04 +0000 | [diff] [blame] | 1434 | return; |
| 1435 | } |
| 1436 | |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1437 | if (const ConstantStruct *CS = dyn_cast<ConstantStruct>(CV)) { |
Andrew Lenharth | 43f344a | 2007-01-08 18:21:30 +0000 | [diff] [blame] | 1438 | if (CS->getType()->isPacked()) |
| 1439 | Out << '<'; |
Misha Brukman | 40c732c | 2004-06-04 21:11:51 +0000 | [diff] [blame] | 1440 | Out << '{'; |
Jim Laskey | a3f332b | 2006-02-25 12:27:03 +0000 | [diff] [blame] | 1441 | unsigned N = CS->getNumOperands(); |
| 1442 | if (N) { |
Chris Lattner | 2423303 | 2008-08-19 04:47:09 +0000 | [diff] [blame] | 1443 | Out << ' '; |
Chris Lattner | 0f7364b | 2009-02-28 21:26:53 +0000 | [diff] [blame] | 1444 | TypePrinter.print(CS->getOperand(0)->getType(), Out); |
Dan Gohman | 8dae138 | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1445 | Out << ' '; |
Chris Lattner | 7a716ad | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 1446 | |
Dan Gohman | 3bdfbf5 | 2010-07-20 23:55:01 +0000 | [diff] [blame] | 1447 | WriteAsOperandInternal(Out, CS->getOperand(0), &TypePrinter, Machine, |
| 1448 | Context); |
Chris Lattner | 7a716ad | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 1449 | |
Jim Laskey | a3f332b | 2006-02-25 12:27:03 +0000 | [diff] [blame] | 1450 | for (unsigned i = 1; i < N; i++) { |
Chris Lattner | 7a716ad | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 1451 | Out << ", "; |
Chris Lattner | 0f7364b | 2009-02-28 21:26:53 +0000 | [diff] [blame] | 1452 | TypePrinter.print(CS->getOperand(i)->getType(), Out); |
Dan Gohman | 8dae138 | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1453 | Out << ' '; |
Chris Lattner | 7a716ad | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 1454 | |
Dan Gohman | 3bdfbf5 | 2010-07-20 23:55:01 +0000 | [diff] [blame] | 1455 | WriteAsOperandInternal(Out, CS->getOperand(i), &TypePrinter, Machine, |
| 1456 | Context); |
Chris Lattner | 7a716ad | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 1457 | } |
Dan Gohman | 8dae138 | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1458 | Out << ' '; |
Chris Lattner | 7a716ad | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 1459 | } |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 1460 | |
Dan Gohman | 8dae138 | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1461 | Out << '}'; |
Andrew Lenharth | 43f344a | 2007-01-08 18:21:30 +0000 | [diff] [blame] | 1462 | if (CS->getType()->isPacked()) |
| 1463 | Out << '>'; |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1464 | return; |
| 1465 | } |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 1466 | |
Chris Lattner | d59ae90 | 2012-01-26 02:32:04 +0000 | [diff] [blame] | 1467 | if (isa<ConstantVector>(CV) || isa<ConstantDataVector>(CV)) { |
| 1468 | Type *ETy = CV->getType()->getVectorElementType(); |
Dan Gohman | 7dfa07f | 2009-02-11 00:25:25 +0000 | [diff] [blame] | 1469 | Out << '<'; |
Chris Lattner | 0f7364b | 2009-02-28 21:26:53 +0000 | [diff] [blame] | 1470 | TypePrinter.print(ETy, Out); |
Dan Gohman | 8dae138 | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1471 | Out << ' '; |
Chris Lattner | d59ae90 | 2012-01-26 02:32:04 +0000 | [diff] [blame] | 1472 | WriteAsOperandInternal(Out, CV->getAggregateElement(0U), &TypePrinter, |
| 1473 | Machine, Context); |
| 1474 | for (unsigned i = 1, e = CV->getType()->getVectorNumElements(); i != e;++i){ |
Chris Lattner | 4667b71 | 2008-08-19 05:26:17 +0000 | [diff] [blame] | 1475 | Out << ", "; |
Chris Lattner | 0f7364b | 2009-02-28 21:26:53 +0000 | [diff] [blame] | 1476 | TypePrinter.print(ETy, Out); |
Dan Gohman | 8dae138 | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1477 | Out << ' '; |
Chris Lattner | d59ae90 | 2012-01-26 02:32:04 +0000 | [diff] [blame] | 1478 | WriteAsOperandInternal(Out, CV->getAggregateElement(i), &TypePrinter, |
| 1479 | Machine, Context); |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1480 | } |
Dan Gohman | 7dfa07f | 2009-02-11 00:25:25 +0000 | [diff] [blame] | 1481 | Out << '>'; |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1482 | return; |
| 1483 | } |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 1484 | |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1485 | if (isa<ConstantPointerNull>(CV)) { |
Chris Lattner | 7a716ad | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 1486 | Out << "null"; |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1487 | return; |
| 1488 | } |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 1489 | |
David Majnemer | 83fc12a | 2015-11-11 21:57:16 +0000 | [diff] [blame] | 1490 | if (isa<ConstantTokenNone>(CV)) { |
| 1491 | Out << "none"; |
| 1492 | return; |
| 1493 | } |
| 1494 | |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1495 | if (isa<UndefValue>(CV)) { |
Chris Lattner | b976e66 | 2004-10-16 18:08:06 +0000 | [diff] [blame] | 1496 | Out << "undef"; |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1497 | return; |
| 1498 | } |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 1499 | |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1500 | if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) { |
Reid Spencer | 81dfeb3 | 2006-12-04 05:19:18 +0000 | [diff] [blame] | 1501 | Out << CE->getOpcodeName(); |
Dan Gohman | 59858cf | 2009-07-27 16:11:46 +0000 | [diff] [blame] | 1502 | WriteOptimizationInfo(Out, CE); |
Reid Spencer | 81dfeb3 | 2006-12-04 05:19:18 +0000 | [diff] [blame] | 1503 | if (CE->isCompare()) |
Tim Northover | 3ed44cd | 2016-08-17 20:25:25 +0000 | [diff] [blame] | 1504 | Out << ' ' << CmpInst::getPredicateName( |
| 1505 | static_cast<CmpInst::Predicate>(CE->getPredicate())); |
Reid Spencer | 81dfeb3 | 2006-12-04 05:19:18 +0000 | [diff] [blame] | 1506 | Out << " ("; |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 1507 | |
Peter Collingbourne | ca668e1 | 2016-11-10 22:34:55 +0000 | [diff] [blame] | 1508 | Optional<unsigned> InRangeOp; |
David Blaikie | 5a70dd1 | 2015-03-13 18:20:45 +0000 | [diff] [blame] | 1509 | if (const GEPOperator *GEP = dyn_cast<GEPOperator>(CE)) { |
David Blaikie | 0552dc7 | 2015-07-29 20:26:23 +0000 | [diff] [blame] | 1510 | TypePrinter.print(GEP->getSourceElementType(), Out); |
David Blaikie | 5a70dd1 | 2015-03-13 18:20:45 +0000 | [diff] [blame] | 1511 | Out << ", "; |
Peter Collingbourne | ca668e1 | 2016-11-10 22:34:55 +0000 | [diff] [blame] | 1512 | InRangeOp = GEP->getInRangeIndex(); |
| 1513 | if (InRangeOp) |
| 1514 | ++*InRangeOp; |
David Blaikie | 5a70dd1 | 2015-03-13 18:20:45 +0000 | [diff] [blame] | 1515 | } |
| 1516 | |
Vikram S. Adve | b4dbb44 | 2002-07-14 23:14:45 +0000 | [diff] [blame] | 1517 | for (User::const_op_iterator OI=CE->op_begin(); OI != CE->op_end(); ++OI) { |
Zachary Turner | 005ec66 | 2016-11-11 23:58:11 +0000 | [diff] [blame] | 1518 | if (InRangeOp && unsigned(OI - CE->op_begin()) == *InRangeOp) |
Peter Collingbourne | ca668e1 | 2016-11-10 22:34:55 +0000 | [diff] [blame] | 1519 | Out << "inrange "; |
Chris Lattner | 0f7364b | 2009-02-28 21:26:53 +0000 | [diff] [blame] | 1520 | TypePrinter.print((*OI)->getType(), Out); |
Dan Gohman | 8dae138 | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1521 | Out << ' '; |
Dan Gohman | 3bdfbf5 | 2010-07-20 23:55:01 +0000 | [diff] [blame] | 1522 | WriteAsOperandInternal(Out, *OI, &TypePrinter, Machine, Context); |
Vikram S. Adve | b4dbb44 | 2002-07-14 23:14:45 +0000 | [diff] [blame] | 1523 | if (OI+1 != CE->op_end()) |
Chris Lattner | c188eeb | 2002-07-30 18:54:25 +0000 | [diff] [blame] | 1524 | Out << ", "; |
Vikram S. Adve | b4dbb44 | 2002-07-14 23:14:45 +0000 | [diff] [blame] | 1525 | } |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 1526 | |
Dan Gohman | 995be7d | 2008-05-31 19:12:39 +0000 | [diff] [blame] | 1527 | if (CE->hasIndices()) { |
Jay Foad | d30aa5a | 2011-04-13 15:22:40 +0000 | [diff] [blame] | 1528 | ArrayRef<unsigned> Indices = CE->getIndices(); |
Dan Gohman | 995be7d | 2008-05-31 19:12:39 +0000 | [diff] [blame] | 1529 | for (unsigned i = 0, e = Indices.size(); i != e; ++i) |
| 1530 | Out << ", " << Indices[i]; |
| 1531 | } |
| 1532 | |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1533 | if (CE->isCast()) { |
Chris Lattner | 95586b8 | 2002-08-15 19:37:43 +0000 | [diff] [blame] | 1534 | Out << " to "; |
Chris Lattner | 0f7364b | 2009-02-28 21:26:53 +0000 | [diff] [blame] | 1535 | TypePrinter.print(CE->getType(), Out); |
Chris Lattner | 95586b8 | 2002-08-15 19:37:43 +0000 | [diff] [blame] | 1536 | } |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 1537 | |
Misha Brukman | 40c732c | 2004-06-04 21:11:51 +0000 | [diff] [blame] | 1538 | Out << ')'; |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1539 | return; |
Chris Lattner | 7a716ad | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 1540 | } |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 1541 | |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1542 | Out << "<placeholder or erroneous Constant>"; |
Chris Lattner | 7a716ad | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 1543 | } |
| 1544 | |
Duncan P. N. Exon Smith | 120c186 | 2015-01-12 23:45:31 +0000 | [diff] [blame] | 1545 | static void writeMDTuple(raw_ostream &Out, const MDTuple *Node, |
| 1546 | TypePrinting *TypePrinter, SlotTracker *Machine, |
| 1547 | const Module *Context) { |
Chris Lattner | 85b1912 | 2009-12-31 02:31:59 +0000 | [diff] [blame] | 1548 | Out << "!{"; |
| 1549 | for (unsigned mi = 0, me = Node->getNumOperands(); mi != me; ++mi) { |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 1550 | const Metadata *MD = Node->getOperand(mi); |
| 1551 | if (!MD) |
Chris Lattner | 85b1912 | 2009-12-31 02:31:59 +0000 | [diff] [blame] | 1552 | Out << "null"; |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 1553 | else if (auto *MDV = dyn_cast<ValueAsMetadata>(MD)) { |
| 1554 | Value *V = MDV->getValue(); |
Chris Lattner | 85b1912 | 2009-12-31 02:31:59 +0000 | [diff] [blame] | 1555 | TypePrinter->print(V->getType(), Out); |
| 1556 | Out << ' '; |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 1557 | WriteAsOperandInternal(Out, V, TypePrinter, Machine, Context); |
| 1558 | } else { |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 1559 | WriteAsOperandInternal(Out, MD, TypePrinter, Machine, Context); |
Chris Lattner | 85b1912 | 2009-12-31 02:31:59 +0000 | [diff] [blame] | 1560 | } |
| 1561 | if (mi + 1 != me) |
| 1562 | Out << ", "; |
| 1563 | } |
Andrew Trick | 18801ec | 2011-09-30 19:48:58 +0000 | [diff] [blame] | 1564 | |
Chris Lattner | 85b1912 | 2009-12-31 02:31:59 +0000 | [diff] [blame] | 1565 | Out << "}"; |
| 1566 | } |
| 1567 | |
Duncan P. N. Exon Smith | d640962 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 1568 | namespace { |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1569 | |
Duncan P. N. Exon Smith | d640962 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 1570 | struct FieldSeparator { |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1571 | bool Skip = true; |
Duncan P. N. Exon Smith | 9f8d403 | 2015-02-21 01:02:18 +0000 | [diff] [blame] | 1572 | const char *Sep; |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1573 | |
| 1574 | FieldSeparator(const char *Sep = ", ") : Sep(Sep) {} |
Duncan P. N. Exon Smith | d640962 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 1575 | }; |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1576 | |
Duncan P. N. Exon Smith | d640962 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 1577 | raw_ostream &operator<<(raw_ostream &OS, FieldSeparator &FS) { |
| 1578 | if (FS.Skip) { |
| 1579 | FS.Skip = false; |
| 1580 | return OS; |
| 1581 | } |
Duncan P. N. Exon Smith | 9f8d403 | 2015-02-21 01:02:18 +0000 | [diff] [blame] | 1582 | return OS << FS.Sep; |
Duncan P. N. Exon Smith | d640962 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 1583 | } |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1584 | |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1585 | struct MDFieldPrinter { |
| 1586 | raw_ostream &Out; |
| 1587 | FieldSeparator FS; |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1588 | TypePrinting *TypePrinter = nullptr; |
| 1589 | SlotTracker *Machine = nullptr; |
| 1590 | const Module *Context = nullptr; |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1591 | |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1592 | explicit MDFieldPrinter(raw_ostream &Out) : Out(Out) {} |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1593 | MDFieldPrinter(raw_ostream &Out, TypePrinting *TypePrinter, |
| 1594 | SlotTracker *Machine, const Module *Context) |
| 1595 | : Out(Out), TypePrinter(TypePrinter), Machine(Machine), Context(Context) { |
| 1596 | } |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1597 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1598 | void printTag(const DINode *N); |
Amjad Aboud | 7db3980 | 2015-12-10 12:56:35 +0000 | [diff] [blame] | 1599 | void printMacinfoType(const DIMacroNode *N); |
Scott Linder | 4863252 | 2018-02-12 19:45:54 +0000 | [diff] [blame] | 1600 | void printChecksum(const DIFile::ChecksumInfo<StringRef> &N); |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1601 | void printString(StringRef Name, StringRef Value, |
| 1602 | bool ShouldSkipEmpty = true); |
| 1603 | void printMetadata(StringRef Name, const Metadata *MD, |
| 1604 | bool ShouldSkipNull = true); |
| 1605 | template <class IntTy> |
| 1606 | void printInt(StringRef Name, IntTy Int, bool ShouldSkipZero = true); |
David Blaikie | bf471b7 | 2016-08-24 18:29:49 +0000 | [diff] [blame] | 1607 | void printBool(StringRef Name, bool Value, Optional<bool> Default = None); |
Leny Kholodov | d9478f8 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 1608 | void printDIFlags(StringRef Name, DINode::DIFlags Flags); |
Paul Robinson | ccefd88 | 2018-11-28 21:14:32 +0000 | [diff] [blame] | 1609 | void printDISPFlags(StringRef Name, DISubprogram::DISPFlags Flags); |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1610 | template <class IntTy, class Stringifier> |
| 1611 | void printDwarfEnum(StringRef Name, IntTy Value, Stringifier toString, |
| 1612 | bool ShouldSkipZero = true); |
Adrian Prantl | 39bb84a | 2016-03-31 23:56:58 +0000 | [diff] [blame] | 1613 | void printEmissionKind(StringRef Name, DICompileUnit::DebugEmissionKind EK); |
David Blaikie | cf8a4a5 | 2018-08-16 21:29:55 +0000 | [diff] [blame] | 1614 | void printNameTableKind(StringRef Name, |
| 1615 | DICompileUnit::DebugNameTableKind NTK); |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1616 | }; |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1617 | |
| 1618 | } // end anonymous namespace |
Duncan P. N. Exon Smith | d640962 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 1619 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1620 | void MDFieldPrinter::printTag(const DINode *N) { |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1621 | Out << FS << "tag: "; |
Mehdi Amini | f9bb6bc | 2016-10-05 05:59:29 +0000 | [diff] [blame] | 1622 | auto Tag = dwarf::TagString(N->getTag()); |
| 1623 | if (!Tag.empty()) |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1624 | Out << Tag; |
| 1625 | else |
| 1626 | Out << N->getTag(); |
| 1627 | } |
| 1628 | |
Amjad Aboud | 7db3980 | 2015-12-10 12:56:35 +0000 | [diff] [blame] | 1629 | void MDFieldPrinter::printMacinfoType(const DIMacroNode *N) { |
| 1630 | Out << FS << "type: "; |
Mehdi Amini | f9bb6bc | 2016-10-05 05:59:29 +0000 | [diff] [blame] | 1631 | auto Type = dwarf::MacinfoString(N->getMacinfoType()); |
| 1632 | if (!Type.empty()) |
Amjad Aboud | 7db3980 | 2015-12-10 12:56:35 +0000 | [diff] [blame] | 1633 | Out << Type; |
| 1634 | else |
| 1635 | Out << N->getMacinfoType(); |
| 1636 | } |
| 1637 | |
Scott Linder | 4863252 | 2018-02-12 19:45:54 +0000 | [diff] [blame] | 1638 | void MDFieldPrinter::printChecksum( |
| 1639 | const DIFile::ChecksumInfo<StringRef> &Checksum) { |
| 1640 | Out << FS << "checksumkind: " << Checksum.getKindAsString(); |
| 1641 | printString("checksum", Checksum.Value, /* ShouldSkipEmpty */ false); |
Amjad Aboud | 4e2e80b | 2016-12-25 10:12:09 +0000 | [diff] [blame] | 1642 | } |
| 1643 | |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1644 | void MDFieldPrinter::printString(StringRef Name, StringRef Value, |
| 1645 | bool ShouldSkipEmpty) { |
| 1646 | if (ShouldSkipEmpty && Value.empty()) |
| 1647 | return; |
| 1648 | |
| 1649 | Out << FS << Name << ": \""; |
Jonas Devlieghere | 7eeba25 | 2018-05-31 17:01:42 +0000 | [diff] [blame] | 1650 | printEscapedString(Value, Out); |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1651 | Out << "\""; |
| 1652 | } |
| 1653 | |
Duncan P. N. Exon Smith | 8b07f1b | 2015-02-06 22:27:22 +0000 | [diff] [blame] | 1654 | static void writeMetadataAsOperand(raw_ostream &Out, const Metadata *MD, |
| 1655 | TypePrinting *TypePrinter, |
| 1656 | SlotTracker *Machine, |
| 1657 | const Module *Context) { |
| 1658 | if (!MD) { |
| 1659 | Out << "null"; |
| 1660 | return; |
| 1661 | } |
| 1662 | WriteAsOperandInternal(Out, MD, TypePrinter, Machine, Context); |
| 1663 | } |
| 1664 | |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1665 | void MDFieldPrinter::printMetadata(StringRef Name, const Metadata *MD, |
| 1666 | bool ShouldSkipNull) { |
| 1667 | if (ShouldSkipNull && !MD) |
Duncan P. N. Exon Smith | 9973291 | 2015-02-28 22:16:56 +0000 | [diff] [blame] | 1668 | return; |
| 1669 | |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1670 | Out << FS << Name << ": "; |
| 1671 | writeMetadataAsOperand(Out, MD, TypePrinter, Machine, Context); |
| 1672 | } |
| 1673 | |
| 1674 | template <class IntTy> |
| 1675 | void MDFieldPrinter::printInt(StringRef Name, IntTy Int, bool ShouldSkipZero) { |
| 1676 | if (ShouldSkipZero && !Int) |
| 1677 | return; |
| 1678 | |
| 1679 | Out << FS << Name << ": " << Int; |
| 1680 | } |
| 1681 | |
David Blaikie | bf471b7 | 2016-08-24 18:29:49 +0000 | [diff] [blame] | 1682 | void MDFieldPrinter::printBool(StringRef Name, bool Value, |
| 1683 | Optional<bool> Default) { |
| 1684 | if (Default && Value == *Default) |
| 1685 | return; |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1686 | Out << FS << Name << ": " << (Value ? "true" : "false"); |
| 1687 | } |
| 1688 | |
Leny Kholodov | d9478f8 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 1689 | void MDFieldPrinter::printDIFlags(StringRef Name, DINode::DIFlags Flags) { |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1690 | if (!Flags) |
| 1691 | return; |
| 1692 | |
| 1693 | Out << FS << Name << ": "; |
| 1694 | |
Leny Kholodov | d9478f8 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 1695 | SmallVector<DINode::DIFlags, 8> SplitFlags; |
| 1696 | auto Extra = DINode::splitFlags(Flags, SplitFlags); |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1697 | |
| 1698 | FieldSeparator FlagsFS(" | "); |
Leny Kholodov | d9478f8 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 1699 | for (auto F : SplitFlags) { |
Mehdi Amini | afe556b | 2016-10-01 05:57:50 +0000 | [diff] [blame] | 1700 | auto StringF = DINode::getFlagString(F); |
| 1701 | assert(!StringF.empty() && "Expected valid flag"); |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1702 | Out << FlagsFS << StringF; |
| 1703 | } |
| 1704 | if (Extra || SplitFlags.empty()) |
| 1705 | Out << FlagsFS << Extra; |
| 1706 | } |
| 1707 | |
Paul Robinson | ccefd88 | 2018-11-28 21:14:32 +0000 | [diff] [blame] | 1708 | void MDFieldPrinter::printDISPFlags(StringRef Name, |
| 1709 | DISubprogram::DISPFlags Flags) { |
| 1710 | // Always print this field, because no flags in the IR at all will be |
| 1711 | // interpreted as old-style isDefinition: true. |
| 1712 | Out << FS << Name << ": "; |
| 1713 | |
| 1714 | if (!Flags) { |
| 1715 | Out << 0; |
| 1716 | return; |
| 1717 | } |
| 1718 | |
| 1719 | SmallVector<DISubprogram::DISPFlags, 8> SplitFlags; |
| 1720 | auto Extra = DISubprogram::splitFlags(Flags, SplitFlags); |
| 1721 | |
| 1722 | FieldSeparator FlagsFS(" | "); |
| 1723 | for (auto F : SplitFlags) { |
| 1724 | auto StringF = DISubprogram::getFlagString(F); |
| 1725 | assert(!StringF.empty() && "Expected valid flag"); |
| 1726 | Out << FlagsFS << StringF; |
| 1727 | } |
| 1728 | if (Extra || SplitFlags.empty()) |
| 1729 | Out << FlagsFS << Extra; |
| 1730 | } |
| 1731 | |
Adrian Prantl | 39bb84a | 2016-03-31 23:56:58 +0000 | [diff] [blame] | 1732 | void MDFieldPrinter::printEmissionKind(StringRef Name, |
| 1733 | DICompileUnit::DebugEmissionKind EK) { |
Fangrui Song | cfc86d4 | 2018-07-06 19:26:00 +0000 | [diff] [blame] | 1734 | Out << FS << Name << ": " << DICompileUnit::emissionKindString(EK); |
Adrian Prantl | 39bb84a | 2016-03-31 23:56:58 +0000 | [diff] [blame] | 1735 | } |
| 1736 | |
David Blaikie | cf8a4a5 | 2018-08-16 21:29:55 +0000 | [diff] [blame] | 1737 | void MDFieldPrinter::printNameTableKind(StringRef Name, |
| 1738 | DICompileUnit::DebugNameTableKind NTK) { |
| 1739 | if (NTK == DICompileUnit::DebugNameTableKind::Default) |
| 1740 | return; |
| 1741 | Out << FS << Name << ": " << DICompileUnit::nameTableKindString(NTK); |
| 1742 | } |
| 1743 | |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1744 | template <class IntTy, class Stringifier> |
| 1745 | void MDFieldPrinter::printDwarfEnum(StringRef Name, IntTy Value, |
| 1746 | Stringifier toString, bool ShouldSkipZero) { |
| 1747 | if (!Value) |
| 1748 | return; |
| 1749 | |
| 1750 | Out << FS << Name << ": "; |
Mehdi Amini | f9bb6bc | 2016-10-05 05:59:29 +0000 | [diff] [blame] | 1751 | auto S = toString(Value); |
| 1752 | if (!S.empty()) |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1753 | Out << S; |
| 1754 | else |
| 1755 | Out << Value; |
Duncan P. N. Exon Smith | 9973291 | 2015-02-28 22:16:56 +0000 | [diff] [blame] | 1756 | } |
| 1757 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1758 | static void writeGenericDINode(raw_ostream &Out, const GenericDINode *N, |
| 1759 | TypePrinting *TypePrinter, SlotTracker *Machine, |
| 1760 | const Module *Context) { |
| 1761 | Out << "!GenericDINode("; |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1762 | MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); |
| 1763 | Printer.printTag(N); |
| 1764 | Printer.printString("header", N->getHeader()); |
Duncan P. N. Exon Smith | 6adbfa3 | 2015-02-03 21:54:14 +0000 | [diff] [blame] | 1765 | if (N->getNumDwarfOperands()) { |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1766 | Out << Printer.FS << "operands: {"; |
Duncan P. N. Exon Smith | 6adbfa3 | 2015-02-03 21:54:14 +0000 | [diff] [blame] | 1767 | FieldSeparator IFS; |
| 1768 | for (auto &I : N->dwarf_operands()) { |
| 1769 | Out << IFS; |
Duncan P. N. Exon Smith | 8b07f1b | 2015-02-06 22:27:22 +0000 | [diff] [blame] | 1770 | writeMetadataAsOperand(Out, I, TypePrinter, Machine, Context); |
Duncan P. N. Exon Smith | 6adbfa3 | 2015-02-03 21:54:14 +0000 | [diff] [blame] | 1771 | } |
| 1772 | Out << "}"; |
| 1773 | } |
| 1774 | Out << ")"; |
Duncan P. N. Exon Smith | 0a9f921 | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 1775 | } |
| 1776 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1777 | static void writeDILocation(raw_ostream &Out, const DILocation *DL, |
Duncan P. N. Exon Smith | d640962 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 1778 | TypePrinting *TypePrinter, SlotTracker *Machine, |
| 1779 | const Module *Context) { |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1780 | Out << "!DILocation("; |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1781 | MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); |
Duncan P. N. Exon Smith | bf13dd0 | 2015-01-14 22:14:26 +0000 | [diff] [blame] | 1782 | // Always output the line, since 0 is a relevant and important value for it. |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1783 | Printer.printInt("line", DL->getLine(), /* ShouldSkipZero */ false); |
| 1784 | Printer.printInt("column", DL->getColumn()); |
| 1785 | Printer.printMetadata("scope", DL->getRawScope(), /* ShouldSkipNull */ false); |
| 1786 | Printer.printMetadata("inlinedAt", DL->getRawInlinedAt()); |
Calixte Denizet | 44db1d1 | 2018-09-20 08:53:06 +0000 | [diff] [blame] | 1787 | Printer.printBool("isImplicitCode", DL->isImplicitCode(), |
| 1788 | /* Default */ false); |
Duncan P. N. Exon Smith | d640962 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 1789 | Out << ")"; |
| 1790 | } |
| 1791 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1792 | static void writeDISubrange(raw_ostream &Out, const DISubrange *N, |
Sander de Smalen | 959cee7 | 2018-01-24 09:56:07 +0000 | [diff] [blame] | 1793 | TypePrinting *TypePrinter, SlotTracker *Machine, |
| 1794 | const Module *Context) { |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1795 | Out << "!DISubrange("; |
Sander de Smalen | 959cee7 | 2018-01-24 09:56:07 +0000 | [diff] [blame] | 1796 | MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); |
| 1797 | if (auto *CE = N->getCount().dyn_cast<ConstantInt*>()) |
| 1798 | Printer.printInt("count", CE->getSExtValue(), /* ShouldSkipZero */ false); |
| 1799 | else |
| 1800 | Printer.printMetadata("count", N->getCount().dyn_cast<DIVariable*>(), |
| 1801 | /*ShouldSkipNull */ false); |
Duncan P. N. Exon Smith | 329f821 | 2015-04-07 00:39:59 +0000 | [diff] [blame] | 1802 | Printer.printInt("lowerBound", N->getLowerBound()); |
Duncan P. N. Exon Smith | b984c49 | 2015-02-13 01:10:38 +0000 | [diff] [blame] | 1803 | Out << ")"; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1804 | } |
Duncan P. N. Exon Smith | b984c49 | 2015-02-13 01:10:38 +0000 | [diff] [blame] | 1805 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1806 | static void writeDIEnumerator(raw_ostream &Out, const DIEnumerator *N, |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1807 | TypePrinting *, SlotTracker *, const Module *) { |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1808 | Out << "!DIEnumerator("; |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1809 | MDFieldPrinter Printer(Out); |
| 1810 | Printer.printString("name", N->getName(), /* ShouldSkipEmpty */ false); |
Momchil Velikov | 0c69bf4 | 2018-02-12 16:10:09 +0000 | [diff] [blame] | 1811 | if (N->isUnsigned()) { |
| 1812 | auto Value = static_cast<uint64_t>(N->getValue()); |
| 1813 | Printer.printInt("value", Value, /* ShouldSkipZero */ false); |
| 1814 | Printer.printBool("isUnsigned", true); |
| 1815 | } else { |
| 1816 | Printer.printInt("value", N->getValue(), /* ShouldSkipZero */ false); |
| 1817 | } |
Duncan P. N. Exon Smith | aa7c943 | 2015-02-13 01:14:11 +0000 | [diff] [blame] | 1818 | Out << ")"; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1819 | } |
Duncan P. N. Exon Smith | aa7c943 | 2015-02-13 01:14:11 +0000 | [diff] [blame] | 1820 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1821 | static void writeDIBasicType(raw_ostream &Out, const DIBasicType *N, |
Duncan P. N. Exon Smith | 57b4c15 | 2015-02-13 01:14:58 +0000 | [diff] [blame] | 1822 | TypePrinting *, SlotTracker *, const Module *) { |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1823 | Out << "!DIBasicType("; |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1824 | MDFieldPrinter Printer(Out); |
Duncan P. N. Exon Smith | 9b18dbf | 2015-02-28 23:21:38 +0000 | [diff] [blame] | 1825 | if (N->getTag() != dwarf::DW_TAG_base_type) |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1826 | Printer.printTag(N); |
| 1827 | Printer.printString("name", N->getName()); |
| 1828 | Printer.printInt("size", N->getSizeInBits()); |
| 1829 | Printer.printInt("align", N->getAlignInBits()); |
| 1830 | Printer.printDwarfEnum("encoding", N->getEncoding(), |
| 1831 | dwarf::AttributeEncodingString); |
Adrian Prantl | c4d1909 | 2018-08-14 19:35:34 +0000 | [diff] [blame] | 1832 | Printer.printDIFlags("flags", N->getFlags()); |
Duncan P. N. Exon Smith | 57b4c15 | 2015-02-13 01:14:58 +0000 | [diff] [blame] | 1833 | Out << ")"; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1834 | } |
Duncan P. N. Exon Smith | 57b4c15 | 2015-02-13 01:14:58 +0000 | [diff] [blame] | 1835 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1836 | static void writeDIDerivedType(raw_ostream &Out, const DIDerivedType *N, |
Duncan P. N. Exon Smith | dacf000 | 2015-02-13 01:20:38 +0000 | [diff] [blame] | 1837 | TypePrinting *TypePrinter, SlotTracker *Machine, |
| 1838 | const Module *Context) { |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1839 | Out << "!DIDerivedType("; |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1840 | MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); |
| 1841 | Printer.printTag(N); |
| 1842 | Printer.printString("name", N->getName()); |
Duncan P. N. Exon Smith | b943370 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1843 | Printer.printMetadata("scope", N->getRawScope()); |
| 1844 | Printer.printMetadata("file", N->getRawFile()); |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1845 | Printer.printInt("line", N->getLine()); |
Duncan P. N. Exon Smith | b943370 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1846 | Printer.printMetadata("baseType", N->getRawBaseType(), |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1847 | /* ShouldSkipNull */ false); |
| 1848 | Printer.printInt("size", N->getSizeInBits()); |
| 1849 | Printer.printInt("align", N->getAlignInBits()); |
| 1850 | Printer.printInt("offset", N->getOffsetInBits()); |
| 1851 | Printer.printDIFlags("flags", N->getFlags()); |
Duncan P. N. Exon Smith | b943370 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1852 | Printer.printMetadata("extraData", N->getRawExtraData()); |
Konstantin Zhuravlyov | 2cee5cc | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 1853 | if (const auto &DWARFAddressSpace = N->getDWARFAddressSpace()) |
| 1854 | Printer.printInt("dwarfAddressSpace", *DWARFAddressSpace, |
| 1855 | /* ShouldSkipZero */ false); |
Duncan P. N. Exon Smith | dacf000 | 2015-02-13 01:20:38 +0000 | [diff] [blame] | 1856 | Out << ")"; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1857 | } |
Duncan P. N. Exon Smith | dacf000 | 2015-02-13 01:20:38 +0000 | [diff] [blame] | 1858 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1859 | static void writeDICompositeType(raw_ostream &Out, const DICompositeType *N, |
Duncan P. N. Exon Smith | dacf000 | 2015-02-13 01:20:38 +0000 | [diff] [blame] | 1860 | TypePrinting *TypePrinter, |
| 1861 | SlotTracker *Machine, const Module *Context) { |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1862 | Out << "!DICompositeType("; |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1863 | MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); |
| 1864 | Printer.printTag(N); |
| 1865 | Printer.printString("name", N->getName()); |
Duncan P. N. Exon Smith | b943370 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1866 | Printer.printMetadata("scope", N->getRawScope()); |
| 1867 | Printer.printMetadata("file", N->getRawFile()); |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1868 | Printer.printInt("line", N->getLine()); |
Duncan P. N. Exon Smith | b943370 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1869 | Printer.printMetadata("baseType", N->getRawBaseType()); |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1870 | Printer.printInt("size", N->getSizeInBits()); |
| 1871 | Printer.printInt("align", N->getAlignInBits()); |
| 1872 | Printer.printInt("offset", N->getOffsetInBits()); |
| 1873 | Printer.printDIFlags("flags", N->getFlags()); |
Duncan P. N. Exon Smith | b943370 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1874 | Printer.printMetadata("elements", N->getRawElements()); |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1875 | Printer.printDwarfEnum("runtimeLang", N->getRuntimeLang(), |
| 1876 | dwarf::LanguageString); |
Duncan P. N. Exon Smith | b943370 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1877 | Printer.printMetadata("vtableHolder", N->getRawVTableHolder()); |
| 1878 | Printer.printMetadata("templateParams", N->getRawTemplateParams()); |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1879 | Printer.printString("identifier", N->getIdentifier()); |
Adrian Prantl | 04aa650 | 2018-02-06 23:45:59 +0000 | [diff] [blame] | 1880 | Printer.printMetadata("discriminator", N->getRawDiscriminator()); |
Duncan P. N. Exon Smith | dacf000 | 2015-02-13 01:20:38 +0000 | [diff] [blame] | 1881 | Out << ")"; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1882 | } |
Duncan P. N. Exon Smith | dacf000 | 2015-02-13 01:20:38 +0000 | [diff] [blame] | 1883 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1884 | static void writeDISubroutineType(raw_ostream &Out, const DISubroutineType *N, |
Duncan P. N. Exon Smith | 1c092c0 | 2015-02-13 01:22:59 +0000 | [diff] [blame] | 1885 | TypePrinting *TypePrinter, |
| 1886 | SlotTracker *Machine, const Module *Context) { |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1887 | Out << "!DISubroutineType("; |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1888 | MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); |
| 1889 | Printer.printDIFlags("flags", N->getFlags()); |
Reid Kleckner | 3d3aca2 | 2016-06-08 20:34:29 +0000 | [diff] [blame] | 1890 | Printer.printDwarfEnum("cc", N->getCC(), dwarf::ConventionString); |
Duncan P. N. Exon Smith | b943370 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1891 | Printer.printMetadata("types", N->getRawTypeArray(), |
| 1892 | /* ShouldSkipNull */ false); |
Duncan P. N. Exon Smith | 1c092c0 | 2015-02-13 01:22:59 +0000 | [diff] [blame] | 1893 | Out << ")"; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1894 | } |
Duncan P. N. Exon Smith | 192d9c3 | 2015-02-13 01:19:14 +0000 | [diff] [blame] | 1895 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1896 | static void writeDIFile(raw_ostream &Out, const DIFile *N, TypePrinting *, |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1897 | SlotTracker *, const Module *) { |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1898 | Out << "!DIFile("; |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1899 | MDFieldPrinter Printer(Out); |
| 1900 | Printer.printString("filename", N->getFilename(), |
| 1901 | /* ShouldSkipEmpty */ false); |
| 1902 | Printer.printString("directory", N->getDirectory(), |
| 1903 | /* ShouldSkipEmpty */ false); |
Scott Linder | 4863252 | 2018-02-12 19:45:54 +0000 | [diff] [blame] | 1904 | // Print all values for checksum together, or not at all. |
| 1905 | if (N->getChecksum()) |
| 1906 | Printer.printChecksum(*N->getChecksum()); |
Scott Linder | 5e4b515 | 2018-02-23 23:01:06 +0000 | [diff] [blame] | 1907 | Printer.printString("source", N->getSource().getValueOr(StringRef()), |
| 1908 | /* ShouldSkipEmpty */ true); |
Duncan P. N. Exon Smith | 192d9c3 | 2015-02-13 01:19:14 +0000 | [diff] [blame] | 1909 | Out << ")"; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1910 | } |
Duncan P. N. Exon Smith | 192d9c3 | 2015-02-13 01:19:14 +0000 | [diff] [blame] | 1911 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1912 | static void writeDICompileUnit(raw_ostream &Out, const DICompileUnit *N, |
Duncan P. N. Exon Smith | 37742c3 | 2015-02-13 01:25:10 +0000 | [diff] [blame] | 1913 | TypePrinting *TypePrinter, SlotTracker *Machine, |
| 1914 | const Module *Context) { |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1915 | Out << "!DICompileUnit("; |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1916 | MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); |
| 1917 | Printer.printDwarfEnum("language", N->getSourceLanguage(), |
| 1918 | dwarf::LanguageString, /* ShouldSkipZero */ false); |
Duncan P. N. Exon Smith | b943370 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1919 | Printer.printMetadata("file", N->getRawFile(), /* ShouldSkipNull */ false); |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1920 | Printer.printString("producer", N->getProducer()); |
| 1921 | Printer.printBool("isOptimized", N->isOptimized()); |
| 1922 | Printer.printString("flags", N->getFlags()); |
| 1923 | Printer.printInt("runtimeVersion", N->getRuntimeVersion(), |
| 1924 | /* ShouldSkipZero */ false); |
| 1925 | Printer.printString("splitDebugFilename", N->getSplitDebugFilename()); |
Adrian Prantl | 39bb84a | 2016-03-31 23:56:58 +0000 | [diff] [blame] | 1926 | Printer.printEmissionKind("emissionKind", N->getEmissionKind()); |
Duncan P. N. Exon Smith | b943370 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1927 | Printer.printMetadata("enums", N->getRawEnumTypes()); |
| 1928 | Printer.printMetadata("retainedTypes", N->getRawRetainedTypes()); |
Duncan P. N. Exon Smith | b943370 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1929 | Printer.printMetadata("globals", N->getRawGlobalVariables()); |
| 1930 | Printer.printMetadata("imports", N->getRawImportedEntities()); |
Amjad Aboud | 7db3980 | 2015-12-10 12:56:35 +0000 | [diff] [blame] | 1931 | Printer.printMetadata("macros", N->getRawMacros()); |
Adrian Prantl | 849c760 | 2015-05-21 20:37:30 +0000 | [diff] [blame] | 1932 | Printer.printInt("dwoId", N->getDWOId()); |
David Blaikie | bf471b7 | 2016-08-24 18:29:49 +0000 | [diff] [blame] | 1933 | Printer.printBool("splitDebugInlining", N->getSplitDebugInlining(), true); |
Dehao Chen | fe46230 | 2017-02-01 22:45:09 +0000 | [diff] [blame] | 1934 | Printer.printBool("debugInfoForProfiling", N->getDebugInfoForProfiling(), |
| 1935 | false); |
David Blaikie | cf8a4a5 | 2018-08-16 21:29:55 +0000 | [diff] [blame] | 1936 | Printer.printNameTableKind("nameTableKind", N->getNameTableKind()); |
David Blaikie | ecc582a | 2018-11-13 20:08:10 +0000 | [diff] [blame] | 1937 | Printer.printBool("rangesBaseAddress", N->getRangesBaseAddress(), false); |
Duncan P. N. Exon Smith | 37742c3 | 2015-02-13 01:25:10 +0000 | [diff] [blame] | 1938 | Out << ")"; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1939 | } |
Duncan P. N. Exon Smith | 37742c3 | 2015-02-13 01:25:10 +0000 | [diff] [blame] | 1940 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1941 | static void writeDISubprogram(raw_ostream &Out, const DISubprogram *N, |
Duncan P. N. Exon Smith | ed356a9 | 2015-02-13 01:26:47 +0000 | [diff] [blame] | 1942 | TypePrinting *TypePrinter, SlotTracker *Machine, |
| 1943 | const Module *Context) { |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1944 | Out << "!DISubprogram("; |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1945 | MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); |
| 1946 | Printer.printString("name", N->getName()); |
| 1947 | Printer.printString("linkageName", N->getLinkageName()); |
Duncan P. N. Exon Smith | bd38c8d | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 1948 | Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); |
| 1949 | Printer.printMetadata("file", N->getRawFile()); |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1950 | Printer.printInt("line", N->getLine()); |
Duncan P. N. Exon Smith | bd38c8d | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 1951 | Printer.printMetadata("type", N->getRawType()); |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1952 | Printer.printInt("scopeLine", N->getScopeLine()); |
Duncan P. N. Exon Smith | bd38c8d | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 1953 | Printer.printMetadata("containingType", N->getRawContainingType()); |
Peter Collingbourne | 4c97b94 | 2016-03-17 23:58:03 +0000 | [diff] [blame] | 1954 | if (N->getVirtuality() != dwarf::DW_VIRTUALITY_none || |
| 1955 | N->getVirtualIndex() != 0) |
| 1956 | Printer.printInt("virtualIndex", N->getVirtualIndex(), false); |
Reid Kleckner | bd79db2 | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 1957 | Printer.printInt("thisAdjustment", N->getThisAdjustment()); |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1958 | Printer.printDIFlags("flags", N->getFlags()); |
Paul Robinson | ccefd88 | 2018-11-28 21:14:32 +0000 | [diff] [blame] | 1959 | Printer.printDISPFlags("spFlags", N->getSPFlags()); |
Adrian Prantl | 4eeaa0d | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 1960 | Printer.printMetadata("unit", N->getRawUnit()); |
Duncan P. N. Exon Smith | bd38c8d | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 1961 | Printer.printMetadata("templateParams", N->getRawTemplateParams()); |
| 1962 | Printer.printMetadata("declaration", N->getRawDeclaration()); |
Shiva Chen | a8a13bc | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 1963 | Printer.printMetadata("retainedNodes", N->getRawRetainedNodes()); |
Adrian Prantl | 1bf6297 | 2017-04-26 22:56:44 +0000 | [diff] [blame] | 1964 | Printer.printMetadata("thrownTypes", N->getRawThrownTypes()); |
Duncan P. N. Exon Smith | ed356a9 | 2015-02-13 01:26:47 +0000 | [diff] [blame] | 1965 | Out << ")"; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1966 | } |
Duncan P. N. Exon Smith | ed356a9 | 2015-02-13 01:26:47 +0000 | [diff] [blame] | 1967 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1968 | static void writeDILexicalBlock(raw_ostream &Out, const DILexicalBlock *N, |
| 1969 | TypePrinting *TypePrinter, SlotTracker *Machine, |
| 1970 | const Module *Context) { |
| 1971 | Out << "!DILexicalBlock("; |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1972 | MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); |
Duncan P. N. Exon Smith | d3ec0ca | 2015-03-30 16:37:48 +0000 | [diff] [blame] | 1973 | Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); |
| 1974 | Printer.printMetadata("file", N->getRawFile()); |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1975 | Printer.printInt("line", N->getLine()); |
| 1976 | Printer.printInt("column", N->getColumn()); |
Duncan P. N. Exon Smith | c7be07e | 2015-02-13 01:29:28 +0000 | [diff] [blame] | 1977 | Out << ")"; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1978 | } |
Duncan P. N. Exon Smith | c7be07e | 2015-02-13 01:29:28 +0000 | [diff] [blame] | 1979 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1980 | static void writeDILexicalBlockFile(raw_ostream &Out, |
| 1981 | const DILexicalBlockFile *N, |
Duncan P. N. Exon Smith | 246f093 | 2015-02-13 01:30:42 +0000 | [diff] [blame] | 1982 | TypePrinting *TypePrinter, |
| 1983 | SlotTracker *Machine, |
| 1984 | const Module *Context) { |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1985 | Out << "!DILexicalBlockFile("; |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1986 | MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); |
Duncan P. N. Exon Smith | d3ec0ca | 2015-03-30 16:37:48 +0000 | [diff] [blame] | 1987 | Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); |
| 1988 | Printer.printMetadata("file", N->getRawFile()); |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1989 | Printer.printInt("discriminator", N->getDiscriminator(), |
| 1990 | /* ShouldSkipZero */ false); |
Duncan P. N. Exon Smith | 246f093 | 2015-02-13 01:30:42 +0000 | [diff] [blame] | 1991 | Out << ")"; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1992 | } |
Duncan P. N. Exon Smith | 246f093 | 2015-02-13 01:30:42 +0000 | [diff] [blame] | 1993 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1994 | static void writeDINamespace(raw_ostream &Out, const DINamespace *N, |
Duncan P. N. Exon Smith | 7bd3d1d | 2015-02-13 01:32:09 +0000 | [diff] [blame] | 1995 | TypePrinting *TypePrinter, SlotTracker *Machine, |
| 1996 | const Module *Context) { |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1997 | Out << "!DINamespace("; |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 1998 | MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); |
| 1999 | Printer.printString("name", N->getName()); |
Duncan P. N. Exon Smith | 7380257 | 2015-03-30 17:21:38 +0000 | [diff] [blame] | 2000 | Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); |
Adrian Prantl | 60a7c43 | 2016-11-03 19:42:02 +0000 | [diff] [blame] | 2001 | Printer.printBool("exportSymbols", N->getExportSymbols(), false); |
Duncan P. N. Exon Smith | 7bd3d1d | 2015-02-13 01:32:09 +0000 | [diff] [blame] | 2002 | Out << ")"; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2003 | } |
Duncan P. N. Exon Smith | 7bd3d1d | 2015-02-13 01:32:09 +0000 | [diff] [blame] | 2004 | |
Amjad Aboud | 7db3980 | 2015-12-10 12:56:35 +0000 | [diff] [blame] | 2005 | static void writeDIMacro(raw_ostream &Out, const DIMacro *N, |
| 2006 | TypePrinting *TypePrinter, SlotTracker *Machine, |
| 2007 | const Module *Context) { |
| 2008 | Out << "!DIMacro("; |
| 2009 | MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); |
| 2010 | Printer.printMacinfoType(N); |
| 2011 | Printer.printInt("line", N->getLine()); |
| 2012 | Printer.printString("name", N->getName()); |
| 2013 | Printer.printString("value", N->getValue()); |
| 2014 | Out << ")"; |
| 2015 | } |
| 2016 | |
| 2017 | static void writeDIMacroFile(raw_ostream &Out, const DIMacroFile *N, |
| 2018 | TypePrinting *TypePrinter, SlotTracker *Machine, |
| 2019 | const Module *Context) { |
| 2020 | Out << "!DIMacroFile("; |
| 2021 | MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); |
| 2022 | Printer.printInt("line", N->getLine()); |
| 2023 | Printer.printMetadata("file", N->getRawFile(), /* ShouldSkipNull */ false); |
| 2024 | Printer.printMetadata("nodes", N->getRawElements()); |
| 2025 | Out << ")"; |
| 2026 | } |
| 2027 | |
Adrian Prantl | 7177647 | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 2028 | static void writeDIModule(raw_ostream &Out, const DIModule *N, |
| 2029 | TypePrinting *TypePrinter, SlotTracker *Machine, |
| 2030 | const Module *Context) { |
| 2031 | Out << "!DIModule("; |
| 2032 | MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); |
| 2033 | Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); |
| 2034 | Printer.printString("name", N->getName()); |
| 2035 | Printer.printString("configMacros", N->getConfigurationMacros()); |
| 2036 | Printer.printString("includePath", N->getIncludePath()); |
| 2037 | Printer.printString("isysroot", N->getISysRoot()); |
| 2038 | Out << ")"; |
| 2039 | } |
| 2040 | |
| 2041 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2042 | static void writeDITemplateTypeParameter(raw_ostream &Out, |
| 2043 | const DITemplateTypeParameter *N, |
Duncan P. N. Exon Smith | 8921bbc | 2015-02-13 01:34:32 +0000 | [diff] [blame] | 2044 | TypePrinting *TypePrinter, |
| 2045 | SlotTracker *Machine, |
| 2046 | const Module *Context) { |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2047 | Out << "!DITemplateTypeParameter("; |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 2048 | MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); |
| 2049 | Printer.printString("name", N->getName()); |
Duncan P. N. Exon Smith | e009b6f | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 2050 | Printer.printMetadata("type", N->getRawType(), /* ShouldSkipNull */ false); |
Duncan P. N. Exon Smith | 8921bbc | 2015-02-13 01:34:32 +0000 | [diff] [blame] | 2051 | Out << ")"; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2052 | } |
Duncan P. N. Exon Smith | 8921bbc | 2015-02-13 01:34:32 +0000 | [diff] [blame] | 2053 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2054 | static void writeDITemplateValueParameter(raw_ostream &Out, |
| 2055 | const DITemplateValueParameter *N, |
Duncan P. N. Exon Smith | 8921bbc | 2015-02-13 01:34:32 +0000 | [diff] [blame] | 2056 | TypePrinting *TypePrinter, |
| 2057 | SlotTracker *Machine, |
| 2058 | const Module *Context) { |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2059 | Out << "!DITemplateValueParameter("; |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 2060 | MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); |
Duncan P. N. Exon Smith | 9b18dbf | 2015-02-28 23:21:38 +0000 | [diff] [blame] | 2061 | if (N->getTag() != dwarf::DW_TAG_template_value_parameter) |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 2062 | Printer.printTag(N); |
| 2063 | Printer.printString("name", N->getName()); |
Duncan P. N. Exon Smith | e009b6f | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 2064 | Printer.printMetadata("type", N->getRawType()); |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 2065 | Printer.printMetadata("value", N->getValue(), /* ShouldSkipNull */ false); |
Duncan P. N. Exon Smith | 8921bbc | 2015-02-13 01:34:32 +0000 | [diff] [blame] | 2066 | Out << ")"; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2067 | } |
Duncan P. N. Exon Smith | 8921bbc | 2015-02-13 01:34:32 +0000 | [diff] [blame] | 2068 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2069 | static void writeDIGlobalVariable(raw_ostream &Out, const DIGlobalVariable *N, |
Duncan P. N. Exon Smith | fbc547d | 2015-02-13 01:35:40 +0000 | [diff] [blame] | 2070 | TypePrinting *TypePrinter, |
| 2071 | SlotTracker *Machine, const Module *Context) { |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2072 | Out << "!DIGlobalVariable("; |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 2073 | MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); |
| 2074 | Printer.printString("name", N->getName()); |
| 2075 | Printer.printString("linkageName", N->getLinkageName()); |
Duncan P. N. Exon Smith | a9902da | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 2076 | Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); |
| 2077 | Printer.printMetadata("file", N->getRawFile()); |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 2078 | Printer.printInt("line", N->getLine()); |
Duncan P. N. Exon Smith | a9902da | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 2079 | Printer.printMetadata("type", N->getRawType()); |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 2080 | Printer.printBool("isLocal", N->isLocalToUnit()); |
| 2081 | Printer.printBool("isDefinition", N->isDefinition()); |
Duncan P. N. Exon Smith | a9902da | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 2082 | Printer.printMetadata("declaration", N->getRawStaticDataMemberDeclaration()); |
Matthew Voss | fff44e6 | 2018-10-03 18:44:53 +0000 | [diff] [blame] | 2083 | Printer.printMetadata("templateParams", N->getRawTemplateParams()); |
Victor Leschuk | e69c459 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 2084 | Printer.printInt("align", N->getAlignInBits()); |
Duncan P. N. Exon Smith | fbc547d | 2015-02-13 01:35:40 +0000 | [diff] [blame] | 2085 | Out << ")"; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2086 | } |
Duncan P. N. Exon Smith | fbc547d | 2015-02-13 01:35:40 +0000 | [diff] [blame] | 2087 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2088 | static void writeDILocalVariable(raw_ostream &Out, const DILocalVariable *N, |
Duncan P. N. Exon Smith | a342d82 | 2015-02-13 01:39:44 +0000 | [diff] [blame] | 2089 | TypePrinting *TypePrinter, |
| 2090 | SlotTracker *Machine, const Module *Context) { |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2091 | Out << "!DILocalVariable("; |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 2092 | MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 2093 | Printer.printString("name", N->getName()); |
Duncan P. N. Exon Smith | bf2040f | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 2094 | Printer.printInt("arg", N->getArg()); |
Duncan P. N. Exon Smith | a9902da | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 2095 | Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); |
| 2096 | Printer.printMetadata("file", N->getRawFile()); |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 2097 | Printer.printInt("line", N->getLine()); |
Duncan P. N. Exon Smith | a9902da | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 2098 | Printer.printMetadata("type", N->getRawType()); |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 2099 | Printer.printDIFlags("flags", N->getFlags()); |
Victor Leschuk | e69c459 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 2100 | Printer.printInt("align", N->getAlignInBits()); |
Duncan P. N. Exon Smith | a342d82 | 2015-02-13 01:39:44 +0000 | [diff] [blame] | 2101 | Out << ")"; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2102 | } |
Duncan P. N. Exon Smith | a342d82 | 2015-02-13 01:39:44 +0000 | [diff] [blame] | 2103 | |
Shiva Chen | a8a13bc | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 2104 | static void writeDILabel(raw_ostream &Out, const DILabel *N, |
| 2105 | TypePrinting *TypePrinter, |
| 2106 | SlotTracker *Machine, const Module *Context) { |
| 2107 | Out << "!DILabel("; |
| 2108 | MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); |
| 2109 | Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); |
| 2110 | Printer.printString("name", N->getName()); |
| 2111 | Printer.printMetadata("file", N->getRawFile()); |
| 2112 | Printer.printInt("line", N->getLine()); |
| 2113 | Out << ")"; |
| 2114 | } |
| 2115 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2116 | static void writeDIExpression(raw_ostream &Out, const DIExpression *N, |
Duncan P. N. Exon Smith | a034e07 | 2015-02-13 01:42:09 +0000 | [diff] [blame] | 2117 | TypePrinting *TypePrinter, SlotTracker *Machine, |
| 2118 | const Module *Context) { |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2119 | Out << "!DIExpression("; |
Duncan P. N. Exon Smith | a034e07 | 2015-02-13 01:42:09 +0000 | [diff] [blame] | 2120 | FieldSeparator FS; |
| 2121 | if (N->isValid()) { |
| 2122 | for (auto I = N->expr_op_begin(), E = N->expr_op_end(); I != E; ++I) { |
Mehdi Amini | f9bb6bc | 2016-10-05 05:59:29 +0000 | [diff] [blame] | 2123 | auto OpStr = dwarf::OperationEncodingString(I->getOp()); |
| 2124 | assert(!OpStr.empty() && "Expected valid opcode"); |
Duncan P. N. Exon Smith | a034e07 | 2015-02-13 01:42:09 +0000 | [diff] [blame] | 2125 | |
| 2126 | Out << FS << OpStr; |
| 2127 | for (unsigned A = 0, AE = I->getNumArgs(); A != AE; ++A) |
| 2128 | Out << FS << I->getArg(A); |
| 2129 | } |
| 2130 | } else { |
| 2131 | for (const auto &I : N->getElements()) |
| 2132 | Out << FS << I; |
| 2133 | } |
| 2134 | Out << ")"; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2135 | } |
Duncan P. N. Exon Smith | a034e07 | 2015-02-13 01:42:09 +0000 | [diff] [blame] | 2136 | |
Adrian Prantl | 7b500b4 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 2137 | static void writeDIGlobalVariableExpression(raw_ostream &Out, |
| 2138 | const DIGlobalVariableExpression *N, |
| 2139 | TypePrinting *TypePrinter, |
| 2140 | SlotTracker *Machine, |
| 2141 | const Module *Context) { |
| 2142 | Out << "!DIGlobalVariableExpression("; |
| 2143 | MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); |
| 2144 | Printer.printMetadata("var", N->getVariable()); |
| 2145 | Printer.printMetadata("expr", N->getExpression()); |
| 2146 | Out << ")"; |
| 2147 | } |
| 2148 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2149 | static void writeDIObjCProperty(raw_ostream &Out, const DIObjCProperty *N, |
Duncan P. N. Exon Smith | 3bfa8d0 | 2015-02-13 01:43:22 +0000 | [diff] [blame] | 2150 | TypePrinting *TypePrinter, SlotTracker *Machine, |
| 2151 | const Module *Context) { |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2152 | Out << "!DIObjCProperty("; |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 2153 | MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); |
| 2154 | Printer.printString("name", N->getName()); |
Duncan P. N. Exon Smith | 7380257 | 2015-03-30 17:21:38 +0000 | [diff] [blame] | 2155 | Printer.printMetadata("file", N->getRawFile()); |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 2156 | Printer.printInt("line", N->getLine()); |
| 2157 | Printer.printString("setter", N->getSetterName()); |
| 2158 | Printer.printString("getter", N->getGetterName()); |
| 2159 | Printer.printInt("attributes", N->getAttributes()); |
Duncan P. N. Exon Smith | 7380257 | 2015-03-30 17:21:38 +0000 | [diff] [blame] | 2160 | Printer.printMetadata("type", N->getRawType()); |
Duncan P. N. Exon Smith | 3bfa8d0 | 2015-02-13 01:43:22 +0000 | [diff] [blame] | 2161 | Out << ")"; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2162 | } |
Duncan P. N. Exon Smith | 3bfa8d0 | 2015-02-13 01:43:22 +0000 | [diff] [blame] | 2163 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2164 | static void writeDIImportedEntity(raw_ostream &Out, const DIImportedEntity *N, |
Duncan P. N. Exon Smith | 6a390dc | 2015-02-13 01:46:02 +0000 | [diff] [blame] | 2165 | TypePrinting *TypePrinter, |
| 2166 | SlotTracker *Machine, const Module *Context) { |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2167 | Out << "!DIImportedEntity("; |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 2168 | MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); |
| 2169 | Printer.printTag(N); |
| 2170 | Printer.printString("name", N->getName()); |
Duncan P. N. Exon Smith | 7380257 | 2015-03-30 17:21:38 +0000 | [diff] [blame] | 2171 | Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); |
| 2172 | Printer.printMetadata("entity", N->getRawEntity()); |
Adrian Prantl | 9563b5a | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 2173 | Printer.printMetadata("file", N->getRawFile()); |
Duncan P. N. Exon Smith | 50b75d5 | 2015-03-27 00:17:42 +0000 | [diff] [blame] | 2174 | Printer.printInt("line", N->getLine()); |
Duncan P. N. Exon Smith | 6a390dc | 2015-02-13 01:46:02 +0000 | [diff] [blame] | 2175 | Out << ")"; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2176 | } |
| 2177 | |
Duncan P. N. Exon Smith | 120c186 | 2015-01-12 23:45:31 +0000 | [diff] [blame] | 2178 | static void WriteMDNodeBodyInternal(raw_ostream &Out, const MDNode *Node, |
| 2179 | TypePrinting *TypePrinter, |
| 2180 | SlotTracker *Machine, |
| 2181 | const Module *Context) { |
Duncan P. N. Exon Smith | b061786 | 2015-01-19 23:13:14 +0000 | [diff] [blame] | 2182 | if (Node->isDistinct()) |
Duncan P. N. Exon Smith | 120c186 | 2015-01-12 23:45:31 +0000 | [diff] [blame] | 2183 | Out << "distinct "; |
Duncan P. N. Exon Smith | bee74a3 | 2015-03-16 21:21:10 +0000 | [diff] [blame] | 2184 | else if (Node->isTemporary()) |
| 2185 | Out << "<temporary!> "; // Handle broken code. |
Duncan P. N. Exon Smith | 120c186 | 2015-01-12 23:45:31 +0000 | [diff] [blame] | 2186 | |
Duncan P. N. Exon Smith | b061786 | 2015-01-19 23:13:14 +0000 | [diff] [blame] | 2187 | switch (Node->getMetadataID()) { |
Duncan P. N. Exon Smith | 120c186 | 2015-01-12 23:45:31 +0000 | [diff] [blame] | 2188 | default: |
| 2189 | llvm_unreachable("Expected uniquable MDNode"); |
Duncan P. N. Exon Smith | b061786 | 2015-01-19 23:13:14 +0000 | [diff] [blame] | 2190 | #define HANDLE_MDNODE_LEAF(CLASS) \ |
Duncan P. N. Exon Smith | 120c186 | 2015-01-12 23:45:31 +0000 | [diff] [blame] | 2191 | case Metadata::CLASS##Kind: \ |
Duncan P. N. Exon Smith | b061786 | 2015-01-19 23:13:14 +0000 | [diff] [blame] | 2192 | write##CLASS(Out, cast<CLASS>(Node), TypePrinter, Machine, Context); \ |
Duncan P. N. Exon Smith | 120c186 | 2015-01-12 23:45:31 +0000 | [diff] [blame] | 2193 | break; |
| 2194 | #include "llvm/IR/Metadata.def" |
| 2195 | } |
| 2196 | } |
| 2197 | |
Chandler Carruth | 560e395 | 2014-01-09 02:29:41 +0000 | [diff] [blame] | 2198 | // Full implementation of printing a Value as an operand with support for |
| 2199 | // TypePrinting, etc. |
Dan Gohman | 1220e10 | 2009-08-12 20:56:03 +0000 | [diff] [blame] | 2200 | static void WriteAsOperandInternal(raw_ostream &Out, const Value *V, |
Dan Gohman | d6c0f65 | 2009-08-13 15:27:57 +0000 | [diff] [blame] | 2201 | TypePrinting *TypePrinter, |
Dan Gohman | 3bdfbf5 | 2010-07-20 23:55:01 +0000 | [diff] [blame] | 2202 | SlotTracker *Machine, |
| 2203 | const Module *Context) { |
Chris Lattner | c97536e | 2008-08-17 04:40:13 +0000 | [diff] [blame] | 2204 | if (V->hasName()) { |
| 2205 | PrintLLVMName(Out, V); |
| 2206 | return; |
| 2207 | } |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 2208 | |
Chris Lattner | c97536e | 2008-08-17 04:40:13 +0000 | [diff] [blame] | 2209 | const Constant *CV = dyn_cast<Constant>(V); |
| 2210 | if (CV && !isa<GlobalValue>(CV)) { |
Dan Gohman | d6c0f65 | 2009-08-13 15:27:57 +0000 | [diff] [blame] | 2211 | assert(TypePrinter && "Constants require TypePrinting!"); |
Dan Gohman | 3bdfbf5 | 2010-07-20 23:55:01 +0000 | [diff] [blame] | 2212 | WriteConstantInternal(Out, CV, *TypePrinter, Machine, Context); |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 2213 | return; |
| 2214 | } |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 2215 | |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 2216 | if (const InlineAsm *IA = dyn_cast<InlineAsm>(V)) { |
Chris Lattner | c97536e | 2008-08-17 04:40:13 +0000 | [diff] [blame] | 2217 | Out << "asm "; |
| 2218 | if (IA->hasSideEffects()) |
| 2219 | Out << "sideeffect "; |
Dale Johannesen | 8ba2d5b | 2009-10-21 23:28:00 +0000 | [diff] [blame] | 2220 | if (IA->isAlignStack()) |
| 2221 | Out << "alignstack "; |
Chad Rosier | 581600b | 2012-09-05 19:00:49 +0000 | [diff] [blame] | 2222 | // We don't emit the AD_ATT dialect as it's the assumed default. |
| 2223 | if (IA->getDialect() == InlineAsm::AD_Intel) |
| 2224 | Out << "inteldialect "; |
Chris Lattner | c97536e | 2008-08-17 04:40:13 +0000 | [diff] [blame] | 2225 | Out << '"'; |
Jonas Devlieghere | 7eeba25 | 2018-05-31 17:01:42 +0000 | [diff] [blame] | 2226 | printEscapedString(IA->getAsmString(), Out); |
Chris Lattner | c97536e | 2008-08-17 04:40:13 +0000 | [diff] [blame] | 2227 | Out << "\", \""; |
Jonas Devlieghere | 7eeba25 | 2018-05-31 17:01:42 +0000 | [diff] [blame] | 2228 | printEscapedString(IA->getConstraintString(), Out); |
Chris Lattner | c97536e | 2008-08-17 04:40:13 +0000 | [diff] [blame] | 2229 | Out << '"'; |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 2230 | return; |
| 2231 | } |
Devang Patel | e54abc9 | 2009-07-22 17:43:22 +0000 | [diff] [blame] | 2232 | |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 2233 | if (auto *MD = dyn_cast<MetadataAsValue>(V)) { |
| 2234 | WriteAsOperandInternal(Out, MD->getMetadata(), TypePrinter, Machine, |
| 2235 | Context, /* FromValue */ true); |
Devang Patel | e54abc9 | 2009-07-22 17:43:22 +0000 | [diff] [blame] | 2236 | return; |
| 2237 | } |
| 2238 | |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 2239 | char Prefix = '%'; |
| 2240 | int Slot; |
Chris Lattner | fb5179a | 2011-08-03 06:15:41 +0000 | [diff] [blame] | 2241 | // If we have a SlotTracker, use it. |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 2242 | if (Machine) { |
| 2243 | if (const GlobalValue *GV = dyn_cast<GlobalValue>(V)) { |
| 2244 | Slot = Machine->getGlobalSlot(GV); |
| 2245 | Prefix = '@'; |
| 2246 | } else { |
| 2247 | Slot = Machine->getLocalSlot(V); |
Andrew Trick | 18801ec | 2011-09-30 19:48:58 +0000 | [diff] [blame] | 2248 | |
Chris Lattner | fb5179a | 2011-08-03 06:15:41 +0000 | [diff] [blame] | 2249 | // If the local value didn't succeed, then we may be referring to a value |
| 2250 | // from a different function. Translate it, as this can happen when using |
| 2251 | // address of blocks. |
| 2252 | if (Slot == -1) |
| 2253 | if ((Machine = createSlotTracker(V))) { |
| 2254 | Slot = Machine->getLocalSlot(V); |
| 2255 | delete Machine; |
| 2256 | } |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 2257 | } |
Chris Lattner | fb5179a | 2011-08-03 06:15:41 +0000 | [diff] [blame] | 2258 | } else if ((Machine = createSlotTracker(V))) { |
| 2259 | // Otherwise, create one to get the # and then destroy it. |
| 2260 | if (const GlobalValue *GV = dyn_cast<GlobalValue>(V)) { |
| 2261 | Slot = Machine->getGlobalSlot(GV); |
| 2262 | Prefix = '@'; |
Chris Lattner | 80cd115 | 2006-01-25 22:26:05 +0000 | [diff] [blame] | 2263 | } else { |
Chris Lattner | fb5179a | 2011-08-03 06:15:41 +0000 | [diff] [blame] | 2264 | Slot = Machine->getLocalSlot(V); |
Chris Lattner | 7a716ad | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 2265 | } |
Chris Lattner | fb5179a | 2011-08-03 06:15:41 +0000 | [diff] [blame] | 2266 | delete Machine; |
Craig Topper | ec0f0bc | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 2267 | Machine = nullptr; |
Chris Lattner | fb5179a | 2011-08-03 06:15:41 +0000 | [diff] [blame] | 2268 | } else { |
| 2269 | Slot = -1; |
Chris Lattner | 7a716ad | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 2270 | } |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 2271 | |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 2272 | if (Slot != -1) |
| 2273 | Out << Prefix << Slot; |
| 2274 | else |
| 2275 | Out << "<badref>"; |
Chris Lattner | 7a716ad | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 2276 | } |
| 2277 | |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 2278 | static void WriteAsOperandInternal(raw_ostream &Out, const Metadata *MD, |
| 2279 | TypePrinting *TypePrinter, |
| 2280 | SlotTracker *Machine, const Module *Context, |
| 2281 | bool FromValue) { |
Reid Kleckner | a5b2af0 | 2017-08-23 20:31:27 +0000 | [diff] [blame] | 2282 | // Write DIExpressions inline when used as a value. Improves readability of |
| 2283 | // debug info intrinsics. |
| 2284 | if (const DIExpression *Expr = dyn_cast<DIExpression>(MD)) { |
| 2285 | writeDIExpression(Out, Expr, TypePrinter, Machine, Context); |
| 2286 | return; |
| 2287 | } |
| 2288 | |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 2289 | if (const MDNode *N = dyn_cast<MDNode>(MD)) { |
Duncan P. N. Exon Smith | 4f95bcc | 2015-06-27 00:15:32 +0000 | [diff] [blame] | 2290 | std::unique_ptr<SlotTracker> MachineStorage; |
| 2291 | if (!Machine) { |
| 2292 | MachineStorage = make_unique<SlotTracker>(Context); |
| 2293 | Machine = MachineStorage.get(); |
| 2294 | } |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 2295 | int Slot = Machine->getMetadataSlot(N); |
Daniel Sanders | a3836a5 | 2018-12-13 14:25:27 +0000 | [diff] [blame] | 2296 | if (Slot == -1) { |
| 2297 | if (const DILocation *Loc = dyn_cast<DILocation>(N)) { |
| 2298 | writeDILocation(Out, Loc, TypePrinter, Machine, Context); |
| 2299 | return; |
| 2300 | } |
Duncan P. N. Exon Smith | 2ebd1ef | 2014-12-16 07:09:37 +0000 | [diff] [blame] | 2301 | // Give the pointer value instead of "badref", since this comes up all |
| 2302 | // the time when debugging. |
| 2303 | Out << "<" << N << ">"; |
Daniel Sanders | a3836a5 | 2018-12-13 14:25:27 +0000 | [diff] [blame] | 2304 | } else |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 2305 | Out << '!' << Slot; |
| 2306 | return; |
| 2307 | } |
| 2308 | |
| 2309 | if (const MDString *MDS = dyn_cast<MDString>(MD)) { |
| 2310 | Out << "!\""; |
Jonas Devlieghere | 7eeba25 | 2018-05-31 17:01:42 +0000 | [diff] [blame] | 2311 | printEscapedString(MDS->getString(), Out); |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 2312 | Out << '"'; |
| 2313 | return; |
| 2314 | } |
| 2315 | |
| 2316 | auto *V = cast<ValueAsMetadata>(MD); |
| 2317 | assert(TypePrinter && "TypePrinter required for metadata values"); |
| 2318 | assert((FromValue || !isa<LocalAsMetadata>(V)) && |
| 2319 | "Unexpected function-local metadata outside of value argument"); |
| 2320 | |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 2321 | TypePrinter->print(V->getValue()->getType(), Out); |
| 2322 | Out << ' '; |
| 2323 | WriteAsOperandInternal(Out, V->getValue(), TypePrinter, Machine, Context); |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 2324 | } |
| 2325 | |
Benjamin Kramer | 93920f0 | 2015-03-17 19:53:41 +0000 | [diff] [blame] | 2326 | namespace { |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 2327 | |
Benjamin Kramer | 93920f0 | 2015-03-17 19:53:41 +0000 | [diff] [blame] | 2328 | class AssemblyWriter { |
| 2329 | formatted_raw_ostream &Out; |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 2330 | const Module *TheModule = nullptr; |
| 2331 | const ModuleSummaryIndex *TheIndex = nullptr; |
Duncan P. N. Exon Smith | 9a61a42 | 2015-06-26 22:04:20 +0000 | [diff] [blame] | 2332 | std::unique_ptr<SlotTracker> SlotTrackerStorage; |
Benjamin Kramer | 93920f0 | 2015-03-17 19:53:41 +0000 | [diff] [blame] | 2333 | SlotTracker &Machine; |
| 2334 | TypePrinting TypePrinter; |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 2335 | AssemblyAnnotationWriter *AnnotationWriter = nullptr; |
Benjamin Kramer | 93920f0 | 2015-03-17 19:53:41 +0000 | [diff] [blame] | 2336 | SetVector<const Comdat *> Comdats; |
Justin Bogner | 0adaaa3 | 2015-09-27 22:38:50 +0000 | [diff] [blame] | 2337 | bool IsForDebug; |
Duncan P. N. Exon Smith | c9d5dea | 2015-04-15 01:36:30 +0000 | [diff] [blame] | 2338 | bool ShouldPreserveUseListOrder; |
Benjamin Kramer | 93920f0 | 2015-03-17 19:53:41 +0000 | [diff] [blame] | 2339 | UseListOrderStack UseListOrders; |
Duncan P. N. Exon Smith | c8be244 | 2015-04-24 21:03:05 +0000 | [diff] [blame] | 2340 | SmallVector<StringRef, 8> MDNames; |
Konstantin Zhuravlyov | 8f85685 | 2017-07-11 22:23:00 +0000 | [diff] [blame] | 2341 | /// Synchronization scope names registered with LLVMContext. |
| 2342 | SmallVector<StringRef, 8> SSNs; |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 2343 | DenseMap<const GlobalValueSummary *, GlobalValue::GUID> SummaryToGUIDMap; |
Benjamin Kramer | 93920f0 | 2015-03-17 19:53:41 +0000 | [diff] [blame] | 2344 | |
| 2345 | public: |
| 2346 | /// Construct an AssemblyWriter with an external SlotTracker |
Duncan P. N. Exon Smith | c9d5dea | 2015-04-15 01:36:30 +0000 | [diff] [blame] | 2347 | AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac, const Module *M, |
Justin Bogner | 0adaaa3 | 2015-09-27 22:38:50 +0000 | [diff] [blame] | 2348 | AssemblyAnnotationWriter *AAW, bool IsForDebug, |
Duncan P. N. Exon Smith | c9d5dea | 2015-04-15 01:36:30 +0000 | [diff] [blame] | 2349 | bool ShouldPreserveUseListOrder = false); |
Benjamin Kramer | 93920f0 | 2015-03-17 19:53:41 +0000 | [diff] [blame] | 2350 | |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 2351 | AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac, |
| 2352 | const ModuleSummaryIndex *Index, bool IsForDebug); |
| 2353 | |
Benjamin Kramer | 93920f0 | 2015-03-17 19:53:41 +0000 | [diff] [blame] | 2354 | void printMDNodeBody(const MDNode *MD); |
| 2355 | void printNamedMDNode(const NamedMDNode *NMD); |
| 2356 | |
| 2357 | void printModule(const Module *M); |
| 2358 | |
| 2359 | void writeOperand(const Value *Op, bool PrintType); |
Reid Kleckner | 331b9af | 2017-04-28 18:37:16 +0000 | [diff] [blame] | 2360 | void writeParamOperand(const Value *Operand, AttributeSet Attrs); |
Chandler Carruth | 9f32dc9 | 2019-01-07 07:31:49 +0000 | [diff] [blame] | 2361 | void writeOperandBundles(const CallBase *Call); |
Konstantin Zhuravlyov | 8f85685 | 2017-07-11 22:23:00 +0000 | [diff] [blame] | 2362 | void writeSyncScope(const LLVMContext &Context, |
| 2363 | SyncScope::ID SSID); |
| 2364 | void writeAtomic(const LLVMContext &Context, |
| 2365 | AtomicOrdering Ordering, |
| 2366 | SyncScope::ID SSID); |
| 2367 | void writeAtomicCmpXchg(const LLVMContext &Context, |
| 2368 | AtomicOrdering SuccessOrdering, |
Benjamin Kramer | 93920f0 | 2015-03-17 19:53:41 +0000 | [diff] [blame] | 2369 | AtomicOrdering FailureOrdering, |
Konstantin Zhuravlyov | 8f85685 | 2017-07-11 22:23:00 +0000 | [diff] [blame] | 2370 | SyncScope::ID SSID); |
Benjamin Kramer | 93920f0 | 2015-03-17 19:53:41 +0000 | [diff] [blame] | 2371 | |
| 2372 | void writeAllMDNodes(); |
| 2373 | void writeMDNode(unsigned Slot, const MDNode *Node); |
| 2374 | void writeAllAttributeGroups(); |
| 2375 | |
| 2376 | void printTypeIdentities(); |
| 2377 | void printGlobal(const GlobalVariable *GV); |
Dmitry Polukhin | 51a06a2 | 2016-04-05 08:47:51 +0000 | [diff] [blame] | 2378 | void printIndirectSymbol(const GlobalIndirectSymbol *GIS); |
Benjamin Kramer | 93920f0 | 2015-03-17 19:53:41 +0000 | [diff] [blame] | 2379 | void printComdat(const Comdat *C); |
| 2380 | void printFunction(const Function *F); |
Reid Kleckner | 331b9af | 2017-04-28 18:37:16 +0000 | [diff] [blame] | 2381 | void printArgument(const Argument *FA, AttributeSet Attrs); |
Benjamin Kramer | 93920f0 | 2015-03-17 19:53:41 +0000 | [diff] [blame] | 2382 | void printBasicBlock(const BasicBlock *BB); |
| 2383 | void printInstructionLine(const Instruction &I); |
| 2384 | void printInstruction(const Instruction &I); |
| 2385 | |
| 2386 | void printUseListOrder(const UseListOrder &Order); |
| 2387 | void printUseLists(const Function *F); |
| 2388 | |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 2389 | void printModuleSummaryIndex(); |
| 2390 | void printSummaryInfo(unsigned Slot, const ValueInfo &VI); |
| 2391 | void printSummary(const GlobalValueSummary &Summary); |
| 2392 | void printAliasSummary(const AliasSummary *AS); |
| 2393 | void printGlobalVarSummary(const GlobalVarSummary *GS); |
| 2394 | void printFunctionSummary(const FunctionSummary *FS); |
| 2395 | void printTypeIdSummary(const TypeIdSummary &TIS); |
| 2396 | void printTypeTestResolution(const TypeTestResolution &TTRes); |
| 2397 | void printArgs(const std::vector<uint64_t> &Args); |
| 2398 | void printWPDRes(const WholeProgramDevirtResolution &WPDRes); |
| 2399 | void printTypeIdInfo(const FunctionSummary::TypeIdInfo &TIDInfo); |
| 2400 | void printVFuncId(const FunctionSummary::VFuncId VFId); |
| 2401 | void |
| 2402 | printNonConstVCalls(const std::vector<FunctionSummary::VFuncId> VCallList, |
| 2403 | const char *Tag); |
| 2404 | void |
| 2405 | printConstVCalls(const std::vector<FunctionSummary::ConstVCall> VCallList, |
| 2406 | const char *Tag); |
| 2407 | |
Benjamin Kramer | 93920f0 | 2015-03-17 19:53:41 +0000 | [diff] [blame] | 2408 | private: |
Adrian Prantl | 26b584c | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 2409 | /// Print out metadata attachments. |
Duncan P. N. Exon Smith | 61317d5 | 2015-04-24 20:59:52 +0000 | [diff] [blame] | 2410 | void printMetadataAttachments( |
Duncan P. N. Exon Smith | 3be4147 | 2015-04-24 21:06:21 +0000 | [diff] [blame] | 2411 | const SmallVectorImpl<std::pair<unsigned, MDNode *>> &MDs, |
| 2412 | StringRef Separator); |
Duncan P. N. Exon Smith | 61317d5 | 2015-04-24 20:59:52 +0000 | [diff] [blame] | 2413 | |
Benjamin Kramer | 93920f0 | 2015-03-17 19:53:41 +0000 | [diff] [blame] | 2414 | // printInfoComment - Print a little comment after the instruction indicating |
| 2415 | // which slot it occupies. |
| 2416 | void printInfoComment(const Value &V); |
Igor Laevsky | a5f2faf | 2015-05-05 13:20:42 +0000 | [diff] [blame] | 2417 | |
| 2418 | // printGCRelocateComment - print comment after call to the gc.relocate |
| 2419 | // intrinsic indicating base and derived pointer names. |
Manuel Jacob | 397864c | 2016-01-05 04:03:00 +0000 | [diff] [blame] | 2420 | void printGCRelocateComment(const GCRelocateInst &Relocate); |
Benjamin Kramer | 93920f0 | 2015-03-17 19:53:41 +0000 | [diff] [blame] | 2421 | }; |
Eugene Zelenko | f193400 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 2422 | |
| 2423 | } // end anonymous namespace |
Benjamin Kramer | 93920f0 | 2015-03-17 19:53:41 +0000 | [diff] [blame] | 2424 | |
Justin Bogner | 8559c49 | 2015-09-02 22:46:15 +0000 | [diff] [blame] | 2425 | AssemblyWriter::AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac, |
| 2426 | const Module *M, AssemblyAnnotationWriter *AAW, |
Justin Bogner | 0adaaa3 | 2015-09-27 22:38:50 +0000 | [diff] [blame] | 2427 | bool IsForDebug, bool ShouldPreserveUseListOrder) |
Roman Tereshin | 238a338 | 2018-03-22 21:29:07 +0000 | [diff] [blame] | 2428 | : Out(o), TheModule(M), Machine(Mac), TypePrinter(M), AnnotationWriter(AAW), |
Justin Bogner | 0adaaa3 | 2015-09-27 22:38:50 +0000 | [diff] [blame] | 2429 | IsForDebug(IsForDebug), |
Justin Bogner | 8559c49 | 2015-09-02 22:46:15 +0000 | [diff] [blame] | 2430 | ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) { |
David Majnemer | c8a1169 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 2431 | if (!TheModule) |
| 2432 | return; |
Peter Collingbourne | 2772584 | 2016-06-22 20:29:42 +0000 | [diff] [blame] | 2433 | for (const GlobalObject &GO : TheModule->global_objects()) |
| 2434 | if (const Comdat *C = GO.getComdat()) |
David Majnemer | c8a1169 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 2435 | Comdats.insert(C); |
Daniel Malea | d0fef32 | 2013-05-08 20:38:31 +0000 | [diff] [blame] | 2436 | } |
Chris Lattner | d8c2e42 | 2001-07-12 23:35:26 +0000 | [diff] [blame] | 2437 | |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 2438 | AssemblyWriter::AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac, |
| 2439 | const ModuleSummaryIndex *Index, bool IsForDebug) |
| 2440 | : Out(o), TheIndex(Index), Machine(Mac), TypePrinter(/*Module=*/nullptr), |
| 2441 | IsForDebug(IsForDebug), ShouldPreserveUseListOrder(false) {} |
| 2442 | |
Chris Lattner | 2fcfdb7 | 2006-12-06 06:24:27 +0000 | [diff] [blame] | 2443 | void AssemblyWriter::writeOperand(const Value *Operand, bool PrintType) { |
Craig Topper | ec0f0bc | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 2444 | if (!Operand) { |
Chris Lattner | aab1820 | 2005-02-24 16:58:29 +0000 | [diff] [blame] | 2445 | Out << "<null operand!>"; |
Chris Lattner | c65b72c | 2009-12-31 02:33:14 +0000 | [diff] [blame] | 2446 | return; |
Chris Lattner | aab1820 | 2005-02-24 16:58:29 +0000 | [diff] [blame] | 2447 | } |
Chris Lattner | c65b72c | 2009-12-31 02:33:14 +0000 | [diff] [blame] | 2448 | if (PrintType) { |
| 2449 | TypePrinter.print(Operand->getType(), Out); |
| 2450 | Out << ' '; |
| 2451 | } |
Dan Gohman | 3bdfbf5 | 2010-07-20 23:55:01 +0000 | [diff] [blame] | 2452 | WriteAsOperandInternal(Out, Operand, &TypePrinter, &Machine, TheModule); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2453 | } |
| 2454 | |
Konstantin Zhuravlyov | 8f85685 | 2017-07-11 22:23:00 +0000 | [diff] [blame] | 2455 | void AssemblyWriter::writeSyncScope(const LLVMContext &Context, |
| 2456 | SyncScope::ID SSID) { |
| 2457 | switch (SSID) { |
| 2458 | case SyncScope::System: { |
| 2459 | break; |
| 2460 | } |
| 2461 | default: { |
| 2462 | if (SSNs.empty()) |
| 2463 | Context.getSyncScopeNames(SSNs); |
| 2464 | |
| 2465 | Out << " syncscope(\""; |
Jonas Devlieghere | 7eeba25 | 2018-05-31 17:01:42 +0000 | [diff] [blame] | 2466 | printEscapedString(SSNs[SSID], Out); |
Konstantin Zhuravlyov | 8f85685 | 2017-07-11 22:23:00 +0000 | [diff] [blame] | 2467 | Out << "\")"; |
| 2468 | break; |
| 2469 | } |
| 2470 | } |
| 2471 | } |
| 2472 | |
| 2473 | void AssemblyWriter::writeAtomic(const LLVMContext &Context, |
| 2474 | AtomicOrdering Ordering, |
| 2475 | SyncScope::ID SSID) { |
JF Bastien | b36d1a8 | 2016-04-06 21:19:33 +0000 | [diff] [blame] | 2476 | if (Ordering == AtomicOrdering::NotAtomic) |
Eli Friedman | 47f3513 | 2011-07-25 23:16:38 +0000 | [diff] [blame] | 2477 | return; |
| 2478 | |
Konstantin Zhuravlyov | 8f85685 | 2017-07-11 22:23:00 +0000 | [diff] [blame] | 2479 | writeSyncScope(Context, SSID); |
JF Bastien | b36d1a8 | 2016-04-06 21:19:33 +0000 | [diff] [blame] | 2480 | Out << " " << toIRString(Ordering); |
Eli Friedman | 47f3513 | 2011-07-25 23:16:38 +0000 | [diff] [blame] | 2481 | } |
| 2482 | |
Konstantin Zhuravlyov | 8f85685 | 2017-07-11 22:23:00 +0000 | [diff] [blame] | 2483 | void AssemblyWriter::writeAtomicCmpXchg(const LLVMContext &Context, |
| 2484 | AtomicOrdering SuccessOrdering, |
Tim Northover | ca396e3 | 2014-03-11 10:48:52 +0000 | [diff] [blame] | 2485 | AtomicOrdering FailureOrdering, |
Konstantin Zhuravlyov | 8f85685 | 2017-07-11 22:23:00 +0000 | [diff] [blame] | 2486 | SyncScope::ID SSID) { |
JF Bastien | b36d1a8 | 2016-04-06 21:19:33 +0000 | [diff] [blame] | 2487 | assert(SuccessOrdering != AtomicOrdering::NotAtomic && |
| 2488 | FailureOrdering != AtomicOrdering::NotAtomic); |
Tim Northover | ca396e3 | 2014-03-11 10:48:52 +0000 | [diff] [blame] | 2489 | |
Konstantin Zhuravlyov | 8f85685 | 2017-07-11 22:23:00 +0000 | [diff] [blame] | 2490 | writeSyncScope(Context, SSID); |
JF Bastien | b36d1a8 | 2016-04-06 21:19:33 +0000 | [diff] [blame] | 2491 | Out << " " << toIRString(SuccessOrdering); |
| 2492 | Out << " " << toIRString(FailureOrdering); |
Tim Northover | ca396e3 | 2014-03-11 10:48:52 +0000 | [diff] [blame] | 2493 | } |
| 2494 | |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 2495 | void AssemblyWriter::writeParamOperand(const Value *Operand, |
Reid Kleckner | 331b9af | 2017-04-28 18:37:16 +0000 | [diff] [blame] | 2496 | AttributeSet Attrs) { |
Craig Topper | ec0f0bc | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 2497 | if (!Operand) { |
Duncan Sands | dc02467 | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 2498 | Out << "<null operand!>"; |
Chris Lattner | c65b72c | 2009-12-31 02:33:14 +0000 | [diff] [blame] | 2499 | return; |
Duncan Sands | dc02467 | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 2500 | } |
Chris Lattner | c65b72c | 2009-12-31 02:33:14 +0000 | [diff] [blame] | 2501 | |
| 2502 | // Print the type |
| 2503 | TypePrinter.print(Operand->getType(), Out); |
| 2504 | // Print parameter attributes list |
Reid Kleckner | 331b9af | 2017-04-28 18:37:16 +0000 | [diff] [blame] | 2505 | if (Attrs.hasAttributes()) |
| 2506 | Out << ' ' << Attrs.getAsString(); |
Chris Lattner | c65b72c | 2009-12-31 02:33:14 +0000 | [diff] [blame] | 2507 | Out << ' '; |
| 2508 | // Print the operand |
Dan Gohman | 3bdfbf5 | 2010-07-20 23:55:01 +0000 | [diff] [blame] | 2509 | WriteAsOperandInternal(Out, Operand, &TypePrinter, &Machine, TheModule); |
Duncan Sands | dc02467 | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 2510 | } |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2511 | |
Chandler Carruth | 9f32dc9 | 2019-01-07 07:31:49 +0000 | [diff] [blame] | 2512 | void AssemblyWriter::writeOperandBundles(const CallBase *Call) { |
| 2513 | if (!Call->hasOperandBundles()) |
Sanjoy Das | f70eb72 | 2015-09-24 23:34:52 +0000 | [diff] [blame] | 2514 | return; |
| 2515 | |
| 2516 | Out << " [ "; |
| 2517 | |
| 2518 | bool FirstBundle = true; |
Chandler Carruth | 9f32dc9 | 2019-01-07 07:31:49 +0000 | [diff] [blame] | 2519 | for (unsigned i = 0, e = Call->getNumOperandBundles(); i != e; ++i) { |
| 2520 | OperandBundleUse BU = Call->getOperandBundleAt(i); |
Sanjoy Das | f70eb72 | 2015-09-24 23:34:52 +0000 | [diff] [blame] | 2521 | |
| 2522 | if (!FirstBundle) |
| 2523 | Out << ", "; |
| 2524 | FirstBundle = false; |
| 2525 | |
| 2526 | Out << '"'; |
Jonas Devlieghere | 7eeba25 | 2018-05-31 17:01:42 +0000 | [diff] [blame] | 2527 | printEscapedString(BU.getTagName(), Out); |
Sanjoy Das | f70eb72 | 2015-09-24 23:34:52 +0000 | [diff] [blame] | 2528 | Out << '"'; |
| 2529 | |
| 2530 | Out << '('; |
| 2531 | |
| 2532 | bool FirstInput = true; |
| 2533 | for (const auto &Input : BU.Inputs) { |
| 2534 | if (!FirstInput) |
| 2535 | Out << ", "; |
| 2536 | FirstInput = false; |
| 2537 | |
| 2538 | TypePrinter.print(Input->getType(), Out); |
| 2539 | Out << " "; |
| 2540 | WriteAsOperandInternal(Out, Input, &TypePrinter, &Machine, TheModule); |
| 2541 | } |
| 2542 | |
| 2543 | Out << ')'; |
| 2544 | } |
| 2545 | |
| 2546 | Out << " ]"; |
| 2547 | } |
| 2548 | |
Chris Lattner | c182499 | 2001-10-29 16:05:51 +0000 | [diff] [blame] | 2549 | void AssemblyWriter::printModule(const Module *M) { |
Teresa Johnson | a9961f3 | 2018-07-03 15:52:57 +0000 | [diff] [blame] | 2550 | Machine.initializeIfNeeded(); |
Bill Wendling | b29ce26 | 2013-02-11 08:43:33 +0000 | [diff] [blame] | 2551 | |
Duncan P. N. Exon Smith | c9d5dea | 2015-04-15 01:36:30 +0000 | [diff] [blame] | 2552 | if (ShouldPreserveUseListOrder) |
Duncan P. N. Exon Smith | 7838818 | 2014-08-19 21:30:15 +0000 | [diff] [blame] | 2553 | UseListOrders = predictUseListOrder(M); |
| 2554 | |
Chris Lattner | 31ab1b3 | 2005-03-02 23:12:40 +0000 | [diff] [blame] | 2555 | if (!M->getModuleIdentifier().empty() && |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 2556 | // Don't print the ID if it will start a new line (which would |
Chris Lattner | 31ab1b3 | 2005-03-02 23:12:40 +0000 | [diff] [blame] | 2557 | // require a comment char before it). |
| 2558 | M->getModuleIdentifier().find('\n') == std::string::npos) |
| 2559 | Out << "; ModuleID = '" << M->getModuleIdentifier() << "'\n"; |
| 2560 | |
Teresa Johnson | 2dec5fc | 2016-03-30 18:15:08 +0000 | [diff] [blame] | 2561 | if (!M->getSourceFileName().empty()) { |
Teresa Johnson | d47ed92 | 2016-03-30 22:17:28 +0000 | [diff] [blame] | 2562 | Out << "source_filename = \""; |
Jonas Devlieghere | 7eeba25 | 2018-05-31 17:01:42 +0000 | [diff] [blame] | 2563 | printEscapedString(M->getSourceFileName(), Out); |
Teresa Johnson | d47ed92 | 2016-03-30 22:17:28 +0000 | [diff] [blame] | 2564 | Out << "\"\n"; |
Teresa Johnson | 2dec5fc | 2016-03-30 18:15:08 +0000 | [diff] [blame] | 2565 | } |
| 2566 | |
Rafael Espindola | aab87fe | 2014-02-25 20:01:08 +0000 | [diff] [blame] | 2567 | const std::string &DL = M->getDataLayoutStr(); |
| 2568 | if (!DL.empty()) |
| 2569 | Out << "target datalayout = \"" << DL << "\"\n"; |
Reid Spencer | cddc86f | 2004-07-25 21:44:54 +0000 | [diff] [blame] | 2570 | if (!M->getTargetTriple().empty()) |
Reid Spencer | c9a1f0d | 2004-07-25 21:29:43 +0000 | [diff] [blame] | 2571 | Out << "target triple = \"" << M->getTargetTriple() << "\"\n"; |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 2572 | |
Chris Lattner | cc041ba | 2006-01-24 04:13:11 +0000 | [diff] [blame] | 2573 | if (!M->getModuleInlineAsm().empty()) { |
Dan Gohman | 9bf0b9b | 2009-08-12 23:54:22 +0000 | [diff] [blame] | 2574 | Out << '\n'; |
Benjamin Kramer | aa84794 | 2015-06-07 13:59:33 +0000 | [diff] [blame] | 2575 | |
| 2576 | // Split the string into lines, to make it easier to read the .ll file. |
Benjamin Kramer | 9ebaf8c | 2015-06-08 18:58:57 +0000 | [diff] [blame] | 2577 | StringRef Asm = M->getModuleInlineAsm(); |
Benjamin Kramer | aa84794 | 2015-06-07 13:59:33 +0000 | [diff] [blame] | 2578 | do { |
| 2579 | StringRef Front; |
| 2580 | std::tie(Front, Asm) = Asm.split('\n'); |
| 2581 | |
Chris Lattner | 42a162e | 2006-01-24 00:45:30 +0000 | [diff] [blame] | 2582 | // We found a newline, print the portion of the asm string from the |
| 2583 | // last newline up to this newline. |
| 2584 | Out << "module asm \""; |
Jonas Devlieghere | 7eeba25 | 2018-05-31 17:01:42 +0000 | [diff] [blame] | 2585 | printEscapedString(Front, Out); |
Chris Lattner | 42a162e | 2006-01-24 00:45:30 +0000 | [diff] [blame] | 2586 | Out << "\"\n"; |
Benjamin Kramer | aa84794 | 2015-06-07 13:59:33 +0000 | [diff] [blame] | 2587 | } while (!Asm.empty()); |
Chris Lattner | 1836550 | 2006-01-23 23:03:36 +0000 | [diff] [blame] | 2588 | } |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 2589 | |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 2590 | printTypeIdentities(); |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 2591 | |
David Majnemer | c8a1169 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 2592 | // Output all comdats. |
| 2593 | if (!Comdats.empty()) |
| 2594 | Out << '\n'; |
| 2595 | for (const Comdat *C : Comdats) { |
| 2596 | printComdat(C); |
| 2597 | if (C != Comdats.back()) |
| 2598 | Out << '\n'; |
| 2599 | } |
| 2600 | |
Dan Gohman | 9bf0b9b | 2009-08-12 23:54:22 +0000 | [diff] [blame] | 2601 | // Output all globals. |
| 2602 | if (!M->global_empty()) Out << '\n'; |
Yaron Keren | 09eacc1 | 2015-06-13 17:50:47 +0000 | [diff] [blame] | 2603 | for (const GlobalVariable &GV : M->globals()) { |
| 2604 | printGlobal(&GV); Out << '\n'; |
Duncan Sands | 79da6ef | 2012-09-12 09:55:51 +0000 | [diff] [blame] | 2605 | } |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 2606 | |
Chris Lattner | 69dacfc | 2007-04-26 02:24:10 +0000 | [diff] [blame] | 2607 | // Output all aliases. |
| 2608 | if (!M->alias_empty()) Out << "\n"; |
Yaron Keren | 09eacc1 | 2015-06-13 17:50:47 +0000 | [diff] [blame] | 2609 | for (const GlobalAlias &GA : M->aliases()) |
Dmitry Polukhin | 51a06a2 | 2016-04-05 08:47:51 +0000 | [diff] [blame] | 2610 | printIndirectSymbol(&GA); |
Chris Lattner | 007377f | 2001-09-07 16:36:04 +0000 | [diff] [blame] | 2611 | |
Dmitry Polukhin | ba49223 | 2016-04-07 12:32:19 +0000 | [diff] [blame] | 2612 | // Output all ifuncs. |
| 2613 | if (!M->ifunc_empty()) Out << "\n"; |
| 2614 | for (const GlobalIFunc &GI : M->ifuncs()) |
| 2615 | printIndirectSymbol(&GI); |
| 2616 | |
Duncan P. N. Exon Smith | 7838818 | 2014-08-19 21:30:15 +0000 | [diff] [blame] | 2617 | // Output global use-lists. |
| 2618 | printUseLists(nullptr); |
| 2619 | |
Chris Lattner | 44da7d7 | 2004-09-14 05:06:58 +0000 | [diff] [blame] | 2620 | // Output all of the functions. |
Yaron Keren | 09eacc1 | 2015-06-13 17:50:47 +0000 | [diff] [blame] | 2621 | for (const Function &F : *M) |
| 2622 | printFunction(&F); |
Duncan P. N. Exon Smith | 7838818 | 2014-08-19 21:30:15 +0000 | [diff] [blame] | 2623 | assert(UseListOrders.empty() && "All use-lists should have been consumed"); |
Devang Patel | 320671d | 2009-07-08 21:44:25 +0000 | [diff] [blame] | 2624 | |
Bill Wendling | b29ce26 | 2013-02-11 08:43:33 +0000 | [diff] [blame] | 2625 | // Output all attribute groups. |
Bill Wendling | 725dae5 | 2013-04-29 23:48:06 +0000 | [diff] [blame] | 2626 | if (!Machine.as_empty()) { |
Bill Wendling | b29ce26 | 2013-02-11 08:43:33 +0000 | [diff] [blame] | 2627 | Out << '\n'; |
| 2628 | writeAllAttributeGroups(); |
| 2629 | } |
| 2630 | |
Devang Patel | 37c4a2d | 2009-07-29 22:04:47 +0000 | [diff] [blame] | 2631 | // Output named metadata. |
Dan Gohman | 9bf0b9b | 2009-08-12 23:54:22 +0000 | [diff] [blame] | 2632 | if (!M->named_metadata_empty()) Out << '\n'; |
Andrew Trick | 18801ec | 2011-09-30 19:48:58 +0000 | [diff] [blame] | 2633 | |
Yaron Keren | 09eacc1 | 2015-06-13 17:50:47 +0000 | [diff] [blame] | 2634 | for (const NamedMDNode &Node : M->named_metadata()) |
| 2635 | printNamedMDNode(&Node); |
Devang Patel | 37c4a2d | 2009-07-29 22:04:47 +0000 | [diff] [blame] | 2636 | |
| 2637 | // Output metadata. |
Chris Lattner | 307c989 | 2009-12-31 02:20:11 +0000 | [diff] [blame] | 2638 | if (!Machine.mdn_empty()) { |
Chris Lattner | 6e6b180 | 2009-12-31 02:13:35 +0000 | [diff] [blame] | 2639 | Out << '\n'; |
| 2640 | writeAllMDNodes(); |
| 2641 | } |
Chris Lattner | 007377f | 2001-09-07 16:36:04 +0000 | [diff] [blame] | 2642 | } |
| 2643 | |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 2644 | void AssemblyWriter::printModuleSummaryIndex() { |
| 2645 | assert(TheIndex); |
Teresa Johnson | a9961f3 | 2018-07-03 15:52:57 +0000 | [diff] [blame] | 2646 | Machine.initializeIndexIfNeeded(); |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 2647 | |
| 2648 | Out << "\n"; |
| 2649 | |
Teresa Johnson | 807ab958 | 2018-07-02 22:09:23 +0000 | [diff] [blame] | 2650 | // Print module path entries. To print in order, add paths to a vector |
| 2651 | // indexed by module slot. |
Teresa Johnson | 601e1a7 | 2018-05-26 02:53:52 +0000 | [diff] [blame] | 2652 | std::vector<std::pair<std::string, ModuleHash>> moduleVec; |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 2653 | std::string RegularLTOModuleName = "[Regular LTO]"; |
| 2654 | moduleVec.resize(TheIndex->modulePaths().size()); |
Teresa Johnson | 807ab958 | 2018-07-02 22:09:23 +0000 | [diff] [blame] | 2655 | for (auto &ModPath : TheIndex->modulePaths()) |
| 2656 | moduleVec[Machine.getModulePathSlot(ModPath.first())] = std::make_pair( |
| 2657 | // A module id of -1 is a special entry for a regular LTO module created |
| 2658 | // during the thin link. |
| 2659 | ModPath.second.first == -1u ? RegularLTOModuleName |
| 2660 | : (std::string)ModPath.first(), |
| 2661 | ModPath.second.second); |
| 2662 | |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 2663 | unsigned i = 0; |
| 2664 | for (auto &ModPair : moduleVec) { |
| 2665 | Out << "^" << i++ << " = module: ("; |
Andrew Ng | f6e6165 | 2018-07-12 14:40:21 +0000 | [diff] [blame] | 2666 | Out << "path: \""; |
| 2667 | printEscapedString(ModPair.first, Out); |
| 2668 | Out << "\", hash: ("; |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 2669 | FieldSeparator FS; |
| 2670 | for (auto Hash : ModPair.second) |
| 2671 | Out << FS << Hash; |
| 2672 | Out << "))\n"; |
| 2673 | } |
| 2674 | |
| 2675 | // FIXME: Change AliasSummary to hold a ValueInfo instead of summary pointer |
| 2676 | // for aliasee (then update BitcodeWriter.cpp and remove get/setAliaseeGUID). |
| 2677 | for (auto &GlobalList : *TheIndex) { |
| 2678 | auto GUID = GlobalList.first; |
| 2679 | for (auto &Summary : GlobalList.second.SummaryList) |
| 2680 | SummaryToGUIDMap[Summary.get()] = GUID; |
| 2681 | } |
| 2682 | |
| 2683 | // Print the global value summary entries. |
| 2684 | for (auto &GlobalList : *TheIndex) { |
| 2685 | auto GUID = GlobalList.first; |
| 2686 | auto VI = TheIndex->getValueInfo(GlobalList); |
| 2687 | printSummaryInfo(Machine.getGUIDSlot(GUID), VI); |
| 2688 | } |
| 2689 | |
| 2690 | // Print the TypeIdMap entries. |
Teresa Johnson | 0d4dfd2 | 2018-09-25 20:14:40 +0000 | [diff] [blame] | 2691 | for (auto TidIter = TheIndex->typeIds().begin(); |
| 2692 | TidIter != TheIndex->typeIds().end(); TidIter++) { |
| 2693 | Out << "^" << Machine.getTypeIdSlot(TidIter->second.first) |
| 2694 | << " = typeid: (name: \"" << TidIter->second.first << "\""; |
| 2695 | printTypeIdSummary(TidIter->second.second); |
| 2696 | Out << ") ; guid = " << TidIter->first << "\n"; |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 2697 | } |
| 2698 | } |
| 2699 | |
| 2700 | static const char * |
| 2701 | getWholeProgDevirtResKindName(WholeProgramDevirtResolution::Kind K) { |
| 2702 | switch (K) { |
| 2703 | case WholeProgramDevirtResolution::Indir: |
| 2704 | return "indir"; |
| 2705 | case WholeProgramDevirtResolution::SingleImpl: |
| 2706 | return "singleImpl"; |
| 2707 | case WholeProgramDevirtResolution::BranchFunnel: |
| 2708 | return "branchFunnel"; |
| 2709 | } |
| 2710 | llvm_unreachable("invalid WholeProgramDevirtResolution kind"); |
| 2711 | } |
| 2712 | |
| 2713 | static const char *getWholeProgDevirtResByArgKindName( |
| 2714 | WholeProgramDevirtResolution::ByArg::Kind K) { |
| 2715 | switch (K) { |
| 2716 | case WholeProgramDevirtResolution::ByArg::Indir: |
| 2717 | return "indir"; |
| 2718 | case WholeProgramDevirtResolution::ByArg::UniformRetVal: |
| 2719 | return "uniformRetVal"; |
| 2720 | case WholeProgramDevirtResolution::ByArg::UniqueRetVal: |
| 2721 | return "uniqueRetVal"; |
| 2722 | case WholeProgramDevirtResolution::ByArg::VirtualConstProp: |
| 2723 | return "virtualConstProp"; |
| 2724 | } |
| 2725 | llvm_unreachable("invalid WholeProgramDevirtResolution::ByArg kind"); |
| 2726 | } |
| 2727 | |
| 2728 | static const char *getTTResKindName(TypeTestResolution::Kind K) { |
| 2729 | switch (K) { |
| 2730 | case TypeTestResolution::Unsat: |
| 2731 | return "unsat"; |
| 2732 | case TypeTestResolution::ByteArray: |
| 2733 | return "byteArray"; |
| 2734 | case TypeTestResolution::Inline: |
| 2735 | return "inline"; |
| 2736 | case TypeTestResolution::Single: |
| 2737 | return "single"; |
| 2738 | case TypeTestResolution::AllOnes: |
| 2739 | return "allOnes"; |
| 2740 | } |
| 2741 | llvm_unreachable("invalid TypeTestResolution kind"); |
| 2742 | } |
| 2743 | |
| 2744 | void AssemblyWriter::printTypeTestResolution(const TypeTestResolution &TTRes) { |
| 2745 | Out << "typeTestRes: (kind: " << getTTResKindName(TTRes.TheKind) |
| 2746 | << ", sizeM1BitWidth: " << TTRes.SizeM1BitWidth; |
| 2747 | |
| 2748 | // The following fields are only used if the target does not support the use |
| 2749 | // of absolute symbols to store constants. Print only if non-zero. |
| 2750 | if (TTRes.AlignLog2) |
| 2751 | Out << ", alignLog2: " << TTRes.AlignLog2; |
| 2752 | if (TTRes.SizeM1) |
| 2753 | Out << ", sizeM1: " << TTRes.SizeM1; |
| 2754 | if (TTRes.BitMask) |
| 2755 | // BitMask is uint8_t which causes it to print the corresponding char. |
| 2756 | Out << ", bitMask: " << (unsigned)TTRes.BitMask; |
| 2757 | if (TTRes.InlineBits) |
| 2758 | Out << ", inlineBits: " << TTRes.InlineBits; |
| 2759 | |
| 2760 | Out << ")"; |
| 2761 | } |
| 2762 | |
| 2763 | void AssemblyWriter::printTypeIdSummary(const TypeIdSummary &TIS) { |
| 2764 | Out << ", summary: ("; |
| 2765 | printTypeTestResolution(TIS.TTRes); |
| 2766 | if (!TIS.WPDRes.empty()) { |
| 2767 | Out << ", wpdResolutions: ("; |
| 2768 | FieldSeparator FS; |
| 2769 | for (auto &WPDRes : TIS.WPDRes) { |
| 2770 | Out << FS; |
| 2771 | Out << "(offset: " << WPDRes.first << ", "; |
| 2772 | printWPDRes(WPDRes.second); |
| 2773 | Out << ")"; |
| 2774 | } |
| 2775 | Out << ")"; |
| 2776 | } |
| 2777 | Out << ")"; |
| 2778 | } |
| 2779 | |
| 2780 | void AssemblyWriter::printArgs(const std::vector<uint64_t> &Args) { |
| 2781 | Out << "args: ("; |
| 2782 | FieldSeparator FS; |
| 2783 | for (auto arg : Args) { |
| 2784 | Out << FS; |
| 2785 | Out << arg; |
| 2786 | } |
| 2787 | Out << ")"; |
| 2788 | } |
| 2789 | |
| 2790 | void AssemblyWriter::printWPDRes(const WholeProgramDevirtResolution &WPDRes) { |
| 2791 | Out << "wpdRes: (kind: "; |
| 2792 | Out << getWholeProgDevirtResKindName(WPDRes.TheKind); |
| 2793 | |
| 2794 | if (WPDRes.TheKind == WholeProgramDevirtResolution::SingleImpl) |
| 2795 | Out << ", singleImplName: \"" << WPDRes.SingleImplName << "\""; |
| 2796 | |
| 2797 | if (!WPDRes.ResByArg.empty()) { |
| 2798 | Out << ", resByArg: ("; |
| 2799 | FieldSeparator FS; |
| 2800 | for (auto &ResByArg : WPDRes.ResByArg) { |
| 2801 | Out << FS; |
| 2802 | printArgs(ResByArg.first); |
| 2803 | Out << ", byArg: (kind: "; |
| 2804 | Out << getWholeProgDevirtResByArgKindName(ResByArg.second.TheKind); |
| 2805 | if (ResByArg.second.TheKind == |
| 2806 | WholeProgramDevirtResolution::ByArg::UniformRetVal || |
| 2807 | ResByArg.second.TheKind == |
| 2808 | WholeProgramDevirtResolution::ByArg::UniqueRetVal) |
| 2809 | Out << ", info: " << ResByArg.second.Info; |
| 2810 | |
| 2811 | // The following fields are only used if the target does not support the |
| 2812 | // use of absolute symbols to store constants. Print only if non-zero. |
| 2813 | if (ResByArg.second.Byte || ResByArg.second.Bit) |
| 2814 | Out << ", byte: " << ResByArg.second.Byte |
| 2815 | << ", bit: " << ResByArg.second.Bit; |
| 2816 | |
| 2817 | Out << ")"; |
| 2818 | } |
| 2819 | Out << ")"; |
| 2820 | } |
| 2821 | Out << ")"; |
| 2822 | } |
| 2823 | |
| 2824 | static const char *getSummaryKindName(GlobalValueSummary::SummaryKind SK) { |
| 2825 | switch (SK) { |
| 2826 | case GlobalValueSummary::AliasKind: |
| 2827 | return "alias"; |
| 2828 | case GlobalValueSummary::FunctionKind: |
| 2829 | return "function"; |
| 2830 | case GlobalValueSummary::GlobalVarKind: |
| 2831 | return "variable"; |
| 2832 | } |
| 2833 | llvm_unreachable("invalid summary kind"); |
| 2834 | } |
| 2835 | |
| 2836 | void AssemblyWriter::printAliasSummary(const AliasSummary *AS) { |
Teresa Johnson | 3aca69c | 2018-07-03 01:11:43 +0000 | [diff] [blame] | 2837 | Out << ", aliasee: "; |
| 2838 | // The indexes emitted for distributed backends may not include the |
| 2839 | // aliasee summary (only if it is being imported directly). Handle |
| 2840 | // that case by just emitting "null" as the aliasee. |
| 2841 | if (AS->hasAliasee()) |
| 2842 | Out << "^" << Machine.getGUIDSlot(SummaryToGUIDMap[&AS->getAliasee()]); |
| 2843 | else |
| 2844 | Out << "null"; |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 2845 | } |
| 2846 | |
| 2847 | void AssemblyWriter::printGlobalVarSummary(const GlobalVarSummary *GS) { |
Eugene Leviant | ae9f773 | 2018-11-23 10:54:51 +0000 | [diff] [blame] | 2848 | Out << ", varFlags: (readonly: " << GS->VarFlags.ReadOnly << ")"; |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 2849 | } |
| 2850 | |
Teresa Johnson | f1f35aa | 2018-05-25 15:15:39 +0000 | [diff] [blame] | 2851 | static std::string getLinkageName(GlobalValue::LinkageTypes LT) { |
| 2852 | switch (LT) { |
| 2853 | case GlobalValue::ExternalLinkage: |
| 2854 | return "external"; |
| 2855 | case GlobalValue::PrivateLinkage: |
| 2856 | return "private"; |
| 2857 | case GlobalValue::InternalLinkage: |
| 2858 | return "internal"; |
| 2859 | case GlobalValue::LinkOnceAnyLinkage: |
| 2860 | return "linkonce"; |
| 2861 | case GlobalValue::LinkOnceODRLinkage: |
| 2862 | return "linkonce_odr"; |
| 2863 | case GlobalValue::WeakAnyLinkage: |
| 2864 | return "weak"; |
| 2865 | case GlobalValue::WeakODRLinkage: |
| 2866 | return "weak_odr"; |
| 2867 | case GlobalValue::CommonLinkage: |
| 2868 | return "common"; |
| 2869 | case GlobalValue::AppendingLinkage: |
| 2870 | return "appending"; |
| 2871 | case GlobalValue::ExternalWeakLinkage: |
| 2872 | return "extern_weak"; |
| 2873 | case GlobalValue::AvailableExternallyLinkage: |
| 2874 | return "available_externally"; |
| 2875 | } |
| 2876 | llvm_unreachable("invalid linkage"); |
| 2877 | } |
| 2878 | |
| 2879 | // When printing the linkage types in IR where the ExternalLinkage is |
| 2880 | // not printed, and other linkage types are expected to be printed with |
| 2881 | // a space after the name. |
| 2882 | static std::string getLinkageNameWithSpace(GlobalValue::LinkageTypes LT) { |
| 2883 | if (LT == GlobalValue::ExternalLinkage) |
| 2884 | return ""; |
| 2885 | return getLinkageName(LT) + " "; |
| 2886 | } |
| 2887 | |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 2888 | void AssemblyWriter::printFunctionSummary(const FunctionSummary *FS) { |
| 2889 | Out << ", insts: " << FS->instCount(); |
| 2890 | |
| 2891 | FunctionSummary::FFlags FFlags = FS->fflags(); |
| 2892 | if (FFlags.ReadNone | FFlags.ReadOnly | FFlags.NoRecurse | |
| 2893 | FFlags.ReturnDoesNotAlias) { |
| 2894 | Out << ", funcFlags: ("; |
| 2895 | Out << "readNone: " << FFlags.ReadNone; |
| 2896 | Out << ", readOnly: " << FFlags.ReadOnly; |
| 2897 | Out << ", noRecurse: " << FFlags.NoRecurse; |
| 2898 | Out << ", returnDoesNotAlias: " << FFlags.ReturnDoesNotAlias; |
Teresa Johnson | 645cd31 | 2018-11-06 19:41:35 +0000 | [diff] [blame] | 2899 | Out << ", noInline: " << FFlags.NoInline; |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 2900 | Out << ")"; |
| 2901 | } |
| 2902 | if (!FS->calls().empty()) { |
| 2903 | Out << ", calls: ("; |
| 2904 | FieldSeparator IFS; |
| 2905 | for (auto &Call : FS->calls()) { |
| 2906 | Out << IFS; |
| 2907 | Out << "(callee: ^" << Machine.getGUIDSlot(Call.first.getGUID()); |
| 2908 | if (Call.second.getHotness() != CalleeInfo::HotnessType::Unknown) |
| 2909 | Out << ", hotness: " << getHotnessName(Call.second.getHotness()); |
| 2910 | else if (Call.second.RelBlockFreq) |
| 2911 | Out << ", relbf: " << Call.second.RelBlockFreq; |
| 2912 | Out << ")"; |
| 2913 | } |
| 2914 | Out << ")"; |
| 2915 | } |
| 2916 | |
| 2917 | if (const auto *TIdInfo = FS->getTypeIdInfo()) |
| 2918 | printTypeIdInfo(*TIdInfo); |
| 2919 | } |
| 2920 | |
| 2921 | void AssemblyWriter::printTypeIdInfo( |
| 2922 | const FunctionSummary::TypeIdInfo &TIDInfo) { |
| 2923 | Out << ", typeIdInfo: ("; |
| 2924 | FieldSeparator TIDFS; |
| 2925 | if (!TIDInfo.TypeTests.empty()) { |
| 2926 | Out << TIDFS; |
| 2927 | Out << "typeTests: ("; |
| 2928 | FieldSeparator FS; |
| 2929 | for (auto &GUID : TIDInfo.TypeTests) { |
Teresa Johnson | 0d4dfd2 | 2018-09-25 20:14:40 +0000 | [diff] [blame] | 2930 | auto TidIter = TheIndex->typeIds().equal_range(GUID); |
| 2931 | if (TidIter.first == TidIter.second) { |
| 2932 | Out << FS; |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 2933 | Out << GUID; |
Teresa Johnson | 0d4dfd2 | 2018-09-25 20:14:40 +0000 | [diff] [blame] | 2934 | continue; |
| 2935 | } |
| 2936 | // Print all type id that correspond to this GUID. |
| 2937 | for (auto It = TidIter.first; It != TidIter.second; ++It) { |
| 2938 | Out << FS; |
| 2939 | auto Slot = Machine.getTypeIdSlot(It->second.first); |
| 2940 | assert(Slot != -1); |
| 2941 | Out << "^" << Slot; |
| 2942 | } |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 2943 | } |
| 2944 | Out << ")"; |
| 2945 | } |
| 2946 | if (!TIDInfo.TypeTestAssumeVCalls.empty()) { |
| 2947 | Out << TIDFS; |
| 2948 | printNonConstVCalls(TIDInfo.TypeTestAssumeVCalls, "typeTestAssumeVCalls"); |
| 2949 | } |
| 2950 | if (!TIDInfo.TypeCheckedLoadVCalls.empty()) { |
| 2951 | Out << TIDFS; |
| 2952 | printNonConstVCalls(TIDInfo.TypeCheckedLoadVCalls, "typeCheckedLoadVCalls"); |
| 2953 | } |
| 2954 | if (!TIDInfo.TypeTestAssumeConstVCalls.empty()) { |
| 2955 | Out << TIDFS; |
| 2956 | printConstVCalls(TIDInfo.TypeTestAssumeConstVCalls, |
| 2957 | "typeTestAssumeConstVCalls"); |
| 2958 | } |
| 2959 | if (!TIDInfo.TypeCheckedLoadConstVCalls.empty()) { |
| 2960 | Out << TIDFS; |
| 2961 | printConstVCalls(TIDInfo.TypeCheckedLoadConstVCalls, |
| 2962 | "typeCheckedLoadConstVCalls"); |
| 2963 | } |
| 2964 | Out << ")"; |
| 2965 | } |
| 2966 | |
| 2967 | void AssemblyWriter::printVFuncId(const FunctionSummary::VFuncId VFId) { |
Teresa Johnson | 0d4dfd2 | 2018-09-25 20:14:40 +0000 | [diff] [blame] | 2968 | auto TidIter = TheIndex->typeIds().equal_range(VFId.GUID); |
| 2969 | if (TidIter.first == TidIter.second) { |
| 2970 | Out << "vFuncId: ("; |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 2971 | Out << "guid: " << VFId.GUID; |
Teresa Johnson | 0d4dfd2 | 2018-09-25 20:14:40 +0000 | [diff] [blame] | 2972 | Out << ", offset: " << VFId.Offset; |
| 2973 | Out << ")"; |
| 2974 | return; |
| 2975 | } |
| 2976 | // Print all type id that correspond to this GUID. |
| 2977 | FieldSeparator FS; |
| 2978 | for (auto It = TidIter.first; It != TidIter.second; ++It) { |
| 2979 | Out << FS; |
| 2980 | Out << "vFuncId: ("; |
| 2981 | auto Slot = Machine.getTypeIdSlot(It->second.first); |
| 2982 | assert(Slot != -1); |
| 2983 | Out << "^" << Slot; |
| 2984 | Out << ", offset: " << VFId.Offset; |
| 2985 | Out << ")"; |
| 2986 | } |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 2987 | } |
| 2988 | |
| 2989 | void AssemblyWriter::printNonConstVCalls( |
| 2990 | const std::vector<FunctionSummary::VFuncId> VCallList, const char *Tag) { |
| 2991 | Out << Tag << ": ("; |
| 2992 | FieldSeparator FS; |
| 2993 | for (auto &VFuncId : VCallList) { |
| 2994 | Out << FS; |
| 2995 | printVFuncId(VFuncId); |
| 2996 | } |
| 2997 | Out << ")"; |
| 2998 | } |
| 2999 | |
| 3000 | void AssemblyWriter::printConstVCalls( |
| 3001 | const std::vector<FunctionSummary::ConstVCall> VCallList, const char *Tag) { |
| 3002 | Out << Tag << ": ("; |
| 3003 | FieldSeparator FS; |
| 3004 | for (auto &ConstVCall : VCallList) { |
| 3005 | Out << FS; |
Teresa Johnson | d64c9dd | 2018-08-14 01:49:33 +0000 | [diff] [blame] | 3006 | Out << "("; |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 3007 | printVFuncId(ConstVCall.VFunc); |
| 3008 | if (!ConstVCall.Args.empty()) { |
| 3009 | Out << ", "; |
| 3010 | printArgs(ConstVCall.Args); |
| 3011 | } |
Teresa Johnson | d64c9dd | 2018-08-14 01:49:33 +0000 | [diff] [blame] | 3012 | Out << ")"; |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 3013 | } |
| 3014 | Out << ")"; |
| 3015 | } |
| 3016 | |
| 3017 | void AssemblyWriter::printSummary(const GlobalValueSummary &Summary) { |
| 3018 | GlobalValueSummary::GVFlags GVFlags = Summary.flags(); |
| 3019 | GlobalValue::LinkageTypes LT = (GlobalValue::LinkageTypes)GVFlags.Linkage; |
| 3020 | Out << getSummaryKindName(Summary.getSummaryKind()) << ": "; |
Teresa Johnson | 807ab958 | 2018-07-02 22:09:23 +0000 | [diff] [blame] | 3021 | Out << "(module: ^" << Machine.getModulePathSlot(Summary.modulePath()) |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 3022 | << ", flags: ("; |
| 3023 | Out << "linkage: " << getLinkageName(LT); |
| 3024 | Out << ", notEligibleToImport: " << GVFlags.NotEligibleToImport; |
| 3025 | Out << ", live: " << GVFlags.Live; |
| 3026 | Out << ", dsoLocal: " << GVFlags.DSOLocal; |
| 3027 | Out << ")"; |
| 3028 | |
| 3029 | if (Summary.getSummaryKind() == GlobalValueSummary::AliasKind) |
| 3030 | printAliasSummary(cast<AliasSummary>(&Summary)); |
| 3031 | else if (Summary.getSummaryKind() == GlobalValueSummary::FunctionKind) |
| 3032 | printFunctionSummary(cast<FunctionSummary>(&Summary)); |
| 3033 | else |
| 3034 | printGlobalVarSummary(cast<GlobalVarSummary>(&Summary)); |
| 3035 | |
| 3036 | auto RefList = Summary.refs(); |
| 3037 | if (!RefList.empty()) { |
| 3038 | Out << ", refs: ("; |
| 3039 | FieldSeparator FS; |
| 3040 | for (auto &Ref : RefList) { |
| 3041 | Out << FS; |
Eugene Leviant | ae9f773 | 2018-11-23 10:54:51 +0000 | [diff] [blame] | 3042 | if (Ref.isReadOnly()) |
| 3043 | Out << "readonly "; |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 3044 | Out << "^" << Machine.getGUIDSlot(Ref.getGUID()); |
| 3045 | } |
| 3046 | Out << ")"; |
| 3047 | } |
| 3048 | |
| 3049 | Out << ")"; |
| 3050 | } |
| 3051 | |
| 3052 | void AssemblyWriter::printSummaryInfo(unsigned Slot, const ValueInfo &VI) { |
| 3053 | Out << "^" << Slot << " = gv: ("; |
| 3054 | if (!VI.name().empty()) |
| 3055 | Out << "name: \"" << VI.name() << "\""; |
| 3056 | else |
| 3057 | Out << "guid: " << VI.getGUID(); |
| 3058 | if (!VI.getSummaryList().empty()) { |
| 3059 | Out << ", summaries: ("; |
| 3060 | FieldSeparator FS; |
| 3061 | for (auto &Summary : VI.getSummaryList()) { |
| 3062 | Out << FS; |
| 3063 | printSummary(*Summary); |
| 3064 | } |
| 3065 | Out << ")"; |
| 3066 | } |
| 3067 | Out << ")"; |
| 3068 | if (!VI.name().empty()) |
| 3069 | Out << " ; guid = " << VI.getGUID(); |
| 3070 | Out << "\n"; |
| 3071 | } |
| 3072 | |
Filipe Cabecinhas | 6af0f89 | 2015-06-02 21:25:08 +0000 | [diff] [blame] | 3073 | static void printMetadataIdentifier(StringRef Name, |
| 3074 | formatted_raw_ostream &Out) { |
Nick Lewycky | 9100a78 | 2011-06-15 06:37:58 +0000 | [diff] [blame] | 3075 | if (Name.empty()) { |
| 3076 | Out << "<empty name> "; |
| 3077 | } else { |
Filipe Cabecinhas | 581e255 | 2015-06-02 21:25:00 +0000 | [diff] [blame] | 3078 | if (isalpha(static_cast<unsigned char>(Name[0])) || Name[0] == '-' || |
| 3079 | Name[0] == '$' || Name[0] == '.' || Name[0] == '_') |
Nick Lewycky | 9100a78 | 2011-06-15 06:37:58 +0000 | [diff] [blame] | 3080 | Out << Name[0]; |
| 3081 | else |
| 3082 | Out << '\\' << hexdigit(Name[0] >> 4) << hexdigit(Name[0] & 0x0F); |
| 3083 | for (unsigned i = 1, e = Name.size(); i != e; ++i) { |
| 3084 | unsigned char C = Name[i]; |
Guy Benyei | 87d0b9e | 2013-02-12 21:21:59 +0000 | [diff] [blame] | 3085 | if (isalnum(static_cast<unsigned char>(C)) || C == '-' || C == '$' || |
| 3086 | C == '.' || C == '_') |
Nick Lewycky | 9100a78 | 2011-06-15 06:37:58 +0000 | [diff] [blame] | 3087 | Out << C; |
| 3088 | else |
| 3089 | Out << '\\' << hexdigit(C >> 4) << hexdigit(C & 0x0F); |
| 3090 | } |
| 3091 | } |
Filipe Cabecinhas | 6af0f89 | 2015-06-02 21:25:08 +0000 | [diff] [blame] | 3092 | } |
| 3093 | |
| 3094 | void AssemblyWriter::printNamedMDNode(const NamedMDNode *NMD) { |
| 3095 | Out << '!'; |
| 3096 | printMetadataIdentifier(NMD->getName(), Out); |
Nick Lewycky | 9100a78 | 2011-06-15 06:37:58 +0000 | [diff] [blame] | 3097 | Out << " = !{"; |
Chris Lattner | fdb3356 | 2009-12-31 01:54:05 +0000 | [diff] [blame] | 3098 | for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) { |
Filipe Cabecinhas | 581e255 | 2015-06-02 21:25:00 +0000 | [diff] [blame] | 3099 | if (i) |
| 3100 | Out << ", "; |
Reid Kleckner | a5b2af0 | 2017-08-23 20:31:27 +0000 | [diff] [blame] | 3101 | |
| 3102 | // Write DIExpressions inline. |
| 3103 | // FIXME: Ban DIExpressions in NamedMDNodes, they will serve no purpose. |
| 3104 | MDNode *Op = NMD->getOperand(i); |
| 3105 | if (auto *Expr = dyn_cast<DIExpression>(Op)) { |
| 3106 | writeDIExpression(Out, Expr, nullptr, nullptr, nullptr); |
| 3107 | continue; |
| 3108 | } |
| 3109 | |
| 3110 | int Slot = Machine.getMetadataSlot(Op); |
Dan Gohman | 3da076f | 2010-09-09 20:53:58 +0000 | [diff] [blame] | 3111 | if (Slot == -1) |
| 3112 | Out << "<badref>"; |
| 3113 | else |
| 3114 | Out << '!' << Slot; |
Chris Lattner | fdb3356 | 2009-12-31 01:54:05 +0000 | [diff] [blame] | 3115 | } |
| 3116 | Out << "}\n"; |
| 3117 | } |
| 3118 | |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 3119 | static void PrintVisibility(GlobalValue::VisibilityTypes Vis, |
Dan Gohman | 683e922 | 2009-08-12 17:23:50 +0000 | [diff] [blame] | 3120 | formatted_raw_ostream &Out) { |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 3121 | switch (Vis) { |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 3122 | case GlobalValue::DefaultVisibility: break; |
| 3123 | case GlobalValue::HiddenVisibility: Out << "hidden "; break; |
| 3124 | case GlobalValue::ProtectedVisibility: Out << "protected "; break; |
| 3125 | } |
| 3126 | } |
| 3127 | |
Rafael Espindola | 1e1801c | 2018-01-11 22:15:05 +0000 | [diff] [blame] | 3128 | static void PrintDSOLocation(const GlobalValue &GV, |
| 3129 | formatted_raw_ostream &Out) { |
Rafael Espindola | 7e523c1 | 2018-01-18 02:08:23 +0000 | [diff] [blame] | 3130 | // GVs with local linkage or non default visibility are implicitly dso_local, |
| 3131 | // so we don't print it. |
| 3132 | bool Implicit = GV.hasLocalLinkage() || |
| 3133 | (!GV.hasExternalWeakLinkage() && !GV.hasDefaultVisibility()); |
| 3134 | if (GV.isDSOLocal() && !Implicit) |
Sean Fertile | 509132b | 2017-10-26 15:00:26 +0000 | [diff] [blame] | 3135 | Out << "dso_local "; |
| 3136 | } |
| 3137 | |
Nico Rieck | 38f68c5 | 2014-01-14 15:22:47 +0000 | [diff] [blame] | 3138 | static void PrintDLLStorageClass(GlobalValue::DLLStorageClassTypes SCT, |
| 3139 | formatted_raw_ostream &Out) { |
| 3140 | switch (SCT) { |
| 3141 | case GlobalValue::DefaultStorageClass: break; |
| 3142 | case GlobalValue::DLLImportStorageClass: Out << "dllimport "; break; |
| 3143 | case GlobalValue::DLLExportStorageClass: Out << "dllexport "; break; |
| 3144 | } |
| 3145 | } |
| 3146 | |
Hans Wennborg | ce718ff | 2012-06-23 11:37:03 +0000 | [diff] [blame] | 3147 | static void PrintThreadLocalModel(GlobalVariable::ThreadLocalMode TLM, |
| 3148 | formatted_raw_ostream &Out) { |
| 3149 | switch (TLM) { |
| 3150 | case GlobalVariable::NotThreadLocal: |
| 3151 | break; |
| 3152 | case GlobalVariable::GeneralDynamicTLSModel: |
| 3153 | Out << "thread_local "; |
| 3154 | break; |
| 3155 | case GlobalVariable::LocalDynamicTLSModel: |
| 3156 | Out << "thread_local(localdynamic) "; |
| 3157 | break; |
| 3158 | case GlobalVariable::InitialExecTLSModel: |
| 3159 | Out << "thread_local(initialexec) "; |
| 3160 | break; |
| 3161 | case GlobalVariable::LocalExecTLSModel: |
| 3162 | Out << "thread_local(localexec) "; |
| 3163 | break; |
| 3164 | } |
| 3165 | } |
| 3166 | |
Peter Collingbourne | 63b34cd | 2016-06-14 21:01:22 +0000 | [diff] [blame] | 3167 | static StringRef getUnnamedAddrEncoding(GlobalVariable::UnnamedAddr UA) { |
| 3168 | switch (UA) { |
| 3169 | case GlobalVariable::UnnamedAddr::None: |
| 3170 | return ""; |
| 3171 | case GlobalVariable::UnnamedAddr::Local: |
| 3172 | return "local_unnamed_addr"; |
| 3173 | case GlobalVariable::UnnamedAddr::Global: |
| 3174 | return "unnamed_addr"; |
| 3175 | } |
Aaron Ballman | 0774f89 | 2016-06-15 15:27:53 +0000 | [diff] [blame] | 3176 | llvm_unreachable("Unknown UnnamedAddr"); |
Peter Collingbourne | 63b34cd | 2016-06-14 21:01:22 +0000 | [diff] [blame] | 3177 | } |
| 3178 | |
Rafael Espindola | f907a26 | 2015-01-06 22:55:16 +0000 | [diff] [blame] | 3179 | static void maybePrintComdat(formatted_raw_ostream &Out, |
| 3180 | const GlobalObject &GO) { |
| 3181 | const Comdat *C = GO.getComdat(); |
| 3182 | if (!C) |
| 3183 | return; |
| 3184 | |
| 3185 | if (isa<GlobalVariable>(GO)) |
| 3186 | Out << ','; |
| 3187 | Out << " comdat"; |
| 3188 | |
| 3189 | if (GO.getName() == C->getName()) |
| 3190 | return; |
| 3191 | |
| 3192 | Out << '('; |
| 3193 | PrintLLVMName(Out, C->getName(), ComdatPrefix); |
| 3194 | Out << ')'; |
| 3195 | } |
| 3196 | |
Chris Lattner | c182499 | 2001-10-29 16:05:51 +0000 | [diff] [blame] | 3197 | void AssemblyWriter::printGlobal(const GlobalVariable *GV) { |
Dan Gohman | 4483c7b | 2010-01-29 23:12:36 +0000 | [diff] [blame] | 3198 | if (GV->isMaterializable()) |
| 3199 | Out << "; Materializable\n"; |
| 3200 | |
Dan Gohman | 3bdfbf5 | 2010-07-20 23:55:01 +0000 | [diff] [blame] | 3201 | WriteAsOperandInternal(Out, GV, &TypePrinter, &Machine, GV->getParent()); |
Dan Gohman | 3845e50 | 2009-08-12 23:32:33 +0000 | [diff] [blame] | 3202 | Out << " = "; |
Chris Lattner | d70684f | 2001-09-18 04:01:05 +0000 | [diff] [blame] | 3203 | |
Chris Lattner | 52b26de | 2008-08-19 05:16:28 +0000 | [diff] [blame] | 3204 | if (!GV->hasInitializer() && GV->hasExternalLinkage()) |
| 3205 | Out << "external "; |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 3206 | |
Teresa Johnson | f1f35aa | 2018-05-25 15:15:39 +0000 | [diff] [blame] | 3207 | Out << getLinkageNameWithSpace(GV->getLinkage()); |
Rafael Espindola | 1e1801c | 2018-01-11 22:15:05 +0000 | [diff] [blame] | 3208 | PrintDSOLocation(*GV, Out); |
Chris Lattner | 52b26de | 2008-08-19 05:16:28 +0000 | [diff] [blame] | 3209 | PrintVisibility(GV->getVisibility(), Out); |
Nico Rieck | 38f68c5 | 2014-01-14 15:22:47 +0000 | [diff] [blame] | 3210 | PrintDLLStorageClass(GV->getDLLStorageClass(), Out); |
Hans Wennborg | ce718ff | 2012-06-23 11:37:03 +0000 | [diff] [blame] | 3211 | PrintThreadLocalModel(GV->getThreadLocalMode(), Out); |
Peter Collingbourne | 63b34cd | 2016-06-14 21:01:22 +0000 | [diff] [blame] | 3212 | StringRef UA = getUnnamedAddrEncoding(GV->getUnnamedAddr()); |
| 3213 | if (!UA.empty()) |
| 3214 | Out << UA << ' '; |
Lauro Ramos Venancio | c763552 | 2007-04-12 18:32:50 +0000 | [diff] [blame] | 3215 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 3216 | if (unsigned AddressSpace = GV->getType()->getAddressSpace()) |
| 3217 | Out << "addrspace(" << AddressSpace << ") "; |
Michael Gottesman | a2de37c | 2013-02-05 05:57:38 +0000 | [diff] [blame] | 3218 | if (GV->isExternallyInitialized()) Out << "externally_initialized "; |
Misha Brukman | 0313e0b | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 3219 | Out << (GV->isConstant() ? "constant " : "global "); |
Manuel Jacob | 75e1cfb | 2016-01-16 20:30:46 +0000 | [diff] [blame] | 3220 | TypePrinter.print(GV->getValueType(), Out); |
Chris Lattner | d70684f | 2001-09-18 04:01:05 +0000 | [diff] [blame] | 3221 | |
Dan Gohman | 8dae138 | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 3222 | if (GV->hasInitializer()) { |
| 3223 | Out << ' '; |
Devang Patel | 320671d | 2009-07-08 21:44:25 +0000 | [diff] [blame] | 3224 | writeOperand(GV->getInitializer(), false); |
Dan Gohman | 8dae138 | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 3225 | } |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 3226 | |
Chris Lattner | 8fff126 | 2010-07-07 23:16:37 +0000 | [diff] [blame] | 3227 | if (GV->hasSection()) { |
| 3228 | Out << ", section \""; |
Jonas Devlieghere | 7eeba25 | 2018-05-31 17:01:42 +0000 | [diff] [blame] | 3229 | printEscapedString(GV->getSection(), Out); |
Chris Lattner | 8fff126 | 2010-07-07 23:16:37 +0000 | [diff] [blame] | 3230 | Out << '"'; |
| 3231 | } |
Rafael Espindola | f907a26 | 2015-01-06 22:55:16 +0000 | [diff] [blame] | 3232 | maybePrintComdat(Out, *GV); |
Chris Lattner | 60962db | 2005-11-12 00:10:19 +0000 | [diff] [blame] | 3233 | if (GV->getAlignment()) |
Chris Lattner | 30caa28 | 2005-11-06 06:48:53 +0000 | [diff] [blame] | 3234 | Out << ", align " << GV->getAlignment(); |
Anton Korobeynikov | 8b0a8c8 | 2007-04-25 14:27:10 +0000 | [diff] [blame] | 3235 | |
Peter Collingbourne | 6aef9f9 | 2016-05-31 23:01:54 +0000 | [diff] [blame] | 3236 | SmallVector<std::pair<unsigned, MDNode *>, 4> MDs; |
| 3237 | GV->getAllMetadata(MDs); |
| 3238 | printMetadataAttachments(MDs, ", "); |
| 3239 | |
Javed Absar | a8ddcaa | 2017-05-11 12:28:08 +0000 | [diff] [blame] | 3240 | auto Attrs = GV->getAttributes(); |
| 3241 | if (Attrs.hasAttributes()) |
| 3242 | Out << " #" << Machine.getAttributeGroupSlot(Attrs); |
| 3243 | |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 3244 | printInfoComment(*GV); |
Chris Lattner | 70cc339 | 2001-09-10 07:58:01 +0000 | [diff] [blame] | 3245 | } |
| 3246 | |
Dmitry Polukhin | 51a06a2 | 2016-04-05 08:47:51 +0000 | [diff] [blame] | 3247 | void AssemblyWriter::printIndirectSymbol(const GlobalIndirectSymbol *GIS) { |
| 3248 | if (GIS->isMaterializable()) |
Dan Gohman | 4483c7b | 2010-01-29 23:12:36 +0000 | [diff] [blame] | 3249 | Out << "; Materializable\n"; |
| 3250 | |
Dmitry Polukhin | 51a06a2 | 2016-04-05 08:47:51 +0000 | [diff] [blame] | 3251 | WriteAsOperandInternal(Out, GIS, &TypePrinter, &Machine, GIS->getParent()); |
Rafael Espindola | 43e5349 | 2015-06-17 17:53:31 +0000 | [diff] [blame] | 3252 | Out << " = "; |
| 3253 | |
Teresa Johnson | f1f35aa | 2018-05-25 15:15:39 +0000 | [diff] [blame] | 3254 | Out << getLinkageNameWithSpace(GIS->getLinkage()); |
Rafael Espindola | 1e1801c | 2018-01-11 22:15:05 +0000 | [diff] [blame] | 3255 | PrintDSOLocation(*GIS, Out); |
Dmitry Polukhin | 51a06a2 | 2016-04-05 08:47:51 +0000 | [diff] [blame] | 3256 | PrintVisibility(GIS->getVisibility(), Out); |
| 3257 | PrintDLLStorageClass(GIS->getDLLStorageClass(), Out); |
| 3258 | PrintThreadLocalModel(GIS->getThreadLocalMode(), Out); |
Peter Collingbourne | 63b34cd | 2016-06-14 21:01:22 +0000 | [diff] [blame] | 3259 | StringRef UA = getUnnamedAddrEncoding(GIS->getUnnamedAddr()); |
| 3260 | if (!UA.empty()) |
| 3261 | Out << UA << ' '; |
Anton Korobeynikov | 8b0a8c8 | 2007-04-25 14:27:10 +0000 | [diff] [blame] | 3262 | |
Dmitry Polukhin | 51a06a2 | 2016-04-05 08:47:51 +0000 | [diff] [blame] | 3263 | if (isa<GlobalAlias>(GIS)) |
| 3264 | Out << "alias "; |
Dmitry Polukhin | ba49223 | 2016-04-07 12:32:19 +0000 | [diff] [blame] | 3265 | else if (isa<GlobalIFunc>(GIS)) |
| 3266 | Out << "ifunc "; |
Dmitry Polukhin | 51a06a2 | 2016-04-05 08:47:51 +0000 | [diff] [blame] | 3267 | else |
Dmitry Polukhin | ba49223 | 2016-04-07 12:32:19 +0000 | [diff] [blame] | 3268 | llvm_unreachable("Not an alias or ifunc!"); |
Anton Korobeynikov | 8b0a8c8 | 2007-04-25 14:27:10 +0000 | [diff] [blame] | 3269 | |
Dmitry Polukhin | 51a06a2 | 2016-04-05 08:47:51 +0000 | [diff] [blame] | 3270 | TypePrinter.print(GIS->getValueType(), Out); |
David Blaikie | 21f77df | 2015-09-11 03:22:04 +0000 | [diff] [blame] | 3271 | |
| 3272 | Out << ", "; |
| 3273 | |
Dmitry Polukhin | 51a06a2 | 2016-04-05 08:47:51 +0000 | [diff] [blame] | 3274 | const Constant *IS = GIS->getIndirectSymbol(); |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 3275 | |
Dmitry Polukhin | 51a06a2 | 2016-04-05 08:47:51 +0000 | [diff] [blame] | 3276 | if (!IS) { |
| 3277 | TypePrinter.print(GIS->getType(), Out); |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 3278 | Out << " <<NULL ALIASEE>>"; |
Jay Foad | 5cd8ea2 | 2011-08-01 12:48:54 +0000 | [diff] [blame] | 3279 | } else { |
Dmitry Polukhin | 51a06a2 | 2016-04-05 08:47:51 +0000 | [diff] [blame] | 3280 | writeOperand(IS, !isa<ConstantExpr>(IS)); |
Jay Foad | 5cd8ea2 | 2011-08-01 12:48:54 +0000 | [diff] [blame] | 3281 | } |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 3282 | |
Dmitry Polukhin | 51a06a2 | 2016-04-05 08:47:51 +0000 | [diff] [blame] | 3283 | printInfoComment(*GIS); |
Chris Lattner | 52b26de | 2008-08-19 05:16:28 +0000 | [diff] [blame] | 3284 | Out << '\n'; |
Anton Korobeynikov | 8b0a8c8 | 2007-04-25 14:27:10 +0000 | [diff] [blame] | 3285 | } |
| 3286 | |
David Majnemer | c8a1169 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 3287 | void AssemblyWriter::printComdat(const Comdat *C) { |
| 3288 | C->print(Out); |
| 3289 | } |
| 3290 | |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 3291 | void AssemblyWriter::printTypeIdentities() { |
Roman Tereshin | 238a338 | 2018-03-22 21:29:07 +0000 | [diff] [blame] | 3292 | if (TypePrinter.empty()) |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 3293 | return; |
Andrew Trick | 18801ec | 2011-09-30 19:48:58 +0000 | [diff] [blame] | 3294 | |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 3295 | Out << '\n'; |
Andrew Trick | 18801ec | 2011-09-30 19:48:58 +0000 | [diff] [blame] | 3296 | |
Chris Lattner | 413fd23 | 2009-03-01 00:03:38 +0000 | [diff] [blame] | 3297 | // Emit all numbered types. |
Roman Tereshin | 238a338 | 2018-03-22 21:29:07 +0000 | [diff] [blame] | 3298 | auto &NumberedTypes = TypePrinter.getNumberedTypes(); |
| 3299 | for (unsigned I = 0, E = NumberedTypes.size(); I != E; ++I) { |
| 3300 | Out << '%' << I << " = type "; |
Andrew Trick | 18801ec | 2011-09-30 19:48:58 +0000 | [diff] [blame] | 3301 | |
Chris Lattner | 413fd23 | 2009-03-01 00:03:38 +0000 | [diff] [blame] | 3302 | // Make sure we print out at least one level of the type structure, so |
| 3303 | // that we do not get %2 = type %2 |
Roman Tereshin | 238a338 | 2018-03-22 21:29:07 +0000 | [diff] [blame] | 3304 | TypePrinter.printStructBody(NumberedTypes[I], Out); |
Dan Gohman | 9bf0b9b | 2009-08-12 23:54:22 +0000 | [diff] [blame] | 3305 | Out << '\n'; |
Chris Lattner | 413fd23 | 2009-03-01 00:03:38 +0000 | [diff] [blame] | 3306 | } |
Andrew Trick | 18801ec | 2011-09-30 19:48:58 +0000 | [diff] [blame] | 3307 | |
Roman Tereshin | 238a338 | 2018-03-22 21:29:07 +0000 | [diff] [blame] | 3308 | auto &NamedTypes = TypePrinter.getNamedTypes(); |
| 3309 | for (unsigned I = 0, E = NamedTypes.size(); I != E; ++I) { |
| 3310 | PrintLLVMName(Out, NamedTypes[I]->getName(), LocalPrefix); |
Chris Lattner | 52b26de | 2008-08-19 05:16:28 +0000 | [diff] [blame] | 3311 | Out << " = type "; |
Reid Spencer | 9231ac8 | 2004-05-25 08:53:40 +0000 | [diff] [blame] | 3312 | |
| 3313 | // Make sure we print out at least one level of the type structure, so |
| 3314 | // that we do not get %FILE = type %FILE |
Roman Tereshin | 238a338 | 2018-03-22 21:29:07 +0000 | [diff] [blame] | 3315 | TypePrinter.printStructBody(NamedTypes[I], Out); |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 3316 | Out << '\n'; |
Reid Spencer | 9231ac8 | 2004-05-25 08:53:40 +0000 | [diff] [blame] | 3317 | } |
Reid Spencer | 78d033e | 2007-01-06 07:24:44 +0000 | [diff] [blame] | 3318 | } |
| 3319 | |
Misha Brukman | ab5c600 | 2004-03-02 00:22:19 +0000 | [diff] [blame] | 3320 | /// printFunction - Print all aspects of a function. |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 3321 | void AssemblyWriter::printFunction(const Function *F) { |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 3322 | // Print out the return type and name. |
| 3323 | Out << '\n'; |
Chris Lattner | 4ad02e7 | 2003-04-16 20:28:45 +0000 | [diff] [blame] | 3324 | |
Misha Brukman | 0313e0b | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 3325 | if (AnnotationWriter) AnnotationWriter->emitFunctionAnnot(F, Out); |
Chris Lattner | 95e5a2c | 2003-10-30 23:41:03 +0000 | [diff] [blame] | 3326 | |
Dan Gohman | 4483c7b | 2010-01-29 23:12:36 +0000 | [diff] [blame] | 3327 | if (F->isMaterializable()) |
| 3328 | Out << "; Materializable\n"; |
| 3329 | |
Reid Kleckner | 6707770 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 3330 | const AttributeList &Attrs = F->getAttributes(); |
| 3331 | if (Attrs.hasAttributes(AttributeList::FunctionIndex)) { |
Reid Kleckner | 0609040 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 3332 | AttributeSet AS = Attrs.getFnAttributes(); |
Rafael Espindola | aae0298 | 2013-05-01 13:07:03 +0000 | [diff] [blame] | 3333 | std::string AttrStr; |
| 3334 | |
Reid Kleckner | 0609040 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 3335 | for (const Attribute &Attr : AS) { |
Rafael Espindola | aae0298 | 2013-05-01 13:07:03 +0000 | [diff] [blame] | 3336 | if (!Attr.isStringAttribute()) { |
| 3337 | if (!AttrStr.empty()) AttrStr += ' '; |
| 3338 | AttrStr += Attr.getAsString(); |
| 3339 | } |
| 3340 | } |
| 3341 | |
Bill Wendling | 6340549 | 2013-04-16 20:55:47 +0000 | [diff] [blame] | 3342 | if (!AttrStr.empty()) |
| 3343 | Out << "; Function Attrs: " << AttrStr << '\n'; |
| 3344 | } |
| 3345 | |
Peter Collingbourne | 99e2e27 | 2016-06-21 23:42:48 +0000 | [diff] [blame] | 3346 | Machine.incorporateFunction(F); |
| 3347 | |
| 3348 | if (F->isDeclaration()) { |
| 3349 | Out << "declare"; |
| 3350 | SmallVector<std::pair<unsigned, MDNode *>, 4> MDs; |
| 3351 | F->getAllMetadata(MDs); |
| 3352 | printMetadataAttachments(MDs, " "); |
| 3353 | Out << ' '; |
| 3354 | } else |
Reid Spencer | b951bc0 | 2006-12-29 20:29:48 +0000 | [diff] [blame] | 3355 | Out << "define "; |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 3356 | |
Teresa Johnson | f1f35aa | 2018-05-25 15:15:39 +0000 | [diff] [blame] | 3357 | Out << getLinkageNameWithSpace(F->getLinkage()); |
Rafael Espindola | 1e1801c | 2018-01-11 22:15:05 +0000 | [diff] [blame] | 3358 | PrintDSOLocation(*F, Out); |
Chris Lattner | cfb5a20 | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 3359 | PrintVisibility(F->getVisibility(), Out); |
Nico Rieck | 38f68c5 | 2014-01-14 15:22:47 +0000 | [diff] [blame] | 3360 | PrintDLLStorageClass(F->getDLLStorageClass(), Out); |
Chris Lattner | 4ad02e7 | 2003-04-16 20:28:45 +0000 | [diff] [blame] | 3361 | |
Chris Lattner | d511898 | 2005-05-06 20:26:43 +0000 | [diff] [blame] | 3362 | // Print the calling convention. |
Micah Villmow | d3766df | 2012-09-13 15:11:12 +0000 | [diff] [blame] | 3363 | if (F->getCallingConv() != CallingConv::C) { |
| 3364 | PrintCallingConv(F->getCallingConv(), Out); |
| 3365 | Out << " "; |
Chris Lattner | d511898 | 2005-05-06 20:26:43 +0000 | [diff] [blame] | 3366 | } |
| 3367 | |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 3368 | FunctionType *FT = F->getFunctionType(); |
Reid Kleckner | 6707770 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 3369 | if (Attrs.hasAttributes(AttributeList::ReturnIndex)) |
| 3370 | Out << Attrs.getAsString(AttributeList::ReturnIndex) << ' '; |
Chris Lattner | 0f7364b | 2009-02-28 21:26:53 +0000 | [diff] [blame] | 3371 | TypePrinter.print(F->getReturnType(), Out); |
Chris Lattner | 4667b71 | 2008-08-19 05:26:17 +0000 | [diff] [blame] | 3372 | Out << ' '; |
Dan Gohman | 3bdfbf5 | 2010-07-20 23:55:01 +0000 | [diff] [blame] | 3373 | WriteAsOperandInternal(Out, F, &TypePrinter, &Machine, F->getParent()); |
Misha Brukman | 0313e0b | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 3374 | Out << '('; |
Chris Lattner | 007377f | 2001-09-07 16:36:04 +0000 | [diff] [blame] | 3375 | |
Chris Lattner | c182499 | 2001-10-29 16:05:51 +0000 | [diff] [blame] | 3376 | // Loop over the arguments, printing them... |
Justin Bogner | 0adaaa3 | 2015-09-27 22:38:50 +0000 | [diff] [blame] | 3377 | if (F->isDeclaration() && !IsForDebug) { |
Justin Bogner | 984b15d | 2015-09-02 17:54:41 +0000 | [diff] [blame] | 3378 | // We're only interested in the type here - don't print argument names. |
| 3379 | for (unsigned I = 0, E = FT->getNumParams(); I != E; ++I) { |
Chris Lattner | 8dcd2f1 | 2007-04-18 00:57:22 +0000 | [diff] [blame] | 3380 | // Insert commas as we go... the first arg doesn't get a comma |
Justin Bogner | 984b15d | 2015-09-02 17:54:41 +0000 | [diff] [blame] | 3381 | if (I) |
| 3382 | Out << ", "; |
| 3383 | // Output type... |
| 3384 | TypePrinter.print(FT->getParamType(I), Out); |
| 3385 | |
Reid Kleckner | 331b9af | 2017-04-28 18:37:16 +0000 | [diff] [blame] | 3386 | AttributeSet ArgAttrs = Attrs.getParamAttributes(I); |
| 3387 | if (ArgAttrs.hasAttributes()) |
| 3388 | Out << ' ' << ArgAttrs.getAsString(); |
Chris Lattner | 8dcd2f1 | 2007-04-18 00:57:22 +0000 | [diff] [blame] | 3389 | } |
| 3390 | } else { |
Justin Bogner | 984b15d | 2015-09-02 17:54:41 +0000 | [diff] [blame] | 3391 | // The arguments are meaningful here, print them in detail. |
Justin Bogner | 984b15d | 2015-09-02 17:54:41 +0000 | [diff] [blame] | 3392 | for (const Argument &Arg : F->args()) { |
Chris Lattner | 8dcd2f1 | 2007-04-18 00:57:22 +0000 | [diff] [blame] | 3393 | // Insert commas as we go... the first arg doesn't get a comma |
Reid Kleckner | 331b9af | 2017-04-28 18:37:16 +0000 | [diff] [blame] | 3394 | if (Arg.getArgNo() != 0) |
Justin Bogner | 984b15d | 2015-09-02 17:54:41 +0000 | [diff] [blame] | 3395 | Out << ", "; |
Reid Kleckner | 331b9af | 2017-04-28 18:37:16 +0000 | [diff] [blame] | 3396 | printArgument(&Arg, Attrs.getParamAttributes(Arg.getArgNo())); |
Chris Lattner | 8dcd2f1 | 2007-04-18 00:57:22 +0000 | [diff] [blame] | 3397 | } |
Reid Spencer | bd5db8e | 2006-12-31 05:24:50 +0000 | [diff] [blame] | 3398 | } |
Chris Lattner | 007377f | 2001-09-07 16:36:04 +0000 | [diff] [blame] | 3399 | |
| 3400 | // Finish printing arguments... |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 3401 | if (FT->isVarArg()) { |
Misha Brukman | 0313e0b | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 3402 | if (FT->getNumParams()) Out << ", "; |
| 3403 | Out << "..."; // Output varargs portion of signature! |
Chris Lattner | 007377f | 2001-09-07 16:36:04 +0000 | [diff] [blame] | 3404 | } |
Misha Brukman | 0313e0b | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 3405 | Out << ')'; |
Peter Collingbourne | 63b34cd | 2016-06-14 21:01:22 +0000 | [diff] [blame] | 3406 | StringRef UA = getUnnamedAddrEncoding(F->getUnnamedAddr()); |
| 3407 | if (!UA.empty()) |
| 3408 | Out << ' ' << UA; |
Alexander Richardson | 47ff67b | 2018-08-23 09:25:17 +0000 | [diff] [blame] | 3409 | // We print the function address space if it is non-zero or if we are writing |
| 3410 | // a module with a non-zero program address space or if there is no valid |
| 3411 | // Module* so that the file can be parsed without the datalayout string. |
| 3412 | const Module *Mod = F->getParent(); |
| 3413 | if (F->getAddressSpace() != 0 || !Mod || |
| 3414 | Mod->getDataLayout().getProgramAddressSpace() != 0) |
| 3415 | Out << " addrspace(" << F->getAddressSpace() << ")"; |
Reid Kleckner | 6707770 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 3416 | if (Attrs.hasAttributes(AttributeList::FunctionIndex)) |
Bill Wendling | 725dae5 | 2013-04-29 23:48:06 +0000 | [diff] [blame] | 3417 | Out << " #" << Machine.getAttributeGroupSlot(Attrs.getFnAttributes()); |
Chris Lattner | 8fff126 | 2010-07-07 23:16:37 +0000 | [diff] [blame] | 3418 | if (F->hasSection()) { |
| 3419 | Out << " section \""; |
Jonas Devlieghere | 7eeba25 | 2018-05-31 17:01:42 +0000 | [diff] [blame] | 3420 | printEscapedString(F->getSection(), Out); |
Chris Lattner | 8fff126 | 2010-07-07 23:16:37 +0000 | [diff] [blame] | 3421 | Out << '"'; |
| 3422 | } |
Rafael Espindola | f907a26 | 2015-01-06 22:55:16 +0000 | [diff] [blame] | 3423 | maybePrintComdat(Out, *F); |
Chris Lattner | 30caa28 | 2005-11-06 06:48:53 +0000 | [diff] [blame] | 3424 | if (F->getAlignment()) |
| 3425 | Out << " align " << F->getAlignment(); |
Gordon Henriksen | 5eca075 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 3426 | if (F->hasGC()) |
| 3427 | Out << " gc \"" << F->getGC() << '"'; |
Peter Collingbourne | 1e3037f | 2013-09-16 01:08:15 +0000 | [diff] [blame] | 3428 | if (F->hasPrefixData()) { |
| 3429 | Out << " prefix "; |
| 3430 | writeOperand(F->getPrefixData(), true); |
| 3431 | } |
Peter Collingbourne | bb660fc | 2014-12-03 02:08:38 +0000 | [diff] [blame] | 3432 | if (F->hasPrologueData()) { |
| 3433 | Out << " prologue "; |
| 3434 | writeOperand(F->getPrologueData(), true); |
| 3435 | } |
David Majnemer | cc714e2 | 2015-06-17 20:52:32 +0000 | [diff] [blame] | 3436 | if (F->hasPersonalityFn()) { |
| 3437 | Out << " personality "; |
| 3438 | writeOperand(F->getPersonalityFn(), /*PrintType=*/true); |
| 3439 | } |
Peter Collingbourne | bb660fc | 2014-12-03 02:08:38 +0000 | [diff] [blame] | 3440 | |
Reid Spencer | 5cbf985 | 2007-01-30 20:08:39 +0000 | [diff] [blame] | 3441 | if (F->isDeclaration()) { |
Chris Lattner | 91fb407 | 2010-09-02 22:52:10 +0000 | [diff] [blame] | 3442 | Out << '\n'; |
Chris Lattner | 03e2acb | 2002-05-06 03:00:40 +0000 | [diff] [blame] | 3443 | } else { |
Peter Collingbourne | 99e2e27 | 2016-06-21 23:42:48 +0000 | [diff] [blame] | 3444 | SmallVector<std::pair<unsigned, MDNode *>, 4> MDs; |
| 3445 | F->getAllMetadata(MDs); |
| 3446 | printMetadataAttachments(MDs, " "); |
| 3447 | |
Chris Lattner | 91fb407 | 2010-09-02 22:52:10 +0000 | [diff] [blame] | 3448 | Out << " {"; |
| 3449 | // Output all of the function's basic blocks. |
Benjamin Kramer | e96e21f | 2016-06-26 14:10:56 +0000 | [diff] [blame] | 3450 | for (const BasicBlock &BB : *F) |
| 3451 | printBasicBlock(&BB); |
Chris Lattner | 007377f | 2001-09-07 16:36:04 +0000 | [diff] [blame] | 3452 | |
Duncan P. N. Exon Smith | 7838818 | 2014-08-19 21:30:15 +0000 | [diff] [blame] | 3453 | // Output the function's use-lists. |
| 3454 | printUseLists(F); |
| 3455 | |
Misha Brukman | 0313e0b | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 3456 | Out << "}\n"; |
Chris Lattner | 007377f | 2001-09-07 16:36:04 +0000 | [diff] [blame] | 3457 | } |
| 3458 | |
Reid Spencer | 0d1b77e | 2004-05-26 07:18:52 +0000 | [diff] [blame] | 3459 | Machine.purgeFunction(); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3460 | } |
| 3461 | |
Misha Brukman | ab5c600 | 2004-03-02 00:22:19 +0000 | [diff] [blame] | 3462 | /// printArgument - This member is called for every argument that is passed into |
| 3463 | /// the function. Simply print it out |
Reid Kleckner | 331b9af | 2017-04-28 18:37:16 +0000 | [diff] [blame] | 3464 | void AssemblyWriter::printArgument(const Argument *Arg, AttributeSet Attrs) { |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3465 | // Output type... |
Chris Lattner | 0f7364b | 2009-02-28 21:26:53 +0000 | [diff] [blame] | 3466 | TypePrinter.print(Arg->getType(), Out); |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 3467 | |
Duncan Sands | dc02467 | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 3468 | // Output parameter attributes list |
Reid Kleckner | 331b9af | 2017-04-28 18:37:16 +0000 | [diff] [blame] | 3469 | if (Attrs.hasAttributes()) |
| 3470 | Out << ' ' << Attrs.getAsString(); |
Reid Spencer | bd5db8e | 2006-12-31 05:24:50 +0000 | [diff] [blame] | 3471 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3472 | // Output name, if available... |
Chris Lattner | c97536e | 2008-08-17 04:40:13 +0000 | [diff] [blame] | 3473 | if (Arg->hasName()) { |
| 3474 | Out << ' '; |
| 3475 | PrintLLVMName(Out, Arg); |
| 3476 | } |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3477 | } |
| 3478 | |
Misha Brukman | ab5c600 | 2004-03-02 00:22:19 +0000 | [diff] [blame] | 3479 | /// printBasicBlock - This member is called for each basic block in a method. |
Chris Lattner | c182499 | 2001-10-29 16:05:51 +0000 | [diff] [blame] | 3480 | void AssemblyWriter::printBasicBlock(const BasicBlock *BB) { |
Nick Lewycky | 280a6e6 | 2008-04-25 16:53:59 +0000 | [diff] [blame] | 3481 | if (BB->hasName()) { // Print out the label if it exists... |
Chris Lattner | c97536e | 2008-08-17 04:40:13 +0000 | [diff] [blame] | 3482 | Out << "\n"; |
Daniel Dunbar | 03d7651 | 2009-07-25 23:55:21 +0000 | [diff] [blame] | 3483 | PrintLLVMName(Out, BB->getName(), LabelPrefix); |
Chris Lattner | c97536e | 2008-08-17 04:40:13 +0000 | [diff] [blame] | 3484 | Out << ':'; |
Nick Lewycky | 280a6e6 | 2008-04-25 16:53:59 +0000 | [diff] [blame] | 3485 | } else if (!BB->use_empty()) { // Don't print block # of no uses... |
Bill Wendling | 5d7a5a4 | 2011-04-10 23:18:04 +0000 | [diff] [blame] | 3486 | Out << "\n; <label>:"; |
Chris Lattner | 22379bc | 2007-01-11 03:54:27 +0000 | [diff] [blame] | 3487 | int Slot = Machine.getLocalSlot(BB); |
Chris Lattner | 6956645 | 2004-06-09 19:41:19 +0000 | [diff] [blame] | 3488 | if (Slot != -1) |
Evgeniy Stepanov | ca14b57 | 2016-01-27 21:53:08 +0000 | [diff] [blame] | 3489 | Out << Slot << ":"; |
Chris Lattner | 6956645 | 2004-06-09 19:41:19 +0000 | [diff] [blame] | 3490 | else |
Misha Brukman | 0313e0b | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 3491 | Out << "<badref>"; |
Chris Lattner | 061269b | 2002-10-02 19:38:55 +0000 | [diff] [blame] | 3492 | } |
Chris Lattner | 4e4d862 | 2003-11-20 00:09:43 +0000 | [diff] [blame] | 3493 | |
Craig Topper | ec0f0bc | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 3494 | if (!BB->getParent()) { |
Chris Lattner | 8f4b1ec | 2009-08-17 15:48:08 +0000 | [diff] [blame] | 3495 | Out.PadToColumn(50); |
Dan Gohman | 683e922 | 2009-08-12 17:23:50 +0000 | [diff] [blame] | 3496 | Out << "; Error: Block without parent!"; |
| 3497 | } else if (BB != &BB->getParent()->getEntryBlock()) { // Not the entry block? |
Chris Lattner | 91fb407 | 2010-09-02 22:52:10 +0000 | [diff] [blame] | 3498 | // Output predecessors for the block. |
Chris Lattner | 8f4b1ec | 2009-08-17 15:48:08 +0000 | [diff] [blame] | 3499 | Out.PadToColumn(50); |
Dan Gohman | 683e922 | 2009-08-12 17:23:50 +0000 | [diff] [blame] | 3500 | Out << ";"; |
Gabor Greif | 4442464 | 2010-03-25 23:25:28 +0000 | [diff] [blame] | 3501 | const_pred_iterator PI = pred_begin(BB), PE = pred_end(BB); |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 3502 | |
Chris Lattner | eb41129 | 2008-04-22 02:45:44 +0000 | [diff] [blame] | 3503 | if (PI == PE) { |
| 3504 | Out << " No predecessors!"; |
| 3505 | } else { |
Dan Gohman | 8dae138 | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 3506 | Out << " preds = "; |
Chris Lattner | eb41129 | 2008-04-22 02:45:44 +0000 | [diff] [blame] | 3507 | writeOperand(*PI, false); |
| 3508 | for (++PI; PI != PE; ++PI) { |
Dan Gohman | 8dae138 | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 3509 | Out << ", "; |
Chris Lattner | 2fcfdb7 | 2006-12-06 06:24:27 +0000 | [diff] [blame] | 3510 | writeOperand(*PI, false); |
Chris Lattner | 40efcec | 2003-11-16 22:59:57 +0000 | [diff] [blame] | 3511 | } |
Chris Lattner | 061269b | 2002-10-02 19:38:55 +0000 | [diff] [blame] | 3512 | } |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3513 | } |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 3514 | |
Chris Lattner | eb41129 | 2008-04-22 02:45:44 +0000 | [diff] [blame] | 3515 | Out << "\n"; |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3516 | |
Misha Brukman | 0313e0b | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 3517 | if (AnnotationWriter) AnnotationWriter->emitBasicBlockStartAnnot(BB, Out); |
Chris Lattner | 95e5a2c | 2003-10-30 23:41:03 +0000 | [diff] [blame] | 3518 | |
Chris Lattner | 007377f | 2001-09-07 16:36:04 +0000 | [diff] [blame] | 3519 | // Output all of the instructions in the basic block... |
Benjamin Kramer | e96e21f | 2016-06-26 14:10:56 +0000 | [diff] [blame] | 3520 | for (const Instruction &I : *BB) { |
| 3521 | printInstructionLine(I); |
Dan Gohman | beca689 | 2009-07-13 18:27:59 +0000 | [diff] [blame] | 3522 | } |
Chris Lattner | 9f717ef | 2004-03-08 18:51:45 +0000 | [diff] [blame] | 3523 | |
Misha Brukman | 0313e0b | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 3524 | if (AnnotationWriter) AnnotationWriter->emitBasicBlockEndAnnot(BB, Out); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3525 | } |
| 3526 | |
Daniel Malea | d0fef32 | 2013-05-08 20:38:31 +0000 | [diff] [blame] | 3527 | /// printInstructionLine - Print an instruction and a newline character. |
| 3528 | void AssemblyWriter::printInstructionLine(const Instruction &I) { |
| 3529 | printInstruction(I); |
| 3530 | Out << '\n'; |
| 3531 | } |
| 3532 | |
Igor Laevsky | a5f2faf | 2015-05-05 13:20:42 +0000 | [diff] [blame] | 3533 | /// printGCRelocateComment - print comment after call to the gc.relocate |
| 3534 | /// intrinsic indicating base and derived pointer names. |
Manuel Jacob | 397864c | 2016-01-05 04:03:00 +0000 | [diff] [blame] | 3535 | void AssemblyWriter::printGCRelocateComment(const GCRelocateInst &Relocate) { |
Igor Laevsky | a5f2faf | 2015-05-05 13:20:42 +0000 | [diff] [blame] | 3536 | Out << " ; ("; |
Manuel Jacob | 397864c | 2016-01-05 04:03:00 +0000 | [diff] [blame] | 3537 | writeOperand(Relocate.getBasePtr(), false); |
Igor Laevsky | a5f2faf | 2015-05-05 13:20:42 +0000 | [diff] [blame] | 3538 | Out << ", "; |
Manuel Jacob | 397864c | 2016-01-05 04:03:00 +0000 | [diff] [blame] | 3539 | writeOperand(Relocate.getDerivedPtr(), false); |
Igor Laevsky | a5f2faf | 2015-05-05 13:20:42 +0000 | [diff] [blame] | 3540 | Out << ")"; |
| 3541 | } |
| 3542 | |
Misha Brukman | ab5c600 | 2004-03-02 00:22:19 +0000 | [diff] [blame] | 3543 | /// printInfoComment - Print a little comment after the instruction indicating |
| 3544 | /// which slot it occupies. |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 3545 | void AssemblyWriter::printInfoComment(const Value &V) { |
Manuel Jacob | 397864c | 2016-01-05 04:03:00 +0000 | [diff] [blame] | 3546 | if (const auto *Relocate = dyn_cast<GCRelocateInst>(&V)) |
| 3547 | printGCRelocateComment(*Relocate); |
Igor Laevsky | a5f2faf | 2015-05-05 13:20:42 +0000 | [diff] [blame] | 3548 | |
Bill Wendling | 6340549 | 2013-04-16 20:55:47 +0000 | [diff] [blame] | 3549 | if (AnnotationWriter) |
Dan Gohman | 7a5666e | 2010-02-10 20:41:46 +0000 | [diff] [blame] | 3550 | AnnotationWriter->printInfoComment(V, Out); |
Chris Lattner | e02fa85 | 2001-10-13 06:42:36 +0000 | [diff] [blame] | 3551 | } |
| 3552 | |
Alexander Richardson | 47ff67b | 2018-08-23 09:25:17 +0000 | [diff] [blame] | 3553 | static void maybePrintCallAddrSpace(const Value *Operand, const Instruction *I, |
| 3554 | raw_ostream &Out) { |
| 3555 | // We print the address space of the call if it is non-zero. |
| 3556 | unsigned CallAddrSpace = Operand->getType()->getPointerAddressSpace(); |
| 3557 | bool PrintAddrSpace = CallAddrSpace != 0; |
| 3558 | if (!PrintAddrSpace) { |
| 3559 | const Module *Mod = getModuleFromVal(I); |
| 3560 | // We also print it if it is zero but not equal to the program address space |
| 3561 | // or if we can't find a valid Module* to make it possible to parse |
| 3562 | // the resulting file even without a datalayout string. |
| 3563 | if (!Mod || Mod->getDataLayout().getProgramAddressSpace() != 0) |
| 3564 | PrintAddrSpace = true; |
| 3565 | } |
| 3566 | if (PrintAddrSpace) |
| 3567 | Out << " addrspace(" << CallAddrSpace << ")"; |
| 3568 | } |
| 3569 | |
Reid Spencer | 3a9ec24 | 2006-08-28 01:02:49 +0000 | [diff] [blame] | 3570 | // This member is called for each Instruction in a function.. |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 3571 | void AssemblyWriter::printInstruction(const Instruction &I) { |
Misha Brukman | 0313e0b | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 3572 | if (AnnotationWriter) AnnotationWriter->emitInstructionAnnot(&I, Out); |
Chris Lattner | 95e5a2c | 2003-10-30 23:41:03 +0000 | [diff] [blame] | 3573 | |
Dan Gohman | 3845e50 | 2009-08-12 23:32:33 +0000 | [diff] [blame] | 3574 | // Print out indentation for an instruction. |
Dan Gohman | 01889ca | 2009-08-13 01:41:52 +0000 | [diff] [blame] | 3575 | Out << " "; |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3576 | |
| 3577 | // Print out name if it exists... |
Chris Lattner | c97536e | 2008-08-17 04:40:13 +0000 | [diff] [blame] | 3578 | if (I.hasName()) { |
| 3579 | PrintLLVMName(Out, &I); |
| 3580 | Out << " = "; |
Chris Lattner | 4ee93c4 | 2009-12-29 07:25:48 +0000 | [diff] [blame] | 3581 | } else if (!I.getType()->isVoidTy()) { |
Chris Lattner | 828db8a | 2008-08-29 17:19:30 +0000 | [diff] [blame] | 3582 | // Print out the def slot taken. |
| 3583 | int SlotNum = Machine.getLocalSlot(&I); |
| 3584 | if (SlotNum == -1) |
| 3585 | Out << "<badref> = "; |
| 3586 | else |
| 3587 | Out << '%' << SlotNum << " = "; |
Chris Lattner | c97536e | 2008-08-17 04:40:13 +0000 | [diff] [blame] | 3588 | } |
Andrew Trick | 18801ec | 2011-09-30 19:48:58 +0000 | [diff] [blame] | 3589 | |
Reid Kleckner | 710c1a4 | 2014-04-24 20:14:34 +0000 | [diff] [blame] | 3590 | if (const CallInst *CI = dyn_cast<CallInst>(&I)) { |
| 3591 | if (CI->isMustTailCall()) |
| 3592 | Out << "musttail "; |
| 3593 | else if (CI->isTailCall()) |
| 3594 | Out << "tail "; |
Akira Hatanaka | c35973b | 2015-11-06 23:55:38 +0000 | [diff] [blame] | 3595 | else if (CI->isNoTailCall()) |
| 3596 | Out << "notail "; |
Reid Kleckner | 710c1a4 | 2014-04-24 20:14:34 +0000 | [diff] [blame] | 3597 | } |
Chris Lattner | e5e475e | 2003-09-08 17:45:59 +0000 | [diff] [blame] | 3598 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3599 | // Print out the opcode... |
Misha Brukman | 0313e0b | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 3600 | Out << I.getOpcodeName(); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3601 | |
Eli Friedman | f03bb26 | 2011-08-12 22:50:01 +0000 | [diff] [blame] | 3602 | // If this is an atomic load or store, print out the atomic marker. |
| 3603 | if ((isa<LoadInst>(I) && cast<LoadInst>(I).isAtomic()) || |
| 3604 | (isa<StoreInst>(I) && cast<StoreInst>(I).isAtomic())) |
| 3605 | Out << " atomic"; |
| 3606 | |
Tim Northover | 8f2a85e | 2014-06-13 14:24:07 +0000 | [diff] [blame] | 3607 | if (isa<AtomicCmpXchgInst>(I) && cast<AtomicCmpXchgInst>(I).isWeak()) |
| 3608 | Out << " weak"; |
| 3609 | |
Eli Friedman | f03bb26 | 2011-08-12 22:50:01 +0000 | [diff] [blame] | 3610 | // If this is a volatile operation, print out the volatile marker. |
| 3611 | if ((isa<LoadInst>(I) && cast<LoadInst>(I).isVolatile()) || |
| 3612 | (isa<StoreInst>(I) && cast<StoreInst>(I).isVolatile()) || |
| 3613 | (isa<AtomicCmpXchgInst>(I) && cast<AtomicCmpXchgInst>(I).isVolatile()) || |
| 3614 | (isa<AtomicRMWInst>(I) && cast<AtomicRMWInst>(I).isVolatile())) |
| 3615 | Out << " volatile"; |
| 3616 | |
Dan Gohman | 59858cf | 2009-07-27 16:11:46 +0000 | [diff] [blame] | 3617 | // Print out optimization information. |
| 3618 | WriteOptimizationInfo(Out, &I); |
| 3619 | |
Reid Spencer | 74f1642 | 2006-12-03 06:27:29 +0000 | [diff] [blame] | 3620 | // Print out the compare instruction predicates |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 3621 | if (const CmpInst *CI = dyn_cast<CmpInst>(&I)) |
Tim Northover | 3ed44cd | 2016-08-17 20:25:25 +0000 | [diff] [blame] | 3622 | Out << ' ' << CmpInst::getPredicateName(CI->getPredicate()); |
Reid Spencer | 74f1642 | 2006-12-03 06:27:29 +0000 | [diff] [blame] | 3623 | |
Eli Friedman | ff03048 | 2011-07-28 21:48:00 +0000 | [diff] [blame] | 3624 | // Print out the atomicrmw operation |
| 3625 | if (const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(&I)) |
Matt Arsenault | 2c2c51b | 2018-10-02 23:44:11 +0000 | [diff] [blame] | 3626 | Out << ' ' << AtomicRMWInst::getOperationName(RMWI->getOperation()); |
Eli Friedman | ff03048 | 2011-07-28 21:48:00 +0000 | [diff] [blame] | 3627 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3628 | // Print out the type of the operands... |
Craig Topper | ec0f0bc | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 3629 | const Value *Operand = I.getNumOperands() ? I.getOperand(0) : nullptr; |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3630 | |
| 3631 | // Special case conditional branches to swizzle the condition out to the front |
Gabor Greif | ccd27fb | 2009-02-09 15:45:06 +0000 | [diff] [blame] | 3632 | if (isa<BranchInst>(I) && cast<BranchInst>(I).isConditional()) { |
David Blaikie | f12b379 | 2013-02-11 01:16:51 +0000 | [diff] [blame] | 3633 | const BranchInst &BI(cast<BranchInst>(I)); |
Dan Gohman | 8dae138 | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 3634 | Out << ' '; |
Gabor Greif | ccd27fb | 2009-02-09 15:45:06 +0000 | [diff] [blame] | 3635 | writeOperand(BI.getCondition(), true); |
Dan Gohman | 8dae138 | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 3636 | Out << ", "; |
Gabor Greif | ccd27fb | 2009-02-09 15:45:06 +0000 | [diff] [blame] | 3637 | writeOperand(BI.getSuccessor(0), true); |
Dan Gohman | 8dae138 | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 3638 | Out << ", "; |
Gabor Greif | ccd27fb | 2009-02-09 15:45:06 +0000 | [diff] [blame] | 3639 | writeOperand(BI.getSuccessor(1), true); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3640 | |
Chris Lattner | 94dc1f2 | 2002-04-13 18:34:38 +0000 | [diff] [blame] | 3641 | } else if (isa<SwitchInst>(I)) { |
David Blaikie | f12b379 | 2013-02-11 01:16:51 +0000 | [diff] [blame] | 3642 | const SwitchInst& SI(cast<SwitchInst>(I)); |
Chris Lattner | f9be95f | 2009-10-27 19:13:16 +0000 | [diff] [blame] | 3643 | // Special case switch instruction to get formatting nice and correct. |
Dan Gohman | 8dae138 | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 3644 | Out << ' '; |
Eli Friedman | bb5a744 | 2011-09-29 20:21:17 +0000 | [diff] [blame] | 3645 | writeOperand(SI.getCondition(), true); |
Dan Gohman | 8dae138 | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 3646 | Out << ", "; |
Eli Friedman | bb5a744 | 2011-09-29 20:21:17 +0000 | [diff] [blame] | 3647 | writeOperand(SI.getDefaultDest(), true); |
Chris Lattner | ab49ee7 | 2008-08-23 22:52:27 +0000 | [diff] [blame] | 3648 | Out << " ["; |
Chandler Carruth | ddfada2 | 2017-04-12 07:27:28 +0000 | [diff] [blame] | 3649 | for (auto Case : SI.cases()) { |
Dan Gohman | 01889ca | 2009-08-13 01:41:52 +0000 | [diff] [blame] | 3650 | Out << "\n "; |
Chandler Carruth | ddfada2 | 2017-04-12 07:27:28 +0000 | [diff] [blame] | 3651 | writeOperand(Case.getCaseValue(), true); |
Dan Gohman | 8dae138 | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 3652 | Out << ", "; |
Chandler Carruth | ddfada2 | 2017-04-12 07:27:28 +0000 | [diff] [blame] | 3653 | writeOperand(Case.getCaseSuccessor(), true); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3654 | } |
Dan Gohman | 01889ca | 2009-08-13 01:41:52 +0000 | [diff] [blame] | 3655 | Out << "\n ]"; |
Chris Lattner | ab21db7 | 2009-10-28 00:19:10 +0000 | [diff] [blame] | 3656 | } else if (isa<IndirectBrInst>(I)) { |
| 3657 | // Special case indirectbr instruction to get formatting nice and correct. |
Chris Lattner | f9be95f | 2009-10-27 19:13:16 +0000 | [diff] [blame] | 3658 | Out << ' '; |
| 3659 | writeOperand(Operand, true); |
Dan Gohman | 0ed1f42 | 2009-10-30 02:01:10 +0000 | [diff] [blame] | 3660 | Out << ", ["; |
Andrew Trick | 18801ec | 2011-09-30 19:48:58 +0000 | [diff] [blame] | 3661 | |
Chris Lattner | f9be95f | 2009-10-27 19:13:16 +0000 | [diff] [blame] | 3662 | for (unsigned i = 1, e = I.getNumOperands(); i != e; ++i) { |
| 3663 | if (i != 1) |
| 3664 | Out << ", "; |
| 3665 | writeOperand(I.getOperand(i), true); |
| 3666 | } |
| 3667 | Out << ']'; |
Jay Foad | c137120 | 2011-06-20 14:18:48 +0000 | [diff] [blame] | 3668 | } else if (const PHINode *PN = dyn_cast<PHINode>(&I)) { |
Misha Brukman | 0313e0b | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 3669 | Out << ' '; |
Chris Lattner | 0f7364b | 2009-02-28 21:26:53 +0000 | [diff] [blame] | 3670 | TypePrinter.print(I.getType(), Out); |
Misha Brukman | 0313e0b | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 3671 | Out << ' '; |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3672 | |
Jay Foad | c137120 | 2011-06-20 14:18:48 +0000 | [diff] [blame] | 3673 | for (unsigned op = 0, Eop = PN->getNumIncomingValues(); op < Eop; ++op) { |
Misha Brukman | 0313e0b | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 3674 | if (op) Out << ", "; |
Dan Gohman | 8dae138 | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 3675 | Out << "[ "; |
Jay Foad | c137120 | 2011-06-20 14:18:48 +0000 | [diff] [blame] | 3676 | writeOperand(PN->getIncomingValue(op), false); Out << ", "; |
| 3677 | writeOperand(PN->getIncomingBlock(op), false); Out << " ]"; |
Chris Lattner | c24d208 | 2001-06-11 15:04:20 +0000 | [diff] [blame] | 3678 | } |
Dan Gohman | 995be7d | 2008-05-31 19:12:39 +0000 | [diff] [blame] | 3679 | } else if (const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(&I)) { |
Dan Gohman | 8dae138 | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 3680 | Out << ' '; |
Dan Gohman | 995be7d | 2008-05-31 19:12:39 +0000 | [diff] [blame] | 3681 | writeOperand(I.getOperand(0), true); |
| 3682 | for (const unsigned *i = EVI->idx_begin(), *e = EVI->idx_end(); i != e; ++i) |
| 3683 | Out << ", " << *i; |
| 3684 | } else if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(&I)) { |
Dan Gohman | 8dae138 | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 3685 | Out << ' '; |
| 3686 | writeOperand(I.getOperand(0), true); Out << ", "; |
Dan Gohman | 995be7d | 2008-05-31 19:12:39 +0000 | [diff] [blame] | 3687 | writeOperand(I.getOperand(1), true); |
| 3688 | for (const unsigned *i = IVI->idx_begin(), *e = IVI->idx_end(); i != e; ++i) |
| 3689 | Out << ", " << *i; |
Bill Wendling | e6e8826 | 2011-08-12 20:24:12 +0000 | [diff] [blame] | 3690 | } else if (const LandingPadInst *LPI = dyn_cast<LandingPadInst>(&I)) { |
| 3691 | Out << ' '; |
| 3692 | TypePrinter.print(I.getType(), Out); |
David Majnemer | cc714e2 | 2015-06-17 20:52:32 +0000 | [diff] [blame] | 3693 | if (LPI->isCleanup() || LPI->getNumClauses() != 0) |
| 3694 | Out << '\n'; |
Bill Wendling | e6e8826 | 2011-08-12 20:24:12 +0000 | [diff] [blame] | 3695 | |
| 3696 | if (LPI->isCleanup()) |
| 3697 | Out << " cleanup"; |
| 3698 | |
| 3699 | for (unsigned i = 0, e = LPI->getNumClauses(); i != e; ++i) { |
| 3700 | if (i != 0 || LPI->isCleanup()) Out << "\n"; |
| 3701 | if (LPI->isCatch(i)) |
| 3702 | Out << " catch "; |
| 3703 | else |
| 3704 | Out << " filter "; |
| 3705 | |
| 3706 | writeOperand(LPI->getClause(i), true); |
| 3707 | } |
David Majnemer | 8cec2f2 | 2015-12-12 05:38:55 +0000 | [diff] [blame] | 3708 | } else if (const auto *CatchSwitch = dyn_cast<CatchSwitchInst>(&I)) { |
| 3709 | Out << " within "; |
| 3710 | writeOperand(CatchSwitch->getParentPad(), /*PrintType=*/false); |
David Majnemer | 4a45f08 | 2015-07-31 17:58:14 +0000 | [diff] [blame] | 3711 | Out << " ["; |
David Majnemer | 8cec2f2 | 2015-12-12 05:38:55 +0000 | [diff] [blame] | 3712 | unsigned Op = 0; |
| 3713 | for (const BasicBlock *PadBB : CatchSwitch->handlers()) { |
| 3714 | if (Op > 0) |
| 3715 | Out << ", "; |
| 3716 | writeOperand(PadBB, /*PrintType=*/true); |
| 3717 | ++Op; |
| 3718 | } |
| 3719 | Out << "] unwind "; |
| 3720 | if (const BasicBlock *UnwindDest = CatchSwitch->getUnwindDest()) |
| 3721 | writeOperand(UnwindDest, /*PrintType=*/true); |
| 3722 | else |
| 3723 | Out << "to caller"; |
| 3724 | } else if (const auto *FPI = dyn_cast<FuncletPadInst>(&I)) { |
| 3725 | Out << " within "; |
| 3726 | writeOperand(FPI->getParentPad(), /*PrintType=*/false); |
| 3727 | Out << " ["; |
| 3728 | for (unsigned Op = 0, NumOps = FPI->getNumArgOperands(); Op < NumOps; |
David Majnemer | 4a45f08 | 2015-07-31 17:58:14 +0000 | [diff] [blame] | 3729 | ++Op) { |
| 3730 | if (Op > 0) |
| 3731 | Out << ", "; |
David Majnemer | 8cec2f2 | 2015-12-12 05:38:55 +0000 | [diff] [blame] | 3732 | writeOperand(FPI->getArgOperand(Op), /*PrintType=*/true); |
David Majnemer | 4a45f08 | 2015-07-31 17:58:14 +0000 | [diff] [blame] | 3733 | } |
David Majnemer | 8cec2f2 | 2015-12-12 05:38:55 +0000 | [diff] [blame] | 3734 | Out << ']'; |
Devang Patel | 57ef4f4 | 2008-02-23 00:35:18 +0000 | [diff] [blame] | 3735 | } else if (isa<ReturnInst>(I) && !Operand) { |
| 3736 | Out << " void"; |
David Majnemer | de17e77 | 2015-08-15 02:46:08 +0000 | [diff] [blame] | 3737 | } else if (const auto *CRI = dyn_cast<CatchReturnInst>(&I)) { |
David Majnemer | 8cec2f2 | 2015-12-12 05:38:55 +0000 | [diff] [blame] | 3738 | Out << " from "; |
| 3739 | writeOperand(CRI->getOperand(0), /*PrintType=*/false); |
David Majnemer | de17e77 | 2015-08-15 02:46:08 +0000 | [diff] [blame] | 3740 | |
| 3741 | Out << " to "; |
David Majnemer | 8cec2f2 | 2015-12-12 05:38:55 +0000 | [diff] [blame] | 3742 | writeOperand(CRI->getOperand(1), /*PrintType=*/true); |
David Majnemer | 4a45f08 | 2015-07-31 17:58:14 +0000 | [diff] [blame] | 3743 | } else if (const auto *CRI = dyn_cast<CleanupReturnInst>(&I)) { |
David Majnemer | 8cec2f2 | 2015-12-12 05:38:55 +0000 | [diff] [blame] | 3744 | Out << " from "; |
| 3745 | writeOperand(CRI->getOperand(0), /*PrintType=*/false); |
David Majnemer | 4a45f08 | 2015-07-31 17:58:14 +0000 | [diff] [blame] | 3746 | |
| 3747 | Out << " unwind "; |
| 3748 | if (CRI->hasUnwindDest()) |
David Majnemer | 8cec2f2 | 2015-12-12 05:38:55 +0000 | [diff] [blame] | 3749 | writeOperand(CRI->getOperand(1), /*PrintType=*/true); |
Joseph Tremoulet | 226889e | 2015-09-03 09:09:43 +0000 | [diff] [blame] | 3750 | else |
| 3751 | Out << "to caller"; |
Chris Lattner | d511898 | 2005-05-06 20:26:43 +0000 | [diff] [blame] | 3752 | } else if (const CallInst *CI = dyn_cast<CallInst>(&I)) { |
| 3753 | // Print the calling convention being used. |
Micah Villmow | d3766df | 2012-09-13 15:11:12 +0000 | [diff] [blame] | 3754 | if (CI->getCallingConv() != CallingConv::C) { |
| 3755 | Out << " "; |
| 3756 | PrintCallingConv(CI->getCallingConv(), Out); |
Chris Lattner | d511898 | 2005-05-06 20:26:43 +0000 | [diff] [blame] | 3757 | } |
| 3758 | |
Gabor Greif | 7bbdf0c | 2010-06-23 13:09:06 +0000 | [diff] [blame] | 3759 | Operand = CI->getCalledValue(); |
Ahmed Bougacha | 9cccec8 | 2016-12-21 23:26:13 +0000 | [diff] [blame] | 3760 | FunctionType *FTy = CI->getFunctionType(); |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 3761 | Type *RetTy = FTy->getReturnType(); |
Reid Kleckner | 6707770 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 3762 | const AttributeList &PAL = CI->getAttributes(); |
Chris Lattner | 268de04 | 2001-11-06 21:28:12 +0000 | [diff] [blame] | 3763 | |
Reid Kleckner | 6707770 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 3764 | if (PAL.hasAttributes(AttributeList::ReturnIndex)) |
| 3765 | Out << ' ' << PAL.getAsString(AttributeList::ReturnIndex); |
Devang Patel | 652203f | 2008-09-29 20:49:50 +0000 | [diff] [blame] | 3766 | |
Alexander Richardson | 47ff67b | 2018-08-23 09:25:17 +0000 | [diff] [blame] | 3767 | // Only print addrspace(N) if necessary: |
| 3768 | maybePrintCallAddrSpace(Operand, &I, Out); |
| 3769 | |
Chris Lattner | 7a01229 | 2003-08-05 15:34:45 +0000 | [diff] [blame] | 3770 | // If possible, print out the short form of the call instruction. We can |
Chris Lattner | b579400 | 2002-04-07 22:49:37 +0000 | [diff] [blame] | 3771 | // only do this if the first argument is a pointer to a nonvararg function, |
Chris Lattner | 7a01229 | 2003-08-05 15:34:45 +0000 | [diff] [blame] | 3772 | // and if the return type is not a pointer to a function. |
Chris Lattner | 268de04 | 2001-11-06 21:28:12 +0000 | [diff] [blame] | 3773 | // |
Dan Gohman | 8dae138 | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 3774 | Out << ' '; |
David Blaikie | 32b845d | 2015-04-16 23:24:18 +0000 | [diff] [blame] | 3775 | TypePrinter.print(FTy->isVarArg() ? FTy : RetTy, Out); |
| 3776 | Out << ' '; |
| 3777 | writeOperand(Operand, false); |
Misha Brukman | 0313e0b | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 3778 | Out << '('; |
Gabor Greif | 7bbdf0c | 2010-06-23 13:09:06 +0000 | [diff] [blame] | 3779 | for (unsigned op = 0, Eop = CI->getNumArgOperands(); op < Eop; ++op) { |
| 3780 | if (op > 0) |
Dan Gohman | 8dae138 | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 3781 | Out << ", "; |
Reid Kleckner | 331b9af | 2017-04-28 18:37:16 +0000 | [diff] [blame] | 3782 | writeParamOperand(CI->getArgOperand(op), PAL.getParamAttributes(op)); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3783 | } |
Reid Kleckner | 44b3a0b | 2014-08-26 00:33:28 +0000 | [diff] [blame] | 3784 | |
| 3785 | // Emit an ellipsis if this is a musttail call in a vararg function. This |
| 3786 | // is only to aid readability, musttail calls forward varargs by default. |
| 3787 | if (CI->isMustTailCall() && CI->getParent() && |
| 3788 | CI->getParent()->getParent() && |
| 3789 | CI->getParent()->getParent()->isVarArg()) |
| 3790 | Out << ", ..."; |
| 3791 | |
Dan Gohman | 8dae138 | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 3792 | Out << ')'; |
Reid Kleckner | 6707770 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 3793 | if (PAL.hasAttributes(AttributeList::FunctionIndex)) |
Bill Wendling | 351b7a1 | 2013-02-22 09:09:42 +0000 | [diff] [blame] | 3794 | Out << " #" << Machine.getAttributeGroupSlot(PAL.getFnAttributes()); |
Sanjoy Das | f70eb72 | 2015-09-24 23:34:52 +0000 | [diff] [blame] | 3795 | |
| 3796 | writeOperandBundles(CI); |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 3797 | } else if (const InvokeInst *II = dyn_cast<InvokeInst>(&I)) { |
Gabor Greif | c9f7500 | 2010-03-24 13:21:49 +0000 | [diff] [blame] | 3798 | Operand = II->getCalledValue(); |
Ahmed Bougacha | 9cccec8 | 2016-12-21 23:26:13 +0000 | [diff] [blame] | 3799 | FunctionType *FTy = II->getFunctionType(); |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 3800 | Type *RetTy = FTy->getReturnType(); |
Reid Kleckner | 6707770 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 3801 | const AttributeList &PAL = II->getAttributes(); |
Chris Lattner | 7a01229 | 2003-08-05 15:34:45 +0000 | [diff] [blame] | 3802 | |
Chris Lattner | d511898 | 2005-05-06 20:26:43 +0000 | [diff] [blame] | 3803 | // Print the calling convention being used. |
Micah Villmow | d3766df | 2012-09-13 15:11:12 +0000 | [diff] [blame] | 3804 | if (II->getCallingConv() != CallingConv::C) { |
| 3805 | Out << " "; |
| 3806 | PrintCallingConv(II->getCallingConv(), Out); |
Chris Lattner | d511898 | 2005-05-06 20:26:43 +0000 | [diff] [blame] | 3807 | } |
| 3808 | |
Reid Kleckner | 6707770 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 3809 | if (PAL.hasAttributes(AttributeList::ReturnIndex)) |
| 3810 | Out << ' ' << PAL.getAsString(AttributeList::ReturnIndex); |
Devang Patel | 652203f | 2008-09-29 20:49:50 +0000 | [diff] [blame] | 3811 | |
Alexander Richardson | 47ff67b | 2018-08-23 09:25:17 +0000 | [diff] [blame] | 3812 | // Only print addrspace(N) if necessary: |
| 3813 | maybePrintCallAddrSpace(Operand, &I, Out); |
| 3814 | |
Chris Lattner | 7a01229 | 2003-08-05 15:34:45 +0000 | [diff] [blame] | 3815 | // If possible, print out the short form of the invoke instruction. We can |
| 3816 | // only do this if the first argument is a pointer to a nonvararg function, |
| 3817 | // and if the return type is not a pointer to a function. |
| 3818 | // |
Dan Gohman | 2b6c3d9 | 2008-10-15 18:02:08 +0000 | [diff] [blame] | 3819 | Out << ' '; |
David Blaikie | e41f384 | 2015-04-24 19:32:54 +0000 | [diff] [blame] | 3820 | TypePrinter.print(FTy->isVarArg() ? FTy : RetTy, Out); |
| 3821 | Out << ' '; |
| 3822 | writeOperand(Operand, false); |
Misha Brukman | 0313e0b | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 3823 | Out << '('; |
Gabor Greif | 7bbdf0c | 2010-06-23 13:09:06 +0000 | [diff] [blame] | 3824 | for (unsigned op = 0, Eop = II->getNumArgOperands(); op < Eop; ++op) { |
Gabor Greif | c9f7500 | 2010-03-24 13:21:49 +0000 | [diff] [blame] | 3825 | if (op) |
Dan Gohman | 8dae138 | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 3826 | Out << ", "; |
Reid Kleckner | 331b9af | 2017-04-28 18:37:16 +0000 | [diff] [blame] | 3827 | writeParamOperand(II->getArgOperand(op), PAL.getParamAttributes(op)); |
Chris Lattner | e02fa85 | 2001-10-13 06:42:36 +0000 | [diff] [blame] | 3828 | } |
| 3829 | |
Dan Gohman | 8dae138 | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 3830 | Out << ')'; |
Reid Kleckner | 6707770 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 3831 | if (PAL.hasAttributes(AttributeList::FunctionIndex)) |
Bill Wendling | 351b7a1 | 2013-02-22 09:09:42 +0000 | [diff] [blame] | 3832 | Out << " #" << Machine.getAttributeGroupSlot(PAL.getFnAttributes()); |
Devang Patel | 19c8746 | 2008-09-26 22:53:05 +0000 | [diff] [blame] | 3833 | |
Sanjoy Das | f70eb72 | 2015-09-24 23:34:52 +0000 | [diff] [blame] | 3834 | writeOperandBundles(II); |
| 3835 | |
Dan Gohman | 01889ca | 2009-08-13 01:41:52 +0000 | [diff] [blame] | 3836 | Out << "\n to "; |
Chris Lattner | e02fa85 | 2001-10-13 06:42:36 +0000 | [diff] [blame] | 3837 | writeOperand(II->getNormalDest(), true); |
Dan Gohman | 8dae138 | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 3838 | Out << " unwind "; |
Chris Lattner | aeb2a1d | 2004-02-08 21:44:31 +0000 | [diff] [blame] | 3839 | writeOperand(II->getUnwindDest(), true); |
Victor Hernandez | 7b929da | 2009-10-23 21:09:37 +0000 | [diff] [blame] | 3840 | } else if (const AllocaInst *AI = dyn_cast<AllocaInst>(&I)) { |
Misha Brukman | 0313e0b | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 3841 | Out << ' '; |
Reid Kleckner | 1d16702 | 2014-01-25 01:24:06 +0000 | [diff] [blame] | 3842 | if (AI->isUsedWithInAlloca()) |
David Majnemer | 39a09d2 | 2014-03-09 06:41:58 +0000 | [diff] [blame] | 3843 | Out << "inalloca "; |
Manman Ren | 4bda882 | 2016-04-01 21:41:15 +0000 | [diff] [blame] | 3844 | if (AI->isSwiftError()) |
| 3845 | Out << "swifterror "; |
David Majnemer | 39a09d2 | 2014-03-09 06:41:58 +0000 | [diff] [blame] | 3846 | TypePrinter.print(AI->getAllocatedType(), Out); |
Duncan P. N. Exon Smith | 95ff656 | 2015-03-13 19:30:44 +0000 | [diff] [blame] | 3847 | |
| 3848 | // Explicitly write the array size if the code is broken, if it's an array |
| 3849 | // allocation, or if the type is not canonical for scalar allocations. The |
| 3850 | // latter case prevents the type from mutating when round-tripping through |
| 3851 | // assembly. |
| 3852 | if (!AI->getArraySize() || AI->isArrayAllocation() || |
| 3853 | !AI->getArraySize()->getType()->isIntegerTy(32)) { |
Dan Gohman | 8dae138 | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 3854 | Out << ", "; |
Chris Lattner | 94dc1f2 | 2002-04-13 18:34:38 +0000 | [diff] [blame] | 3855 | writeOperand(AI->getArraySize(), true); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3856 | } |
Nate Begeman | 14b0529 | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 3857 | if (AI->getAlignment()) { |
Chris Lattner | 9fad0b9 | 2005-11-05 21:20:34 +0000 | [diff] [blame] | 3858 | Out << ", align " << AI->getAlignment(); |
Nate Begeman | 14b0529 | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 3859 | } |
Matt Arsenault | e0b3c33 | 2017-04-10 22:27:50 +0000 | [diff] [blame] | 3860 | |
| 3861 | unsigned AddrSpace = AI->getType()->getAddressSpace(); |
| 3862 | if (AddrSpace != 0) { |
| 3863 | Out << ", addrspace(" << AddrSpace << ')'; |
| 3864 | } |
Chris Lattner | e02fa85 | 2001-10-13 06:42:36 +0000 | [diff] [blame] | 3865 | } else if (isa<CastInst>(I)) { |
Dan Gohman | 8dae138 | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 3866 | if (Operand) { |
| 3867 | Out << ' '; |
| 3868 | writeOperand(Operand, true); // Work with broken code |
| 3869 | } |
Misha Brukman | 0313e0b | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 3870 | Out << " to "; |
Chris Lattner | 0f7364b | 2009-02-28 21:26:53 +0000 | [diff] [blame] | 3871 | TypePrinter.print(I.getType(), Out); |
Chris Lattner | 4d45bd0 | 2003-10-18 05:57:43 +0000 | [diff] [blame] | 3872 | } else if (isa<VAArgInst>(I)) { |
Dan Gohman | 8dae138 | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 3873 | if (Operand) { |
| 3874 | Out << ' '; |
| 3875 | writeOperand(Operand, true); // Work with broken code |
| 3876 | } |
Misha Brukman | 0313e0b | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 3877 | Out << ", "; |
Chris Lattner | 0f7364b | 2009-02-28 21:26:53 +0000 | [diff] [blame] | 3878 | TypePrinter.print(I.getType(), Out); |
| 3879 | } else if (Operand) { // Print the normal way. |
David Blaikie | 7c9c6ed | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 3880 | if (const auto *GEP = dyn_cast<GetElementPtrInst>(&I)) { |
David Blaikie | 198d8ba | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 3881 | Out << ' '; |
| 3882 | TypePrinter.print(GEP->getSourceElementType(), Out); |
| 3883 | Out << ','; |
David Blaikie | 7c9c6ed | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 3884 | } else if (const auto *LI = dyn_cast<LoadInst>(&I)) { |
| 3885 | Out << ' '; |
| 3886 | TypePrinter.print(LI->getType(), Out); |
Benjamin Kramer | 6cc6b41 | 2015-03-02 15:24:41 +0000 | [diff] [blame] | 3887 | Out << ','; |
David Blaikie | 198d8ba | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 3888 | } |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3889 | |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 3890 | // PrintAllTypes - Instructions who have operands of all the same type |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3891 | // omit the type from all but the first operand. If the instruction has |
| 3892 | // different type operands (for example br), then they are all printed. |
| 3893 | bool PrintAllTypes = false; |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 3894 | Type *TheType = Operand->getType(); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3895 | |
Reid Spencer | ebe57e3 | 2007-02-02 13:54:55 +0000 | [diff] [blame] | 3896 | // Select, Store and ShuffleVector always print all types. |
Devang Patel | 6494768 | 2008-03-04 22:05:14 +0000 | [diff] [blame] | 3897 | if (isa<SelectInst>(I) || isa<StoreInst>(I) || isa<ShuffleVectorInst>(I) |
| 3898 | || isa<ReturnInst>(I)) { |
Chris Lattner | ffd9bf4 | 2003-04-16 20:20:02 +0000 | [diff] [blame] | 3899 | PrintAllTypes = true; |
| 3900 | } else { |
| 3901 | for (unsigned i = 1, E = I.getNumOperands(); i != E; ++i) { |
| 3902 | Operand = I.getOperand(i); |
Nuno Lopes | 6ad2b2a | 2009-01-15 18:40:57 +0000 | [diff] [blame] | 3903 | // note that Operand shouldn't be null, but the test helps make dump() |
| 3904 | // more tolerant of malformed IR |
Nuno Lopes | a8c78a9 | 2009-01-14 17:51:41 +0000 | [diff] [blame] | 3905 | if (Operand && Operand->getType() != TheType) { |
Chris Lattner | ffd9bf4 | 2003-04-16 20:20:02 +0000 | [diff] [blame] | 3906 | PrintAllTypes = true; // We have differing types! Print them all! |
| 3907 | break; |
| 3908 | } |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3909 | } |
| 3910 | } |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 3911 | |
Chris Lattner | c182499 | 2001-10-29 16:05:51 +0000 | [diff] [blame] | 3912 | if (!PrintAllTypes) { |
Misha Brukman | 0313e0b | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 3913 | Out << ' '; |
Chris Lattner | 0f7364b | 2009-02-28 21:26:53 +0000 | [diff] [blame] | 3914 | TypePrinter.print(TheType, Out); |
Chris Lattner | c182499 | 2001-10-29 16:05:51 +0000 | [diff] [blame] | 3915 | } |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3916 | |
Dan Gohman | 8dae138 | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 3917 | Out << ' '; |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 3918 | for (unsigned i = 0, E = I.getNumOperands(); i != E; ++i) { |
Dan Gohman | 8dae138 | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 3919 | if (i) Out << ", "; |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 3920 | writeOperand(I.getOperand(i), PrintAllTypes); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3921 | } |
| 3922 | } |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 3923 | |
Eli Friedman | 21006d4 | 2011-08-09 23:02:53 +0000 | [diff] [blame] | 3924 | // Print atomic ordering/alignment for memory operations |
| 3925 | if (const LoadInst *LI = dyn_cast<LoadInst>(&I)) { |
| 3926 | if (LI->isAtomic()) |
Konstantin Zhuravlyov | 8f85685 | 2017-07-11 22:23:00 +0000 | [diff] [blame] | 3927 | writeAtomic(LI->getContext(), LI->getOrdering(), LI->getSyncScopeID()); |
Eli Friedman | 21006d4 | 2011-08-09 23:02:53 +0000 | [diff] [blame] | 3928 | if (LI->getAlignment()) |
| 3929 | Out << ", align " << LI->getAlignment(); |
| 3930 | } else if (const StoreInst *SI = dyn_cast<StoreInst>(&I)) { |
| 3931 | if (SI->isAtomic()) |
Konstantin Zhuravlyov | 8f85685 | 2017-07-11 22:23:00 +0000 | [diff] [blame] | 3932 | writeAtomic(SI->getContext(), SI->getOrdering(), SI->getSyncScopeID()); |
Eli Friedman | 21006d4 | 2011-08-09 23:02:53 +0000 | [diff] [blame] | 3933 | if (SI->getAlignment()) |
| 3934 | Out << ", align " << SI->getAlignment(); |
Eli Friedman | ff03048 | 2011-07-28 21:48:00 +0000 | [diff] [blame] | 3935 | } else if (const AtomicCmpXchgInst *CXI = dyn_cast<AtomicCmpXchgInst>(&I)) { |
Konstantin Zhuravlyov | 8f85685 | 2017-07-11 22:23:00 +0000 | [diff] [blame] | 3936 | writeAtomicCmpXchg(CXI->getContext(), CXI->getSuccessOrdering(), |
| 3937 | CXI->getFailureOrdering(), CXI->getSyncScopeID()); |
Eli Friedman | ff03048 | 2011-07-28 21:48:00 +0000 | [diff] [blame] | 3938 | } else if (const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(&I)) { |
Konstantin Zhuravlyov | 8f85685 | 2017-07-11 22:23:00 +0000 | [diff] [blame] | 3939 | writeAtomic(RMWI->getContext(), RMWI->getOrdering(), |
| 3940 | RMWI->getSyncScopeID()); |
Eli Friedman | 47f3513 | 2011-07-25 23:16:38 +0000 | [diff] [blame] | 3941 | } else if (const FenceInst *FI = dyn_cast<FenceInst>(&I)) { |
Konstantin Zhuravlyov | 8f85685 | 2017-07-11 22:23:00 +0000 | [diff] [blame] | 3942 | writeAtomic(FI->getContext(), FI->getOrdering(), FI->getSyncScopeID()); |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 3943 | } |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3944 | |
Chris Lattner | 7d05c46 | 2009-12-28 20:10:43 +0000 | [diff] [blame] | 3945 | // Print Metadata info. |
Duncan P. N. Exon Smith | 5bf8ade | 2014-11-11 21:30:22 +0000 | [diff] [blame] | 3946 | SmallVector<std::pair<unsigned, MDNode *>, 4> InstMD; |
Nick Lewycky | fa0c54e | 2010-02-25 06:53:04 +0000 | [diff] [blame] | 3947 | I.getAllMetadata(InstMD); |
Duncan P. N. Exon Smith | 3be4147 | 2015-04-24 21:06:21 +0000 | [diff] [blame] | 3948 | printMetadataAttachments(InstMD, ", "); |
Duncan P. N. Exon Smith | 61317d5 | 2015-04-24 20:59:52 +0000 | [diff] [blame] | 3949 | |
| 3950 | // Print a nice comment. |
Chris Lattner | e02fa85 | 2001-10-13 06:42:36 +0000 | [diff] [blame] | 3951 | printInfoComment(I); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3952 | } |
| 3953 | |
Duncan P. N. Exon Smith | 61317d5 | 2015-04-24 20:59:52 +0000 | [diff] [blame] | 3954 | void AssemblyWriter::printMetadataAttachments( |
Duncan P. N. Exon Smith | 3be4147 | 2015-04-24 21:06:21 +0000 | [diff] [blame] | 3955 | const SmallVectorImpl<std::pair<unsigned, MDNode *>> &MDs, |
| 3956 | StringRef Separator) { |
Duncan P. N. Exon Smith | 61317d5 | 2015-04-24 20:59:52 +0000 | [diff] [blame] | 3957 | if (MDs.empty()) |
| 3958 | return; |
| 3959 | |
Duncan P. N. Exon Smith | c8be244 | 2015-04-24 21:03:05 +0000 | [diff] [blame] | 3960 | if (MDNames.empty()) |
Mehdi Amini | f452675 | 2016-01-07 20:14:30 +0000 | [diff] [blame] | 3961 | MDs[0].second->getContext().getMDKindNames(MDNames); |
Duncan P. N. Exon Smith | c8be244 | 2015-04-24 21:03:05 +0000 | [diff] [blame] | 3962 | |
Duncan P. N. Exon Smith | 61317d5 | 2015-04-24 20:59:52 +0000 | [diff] [blame] | 3963 | for (const auto &I : MDs) { |
| 3964 | unsigned Kind = I.first; |
Duncan P. N. Exon Smith | 3be4147 | 2015-04-24 21:06:21 +0000 | [diff] [blame] | 3965 | Out << Separator; |
Filipe Cabecinhas | 6af0f89 | 2015-06-02 21:25:08 +0000 | [diff] [blame] | 3966 | if (Kind < MDNames.size()) { |
| 3967 | Out << "!"; |
| 3968 | printMetadataIdentifier(MDNames[Kind], Out); |
| 3969 | } else |
Duncan P. N. Exon Smith | 3be4147 | 2015-04-24 21:06:21 +0000 | [diff] [blame] | 3970 | Out << "!<unknown kind #" << Kind << ">"; |
Duncan P. N. Exon Smith | 61317d5 | 2015-04-24 20:59:52 +0000 | [diff] [blame] | 3971 | Out << ' '; |
| 3972 | WriteAsOperandInternal(Out, I.second, &TypePrinter, &Machine, TheModule); |
| 3973 | } |
| 3974 | } |
| 3975 | |
Daniel Malea | d0fef32 | 2013-05-08 20:38:31 +0000 | [diff] [blame] | 3976 | void AssemblyWriter::writeMDNode(unsigned Slot, const MDNode *Node) { |
Duncan P. N. Exon Smith | 1ef70ff | 2014-12-15 19:07:53 +0000 | [diff] [blame] | 3977 | Out << '!' << Slot << " = "; |
Daniel Malea | d0fef32 | 2013-05-08 20:38:31 +0000 | [diff] [blame] | 3978 | printMDNodeBody(Node); |
Duncan P. N. Exon Smith | 344ea29 | 2015-02-25 22:46:38 +0000 | [diff] [blame] | 3979 | Out << "\n"; |
Daniel Malea | d0fef32 | 2013-05-08 20:38:31 +0000 | [diff] [blame] | 3980 | } |
| 3981 | |
Chris Lattner | 6e6b180 | 2009-12-31 02:13:35 +0000 | [diff] [blame] | 3982 | void AssemblyWriter::writeAllMDNodes() { |
| 3983 | SmallVector<const MDNode *, 16> Nodes; |
Chris Lattner | 307c989 | 2009-12-31 02:20:11 +0000 | [diff] [blame] | 3984 | Nodes.resize(Machine.mdn_size()); |
| 3985 | for (SlotTracker::mdn_iterator I = Machine.mdn_begin(), E = Machine.mdn_end(); |
| 3986 | I != E; ++I) |
Chris Lattner | 6e6b180 | 2009-12-31 02:13:35 +0000 | [diff] [blame] | 3987 | Nodes[I->second] = cast<MDNode>(I->first); |
Andrew Trick | 18801ec | 2011-09-30 19:48:58 +0000 | [diff] [blame] | 3988 | |
Chris Lattner | 6e6b180 | 2009-12-31 02:13:35 +0000 | [diff] [blame] | 3989 | for (unsigned i = 0, e = Nodes.size(); i != e; ++i) { |
Daniel Malea | d0fef32 | 2013-05-08 20:38:31 +0000 | [diff] [blame] | 3990 | writeMDNode(i, Nodes[i]); |
Chris Lattner | 6e6b180 | 2009-12-31 02:13:35 +0000 | [diff] [blame] | 3991 | } |
| 3992 | } |
| 3993 | |
| 3994 | void AssemblyWriter::printMDNodeBody(const MDNode *Node) { |
Dan Gohman | 3bdfbf5 | 2010-07-20 23:55:01 +0000 | [diff] [blame] | 3995 | WriteMDNodeBodyInternal(Out, Node, &TypePrinter, &Machine, TheModule); |
Chris Lattner | 6e6b180 | 2009-12-31 02:13:35 +0000 | [diff] [blame] | 3996 | } |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3997 | |
Bill Wendling | b29ce26 | 2013-02-11 08:43:33 +0000 | [diff] [blame] | 3998 | void AssemblyWriter::writeAllAttributeGroups() { |
Reid Kleckner | 0609040 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 3999 | std::vector<std::pair<AttributeSet, unsigned>> asVec; |
Bill Wendling | b29ce26 | 2013-02-11 08:43:33 +0000 | [diff] [blame] | 4000 | asVec.resize(Machine.as_size()); |
| 4001 | |
| 4002 | for (SlotTracker::as_iterator I = Machine.as_begin(), E = Machine.as_end(); |
| 4003 | I != E; ++I) |
| 4004 | asVec[I->second] = *I; |
| 4005 | |
Benjamin Kramer | e96e21f | 2016-06-26 14:10:56 +0000 | [diff] [blame] | 4006 | for (const auto &I : asVec) |
| 4007 | Out << "attributes #" << I.second << " = { " |
Reid Kleckner | 0609040 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 4008 | << I.first.getAsString(true) << " }\n"; |
Bill Wendling | b29ce26 | 2013-02-11 08:43:33 +0000 | [diff] [blame] | 4009 | } |
| 4010 | |
Duncan P. N. Exon Smith | 7838818 | 2014-08-19 21:30:15 +0000 | [diff] [blame] | 4011 | void AssemblyWriter::printUseListOrder(const UseListOrder &Order) { |
| 4012 | bool IsInFunction = Machine.getFunction(); |
| 4013 | if (IsInFunction) |
| 4014 | Out << " "; |
| 4015 | |
| 4016 | Out << "uselistorder"; |
| 4017 | if (const BasicBlock *BB = |
| 4018 | IsInFunction ? nullptr : dyn_cast<BasicBlock>(Order.V)) { |
| 4019 | Out << "_bb "; |
| 4020 | writeOperand(BB->getParent(), false); |
| 4021 | Out << ", "; |
| 4022 | writeOperand(BB, false); |
| 4023 | } else { |
| 4024 | Out << " "; |
| 4025 | writeOperand(Order.V, true); |
| 4026 | } |
| 4027 | Out << ", { "; |
| 4028 | |
| 4029 | assert(Order.Shuffle.size() >= 2 && "Shuffle too small"); |
| 4030 | Out << Order.Shuffle[0]; |
| 4031 | for (unsigned I = 1, E = Order.Shuffle.size(); I != E; ++I) |
| 4032 | Out << ", " << Order.Shuffle[I]; |
| 4033 | Out << " }\n"; |
| 4034 | } |
| 4035 | |
| 4036 | void AssemblyWriter::printUseLists(const Function *F) { |
| 4037 | auto hasMore = |
| 4038 | [&]() { return !UseListOrders.empty() && UseListOrders.back().F == F; }; |
| 4039 | if (!hasMore()) |
| 4040 | // Nothing to do. |
| 4041 | return; |
| 4042 | |
| 4043 | Out << "\n; uselistorder directives\n"; |
| 4044 | while (hasMore()) { |
| 4045 | printUseListOrder(UseListOrders.back()); |
| 4046 | UseListOrders.pop_back(); |
| 4047 | } |
| 4048 | } |
| 4049 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 4050 | //===----------------------------------------------------------------------===// |
| 4051 | // External Interface declarations |
| 4052 | //===----------------------------------------------------------------------===// |
| 4053 | |
George Burgess IV | 02e0bb6 | 2016-02-02 22:46:49 +0000 | [diff] [blame] | 4054 | void Function::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW, |
| 4055 | bool ShouldPreserveUseListOrder, |
| 4056 | bool IsForDebug) const { |
| 4057 | SlotTracker SlotTable(this->getParent()); |
| 4058 | formatted_raw_ostream OS(ROS); |
| 4059 | AssemblyWriter W(OS, SlotTable, this->getParent(), AAW, |
| 4060 | IsForDebug, |
| 4061 | ShouldPreserveUseListOrder); |
| 4062 | W.printFunction(this); |
| 4063 | } |
| 4064 | |
Duncan P. N. Exon Smith | 8b376eb | 2015-04-15 02:12:41 +0000 | [diff] [blame] | 4065 | void Module::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW, |
Justin Bogner | 0adaaa3 | 2015-09-27 22:38:50 +0000 | [diff] [blame] | 4066 | bool ShouldPreserveUseListOrder, bool IsForDebug) const { |
Chris Lattner | 0d9574a | 2008-08-19 04:26:57 +0000 | [diff] [blame] | 4067 | SlotTracker SlotTable(this); |
Dan Gohman | 683e922 | 2009-08-12 17:23:50 +0000 | [diff] [blame] | 4068 | formatted_raw_ostream OS(ROS); |
Justin Bogner | 0adaaa3 | 2015-09-27 22:38:50 +0000 | [diff] [blame] | 4069 | AssemblyWriter W(OS, SlotTable, this, AAW, IsForDebug, |
| 4070 | ShouldPreserveUseListOrder); |
Chris Lattner | bd72b32 | 2009-12-31 02:23:35 +0000 | [diff] [blame] | 4071 | W.printModule(this); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 4072 | } |
| 4073 | |
Justin Bogner | 0adaaa3 | 2015-09-27 22:38:50 +0000 | [diff] [blame] | 4074 | void NamedMDNode::print(raw_ostream &ROS, bool IsForDebug) const { |
Dan Gohman | 17aa92c | 2010-07-21 23:38:33 +0000 | [diff] [blame] | 4075 | SlotTracker SlotTable(getParent()); |
| 4076 | formatted_raw_ostream OS(ROS); |
Justin Bogner | 0adaaa3 | 2015-09-27 22:38:50 +0000 | [diff] [blame] | 4077 | AssemblyWriter W(OS, SlotTable, getParent(), nullptr, IsForDebug); |
Dan Gohman | 17aa92c | 2010-07-21 23:38:33 +0000 | [diff] [blame] | 4078 | W.printNamedMDNode(this); |
| 4079 | } |
| 4080 | |
Duncan P. N. Exon Smith | 4ca56a6 | 2016-04-20 17:27:44 +0000 | [diff] [blame] | 4081 | void NamedMDNode::print(raw_ostream &ROS, ModuleSlotTracker &MST, |
| 4082 | bool IsForDebug) const { |
| 4083 | Optional<SlotTracker> LocalST; |
| 4084 | SlotTracker *SlotTable; |
| 4085 | if (auto *ST = MST.getMachine()) |
| 4086 | SlotTable = ST; |
| 4087 | else { |
| 4088 | LocalST.emplace(getParent()); |
| 4089 | SlotTable = &*LocalST; |
| 4090 | } |
| 4091 | |
| 4092 | formatted_raw_ostream OS(ROS); |
| 4093 | AssemblyWriter W(OS, *SlotTable, getParent(), nullptr, IsForDebug); |
| 4094 | W.printNamedMDNode(this); |
| 4095 | } |
| 4096 | |
Justin Bogner | 0adaaa3 | 2015-09-27 22:38:50 +0000 | [diff] [blame] | 4097 | void Comdat::print(raw_ostream &ROS, bool /*IsForDebug*/) const { |
David Majnemer | c8a1169 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 4098 | PrintLLVMName(ROS, getName(), ComdatPrefix); |
| 4099 | ROS << " = comdat "; |
| 4100 | |
| 4101 | switch (getSelectionKind()) { |
| 4102 | case Comdat::Any: |
| 4103 | ROS << "any"; |
| 4104 | break; |
| 4105 | case Comdat::ExactMatch: |
| 4106 | ROS << "exactmatch"; |
| 4107 | break; |
| 4108 | case Comdat::Largest: |
| 4109 | ROS << "largest"; |
| 4110 | break; |
| 4111 | case Comdat::NoDuplicates: |
| 4112 | ROS << "noduplicates"; |
| 4113 | break; |
| 4114 | case Comdat::SameSize: |
| 4115 | ROS << "samesize"; |
| 4116 | break; |
| 4117 | } |
| 4118 | |
| 4119 | ROS << '\n'; |
| 4120 | } |
| 4121 | |
Quentin Colombet | dbefd77 | 2016-03-07 22:32:42 +0000 | [diff] [blame] | 4122 | void Type::print(raw_ostream &OS, bool /*IsForDebug*/, bool NoDetails) const { |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 4123 | TypePrinting TP; |
| 4124 | TP.print(const_cast<Type*>(this), OS); |
Andrew Trick | 18801ec | 2011-09-30 19:48:58 +0000 | [diff] [blame] | 4125 | |
Quentin Colombet | dbefd77 | 2016-03-07 22:32:42 +0000 | [diff] [blame] | 4126 | if (NoDetails) |
| 4127 | return; |
| 4128 | |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 4129 | // If the type is a named struct type, print the body as well. |
| 4130 | if (StructType *STy = dyn_cast<StructType>(const_cast<Type*>(this))) |
Chris Lattner | c4d0e9f | 2011-08-12 18:07:07 +0000 | [diff] [blame] | 4131 | if (!STy->isLiteral()) { |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 4132 | OS << " = type "; |
| 4133 | TP.printStructBody(STy, OS); |
| 4134 | } |
Chris Lattner | 75cf7cf | 2002-04-08 22:03:40 +0000 | [diff] [blame] | 4135 | } |
| 4136 | |
Duncan P. N. Exon Smith | f9f505e | 2015-03-14 20:19:36 +0000 | [diff] [blame] | 4137 | static bool isReferencingMDNode(const Instruction &I) { |
| 4138 | if (const auto *CI = dyn_cast<CallInst>(&I)) |
| 4139 | if (Function *F = CI->getCalledFunction()) |
Justin Lebar | 24dbd38 | 2016-07-28 23:58:15 +0000 | [diff] [blame] | 4140 | if (F->isIntrinsic()) |
Duncan P. N. Exon Smith | f9f505e | 2015-03-14 20:19:36 +0000 | [diff] [blame] | 4141 | for (auto &Op : I.operands()) |
| 4142 | if (auto *V = dyn_cast_or_null<MetadataAsValue>(Op)) |
| 4143 | if (isa<MDNode>(V->getMetadata())) |
| 4144 | return true; |
| 4145 | return false; |
| 4146 | } |
| 4147 | |
Justin Bogner | 0adaaa3 | 2015-09-27 22:38:50 +0000 | [diff] [blame] | 4148 | void Value::print(raw_ostream &ROS, bool IsForDebug) const { |
Duncan P. N. Exon Smith | 2a5fda9 | 2015-06-27 00:38:26 +0000 | [diff] [blame] | 4149 | bool ShouldInitializeAllMetadata = false; |
| 4150 | if (auto *I = dyn_cast<Instruction>(this)) |
| 4151 | ShouldInitializeAllMetadata = isReferencingMDNode(*I); |
| 4152 | else if (isa<Function>(this) || isa<MetadataAsValue>(this)) |
| 4153 | ShouldInitializeAllMetadata = true; |
| 4154 | |
| 4155 | ModuleSlotTracker MST(getModuleFromVal(this), ShouldInitializeAllMetadata); |
Justin Bogner | 0adaaa3 | 2015-09-27 22:38:50 +0000 | [diff] [blame] | 4156 | print(ROS, MST, IsForDebug); |
Duncan P. N. Exon Smith | 2a5fda9 | 2015-06-27 00:38:26 +0000 | [diff] [blame] | 4157 | } |
| 4158 | |
Justin Bogner | 0adaaa3 | 2015-09-27 22:38:50 +0000 | [diff] [blame] | 4159 | void Value::print(raw_ostream &ROS, ModuleSlotTracker &MST, |
| 4160 | bool IsForDebug) const { |
Dan Gohman | 1220e10 | 2009-08-12 20:56:03 +0000 | [diff] [blame] | 4161 | formatted_raw_ostream OS(ROS); |
Duncan P. N. Exon Smith | 2a5fda9 | 2015-06-27 00:38:26 +0000 | [diff] [blame] | 4162 | SlotTracker EmptySlotTable(static_cast<const Module *>(nullptr)); |
| 4163 | SlotTracker &SlotTable = |
| 4164 | MST.getMachine() ? *MST.getMachine() : EmptySlotTable; |
| 4165 | auto incorporateFunction = [&](const Function *F) { |
| 4166 | if (F) |
| 4167 | MST.incorporateFunction(*F); |
| 4168 | }; |
| 4169 | |
Chris Lattner | 944fac7 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 4170 | if (const Instruction *I = dyn_cast<Instruction>(this)) { |
Duncan P. N. Exon Smith | 2a5fda9 | 2015-06-27 00:38:26 +0000 | [diff] [blame] | 4171 | incorporateFunction(I->getParent() ? I->getParent()->getParent() : nullptr); |
Justin Bogner | 0adaaa3 | 2015-09-27 22:38:50 +0000 | [diff] [blame] | 4172 | AssemblyWriter W(OS, SlotTable, getModuleFromVal(I), nullptr, IsForDebug); |
Chris Lattner | bd72b32 | 2009-12-31 02:23:35 +0000 | [diff] [blame] | 4173 | W.printInstruction(*I); |
Chris Lattner | 944fac7 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 4174 | } else if (const BasicBlock *BB = dyn_cast<BasicBlock>(this)) { |
Duncan P. N. Exon Smith | 2a5fda9 | 2015-06-27 00:38:26 +0000 | [diff] [blame] | 4175 | incorporateFunction(BB->getParent()); |
Justin Bogner | 0adaaa3 | 2015-09-27 22:38:50 +0000 | [diff] [blame] | 4176 | AssemblyWriter W(OS, SlotTable, getModuleFromVal(BB), nullptr, IsForDebug); |
Chris Lattner | bd72b32 | 2009-12-31 02:23:35 +0000 | [diff] [blame] | 4177 | W.printBasicBlock(BB); |
Chris Lattner | 944fac7 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 4178 | } else if (const GlobalValue *GV = dyn_cast<GlobalValue>(this)) { |
Justin Bogner | 0adaaa3 | 2015-09-27 22:38:50 +0000 | [diff] [blame] | 4179 | AssemblyWriter W(OS, SlotTable, GV->getParent(), nullptr, IsForDebug); |
Chris Lattner | bd72b32 | 2009-12-31 02:23:35 +0000 | [diff] [blame] | 4180 | if (const GlobalVariable *V = dyn_cast<GlobalVariable>(GV)) |
| 4181 | W.printGlobal(V); |
| 4182 | else if (const Function *F = dyn_cast<Function>(GV)) |
| 4183 | W.printFunction(F); |
| 4184 | else |
Dmitry Polukhin | 51a06a2 | 2016-04-05 08:47:51 +0000 | [diff] [blame] | 4185 | W.printIndirectSymbol(cast<GlobalIndirectSymbol>(GV)); |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 4186 | } else if (const MetadataAsValue *V = dyn_cast<MetadataAsValue>(this)) { |
Duncan P. N. Exon Smith | 2a5fda9 | 2015-06-27 00:38:26 +0000 | [diff] [blame] | 4187 | V->getMetadata()->print(ROS, MST, getModuleFromVal(V)); |
Chris Lattner | 944fac7 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 4188 | } else if (const Constant *C = dyn_cast<Constant>(this)) { |
Chris Lattner | e9fa33e | 2009-02-28 23:20:19 +0000 | [diff] [blame] | 4189 | TypePrinting TypePrinter; |
Chris Lattner | 0f7364b | 2009-02-28 21:26:53 +0000 | [diff] [blame] | 4190 | TypePrinter.print(C->getType(), OS); |
Chris Lattner | 6d4306e | 2009-02-28 21:11:05 +0000 | [diff] [blame] | 4191 | OS << ' '; |
Duncan P. N. Exon Smith | 2a5fda9 | 2015-06-27 00:38:26 +0000 | [diff] [blame] | 4192 | WriteConstantInternal(OS, C, TypePrinter, MST.getMachine(), nullptr); |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 4193 | } else if (isa<InlineAsm>(this) || isa<Argument>(this)) { |
Duncan P. N. Exon Smith | 2a5fda9 | 2015-06-27 00:38:26 +0000 | [diff] [blame] | 4194 | this->printAsOperand(OS, /* PrintType */ true, MST); |
Chris Lattner | 944fac7 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 4195 | } else { |
Nick Lewycky | e584911 | 2014-05-09 00:49:03 +0000 | [diff] [blame] | 4196 | llvm_unreachable("Unknown value to print out!"); |
Chris Lattner | 944fac7 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 4197 | } |
| 4198 | } |
| 4199 | |
Duncan P. N. Exon Smith | 9a61a42 | 2015-06-26 22:04:20 +0000 | [diff] [blame] | 4200 | /// Print without a type, skipping the TypePrinting object. |
| 4201 | /// |
Benjamin Kramer | d3c712e | 2015-08-08 18:27:36 +0000 | [diff] [blame] | 4202 | /// \return \c true iff printing was successful. |
Duncan P. N. Exon Smith | 9a61a42 | 2015-06-26 22:04:20 +0000 | [diff] [blame] | 4203 | static bool printWithoutType(const Value &V, raw_ostream &O, |
| 4204 | SlotTracker *Machine, const Module *M) { |
| 4205 | if (V.hasName() || isa<GlobalValue>(V) || |
| 4206 | (!isa<Constant>(V) && !isa<MetadataAsValue>(V))) { |
| 4207 | WriteAsOperandInternal(O, &V, nullptr, Machine, M); |
| 4208 | return true; |
Chandler Carruth | 560e395 | 2014-01-09 02:29:41 +0000 | [diff] [blame] | 4209 | } |
Duncan P. N. Exon Smith | 9a61a42 | 2015-06-26 22:04:20 +0000 | [diff] [blame] | 4210 | return false; |
| 4211 | } |
Chandler Carruth | 560e395 | 2014-01-09 02:29:41 +0000 | [diff] [blame] | 4212 | |
Duncan P. N. Exon Smith | 9a61a42 | 2015-06-26 22:04:20 +0000 | [diff] [blame] | 4213 | static void printAsOperandImpl(const Value &V, raw_ostream &O, bool PrintType, |
| 4214 | ModuleSlotTracker &MST) { |
Roman Tereshin | 238a338 | 2018-03-22 21:29:07 +0000 | [diff] [blame] | 4215 | TypePrinting TypePrinter(MST.getModule()); |
Chandler Carruth | 560e395 | 2014-01-09 02:29:41 +0000 | [diff] [blame] | 4216 | if (PrintType) { |
Duncan P. N. Exon Smith | 9a61a42 | 2015-06-26 22:04:20 +0000 | [diff] [blame] | 4217 | TypePrinter.print(V.getType(), O); |
Chandler Carruth | 560e395 | 2014-01-09 02:29:41 +0000 | [diff] [blame] | 4218 | O << ' '; |
| 4219 | } |
| 4220 | |
Duncan P. N. Exon Smith | 9a61a42 | 2015-06-26 22:04:20 +0000 | [diff] [blame] | 4221 | WriteAsOperandInternal(O, &V, &TypePrinter, MST.getMachine(), |
| 4222 | MST.getModule()); |
| 4223 | } |
| 4224 | |
| 4225 | void Value::printAsOperand(raw_ostream &O, bool PrintType, |
| 4226 | const Module *M) const { |
| 4227 | if (!M) |
| 4228 | M = getModuleFromVal(this); |
| 4229 | |
| 4230 | if (!PrintType) |
| 4231 | if (printWithoutType(*this, O, nullptr, M)) |
| 4232 | return; |
| 4233 | |
| 4234 | SlotTracker Machine( |
| 4235 | M, /* ShouldInitializeAllMetadata */ isa<MetadataAsValue>(this)); |
| 4236 | ModuleSlotTracker MST(Machine, M); |
| 4237 | printAsOperandImpl(*this, O, PrintType, MST); |
| 4238 | } |
| 4239 | |
| 4240 | void Value::printAsOperand(raw_ostream &O, bool PrintType, |
| 4241 | ModuleSlotTracker &MST) const { |
| 4242 | if (!PrintType) |
| 4243 | if (printWithoutType(*this, O, MST.getMachine(), MST.getModule())) |
| 4244 | return; |
| 4245 | |
| 4246 | printAsOperandImpl(*this, O, PrintType, MST); |
Chandler Carruth | 560e395 | 2014-01-09 02:29:41 +0000 | [diff] [blame] | 4247 | } |
| 4248 | |
Duncan P. N. Exon Smith | f9f505e | 2015-03-14 20:19:36 +0000 | [diff] [blame] | 4249 | static void printMetadataImpl(raw_ostream &ROS, const Metadata &MD, |
Duncan P. N. Exon Smith | 8266df7 | 2015-06-26 22:28:47 +0000 | [diff] [blame] | 4250 | ModuleSlotTracker &MST, const Module *M, |
| 4251 | bool OnlyAsOperand) { |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 4252 | formatted_raw_ostream OS(ROS); |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 4253 | |
Roman Tereshin | 238a338 | 2018-03-22 21:29:07 +0000 | [diff] [blame] | 4254 | TypePrinting TypePrinter(M); |
Duncan P. N. Exon Smith | f9f505e | 2015-03-14 20:19:36 +0000 | [diff] [blame] | 4255 | |
Duncan P. N. Exon Smith | 8266df7 | 2015-06-26 22:28:47 +0000 | [diff] [blame] | 4256 | WriteAsOperandInternal(OS, &MD, &TypePrinter, MST.getMachine(), M, |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 4257 | /* FromValue */ true); |
Duncan P. N. Exon Smith | 8266df7 | 2015-06-26 22:28:47 +0000 | [diff] [blame] | 4258 | |
| 4259 | auto *N = dyn_cast<MDNode>(&MD); |
Reid Kleckner | b5b9823 | 2017-08-30 20:40:36 +0000 | [diff] [blame] | 4260 | if (OnlyAsOperand || !N || isa<DIExpression>(MD)) |
Duncan P. N. Exon Smith | f9f505e | 2015-03-14 20:19:36 +0000 | [diff] [blame] | 4261 | return; |
| 4262 | |
| 4263 | OS << " = "; |
Duncan P. N. Exon Smith | 8266df7 | 2015-06-26 22:28:47 +0000 | [diff] [blame] | 4264 | WriteMDNodeBodyInternal(OS, N, &TypePrinter, MST.getMachine(), M); |
Duncan P. N. Exon Smith | f9f505e | 2015-03-14 20:19:36 +0000 | [diff] [blame] | 4265 | } |
| 4266 | |
| 4267 | void Metadata::printAsOperand(raw_ostream &OS, const Module *M) const { |
Duncan P. N. Exon Smith | 8266df7 | 2015-06-26 22:28:47 +0000 | [diff] [blame] | 4268 | ModuleSlotTracker MST(M, isa<MDNode>(this)); |
| 4269 | printMetadataImpl(OS, *this, MST, M, /* OnlyAsOperand */ true); |
| 4270 | } |
| 4271 | |
| 4272 | void Metadata::printAsOperand(raw_ostream &OS, ModuleSlotTracker &MST, |
| 4273 | const Module *M) const { |
| 4274 | printMetadataImpl(OS, *this, MST, M, /* OnlyAsOperand */ true); |
Duncan P. N. Exon Smith | f9f505e | 2015-03-14 20:19:36 +0000 | [diff] [blame] | 4275 | } |
| 4276 | |
Justin Bogner | 0adaaa3 | 2015-09-27 22:38:50 +0000 | [diff] [blame] | 4277 | void Metadata::print(raw_ostream &OS, const Module *M, |
| 4278 | bool /*IsForDebug*/) const { |
Duncan P. N. Exon Smith | 8266df7 | 2015-06-26 22:28:47 +0000 | [diff] [blame] | 4279 | ModuleSlotTracker MST(M, isa<MDNode>(this)); |
| 4280 | printMetadataImpl(OS, *this, MST, M, /* OnlyAsOperand */ false); |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 4281 | } |
| 4282 | |
Duncan P. N. Exon Smith | 2a5fda9 | 2015-06-27 00:38:26 +0000 | [diff] [blame] | 4283 | void Metadata::print(raw_ostream &OS, ModuleSlotTracker &MST, |
Justin Bogner | 0adaaa3 | 2015-09-27 22:38:50 +0000 | [diff] [blame] | 4284 | const Module *M, bool /*IsForDebug*/) const { |
Duncan P. N. Exon Smith | 2a5fda9 | 2015-06-27 00:38:26 +0000 | [diff] [blame] | 4285 | printMetadataImpl(OS, *this, MST, M, /* OnlyAsOperand */ false); |
| 4286 | } |
| 4287 | |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 4288 | void ModuleSummaryIndex::print(raw_ostream &ROS, bool IsForDebug) const { |
| 4289 | SlotTracker SlotTable(this); |
| 4290 | formatted_raw_ostream OS(ROS); |
| 4291 | AssemblyWriter W(OS, SlotTable, this, IsForDebug); |
| 4292 | W.printModuleSummaryIndex(); |
| 4293 | } |
| 4294 | |
Aaron Ballman | 1d03d38 | 2017-10-15 14:32:27 +0000 | [diff] [blame] | 4295 | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
Chris Lattner | 7059e53 | 2008-08-25 17:03:15 +0000 | [diff] [blame] | 4296 | // Value::dump - allow easy printing of Values from the debugger. |
Duncan P. N. Exon Smith | 3a955f3 | 2015-02-25 22:08:21 +0000 | [diff] [blame] | 4297 | LLVM_DUMP_METHOD |
Justin Bogner | 0adaaa3 | 2015-09-27 22:38:50 +0000 | [diff] [blame] | 4298 | void Value::dump() const { print(dbgs(), /*IsForDebug=*/true); dbgs() << '\n'; } |
Reid Spencer | fa452c0 | 2004-05-25 18:14:38 +0000 | [diff] [blame] | 4299 | |
Chris Lattner | 7059e53 | 2008-08-25 17:03:15 +0000 | [diff] [blame] | 4300 | // Type::dump - allow easy printing of Types from the debugger. |
Duncan P. N. Exon Smith | 3a955f3 | 2015-02-25 22:08:21 +0000 | [diff] [blame] | 4301 | LLVM_DUMP_METHOD |
Justin Bogner | 0adaaa3 | 2015-09-27 22:38:50 +0000 | [diff] [blame] | 4302 | void Type::dump() const { print(dbgs(), /*IsForDebug=*/true); dbgs() << '\n'; } |
Chris Lattner | c287137 | 2009-02-28 21:05:51 +0000 | [diff] [blame] | 4303 | |
Chris Lattner | 7059e53 | 2008-08-25 17:03:15 +0000 | [diff] [blame] | 4304 | // Module::dump() - Allow printing of Modules from the debugger. |
Duncan P. N. Exon Smith | 3a955f3 | 2015-02-25 22:08:21 +0000 | [diff] [blame] | 4305 | LLVM_DUMP_METHOD |
Justin Bogner | 0adaaa3 | 2015-09-27 22:38:50 +0000 | [diff] [blame] | 4306 | void Module::dump() const { |
| 4307 | print(dbgs(), nullptr, |
| 4308 | /*ShouldPreserveUseListOrder=*/false, /*IsForDebug=*/true); |
| 4309 | } |
Bill Wendling | f4374e4 | 2011-12-09 23:18:34 +0000 | [diff] [blame] | 4310 | |
Adrian Prantl | 26b584c | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 4311 | // Allow printing of Comdats from the debugger. |
Duncan P. N. Exon Smith | 3a955f3 | 2015-02-25 22:08:21 +0000 | [diff] [blame] | 4312 | LLVM_DUMP_METHOD |
Justin Bogner | 0adaaa3 | 2015-09-27 22:38:50 +0000 | [diff] [blame] | 4313 | void Comdat::dump() const { print(dbgs(), /*IsForDebug=*/true); } |
David Majnemer | c8a1169 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 4314 | |
Bill Wendling | f4374e4 | 2011-12-09 23:18:34 +0000 | [diff] [blame] | 4315 | // NamedMDNode::dump() - Allow printing of NamedMDNodes from the debugger. |
Duncan P. N. Exon Smith | 3a955f3 | 2015-02-25 22:08:21 +0000 | [diff] [blame] | 4316 | LLVM_DUMP_METHOD |
Justin Bogner | 0adaaa3 | 2015-09-27 22:38:50 +0000 | [diff] [blame] | 4317 | void NamedMDNode::dump() const { print(dbgs(), /*IsForDebug=*/true); } |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 4318 | |
Duncan P. N. Exon Smith | 3a955f3 | 2015-02-25 22:08:21 +0000 | [diff] [blame] | 4319 | LLVM_DUMP_METHOD |
Duncan P. N. Exon Smith | 9ca3580 | 2015-03-15 06:53:32 +0000 | [diff] [blame] | 4320 | void Metadata::dump() const { dump(nullptr); } |
| 4321 | |
| 4322 | LLVM_DUMP_METHOD |
Duncan P. N. Exon Smith | f9f505e | 2015-03-14 20:19:36 +0000 | [diff] [blame] | 4323 | void Metadata::dump(const Module *M) const { |
Justin Bogner | 0adaaa3 | 2015-09-27 22:38:50 +0000 | [diff] [blame] | 4324 | print(dbgs(), M, /*IsForDebug=*/true); |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 4325 | dbgs() << '\n'; |
| 4326 | } |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 4327 | |
| 4328 | // Allow printing of ModuleSummaryIndex from the debugger. |
| 4329 | LLVM_DUMP_METHOD |
| 4330 | void ModuleSummaryIndex::dump() const { print(dbgs(), /*IsForDebug=*/true); } |
Matthias Braun | 88d2075 | 2017-01-28 02:02:38 +0000 | [diff] [blame] | 4331 | #endif |