Mehdi Amini | ef27db8 | 2016-12-12 19:34:26 +0000 | [diff] [blame] | 1 | //===- MetadataLoader.cpp - Internal BitcodeReader implementation ---------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "MetadataLoader.h" |
| 11 | #include "ValueList.h" |
| 12 | |
| 13 | #include "llvm/ADT/APFloat.h" |
| 14 | #include "llvm/ADT/APInt.h" |
| 15 | #include "llvm/ADT/ArrayRef.h" |
| 16 | #include "llvm/ADT/DenseMap.h" |
| 17 | #include "llvm/ADT/None.h" |
| 18 | #include "llvm/ADT/STLExtras.h" |
| 19 | #include "llvm/ADT/SmallString.h" |
| 20 | #include "llvm/ADT/SmallVector.h" |
| 21 | #include "llvm/ADT/StringRef.h" |
| 22 | #include "llvm/ADT/Triple.h" |
| 23 | #include "llvm/ADT/Twine.h" |
| 24 | #include "llvm/Bitcode/BitcodeReader.h" |
| 25 | #include "llvm/Bitcode/BitstreamReader.h" |
| 26 | #include "llvm/Bitcode/LLVMBitCodes.h" |
| 27 | #include "llvm/IR/Argument.h" |
| 28 | #include "llvm/IR/Attributes.h" |
| 29 | #include "llvm/IR/AutoUpgrade.h" |
| 30 | #include "llvm/IR/BasicBlock.h" |
| 31 | #include "llvm/IR/CallSite.h" |
| 32 | #include "llvm/IR/CallingConv.h" |
| 33 | #include "llvm/IR/Comdat.h" |
| 34 | #include "llvm/IR/Constant.h" |
| 35 | #include "llvm/IR/Constants.h" |
| 36 | #include "llvm/IR/DebugInfo.h" |
| 37 | #include "llvm/IR/DebugInfoMetadata.h" |
| 38 | #include "llvm/IR/DebugLoc.h" |
| 39 | #include "llvm/IR/DerivedTypes.h" |
| 40 | #include "llvm/IR/DiagnosticInfo.h" |
| 41 | #include "llvm/IR/DiagnosticPrinter.h" |
| 42 | #include "llvm/IR/Function.h" |
| 43 | #include "llvm/IR/GVMaterializer.h" |
| 44 | #include "llvm/IR/GlobalAlias.h" |
| 45 | #include "llvm/IR/GlobalIFunc.h" |
| 46 | #include "llvm/IR/GlobalIndirectSymbol.h" |
| 47 | #include "llvm/IR/GlobalObject.h" |
| 48 | #include "llvm/IR/GlobalValue.h" |
| 49 | #include "llvm/IR/GlobalVariable.h" |
| 50 | #include "llvm/IR/InlineAsm.h" |
| 51 | #include "llvm/IR/InstrTypes.h" |
| 52 | #include "llvm/IR/Instruction.h" |
| 53 | #include "llvm/IR/Instructions.h" |
| 54 | #include "llvm/IR/Intrinsics.h" |
| 55 | #include "llvm/IR/LLVMContext.h" |
| 56 | #include "llvm/IR/Module.h" |
| 57 | #include "llvm/IR/ModuleSummaryIndex.h" |
| 58 | #include "llvm/IR/OperandTraits.h" |
| 59 | #include "llvm/IR/Operator.h" |
| 60 | #include "llvm/IR/TrackingMDRef.h" |
| 61 | #include "llvm/IR/Type.h" |
| 62 | #include "llvm/IR/ValueHandle.h" |
| 63 | #include "llvm/Support/AtomicOrdering.h" |
| 64 | #include "llvm/Support/Casting.h" |
| 65 | #include "llvm/Support/CommandLine.h" |
| 66 | #include "llvm/Support/Compiler.h" |
| 67 | #include "llvm/Support/Debug.h" |
| 68 | #include "llvm/Support/Error.h" |
| 69 | #include "llvm/Support/ErrorHandling.h" |
| 70 | #include "llvm/Support/ManagedStatic.h" |
| 71 | #include "llvm/Support/MemoryBuffer.h" |
| 72 | #include "llvm/Support/raw_ostream.h" |
| 73 | #include <algorithm> |
| 74 | #include <cassert> |
| 75 | #include <cstddef> |
| 76 | #include <cstdint> |
| 77 | #include <deque> |
| 78 | #include <limits> |
| 79 | #include <map> |
| 80 | #include <memory> |
| 81 | #include <string> |
| 82 | #include <system_error> |
| 83 | #include <tuple> |
| 84 | #include <utility> |
| 85 | #include <vector> |
| 86 | |
| 87 | using namespace llvm; |
| 88 | |
Teresa Johnson | a61f5e3 | 2016-12-16 21:25:01 +0000 | [diff] [blame] | 89 | /// Flag whether we need to import full type definitions for ThinLTO. |
| 90 | /// Currently needed for Darwin and LLDB. |
| 91 | static cl::opt<bool> ImportFullTypeDefinitions( |
| 92 | "import-full-type-definitions", cl::init(false), cl::Hidden, |
| 93 | cl::desc("Import full type definitions for ThinLTO.")); |
| 94 | |
Mehdi Amini | ef27db8 | 2016-12-12 19:34:26 +0000 | [diff] [blame] | 95 | namespace { |
| 96 | |
| 97 | static int64_t unrotateSign(uint64_t U) { return U & 1 ? ~(U >> 1) : U >> 1; } |
| 98 | |
| 99 | class BitcodeReaderMetadataList { |
| 100 | unsigned NumFwdRefs; |
| 101 | bool AnyFwdRefs; |
| 102 | unsigned MinFwdRef; |
| 103 | unsigned MaxFwdRef; |
| 104 | |
| 105 | /// Array of metadata references. |
| 106 | /// |
| 107 | /// Don't use std::vector here. Some versions of libc++ copy (instead of |
| 108 | /// move) on resize, and TrackingMDRef is very expensive to copy. |
| 109 | SmallVector<TrackingMDRef, 1> MetadataPtrs; |
| 110 | |
| 111 | /// Structures for resolving old type refs. |
| 112 | struct { |
| 113 | SmallDenseMap<MDString *, TempMDTuple, 1> Unknown; |
| 114 | SmallDenseMap<MDString *, DICompositeType *, 1> Final; |
| 115 | SmallDenseMap<MDString *, DICompositeType *, 1> FwdDecls; |
| 116 | SmallVector<std::pair<TrackingMDRef, TempMDTuple>, 1> Arrays; |
| 117 | } OldTypeRefs; |
| 118 | |
| 119 | LLVMContext &Context; |
| 120 | |
| 121 | public: |
| 122 | BitcodeReaderMetadataList(LLVMContext &C) |
| 123 | : NumFwdRefs(0), AnyFwdRefs(false), Context(C) {} |
| 124 | |
| 125 | // vector compatibility methods |
| 126 | unsigned size() const { return MetadataPtrs.size(); } |
| 127 | void resize(unsigned N) { MetadataPtrs.resize(N); } |
| 128 | void push_back(Metadata *MD) { MetadataPtrs.emplace_back(MD); } |
| 129 | void clear() { MetadataPtrs.clear(); } |
| 130 | Metadata *back() const { return MetadataPtrs.back(); } |
| 131 | void pop_back() { MetadataPtrs.pop_back(); } |
| 132 | bool empty() const { return MetadataPtrs.empty(); } |
| 133 | |
| 134 | Metadata *operator[](unsigned i) const { |
| 135 | assert(i < MetadataPtrs.size()); |
| 136 | return MetadataPtrs[i]; |
| 137 | } |
| 138 | |
| 139 | Metadata *lookup(unsigned I) const { |
| 140 | if (I < MetadataPtrs.size()) |
| 141 | return MetadataPtrs[I]; |
| 142 | return nullptr; |
| 143 | } |
| 144 | |
| 145 | void shrinkTo(unsigned N) { |
| 146 | assert(N <= size() && "Invalid shrinkTo request!"); |
| 147 | assert(!AnyFwdRefs && "Unexpected forward refs"); |
| 148 | MetadataPtrs.resize(N); |
| 149 | } |
| 150 | |
| 151 | /// Return the given metadata, creating a replaceable forward reference if |
| 152 | /// necessary. |
| 153 | Metadata *getMetadataFwdRef(unsigned Idx); |
| 154 | |
| 155 | /// Return the the given metadata only if it is fully resolved. |
| 156 | /// |
| 157 | /// Gives the same result as \a lookup(), unless \a MDNode::isResolved() |
| 158 | /// would give \c false. |
| 159 | Metadata *getMetadataIfResolved(unsigned Idx); |
| 160 | |
| 161 | MDNode *getMDNodeFwdRefOrNull(unsigned Idx); |
| 162 | void assignValue(Metadata *MD, unsigned Idx); |
| 163 | void tryToResolveCycles(); |
| 164 | bool hasFwdRefs() const { return AnyFwdRefs; } |
| 165 | |
| 166 | /// Upgrade a type that had an MDString reference. |
| 167 | void addTypeRef(MDString &UUID, DICompositeType &CT); |
| 168 | |
| 169 | /// Upgrade a type that had an MDString reference. |
| 170 | Metadata *upgradeTypeRef(Metadata *MaybeUUID); |
| 171 | |
| 172 | /// Upgrade a type ref array that may have MDString references. |
| 173 | Metadata *upgradeTypeRefArray(Metadata *MaybeTuple); |
| 174 | |
| 175 | private: |
| 176 | Metadata *resolveTypeRefArray(Metadata *MaybeTuple); |
| 177 | }; |
| 178 | |
| 179 | void BitcodeReaderMetadataList::assignValue(Metadata *MD, unsigned Idx) { |
| 180 | if (Idx == size()) { |
| 181 | push_back(MD); |
| 182 | return; |
| 183 | } |
| 184 | |
| 185 | if (Idx >= size()) |
| 186 | resize(Idx + 1); |
| 187 | |
| 188 | TrackingMDRef &OldMD = MetadataPtrs[Idx]; |
| 189 | if (!OldMD) { |
| 190 | OldMD.reset(MD); |
| 191 | return; |
| 192 | } |
| 193 | |
| 194 | // If there was a forward reference to this value, replace it. |
| 195 | TempMDTuple PrevMD(cast<MDTuple>(OldMD.get())); |
| 196 | PrevMD->replaceAllUsesWith(MD); |
| 197 | --NumFwdRefs; |
| 198 | } |
| 199 | |
| 200 | Metadata *BitcodeReaderMetadataList::getMetadataFwdRef(unsigned Idx) { |
| 201 | if (Idx >= size()) |
| 202 | resize(Idx + 1); |
| 203 | |
| 204 | if (Metadata *MD = MetadataPtrs[Idx]) |
| 205 | return MD; |
| 206 | |
| 207 | // Track forward refs to be resolved later. |
| 208 | if (AnyFwdRefs) { |
| 209 | MinFwdRef = std::min(MinFwdRef, Idx); |
| 210 | MaxFwdRef = std::max(MaxFwdRef, Idx); |
| 211 | } else { |
| 212 | AnyFwdRefs = true; |
| 213 | MinFwdRef = MaxFwdRef = Idx; |
| 214 | } |
| 215 | ++NumFwdRefs; |
| 216 | |
| 217 | // Create and return a placeholder, which will later be RAUW'd. |
| 218 | Metadata *MD = MDNode::getTemporary(Context, None).release(); |
| 219 | MetadataPtrs[Idx].reset(MD); |
| 220 | return MD; |
| 221 | } |
| 222 | |
| 223 | Metadata *BitcodeReaderMetadataList::getMetadataIfResolved(unsigned Idx) { |
| 224 | Metadata *MD = lookup(Idx); |
| 225 | if (auto *N = dyn_cast_or_null<MDNode>(MD)) |
| 226 | if (!N->isResolved()) |
| 227 | return nullptr; |
| 228 | return MD; |
| 229 | } |
| 230 | |
| 231 | MDNode *BitcodeReaderMetadataList::getMDNodeFwdRefOrNull(unsigned Idx) { |
| 232 | return dyn_cast_or_null<MDNode>(getMetadataFwdRef(Idx)); |
| 233 | } |
| 234 | |
| 235 | void BitcodeReaderMetadataList::tryToResolveCycles() { |
| 236 | if (NumFwdRefs) |
| 237 | // Still forward references... can't resolve cycles. |
| 238 | return; |
| 239 | |
| 240 | bool DidReplaceTypeRefs = false; |
| 241 | |
| 242 | // Give up on finding a full definition for any forward decls that remain. |
| 243 | for (const auto &Ref : OldTypeRefs.FwdDecls) |
| 244 | OldTypeRefs.Final.insert(Ref); |
| 245 | OldTypeRefs.FwdDecls.clear(); |
| 246 | |
| 247 | // Upgrade from old type ref arrays. In strange cases, this could add to |
| 248 | // OldTypeRefs.Unknown. |
| 249 | for (const auto &Array : OldTypeRefs.Arrays) { |
| 250 | DidReplaceTypeRefs = true; |
| 251 | Array.second->replaceAllUsesWith(resolveTypeRefArray(Array.first.get())); |
| 252 | } |
| 253 | OldTypeRefs.Arrays.clear(); |
| 254 | |
| 255 | // Replace old string-based type refs with the resolved node, if possible. |
| 256 | // If we haven't seen the node, leave it to the verifier to complain about |
| 257 | // the invalid string reference. |
| 258 | for (const auto &Ref : OldTypeRefs.Unknown) { |
| 259 | DidReplaceTypeRefs = true; |
| 260 | if (DICompositeType *CT = OldTypeRefs.Final.lookup(Ref.first)) |
| 261 | Ref.second->replaceAllUsesWith(CT); |
| 262 | else |
| 263 | Ref.second->replaceAllUsesWith(Ref.first); |
| 264 | } |
| 265 | OldTypeRefs.Unknown.clear(); |
| 266 | |
| 267 | // Make sure all the upgraded types are resolved. |
| 268 | if (DidReplaceTypeRefs) { |
| 269 | AnyFwdRefs = true; |
| 270 | MinFwdRef = 0; |
| 271 | MaxFwdRef = MetadataPtrs.size() - 1; |
| 272 | } |
| 273 | |
| 274 | if (!AnyFwdRefs) |
| 275 | // Nothing to do. |
| 276 | return; |
| 277 | |
| 278 | // Resolve any cycles. |
| 279 | for (unsigned I = MinFwdRef, E = MaxFwdRef + 1; I != E; ++I) { |
| 280 | auto &MD = MetadataPtrs[I]; |
| 281 | auto *N = dyn_cast_or_null<MDNode>(MD); |
| 282 | if (!N) |
| 283 | continue; |
| 284 | |
| 285 | assert(!N->isTemporary() && "Unexpected forward reference"); |
| 286 | N->resolveCycles(); |
| 287 | } |
| 288 | |
| 289 | // Make sure we return early again until there's another forward ref. |
| 290 | AnyFwdRefs = false; |
| 291 | } |
| 292 | |
| 293 | void BitcodeReaderMetadataList::addTypeRef(MDString &UUID, |
| 294 | DICompositeType &CT) { |
| 295 | assert(CT.getRawIdentifier() == &UUID && "Mismatched UUID"); |
| 296 | if (CT.isForwardDecl()) |
| 297 | OldTypeRefs.FwdDecls.insert(std::make_pair(&UUID, &CT)); |
| 298 | else |
| 299 | OldTypeRefs.Final.insert(std::make_pair(&UUID, &CT)); |
| 300 | } |
| 301 | |
| 302 | Metadata *BitcodeReaderMetadataList::upgradeTypeRef(Metadata *MaybeUUID) { |
| 303 | auto *UUID = dyn_cast_or_null<MDString>(MaybeUUID); |
| 304 | if (LLVM_LIKELY(!UUID)) |
| 305 | return MaybeUUID; |
| 306 | |
| 307 | if (auto *CT = OldTypeRefs.Final.lookup(UUID)) |
| 308 | return CT; |
| 309 | |
| 310 | auto &Ref = OldTypeRefs.Unknown[UUID]; |
| 311 | if (!Ref) |
| 312 | Ref = MDNode::getTemporary(Context, None); |
| 313 | return Ref.get(); |
| 314 | } |
| 315 | |
| 316 | Metadata *BitcodeReaderMetadataList::upgradeTypeRefArray(Metadata *MaybeTuple) { |
| 317 | auto *Tuple = dyn_cast_or_null<MDTuple>(MaybeTuple); |
| 318 | if (!Tuple || Tuple->isDistinct()) |
| 319 | return MaybeTuple; |
| 320 | |
| 321 | // Look through the array immediately if possible. |
| 322 | if (!Tuple->isTemporary()) |
| 323 | return resolveTypeRefArray(Tuple); |
| 324 | |
| 325 | // Create and return a placeholder to use for now. Eventually |
| 326 | // resolveTypeRefArrays() will be resolve this forward reference. |
| 327 | OldTypeRefs.Arrays.emplace_back( |
| 328 | std::piecewise_construct, std::forward_as_tuple(Tuple), |
| 329 | std::forward_as_tuple(MDTuple::getTemporary(Context, None))); |
| 330 | return OldTypeRefs.Arrays.back().second.get(); |
| 331 | } |
| 332 | |
| 333 | Metadata *BitcodeReaderMetadataList::resolveTypeRefArray(Metadata *MaybeTuple) { |
| 334 | auto *Tuple = dyn_cast_or_null<MDTuple>(MaybeTuple); |
| 335 | if (!Tuple || Tuple->isDistinct()) |
| 336 | return MaybeTuple; |
| 337 | |
| 338 | // Look through the DITypeRefArray, upgrading each DITypeRef. |
| 339 | SmallVector<Metadata *, 32> Ops; |
| 340 | Ops.reserve(Tuple->getNumOperands()); |
| 341 | for (Metadata *MD : Tuple->operands()) |
| 342 | Ops.push_back(upgradeTypeRef(MD)); |
| 343 | |
| 344 | return MDTuple::get(Context, Ops); |
| 345 | } |
| 346 | |
| 347 | namespace { |
| 348 | |
| 349 | class PlaceholderQueue { |
| 350 | // Placeholders would thrash around when moved, so store in a std::deque |
| 351 | // instead of some sort of vector. |
| 352 | std::deque<DistinctMDOperandPlaceholder> PHs; |
| 353 | |
| 354 | public: |
| 355 | DistinctMDOperandPlaceholder &getPlaceholderOp(unsigned ID); |
| 356 | void flush(BitcodeReaderMetadataList &MetadataList); |
| 357 | }; |
| 358 | |
| 359 | } // end anonymous namespace |
| 360 | |
| 361 | DistinctMDOperandPlaceholder &PlaceholderQueue::getPlaceholderOp(unsigned ID) { |
| 362 | PHs.emplace_back(ID); |
| 363 | return PHs.back(); |
| 364 | } |
| 365 | |
| 366 | void PlaceholderQueue::flush(BitcodeReaderMetadataList &MetadataList) { |
| 367 | while (!PHs.empty()) { |
| 368 | PHs.front().replaceUseWith( |
| 369 | MetadataList.getMetadataFwdRef(PHs.front().getID())); |
| 370 | PHs.pop_front(); |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | } // anonynous namespace |
| 375 | |
| 376 | class MetadataLoader::MetadataLoaderImpl { |
| 377 | BitcodeReaderMetadataList MetadataList; |
| 378 | BitcodeReaderValueList &ValueList; |
| 379 | BitstreamCursor &Stream; |
| 380 | LLVMContext &Context; |
| 381 | Module &TheModule; |
| 382 | std::function<Type *(unsigned)> getTypeByID; |
| 383 | |
| 384 | /// Functions that need to be matched with subprograms when upgrading old |
| 385 | /// metadata. |
| 386 | SmallDenseMap<Function *, DISubprogram *, 16> FunctionsWithSPs; |
| 387 | |
| 388 | // Map the bitcode's custom MDKind ID to the Module's MDKind ID. |
| 389 | DenseMap<unsigned, unsigned> MDKindMap; |
| 390 | |
Mehdi Amini | 8662305 | 2016-12-16 19:16:29 +0000 | [diff] [blame] | 391 | bool StripTBAA = false; |
Mehdi Amini | ef27db8 | 2016-12-12 19:34:26 +0000 | [diff] [blame] | 392 | bool HasSeenOldLoopTags = false; |
| 393 | |
| 394 | Error parseMetadataStrings(ArrayRef<uint64_t> Record, StringRef Blob, |
| 395 | unsigned &NextMetadataNo); |
| 396 | Error parseGlobalObjectAttachment(GlobalObject &GO, |
| 397 | ArrayRef<uint64_t> Record); |
| 398 | Error parseMetadataKindRecord(SmallVectorImpl<uint64_t> &Record); |
| 399 | |
| 400 | public: |
| 401 | MetadataLoaderImpl(BitstreamCursor &Stream, Module &TheModule, |
| 402 | BitcodeReaderValueList &ValueList, |
| 403 | std::function<Type *(unsigned)> getTypeByID) |
| 404 | : MetadataList(TheModule.getContext()), ValueList(ValueList), |
| 405 | Stream(Stream), Context(TheModule.getContext()), TheModule(TheModule), |
| 406 | getTypeByID(getTypeByID) {} |
| 407 | |
Teresa Johnson | a61f5e3 | 2016-12-16 21:25:01 +0000 | [diff] [blame] | 408 | Error parseMetadata(bool ModuleLevel, bool IsImporting); |
Mehdi Amini | ef27db8 | 2016-12-12 19:34:26 +0000 | [diff] [blame] | 409 | |
| 410 | bool hasFwdRefs() const { return MetadataList.hasFwdRefs(); } |
| 411 | Metadata *getMetadataFwdRef(unsigned Idx) { |
| 412 | return MetadataList.getMetadataFwdRef(Idx); |
| 413 | } |
| 414 | |
| 415 | MDNode *getMDNodeFwdRefOrNull(unsigned Idx) { |
| 416 | return MetadataList.getMDNodeFwdRefOrNull(Idx); |
| 417 | } |
| 418 | |
| 419 | DISubprogram *lookupSubprogramForFunction(Function *F) { |
| 420 | return FunctionsWithSPs.lookup(F); |
| 421 | } |
| 422 | |
| 423 | bool hasSeenOldLoopTags() { return HasSeenOldLoopTags; } |
| 424 | |
| 425 | Error parseMetadataAttachment( |
| 426 | Function &F, const SmallVectorImpl<Instruction *> &InstructionList); |
| 427 | |
| 428 | Error parseMetadataKinds(); |
| 429 | |
Mehdi Amini | 8662305 | 2016-12-16 19:16:29 +0000 | [diff] [blame] | 430 | void setStripTBAA(bool Value) { StripTBAA = Value; } |
| 431 | bool isStrippingTBAA() { return StripTBAA; } |
| 432 | |
Mehdi Amini | ef27db8 | 2016-12-12 19:34:26 +0000 | [diff] [blame] | 433 | unsigned size() const { return MetadataList.size(); } |
| 434 | void shrinkTo(unsigned N) { MetadataList.shrinkTo(N); } |
| 435 | }; |
| 436 | |
| 437 | Error error(const Twine &Message) { |
| 438 | return make_error<StringError>( |
| 439 | Message, make_error_code(BitcodeError::CorruptedBitcode)); |
| 440 | } |
| 441 | |
| 442 | /// Parse a METADATA_BLOCK. If ModuleLevel is true then we are parsing |
| 443 | /// module level metadata. |
Teresa Johnson | a61f5e3 | 2016-12-16 21:25:01 +0000 | [diff] [blame] | 444 | Error MetadataLoader::MetadataLoaderImpl::parseMetadata(bool ModuleLevel, |
| 445 | bool IsImporting) { |
Mehdi Amini | ef27db8 | 2016-12-12 19:34:26 +0000 | [diff] [blame] | 446 | if (!ModuleLevel && MetadataList.hasFwdRefs()) |
| 447 | return error("Invalid metadata: fwd refs into function blocks"); |
| 448 | |
| 449 | if (Stream.EnterSubBlock(bitc::METADATA_BLOCK_ID)) |
| 450 | return error("Invalid record"); |
| 451 | |
| 452 | unsigned NextMetadataNo = MetadataList.size(); |
| 453 | std::vector<std::pair<DICompileUnit *, Metadata *>> CUSubprograms; |
| 454 | SmallVector<uint64_t, 64> Record; |
| 455 | |
| 456 | PlaceholderQueue Placeholders; |
| 457 | bool IsDistinct; |
| 458 | auto getMD = [&](unsigned ID) -> Metadata * { |
| 459 | if (!IsDistinct) |
| 460 | return MetadataList.getMetadataFwdRef(ID); |
| 461 | if (auto *MD = MetadataList.getMetadataIfResolved(ID)) |
| 462 | return MD; |
| 463 | return &Placeholders.getPlaceholderOp(ID); |
| 464 | }; |
| 465 | auto getMDOrNull = [&](unsigned ID) -> Metadata * { |
| 466 | if (ID) |
| 467 | return getMD(ID - 1); |
| 468 | return nullptr; |
| 469 | }; |
| 470 | auto getMDOrNullWithoutPlaceholders = [&](unsigned ID) -> Metadata * { |
| 471 | if (ID) |
| 472 | return MetadataList.getMetadataFwdRef(ID - 1); |
| 473 | return nullptr; |
| 474 | }; |
| 475 | auto getMDString = [&](unsigned ID) -> MDString * { |
| 476 | // This requires that the ID is not really a forward reference. In |
| 477 | // particular, the MDString must already have been resolved. |
| 478 | return cast_or_null<MDString>(getMDOrNull(ID)); |
| 479 | }; |
| 480 | |
| 481 | // Support for old type refs. |
| 482 | auto getDITypeRefOrNull = [&](unsigned ID) { |
| 483 | return MetadataList.upgradeTypeRef(getMDOrNull(ID)); |
| 484 | }; |
| 485 | |
| 486 | #define GET_OR_DISTINCT(CLASS, ARGS) \ |
| 487 | (IsDistinct ? CLASS::getDistinct ARGS : CLASS::get ARGS) |
| 488 | |
| 489 | // Read all the records. |
| 490 | while (true) { |
| 491 | BitstreamEntry Entry = Stream.advanceSkippingSubblocks(); |
| 492 | |
| 493 | switch (Entry.Kind) { |
| 494 | case BitstreamEntry::SubBlock: // Handled for us already. |
| 495 | case BitstreamEntry::Error: |
| 496 | return error("Malformed block"); |
| 497 | case BitstreamEntry::EndBlock: |
| 498 | // Upgrade old-style CU <-> SP pointers to point from SP to CU. |
| 499 | for (auto CU_SP : CUSubprograms) |
| 500 | if (auto *SPs = dyn_cast_or_null<MDTuple>(CU_SP.second)) |
| 501 | for (auto &Op : SPs->operands()) |
| 502 | if (auto *SP = dyn_cast_or_null<MDNode>(Op)) |
| 503 | SP->replaceOperandWith(7, CU_SP.first); |
| 504 | |
| 505 | MetadataList.tryToResolveCycles(); |
| 506 | Placeholders.flush(MetadataList); |
| 507 | return Error::success(); |
| 508 | case BitstreamEntry::Record: |
| 509 | // The interesting case. |
| 510 | break; |
| 511 | } |
| 512 | |
| 513 | // Read a record. |
| 514 | Record.clear(); |
| 515 | StringRef Blob; |
| 516 | unsigned Code = Stream.readRecord(Entry.ID, Record, &Blob); |
| 517 | IsDistinct = false; |
| 518 | switch (Code) { |
| 519 | default: // Default behavior: ignore. |
| 520 | break; |
| 521 | case bitc::METADATA_NAME: { |
| 522 | // Read name of the named metadata. |
| 523 | SmallString<8> Name(Record.begin(), Record.end()); |
| 524 | Record.clear(); |
| 525 | Code = Stream.ReadCode(); |
| 526 | |
| 527 | unsigned NextBitCode = Stream.readRecord(Code, Record); |
| 528 | if (NextBitCode != bitc::METADATA_NAMED_NODE) |
| 529 | return error("METADATA_NAME not followed by METADATA_NAMED_NODE"); |
| 530 | |
| 531 | // Read named metadata elements. |
| 532 | unsigned Size = Record.size(); |
| 533 | NamedMDNode *NMD = TheModule.getOrInsertNamedMetadata(Name); |
| 534 | for (unsigned i = 0; i != Size; ++i) { |
| 535 | MDNode *MD = MetadataList.getMDNodeFwdRefOrNull(Record[i]); |
| 536 | if (!MD) |
| 537 | return error("Invalid record"); |
| 538 | NMD->addOperand(MD); |
| 539 | } |
| 540 | break; |
| 541 | } |
| 542 | case bitc::METADATA_OLD_FN_NODE: { |
| 543 | // FIXME: Remove in 4.0. |
| 544 | // This is a LocalAsMetadata record, the only type of function-local |
| 545 | // metadata. |
| 546 | if (Record.size() % 2 == 1) |
| 547 | return error("Invalid record"); |
| 548 | |
| 549 | // If this isn't a LocalAsMetadata record, we're dropping it. This used |
| 550 | // to be legal, but there's no upgrade path. |
| 551 | auto dropRecord = [&] { |
| 552 | MetadataList.assignValue(MDNode::get(Context, None), NextMetadataNo++); |
| 553 | }; |
| 554 | if (Record.size() != 2) { |
| 555 | dropRecord(); |
| 556 | break; |
| 557 | } |
| 558 | |
| 559 | Type *Ty = getTypeByID(Record[0]); |
| 560 | if (Ty->isMetadataTy() || Ty->isVoidTy()) { |
| 561 | dropRecord(); |
| 562 | break; |
| 563 | } |
| 564 | |
| 565 | MetadataList.assignValue( |
| 566 | LocalAsMetadata::get(ValueList.getValueFwdRef(Record[1], Ty)), |
| 567 | NextMetadataNo++); |
| 568 | break; |
| 569 | } |
| 570 | case bitc::METADATA_OLD_NODE: { |
| 571 | // FIXME: Remove in 4.0. |
| 572 | if (Record.size() % 2 == 1) |
| 573 | return error("Invalid record"); |
| 574 | |
| 575 | unsigned Size = Record.size(); |
| 576 | SmallVector<Metadata *, 8> Elts; |
| 577 | for (unsigned i = 0; i != Size; i += 2) { |
| 578 | Type *Ty = getTypeByID(Record[i]); |
| 579 | if (!Ty) |
| 580 | return error("Invalid record"); |
| 581 | if (Ty->isMetadataTy()) |
| 582 | Elts.push_back(getMD(Record[i + 1])); |
| 583 | else if (!Ty->isVoidTy()) { |
| 584 | auto *MD = |
| 585 | ValueAsMetadata::get(ValueList.getValueFwdRef(Record[i + 1], Ty)); |
| 586 | assert(isa<ConstantAsMetadata>(MD) && |
| 587 | "Expected non-function-local metadata"); |
| 588 | Elts.push_back(MD); |
| 589 | } else |
| 590 | Elts.push_back(nullptr); |
| 591 | } |
| 592 | MetadataList.assignValue(MDNode::get(Context, Elts), NextMetadataNo++); |
| 593 | break; |
| 594 | } |
| 595 | case bitc::METADATA_VALUE: { |
| 596 | if (Record.size() != 2) |
| 597 | return error("Invalid record"); |
| 598 | |
| 599 | Type *Ty = getTypeByID(Record[0]); |
| 600 | if (Ty->isMetadataTy() || Ty->isVoidTy()) |
| 601 | return error("Invalid record"); |
| 602 | |
| 603 | MetadataList.assignValue( |
| 604 | ValueAsMetadata::get(ValueList.getValueFwdRef(Record[1], Ty)), |
| 605 | NextMetadataNo++); |
| 606 | break; |
| 607 | } |
| 608 | case bitc::METADATA_DISTINCT_NODE: |
| 609 | IsDistinct = true; |
| 610 | LLVM_FALLTHROUGH; |
| 611 | case bitc::METADATA_NODE: { |
| 612 | SmallVector<Metadata *, 8> Elts; |
| 613 | Elts.reserve(Record.size()); |
| 614 | for (unsigned ID : Record) |
| 615 | Elts.push_back(getMDOrNull(ID)); |
| 616 | MetadataList.assignValue(IsDistinct ? MDNode::getDistinct(Context, Elts) |
| 617 | : MDNode::get(Context, Elts), |
| 618 | NextMetadataNo++); |
| 619 | break; |
| 620 | } |
| 621 | case bitc::METADATA_LOCATION: { |
| 622 | if (Record.size() != 5) |
| 623 | return error("Invalid record"); |
| 624 | |
| 625 | IsDistinct = Record[0]; |
| 626 | unsigned Line = Record[1]; |
| 627 | unsigned Column = Record[2]; |
| 628 | Metadata *Scope = getMD(Record[3]); |
| 629 | Metadata *InlinedAt = getMDOrNull(Record[4]); |
| 630 | MetadataList.assignValue( |
| 631 | GET_OR_DISTINCT(DILocation, |
| 632 | (Context, Line, Column, Scope, InlinedAt)), |
| 633 | NextMetadataNo++); |
| 634 | break; |
| 635 | } |
| 636 | case bitc::METADATA_GENERIC_DEBUG: { |
| 637 | if (Record.size() < 4) |
| 638 | return error("Invalid record"); |
| 639 | |
| 640 | IsDistinct = Record[0]; |
| 641 | unsigned Tag = Record[1]; |
| 642 | unsigned Version = Record[2]; |
| 643 | |
| 644 | if (Tag >= 1u << 16 || Version != 0) |
| 645 | return error("Invalid record"); |
| 646 | |
| 647 | auto *Header = getMDString(Record[3]); |
| 648 | SmallVector<Metadata *, 8> DwarfOps; |
| 649 | for (unsigned I = 4, E = Record.size(); I != E; ++I) |
| 650 | DwarfOps.push_back(getMDOrNull(Record[I])); |
| 651 | MetadataList.assignValue( |
| 652 | GET_OR_DISTINCT(GenericDINode, (Context, Tag, Header, DwarfOps)), |
| 653 | NextMetadataNo++); |
| 654 | break; |
| 655 | } |
| 656 | case bitc::METADATA_SUBRANGE: { |
| 657 | if (Record.size() != 3) |
| 658 | return error("Invalid record"); |
| 659 | |
| 660 | IsDistinct = Record[0]; |
| 661 | MetadataList.assignValue( |
| 662 | GET_OR_DISTINCT(DISubrange, |
| 663 | (Context, Record[1], unrotateSign(Record[2]))), |
| 664 | NextMetadataNo++); |
| 665 | break; |
| 666 | } |
| 667 | case bitc::METADATA_ENUMERATOR: { |
| 668 | if (Record.size() != 3) |
| 669 | return error("Invalid record"); |
| 670 | |
| 671 | IsDistinct = Record[0]; |
| 672 | MetadataList.assignValue( |
| 673 | GET_OR_DISTINCT(DIEnumerator, (Context, unrotateSign(Record[1]), |
| 674 | getMDString(Record[2]))), |
| 675 | NextMetadataNo++); |
| 676 | break; |
| 677 | } |
| 678 | case bitc::METADATA_BASIC_TYPE: { |
| 679 | if (Record.size() != 6) |
| 680 | return error("Invalid record"); |
| 681 | |
| 682 | IsDistinct = Record[0]; |
| 683 | MetadataList.assignValue( |
| 684 | GET_OR_DISTINCT(DIBasicType, |
| 685 | (Context, Record[1], getMDString(Record[2]), |
| 686 | Record[3], Record[4], Record[5])), |
| 687 | NextMetadataNo++); |
| 688 | break; |
| 689 | } |
| 690 | case bitc::METADATA_DERIVED_TYPE: { |
| 691 | if (Record.size() != 12) |
| 692 | return error("Invalid record"); |
| 693 | |
| 694 | IsDistinct = Record[0]; |
| 695 | DINode::DIFlags Flags = static_cast<DINode::DIFlags>(Record[10]); |
| 696 | MetadataList.assignValue( |
| 697 | GET_OR_DISTINCT(DIDerivedType, |
| 698 | (Context, Record[1], getMDString(Record[2]), |
| 699 | getMDOrNull(Record[3]), Record[4], |
| 700 | getDITypeRefOrNull(Record[5]), |
| 701 | getDITypeRefOrNull(Record[6]), Record[7], Record[8], |
| 702 | Record[9], Flags, getDITypeRefOrNull(Record[11]))), |
| 703 | NextMetadataNo++); |
| 704 | break; |
| 705 | } |
| 706 | case bitc::METADATA_COMPOSITE_TYPE: { |
| 707 | if (Record.size() != 16) |
| 708 | return error("Invalid record"); |
| 709 | |
| 710 | // If we have a UUID and this is not a forward declaration, lookup the |
| 711 | // mapping. |
| 712 | IsDistinct = Record[0] & 0x1; |
| 713 | bool IsNotUsedInTypeRef = Record[0] >= 2; |
| 714 | unsigned Tag = Record[1]; |
| 715 | MDString *Name = getMDString(Record[2]); |
| 716 | Metadata *File = getMDOrNull(Record[3]); |
| 717 | unsigned Line = Record[4]; |
| 718 | Metadata *Scope = getDITypeRefOrNull(Record[5]); |
Teresa Johnson | a61f5e3 | 2016-12-16 21:25:01 +0000 | [diff] [blame] | 719 | Metadata *BaseType = nullptr; |
Mehdi Amini | ef27db8 | 2016-12-12 19:34:26 +0000 | [diff] [blame] | 720 | uint64_t SizeInBits = Record[7]; |
| 721 | if (Record[8] > (uint64_t)std::numeric_limits<uint32_t>::max()) |
| 722 | return error("Alignment value is too large"); |
| 723 | uint32_t AlignInBits = Record[8]; |
Teresa Johnson | a61f5e3 | 2016-12-16 21:25:01 +0000 | [diff] [blame] | 724 | uint64_t OffsetInBits = 0; |
Mehdi Amini | ef27db8 | 2016-12-12 19:34:26 +0000 | [diff] [blame] | 725 | DINode::DIFlags Flags = static_cast<DINode::DIFlags>(Record[10]); |
Teresa Johnson | a61f5e3 | 2016-12-16 21:25:01 +0000 | [diff] [blame] | 726 | Metadata *Elements = nullptr; |
Mehdi Amini | ef27db8 | 2016-12-12 19:34:26 +0000 | [diff] [blame] | 727 | unsigned RuntimeLang = Record[12]; |
Teresa Johnson | a61f5e3 | 2016-12-16 21:25:01 +0000 | [diff] [blame] | 728 | Metadata *VTableHolder = nullptr; |
| 729 | Metadata *TemplateParams = nullptr; |
Mehdi Amini | ef27db8 | 2016-12-12 19:34:26 +0000 | [diff] [blame] | 730 | auto *Identifier = getMDString(Record[15]); |
Teresa Johnson | a61f5e3 | 2016-12-16 21:25:01 +0000 | [diff] [blame] | 731 | // If this module is being parsed so that it can be ThinLTO imported |
| 732 | // into another module, composite types only need to be imported |
| 733 | // as type declarations (unless full type definitions requested). |
| 734 | // Create type declarations up front to save memory. Also, buildODRType |
| 735 | // handles the case where this is type ODRed with a definition needed |
| 736 | // by the importing module, in which case the existing definition is |
| 737 | // used. |
| 738 | if (IsImporting && !ImportFullTypeDefinitions && |
| 739 | (Tag == dwarf::DW_TAG_enumeration_type || |
| 740 | Tag == dwarf::DW_TAG_class_type || |
| 741 | Tag == dwarf::DW_TAG_structure_type || |
| 742 | Tag == dwarf::DW_TAG_union_type)) { |
| 743 | Flags = Flags | DINode::FlagFwdDecl; |
| 744 | } else { |
| 745 | BaseType = getDITypeRefOrNull(Record[6]); |
| 746 | OffsetInBits = Record[9]; |
| 747 | Elements = getMDOrNull(Record[11]); |
| 748 | VTableHolder = getDITypeRefOrNull(Record[13]); |
| 749 | TemplateParams = getMDOrNull(Record[14]); |
| 750 | } |
Mehdi Amini | ef27db8 | 2016-12-12 19:34:26 +0000 | [diff] [blame] | 751 | DICompositeType *CT = nullptr; |
| 752 | if (Identifier) |
| 753 | CT = DICompositeType::buildODRType( |
| 754 | Context, *Identifier, Tag, Name, File, Line, Scope, BaseType, |
| 755 | SizeInBits, AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, |
| 756 | VTableHolder, TemplateParams); |
| 757 | |
| 758 | // Create a node if we didn't get a lazy ODR type. |
| 759 | if (!CT) |
| 760 | CT = GET_OR_DISTINCT(DICompositeType, |
| 761 | (Context, Tag, Name, File, Line, Scope, BaseType, |
| 762 | SizeInBits, AlignInBits, OffsetInBits, Flags, |
| 763 | Elements, RuntimeLang, VTableHolder, |
| 764 | TemplateParams, Identifier)); |
| 765 | if (!IsNotUsedInTypeRef && Identifier) |
| 766 | MetadataList.addTypeRef(*Identifier, *cast<DICompositeType>(CT)); |
| 767 | |
| 768 | MetadataList.assignValue(CT, NextMetadataNo++); |
| 769 | break; |
| 770 | } |
| 771 | case bitc::METADATA_SUBROUTINE_TYPE: { |
| 772 | if (Record.size() < 3 || Record.size() > 4) |
| 773 | return error("Invalid record"); |
| 774 | bool IsOldTypeRefArray = Record[0] < 2; |
| 775 | unsigned CC = (Record.size() > 3) ? Record[3] : 0; |
| 776 | |
| 777 | IsDistinct = Record[0] & 0x1; |
| 778 | DINode::DIFlags Flags = static_cast<DINode::DIFlags>(Record[1]); |
| 779 | Metadata *Types = getMDOrNull(Record[2]); |
| 780 | if (LLVM_UNLIKELY(IsOldTypeRefArray)) |
| 781 | Types = MetadataList.upgradeTypeRefArray(Types); |
| 782 | |
| 783 | MetadataList.assignValue( |
| 784 | GET_OR_DISTINCT(DISubroutineType, (Context, Flags, CC, Types)), |
| 785 | NextMetadataNo++); |
| 786 | break; |
| 787 | } |
| 788 | |
| 789 | case bitc::METADATA_MODULE: { |
| 790 | if (Record.size() != 6) |
| 791 | return error("Invalid record"); |
| 792 | |
| 793 | IsDistinct = Record[0]; |
| 794 | MetadataList.assignValue( |
| 795 | GET_OR_DISTINCT(DIModule, |
| 796 | (Context, getMDOrNull(Record[1]), |
| 797 | getMDString(Record[2]), getMDString(Record[3]), |
| 798 | getMDString(Record[4]), getMDString(Record[5]))), |
| 799 | NextMetadataNo++); |
| 800 | break; |
| 801 | } |
| 802 | |
| 803 | case bitc::METADATA_FILE: { |
| 804 | if (Record.size() != 3) |
| 805 | return error("Invalid record"); |
| 806 | |
| 807 | IsDistinct = Record[0]; |
| 808 | MetadataList.assignValue( |
| 809 | GET_OR_DISTINCT(DIFile, (Context, getMDString(Record[1]), |
| 810 | getMDString(Record[2]))), |
| 811 | NextMetadataNo++); |
| 812 | break; |
| 813 | } |
| 814 | case bitc::METADATA_COMPILE_UNIT: { |
| 815 | if (Record.size() < 14 || Record.size() > 17) |
| 816 | return error("Invalid record"); |
| 817 | |
| 818 | // Ignore Record[0], which indicates whether this compile unit is |
| 819 | // distinct. It's always distinct. |
| 820 | IsDistinct = true; |
| 821 | auto *CU = DICompileUnit::getDistinct( |
| 822 | Context, Record[1], getMDOrNull(Record[2]), getMDString(Record[3]), |
| 823 | Record[4], getMDString(Record[5]), Record[6], getMDString(Record[7]), |
| 824 | Record[8], getMDOrNull(Record[9]), getMDOrNull(Record[10]), |
| 825 | getMDOrNull(Record[12]), getMDOrNull(Record[13]), |
| 826 | Record.size() <= 15 ? nullptr : getMDOrNull(Record[15]), |
| 827 | Record.size() <= 14 ? 0 : Record[14], |
| 828 | Record.size() <= 16 ? true : Record[16]); |
| 829 | |
| 830 | MetadataList.assignValue(CU, NextMetadataNo++); |
| 831 | |
| 832 | // Move the Upgrade the list of subprograms. |
| 833 | if (Metadata *SPs = getMDOrNullWithoutPlaceholders(Record[11])) |
| 834 | CUSubprograms.push_back({CU, SPs}); |
| 835 | break; |
| 836 | } |
| 837 | case bitc::METADATA_SUBPROGRAM: { |
| 838 | if (Record.size() < 18 || Record.size() > 20) |
| 839 | return error("Invalid record"); |
| 840 | |
| 841 | IsDistinct = |
| 842 | (Record[0] & 1) || Record[8]; // All definitions should be distinct. |
| 843 | // Version 1 has a Function as Record[15]. |
| 844 | // Version 2 has removed Record[15]. |
| 845 | // Version 3 has the Unit as Record[15]. |
| 846 | // Version 4 added thisAdjustment. |
| 847 | bool HasUnit = Record[0] >= 2; |
| 848 | if (HasUnit && Record.size() < 19) |
| 849 | return error("Invalid record"); |
| 850 | Metadata *CUorFn = getMDOrNull(Record[15]); |
| 851 | unsigned Offset = Record.size() >= 19 ? 1 : 0; |
| 852 | bool HasFn = Offset && !HasUnit; |
| 853 | bool HasThisAdj = Record.size() >= 20; |
| 854 | DISubprogram *SP = GET_OR_DISTINCT( |
| 855 | DISubprogram, (Context, |
| 856 | getDITypeRefOrNull(Record[1]), // scope |
| 857 | getMDString(Record[2]), // name |
| 858 | getMDString(Record[3]), // linkageName |
| 859 | getMDOrNull(Record[4]), // file |
| 860 | Record[5], // line |
| 861 | getMDOrNull(Record[6]), // type |
| 862 | Record[7], // isLocal |
| 863 | Record[8], // isDefinition |
| 864 | Record[9], // scopeLine |
| 865 | getDITypeRefOrNull(Record[10]), // containingType |
| 866 | Record[11], // virtuality |
| 867 | Record[12], // virtualIndex |
| 868 | HasThisAdj ? Record[19] : 0, // thisAdjustment |
| 869 | static_cast<DINode::DIFlags>(Record[13] // flags |
| 870 | ), |
| 871 | Record[14], // isOptimized |
| 872 | HasUnit ? CUorFn : nullptr, // unit |
| 873 | getMDOrNull(Record[15 + Offset]), // templateParams |
| 874 | getMDOrNull(Record[16 + Offset]), // declaration |
| 875 | getMDOrNull(Record[17 + Offset]) // variables |
| 876 | )); |
| 877 | MetadataList.assignValue(SP, NextMetadataNo++); |
| 878 | |
| 879 | // Upgrade sp->function mapping to function->sp mapping. |
| 880 | if (HasFn) { |
| 881 | if (auto *CMD = dyn_cast_or_null<ConstantAsMetadata>(CUorFn)) |
| 882 | if (auto *F = dyn_cast<Function>(CMD->getValue())) { |
| 883 | if (F->isMaterializable()) |
| 884 | // Defer until materialized; unmaterialized functions may not have |
| 885 | // metadata. |
| 886 | FunctionsWithSPs[F] = SP; |
| 887 | else if (!F->empty()) |
| 888 | F->setSubprogram(SP); |
| 889 | } |
| 890 | } |
| 891 | break; |
| 892 | } |
| 893 | case bitc::METADATA_LEXICAL_BLOCK: { |
| 894 | if (Record.size() != 5) |
| 895 | return error("Invalid record"); |
| 896 | |
| 897 | IsDistinct = Record[0]; |
| 898 | MetadataList.assignValue( |
| 899 | GET_OR_DISTINCT(DILexicalBlock, |
| 900 | (Context, getMDOrNull(Record[1]), |
| 901 | getMDOrNull(Record[2]), Record[3], Record[4])), |
| 902 | NextMetadataNo++); |
| 903 | break; |
| 904 | } |
| 905 | case bitc::METADATA_LEXICAL_BLOCK_FILE: { |
| 906 | if (Record.size() != 4) |
| 907 | return error("Invalid record"); |
| 908 | |
| 909 | IsDistinct = Record[0]; |
| 910 | MetadataList.assignValue( |
| 911 | GET_OR_DISTINCT(DILexicalBlockFile, |
| 912 | (Context, getMDOrNull(Record[1]), |
| 913 | getMDOrNull(Record[2]), Record[3])), |
| 914 | NextMetadataNo++); |
| 915 | break; |
| 916 | } |
| 917 | case bitc::METADATA_NAMESPACE: { |
| 918 | if (Record.size() != 5) |
| 919 | return error("Invalid record"); |
| 920 | |
| 921 | IsDistinct = Record[0] & 1; |
| 922 | bool ExportSymbols = Record[0] & 2; |
| 923 | MetadataList.assignValue( |
| 924 | GET_OR_DISTINCT(DINamespace, |
| 925 | (Context, getMDOrNull(Record[1]), |
| 926 | getMDOrNull(Record[2]), getMDString(Record[3]), |
| 927 | Record[4], ExportSymbols)), |
| 928 | NextMetadataNo++); |
| 929 | break; |
| 930 | } |
| 931 | case bitc::METADATA_MACRO: { |
| 932 | if (Record.size() != 5) |
| 933 | return error("Invalid record"); |
| 934 | |
| 935 | IsDistinct = Record[0]; |
| 936 | MetadataList.assignValue( |
| 937 | GET_OR_DISTINCT(DIMacro, |
| 938 | (Context, Record[1], Record[2], |
| 939 | getMDString(Record[3]), getMDString(Record[4]))), |
| 940 | NextMetadataNo++); |
| 941 | break; |
| 942 | } |
| 943 | case bitc::METADATA_MACRO_FILE: { |
| 944 | if (Record.size() != 5) |
| 945 | return error("Invalid record"); |
| 946 | |
| 947 | IsDistinct = Record[0]; |
| 948 | MetadataList.assignValue( |
| 949 | GET_OR_DISTINCT(DIMacroFile, |
| 950 | (Context, Record[1], Record[2], |
| 951 | getMDOrNull(Record[3]), getMDOrNull(Record[4]))), |
| 952 | NextMetadataNo++); |
| 953 | break; |
| 954 | } |
| 955 | case bitc::METADATA_TEMPLATE_TYPE: { |
| 956 | if (Record.size() != 3) |
| 957 | return error("Invalid record"); |
| 958 | |
| 959 | IsDistinct = Record[0]; |
| 960 | MetadataList.assignValue(GET_OR_DISTINCT(DITemplateTypeParameter, |
| 961 | (Context, getMDString(Record[1]), |
| 962 | getDITypeRefOrNull(Record[2]))), |
| 963 | NextMetadataNo++); |
| 964 | break; |
| 965 | } |
| 966 | case bitc::METADATA_TEMPLATE_VALUE: { |
| 967 | if (Record.size() != 5) |
| 968 | return error("Invalid record"); |
| 969 | |
| 970 | IsDistinct = Record[0]; |
| 971 | MetadataList.assignValue( |
| 972 | GET_OR_DISTINCT(DITemplateValueParameter, |
| 973 | (Context, Record[1], getMDString(Record[2]), |
| 974 | getDITypeRefOrNull(Record[3]), |
| 975 | getMDOrNull(Record[4]))), |
| 976 | NextMetadataNo++); |
| 977 | break; |
| 978 | } |
| 979 | case bitc::METADATA_GLOBAL_VAR: { |
| 980 | if (Record.size() < 11 || Record.size() > 12) |
| 981 | return error("Invalid record"); |
| 982 | |
Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 983 | IsDistinct = Record[0] & 1; |
| 984 | unsigned Version = Record[0] >> 1; |
Mehdi Amini | ef27db8 | 2016-12-12 19:34:26 +0000 | [diff] [blame] | 985 | |
Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 986 | if (Version == 1) { |
| 987 | MetadataList.assignValue( |
| 988 | GET_OR_DISTINCT(DIGlobalVariable, |
| 989 | (Context, getMDOrNull(Record[1]), |
| 990 | getMDString(Record[2]), getMDString(Record[3]), |
| 991 | getMDOrNull(Record[4]), Record[5], |
| 992 | getDITypeRefOrNull(Record[6]), Record[7], |
| 993 | Record[8], getMDOrNull(Record[10]), Record[11])), |
| 994 | NextMetadataNo++); |
| 995 | } else if (Version == 0) { |
| 996 | // Upgrade old metadata, which stored a global variable reference or a |
| 997 | // ConstantInt here. |
| 998 | Metadata *Expr = getMDOrNull(Record[9]); |
| 999 | uint32_t AlignInBits = 0; |
| 1000 | if (Record.size() > 11) { |
| 1001 | if (Record[11] > (uint64_t)std::numeric_limits<uint32_t>::max()) |
| 1002 | return error("Alignment value is too large"); |
| 1003 | AlignInBits = Record[11]; |
Mehdi Amini | ef27db8 | 2016-12-12 19:34:26 +0000 | [diff] [blame] | 1004 | } |
Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 1005 | GlobalVariable *Attach = nullptr; |
| 1006 | if (auto *CMD = dyn_cast_or_null<ConstantAsMetadata>(Expr)) { |
| 1007 | if (auto *GV = dyn_cast<GlobalVariable>(CMD->getValue())) { |
| 1008 | Attach = GV; |
| 1009 | Expr = nullptr; |
| 1010 | } else if (auto *CI = dyn_cast<ConstantInt>(CMD->getValue())) { |
| 1011 | Expr = DIExpression::get(Context, |
| 1012 | {dwarf::DW_OP_constu, CI->getZExtValue(), |
| 1013 | dwarf::DW_OP_stack_value}); |
| 1014 | } else { |
| 1015 | Expr = nullptr; |
| 1016 | } |
| 1017 | } |
| 1018 | DIGlobalVariable *DGV = GET_OR_DISTINCT( |
| 1019 | DIGlobalVariable, |
| 1020 | (Context, getMDOrNull(Record[1]), getMDString(Record[2]), |
| 1021 | getMDString(Record[3]), getMDOrNull(Record[4]), Record[5], |
| 1022 | getDITypeRefOrNull(Record[6]), Record[7], Record[8], |
| 1023 | getMDOrNull(Record[10]), AlignInBits)); |
Mehdi Amini | ef27db8 | 2016-12-12 19:34:26 +0000 | [diff] [blame] | 1024 | |
Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 1025 | auto *DGVE = |
| 1026 | DIGlobalVariableExpression::getDistinct(Context, DGV, Expr); |
| 1027 | MetadataList.assignValue(DGVE, NextMetadataNo++); |
| 1028 | if (Attach) |
| 1029 | Attach->addDebugInfo(DGVE); |
| 1030 | } else |
| 1031 | return error("Invalid record"); |
Mehdi Amini | ef27db8 | 2016-12-12 19:34:26 +0000 | [diff] [blame] | 1032 | |
| 1033 | break; |
| 1034 | } |
| 1035 | case bitc::METADATA_LOCAL_VAR: { |
| 1036 | // 10th field is for the obseleted 'inlinedAt:' field. |
| 1037 | if (Record.size() < 8 || Record.size() > 10) |
| 1038 | return error("Invalid record"); |
| 1039 | |
| 1040 | IsDistinct = Record[0] & 1; |
| 1041 | bool HasAlignment = Record[0] & 2; |
| 1042 | // 2nd field used to be an artificial tag, either DW_TAG_auto_variable or |
| 1043 | // DW_TAG_arg_variable, if we have alignment flag encoded it means, that |
| 1044 | // this is newer version of record which doesn't have artifical tag. |
| 1045 | bool HasTag = !HasAlignment && Record.size() > 8; |
| 1046 | DINode::DIFlags Flags = static_cast<DINode::DIFlags>(Record[7 + HasTag]); |
| 1047 | uint32_t AlignInBits = 0; |
| 1048 | if (HasAlignment) { |
| 1049 | if (Record[8 + HasTag] > (uint64_t)std::numeric_limits<uint32_t>::max()) |
| 1050 | return error("Alignment value is too large"); |
| 1051 | AlignInBits = Record[8 + HasTag]; |
| 1052 | } |
| 1053 | MetadataList.assignValue( |
| 1054 | GET_OR_DISTINCT(DILocalVariable, |
| 1055 | (Context, getMDOrNull(Record[1 + HasTag]), |
| 1056 | getMDString(Record[2 + HasTag]), |
| 1057 | getMDOrNull(Record[3 + HasTag]), Record[4 + HasTag], |
| 1058 | getDITypeRefOrNull(Record[5 + HasTag]), |
| 1059 | Record[6 + HasTag], Flags, AlignInBits)), |
| 1060 | NextMetadataNo++); |
| 1061 | break; |
| 1062 | } |
| 1063 | case bitc::METADATA_EXPRESSION: { |
| 1064 | if (Record.size() < 1) |
| 1065 | return error("Invalid record"); |
| 1066 | |
| 1067 | IsDistinct = Record[0] & 1; |
| 1068 | bool HasOpFragment = Record[0] & 2; |
| 1069 | auto Elts = MutableArrayRef<uint64_t>(Record).slice(1); |
| 1070 | if (!HasOpFragment) |
| 1071 | if (unsigned N = Elts.size()) |
| 1072 | if (N >= 3 && Elts[N - 3] == dwarf::DW_OP_bit_piece) |
| 1073 | Elts[N - 3] = dwarf::DW_OP_LLVM_fragment; |
| 1074 | |
| 1075 | MetadataList.assignValue( |
| 1076 | GET_OR_DISTINCT(DIExpression, |
| 1077 | (Context, makeArrayRef(Record).slice(1))), |
| 1078 | NextMetadataNo++); |
| 1079 | break; |
| 1080 | } |
Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 1081 | case bitc::METADATA_GLOBAL_VAR_EXPR: { |
| 1082 | if (Record.size() != 3) |
| 1083 | return error("Invalid record"); |
| 1084 | |
| 1085 | IsDistinct = Record[0]; |
| 1086 | MetadataList.assignValue(GET_OR_DISTINCT(DIGlobalVariableExpression, |
| 1087 | (Context, getMDOrNull(Record[1]), |
| 1088 | getMDOrNull(Record[2]))), |
| 1089 | NextMetadataNo++); |
| 1090 | break; |
| 1091 | } |
Mehdi Amini | ef27db8 | 2016-12-12 19:34:26 +0000 | [diff] [blame] | 1092 | case bitc::METADATA_OBJC_PROPERTY: { |
| 1093 | if (Record.size() != 8) |
| 1094 | return error("Invalid record"); |
| 1095 | |
| 1096 | IsDistinct = Record[0]; |
| 1097 | MetadataList.assignValue( |
| 1098 | GET_OR_DISTINCT(DIObjCProperty, |
| 1099 | (Context, getMDString(Record[1]), |
| 1100 | getMDOrNull(Record[2]), Record[3], |
| 1101 | getMDString(Record[4]), getMDString(Record[5]), |
| 1102 | Record[6], getDITypeRefOrNull(Record[7]))), |
| 1103 | NextMetadataNo++); |
| 1104 | break; |
| 1105 | } |
| 1106 | case bitc::METADATA_IMPORTED_ENTITY: { |
| 1107 | if (Record.size() != 6) |
| 1108 | return error("Invalid record"); |
| 1109 | |
| 1110 | IsDistinct = Record[0]; |
| 1111 | MetadataList.assignValue( |
| 1112 | GET_OR_DISTINCT(DIImportedEntity, |
| 1113 | (Context, Record[1], getMDOrNull(Record[2]), |
| 1114 | getDITypeRefOrNull(Record[3]), Record[4], |
| 1115 | getMDString(Record[5]))), |
| 1116 | NextMetadataNo++); |
| 1117 | break; |
| 1118 | } |
| 1119 | case bitc::METADATA_STRING_OLD: { |
| 1120 | std::string String(Record.begin(), Record.end()); |
| 1121 | |
| 1122 | // Test for upgrading !llvm.loop. |
| 1123 | HasSeenOldLoopTags |= mayBeOldLoopAttachmentTag(String); |
| 1124 | |
| 1125 | Metadata *MD = MDString::get(Context, String); |
| 1126 | MetadataList.assignValue(MD, NextMetadataNo++); |
| 1127 | break; |
| 1128 | } |
| 1129 | case bitc::METADATA_STRINGS: |
| 1130 | if (Error Err = parseMetadataStrings(Record, Blob, NextMetadataNo)) |
| 1131 | return Err; |
| 1132 | break; |
| 1133 | case bitc::METADATA_GLOBAL_DECL_ATTACHMENT: { |
| 1134 | if (Record.size() % 2 == 0) |
| 1135 | return error("Invalid record"); |
| 1136 | unsigned ValueID = Record[0]; |
| 1137 | if (ValueID >= ValueList.size()) |
| 1138 | return error("Invalid record"); |
| 1139 | if (auto *GO = dyn_cast<GlobalObject>(ValueList[ValueID])) |
| 1140 | if (Error Err = parseGlobalObjectAttachment( |
| 1141 | *GO, ArrayRef<uint64_t>(Record).slice(1))) |
| 1142 | return Err; |
| 1143 | break; |
| 1144 | } |
| 1145 | case bitc::METADATA_KIND: { |
| 1146 | // Support older bitcode files that had METADATA_KIND records in a |
| 1147 | // block with METADATA_BLOCK_ID. |
| 1148 | if (Error Err = parseMetadataKindRecord(Record)) |
| 1149 | return Err; |
| 1150 | break; |
| 1151 | } |
| 1152 | } |
| 1153 | } |
| 1154 | #undef GET_OR_DISTINCT |
| 1155 | } |
| 1156 | |
| 1157 | Error MetadataLoader::MetadataLoaderImpl::parseMetadataStrings( |
| 1158 | ArrayRef<uint64_t> Record, StringRef Blob, unsigned &NextMetadataNo) { |
| 1159 | // All the MDStrings in the block are emitted together in a single |
| 1160 | // record. The strings are concatenated and stored in a blob along with |
| 1161 | // their sizes. |
| 1162 | if (Record.size() != 2) |
| 1163 | return error("Invalid record: metadata strings layout"); |
| 1164 | |
| 1165 | unsigned NumStrings = Record[0]; |
| 1166 | unsigned StringsOffset = Record[1]; |
| 1167 | if (!NumStrings) |
| 1168 | return error("Invalid record: metadata strings with no strings"); |
| 1169 | if (StringsOffset > Blob.size()) |
| 1170 | return error("Invalid record: metadata strings corrupt offset"); |
| 1171 | |
| 1172 | StringRef Lengths = Blob.slice(0, StringsOffset); |
| 1173 | SimpleBitstreamCursor R(Lengths); |
| 1174 | |
| 1175 | StringRef Strings = Blob.drop_front(StringsOffset); |
| 1176 | do { |
| 1177 | if (R.AtEndOfStream()) |
| 1178 | return error("Invalid record: metadata strings bad length"); |
| 1179 | |
| 1180 | unsigned Size = R.ReadVBR(6); |
| 1181 | if (Strings.size() < Size) |
| 1182 | return error("Invalid record: metadata strings truncated chars"); |
| 1183 | |
| 1184 | MetadataList.assignValue(MDString::get(Context, Strings.slice(0, Size)), |
| 1185 | NextMetadataNo++); |
| 1186 | Strings = Strings.drop_front(Size); |
| 1187 | } while (--NumStrings); |
| 1188 | |
| 1189 | return Error::success(); |
| 1190 | } |
| 1191 | |
| 1192 | Error MetadataLoader::MetadataLoaderImpl::parseGlobalObjectAttachment( |
| 1193 | GlobalObject &GO, ArrayRef<uint64_t> Record) { |
| 1194 | assert(Record.size() % 2 == 0); |
| 1195 | for (unsigned I = 0, E = Record.size(); I != E; I += 2) { |
| 1196 | auto K = MDKindMap.find(Record[I]); |
| 1197 | if (K == MDKindMap.end()) |
| 1198 | return error("Invalid ID"); |
| 1199 | MDNode *MD = MetadataList.getMDNodeFwdRefOrNull(Record[I + 1]); |
| 1200 | if (!MD) |
| 1201 | return error("Invalid metadata attachment"); |
| 1202 | GO.addMetadata(K->second, *MD); |
| 1203 | } |
| 1204 | return Error::success(); |
| 1205 | } |
| 1206 | |
| 1207 | /// Parse metadata attachments. |
| 1208 | Error MetadataLoader::MetadataLoaderImpl::parseMetadataAttachment( |
| 1209 | Function &F, const SmallVectorImpl<Instruction *> &InstructionList) { |
| 1210 | if (Stream.EnterSubBlock(bitc::METADATA_ATTACHMENT_ID)) |
| 1211 | return error("Invalid record"); |
| 1212 | |
| 1213 | SmallVector<uint64_t, 64> Record; |
| 1214 | |
| 1215 | while (true) { |
| 1216 | BitstreamEntry Entry = Stream.advanceSkippingSubblocks(); |
| 1217 | |
| 1218 | switch (Entry.Kind) { |
| 1219 | case BitstreamEntry::SubBlock: // Handled for us already. |
| 1220 | case BitstreamEntry::Error: |
| 1221 | return error("Malformed block"); |
| 1222 | case BitstreamEntry::EndBlock: |
| 1223 | return Error::success(); |
| 1224 | case BitstreamEntry::Record: |
| 1225 | // The interesting case. |
| 1226 | break; |
| 1227 | } |
| 1228 | |
| 1229 | // Read a metadata attachment record. |
| 1230 | Record.clear(); |
| 1231 | switch (Stream.readRecord(Entry.ID, Record)) { |
| 1232 | default: // Default behavior: ignore. |
| 1233 | break; |
| 1234 | case bitc::METADATA_ATTACHMENT: { |
| 1235 | unsigned RecordLength = Record.size(); |
| 1236 | if (Record.empty()) |
| 1237 | return error("Invalid record"); |
| 1238 | if (RecordLength % 2 == 0) { |
| 1239 | // A function attachment. |
| 1240 | if (Error Err = parseGlobalObjectAttachment(F, Record)) |
| 1241 | return Err; |
| 1242 | continue; |
| 1243 | } |
| 1244 | |
| 1245 | // An instruction attachment. |
| 1246 | Instruction *Inst = InstructionList[Record[0]]; |
| 1247 | for (unsigned i = 1; i != RecordLength; i = i + 2) { |
| 1248 | unsigned Kind = Record[i]; |
| 1249 | DenseMap<unsigned, unsigned>::iterator I = MDKindMap.find(Kind); |
| 1250 | if (I == MDKindMap.end()) |
| 1251 | return error("Invalid ID"); |
Mehdi Amini | 8662305 | 2016-12-16 19:16:29 +0000 | [diff] [blame] | 1252 | if (I->second == LLVMContext::MD_tbaa && StripTBAA) |
| 1253 | continue; |
| 1254 | |
Mehdi Amini | ef27db8 | 2016-12-12 19:34:26 +0000 | [diff] [blame] | 1255 | Metadata *Node = MetadataList.getMetadataFwdRef(Record[i + 1]); |
| 1256 | if (isa<LocalAsMetadata>(Node)) |
| 1257 | // Drop the attachment. This used to be legal, but there's no |
| 1258 | // upgrade path. |
| 1259 | break; |
| 1260 | MDNode *MD = dyn_cast_or_null<MDNode>(Node); |
| 1261 | if (!MD) |
| 1262 | return error("Invalid metadata attachment"); |
| 1263 | |
| 1264 | if (HasSeenOldLoopTags && I->second == LLVMContext::MD_loop) |
| 1265 | MD = upgradeInstructionLoopAttachment(*MD); |
| 1266 | |
| 1267 | if (I->second == LLVMContext::MD_tbaa) { |
| 1268 | assert(!MD->isTemporary() && "should load MDs before attachments"); |
| 1269 | MD = UpgradeTBAANode(*MD); |
| 1270 | } |
| 1271 | Inst->setMetadata(I->second, MD); |
| 1272 | } |
| 1273 | break; |
| 1274 | } |
| 1275 | } |
| 1276 | } |
| 1277 | } |
| 1278 | |
| 1279 | /// Parse a single METADATA_KIND record, inserting result in MDKindMap. |
| 1280 | Error MetadataLoader::MetadataLoaderImpl::parseMetadataKindRecord( |
| 1281 | SmallVectorImpl<uint64_t> &Record) { |
| 1282 | if (Record.size() < 2) |
| 1283 | return error("Invalid record"); |
| 1284 | |
| 1285 | unsigned Kind = Record[0]; |
| 1286 | SmallString<8> Name(Record.begin() + 1, Record.end()); |
| 1287 | |
| 1288 | unsigned NewKind = TheModule.getMDKindID(Name.str()); |
| 1289 | if (!MDKindMap.insert(std::make_pair(Kind, NewKind)).second) |
| 1290 | return error("Conflicting METADATA_KIND records"); |
| 1291 | return Error::success(); |
| 1292 | } |
| 1293 | |
| 1294 | /// Parse the metadata kinds out of the METADATA_KIND_BLOCK. |
| 1295 | Error MetadataLoader::MetadataLoaderImpl::parseMetadataKinds() { |
| 1296 | if (Stream.EnterSubBlock(bitc::METADATA_KIND_BLOCK_ID)) |
| 1297 | return error("Invalid record"); |
| 1298 | |
| 1299 | SmallVector<uint64_t, 64> Record; |
| 1300 | |
| 1301 | // Read all the records. |
| 1302 | while (true) { |
| 1303 | BitstreamEntry Entry = Stream.advanceSkippingSubblocks(); |
| 1304 | |
| 1305 | switch (Entry.Kind) { |
| 1306 | case BitstreamEntry::SubBlock: // Handled for us already. |
| 1307 | case BitstreamEntry::Error: |
| 1308 | return error("Malformed block"); |
| 1309 | case BitstreamEntry::EndBlock: |
| 1310 | return Error::success(); |
| 1311 | case BitstreamEntry::Record: |
| 1312 | // The interesting case. |
| 1313 | break; |
| 1314 | } |
| 1315 | |
| 1316 | // Read a record. |
| 1317 | Record.clear(); |
| 1318 | unsigned Code = Stream.readRecord(Entry.ID, Record); |
| 1319 | switch (Code) { |
| 1320 | default: // Default behavior: ignore. |
| 1321 | break; |
| 1322 | case bitc::METADATA_KIND: { |
| 1323 | if (Error Err = parseMetadataKindRecord(Record)) |
| 1324 | return Err; |
| 1325 | break; |
| 1326 | } |
| 1327 | } |
| 1328 | } |
| 1329 | } |
| 1330 | |
| 1331 | MetadataLoader &MetadataLoader::operator=(MetadataLoader &&RHS) { |
| 1332 | Pimpl = std::move(RHS.Pimpl); |
| 1333 | return *this; |
| 1334 | } |
| 1335 | MetadataLoader::MetadataLoader(MetadataLoader &&RHS) |
Teresa Johnson | a61f5e3 | 2016-12-16 21:25:01 +0000 | [diff] [blame] | 1336 | : Pimpl(std::move(RHS.Pimpl)), IsImporting(RHS.IsImporting) {} |
Mehdi Amini | ef27db8 | 2016-12-12 19:34:26 +0000 | [diff] [blame] | 1337 | |
| 1338 | MetadataLoader::~MetadataLoader() = default; |
| 1339 | MetadataLoader::MetadataLoader(BitstreamCursor &Stream, Module &TheModule, |
| 1340 | BitcodeReaderValueList &ValueList, |
Teresa Johnson | a61f5e3 | 2016-12-16 21:25:01 +0000 | [diff] [blame] | 1341 | bool IsImporting, |
Mehdi Amini | ef27db8 | 2016-12-12 19:34:26 +0000 | [diff] [blame] | 1342 | std::function<Type *(unsigned)> getTypeByID) |
Nico Weber | b3901bd | 2016-12-12 22:46:40 +0000 | [diff] [blame] | 1343 | : Pimpl(llvm::make_unique<MetadataLoaderImpl>(Stream, TheModule, ValueList, |
Teresa Johnson | a61f5e3 | 2016-12-16 21:25:01 +0000 | [diff] [blame] | 1344 | getTypeByID)), |
| 1345 | IsImporting(IsImporting) {} |
Mehdi Amini | ef27db8 | 2016-12-12 19:34:26 +0000 | [diff] [blame] | 1346 | |
| 1347 | Error MetadataLoader::parseMetadata(bool ModuleLevel) { |
Teresa Johnson | a61f5e3 | 2016-12-16 21:25:01 +0000 | [diff] [blame] | 1348 | return Pimpl->parseMetadata(ModuleLevel, IsImporting); |
Mehdi Amini | ef27db8 | 2016-12-12 19:34:26 +0000 | [diff] [blame] | 1349 | } |
| 1350 | |
| 1351 | bool MetadataLoader::hasFwdRefs() const { return Pimpl->hasFwdRefs(); } |
| 1352 | |
| 1353 | /// Return the given metadata, creating a replaceable forward reference if |
| 1354 | /// necessary. |
| 1355 | Metadata *MetadataLoader::getMetadataFwdRef(unsigned Idx) { |
| 1356 | return Pimpl->getMetadataFwdRef(Idx); |
| 1357 | } |
| 1358 | |
| 1359 | MDNode *MetadataLoader::getMDNodeFwdRefOrNull(unsigned Idx) { |
| 1360 | return Pimpl->getMDNodeFwdRefOrNull(Idx); |
| 1361 | } |
| 1362 | |
| 1363 | DISubprogram *MetadataLoader::lookupSubprogramForFunction(Function *F) { |
| 1364 | return Pimpl->lookupSubprogramForFunction(F); |
| 1365 | } |
| 1366 | |
| 1367 | Error MetadataLoader::parseMetadataAttachment( |
| 1368 | Function &F, const SmallVectorImpl<Instruction *> &InstructionList) { |
| 1369 | return Pimpl->parseMetadataAttachment(F, InstructionList); |
| 1370 | } |
| 1371 | |
| 1372 | Error MetadataLoader::parseMetadataKinds() { |
| 1373 | return Pimpl->parseMetadataKinds(); |
| 1374 | } |
| 1375 | |
Mehdi Amini | 8662305 | 2016-12-16 19:16:29 +0000 | [diff] [blame] | 1376 | void MetadataLoader::setStripTBAA(bool StripTBAA) { |
| 1377 | return Pimpl->setStripTBAA(StripTBAA); |
| 1378 | } |
| 1379 | |
| 1380 | bool MetadataLoader::isStrippingTBAA() { return Pimpl->isStrippingTBAA(); } |
| 1381 | |
Mehdi Amini | ef27db8 | 2016-12-12 19:34:26 +0000 | [diff] [blame] | 1382 | unsigned MetadataLoader::size() const { return Pimpl->size(); } |
| 1383 | void MetadataLoader::shrinkTo(unsigned N) { return Pimpl->shrinkTo(N); } |