Commit Graph

858 Commits

Author SHA1 Message Date
Alon Mishne ad312155a6 [C++11] Change DebugInfoFinder to use range-based loops
Also changes the iterators to return actual DI type over MDNode.

llvm-svn: 204130
2014-03-18 09:41:07 +00:00
Adrian Prantl 1a1647cab6 Switch the type field in DIVariable and DIGlobalVariable over to DITypeRefs.
This allows us to catch more opportunities for ODR-based type uniquing
during LTO.
Paired commit with CFE which updates some testcases to verify the new
DIBuilder behavior.

llvm-svn: 204106
2014-03-18 02:34:58 +00:00
Benjamin Kramer 86c7741f68 Make some assertions on constant expressions static.
llvm-svn: 204011
2014-03-15 18:47:07 +00:00
Diego Novillo a32aa3251c Use DiagnosticInfo facility.
Summary:
The sample profiler pass emits several error messages. Instead of
just aborting the compiler with report_fatal_error, we can emit
better messages using DiagnosticInfo.

This adds a new sub-class of DiagnosticInfo to handle the sample
profiler.

Reviewers: chandlerc, qcolombet

CC: llvm-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D3086

llvm-svn: 203976
2014-03-14 21:58:59 +00:00
Rafael Espindola 2fb5bc33a3 Remove the linker_private and linker_private_weak linkages.
These linkages were introduced some time ago, but it was never very
clear what exactly their semantics were or what they should be used
for. Some investigation found these uses:

* utf-16 strings in clang.
* non-unnamed_addr strings produced by the sanitizers.

It turns out they were just working around a more fundamental problem.
For some sections a MachO linker needs a symbol in order to split the
section into atoms, and llvm had no idea that was the case. I fixed
that in r201700 and it is now safe to use the private linkage. When
the object ends up in a section that requires symbols, llvm will use a
'l' prefix instead of a 'L' prefix and things just work.

With that, these linkages were already dead, but there was a potential
future user in the objc metadata information. I am still looking at
CGObjcMac.cpp, but at this point I am convinced that linker_private
and linker_private_weak are not what they need.

The objc uses are currently split in

* Regular symbols (no '\01' prefix). LLVM already directly provides
whatever semantics they need.
* Uses of a private name (start with "\01L" or "\01l") and private
linkage. We can drop the "\01L" and "\01l" prefixes as soon as llvm
agrees with clang on L being ok or not for a given section. I have two
patches in code review for this.
* Uses of private name and weak linkage.

The last case is the one that one could think would fit one of these
linkages. That is not the case. The semantics are

* the linker will merge these symbol by *name*.
* the linker will hide them in the final DSO.

Given that the merging is done by name, any of the private (or
internal) linkages would be a bad match. They allow llvm to rename the
symbols, and that is really not what we want. From the llvm point of
view, these objects should really be (linkonce|weak)(_odr)?.

For now, just keeping the "\01l" prefix is probably the best for these
symbols. If we one day want to have a more direct support in llvm,
IMHO what we should add is not a linkage, it is just a hidden_symbol
attribute. It would be applicable to multiple linkages. For example,
on weak it would produce the current behavior we have for objc
metadata. On internal, it would be equivalent to private (and we
should then remove private).

llvm-svn: 203866
2014-03-13 23:18:37 +00:00
Chandler Carruth b07f378fc8 [PM] Stop playing fast and loose with rebinding of references. However
convenient it is to imagine a world where this works, that is not C++ as
was pointed out in review. The standard even goes to some lengths to
preclude any attempt at this, for better or worse. Maybe better. =]

llvm-svn: 203775
2014-03-13 09:50:31 +00:00
Rafael Espindola f3336bc1d5 Reject alias to undefined symbols in the verifier.
On ELF and COFF an alias is just another name for a position in the file.
There is no way to refer to a position in another file, so an alias to
undefined is meaningless.

MachO currently doesn't support aliases. The spec has a N_INDR, which when
implemented will have a different set of restrictions. Adding support for
it shouldn't be harder than any other IR extension.

For now, having the IR represent what is actually possible with current
tools makes it easier to fix the design of GlobalAlias.

llvm-svn: 203705
2014-03-12 20:15:49 +00:00
Evan Cheng ad6efbfa0f Revert r203488 and r203520.
llvm-svn: 203687
2014-03-12 18:09:37 +00:00
Rafael Espindola 2e43aff460 Avoid repeated calls to CE->getOperand(0). No functionality change.
llvm-svn: 203686
2014-03-12 18:08:14 +00:00
Benjamin Kramer f8502272ef Remove copy ctors that did the same thing as the default one.
The code added nothing but potentially disabled move semantics and made
types non-trivially copyable.

llvm-svn: 203563
2014-03-11 11:32:49 +00:00
Tim Northover e94a518a22 IR: add a second ordering operand to cmpxhg for failure
The syntax for "cmpxchg" should now look something like:

	cmpxchg i32* %addr, i32 42, i32 3 acquire monotonic

where the second ordering argument gives the required semantics in the case
that no exchange takes place. It should be no stronger than the first ordering
constraint and cannot be either "release" or "acq_rel" (since no store will
have taken place).

rdar://problem/15996804

llvm-svn: 203559
2014-03-11 10:48:52 +00:00
Duncan P. N. Exon Smith 56cc990480 Module: Don't rename in getOrInsertFunction()
During LTO, user-supplied definitions of C library functions often
exist.  -instcombine uses Module::getOrInsertFunction() to get a handle
on library functions (e.g., @puts, when optimizing @printf).

Previously, Module::getOrInsertFunction() would rename any matching
functions with local linkage, and create a new declaration.  In LTO,
this is the opposite of desired behaviour, as it skips by the
user-supplied version of the library function and creates a new
undefined reference which the linker often cannot resolve.

After some discussing with Rafael on the list, it looks like it's
undesired behaviour.  If a consumer actually *needs* this behaviour, we
should add new API with a more explicit name.

I added two testcases: one specifically for the -instcombine behaviour
and one for the LTO flow.

<rdar://problem/16165191>

llvm-svn: 203513
2014-03-10 23:42:28 +00:00
Justin Bogner 28e1cf6061 IR: Slightly more verbose error in Verifier
Extend the error message generated by the Verifier when an intrinsic
name does not match the expected mangling to include the expected
name.  Simplifies debugging.

Patch by Philip Reames!

llvm-svn: 203490
2014-03-10 21:22:44 +00:00
Evan Cheng 0e8f4612a9 For functions with ARM target specific calling convention, when simplify-libcall
optimize a call to a llvm intrinsic to something that invovles a call to a C
library call, make sure it sets the right calling convention on the call.

e.g.
extern double pow(double, double);
double t(double x) {
  return pow(10, x);
}

Compiles to something like this for AAPCS-VFP:
define arm_aapcs_vfpcc double @t(double %x) #0 {
entry:
  %0 = call double @llvm.pow.f64(double 1.000000e+01, double %x)
  ret double %0
}

declare double @llvm.pow.f64(double, double) #1

Simplify libcall (part of instcombine) will turn the above into:
define arm_aapcs_vfpcc double @t(double %x) #0 {
entry:
  %__exp10 = call double @__exp10(double %x) #1
  ret double %__exp10
}

declare double @__exp10(double)

The pre-instcombine code works because calls to LLVM builtins are special.
Instruction selection will chose the right calling convention for the call.
However, the code after instcombine is wrong. The call to __exp10 will use
the C calling convention.

I can think of 3 options to fix this.

1. Make "C" calling convention just work since the target should know what CC
   is being used.

   This doesn't work because each function can use different CC with the "pcs"
   attribute.

2. Have Clang add the right CC keyword on the calls to LLVM builtin.

   This will work but it doesn't match the LLVM IR specification which states
   these are "Standard C Library Intrinsics".

3. Fix simplify libcall so the resulting calls to the C routines will have the
   proper CC keyword. e.g.
   %__exp10 = call arm_aapcs_vfpcc double @__exp10(double %x) #1

   This works and is the solution I implemented here.

Both solutions #2 and #3 would work. After carefully considering the pros and
cons, I decided to implement #3 for the following reasons.

1. It doesn't change the "spec" of the intrinsics.
2. It's a self-contained fix.

There are a couple of potential downsides.
1. There could be other places in the optimizer that is broken in the same way
   that's not addressed by this.
2. There could be other calling conventions that need to be propagated by
   simplify-libcall that's not handled.

But for now, this is the fix that I'm most comfortable with.

llvm-svn: 203488
2014-03-10 20:49:45 +00:00
Tim Northover ad96d012c3 llvm-c: expose unnamedaddr field of globals
Patch by Manuel Jacob.

llvm-svn: 203482
2014-03-10 19:24:35 +00:00
Benjamin Kramer 3ad5c96268 [C++11] Modernize the IR library a bit.
No functionality change.

llvm-svn: 203465
2014-03-10 15:03:06 +00:00
Chandler Carruth 5ae74a6af2 [PM] While I'm here, fix a few other clang-format issues. Pulls some
lines under 80-columns, etc.

llvm-svn: 203434
2014-03-10 02:12:14 +00:00
Chandler Carruth c3f3da3d21 [PM] Switch new pass manager from polymorphic_ptr to unique_ptr now that
it is available. Also make the move semantics sufficiently correct to
tolerate move-only passes, as the PassManagers *are* move-only passes.

llvm-svn: 203391
2014-03-09 11:49:53 +00:00
David Majnemer c4ab61cb2f IR: Change inalloca's grammar a bit
The grammar for LLVM IR is not well specified in any document but seems
to obey the following rules:

 - Attributes which have parenthesized arguments are never preceded by
   commas.  This form of attribute is the only one which ever has
   optional arguments.  However, not all of these attributes support
   optional arguments: 'thread_local' supports an optional argument but
   'addrspace' does not.  Interestingly, 'addrspace' is documented as
   being a "qualifier".  What constitutes a qualifier?  I cannot find a
   definition.

 - Some attributes use a space between the keyword and the value.
   Examples of this form are 'align' and 'section'.  These are always
   preceded by a comma.

 - Otherwise, the attribute has no argument.  These attributes do not
   have a preceding comma.

Sometimes an attribute goes before the instruction, between the
instruction and it's type, or after it's type.  'atomicrmw' has
'volatile' between the instruction and the type while 'call' has 'tail'
preceding the instruction.

With all this in mind, it seems most consistent for 'inalloca' on an
'inalloca' instruction to occur before between the instruction and the
type.  Unlike the current formulation, there would be no preceding
comma.  The combination 'alloca inalloca' doesn't look particularly
appetizing, perhaps a better spelling of 'inalloca' is down the road.

llvm-svn: 203376
2014-03-09 06:41:58 +00:00
Ahmed Charles 821b66669c [C++11] Fix break due to MSVC bug.
MSVC (2012, 2013, 2013 Nov CTP) fail on the following code:

int main() {
  int arr[] = {1, 2};
  for (int i : arr)
    do {} while (0);
}

The fix is to put {} around the for loop. I've reported this to the MSVC
team.

llvm-svn: 203371
2014-03-09 04:57:09 +00:00
Chandler Carruth cdf4788401 [C++11] Add range based accessors for the Use-Def chain of a Value.
This requires a number of steps.
1) Move value_use_iterator into the Value class as an implementation
   detail
2) Change it to actually be a *Use* iterator rather than a *User*
   iterator.
3) Add an adaptor which is a User iterator that always looks through the
   Use to the User.
4) Wrap these in Value::use_iterator and Value::user_iterator typedefs.
5) Add the range adaptors as Value::uses() and Value::users().
6) Update *all* of the callers to correctly distinguish between whether
   they wanted a use_iterator (and to explicitly dig out the User when
   needed), or a user_iterator which makes the Use itself totally
   opaque.

Because #6 requires churning essentially everything that walked the
Use-Def chains, I went ahead and added all of the range adaptors and
switched them to range-based loops where appropriate. Also because the
renaming requires at least churning every line of code, it didn't make
any sense to split these up into multiple commits -- all of which would
touch all of the same lies of code.

The result is still not quite optimal. The Value::use_iterator is a nice
regular iterator, but Value::user_iterator is an iterator over User*s
rather than over the User objects themselves. As a consequence, it fits
a bit awkwardly into the range-based world and it has the weird
extra-dereferencing 'operator->' that so many of our iterators have.
I think this could be fixed by providing something which transforms
a range of T&s into a range of T*s, but that *can* be separated into
another patch, and it isn't yet 100% clear whether this is the right
move.

However, this change gets us most of the benefit and cleans up
a substantial amount of code around Use and User. =]

llvm-svn: 203364
2014-03-09 03:16:01 +00:00
Matt Arsenault a236ea551c Teach lint about address spaces
llvm-svn: 203132
2014-03-06 17:33:55 +00:00
Ahmed Charles 56440fd820 Replace OwningPtr<T> with std::unique_ptr<T>.
This compiles with no changes to clang/lld/lldb with MSVC and includes
overloads to various functions which are used by those projects and llvm
which have OwningPtr's as parameters. This should allow out of tree
projects some time to move. There are also no changes to libs/Target,
which should help out of tree targets have time to move, if necessary.

llvm-svn: 203083
2014-03-06 05:51:42 +00:00
Chandler Carruth d1163aa59e [Layering] Move GVMaterializer.h into the IR library where its
implementation already lived.

After this commit, the only IR-library headers in include/llvm/* are
ones related to the legacy pass infrastructure that I'm planning to
leave there until the new one is farther along.

The only other headers at the top level are linking and initialization
aids that aren't really libraries but just headers.

llvm-svn: 203069
2014-03-06 03:50:29 +00:00
Chandler Carruth 7da14f1ab9 [Layering] Move InstVisitor.h into the IR library as it is pretty
obviously coupled to the IR.

llvm-svn: 203064
2014-03-06 03:23:41 +00:00
Chandler Carruth 9a4c9e597b [Layering] Move DebugInfo.h into the IR library where its implementation
already lives.

llvm-svn: 203046
2014-03-06 00:46:21 +00:00
Chandler Carruth 12664a0b17 [Layering] Move DIBuilder.h into the IR library where its implementation
already lives.

llvm-svn: 203038
2014-03-06 00:22:06 +00:00
Chandler Carruth 9106521056 [Layering] Move AutoUpgrade.h into the IR library where its
implementation already lives.

llvm-svn: 202961
2014-03-05 10:34:14 +00:00
Chandler Carruth 9205140772 [Layering] Move DebugLoc.h into the IR library. The implementation
already lived there and it is where it belongs -- this is the in-memory
debug location representation.

This is just cleanup -- Modules can actually cope with this, but that
doesn't make it right. After chatting with folks that have out-of-tree
stuff, going ahead and moving the rest of the headers seems preferable.

llvm-svn: 202960
2014-03-05 10:30:38 +00:00
Ahmed Charles 96c9d95f51 [C++11] Replace OwningPtr::take() with OwningPtr::release().
llvm-svn: 202957
2014-03-05 10:19:29 +00:00
Craig Topper f398d7c6bf [C++11] Add 'override' keyword to IR library.
llvm-svn: 202939
2014-03-05 06:35:38 +00:00
Peter Zotov 9f584e67f4 [C API] Implement LLVM{Get,Set}Alignment for AllocaInst.
Patch by Manuel Jacob.

llvm-svn: 202936
2014-03-05 05:05:34 +00:00
Reid Kleckner 2fae26fa2c C API: Add functions to get or set a GlobalValue's DLLStorageClass
Patch by Manuel Jacob!

llvm-svn: 202928
2014-03-05 02:34:23 +00:00
Chandler Carruth 4b6845c7e7 [Modules] Move the LeakDetector header into the IR library where the
source file had already been moved. Also move the unittest into the IR
unittest library.

This may seem an odd thing to put in the IR library but we only really
use this with instructions and it needs the LLVM context to work, so it
is intrinsically tied to the IR library.

llvm-svn: 202842
2014-03-04 12:46:06 +00:00
Chandler Carruth 1b69ed8f6a [Modules] Move the PassNameParser to the IR library as it deals in the
PassInfo structures of the legacy pass manager. Also give it the Legacy
prefix as it is not a particularly widely used header.

llvm-svn: 202839
2014-03-04 12:32:42 +00:00
Chandler Carruth 8cd041ef19 [Modules] Move the ConstantRange class into the IR library. This is
a bit surprising, as the class is almost entirely abstracted away from
any particular IR, however it encodes the comparsion predicates which
mutate ranges as ICmp predicate codes. This is reasonable as they're
used for both instructions and constants. Thus, it belongs in the IR
library with instructions and constants.

llvm-svn: 202838
2014-03-04 12:24:34 +00:00
Chandler Carruth 1305dc3351 [Modules] Move CFG.h to the IR library as it defines graph traits over
IR types.

llvm-svn: 202827
2014-03-04 11:45:46 +00:00
Chandler Carruth 4220e9c154 [Modules] Move ValueHandle into the IR library where Value itself lives.
Move the test for this class into the IR unittests as well.

This uncovers that ValueMap too is in the IR library. Ironically, the
unittest for ValueMap is useless in the Support library (honestly, so
was the ValueHandle test) and so it already lives in the IR unittests.
Mmmm, tasty layering.

llvm-svn: 202821
2014-03-04 11:17:44 +00:00
Chandler Carruth 219b89b987 [Modules] Move CallSite into the IR library where it belogs. It is
abstracting between a CallInst and an InvokeInst, both of which are IR
concepts.

llvm-svn: 202816
2014-03-04 11:01:28 +00:00
Chandler Carruth 03eb0de93d [Modules] Move GetElementPtrTypeIterator into the IR library. As its
name might indicate, it is an iterator over the types in an instruction
in the IR.... You see where this is going.

Another step of modularizing the support library.

llvm-svn: 202815
2014-03-04 10:40:04 +00:00
Chandler Carruth 8394857f43 [Modules] Move InstIterator out of the Support library, where it had no
business.

This header includes Function and BasicBlock and directly uses the
interfaces of both classes. It has to do with the IR, it even has that
in the name. =] Put it in the library it belongs to.

This is one step toward making LLVM's Support library survive a C++
modules bootstrap.

llvm-svn: 202814
2014-03-04 10:30:26 +00:00
Chandler Carruth 442f784814 [cleanup] Re-sort all the includes with utils/sort_includes.py.
llvm-svn: 202811
2014-03-04 10:07:28 +00:00
Yaron Keren 225d550b05 Cleaning up a bunch of pre-Visual C++ 2012 build hacks.
llvm-svn: 202806
2014-03-04 09:23:33 +00:00
Chandler Carruth 387e059c04 [cleanup] Add a getOperandNo method to the Use class and implement it
out-of-line so that it can refer to the methods on User. As
a consequence, this removes the need to define one template method if
value_use_iterator in the extremely strange User.h header (!!!).

This makse Use.h slightly less peculiar. The only remaining real
peculiarity is the definition of Use::set in Value.h

llvm-svn: 202805
2014-03-04 09:19:43 +00:00
Chandler Carruth 4ffd9d250c [cleanup] Use early exit and simpler temporary variables to clarify the
swap implementation.

llvm-svn: 202802
2014-03-04 09:00:15 +00:00
Chandler Carruth 618bd1b75b [cleanup] Run clang-format over the Use code. It was *really*
inconsistent both with itself and with LLVM at large with formatting.
The *s were on the wrong side, the indent was off, etc etc. This is much
cleaner.

Also, go clang-format laying out the array of tags in nice columns.

llvm-svn: 202799
2014-03-04 08:53:41 +00:00
Chandler Carruth 06d49183ec [cleanup] Tidy up and modernize comments and the definition order for
the Use class.

More cleanups to come here. This class just needs some TLC.

llvm-svn: 202798
2014-03-04 08:51:00 +00:00
Diego Novillo f5041ce558 Pass to emit DWARF path discriminators.
DWARF discriminators are used to distinguish multiple control flow paths
on the same source location. When this happens, instructions across
basic block boundaries will share the same debug location.

This pass detects this situation and creates a new lexical scope to one
of the two instructions. This lexical scope is a child scope of the
original and contains a new discriminator value. This discriminator is
then picked up from MCObjectStreamer::EmitDwarfLocDirective to be
written on the object file.

This fixes http://llvm.org/bugs/show_bug.cgi?id=18270.

llvm-svn: 202752
2014-03-03 20:06:11 +00:00
Benjamin Kramer b2f034b85e [C++11] Use std::tie to simplify compare operators.
No functionality change.

llvm-svn: 202751
2014-03-03 19:58:30 +00:00
Diego Novillo 282450d94c Add DWARF discriminator support to DILexicalBlocks.
This adds support for emitting discriminators from DILexicalBlocks.

llvm-svn: 202736
2014-03-03 18:53:17 +00:00
Benjamin Kramer 17388a61b2 Revert "[C++11] Replace LLVM atomics with std::atomic."
Breaks the MSVC build.
DataStream.cpp(44): error C2552: 'llvm::Statistic::Value' : non-aggregates cannot be initialized with initializer list

llvm-svn: 202731
2014-03-03 18:02:34 +00:00
Benjamin Kramer 0b6eb591a4 [C++11] Replace LLVM atomics with std::atomic.
With C++11 we finally have a standardized way to specify atomic operations. Use
them to replace the existing custom implemention. Sadly the translation is not
entirely trivial as std::atomic allows more fine-grained control over the
atomicity. I tried to preserve the old semantics as well as possible.

Differential Revision: http://llvm-reviews.chandlerc.com/D2915

llvm-svn: 202730
2014-03-03 17:53:30 +00:00
Benjamin Kramer d6f1f84f51 [C++11] Replace llvm::tie with std::tie.
The old implementation is no longer needed in C++11.

llvm-svn: 202644
2014-03-02 13:30:33 +00:00
Benjamin Kramer b6d0bd48bd [C++11] Replace llvm::next and llvm::prior with std::next and std::prev.
Remove the old functions.

llvm-svn: 202636
2014-03-02 12:27:27 +00:00
Chandler Carruth 002da5db29 [C++11] Switch all uses of the llvm_move macro to use std::move
directly, and remove the macro.

llvm-svn: 202612
2014-03-02 04:08:41 +00:00
Eric Christopher e587c0853b Fix >> to be > > for non-c++11.
llvm-svn: 202545
2014-02-28 21:37:28 +00:00
Eric Christopher 961959faec 80-col.
llvm-svn: 202541
2014-02-28 21:27:59 +00:00
Eric Christopher 2c3a6dce44 Fix a crasher where when we're attempting to replace a type
during the finalization for CGDebugInfo in clang we would RAUW
a type and it would result in a corrupted MDNode for an
imported declaration.

Testcase pending as reducing has been difficult.

llvm-svn: 202540
2014-02-28 21:27:57 +00:00
Tobias Grosser e8d4c9a2c7 Add 'remark' diagnostic type in LLVM
A 'remark' is information that is not an error or a warning, but rather some
additional information provided to the user. In contrast to a 'note' a 'remark'
is an independent diagnostic, whereas a 'note' always depends on another
diagnostic.

A typical use case for remark nodes is information provided to the user, e.g.
information provided by the vectorizer about loops that have been vectorized.

llvm-svn: 202474
2014-02-28 09:08:45 +00:00
Eric Christopher 75d49db19b Add a debug info code generation level to the compile unit metadata
and update everything accordingly. This can be used to conditionalize
the amount of output in the backend based on the amount of debug
requested/metadata emission scheme by a front end (e.g. clang).

Paired with a commit to clang.

llvm-svn: 202332
2014-02-27 01:24:56 +00:00
Eric Christopher a13839f5ca Remove unnecessary llvm:: qualification.
llvm-svn: 202316
2014-02-26 23:27:16 +00:00
Rafael Espindola e8ae0dba52 Fix typo. Thanks to Roman Divacky for noticing it.
llvm-svn: 202277
2014-02-26 17:05:38 +00:00
Rafael Espindola ae593f1563 Compare DataLayout by Value, not by pointer.
This fixes spurious warnings in llvm-link about the datalayout not matching.

Thanks to Zalman Stern for reporting the bug!

llvm-svn: 202276
2014-02-26 17:02:08 +00:00
Rafael Espindola 667fcb839e Use a sorted array to store the information about a few address spaces.
We don't have any test with more than 6 address spaces, so a DenseMap is
probably not the correct answer.

An unsorted array would also be OK, but we have to sort it for printing anyway.

llvm-svn: 202275
2014-02-26 16:58:35 +00:00
Rafael Espindola 5109fcc0ae Move these functions out of line. A DenseMap lookup is not a simple operation.
llvm-svn: 202274
2014-02-26 16:49:40 +00:00
Nick Lewycky ea08c7090b Remove spurious emacs major mode marker, these should only go on .h files.
llvm-svn: 202222
2014-02-26 03:10:45 +00:00
Paul Robinson 0c12b1d23c Constify the Optnone checks in IR passes.
llvm-svn: 202213
2014-02-26 01:23:26 +00:00
Adrian Prantl b363c30b5d Add DIUnspecifiedParameter, so we can pretty-print it.
This will be used for testcases in CFE.

llvm-svn: 202207
2014-02-25 23:42:11 +00:00
Rafael Espindola 339430f993 Use DataLayout from the module when easily available.
Eventually DataLayoutPass should go away, but for now that is the only easy
way to get a DataLayout in some APIs. This patch only changes the ones that
have easy access to a Module.

One interesting issue with sometimes using DataLayoutPass and sometimes
fetching it from the Module is that we have to make sure they are equivalent.
We can get most of the way there by always constructing the pass with a Module.
In fact, the pass could be changed to point to an external DataLayout instead
of owning one to make this stricter.

Unfortunately, the C api passes a DataLayout, so it has to be up to the caller
to make sure the pass and the module are in sync.

llvm-svn: 202204
2014-02-25 23:25:17 +00:00
Rafael Espindola 248ac13975 Fix resetting the DataLayout in a Module.
No tool does this currently, but as everything else in a module we should be
able to change its DataLayout.

Most of the fix is in DataLayout to make sure it can be reset properly.

The test uses Module::setDataLayout since the fact that we mutate a DataLayout
is an implementation detail. The module could hold a OwningPtr<DataLayout> and
the DataLayout itself could be immutable.

Thanks to Philip Reames for pushing me in the right direction.

llvm-svn: 202198
2014-02-25 22:23:04 +00:00
Rafael Espindola f863ee2949 Store a DataLayout in Module.
Now that DataLayout is not a pass, store one in Module.

Since the C API expects to be able to get a char* to the datalayout description,
we have to keep a std::string somewhere. This patch keeps it in Module and also
uses it to represent modules without a DataLayout.

Once DataLayout is mandatory, we should probably move the string to DataLayout
itself since it won't be necessary anymore to represent the special case of a
module without a DataLayout.

llvm-svn: 202190
2014-02-25 20:01:08 +00:00
Rafael Espindola 935125126c Make DataLayout a plain object, not a pass.
Instead, have a DataLayoutPass that holds one. This will allow parts of LLVM
don't don't handle passes to also use DataLayout.

llvm-svn: 202168
2014-02-25 17:30:31 +00:00
Rafael Espindola 90c7f1cc16 Replace the F_Binary flag with a F_Text one.
After this I will set the default back to F_None. The advantage is that
before this patch forgetting to set F_Binary would corrupt a file on windows.
Forgetting to set F_Text produces one that cannot be read in notepad, which
is a better failure mode :-)

llvm-svn: 202052
2014-02-24 18:20:12 +00:00
Rafael Espindola 7dbcdd08c2 Don't make F_None the default.
This will make it easier to switch the default to being binary files.

llvm-svn: 202042
2014-02-24 15:07:20 +00:00
Quentin Colombet dec8d55b1d Switch the LLVM error reporting on the new diagnostic system.
The LLVM diagnostic are now wired-up in clang (since r200931),
thus the user experience will not be impacted by this change
anymore.

Related to <rdar://problem/15886697>

llvm-svn: 201915
2014-02-22 00:34:11 +00:00
Rafael Espindola daeafb4c2a Add back r201608, r201622, r201624 and r201625
r201608 made llvm corretly handle private globals with MachO. r201622 fixed
a bug in it and r201624 and r201625 were changes for using private linkage,
assuming that llvm would do the right thing.

They all got reverted because r201608 introduced a crash in LTO. This patch
includes a fix for that. The issue was that TargetLoweringObjectFile now has
to be initialized before we can mangle names of private globals. This is
trivially true during the normal codegen pipeline (the asm printer does it),
but LTO has to do it manually.

llvm-svn: 201700
2014-02-19 17:23:20 +00:00
Daniel Jasper 7e198ad862 Revert r201622 and r201608.
This causes the LLVMgold plugin to segfault. More information on the
replies to r201608.

llvm-svn: 201669
2014-02-19 12:26:01 +00:00
Rafael Espindola 09dcc6a536 Fix PR18743.
The IR
@foo = private constant i32 42

is valid, but before this patch we would produce an invalid MachO from it. It
was invalid because it would use an L label in a section where the liker needs
the labels in order to atomize it.

One way of fixing it would be to just reject this IR in the backend, but that
would not be very front end friendly.

What this patch does is use an 'l' prefix in sections that we know the linker
requires symbols for atomizing them. This allows frontends to just use
private and not worry about which sections they go to or how the linker handles
them.

One small issue with this strategy is that now a symbol name depends on the
section, which is not available before codegen. This is not a problem in
practice. The reason is that it only happens with private linkage, which will
be ignored by the non codegen users (llvm-nm and llvm-ar).

llvm-svn: 201608
2014-02-18 22:24:57 +00:00
Rafael Espindola 56b663b6e4 Remove unnecessary typename.
Thanks to Elena Demikhovsky for noticing.

llvm-svn: 201494
2014-02-16 14:12:35 +00:00
Rafael Espindola 30616362d3 Add extern template instantiations of llvm::Calculate.
This should be a small build time improvement in general and fixes
the build on OS X with -DBUILD_SHARED_LIBS=ON.

The issue is that not all users are including GenericDomTreeConstruction.h,
causing undefined references when ld64 managed to hide the
linkonce_odr symbols.

llvm-svn: 201440
2014-02-14 22:36:16 +00:00
Rafael Espindola 79c3ab7c5e Check that GlobalAliases don't have section or alignment.
An alias is always in the section of its aliasee and has the same alignment
(since it has the same address).

llvm-svn: 201354
2014-02-13 18:26:41 +00:00
Rafael Espindola 75ec01f3de Copy dll storage in copyAttributes.
llvm-svn: 201295
2014-02-13 05:11:35 +00:00
Rafael Espindola efedd3aa1b Mark the methods in the Mangler const.
A const ObjectFile needs to be able to provide its name. For an IRObjectFile,
that means being able to call the mangler. Since each IRObjectFile can have
a different mangling, it is natural for them to contain a Mangler which is
therefore also const.

llvm-svn: 201113
2014-02-10 21:25:13 +00:00
Hans Wennborg 4a4be11e62 Copy the ThreadLocalMode in GlobalVariable::copyAttributesFrom
This fixes the oversight from r159077.

llvm-svn: 201098
2014-02-10 17:13:56 +00:00
Paul Robinson af4e64d095 Disable most IR-level transform passes on functions marked 'optnone'.
Ideally only those transform passes that run at -O0 remain enabled,
in reality we get as close as we reasonably can.
Passes are responsible for disabling themselves, it's not the job of
the pass manager to do it for them.

llvm-svn: 200892
2014-02-06 00:07:05 +00:00
Chandler Carruth eedf9fca28 [PM] Don't require analysis results to be const in the new pass manager.
I think this was just over-eagerness on my part. The analysis results
need to often be non-const because they need to (in some cases at least)
be updated by the transformation pass in order to remain correct. It
also makes lazy analyses (a common case) needlessly annoying to write in
order to make their entire state mutable.

llvm-svn: 200881
2014-02-05 21:41:42 +00:00
Alon Mishne 0394c1e615 Test commit
llvm-svn: 200843
2014-02-05 14:23:18 +00:00
Manman Ren 3762808d05 Fix wording of warning message about invalid debug info.
llvm-svn: 200806
2014-02-04 23:49:02 +00:00
Justin Bogner df82c62fcf llvm-cov: Fix include order in GCOV.cpp
llvm-svn: 200796
2014-02-04 21:03:17 +00:00
Justin Bogner c6af350698 llvm-cov: Implement the preserve-paths flag
Until now, when a path in a gcno file included a directory, we would
emit our .gcov file in that directory, whereas gcov always emits the
file in the current directory. In doing so, this implements gcov's
strange name-mangling -p flag, which is needed to avoid clobbering
files when two with the same name exist in different directories.

The path mangling is a bit ugly and only handles unix-like paths, but
it's simple, and it doesn't make any guesses as to how it should
behave outside of what gcov documents. If we decide this should be
cross platform later, we can consider the compatibility implications
then.

llvm-svn: 200754
2014-02-04 10:45:02 +00:00
David Blaikie 2c7a2684f2 DIBuilder: simplify array generation to produce true zero-length arrays
For some anachronistic reason we were producing {i32 0} for zero-length
debug info arrays.

(this change is paired with a Clang change and may cause temporary
buildbot noise)

Let's not.

llvm-svn: 200721
2014-02-03 23:08:54 +00:00
Reid Kleckner f5b76518c9 Implement inalloca codegen for x86 with the new inalloca design
Calls with inalloca are lowered by skipping all stores for arguments
passed in memory and the initial stack adjustment to allocate argument
memory.

Now the frontend is responsible for the memory layout, and the backend
doesn't have to do any work.  As a result these changes are pretty
minimal.

Reviewers: echristo

Differential Revision: http://llvm-reviews.chandlerc.com/D2637

llvm-svn: 200596
2014-01-31 23:50:57 +00:00
Reid Kleckner 1c843228f8 [ms-cxxabi] Add a new calling convention that swaps 'this' and 'sret'
MSVC always places the 'this' parameter for a method first.  The
implicit 'sret' pointer for methods always comes second.  We already
implement this for __thiscall by putting sret parameters on the stack,
but __cdecl methods require putting both parameters on the stack in
opposite order.

Using a special calling convention allows frontends to keep the sret
parameter first, which avoids breaking lots of assumptions in LLVM and
Clang.

Fixes PR15768 with the corresponding change in Clang.

Reviewers: ributzka, majnemer

Differential Revision: http://llvm-reviews.chandlerc.com/D2663

llvm-svn: 200561
2014-01-31 17:41:22 +00:00
Timur Iskhodzhanov f166f6c8d0 Reland r200340 - 'Add line table debug info to COFF files when using a win32 triple'
This incorporates a couple of fixes reviewed at http://llvm-reviews.chandlerc.com/D2651

llvm-svn: 200440
2014-01-30 01:39:17 +00:00
NAKAMURA Takumi b366f01f83 Revert r200340, "Add line table debug info to COFF files when using a win32 triple."
It was incompatible with --target=i686-win32.

llvm-svn: 200375
2014-01-29 06:05:38 +00:00
Rafael Espindola 310f501ef0 Use a raw_stream to implement the mangler.
This is a bit more convenient for some callers, but more importantly, it is
easier to implement correctly. Doing this removes the patching of already
printed data that was used for fastcall, fixing a crash with private fastcall
symbols.

llvm-svn: 200367
2014-01-29 02:30:38 +00:00
Timur Iskhodzhanov 2c659648b3 Add line table debug info to COFF files when using a win32 triple.
Reviewed at http://llvm-reviews.chandlerc.com/D2232

llvm-svn: 200340
2014-01-28 21:33:27 +00:00
Rafael Espindola ab73c493ea Fix pr14893.
When simplifycfg moves an instruction, it must drop metadata it doesn't know
is still valid with the preconditions changes. In particular, it must drop
the range and tbaa metadata.

The patch implements this with an utility function to drop all metadata not
in a white list.

llvm-svn: 200322
2014-01-28 16:56:46 +00:00
Reid Kleckner 2084403afb Fix llvm-dis to print the inalloca bit on allocas.
llvm-svn: 200059
2014-01-25 01:24:06 +00:00
Matt Arsenault fc3c91d0cb Bug 18228 - Fix accepting bitcasts between vectors of pointers with a
different number of elements.

Bitcasts were passing with vectors of pointers with different number of
elements since the number of elements was checking
SrcTy->getVectorNumElements() == SrcTy->getVectorNumElements() which
isn't helpful. The addrspacecast was also wrong, but that case at least
is caught by the verifier. Refactor bitcast and addrspacecast handling
in castIsValid to be more readable and fix this problem.

llvm-svn: 199821
2014-01-22 19:21:33 +00:00
Chandler Carruth 4d35631a6c [PM] Wire up the Verifier for the new pass manager and connect it to the
various opt verifier commandline options.

Mostly mechanical wiring of the verifier to the new pass manager.
Exercises one of the more unusual aspects of it -- a pass can be either
a module or function pass interchangably. If this is ever problematic,
we can make things more constrained, but for things like the verifier
where there is an "obvious" applicability at both levels, it seems
convenient.

This is the next-to-last piece of basic functionality left to make the
opt commandline driving of the new pass manager minimally functional for
testing and further development. There is still a lot to be done there
(notably the factoring into .def files to kill the current boilerplate
code) but it is relatively uninteresting. The only interesting bit left
for minimal functionality is supporting the registration of analyses.
I'm planning on doing that on top of the .def file switch mostly because
the boilerplate for the analyses would be significantly worse.

llvm-svn: 199646
2014-01-20 11:34:08 +00:00
Chandler Carruth 043949d446 [PM] Make the verifier work independently of any pass manager.
This makes the 'verifyFunction' and 'verifyModule' functions totally
independent operations on the LLVM IR. It also cleans up their API a bit
by lifting the abort behavior into their clients and just using an
optional raw_ostream parameter to control printing.

The implementation of the verifier is now just an InstVisitor with no
multiple inheritance. It also is significantly more const-correct, and
hides the const violations internally. The two layers that force us to
break const correctness are building a DomTree and dispatching through
the InstVisitor.

A new VerifierPass is used to implement the legacy pass manager
interface in terms of the other pieces.

The error messages produced may be slightly different now, and we may
have slightly different short circuiting behavior with different usage
models of the verifier, but generally everything works equivalently and
this unblocks wiring the verifier up to the new pass manager.

llvm-svn: 199569
2014-01-19 02:22:18 +00:00
Chandler Carruth 6a93692a34 Add a const lookup routine to get a BlockAddress constant if there is
one, but not create one. This is useful in the verifier when we want to
query the constant if it exists but not create one. To be used in an
upcoming commit.

llvm-svn: 199568
2014-01-19 02:13:50 +00:00
Eli Bendersky 157a97a6a0 Support AddrSpaceCast in ConstantExpr::getAsInstruction.
It's handled similarly to the other casts. CastInst::Create already knows how
to handle it.

llvm-svn: 199565
2014-01-18 22:54:33 +00:00
Benjamin Kramer 5d2ff221f6 Upgrade ConstantFP's negative zero and infinity getters to handle vector types.
Will be used soon.

llvm-svn: 199552
2014-01-18 16:43:06 +00:00
Reid Kleckner 436c42ec3d Add an inalloca flag to allocas
Summary:
The only current use of this flag is to mark the alloca as dynamic, even
if its in the entry block.  The stack adjustment for the alloca can
never be folded into the prologue because the call may clear it and it
has to be allocated at the top of the stack.

Reviewers: majnemer

CC: llvm-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D2571

llvm-svn: 199525
2014-01-17 23:58:17 +00:00
Juergen Ributzka e625013071 Add two new calling conventions for runtime calls
This patch adds two new target-independent calling conventions for runtime
calls - PreserveMost and PreserveAll.
The target-specific implementation for X86-64 is defined as following:
  - Arguments are passed as for the default C calling convention
  - The same applies for the return value(s)
  - PreserveMost preserves all GPRs - except R11
  - PreserveAll preserves all GPRs and all XMMs/YMMs - except R11

Reviewed by Lang and Philip

llvm-svn: 199508
2014-01-17 19:47:03 +00:00
Chandler Carruth bf2b652c05 [PM] [cleanup] Rename some of the Verifier's members, re-arrange them,
and tweak comments prior to more invasive surgery. Also clean up some
other non-doxygen comments, and run clang-format over the parts that are
going to change dramatically in subsequent commits so that those don't
get cluttered with formatting changes.

No functionality changed.

llvm-svn: 199489
2014-01-17 11:09:34 +00:00
Chandler Carruth 7677760ec8 [PM] Remove the preverifier and directly compute the DominatorTree for
the verifier after ensuring the CFG is at least usefully formed.

This fixes a number of problems:
1) The PreVerifier was missing the controls the Verifier provides over
   *how* an invalid module is handled -- it just aborted the program!
   Now it uses the same logic as the Verifier which is significantly
   more library-friendly.
2) The DominatorTree used previously could have been cached and not
   updated due to bugs in prior passes and we would silently use the
   stale tree. This could cause dominance errors to not be as quickly
   diagnosed.
3) We can now (in the next patch) pull the functionality of the verifier
   apart from the pass infrastructure so that you can verify IR without
   having any form of pass manager. This in turn frees the code to share
   logic between old and new pass manager variants.

Along the way I fixed at least one annoying bug -- the state for
'Broken' wasn't being cleared from run to run causing all functions
visited after the first broken function to be marked as broken
regardless of whether *they* were a problem. Fortunately, I don't really
know much of a way to observe this peculiarity.

In case folks are worried about the runtime cost, its negligible.
I looked at running the entire regression test suite (which should be
a relatively good use of the verifier) before and after but was unable
to even measure the time spent on the verifier and there was no
regresion from before to after. I checked both with debug builds and
optimized builds.

llvm-svn: 199487
2014-01-17 10:56:02 +00:00
Reid Kleckner 60d3a835ff Change inalloca rules to make it only apply to the last parameter
This makes things a lot easier, because we can now talk about the
"argument allocation", which allocates all the memory for the call in
one shot.

The only functional change is to the verifier for a feature that hasn't
shipped yet.

llvm-svn: 199434
2014-01-16 22:59:24 +00:00
Quentin Colombet dc0b2ea2bc [opt][PassInfo] Allow opt to run passes that need target machine.
When registering a pass, a pass can now specify a second construct that takes as
argument a pointer to TargetMachine.
The PassInfo class has been updated to reflect that possibility.
If such a constructor exists opt will use it instead of the default constructor
when instantiating the pass.

Since such IR passes are supposed to be rare, no specific support has been
added to this commit to allow an easy registration of such a pass.
In other words, for such pass, the initialization function has to be
hand-written (see CodeGenPrepare for instance).

Now, codegenprepare can be tested using opt:
opt -codegenprepare -mtriple=mytriple input.ll

llvm-svn: 199430
2014-01-16 21:44:34 +00:00
Manman Ren 2ebfb42fe9 Report a warning when dropping outdated debug info metadata.
Use DiagnosticInfo to emit the warning.

llvm-svn: 199346
2014-01-16 01:51:12 +00:00
Rafael Espindola e9fab9b077 Return an error_code from materializeAllPermanently.
llvm-svn: 199275
2014-01-14 23:51:27 +00:00
Rafael Espindola 1d06f7208c Use error_code in Module::materializeAll.
llvm-svn: 199269
2014-01-14 23:02:01 +00:00
Nico Rieck 7157bb765e Decouple dllexport/dllimport from linkage
Representing dllexport/dllimport as distinct linkage types prevents using
these attributes on templates and inline functions.

Instead of introducing further mixed linkage types to include linkonce and
weak ODR, the old import/export linkage types are replaced with a new
separate visibility-like specifier:

  define available_externally dllimport void @f() {}
  @Var = dllexport global i32 1, align 4

Linkage for dllexported globals and functions is now equal to their linkage
without dllexport. Imported globals and functions must be either
declarations with external linkage, or definitions with
AvailableExternallyLinkage.

llvm-svn: 199218
2014-01-14 15:22:47 +00:00
Nico Rieck 9d2e0df049 Revert "Decouple dllexport/dllimport from linkage"
Revert this for now until I fix an issue in Clang with it.

This reverts commit r199204.

llvm-svn: 199207
2014-01-14 12:38:32 +00:00
Nico Rieck e43aaf7967 Decouple dllexport/dllimport from linkage
Representing dllexport/dllimport as distinct linkage types prevents using
these attributes on templates and inline functions.

Instead of introducing further mixed linkage types to include linkonce and
weak ODR, the old import/export linkage types are replaced with a new
separate visibility-like specifier:

  define available_externally dllimport void @f() {}
  @Var = dllexport global i32 1, align 4

Linkage for dllexported globals and functions is now equal to their linkage
without dllexport. Imported globals and functions must be either
declarations with external linkage, or definitions with
AvailableExternallyLinkage.

llvm-svn: 199204
2014-01-14 11:55:03 +00:00
Nico Rieck da881a2742 Fix fastcall mangling of dllimported symbols
fastcall requires @ as global prefix instead of _ but getNameWithPrefix
wrongly assumes the OutName buffer is empty and replaces at index 0.
For imported functions this buffer is pre-filled with "__imp_" resulting
in broken "@_imp_foo@0" mangling.

Instead replace at the proper index. We also never have to prepend the
@-prefix because this fastcall mangling is only used on 32-bit Windows
targets which have _ has global prefix.

llvm-svn: 199203
2014-01-14 11:53:26 +00:00
Mark Seaborn 8271118a65 Fix llc to not reuse spill slots in functions that invoke setjmp()
We need to ensure that StackSlotColoring.cpp does not reuse stack
spill slots in functions that call "returns_twice" functions such as
setjmp(), otherwise this can lead to miscompiled code, because a stack
slot would be clobbered when it's still live.

This was already handled correctly for functions that call setjmp()
(though this wasn't covered by a test), but not for functions that
invoke setjmp().

We fix this by changing callsFunctionThatReturnsTwice() to check for
invoke instructions.

This fixes PR18244.

llvm-svn: 199180
2014-01-14 04:20:01 +00:00
Cameron McInally f0379fa41a Fix uninitialized warning in llvm/lib/IR/DataLayout.cpp.
llvm-svn: 199147
2014-01-13 22:04:55 +00:00
Chandler Carruth 73523021d0 [PM] Split DominatorTree into a concrete analysis result object which
can be used by both the new pass manager and the old.

This removes it from any of the virtual mess of the pass interfaces and
lets it derive cleanly from the DominatorTreeBase<> template. In turn,
tons of boilerplate interface can be nuked and it turns into a very
straightforward extension of the base DominatorTree interface.

The old analysis pass is now a simple wrapper. The names and style of
this split should match the split between CallGraph and
CallGraphWrapperPass. All of the users of DominatorTree have been
updated to match using many of the same tricks as with CallGraph. The
goal is that the common type remains the resulting DominatorTree rather
than the pass. This will make subsequent work toward the new pass
manager significantly easier.

Also in numerous places things became cleaner because I switched from
re-running the pass (!!! mid way through some other passes run!!!) to
directly recomputing the domtree.

llvm-svn: 199104
2014-01-13 13:07:17 +00:00
Chandler Carruth e509db410a [PM] Pull the generic graph algorithms and data structures for dominator
trees into the Support library.

These are all expressed in terms of the generic GraphTraits and CFG,
with no reliance on any concrete IR types. Putting them in support
clarifies that and makes the fact that the static analyzer in Clang uses
them much more sane. When moving the Dominators.h file into the IR
library I claimed that this was the right home for it but not something
I planned to work on. Oops.

So why am I doing this? It happens to be one step toward breaking the
requirement that IR verification can only be performed from inside of
a pass context, which completely blocks the implementation of
verification for the new pass manager infrastructure. Fixing it will
also allow removing the concept of the "preverify" step (WTF???) and
allow the verifier to cleanly flag functions which fail verification in
a way that precludes even computing dominance information. Currently,
that results in a fatal error even when you ask the verifier to not
fatally error. It's awesome like that.

The yak shaving will continue...

llvm-svn: 199095
2014-01-13 10:52:56 +00:00
Chandler Carruth 5ad5f15cff [cleanup] Move the Dominators.h and Verifier.h headers into the IR
directory. These passes are already defined in the IR library, and it
doesn't make any sense to have the headers in Analysis.

Long term, I think there is going to be a much better way to divide
these matters. The dominators code should be fully separated into the
abstract graph algorithm and have that put in Support where it becomes
obvious that evn Clang's CFGBlock's can use it. Then the verifier can
manually construct dominance information from the Support-driven
interface while the Analysis library can provide a pass which both
caches, reconstructs, and supports a nice update API.

But those are very long term, and so I don't want to leave the really
confusing structure until that day arrives.

llvm-svn: 199082
2014-01-13 09:26:24 +00:00
Chandler Carruth 52eef8876e [PM] Add module and function printing passes for the new pass manager.
This implements the legacy passes in terms of the new ones. It adds
basic testing using explicit runs of the passes. Next up will be wiring
the basic output mechanism of opt up when the new pass manager is
engaged unless bitcode writing is requested.

llvm-svn: 199049
2014-01-12 12:15:39 +00:00
Chandler Carruth e0af664cd8 [PM] Simplify the IR printing passes significantly now that a narrower
API is exposed.

This removes the support for deleting the ostream, switches the member
and constructor order arround to be consistent with the creation
routines, and switches to using references.

llvm-svn: 199047
2014-01-12 11:40:03 +00:00
Chandler Carruth 9d805139bd [PM] Simplify the interface exposed for IR printing passes.
Nothing was using the ability of the pass to delete the raw_ostream it
printed to, and nothing was trying to pass it a pointer to the
raw_ostream. Also, the function variant had a different order of
arguments from all of the others which was just really confusing. Now
the interface accepts a reference, doesn't offer to delete it, and uses
a consistent order. The implementation of the printing passes haven't
been updated with this simplification, this is just the API switch.

llvm-svn: 199044
2014-01-12 11:30:46 +00:00
Chandler Carruth 3dd261d0c9 [PM] Run clang-format and remove redundant or obvious comments before
the heavy factoring needed to share logic between the new pass manager
and the old.

llvm-svn: 199043
2014-01-12 11:16:01 +00:00
Chandler Carruth b8ddc7043c [PM] Rename the IR printing pass header to a more generic and correct
name to match the source file which I got earlier. Update the include
sites. Also modernize the comments in the header to use the more
recommended doxygen style.

llvm-svn: 199041
2014-01-12 11:10:32 +00:00
Chandler Carruth a13f27cc34 [PM] Add names to passes under the new pass manager, and a debug output
mode that can be used to debug the execution of everything.

No support for analyses here, that will come later. This already helps
show parts of the opt commandline integration that isn't working. Tests
of that will start using it as the bugs are fixed.

llvm-svn: 199004
2014-01-11 11:52:05 +00:00
Rafael Espindola af77e1205a Use 'w' instead of 'c' to represent the win32 mangling.
This change was requested to avoid confusion if we ever support non windows coff
systems.

llvm-svn: 198938
2014-01-10 13:42:12 +00:00
Nadav Rotem 032b39e40d Re-remove dead code.
This reverts r198854.

llvm-svn: 198879
2014-01-09 19:22:07 +00:00
Nadav Rotem d677b310e8 Revert r198819 - "Remove dead code."
llvm-svn: 198854
2014-01-09 07:50:34 +00:00
Chandler Carruth 12e9d2b5c1 [PM] Rename this source file to something a bit more generic before
I add support for the new pass manager to it.

llvm-svn: 198838
2014-01-09 02:39:45 +00:00
Chandler Carruth d48cdbf0c3 Put the functionality for printing a value to a raw_ostream as an
operand into the Value interface just like the core print method is.
That gives a more conistent organization to the IR printing interfaces
-- they are all attached to the IR objects themselves. Also, update all
the users.

This removes the 'Writer.h' header which contained only a single function
declaration.

llvm-svn: 198836
2014-01-09 02:29:41 +00:00
Rafael Espindola 5e10aaeb18 Remove dead code.
llvm-svn: 198819
2014-01-09 00:32:54 +00:00
Chandler Carruth 98f3de8880 Remove vestigal bits of MC from the mangler. It no longer uses this, and
having the include could cause weird layering problems between the IR
and MC libraries.

llvm-svn: 198796
2014-01-08 21:59:22 +00:00
Rafael Espindola 894843cb4e Move the llvm mangler to lib/IR.
This makes it available to tools that don't link with target (like llvm-ar).

llvm-svn: 198708
2014-01-07 21:19:40 +00:00
Cameron McInally 8af9eac331 Fix uninitialized variable warning in DataLayout.
llvm-svn: 198702
2014-01-07 19:51:38 +00:00
Chandler Carruth 9aca918df9 Move the LLVM IR asm writer header files into the IR directory, as they
are part of the core IR library in order to support dumping and other
basic functionality.

Rename the 'Assembly' include directory to 'AsmParser' to match the
library name and the only functionality left their -- printing has been
in the core IR library for quite some time.

Update all of the #includes to match.

All of this started because I wanted to have the layering in good shape
before I started adding support for printing LLVM IR using the new pass
infrastructure, and commandline support for the new pass infrastructure.

llvm-svn: 198688
2014-01-07 12:34:26 +00:00
Chandler Carruth 8a8cd2bab9 Re-sort all of the includes with ./utils/sort_includes.py so that
subsequent changes are easier to review. About to fix some layering
issues, and wanted to separate out the necessary churn.

Also comment and sink the include of "Windows.h" in three .inc files to
match the usage in Memory.inc.

llvm-svn: 198685
2014-01-07 11:48:04 +00:00
Rafael Espindola abdd726ce5 Improve documentation of the 'a' specifier and the '<abi>:<pref>' align pair.
llvm-svn: 198636
2014-01-06 21:40:24 +00:00
Rafael Espindola 58873566b3 Make the llvm mangler depend only on DataLayout.
Before this patch any program that wanted to know the final symbol name of a
GlobalValue had to link with Target.

This patch implements a compromise solution where the mangler uses DataLayout.
This way, any tool that already links with Target (llc, clang) gets the exact
behavior as before and new IR files can be mangled without linking with Target.

With this patch the mangler is constructed with just a DataLayout and DataLayout
is extended to include the information the Mangler needs.

llvm-svn: 198438
2014-01-03 19:21:54 +00:00
Matt Arsenault 00436ea156 Allow addrspacecast in global aliases
llvm-svn: 198349
2014-01-02 20:55:01 +00:00
Rafael Espindola 6994fdf33c Remove the 's' DataLayout specification
During the years there have been some attempts at figuring out how to
align byval arguments. A look at the commit log suggests that they
were

* Use the ABI alignment.
* When that was not sufficient for x86-64, I added the 's' specification to
  DataLayout.
* When that was not sufficient Evan added the virtual getByValTypeAlignment.
* When even that was not sufficient, we just got the FE to add the alignment
  to the byval.

This patch is just a simple cleanup that removes my first attempt at fixing the
problem. I also added an AArch64 implementation of getByValTypeAlignment to
make sure this patch is a nop. I also left the 's' parsing for backward
compatibility.

I will send a short email to llvmdev about the change for anyone maintaining
an out of tree target.

llvm-svn: 198287
2014-01-01 22:29:43 +00:00
Nick Lewycky 2d4ba2ebba Fold vector selects with undef elements in the condition. Fixes PR18319.
Patch by Ilia Filippov!

llvm-svn: 198267
2013-12-31 19:30:47 +00:00
Craig Topper 8c4ac147ec Mark some Type and EVT methods as LLVM_READONLY.
llvm-svn: 198115
2013-12-28 16:17:26 +00:00
David Blaikie ac2002973c DebugInfo: Remove dead code, DICompositeType::addMember(DIDescriptor D)
It's no longer necessary to lazily add members to the DICompositeType
member list. Instead any lazy members (special member functions and
member template instantiations) are added to the parent late based on
their context link, the same way that nested types have always been
handled (never being in the member list - just added to the parent DIE
lazily based on context).

Clang's been updated not to use this function anymore as it improves
type unit consistency by never emitting lazy members in type units.

llvm-svn: 198079
2013-12-27 19:11:52 +00:00
Mark Lacey 1d7c97eff3 Fix typo in assert message: s/load/store
llvm-svn: 197846
2013-12-21 00:00:49 +00:00
Rafael Espindola e23b87746a Make this array const.
llvm-svn: 197814
2013-12-20 15:21:32 +00:00
Dmitri Gribenko 8da5f7a96d When parsing data layout string looking for endianness, use the correct default
llvm-svn: 197771
2013-12-20 02:54:35 +00:00
Dmitri Gribenko 5362ad579e Correctly apply the default pointer size
llvm-svn: 197770
2013-12-20 02:46:23 +00:00
Rafael Espindola 458a4851dd Change getStringRepresentation to skip defaults.
I have a pending change for clang to use getStringRepresentation to check
that its DataLayout is in sync with llvm's.

getStringRepresentation is not called from llvm itself, so far it is mostly
a debugging aid, so the shorter strings are an independent improvement.

llvm-svn: 197740
2013-12-19 23:03:03 +00:00
NAKAMURA Takumi 6e3c4235be GCOV.cpp: Fix format strings, %lf. Don't use %lf to double.
llvm-svn: 197663
2013-12-19 08:46:28 +00:00
Reid Kleckner a534a38130 Begin adding docs and IR-level support for the inalloca attribute
The inalloca attribute is designed to support passing C++ objects by
value in the Microsoft C++ ABI.  It behaves the same as byval, except
that it always implies that the argument is in memory and that the bytes
are never copied.  This attribute allows the caller to take the address
of an outgoing argument's memory and execute arbitrary code to store
into it.

This patch adds basic IR support, docs, and verification.  It does not
attempt to implement any lowering or fix any possibly broken transforms.

When this patch lands, a complete description of this feature should
appear at http://llvm.org/docs/InAlloca.html .

Differential Revision: http://llvm-reviews.chandlerc.com/D2173

llvm-svn: 197645
2013-12-19 02:14:12 +00:00
Yuchen Wu bb6a477131 llvm-cov: Added -f option for function summaries.
Similar to the file summaries, the function summaries output line,
branching and call statistics. The file summaries have been moved
outside the initial loop so that all of the function summaries can be
outputted before file summaries.

Also updated test cases.

llvm-svn: 197633
2013-12-19 00:29:25 +00:00
Adrian Prantl 99c7af26b7 Debug info: Implement (rvalue) reference qualifiers for C++11 non-static
member functions. Paired commit with CFE.

rdar://problem/15356637

llvm-svn: 197613
2013-12-18 21:48:19 +00:00
Yuchen Wu 8256ee6d4a llvm-cov: Print coverage summary to STDOUT.
File summaries will now be optionally outputted which will give line,
branching and call coverage info. Unfortunately, clang's current
instrumentation does not give enough information to deduce function
calls, something that gcc is able to do. Thus, no calls are always
outputted to be consistent with gcov output.

Also updated tests.

llvm-svn: 197606
2013-12-18 21:12:51 +00:00
Yuchen Wu c9b2dcdbee llvm-cov: s/(.*)Executed/\1Exec/
llvm-svn: 197595
2013-12-18 18:46:25 +00:00
Yuchen Wu 73dc38187b llvm-cov: Added -c option for branch counts.
This will cause llvm-cov to output branch counts instead of branch
probabilities. -b must be enabled.

Also updated tests.

llvm-svn: 197594
2013-12-18 18:40:15 +00:00
Tobias Grosser 84db1e744d DiagnosticInfo: Add missing namespace
llvm-svn: 197556
2013-12-18 10:12:06 +00:00
Quentin Colombet 98e79a0604 [DiagnosticPrinter] Use the appropriate method to print a Twine object in a
raw_ostream.

llvm-svn: 197531
2013-12-17 22:35:07 +00:00
Quentin Colombet b4c44d239c Add warning capabilities in LLVM.
This reapplies r197438 and fixes the link-time circular dependency between
IR and Support. The fix consists in moving the diagnostic support into IR.

The patch adds a new LLVMContext::diagnose that can be used to communicate to
the front-end, if any, that something of interest happened.
The diagnostics are supported by a new abstraction, the DiagnosticInfo class.
The base class contains the following information:
- The kind of the report: What this is about.
- The severity of the report: How bad this is.

This patch also adds 2 classes:
- DiagnosticInfoInlineAsm: For inline asm reporting. Basically, this diagnostic
will be used to switch to the new diagnostic API for LLVMContext::emitError.
- DiagnosticStackSize: For stack size reporting. Comes as a replacement of the
hard coded warning in PEI.

This patch also features dynamic diagnostic identifiers. In other words plugins
can use this infrastructure for their own diagnostics (for more details, see
getNextAvailablePluginDiagnosticKind).

This patch introduces a new DiagnosticHandlerTy and a new DiagnosticContext in
the LLVMContext that should be set by the front-end to be able to map these
diagnostics in its own system.

http://llvm-reviews.chandlerc.com/D2376
<rdar://problem/15515174>

llvm-svn: 197508
2013-12-17 17:47:22 +00:00
Quentin Colombet 382b135d92 Revert r197438 and r197447 until we figure out how to avoid circular dependency at link time
llvm-svn: 197451
2013-12-17 01:19:59 +00:00
Quentin Colombet 66673f4075 Add warning capabilities in LLVM.
The patch adds a new LLVMContext::diagnose that can be used to communicate to
the front-end, if any, that something of interest happened.
The diagnostics are supported by a new abstraction, the DiagnosticInfo class.
The base class contains the following information:
- The kind of the report: What this is about.
- The severity of the report: How bad this is.

This patch also adds 2 classes:
- DiagnosticInfoInlineAsm: For inline asm reporting. Basically, this diagnostic
will be used to switch to the new diagnostic API for LLVMContext::emitError.
- DiagnosticStackSize: For stack size reporting. Comes as a replacement of the
hard coded warning in PEI.

This patch also features dynamic diagnostic identifiers. In other words plugins
can use this infrastructure for their own diagnostics (for more details, see
getNextAvailablePluginDiagnosticKind).

This patch introduces a new DiagnosticHandlerTy and a new DiagnosticContext in
the LLVMContext that should be set by the front-end to be able to map these
diagnostics in its own system.

http://llvm-reviews.chandlerc.com/D2376
<rdar://problem/15515174>

llvm-svn: 197438
2013-12-16 23:22:51 +00:00
Yuchen Wu 66d93b82ac llvm-cov: Added -u option for unconditional branch info.
Outputs branch information for unconditional branches in addition to
conditional branches. -b option must be enabled.

Also updated tests.

llvm-svn: 197432
2013-12-16 22:14:02 +00:00
Yuchen Wu 8742a28560 llvm-cov: Removed extra semicolon from ;;.
llvm-svn: 197418
2013-12-16 20:03:11 +00:00
Michael Kuperstein e31b486cdd Fix AsmWriter's handling of SPIR calling conventions. Patch by Boaz Ouriel.
llvm-svn: 197335
2013-12-15 10:01:20 +00:00
Rafael Espindola f39136c39f Pointer sizes are stored in Bytes. Fix variables names to say so.
Also update for the current naming style.

llvm-svn: 197283
2013-12-13 23:15:20 +00:00
Yuchen Wu 342714c11c llvm-cov: Added -b option for branch probabilities.
This option tells llvm-cov to print out branch probabilities when
a basic block contains multiple branches. It also prints out some
function summary info including the number of times the function enters,
the percent of time it returns, and how many blocks were executed.

Also updated tests.

llvm-svn: 197198
2013-12-13 01:15:07 +00:00
NAKAMURA Takumi 7ce0fe015e GCOV.cpp: Use PRIu64 instead of %lu.
llvm-svn: 196882
2013-12-10 05:39:40 +00:00
Yuchen Wu 8c6bb5f4d4 llvm-cov: Added -a option for block data.
Similar to gcov, llvm-cov will now print out the block count at the end
of each block. Multiple blocks can end on the same line.

One computational difference is by using -a, llvm-cov will no longer
simply add the block counts together to form a line count. Instead, it
will take the maximum of the block counts on that line. This has a
similar effect to what gcov does, but generates more correct counts in
certain scenarios.

Also updated tests.

llvm-svn: 196856
2013-12-10 01:02:07 +00:00
Matt Arsenault 21f38f4539 Add getBitCastOrAddrSpaceCast
llvm-svn: 196637
2013-12-07 02:58:41 +00:00
Rafael Espindola ba7df70418 Remove unused value.
llvm-svn: 196635
2013-12-07 02:27:52 +00:00
Kaelyn Uhrain 4e8656077c Fix the segfault reported in PR 11990.
The sefault occurs due to an infinite loop when the verifier tries to
determine the size of a type of the form "%rt = type { %rt }" while
checking an alloca of the type.

llvm-svn: 196626
2013-12-07 00:13:34 +00:00
Rafael Espindola 1a68f2383f micro optimization: isSizedDerivedType is only called with arrays, vectors and structs.
llvm-svn: 196604
2013-12-06 20:12:19 +00:00
Yuchen Wu 4c9f19d682 llvm-cov: Further improved error messages.
llvm-svn: 196542
2013-12-05 22:02:33 +00:00
Yuchen Wu c3e6424722 llvm-cov: Conformed headers.
llvm-svn: 196541
2013-12-05 22:02:29 +00:00
Yuchen Wu 9af3938b51 llvm-cov: Changed extension from .llcov to .gcov.
llvm-svn: 196530
2013-12-05 20:45:36 +00:00
Matt Arsenault a68c9adca6 Use isIntrinsic() instead of checking for "llvm."
llvm-svn: 196473
2013-12-05 06:05:43 +00:00
Alp Toker f907b891da Correct word hyphenations
This patch tries to avoid unrelated changes other than fixing a few
hyphen-related ambiguities and contractions in nearby lines.

llvm-svn: 196471
2013-12-05 05:44:44 +00:00
Daniel Jasper 87a24d5c27 Un-revert r196358: "llvm-cov: Added support for function checksums."
And add the proper fix.

llvm-svn: 196367
2013-12-04 08:57:17 +00:00
Daniel Jasper c176b5d1d6 Revert r196358: "llvm-cov: Added support for function checksums."
This currently breaks clang/test/CodeGen/code-coverage.c. The root cause
is that the newly introduced access to Funcs[j] is out of bounds.

llvm-svn: 196365
2013-12-04 08:23:33 +00:00
Yuchen Wu 06655f3570 llvm-cov: Added support for function checksums.
The function checksums are hashed from the concatenation of the function
name and line number.

llvm-svn: 196358
2013-12-04 06:00:17 +00:00
Yuchen Wu 5752997c04 llvm-cov: Added checks for ident, checksum, name.
Added additional checks for the Identifier, CfgChecksum and Name for
each GCOVFunction. Also added function names in error messages.

llvm-svn: 196356
2013-12-04 05:42:28 +00:00
Yuchen Wu 21517e4b89 llvm-cov: Capitalized GCNO and GCDA for consistency.
llvm-svn: 196354
2013-12-04 05:07:36 +00:00
Yuchen Wu bec4e90769 llvm-cov: Split GCOVFile's read into GCNO and GCDA.
This splits the file-scope read() function into readGCNO() and
readGCDA(). Also broke file format read into functions that first read
the file type, then check the version.

llvm-svn: 196353
2013-12-04 04:49:23 +00:00
Yuchen Wu 1c0681637e llvm-cov: Cleaned up print() function slightly.
Changed while to for loop. Removed unnecessary if statement.

llvm-svn: 196194
2013-12-03 01:35:31 +00:00
Yuchen Wu 26326ad396 llvm-cov: Removed output to STDOUT/specified file.
Instead of asking the user to specify a single file to output coverage
info and defaulting to STDOUT, llvm-cov now creates files for each
source file with a naming system of: <source filename> + ".llcov".

This is what gcov does and although it can clutter the working directory
with numerous coverage files, it will be easier to hook the llvm-cov
output to tools which operate on this assumption (such as lcov).

llvm-svn: 196184
2013-12-03 00:57:11 +00:00
Yuchen Wu 8f1c881abc llvm-cov: Store blocks rather than counts per line.
Each line stores all the blocks that execute on that line, instead of
only storing the line counts previously accumulated. This provides more
information for each line, and will be useful for options in enabling
block and branch information.

llvm-svn: 196177
2013-12-03 00:38:21 +00:00
Yuchen Wu 8ad9b04ff2 llvm-cov: Added edge struct for traversal in block.
Added GCOVEdge which are simple structs owned by the GCOVFunction that
stores the source and destination GCOVBlocks, as well as the counts.
Changed GCOVBlocks so that it stores a vector of source GCOVEdges and a
vector of destination GCOVEdges, rather than just the block number.

Storing the block number was only useful for knowing the number of edges
and for debug info. Using a struct is useful for traversing the edges,
especially back edges which may be needed later.

llvm-svn: 196175
2013-12-03 00:24:44 +00:00
Yuchen Wu ba71833846 llvm-cov: Split up reading of GCNO and GCDA files.
There are now two functions: readGCNO() and readGCDA().

llvm-svn: 196173
2013-12-03 00:15:49 +00:00
Manman Ren bd4daf826f Debug Info: rename getDebugInfoVersionFromModule to getDebugMetadataVersionFromModule.
Suggested by Eric.

llvm-svn: 196172
2013-12-03 00:12:14 +00:00
Manman Ren 8b4306ce05 Debug Info: drop debug info via upgrading path if version number does not match.
Add a helper function getDebugInfoVersionFromModule to return the debug info
version number for a module.

"Verifier/module-flags-1.ll" checks for verification errors.
It will seg fault when calling getDebugInfoVersionFromModule because of the
incorrect format for module flags in the testing case. We make
getModuleFlagsMetadata more robust by checking for error conditions.

PR17982

llvm-svn: 196158
2013-12-02 21:29:56 +00:00
Renato Golin 1388f07053 Fix spurious return introduced by my earlier patch to DebugInfo
llvm-svn: 195775
2013-11-26 18:54:37 +00:00
Renato Golin 47f46fd42c Add return to DIType::Verify
Code scanner ran by Sylvestre Ledru got a no_return bug
in DebugInfo.cpp. Adding the return statements that
should be there.

llvm-svn: 195772
2013-11-26 16:47:00 +00:00
Chandler Carruth 16ea68e806 [PM] Factor the overwhelming majority of the interface boiler plate out
of the two analysis managers into a CRTP base class that can be shared
and re-used in building any analysis manager. This will in turn simplify
adding yet another analysis manager to the system.

The base class provides all of the interface sugar for the analysis
manager delegating the functionality back through DerivedT methods which
operate on simple pass IDs. It also provides the pass registration,
storage, and lookup system which is common across the various
formulations of analysis managers.

llvm-svn: 195747
2013-11-26 11:24:37 +00:00
Chandler Carruth c1ff9ed6e0 [PM] Complete the cross-layer interfaces with a Module-to-Function
proxy. This lets a function pass query a module analysis manager.
However, the interface is const to indicate that only cached results can
be safely queried.

With this, I think the new pass manager is largely functionally complete
for modules and analyses. Still lots to test, and need to generalize to
SCCs and Loops, and need to build an adaptor layer to support the use of
existing Pass objects in the new managers.

llvm-svn: 195538
2013-11-23 01:25:07 +00:00
Chandler Carruth de9afd845b [PM] Add support to the analysis managers to query explicitly for cached
results.

This is the last piece of infrastructure needed to effectively support
querying *up* the analysis layers. The next step will be to introduce
a proxy which provides access to those layers with appropriate use of
const to direct queries to the safe interface.

llvm-svn: 195525
2013-11-23 00:38:42 +00:00
Chandler Carruth bceeb22905 [PM] Switch the downward invalidation to be incremental where only the
one function's analyses are invalidated at a time. Also switch the
preservation of the proxy to *fully* preserve the lower (function)
analyses.

Combined, this gets both upward and downward analysis invalidation to
a point I'm happy with:

- A function pass invalidates its function analyses, and its parent's
  module analyses.
- A module pass invalidates all of its functions' analyses including the
  set of which functions are in the module.
- A function pass can preserve a module analysis pass.
- If all function passes preserve a module analysis pass, that
  preservation persists. If any doesn't the module analysis is
  invalidated.
- A module pass can opt into managing *all* function analysis
  invalidation itself or *none*.
- The conservative default is none, and the proxy takes the maximally
  conservative approach that works even if the set of functions has
  changed.
- If a module pass opts into managing function analysis invalidation it
  has to propagate the invalidation itself, the proxy just does nothing.

The only thing really missing is a way to query for a cached analysis or
nothing at all. With this, function passes can more safely request
a cached module analysis pass without fear of it accidentally running
part way through.

llvm-svn: 195519
2013-11-22 23:38:07 +00:00
Manman Ren cb14bbcc48 Debug Info: move StripDebugInfo from StripSymbols.cpp to DebugInfo.cpp.
We can share the implementation between StripSymbols and dropping debug info
for metadata versions that do not match.

Also update the comments to match the implementation. A follow-on patch will
drop the "Debug Info Version" module flag in StripDebugInfo.

llvm-svn: 195505
2013-11-22 22:06:31 +00:00