1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00
Commit Graph

428 Commits

Author SHA1 Message Date
Duncan P. N. Exon Smith
e0106d31c8 Assembler: Rewrite test for function-local metadata
This test for function-local metadata did strange things, and never
really sent in valid arguments for `llvm.dbg.declare` and
`llvm.dbg.value` intrinsics.  Those that might have once been valid have
bitrotted.

Rewrite it to be a targeted test for function-local metadata --
unrelated to debug info, which is tested elsewhere -- and rename it to
better match other metadata-related tests.

(Note: the scope of function-local metadata changed drastically during
the metadata/value split, but I didn't properly clean up this testcase.
Most of the IR in this file, while invalid for debug info intrinsics,
used to provide coverage for various (now illegal) forms of
function-local metadata.)

llvm-svn: 232290
2015-03-15 00:45:51 +00:00
Duncan P. N. Exon Smith
4326380356 AsmWriter: Write alloca array size explicitly (and -instcombine fixup)
Write the `alloca` array size explicitly when it's non-canonical.
Previously, if the array size was `iX 1` (where X is not 32), the type
would mutate to `i32` when round-tripping through assembly.

The testcase I added fails in `verify-uselistorder` (as well as
`FileCheck`), since the use-lists for `i32 1` and `i64 1` change.
(Manman Ren came across this when running `verify-uselistorder` on some
non-trivial, optimized code as part of PR5680.)

The type mutation started with r104911, which allowed array sizes to be
something other than an `i32`.  Starting with r204945, we
"canonicalized" to `i64` on 64-bit platforms -- and then on every
round-trip through assembly, mutated back to `i32`.

I bundled a fixup for `-instcombine` to avoid r204945 on scalar
allocations.  (There wasn't a clean way to sequence this into two
commits, since the assembly change on its own caused testcase churn, and
the `-instcombine` change can't be tested without the assembly changes.)

An obvious alternative fix -- change `AllocaInst::AllocaInst()`,
`AsmWriter` and `LLParser` to treat `intptr_t` as the canonical type for
scalar allocations -- was rejected out of hand, since this required
teaching them each about the data layout.

A follow-up commit will add an `-instcombine` to canonicalize the scalar
allocation array size to `i32 1` rather than leaving `iX 1` alone.

rdar://problem/20075773

llvm-svn: 232200
2015-03-13 19:30:44 +00:00
David Blaikie
3ea2df7c7b [opaque pointer type] Add textual IR support for explicit type parameter to gep operator
Similar to gep (r230786) and load (r230794) changes.

Similar migration script can be used to update test cases, which
successfully migrated all of LLVM and Polly, but about 4 test cases
needed manually changes in Clang.

(this script will read the contents of stdin and massage it into stdout
- wrap it in the 'apply.sh' script shown in previous commits + xargs to
apply it over a large set of test cases)

import fileinput
import sys
import re

rep = re.compile(r"(getelementptr(?:\s+inbounds)?\s*\()((<\d*\s+x\s+)?([^@]*?)(|\s*addrspace\(\d+\))\s*\*(?(3)>)\s*)(?=$|%|@|null|undef|blockaddress|getelementptr|addrspacecast|bitcast|inttoptr|zeroinitializer|<|\[\[[a-zA-Z]|\{\{)", re.MULTILINE | re.DOTALL)

def conv(match):
  line = match.group(1)
  line += match.group(4)
  line += ", "
  line += match.group(2)
  return line

line = sys.stdin.read()
off = 0
for match in re.finditer(rep, line):
  sys.stdout.write(line[off:match.start()])
  sys.stdout.write(conv(match))
  off = match.end()
sys.stdout.write(line[off:])

llvm-svn: 232184
2015-03-13 18:20:45 +00:00
Owen Anderson
a93b443224 Fix a stack overflow in the assembler when checking that GEPs must be over sized types.
We failed to use a marking set to properly handle recursive types, which caused use
to recurse infinitely and eventually overflow the stack.

llvm-svn: 231760
2015-03-10 06:34:57 +00:00
David Blaikie
d9778583bf LLParser: gep: Simplify parsing error handling
llvm-svn: 231722
2015-03-09 23:08:44 +00:00
Owen Anderson
b3274a3484 Fix a bug in the LLParser where we failed to diagnose landingpads with non-constant clause operands.
Fixing this also exposed a related issue where the landingpad under construction was not
cleaned up when an error was raised, which would cause bad reference errors before the
error could actually be printed.

llvm-svn: 231634
2015-03-09 07:13:42 +00:00
Duncan P. N. Exon Smith
8d1b74869c DebugInfo: Move new hierarchy into place
Move the specialized metadata nodes for the new debug info hierarchy
into place, finishing off PR22464.  I've done bootstraps (and all that)
and I'm confident this commit is NFC as far as DWARF output is
concerned.  Let me know if I'm wrong :).

The code changes are fairly mechanical:

  - Bumped the "Debug Info Version".
  - `DIBuilder` now creates the appropriate subclass of `MDNode`.
  - Subclasses of DIDescriptor now expect to hold their "MD"
    counterparts (e.g., `DIBasicType` expects `MDBasicType`).
  - Deleted a ton of dead code in `AsmWriter.cpp` and `DebugInfo.cpp`
    for printing comments.
  - Big update to LangRef to describe the nodes in the new hierarchy.
    Feel free to make it better.

Testcase changes are enormous.  There's an accompanying clang commit on
its way.

If you have out-of-tree debug info testcases, I just broke your build.

  - `upgrade-specialized-nodes.sh` is attached to PR22564.  I used it to
    update all the IR testcases.
  - Unfortunately I failed to find way to script the updates to CHECK
    lines, so I updated all of these by hand.  This was fairly painful,
    since the old CHECKs are difficult to reason about.  That's one of
    the benefits of the new hierarchy.

This work isn't quite finished, BTW.  The `DIDescriptor` subclasses are
almost empty wrappers, but not quite: they still have loose casting
checks (see the `RETURN_FROM_RAW()` macro).  Once they're completely
gutted, I'll rename the "MD" classes to "DI" and kill the wrappers.  I
also expect to make a few schema changes now that it's easier to reason
about everything.

llvm-svn: 231082
2015-03-03 17:24:31 +00:00
Owen Anderson
f9f1328955 Cleanup after r230934 per Dave's suggestions.
llvm-svn: 231056
2015-03-03 05:39:27 +00:00
Owen Anderson
e464d46ff1 Teach DataLayout that alignments on basic types must be powers of two.
Fixes assertion failures/crashes on bad datalayout specifications.

llvm-svn: 230940
2015-03-02 09:35:03 +00:00
Owen Anderson
f1ccd9db94 Teach DataLayout that ABI alignments for non-aggregate types must be non-zero.
This manifested as assertions and/or crashes in later phases of optimization,
depending on the build configuration.

llvm-svn: 230939
2015-03-02 09:34:59 +00:00
Owen Anderson
9691e92c81 Teach DataLayout that pointer ABI and preferred alignments are required to be powers of two.
Previously this resulted in asserts and/or crashes (depending on build configuration) at various phases in the optimizer.

llvm-svn: 230938
2015-03-02 06:33:51 +00:00
Owen Anderson
22efff3c98 Teach DataLayout that zero-byte pointer sizes don't make sense.
Previously this would result in assertion failures or simply crashes
at various points in the optimizer when trying to create types of zero
bit width.

llvm-svn: 230936
2015-03-02 06:00:02 +00:00
Owen Anderson
39b32da21b Teach the LLParser to fail gracefully when it encounters an invalid label name.
Previous it would either assert in +Asserts, or crash in -Asserts. Found by fuzzing LLParser.

llvm-svn: 230935
2015-03-02 05:25:09 +00:00
Owen Anderson
93f8351a0a Fix a crash in the LL parser where it failed to validate that the pointer operand of a GEP was valid.
This manifested as an assertion failure in +Asserts builds, and a hard crash in -Asserts builds.  Found by fuzzing the LL parser.

llvm-svn: 230934
2015-03-02 05:25:06 +00:00
Duncan P. N. Exon Smith
a2835fc0fd Optimize metadata node fields for CHECK-ability
While gaining practical experience hand-updating CHECK lines (for moving
the new debug info hierarchy into place),  I learnt a few things about
CHECK-ability of the specialized node assembly output.

  - The first part of a `CHECK:` is to identify the "right" node (this
    is especially true if you intend to use the new `CHECK-SAME`
    feature, since the first CHECK needs to identify the node correctly
    before you can split the line).
      - If there's a `tag:`, it should go first.
      - If there's a `name:`, it should go next (followed by the
        `linkageName:`, if any).
      - If there's a `scope:`, it should follow after that.
  - When a node type supports multiple DW_TAGs, but one is implied by
    its name and is overwhelmingly more common, the `tag:` field is
    terribly uninteresting unless it's different.
      - `MDBasicType` is almost always `DW_TAG_base_type`.
      - `MDTemplateValueParameter` is almost always
        `DW_TAG_template_value_parameter`.
  - Printing `name: ""` doesn't improve CHECK-ability, and there are far
    more nodes than I realized that are commonly nameless.
  - There are a few other fields that similarly aren't very interesting
    when they're empty.

This commit updates the `AsmWriter` as suggested above (and makes
necessary changes in `LLParser` for round-tripping).

llvm-svn: 230877
2015-02-28 23:21:38 +00:00
Duncan P. N. Exon Smith
75f598d216 AsmWriter: Escape string fields in metadata
Properly escape string fields in metadata.  I've added a spot-check with
direct coverage for `MDFile::getFilename()`, but we'll get more coverage
once the hierarchy is moved into place (since this comes up in various
checked-in testcases).

I've replicated the `if` logic using the `ShouldSkipEmpty` flag
(although a follow-up commit is going to change how often this flag is
specified); no NFCI other than escaping the string fields.

llvm-svn: 230875
2015-02-28 22:20:16 +00:00
David Blaikie
ab043ff680 [opaque pointer type] Add textual IR support for explicit type parameter to load instruction
Essentially the same as the GEP change in r230786.

A similar migration script can be used to update test cases, though a few more
test case improvements/changes were required this time around: (r229269-r229278)

import fileinput
import sys
import re

pat = re.compile(r"((?:=|:|^)\s*load (?:atomic )?(?:volatile )?(.*?))(| addrspace\(\d+\) *)\*($| *(?:%|@|null|undef|blockaddress|getelementptr|addrspacecast|bitcast|inttoptr|\[\[[a-zA-Z]|\{\{).*$)")

for line in sys.stdin:
  sys.stdout.write(re.sub(pat, r"\1, \2\3*\4", line))

Reviewers: rafael, dexonsmith, grosser

Differential Revision: http://reviews.llvm.org/D7649

llvm-svn: 230794
2015-02-27 21:17:42 +00:00
David Blaikie
0d99339102 [opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction
One of several parallel first steps to remove the target type of pointers,
replacing them with a single opaque pointer type.

This adds an explicit type parameter to the gep instruction so that when the
first parameter becomes an opaque pointer type, the type to gep through is
still available to the instructions.

* This doesn't modify gep operators, only instructions (operators will be
  handled separately)

* Textual IR changes only. Bitcode (including upgrade) and changing the
  in-memory representation will be in separate changes.

* geps of vectors are transformed as:
    getelementptr <4 x float*> %x, ...
  ->getelementptr float, <4 x float*> %x, ...
  Then, once the opaque pointer type is introduced, this will ultimately look
  like:
    getelementptr float, <4 x ptr> %x
  with the unambiguous interpretation that it is a vector of pointers to float.

* address spaces remain on the pointer, not the type:
    getelementptr float addrspace(1)* %x
  ->getelementptr float, float addrspace(1)* %x
  Then, eventually:
    getelementptr float, ptr addrspace(1) %x

Importantly, the massive amount of test case churn has been automated by
same crappy python code. I had to manually update a few test cases that
wouldn't fit the script's model (r228970,r229196,r229197,r229198). The
python script just massages stdin and writes the result to stdout, I
then wrapped that in a shell script to handle replacing files, then
using the usual find+xargs to migrate all the files.

update.py:
import fileinput
import sys
import re

ibrep = re.compile(r"(^.*?[^%\w]getelementptr inbounds )(((?:<\d* x )?)(.*?)(| addrspace\(\d\)) *\*(|>)(?:$| *(?:%|@|null|undef|blockaddress|getelementptr|addrspacecast|bitcast|inttoptr|\[\[[a-zA-Z]|\{\{).*$))")
normrep = re.compile(       r"(^.*?[^%\w]getelementptr )(((?:<\d* x )?)(.*?)(| addrspace\(\d\)) *\*(|>)(?:$| *(?:%|@|null|undef|blockaddress|getelementptr|addrspacecast|bitcast|inttoptr|\[\[[a-zA-Z]|\{\{).*$))")

def conv(match, line):
  if not match:
    return line
  line = match.groups()[0]
  if len(match.groups()[5]) == 0:
    line += match.groups()[2]
  line += match.groups()[3]
  line += ", "
  line += match.groups()[1]
  line += "\n"
  return line

for line in sys.stdin:
  if line.find("getelementptr ") == line.find("getelementptr inbounds"):
    if line.find("getelementptr inbounds") != line.find("getelementptr inbounds ("):
      line = conv(re.match(ibrep, line), line)
  elif line.find("getelementptr ") != line.find("getelementptr ("):
    line = conv(re.match(normrep, line), line)
  sys.stdout.write(line)

apply.sh:
for name in "$@"
do
  python3 `dirname "$0"`/update.py < "$name" > "$name.tmp" && mv "$name.tmp" "$name"
  rm -f "$name.tmp"
done

The actual commands:
From llvm/src:
find test/ -name *.ll | xargs ./apply.sh
From llvm/src/tools/clang:
find test/ -name *.mm -o -name *.m -o -name *.cpp -o -name *.c | xargs -I '{}' ../../apply.sh "{}"
From llvm/src/tools/polly:
find test/ -name *.ll | xargs ./apply.sh

After that, check-all (with llvm, clang, clang-tools-extra, lld,
compiler-rt, and polly all checked out).

The extra 'rm' in the apply.sh script is due to a few files in clang's test
suite using interesting unicode stuff that my python script was throwing
exceptions on. None of those files needed to be migrated, so it seemed
sufficient to ignore those cases.

Reviewers: rafael, dexonsmith, grosser

Differential Revision: http://reviews.llvm.org/D7636

llvm-svn: 230786
2015-02-27 19:29:02 +00:00
Duncan P. N. Exon Smith
3eb494d1b9 llvm-dis: Stop crashing when dropping debug info
Since r199356, we've printed a warning when dropping debug info.
r225562 started crashing on that, since it registered a diagnostic
handler that only expected errors.  This fixes the handler to expect
other severities.  As a side effect, it now prints "error: " at the
start of error messages, similar to `llvm-as`.

There was a testcase for r199356, but it only really checked the
assembler.  Move `test/Bitcode/drop-debug-info.ll` to `test/Assembler`,
and introduce `test/Bitcode/drop-debug-info.3.5.ll` (and companion
`.bc`) to test the bitcode reader.

Note: tools/gold/gold-plugin.cpp has an equivalent bug, but I'm not sure
what the best fix is there.  I'll file a PR.

llvm-svn: 230416
2015-02-25 01:10:03 +00:00
David Majnemer
c9335a127a AsmParser: Check ConstantExpr insertvalue operands for type correctness
llvm-svn: 230206
2015-02-23 07:13:52 +00:00
David Majnemer
5ce7bb3582 AsmParser: Call instructions can't have an alignment
llvm-svn: 230193
2015-02-23 00:01:32 +00:00
David Majnemer
fe7d978682 AsmParser: Check ConstantExpr GEP operands for validity
llvm-svn: 230188
2015-02-22 23:14:52 +00:00
Duncan P. N. Exon Smith
f111dd5556 AsmParser/Writer: Handle symbolic constants in DI 'flags:'
Parse (and write) symbolic constants in debug info `flags:` fields.
This prevents a readability (and CHECK-ability) regression with the new
debug info hierarchy.

Old (well, current) assembly, with pretty-printing:

    !{!"...\\0016387", ...} ; ... [public] [rvalue reference]

Flags field without this change:

   !MDDerivedType(flags: 16387, ...)

Flags field with this change:

   !MDDerivedType(flags: DIFlagPublic | DIFlagRValueReference, ...)

As discussed in the review thread, this isn't a final state.  Most of
these flags correspond to `DW_AT_` symbolic constants, and we might
eventually want to support arbitrary attributes in some form.  However,
as it stands now, some of the flags correspond to other concepts (like
`FlagStaticMember`); until things are refactored this is the simplest
way to move forward without regressing assembly.

llvm-svn: 230111
2015-02-21 01:02:18 +00:00
Duncan P. N. Exon Smith
88b6f5e838 IR: Change MDFile to directly store the filename/directory
In the old (well, current) schema, there are two types of file
references: untagged and tagged (the latter references the former).

    !0 = !{!"filename", !"/directory"}
    !1 = !{!"0x29", !1} ; DW_TAG_file_type [filename] [/directory]

The interface to `DIBuilder` universally takes the tagged version,
described by `DIFile`.  However, most `file:` references actually use
the untagged version directly.

In the new hierarchy, I'm merging this into a single node: `MDFile`.

Originally I'd planned to keep the old schema unchanged until after I
moved the new hierarchy into place.

However, it turns out to be trivial to make `MDFile` match both nodes at
the same time.

  - Anyone referencing !1 does so through `DIFile`, whose implementation
    I need to gut anyway (as I do the rest of the `DIDescriptor`s).
  - Anyone referencing !0 just references an `MDNode`, and expects a
    node with two `MDString` operands.

This commit achieves that, and updates all the testcases for the parts
of the new hierarchy that used the two-node schema (I've replaced the
untagged nodes with `distinct !{}` to make the diff clear (otherwise the
metadata all gets renumbered); it might be worthwhile to come back and
delete those nodes and renumber the world, not sure).

llvm-svn: 230057
2015-02-20 20:35:17 +00:00
Duncan P. N. Exon Smith
650a4c9733 Bitcode: Stop assuming non-null fields
When writing the bitcode serialization for the new debug info hierarchy,
I assumed two fields would never be null.

Drop that assumption, since it's brittle (and crashes the
`BitcodeWriter` if wrong), and is a check better left for the verifier
anyway.  (No need for a bitcode upgrade here, since the new hierarchy is
still not in place.)

The fields in question are `MDCompileUnit::getFile()` and
`MDDerivedType::getBaseType()`, the latter of which isn't null in
test/Transforms/Mem2Reg/ConvertDebugInfo2.ll (see !14, a pointer to
nothing).  While the testcase might have bitrotted, there's no reason
for the bitcode format to rely on non-null for metadata operands.

This also fixes a bug in `AsmWriter` where if the `file:` is null it
isn't emitted (caught by the double-round trip in the testcase I'm
adding) -- this is a required field in `LLParser`.

I'll circle back to ConvertDebugInfo2.  Once the specialized nodes are
in place, I'll be trying to turn the debug info verifier back on by
default (in the newer module pass form committed r206300) and throwing
more logic in there.  If the testcase has bitrotted (as opposed to me
not understanding the schema correctly) I'll fix it then.

llvm-svn: 229960
2015-02-20 03:17:58 +00:00
Duncan P. N. Exon Smith
44c8e1ece2 IR: Fix MDType fields from unsigned to uint64_t
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
2015-02-19 23:56:07 +00:00
Duncan P. N. Exon Smith
9d3d24622e IR: Drop scope from MDTemplateParameter
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
2015-02-19 00:37:21 +00:00
Duncan P. N. Exon Smith
6c5c6d3ab2 IR: Allow MDSubrange to have 'count: -1'
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
2015-02-18 23:17:51 +00:00
Duncan P. N. Exon Smith
8768f09195 IR: Swap order of name and value in MDEnum
Put the name before the value in assembly for `MDEnum`.  While working
on the testcase upgrade script for the new hierarchy, I noticed that it
"looks nicer" to have the name first, since it lines the names up in the
(somewhat typical) case that they have a common prefix.

llvm-svn: 229747
2015-02-18 21:16:33 +00:00
David Majnemer
4da38e22ad ConstantFold: Properly fold GEP indices wider than i64
llvm-svn: 229420
2015-02-16 19:10:02 +00:00
David Majnemer
64cd3dbda5 IR: SrcTy == DstTy doesn't imply that a cast is valid
Cast validity depends on the cast's kind, not just its types.

llvm-svn: 229366
2015-02-16 09:37:35 +00:00
David Majnemer
4f5d97ee4f AsmParser: extractvalue requires at least one index operand
llvm-svn: 229365
2015-02-16 09:18:13 +00:00
David Majnemer
7f40c08dca AsmParser: Make sure GlobalVariables have sane types
llvm-svn: 229364
2015-02-16 08:41:08 +00:00
David Majnemer
b5464fbff9 AsmParser: Reject alloca with function type
llvm-svn: 229363
2015-02-16 08:38:03 +00:00
David Majnemer
3ae73b8e74 DebugInfo: Don't crash if 'Debug Info Version' has a strange value
llvm-svn: 229356
2015-02-16 06:04:53 +00:00
David Majnemer
271992a42e DataLayout: Validate that the pref alignment is at least the ABI align
llvm-svn: 229355
2015-02-16 05:41:55 +00:00
David Majnemer
18f3685387 DataLayout: Report when the datalayout type alignment/width is too large
llvm-svn: 229354
2015-02-16 05:41:53 +00:00
Duncan P. N. Exon Smith
8dc64a4707 AsmWriter/Bitcode: MDImportedEntity
llvm-svn: 229025
2015-02-13 01:46:02 +00:00
Duncan P. N. Exon Smith
baf6eacc58 AsmWriter/Bitcode: MDObjCProperty
llvm-svn: 229024
2015-02-13 01:43:22 +00:00
Duncan P. N. Exon Smith
e023c0f5eb AsmWriter/Bitcode: MDExpression
llvm-svn: 229023
2015-02-13 01:42:09 +00:00
Duncan P. N. Exon Smith
c9450daed2 AsmWriter/Bitcode: MDLocalVariable
llvm-svn: 229022
2015-02-13 01:39:44 +00:00
Duncan P. N. Exon Smith
58b49ba795 AsmWriter/Bitcode: MDGlobalVariable
llvm-svn: 229020
2015-02-13 01:35:40 +00:00
Duncan P. N. Exon Smith
d136432599 AsmWriter/Bitcode: MDTemplate{Type,Value}Parameter
llvm-svn: 229019
2015-02-13 01:34:32 +00:00
Duncan P. N. Exon Smith
c96d92ad70 AsmWriter/Bitcode: MDNamespace
llvm-svn: 229018
2015-02-13 01:32:09 +00:00
Duncan P. N. Exon Smith
affacdfc5b AsmWriter/Bitcode: MDLexicalBlockFile
llvm-svn: 229017
2015-02-13 01:30:42 +00:00
Duncan P. N. Exon Smith
b3ef6197cf AsmWriter/Bitcode: MDLexicalBlock
llvm-svn: 229016
2015-02-13 01:29:28 +00:00
Duncan P. N. Exon Smith
9c2655de4a AsmWriter: MDSubprogram: Recognize DW_VIRTUALITY in 'virtuality'
llvm-svn: 229015
2015-02-13 01:28:16 +00:00
Duncan P. N. Exon Smith
52584d6996 AsmWriter/Bitcode: MDSubprogram
llvm-svn: 229014
2015-02-13 01:26:47 +00:00
Duncan P. N. Exon Smith
21bc2cacec AsmWriter/Bitcode: MDCompileUnit
llvm-svn: 229013
2015-02-13 01:25:10 +00:00
Duncan P. N. Exon Smith
51dcb8de94 AsmWriter/Bitcode: MDSubroutineType
llvm-svn: 229011
2015-02-13 01:22:59 +00:00
Duncan P. N. Exon Smith
23fded4323 AsmWriter: MDCompositeType: Recognize DW_LANG in 'runtimeLang'
llvm-svn: 229010
2015-02-13 01:21:25 +00:00
Duncan P. N. Exon Smith
c4bb6d7bbb AsmWriter/Bitcode: MDDerivedType and MDCompositeType
llvm-svn: 229009
2015-02-13 01:20:38 +00:00
Duncan P. N. Exon Smith
4428ff1087 AsmWriter/Bitcode: MDFile
llvm-svn: 229007
2015-02-13 01:19:14 +00:00
Duncan P. N. Exon Smith
ab0350e2c0 AsmWriter: MDBasicType: Recognize DW_ATE in 'encoding'
llvm-svn: 229006
2015-02-13 01:17:35 +00:00
Duncan P. N. Exon Smith
38e2854cc3 AsmWriter/Bitcode: MDBasicType
llvm-svn: 229005
2015-02-13 01:14:58 +00:00
Duncan P. N. Exon Smith
8b689964a4 AsmWriter/Bitcode: MDEnumerator
llvm-svn: 229004
2015-02-13 01:14:11 +00:00
Duncan P. N. Exon Smith
9879c4ea87 AsmWriter/Bitcode: MDSubrange
llvm-svn: 229003
2015-02-13 01:10:38 +00:00
David Majnemer
fbc347f596 AsmParser: Validate alloca's type
An alloca's type should be weird things like metadata.

llvm-svn: 228820
2015-02-11 09:13:11 +00:00
David Majnemer
61ddeb2d4b DataLayout: Report when the preferred alignment is less than the ABI
llvm-svn: 228819
2015-02-11 09:13:09 +00:00
David Majnemer
b2167a7a64 AsmParser: Don't crash when insertvalue has bad operands
llvm-svn: 228813
2015-02-11 07:43:58 +00:00
Duncan P. N. Exon Smith
213984fa5d IR: Allow 32-bits for lines in debug location
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
2015-02-06 22:50:13 +00:00
Duncan P. N. Exon Smith
b0edee547b AsmParser: Recognize DW_TAG_* constants
Recognize `DW_TAG_` constants in assembly, and output it by default for
`GenericDebugNode`.

llvm-svn: 228042
2015-02-03 21:56:01 +00:00
Duncan P. N. Exon Smith
55694c075d IR: Assembly and bitcode for GenericDebugNode
llvm-svn: 228041
2015-02-03 21:54:14 +00:00
Duncan P. N. Exon Smith
c7c851bb04 IR: Update references to temporaries before deleting
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
2015-01-22 21:36:45 +00:00
Duncan P. N. Exon Smith
56c8d44827 AsmParser: Fix error location for missing fields
llvm-svn: 226524
2015-01-19 23:32:36 +00:00
Duncan P. N. Exon Smith
97ed3e1e77 IR: Allow 16-bits for column info
Raise the limit for column information from 8 bits to 16 bits.

llvm-svn: 226291
2015-01-16 17:33:08 +00:00
Duncan P. N. Exon Smith
4a5feedcaa IR: Move MDLocation into place
This commit moves `MDLocation`, finishing off PR21433.  There's an
accompanying clang commit for frontend testcases.  I'll attach the
testcase upgrade script I used to PR21433 to help out-of-tree
frontends/backends.

This changes the schema for `DebugLoc` and `DILocation` from:

    !{i32 3, i32 7, !7, !8}

to:

    !MDLocation(line: 3, column: 7, scope: !7, inlinedAt: !8)

Note that empty fields (line/column: 0 and inlinedAt: null) don't get
printed by the assembly writer.

llvm-svn: 226048
2015-01-14 22:27:36 +00:00
Duncan P. N. Exon Smith
c9a6b68ef2 IR: Always print MDLocation line
Print `MDLocation`'s `line` field even when it's 0.

llvm-svn: 226046
2015-01-14 22:14:26 +00:00
Rafael Espindola
ee0c3b182d Add support for comdats with names larger than 256 characters.
llvm-svn: 226012
2015-01-14 18:25:45 +00:00
Duncan P. N. Exon Smith
85eaac222d AsmParser/Bitcode: Add support for MDLocation
This adds assembly and bitcode support for `MDLocation`.  The assembly
side is rather big, since this is the first `MDNode` subclass (that
isn't `MDTuple`).  Part of PR21433.

(If you're wondering where the mountains of testcase updates are, we
don't need them until I update `DILocation` and `DebugLoc` to actually
use this class.)

llvm-svn: 225830
2015-01-13 21:10:44 +00:00
Duncan P. N. Exon Smith
bc9ee9160a IR: Add 'distinct' MDNodes to bitcode and assembly
Propagate whether `MDNode`s are 'distinct' through the other types of IR
(assembly and bitcode).  This adds the `distinct` keyword to assembly.

Currently, no one actually calls `MDNode::getDistinct()`, so these nodes
only get created for:

  - self-references, which are never uniqued, and
  - nodes whose operands are replaced that hit a uniquing collision.

The concept of distinct nodes is still not quite first-class, since
distinct-ness doesn't yet survive across `MapMetadata()`.

Part of PR22111.

llvm-svn: 225474
2015-01-08 22:38:29 +00:00
Rafael Espindola
20dc6c7571 Change the .ll syntax for comdats and add a syntactic sugar.
In order to make comdats always explicit in the IR, we decided to make
the syntax a bit more compact for the case of a GlobalObject in a
comdat with the same name.

Just dropping the $name causes problems for

@foo = globabl i32 0, comdat
$bar = comdat ...

and

declare void @foo() comdat
$bar = comdat ...

So the syntax is changed to

@g1 = globabl i32 0, comdat($c1)
@g2 = globabl i32 0, comdat

and

declare void @foo() comdat($c1)
declare void @foo() comdat

llvm-svn: 225302
2015-01-06 22:55:16 +00:00
Duncan P. N. Exon Smith
c03e29935e DebugInfo: Update testcase to actually check something
This test was missing a `Debug Info Version` so it's `not grep` was
passing vacuously.  Update it to CHECK for something useful at the same
time so it doesn't bitrot quite so easily in the future.

llvm-svn: 224324
2014-12-16 07:08:19 +00:00
Duncan P. N. Exon Smith
9c5542c040 IR: Make metadata typeless in assembly
Now that `Metadata` is typeless, reflect that in the assembly.  These
are the matching assembly changes for the metadata/value split in
r223802.

  - Only use the `metadata` type when referencing metadata from a call
    intrinsic -- i.e., only when it's used as a `Value`.

  - Stop pretending that `ValueAsMetadata` is wrapped in an `MDNode`
    when referencing it from call intrinsics.

So, assembly like this:

    define @foo(i32 %v) {
      call void @llvm.foo(metadata !{i32 %v}, metadata !0)
      call void @llvm.foo(metadata !{i32 7}, metadata !0)
      call void @llvm.foo(metadata !1, metadata !0)
      call void @llvm.foo(metadata !3, metadata !0)
      call void @llvm.foo(metadata !{metadata !3}, metadata !0)
      ret void, !bar !2
    }
    !0 = metadata !{metadata !2}
    !1 = metadata !{i32* @global}
    !2 = metadata !{metadata !3}
    !3 = metadata !{}

turns into this:

    define @foo(i32 %v) {
      call void @llvm.foo(metadata i32 %v, metadata !0)
      call void @llvm.foo(metadata i32 7, metadata !0)
      call void @llvm.foo(metadata i32* @global, metadata !0)
      call void @llvm.foo(metadata !3, metadata !0)
      call void @llvm.foo(metadata !{!3}, metadata !0)
      ret void, !bar !2
    }
    !0 = !{!2}
    !1 = !{i32* @global}
    !2 = !{!3}
    !3 = !{}

I wrote an upgrade script that handled almost all of the tests in llvm
and many of the tests in cfe (even handling many `CHECK` lines).  I've
attached it (or will attach it in a moment if you're speedy) to PR21532
to help everyone update their out-of-tree testcases.

This is part of PR21532.

llvm-svn: 224257
2014-12-15 19:07:53 +00:00
David Majnemer
87f7df4d2e AsmParser: Don't crash on an ill-formed MDNodeVector
llvm-svn: 224056
2014-12-11 20:51:54 +00:00
David Majnemer
3705a77a71 AsmParser: Don't crash on an ill-formed MDNodeVector
llvm-svn: 224053
2014-12-11 20:44:09 +00:00
Duncan P. N. Exon Smith
91a58545de IR: Add 'invalid-' to test names for invalid assembly
Take the opportunity to sort these by `metadata`.

llvm-svn: 223993
2014-12-11 01:34:46 +00:00
David Majnemer
df607e95a0 DataLayout: Provide nicer diagnostics for malformed strings
llvm-svn: 223911
2014-12-10 02:36:41 +00:00
David Majnemer
6f52870a48 AsmParser: Don't allow null bytes in BB labels
Since Value objects can't have null bytes in their name, we shouldn't
allow them in the labels of basic blocks.

llvm-svn: 223907
2014-12-10 02:10:35 +00:00
David Majnemer
c64f605e39 DataLayout: Be more verbose when diagnosing problems in pointer specs
llvm-svn: 223903
2014-12-10 01:38:28 +00:00
David Majnemer
6cc7f21933 I didn't intend to commit this with r223898
llvm-svn: 223899
2014-12-10 01:17:48 +00:00
David Majnemer
6ed74720c1 DataLayout: Move asserts over to report_fatal_error
As indicated by the tests, it is possible to feed the AsmParser an
invalid datalayout string.  We should verify the result of parsing this
string regardless of whether or not we have assertions enabled.

llvm-svn: 223898
2014-12-10 01:17:08 +00:00
David Majnemer
2d2a18adb4 AsmParser: Don't crash if a null byte is inside a quoted string
We don't allow Value* to have names which contain null bytes.  The
AsmParser should reject .ll files that try to do this.

llvm-svn: 223869
2014-12-10 00:43:17 +00:00
David Majnemer
439f3eddb7 Forgot to add test for r223856
llvm-svn: 223857
2014-12-09 23:51:14 +00:00
David Majnemer
e1b75899bd AsmParser: Don't crash on short hex constants for fp128 types
If we see 0xL01, treat it like 0xL00000000000000000000000000000001
instead of crashing.

llvm-svn: 223811
2014-12-09 19:10:03 +00:00
Duncan P. N. Exon Smith
3d57886267 IR: Split Metadata from Value
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
2014-12-09 18:38:53 +00:00
David Majnemer
9047561af5 AsmParser: Don't crash on malformed attribute groups
This fixes PR21785.

llvm-svn: 223801
2014-12-09 18:33:57 +00:00
David Majnemer
db0e82a418 Reland r223754
The commit is identical except a reference to `GV' should have been to
`GVal'.

llvm-svn: 223756
2014-12-09 05:56:09 +00:00
David Majnemer
a165fae214 Revert "AsmParser: Reject invalid mismatch between forward ref and def"
This reverts commit r223754.  I've upset the buildbots.

llvm-svn: 223755
2014-12-09 05:50:11 +00:00
David Majnemer
357d253bf3 AsmParser: Reject invalid mismatch between forward ref and def
Don't assume that the forward referenced entity was of the same
global-kind as the new entity.

This fixes PR21779.

llvm-svn: 223754
2014-12-09 05:43:56 +00:00
David Majnemer
c5dbd099c5 ConstantFold: Zero-sized globals might land on top of another global
A zero sized array is zero sized and might share its address with
another global.

llvm-svn: 223684
2014-12-08 19:35:31 +00:00
Duncan P. N. Exon Smith
7c303fdacc IR: Add missing tests for function-local metadata
Add assembly and bitcode tests that I neglected to add in r223564 (IR:
Disallow complicated function-local metadata) and r223574 (IR: Disallow
function-local metadata attachments).

Found a couple of bugs:

  - The error message for function-local attachments gave the wrong line
    number -- it indicated the next token (typically on the next line)
    instead of the token that started the attachment.  Fixed.

  - Metadata arguments of the form `!{i32 0, i32 %v}` (or with the
    arguments reversed) fired an assertion in `ValueEnumerator` in LLVM
    v3.5, so I suppose this never really worked.  I suppose this was
    "fixed" by r223564.

(Thanks to dblaikie for pointing out my omission.)

Part of PR21532.

llvm-svn: 223616
2014-12-07 17:56:16 +00:00
David Majnemer
0d1f96063b ConstantFold: Don't optimize comparisons with weak linkage objects
Consider:
void f() {}
void __attribute__((weak)) g() {}
bool b = &f != &g;

It's possble for g to resolve to f if --defsym=g=f is passed on to the
linker.

llvm-svn: 223585
2014-12-06 11:58:33 +00:00
Duncan P. N. Exon Smith
62ee08db9a IR: Disallow complicated function-local metadata
Disallow complex types of function-local metadata.  The only valid
function-local metadata is an `MDNode` whose sole argument is a
non-metadata function-local value.

Part of PR21532.

llvm-svn: 223564
2014-12-06 01:26:49 +00:00
Rafael Espindola
233f1b11dd Use FileCheck in a few tests.
llvm-svn: 221459
2014-11-06 15:05:51 +00:00
Rafael Espindola
253081a9b6 Delete -std-compile-opts.
These days -std-compile-opts was just a silly alias for -O3.

llvm-svn: 219951
2014-10-16 20:00:02 +00:00
Duncan P. N. Exon Smith
c1be4794ba Revert "Revert "DI: Fold constant arguments into a single MDString""
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
2014-10-03 20:01:09 +00:00
Duncan P. N. Exon Smith
fb6bcc4eb2 Revert "DI: Fold constant arguments into a single MDString"
This reverts commit r218914 while I investigate some bots.

llvm-svn: 218918
2014-10-02 22:15:31 +00:00
Duncan P. N. Exon Smith
58b6077a79 DI: Fold constant arguments into a single MDString
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
2014-10-02 21:56:57 +00:00
Adrian Prantl
2b1df58ebe Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.

Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.

By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.

The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)

This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.

What this patch doesn't do:

This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.

http://reviews.llvm.org/D4919
rdar://problem/17994491

Thanks to dblaikie and dexonsmith for reviewing this patch!

Note: I accidentally committed a bogus older version of this patch previously.
llvm-svn: 218787
2014-10-01 18:55:02 +00:00