summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/IR/MetadataTest.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* IR: Give 'DI' prefix to debug info metadataDuncan P. N. Exon Smith2015-04-291-355/+356
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Finish off PR23080 by renaming the debug info IR constructs from `MD*` to `DI*`. The last of the `DIDescriptor` classes were deleted in r235356, and the last of the related typedefs removed in r235413, so this has all baked for about a week. Note: If you have out-of-tree code (like a frontend), I recommend that you get everything compiling and tests passing with the *previous* commit before updating to this one. It'll be easier to keep track of what code is using the `DIDescriptor` hierarchy and what you've already updated, and I think you're extremely unlikely to insert bugs. YMMV of course. Back to *this* commit: I did this using the rename-md-di-nodes.sh upgrade script I've attached to PR23080 (both code and testcases) and filtered through clang-format-diff.py. I edited the tests for test/Assembler/invalid-generic-debug-node-*.ll by hand since the columns were off-by-three. It should work on your out-of-tree testcases (and code, if you've followed the advice in the previous paragraph). Some of the tests are in badly named files now (e.g., test/Assembler/invalid-mdcompositetype-missing-tag.ll should be 'dicompositetype'); I'll come back and move the files in a follow-up commit. llvm-svn: 236120
* DebugInfo: Support up to 2^16 arguments in a subprogramDuncan P. N. Exon Smith2015-04-281-0/+20
| | | | | | | | | Support up to 2^16 arguments to a function. If we do hit the limit, assert out rather than restarting at 0 as we've done historically. This fixes PR23332. A clang test will follow. llvm-svn: 235955
* Verifier: Function metadata attachments require a bodyDuncan P. N. Exon Smith2015-04-241-0/+18
| | | | | | | | Add a verifier check that only functions with bodies have metadata attachments. This should help catch bugs in frontends and transformation passes. Part of PR23340. llvm-svn: 235784
* IR: Add Function metadata attachmentsDuncan P. N. Exon Smith2015-04-241-0/+108
| | | | | | | | Add IR support for `Metadata` attachments. Assembly and bitcode support will follow shortly, but for now we just have unit tests. This is part of PR23340. llvm-svn: 235783
* DebugInfo: Gut DIDescriptorDuncan P. N. Exon Smith2015-04-161-4/+4
| | | | | | | | | | | | | | | PR23080 is almost finished. With this commit, there's no consequential API in `DIDescriptor` and its subclasses. What's left? - Default-constructed to `nullptr`. - Handy `const_cast<>` (constructed from `const`, but accessors are non-`const`). I think the safe way to catch those is to delete the classes and fix compile errors. That'll be my next step, after I delete the `DITypeRef` (etc.) wrapper around `MDTypeRef`. llvm-svn: 235069
* DebugInfo: Remove 'inlinedAt:' field from MDLocalVariableDuncan P. N. Exon Smith2015-04-151-30/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Remove 'inlinedAt:' from MDLocalVariable. Besides saving some memory (variables with it seem to be single largest `Metadata` contributer to memory usage right now in -g -flto builds), this stops optimization and backend passes from having to change local variables. The 'inlinedAt:' field was used by the backend in two ways: 1. To tell the backend whether and into what a variable was inlined. 2. To create a unique id for each inlined variable. Instead, rely on the 'inlinedAt:' field of the intrinsic's `!dbg` attachment, and change the DWARF backend to use a typedef called `InlinedVariable` which is `std::pair<MDLocalVariable*, MDLocation*>`. This `DebugLoc` is already passed reliably through the backend (as verified by r234021). This commit removes the check from r234021, but I added a new check (that will survive) in r235048, and changed the `DIBuilder` API in r235041 to require a `!dbg` attachment whose 'scope:` is in the same `MDSubprogram` as the variable's. If this breaks your out-of-tree testcases, perhaps the script I used (mdlocalvariable-drop-inlinedat.sh) will help; I'll attach it to PR22778 in a moment. llvm-svn: 235050
* DebugInfo: Make MDSubprogram::getFunction() return ConstantDuncan P. N. Exon Smith2015-04-111-17/+18
| | | | | | | | Change `MDSubprogram::getFunction()` and `MDGlobalVariable::getConstant()` to return a `Constant`. Previously, both returned `ConstantAsMetadata`. llvm-svn: 234699
* IR: Remove MDTupleTypedArrayWrapper::operator MDTuple*()Duncan P. N. Exon Smith2015-04-071-23/+23
| | | | | | | | | | | | Remove `MDTupleTypedArrayWrapper::operator MDTuple*()`, since it causes ambiguity (at least in some [1] compilers [2]) when using indexes to `MDTupleTypedArrayWrapper::operator[](unsigned)` that are convertible to (but not the same as) `unsigned`. [1]: http://lab.llvm.org:8011/builders/sanitizer-windows/builds/2308 [2]: http://lab.llvm.org:8011/builders/clang-cmake-mips/builds/4442 llvm-svn: 234326
* IR: Rename MDSubrange::getLo() to getLowerBound()Duncan P. N. Exon Smith2015-04-071-2/+2
| | | | | | | During initial review, the `lo:` field was renamed to `lowerBound:`. Make the same change to the C++ API. llvm-svn: 234267
* DebugInfo: Use MDTypeRef throughout the hierarchyDuncan P. N. Exon Smith2015-04-061-47/+54
| | | | | | | | | | | | | | Use `MDTypeRef` (etc.) in the new debug info hierarchy rather than raw `Metadata *` pointers. I rolled in a change to `DIBuilder` that looks unrelated: take `DIType` instead of `DITypeRef` as type arguments when creating variables. However, this was the simplest way to use `MDTypeRef` within the functions, and didn't require any cleanups from callers in clang (since they were all passing in `DIType`s anyway, relying on their implicit conversions to `DITypeRef`). llvm-svn: 234197
* IR: Rename replaceWithUniqued() tests from r233751Duncan P. N. Exon Smith2015-03-311-2/+2
| | | | | | | | | | | | | replaceWithUniquedUnresolved replaceWithUniquedUnresolvedChangedOperand => replaceWithUniquedResolvingOperand replaceWithUniquedChangingOperand I find the new names less confusing; they're also more accurate. Sorry for the churn. llvm-svn: 233759
* IR: Enable uniquing callbacks during MDNode::replaceWithUniqued()Duncan P. N. Exon Smith2015-03-311-0/+42
| | | | | | | | | | | | | | | | Uniqued nodes have more complete registration with `ReplaceableMetadataImpl` so that they can update themselves when operands change. Fix a bug where `MDNode::replaceWithUniqued()` wasn't enabling these callbacks. The two most obvious ways missing callbacks causes problems is that auto-resolution fails and re-uniquing (on changed operands) just doesn't happen. I've added tests for both -- in both cases, I confirmed that the final check was failing before the fix. rdar://problem/20365935 llvm-svn: 233751
* Verifier: Add operand checks for remaining debug infoDuncan P. N. Exon Smith2015-03-301-22/+25
| | | | llvm-svn: 233565
* Verifier: Add operand checks for MDLexicalBlockDuncan P. N. Exon Smith2015-03-301-8/+11
| | | | | | | | | | Add operand checks for `MDLexicalBlock` and `MDLexicalBlockFile`. Like `MDLocalVariable` and `MDLocation`, these nodes always require a scope. There was no test bitrot to fix here (just updated the serialization tests in test/Assembler/mdlexicalblock.ll). llvm-svn: 233561
* Verifier: Check operands of MDSubprogram nodesDuncan P. N. Exon Smith2015-03-301-41/+50
| | | | | | | | | | | Check operands of `MDSubprogram`s in the verifier, and update the accessors and factory functions to use more specific types. There were a lot of broken testcases, which I fixed in r233466. If you have out-of-tree tests for debug info, you probably need similar changes to the ones I made there. llvm-svn: 233559
* Verifier: Check operands of MDType subclasses and MDCompileUnitDuncan P. N. Exon Smith2015-03-271-70/+76
| | | | | | | | | | | | | | | | | Add verify checks for `MDType` subclasses and for `MDCompileUnit`. These new checks don't yet incorporate everything from `Verify()`, but at least they sanity check the operands. Also downcast accessors as possible. A lot of these accessors can't be downcast as far as we'd like because of arrays of typed objects (stored in a generic `MDTuple`) and `MDString`-based type references. Eventually I'll port over `DIRef<>` and `DITypedArray<>` from `DebugInfo.h` to clean those up as well. Updated bitrotted testcases separately in r233415 and r233443 to reduce churn on the off-chance this needs to be reverted. llvm-svn: 233446
* Verifier: Check fields of MDVariable subclassesDuncan P. N. Exon Smith2015-03-271-22/+45
| | | | | | | | | | | | | | | | Check fields from `MDLocalVariable` and `MDGlobalVariable` and change the accessors to downcast to the right types. `getType()` still returns `Metadata*` since it could be an `MDString`-based reference. Since local variables require non-null scopes, I also updated `LLParser` to require a `scope:` field. A number of testcases had grown bitrot and started failing with this patch; I committed them separately in r233349. If I just broke your out-of-tree testcases, you're probably hitting similar problems (so have a look there). llvm-svn: 233389
* Verifier: Check accessors of MDLocationDuncan P. N. Exon Smith2015-03-261-2/+8
| | | | | | | | | | | | | | | | | | | | Check accessors of `MDLocation`, and change them to `cast<>` down to the right types. Also add type-safe factory functions. All the callers that handle broken code need to use the new versions of the accessors (`getRawScope()` instead of `getScope()`) that still return `Metadata*`. This is also necessary for things like `MDNodeKeyImpl<MDLocation>` (in LLVMContextImpl.h) that need to unique the nodes when their operands might still be forward references of the wrong type. In the `Value` hierarchy, consumers that handle broken code use `getOperand()` directly. However, debug info nodes have a ton of operands, and their order (even their existence) isn't stable yet. It's safer and more maintainable to add an explicit "raw" accessor on the class itself. llvm-svn: 233322
* AsmWriter: Handle broken metadata nodesDuncan P. N. Exon Smith2015-03-161-0/+16
| | | | | | | Print out temporary `MDNode`s so we don't crash in the verifier (or during `dump()` output). llvm-svn: 232417
* IR: Make Metadata::print() reliable and usefulDuncan P. N. Exon Smith2015-03-141-1/+84
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Replumb the `AsmWriter` so that `Metadata::print()` is generally useful. (Similarly change `Metadata::printAsOperand()`.) - `SlotTracker` now has a mode where all metadata will be correctly numbered when initializing a `Module`. Normally, `Metadata` only referenced from within `Function`s gets numbered when the `Function` is incorporated. - `Metadata::print()` and `Metadata::printAsOperand()` (and `Metadata::dump()`) now take an optional `Module` argument. When provided, `SlotTracker` is initialized with the new mode, and the numbering will be complete and consistent for all calls to `print()`. - `Value::print()` uses the new `SlotTracker` mode when printing intrinsics with `MDNode` operands, `MetadataAsValue` operands, or the bodies of functions. Thus, metadata numbering will be consistent between calls to `Metadata::print()` and `Value::print()`. - `Metadata::print()` (and `Metadata::dump()`) now print the full definition of `MDNode`s: !5 = !{!6, !"abc", !7} This matches behaviour for `Value::print()`, which includes the name of instructions. - Updated call sites in `Verifier` to call `print()` instead of `printAsOperand()`. All this, so that `Verifier` can print out useful failure messages that involve `Metadata` for PR22777. Note that `Metadata::printAsOperand()` previously took an optional `bool` and `Module` operand. The former was cargo-culted from `Value::printAsOperand()` and wasn't doing anything useful. The latter didn't give consistent results (without the new `SlotTracker` mode). llvm-svn: 232275
* IR: Add missing API to specialized metadata nodesDuncan P. N. Exon Smith2015-03-031-1/+59
| | | | | | | | | | | | | | | | | | | Add the final bits of API that `DIBuilder` needs before the new nodes can be moved into place. - Add `MDType::clone()` and `MDType::setFlags()` to support `DIBuilder::createTypeWithFlags()`. - Add `MDBasicType::get()` overload that just requires a tag and a name, as a convenience for `DIBuilder::createUnspecifiedType()`. - Add `MDLocalVariable::withInline()` and `MDLocalVariable::withoutInline()` to support `llvm::createInlinedVariable()` and `llvm::cleanseInlinedVariable()`. (Somehow these got lost inside the "move into place" patch I'm about to commit -- better to commit separately!) llvm-svn: 231079
* IR: Specialize MDScope::getFile() for MDFileDuncan P. N. Exon Smith2015-02-281-0/+6
| | | | | | | | | | Fix `MDScope::getFile()` so that it correctly returns a valid `MDFile` even when it's an instance of `MDFile`. This logic is necessary because of r230057. I'm working on moving the new hierarchy into place out-of-tree (on track to commit Monday morning, BTW), and this was exposed by a few failing tests. llvm-svn: 230871
* IR: Drop newline from AssemblyWriter::printMDNodeBody()Duncan P. N. Exon Smith2015-02-251-1/+1
| | | | | | | | | | | Remove a newline from `AssemblyWriter::printMDNodeBody()`, and add one to `AssemblyWriter::writeMDNode()`. NFCI for assembly output. However, this drops an inconsistent newline from `Metadata::print()` when `this` is an `MDNode`. Now the newline added by `Metadata::dump()` won't look so verbose. llvm-svn: 230565
* IR: Fix MDType fields from unsigned to uint64_tDuncan P. N. Exon Smith2015-02-191-6/+53
| | | | | | | | | When trying to match the current schema with the new debug info hierarchy, I downgraded `SizeInBits`, `AlignInBits` and `OffsetInBits` to 32-bits (oops!). Caught this while testing my upgrade script to move the hierarchy into place. Bump it back up to 64-bits and update tests. llvm-svn: 229933
* IR: Add missing null operand to MDSubroutineTypeDuncan P. N. Exon Smith2015-02-191-0/+9
| | | | | | | | | Add missing `nullptr` from `MDSubroutineType`'s operands for `MDCompositeTypeBase::getIdentifier()` (and add tests for all the other unused fields). This highlights just how crazy it is that `MDSubroutineType` inherits from `MDCompositeTypeBase`. llvm-svn: 229926
* IR: Drop scope from MDTemplateParameterDuncan P. N. Exon Smith2015-02-191-21/+13
| | | | | | | | | | Follow-up to r229740, which removed `DITemplate*::getContext()` after my upgrade script revealed that scopes are always `nullptr` for template parameters. This is the other shoe: drop `scope:` from `MDTemplateParameter` and its two subclasses. (Note: a bitcode upgrade would be pointless, since the hierarchy hasn't been moved into place.) llvm-svn: 229791
* IR: Allow MDSubrange to have 'count: -1'Duncan P. N. Exon Smith2015-02-181-0/+8
| | | | | | | | | | | | | | It turns out that `count: -1` is a special value indicating an empty array, such as `Values` in: struct T { unsigned Count; int Values[]; }; Handle it. llvm-svn: 229769
* IR: Add MDCompositeTypeBase::replace*()Duncan P. N. Exon Smith2015-02-181-0/+41
| | | | | | | | | Add `replaceElements()`, `replaceVTableHolder()`, and `replaceTemplateParams()` to `MDCompositeTypeBase`. Included an assertion in `replaceElements()` to match the one in `DICompositeType::replaceArrays()`. llvm-svn: 229744
* IR: Add MDCompileUnit::replace*()Duncan P. N. Exon Smith2015-02-181-0/+32
| | | | | | | Add `MDCompileUnit::replaceGlobalVariables()` and `MDCompileUnit::replaceSubprograms()`. llvm-svn: 229743
* IR: Add MDSubprogram::replaceFunction()Duncan P. N. Exon Smith2015-02-181-0/+37
| | | | llvm-svn: 229742
* IR: Add missing clone() overloadsDuncan P. N. Exon Smith2015-02-171-0/+60
| | | | | | | | | | Add missing specialized node overloads for `MDNode::clone()` (they were on most of the node types already, but missing from the others). `MDNode::clone()` returns `TempMDNode` (`std::unique_ptr<MDNode,...>`), while `TempMDSubrange::clone()` (for example) returns the more convenient `TempMDSubrange` (`std::unique_ptr<TempMDSubrange,...>`). llvm-svn: 229579
* IR: Add MDExpression::ExprOperandDuncan P. N. Exon Smith2015-02-131-0/+36
| | | | | | | | Port `DIExpression::Operand` over to `MDExpression::ExprOperand`. The logic is needed directly in `MDExpression` to support printing in assembly. llvm-svn: 229002
* IR: Add MDNode::replaceWithPermanent()Duncan P. N. Exon Smith2015-02-101-0/+38
| | | | | | | | | | | | | | | | Add new API for converting temporaries that may self-reference. Self-referencing nodes are not allowed to be uniqued, so sending them into `replaceWithUniqued()` is dangerous (and this commit adds assertions that prevent it). `replaceWithPermanent()` has similar semantics to `get()` followed by calls to `replaceOperandWith()`. In particular, if there's a self-reference, it returns a distinct node; otherwise, it returns a uniqued one. Like `replaceWithUniqued()` and `replaceWithDistinct()` (well, it calls out to them) it mutates the temporary node in place if possible, only calling `replaceAllUsesWith()` on a uniquing collision. llvm-svn: 228726
* IR: Remove unnecessary fields from MDTemplateParameterDuncan P. N. Exon Smith2015-02-101-46/+17
| | | | | | | | I noticed this fields were never used in r228607, but I neglected to propagate that into `MDTemplateParameter` until now. This really should have been done before commit in r228640; sorry for the churn. llvm-svn: 228652
* IR: Add accessors to MDExpressionDuncan P. N. Exon Smith2015-02-101-0/+7
| | | | | | Add some accessors to `MDExpression`. llvm-svn: 228648
* IR: Add specialized debug info metadata nodesDuncan P. N. Exon Smith2015-02-101-0/+847
| | | | | | | | | | | | | | | Add specialized debug info metadata nodes that match the `DIDescriptor` wrappers (used by `DIBuilder`) closely. Assembly and bitcode support to follow soon (it'll mostly just be obvious), but this sketches in today's schema. This is the first big commit (well, the only *big* one aside from the testcase changes that'll come when I move this into place) for PR22464. I've marked a bunch of obvious changes as `TODO`s in the source; I plan to make those changes promptly after this hierarchy is moved underneath `DIDescriptor`, but for now I'm aiming mostly to match the status quo. llvm-svn: 228640
* IR: Allow 32-bits for lines in debug locationDuncan P. N. Exon Smith2015-02-061-7/+6
| | | | | | | | | | | | Remove unnecessary restriction of 24-bits for line numbers in `MDLocation`. The rest of the debug info schema (with the exception of local variables) uses 32-bits for line numbers. As I introduce the specialized nodes, it makes sense to canonicalize on one size or the other. llvm-svn: 228455
* IR: Split out DebugInfoMetadata.h, NFCDuncan P. N. Exon Smith2015-02-021-0/+1
| | | | | | | | | Move debug-info-centred `Metadata` subclasses into their own header/source file. A couple of private template functions are needed from both `Metadata.cpp` and `DebugInfoMetadata.cpp`, so I've moved them to `lib/IR/MetadataImpl.h`. llvm-svn: 227835
* Fix some file headers, NFCDuncan P. N. Exon Smith2015-02-021-1/+1
| | | | llvm-svn: 227826
* IR: Change GenericDwarfNode::getHeader() to StringRefDuncan P. N. Exon Smith2015-01-221-6/+5
| | | | | | | Simplify the API to use a `StringRef` directly rather than exposing the `MDString` bits underneath. llvm-svn: 226876
* IR: DwarfNode => DebugNode, NFCDuncan P. N. Exon Smith2015-01-221-8/+8
| | | | | | | | | These things are potentially used for non-DWARF data (see the discussion in PR22235), so take the `Dwarf` out of the name. Since the new name gives fewer clues, update the doxygen to properly describe what they are. llvm-svn: 226874
* IR: Update references to temporaries before deletingDuncan P. N. Exon Smith2015-01-221-0/+11
| | | | | | | | | | | | | | | | During `MDNode::deleteTemporary()`, call `replaceAllUsesWith(nullptr)` to update all tracking references to `nullptr`. This fixes PR22280, where inverted destruction order between tracking references and the temporaries themselves caused a use-after-free in `LLParser`. An alternative fix would be to add an assertion that there are no users, and continue to fix inverted destruction order in clients (like `LLParser`), but instead I decided to make getting-teardown-right easy. (If someone disagrees let me know.) llvm-svn: 226866
* IR: Canonicalize GenericDwarfNode empty headers to nullDuncan P. N. Exon Smith2015-01-201-0/+8
| | | | llvm-svn: 226532
* IR: Introduce GenericDwarfNodeDuncan P. N. Exon Smith2015-01-201-0/+35
| | | | | | | | | | | | As part of PR22235, introduce `DwarfNode` and `GenericDwarfNode`. The former is a metadata node with a DWARF tag. The latter matches our current (generic) schema of a header with string (and stringified integer) data and an arbitrary number of operands. This doesn't move it into place yet; that change will require a large number of testcase updates. llvm-svn: 226529
* IR: Allow temporary nodes to become uniqued or distinctDuncan P. N. Exon Smith2015-01-191-0/+79
| | | | | | | | | | | Add `MDNode::replaceWithUniqued()` and `MDNode::replaceWithDistinct()`, which mutate temporary nodes to become uniqued or distinct. On uniquing collisions, the unique version is returned and the node is deleted. This takes advantage of temporary nodes being folded back in, and should let me clean up some awkward logic in `MapMetadata()`. llvm-svn: 226510
* IR: Return unique_ptr from MDNode::getTemporary()Duncan P. N. Exon Smith2015-01-191-32/+22
| | | | | | | | | | | | Change `MDTuple::getTemporary()` and `MDLocation::getTemporary()` to return (effectively) `std::unique_ptr<T, MDNode::deleteTemporary>`, and clean up call sites. (For now, `DIBuilder` call sites just call `release()` immediately.) There's an accompanying change in each of clang and polly to use the new API. llvm-svn: 226504
* IR: Add MDLocation::getTemporary()Duncan P. N. Exon Smith2015-01-191-0/+8
| | | | llvm-svn: 226502
* IR: Remove MDNodeFwdDeclDuncan P. N. Exon Smith2015-01-191-16/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Remove `MDNodeFwdDecl` (as promised in r226481). Aside from API changes, there's no real functionality change here. `MDNode::getTemporary()` now forwards to `MDTuple::getTemporary()`, which returns a tuple with `isTemporary()` equal to true. The main point is that we can now add temporaries of other `MDNode` subclasses, needed for PR22235 (I introduced `MDNodeFwdDecl` in the first place because I didn't recognize this need, and thought they were only needed to handle forward references). A few things left out of (or highlighted by) this commit: - I've had to remove the (few) uses of `std::unique_ptr<>` to deal with temporaries, since the destructor is no longer public. `getTemporary()` should probably return the equivalent of `std::unique_ptr<T, MDNode::deleteTemporary>`. - `MDLocation::getTemporary()` doesn't exist yet (worse, it actually does exist, but does the wrong thing: `MDNode::getTemporary()` is inherited and returns an `MDTuple`). - `MDNode` now only has one subclass, `UniquableMDNode`, and the distinction between them is actually somewhat confusing. I'll fix those up next. llvm-svn: 226501
* IR: Store RAUW support and Context in the same pointer, NFCDuncan P. N. Exon Smith2015-01-191-0/+37
| | | | | | | | | | | | | | Add an `LLVMContext &` to `ReplaceableMetadataImpl`, create a class that either holds a reference to an `LLVMContext` or owns a `ReplaceableMetadataImpl`, and use the new class in `MDNode`. - This saves a pointer in `UniquableMDNode` at the cost of a pointer in `ValueAsMetadata` (which didn't used to store the `LLVMContext`). There are far more of the former. - Unifies RAUW support between `MDNodeFwdDecl` (which is going away, see r226481) and `UniquableMDNode`. llvm-svn: 226484
* IR: Add isUniqued() and isTemporary()Duncan P. N. Exon Smith2015-01-191-3/+27
| | | | | | | | Change `MDNode::isDistinct()` to only apply to 'distinct' nodes (not temporaries), and introduce `MDNode::isUniqued()` and `MDNode::isTemporary()` for the other two possibilities. llvm-svn: 226482
OpenPOWER on IntegriCloud