summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/IR
Commit message (Collapse)AuthorAgeFilesLines
...
* IR: Add MDNode::getDistinct()Duncan P. N. Exon Smith2015-01-071-0/+38
| | | | | | | | | | Allow distinct `MDNode`s to be explicitly created. There's no way (yet) of representing their distinctness in assembly/bitcode, however, so this still isn't first-class. Part of PR22111. llvm-svn: 225406
* IR: Add MDNode::isDistinct()Duncan P. N. Exon Smith2015-01-071-0/+27
| | | | | | | | | | | | Add API to indicate whether an `MDNode` is distinct. A distinct node is not stored in the MDNode uniquing tables, and will never be returned by `MDNode::get()`. Although distinct nodes are only currently created by uniquing collisions (when operands change), PR22111 will allow these nodes to be explicitly created. llvm-svn: 225401
* IR: Don't drop MDNode uniquing on null operandsDuncan P. N. Exon Smith2015-01-051-0/+20
| | | | | | | | | | Now that `LLVMContextImpl` can call `MDNode::dropAllReferences()` to prevent teardown madness, stop dropping uniquing just because an operand drops to null. Part of PR21532. llvm-svn: 225223
* [PM] Add names and debug logging for analysis passes to the new passChandler Carruth2015-01-051-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | manager. This starts to allow us to test analyses more easily, but it's really only the beginning. Some of the code here is still untestable without manual changes to create analysis passes, but I wanted to factor it into a small of chunks as possible. Next up in order to be able to test things are, in no particular order: - No-op analyses passes so we don't have to use real ones to exercise the pass maneger itself. - Automatic way of generating dummy passes that require an analysis be run, including a variant that calls a 'print' method on a pass to make it even easier to print out the results of an analysis. - Dummy passes that invalidate all analyses for their IR unit so we can test invalidation and re-runs. - Automatic way to print each analysis pass as it is re-run. - Automatic but optional verification of analysis passes everywhere possible. I'm not claiming I'll get to all of these immediately, but that's what is in the pipeline at some stage. I'm fleshing out exactly what I need and what to prioritize by working on converting analyses and then trying to test the conversion. =] llvm-svn: 225162
* [PM] Switch the new pass manager to use a reference-based API for IRChandler Carruth2015-01-051-15/+15
| | | | | | | | | | | | | | | | | | | | | units. This was debated back and forth a bunch, but using references is now clearly cleaner. Of all the code written using pointers thus far, in only one place did it really make more sense to have a pointer. In most cases, this just removes immediate dereferencing from the code. I think it is much better to get errors on null IR units earlier, potentially at compile time, than to delay it. Most notably, the legacy pass manager uses references for its routines and so as more and more code works with both, the use of pointers was likely to become really annoying. I noticed this when I ported the domtree analysis over and wrote the entire thing with references only to have it fail to compile. =/ It seemed better to switch now than to delay. We can, of course, revisit this is we learn that references are really problematic in the API. llvm-svn: 225145
* Fix a leak found by asan.Rafael Espindola2014-12-231-2/+3
| | | | llvm-svn: 224773
* The leak detector is dead, long live asan and valgrind.Rafael Espindola2014-12-222-32/+0
| | | | | | | In resent times asan and valgrind have found way more memory management bugs in llvm than the special purpose leak detector. llvm-svn: 224703
* Remove 'metadata' from commentsDuncan P. N. Exon Smith2014-12-161-4/+4
| | | | llvm-svn: 224328
* IR: Stop printing 'metadata' in Metadata::print()Duncan P. N. Exon Smith2014-12-161-4/+4
| | | | | | | Stop printing `metadata` in `Metadata::print()` and `Metadata::printAsOperand()`. llvm-svn: 224327
* IR: Make MDNode::dump() useful by adding addressesDuncan P. N. Exon Smith2014-12-161-0/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It's horrible to inspect `MDNode`s in a debugger. All of their operands that are `MDNode`s get dumped as `<badref>`, since we can't assign metadata slots in the context of a `Metadata::dump()`. (Why not? Why not assign numbers lazily? Because then each time you called `dump()`, a given `MDNode` could have a different lazily assigned number.) Fortunately, the C memory model gives us perfectly good identifiers for `MDNode`. Add pointer addresses to the dumps, transforming this: (lldb) e N->dump() !{i32 662302, i32 26, <badref>, null} (lldb) e ((MDNode*)N->getOperand(2))->dump() !{i32 4, !"foo"} into: (lldb) e N->dump() !{i32 662302, i32 26, <0x100706ee0>, null} (lldb) e ((MDNode*)0x100706ee0)->dump() !{i32 4, !"foo"} and this: (lldb) e N->dump() 0x101200248 = !{<badref>, <badref>, <badref>, <badref>, <badref>} (lldb) e N->getOperand(0) (const llvm::MDOperand) $0 = { MD = 0x00000001012004e0 } (lldb) e N->getOperand(1) (const llvm::MDOperand) $1 = { MD = 0x00000001012004e0 } (lldb) e N->getOperand(2) (const llvm::MDOperand) $2 = { MD = 0x0000000101200058 } (lldb) e N->getOperand(3) (const llvm::MDOperand) $3 = { MD = 0x00000001012004e0 } (lldb) e N->getOperand(4) (const llvm::MDOperand) $4 = { MD = 0x0000000101200058 } (lldb) e ((MDNode*)0x00000001012004e0)->dump() !{} (lldb) e ((MDNode*)0x0000000101200058)->dump() !{null} into: (lldb) e N->dump() !{<0x1012004e0>, <0x1012004e0>, <0x101200058>, <0x1012004e0>, <0x101200058>} (lldb) e ((MDNode*)0x1012004e0)->dump() !{} (lldb) e ((MDNode*)0x101200058)->dump() !{null} llvm-svn: 224325
* IR: Don't track nullptr on metadata RAUWDuncan P. N. Exon Smith2014-12-121-0/+47
| | | | | | | | | | | | | | | | | The RAUW support in `Metadata` supports going to `nullptr` specifically to handle values being deleted, causing `ValueAsMetadata` to be deleted. Fix the case where the reference is from a `TrackingMDRef` (as opposed to an `MDOperand` or a `MetadataAsValue`). This is surprisingly rare -- metadata tracked by `TrackingMDRef` going to null -- but it came up in an openSUSE bootstrap during inlining. The tracking ref was held by the `ValueMap` because it was referencing a local, the basic block containing the local became dead after it had been merged in, and when the local was deleted, the tracking ref asserted in an `isa`. llvm-svn: 224146
* IR: Split Metadata from ValueDuncan P. N. Exon Smith2014-12-092-24/+71
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Split `Metadata` away from the `Value` class hierarchy, as part of PR21532. Assembly and bitcode changes are in the wings, but this is the bulk of the change for the IR C++ API. I have a follow-up patch prepared for `clang`. If this breaks other sub-projects, I apologize in advance :(. Help me compile it on Darwin I'll try to fix it. FWIW, the errors should be easy to fix, so it may be simpler to just fix it yourself. This breaks the build for all metadata-related code that's out-of-tree. Rest assured the transition is mechanical and the compiler should catch almost all of the problems. Here's a quick guide for updating your code: - `Metadata` is the root of a class hierarchy with three main classes: `MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from the `Value` class hierarchy. It is typeless -- i.e., instances do *not* have a `Type`. - `MDNode`'s operands are all `Metadata *` (instead of `Value *`). - `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively. If you're referring solely to resolved `MDNode`s -- post graph construction -- just use `MDNode*`. - `MDNode` (and the rest of `Metadata`) have only limited support for `replaceAllUsesWith()`. As long as an `MDNode` is pointing at a forward declaration -- the result of `MDNode::getTemporary()` -- it maintains a side map of its uses and can RAUW itself. Once the forward declarations are fully resolved RAUW support is dropped on the ground. This means that uniquing collisions on changing operands cause nodes to become "distinct". (This already happened fairly commonly, whenever an operand went to null.) If you're constructing complex (non self-reference) `MDNode` cycles, you need to call `MDNode::resolveCycles()` on each node (or on a top-level node that somehow references all of the nodes). Also, don't do that. Metadata cycles (and the RAUW machinery needed to construct them) are expensive. - An `MDNode` can only refer to a `Constant` through a bridge called `ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`). As a side effect, accessing an operand of an `MDNode` that is known to be, e.g., `ConstantInt`, takes three steps: first, cast from `Metadata` to `ConstantAsMetadata`; second, extract the `Constant`; third, cast down to `ConstantInt`. The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have metadata schema owners transition away from using `Constant`s when the type isn't important (and they don't care about referring to `GlobalValue`s). In the meantime, I've added transitional API to the `mdconst` namespace that matches semantics with the old code, in order to avoid adding the error-prone three-step equivalent to every call site. If your old code was: MDNode *N = foo(); bar(isa <ConstantInt>(N->getOperand(0))); baz(cast <ConstantInt>(N->getOperand(1))); bak(cast_or_null <ConstantInt>(N->getOperand(2))); bat(dyn_cast <ConstantInt>(N->getOperand(3))); bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4))); you can trivially match its semantics with: MDNode *N = foo(); bar(mdconst::hasa <ConstantInt>(N->getOperand(0))); baz(mdconst::extract <ConstantInt>(N->getOperand(1))); bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2))); bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3))); bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4))); and when you transition your metadata schema to `MDInt`: MDNode *N = foo(); bar(isa <MDInt>(N->getOperand(0))); baz(cast <MDInt>(N->getOperand(1))); bak(cast_or_null <MDInt>(N->getOperand(2))); bat(dyn_cast <MDInt>(N->getOperand(3))); bay(dyn_cast_or_null<MDInt>(N->getOperand(4))); - A `CallInst` -- specifically, intrinsic instructions -- can refer to metadata through a bridge called `MetadataAsValue`. This is a subclass of `Value` where `getType()->isMetadataTy()`. `MetadataAsValue` is the *only* class that can legally refer to a `LocalAsMetadata`, which is a bridged form of non-`Constant` values like `Argument` and `Instruction`. It can also refer to any other `Metadata` subclass. (I'll break all your testcases in a follow-up commit, when I propagate this change to assembly.) llvm-svn: 223802
* IR: Drop uniquing for self-referencing MDNodesDuncan P. N. Exon Smith2014-12-071-0/+40
| | | | | | | | | | | | | | | It doesn't make sense to unique self-referencing nodes. Drop uniquing for them. Note that `MDNode::intersect()` occasionally returns self-referencing nodes. Previously these would be returned by `MDNode::get()`. I'm not convinced this was intended behaviour -- to me it seems it should return a node whose only operand is the self-reference -- but I don't know much about alias scopes so I'm preserving it for now. This is part of PR21532. llvm-svn: 223618
* IR: Remove reference to ENABLE_MDNODE_UNIQUINGDuncan P. N. Exon Smith2014-12-071-4/+0
| | | | | | | | | Apparently `MDNode` uniquing used to be optional. I suppose the configure flag must have disappeared at some point. Change the test so it actually tests uniquing, and remove the check for `ENABLE_MDNODE_UNIQUING`. llvm-svn: 223617
* Add unittest for extreme alignments.Rafael Espindola2014-10-231-0/+23
| | | | llvm-svn: 220483
* Silence a -Wcast-qual warning; NFC.Aaron Ballman2014-10-211-1/+1
| | | | llvm-svn: 220300
* Revert "Revert "DI: Fold constant arguments into a single MDString""Duncan P. N. Exon Smith2014-10-032-0/+69
| | | | | | | | | | | | | | | | | | | | | | This reverts commit r218918, effectively reapplying r218914 after fixing an Ocaml bindings test and an Asan crash. The root cause of the latter was a tightened-up check in `DILexicalBlock::Verify()`, so I'll file a PR to investigate who requires the loose check (and why). Original commit message follows. -- This patch addresses the first stage of PR17891 by folding constant arguments together into a single MDString. Integers are stringified and a `\0` character is used as a separator. Part of PR17891. Note: I've attached my testcases upgrade scripts to the PR. If I've just broken your out-of-tree testcases, they might help. llvm-svn: 219010
* Revert "DI: Fold constant arguments into a single MDString"Duncan P. N. Exon Smith2014-10-022-69/+0
| | | | | | This reverts commit r218914 while I investigate some bots. llvm-svn: 218918
* DI: Fold constant arguments into a single MDStringDuncan P. N. Exon Smith2014-10-022-0/+69
| | | | | | | | | | | | | This patch addresses the first stage of PR17891 by folding constant arguments together into a single MDString. Integers are stringified and a `\0` character is used as a separator. Part of PR17891. Note: I've attached my testcases upgrade scripts to the PR. If I've just broken your out-of-tree testcases, they might help. llvm-svn: 218914
* Add doInitialization/doFinalization to DataLayoutPass.Rafael Espindola2014-09-101-5/+5
| | | | | | | | | | | | | With this a DataLayoutPass can be reused for multiple modules. Once we have doInitialization/doFinalization, it doesn't seem necessary to pass a Module to the constructor. Overall this change seems in line with the idea of making DataLayout a required part of Module. With it the only way of having a DataLayout used is to add it to the Module. llvm-svn: 217548
* Replace a few virtual with override.Rafael Espindola2014-09-101-21/+21
| | | | llvm-svn: 217513
* Fix a logic bug when copying fast-math flags.Sanjay Patel2014-09-021-0/+4
| | | | | | | | | | | | | "Setting" does not equal "copying". This bug has sat dormant for 2 reasons: 1. The unit test was not adequate. 2. Every current user of the "copyFastMathFlags" API is operating on a new instruction. (ie, all existing fast-math flags are off). If you copy flags to an existing instruction that has some flags on already, you will not necessarily turn them off as expected. I uncovered this bug while trying to implement a fix for PR20802. llvm-svn: 216939
* Support: make LLVM Mutexes STL-compatibleDylan Noblesmith2014-08-231-2/+2
| | | | | | Use lock/unlock() convention instead of acquire/release(). llvm-svn: 216336
* IR: Fix a missed case when threading OnlyIfReduced through ConstantExprDuncan P. N. Exon Smith2014-08-191-0/+25
| | | | | | | | In r216015 I missed propagating `OnlyIfReduced` through the inline versions of `getGetElementPtr()` (I was relying on compile failures on mismatches between the header and source signatures to get them all). llvm-svn: 216023
* IR: Fix ConstantExpr::replaceUsesOfWithOnConstant()Duncan P. N. Exon Smith2014-08-191-0/+23
| | | | | | | | | | | | | Change `ConstantExpr` to follow the model the other constants are using: only malloc a replacement if it's going to be used. This fixes a subtle bug where if an API user had used `ConstantExpr::get()` already to create the replacement but hadn't given it any users, we'd delete the replacement. This relies on r216015 to thread `OnlyIfReduced` through `ConstantExpr::getWithOperands()`. llvm-svn: 216016
* Modernize the .ll parsing interface.Rafael Espindola2014-08-195-9/+8
| | | | | | | | | | * Use StringRef instead of std::string& * Return a std::unique_ptr<Module> instead of taking an optional module to write to (was not really used). * Use current comment style. * Use current naming convention. llvm-svn: 215989
* Reapply r215966, r215965, r215964, r215963, r215960, r215959, r215958, and ↵Duncan P. N. Exon Smith2014-08-191-0/+25
| | | | | | | | | | | | r215957 This reverts commit r215981, which reverted the above commits because MSVC std::equal asserts on nullptr iterators, and thes commits introduced an `ArrayRef::equals()` on empty ArrayRefs. ArrayRef was changed not to use std::equal in r215986. llvm-svn: 215987
* Reverting r215966, r215965, r215964, r215963, r215960, r215959, r215958, and ↵Aaron Ballman2014-08-191-25/+0
| | | | | | r215957 (these commits all rely on previous commits) due to build breakage. These commits cause failed assertions when testing Clang using MSVC 2013. The asserts are triggered from the std::equal call within ArrayRef::equals due to being passed invalid input (ArrayRef.begin() is returning a nullptr which is problematic). llvm-svn: 215981
* IR: Fix ConstantArray::replaceUsesOfWithOnConstant()Duncan P. N. Exon Smith2014-08-191-0/+25
| | | | | | | | Previously, `ConstantArray::replaceUsesOfWithOnConstant()` neglected to check whether it becomes a `ConstantDataArray`. Call `ConstantArray::getImpl()` to check for that. llvm-svn: 215965
* IR: Add Value::reverseUseList()Duncan P. N. Exon Smith2014-08-011-0/+43
| | | | | | I'm going to use this to improve `verify-uselistorder`. Part of PR5680. llvm-svn: 214594
* IR/UseTest.cpp: Avoid std::to_string() to appease mingw32 bot.NAKAMURA Takumi2014-07-261-5/+10
| | | | llvm-svn: 213994
* Fix r213824 on windowsDuncan P. N. Exon Smith2014-07-241-0/+2
| | | | llvm-svn: 213866
* IR: Add Value::sortUseList()Duncan P. N. Exon Smith2014-07-242-0/+63
| | | | | | | | | | | Add `Value::sortUseList()`, templated on the comparison function to use. The sort is an iterative merge sort that uses a binomial vector of already-merged lists to limit the size overhead to `O(1)`. This is part of PR5680. llvm-svn: 213824
* Revert "Replace Execution Engine's mutex with std::recursive_mutex."Zachary Turner2014-06-201-4/+4
| | | | | | | | | | This reverts commit 1f502bd9d7d2c1f98ad93a09ffe435e11a95aedd, due to GCC / MinGW's lack of support for C++11 threading. It's possible this will go back in after we come up with a reasonable solution. llvm-svn: 211401
* Fix some -Wsign-compare fallout from changing container count member ↵David Blaikie2014-06-201-10/+10
| | | | | | functions to return unsigned instead of bool. llvm-svn: 211393
* Replace Execution Engine's mutex with std::recursive_mutex.Zachary Turner2014-06-181-4/+4
| | | | | | | | | | | | | This change has a bit of a trickle down effect due to the fact that there are a number of derived implementations of ExecutionEngine, and that the mutex is not tightly encapsulated so is used by other classes directly. Reviewed by: rnk Differential Revision: http://reviews.llvm.org/D4196 llvm-svn: 211214
* Fix build breakage caused by change to ValueMapTest.Zachary Turner2014-06-171-2/+2
| | | | llvm-svn: 211083
* Expose ValueMap's mutex type as a typedef instead of a sys::Mutex.Zachary Turner2014-06-171-7/+7
| | | | | | | | This enables static polymorphism of the mutex type, which is necessary in order to replace the standard mutex implementation with a different type. llvm-svn: 211080
* [C++11] Use 'nullptr'.Craig Topper2014-06-0815-66/+66
| | | | llvm-svn: 210442
* Allow aliases to be unnamed_addr.Rafael Espindola2014-06-061-17/+0
| | | | | | | | | | | | | | | | | | Alias with unnamed_addr were in a strange state. It is stored in GlobalValue, the language reference talks about "unnamed_addr aliases" but the verifier was rejecting them. It seems natural to allow unnamed_addr in aliases: * It is a property of how it is accessed, not of the data itself. * It is perfectly possible to write code that depends on the address of an alias. This patch then makes unname_addr legal for aliases. One side effect is that the syntax changes for a corner case: In globals, unnamed_addr is now printed before the address space. llvm-svn: 210302
* Allow alias to point to an arbitrary ConstantExpr.Rafael Espindola2014-06-031-10/+0
| | | | | | | | | | | | | | | | | | | | | This patch changes GlobalAlias to point to an arbitrary ConstantExpr and it is up to MC (or the system assembler) to decide if that expression is valid or not. This reduces our ability to diagnose invalid uses and how early we can spot them, but it also lets us do things like @test5 = alias inttoptr(i32 sub (i32 ptrtoint (i32* @test2 to i32), i32 ptrtoint (i32* @bar to i32)) to i32*) An important implication of this patch is that the notion of aliased global doesn't exist any more. The alias has to encode the information needed to access it in its metadata (linkage, visibility, type, etc). Another consequence to notice is that getSection has to return a "const char *". It could return a NullTerminatedStringRef if there was such a thing, but when that was proposed the decision was to just uses "const char*" for that. llvm-svn: 210062
* Use create methods since msvc doesn't handle delegating constructors.Rafael Espindola2014-05-172-2/+2
| | | | llvm-svn: 209076
* Reduce abuse of default values in the GlobalAlias constructor.Rafael Espindola2014-05-172-4/+2
| | | | | | This is in preparation for adding an optional offset. llvm-svn: 209073
* Fix most of PR10367.Rafael Espindola2014-05-161-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch changes the design of GlobalAlias so that it doesn't take a ConstantExpr anymore. It now points directly to a GlobalObject, but its type is independent of the aliasee type. To avoid changing all alias related tests in this patches, I kept the common syntax @foo = alias i32* @bar to mean the same as now. The cases that used to use cast now use the more general syntax @foo = alias i16, i32* @bar. Note that GlobalAlias now behaves a bit more like GlobalVariable. We know that its type is always a pointer, so we omit the '*'. For the bitcode, a nice surprise is that we were writing both identical types already, so the format change is minimal. Auto upgrade is handled by looking through the casts and no new fields are needed for now. New bitcode will simply have different types for Alias and Aliasee. One last interesting point in the patch is that replaceAllUsesWith becomes smart enough to avoid putting a ConstantExpr in the aliasee. This seems better than checking and updating every caller. A followup patch will delete getAliasedGlobal now that it is redundant. Another patch will add support for an explicit offset. llvm-svn: 209007
* Change the GlobalAlias constructor to look a bit more like GlobalVariable.Rafael Espindola2014-05-161-3/+2
| | | | | | | This is part of the fix for pr10367. A GlobalAlias always has a pointer type, so just have the constructor build the type. llvm-svn: 208983
* Assert that we don't RAUW a Constant with a ConstantExpr that contains it.Rafael Espindola2014-05-131-0/+17
| | | | | | | | We already had an assert for foo->RAUW(foo), but not for something like foo->RAUW(GEP(foo)) and would go in an infinite loop trying to apply the replacement. llvm-svn: 208663
* Copy the full TailCallKind in CallInst::clone_implReid Kleckner2014-05-061-0/+33
| | | | | | | Split from the musttail inliner change. This will be covered by an opt test when the inliner change lands. llvm-svn: 208126
* Make the User::value_op_iterator a random access iterator. I had writtenChandler Carruth2014-04-172-0/+97
| | | | | | | | | this code ages ago and lost track of it. Seems worth doing though -- this thing can get called from places that would benefit from knowing that std::distance is O(1). Also add a very fledgeling unittest for Users and make sure various aspects of this seem to work reasonably. llvm-svn: 206453
* Move MDBuilder's methods out of line.Benjamin Kramer2014-04-121-0/+1
| | | | | | | Making them inline was a historical accident, they're neither hot nor templated. llvm-svn: 206109
* Untabify.NAKAMURA Takumi2014-03-271-3/+3
| | | | llvm-svn: 204916
OpenPOWER on IntegriCloud