Commit Graph

8939 Commits

Author SHA1 Message Date
Benjamin Kramer 439ee9d7bc Make helper functions static. NFC.
llvm-svn: 236315
2015-05-01 13:59:53 +00:00
Justin Bogner f43d8e1cce InstrProf: This call does nothing, remove it
llvm-svn: 236298
2015-05-01 01:02:17 +00:00
Justin Bogner a71e681792 InstrProf: Support for setting profile output from command line
This change is the third of 3 patches to add support for specifying
the profile output from the command line via -fprofile-instr-generate=<path>,
where the specified output path/file will be overridden by the
LLVM_PROFILE_FILE environment variable.

This patch adds the necessary support to the clang frontend, and adds a
new test.

The compiler-rt and llvm parts are r236055 and r236288, respectively.

Patch by Teresa Johnson. Thanks!

llvm-svn: 236289
2015-04-30 23:49:42 +00:00
Richard Trieu d1ffdda418 Fix -Wpessimizing-move by removing call to std::move
llvm-svn: 236281
2015-04-30 23:13:52 +00:00
Justin Bogner 2e5d484597 InstrProf: Fix handling of profile counters in the body of range based for
We were assigning the counter for the body of the loop to the loop
variable initialization for some reason here, but our tests completely
lacked coverage for range-for loops. This fixes that and makes the
logic generally more similar to the logic for a regular for.

llvm-svn: 236277
2015-04-30 22:58:28 +00:00
Reid Kleckner cb7a0a0562 Revert most of r236271, leaving only the datalayout change in lib/Basic/Targets.cpp
llvm-svn: 236274
2015-04-30 22:29:25 +00:00
Reid Kleckner af67602e14 Use 4 byte preferred aggregate alignment in datalayout on x86 Win32
llvm-svn: 236271
2015-04-30 22:13:05 +00:00
Justin Bogner 1587432d1f InstrProf: Make sure coverage propagates out of foreach loops correctly
llvm-svn: 236264
2015-04-30 21:31:02 +00:00
Alexey Bataev 36c1eb95e0 [OPENMP] Codegen for 'private' clause in 'task' directive.
For tasks codegen for private/firstprivate variables are different rather than for other directives.

1. Build an internal structure of privates for each private variable:
struct .kmp_privates_t. {
  Ty1 var1;
  ...
  Tyn varn;
};
2. Add a new field to kmp_task_t type with list of privates.
struct kmp_task_t {
  void *              shareds;
  kmp_routine_entry_t routine;
  kmp_int32           part_id;
  kmp_routine_entry_t destructors;
  .kmp_privates_t.    privates;
};
3. Create a function with destructors calls for all privates after end of task region.
kmp_int32 .omp_task_destructor.(kmp_int32 gtid, kmp_task_t *tt) {
  ~Destructor(&tt->privates.var1);
  ...
  ~Destructor(&tt->privates.varn);
  return 0;
}
4. Perform default initialization of all private fields (no initialization for POD data, default constructor calls for classes) + provide address of a destructor function after kmpc_omp_task_alloc() and before kmpc_omp_task() calls.
kmp_task_t *new_task = __kmpc_omp_task_alloc(ident_t *, kmp_int32 gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds, kmp_routine_entry_t *task_entry);

DefaultConstructor(new_task->privates.var1);
new_task->shareds.var1_ref = &new_task->privates.var1;
...
DefaultConstructor(new_task->privates.varn);
new_task->shareds.varn_ref = &new_task->privates.varn;

new_task->destructors = .omp_task_destructor.;
kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid, kmp_task_t *new_task)


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

llvm-svn: 236207
2015-04-30 06:51:57 +00:00
Alexey Bataev 66beaa9349 [OPENMP] Fixed codegen for 'copyprivate' clause.
Fixed initialization of 'single' region completion + changed type of the third argument of __kmpc_copyprivate() runtime function to size_t.

llvm-svn: 236198
2015-04-30 03:47:32 +00:00
Reid Kleckner be9843ce54 Revert r236128, LLVM isn't falling back in the right way
llvm-svn: 236167
2015-04-29 21:55:21 +00:00
David Blaikie 881b23402e [opaque pointer type] update for LLVM API change
llvm-svn: 236161
2015-04-29 21:22:47 +00:00
Richard Smith 419bd09415 PR23373: A defaulted union copy constructor that is not trivial must still be
emitted as a memcpy.

llvm-svn: 236142
2015-04-29 19:26:57 +00:00
Reid Kleckner 0bb12a8981 Re-land r236052, the linker errors were fixed by LLVM r236123
Basic __finally blocks don't cause linker errors anymore (although they
are miscompiled).

llvm-svn: 236128
2015-04-29 17:17:17 +00:00
Adrian Prantl 00820abf02 Debug Info: Represent local anonymous unions as anonymous unions
and as artificial local variables in the debug info.

This is a follow-up to r236059. We can't get rid of the local variables
entirely because the gdb buildbot depends on them, but we can mark them
as artificial while still emitting the correct debug info. As I learned
from review comments other compilers also follow this model.

A paired commit in LLVM temporarily relaxes the debug info verifier to
not check the integrity of DW_OP_bit_pieces of artificial variables.

rdar://problem/20730771

llvm-svn: 236125
2015-04-29 16:52:31 +00:00
Duncan P. N. Exon Smith 9dd4e4e63a DebugInfo: Metadata constructs now start with DI*
LLVM r236120 renamed debug info IR constructs to use a `DI` prefix, now
that the `DIDescriptor` hierarchy has been gone for about a week.  This
commit was generated using the rename-md-di-nodes.sh upgrade script
attached to PR23080, followed by running clang-format-diff.py on the
`lib/` portion of the patch.

llvm-svn: 236121
2015-04-29 16:40:08 +00:00
Adrian Prantl 0d82089233 Revert "Debug Info: Represent local anonymous unions as anonymous unions"
This reverts commit r236059 as it breaks the gdb buildbot.

llvm-svn: 236110
2015-04-29 15:05:50 +00:00
Bradley Smith dfddebcfb9 Revert code changes made under r235976.
This issue was fixed elsewhere in r235396 in a more general way, hence these
changes no longer do anything. Keep the testcase however, to ensure that we
don't regress this for ARM.

llvm-svn: 236104
2015-04-29 14:32:06 +00:00
Alexey Bataev 19fa2c3b66 [OPENMP] Fix crash on reductions codegen for short circuit reduction operations.
llvm-svn: 236084
2015-04-29 05:21:03 +00:00
Nico Weber ea721b64df Revert r236052, it caused linker errors when building 32-bit applications.
llvm-svn: 236082
2015-04-29 03:08:32 +00:00
Adrian Prantl 0a4ddc180b Debug Info: Represent local anonymous unions as anonymous unions
in the debug info. This patch deletes a hack that emits the members
of local anonymous unions as local variables.

Besides being morally wrong, the existing representation using local
variables breaks internal assumptions about the local variables' storage
size.

Compiling

```
   void fn1() {
     union {
       int i;
       char c;
     };
     i = c;
   }

```

with -g -O3 -verify will cause the verifier to fail after SROA splits
the 32-bit storage for the "local variable" c into two pieces because the
second piece is clearly outside the 8-bit range that is expected for a
variable of type char. Given the choice I'd rather fix the debug
representation than weaken the verifier.

Debuggers generally already know how to deal with anonymous unions when
they are members of C++ record types, but they may have problems finding
the local anonymous struct members in the expression evaluator.

rdar://problem/20730771

llvm-svn: 236059
2015-04-28 23:01:24 +00:00
Reid Kleckner ddd40964f0 [SEH] Add 32-bit lowering code for __try
This is just the clang-side of 32-bit SEH. LLVM still needs work, and it
will determinstically fail to compile until it's feature complete.

On x86, all outlined handlers have no parameters, but they do implicitly
take the EBP value passed in and use it to address locals of the parent
frame. We model this with llvm.frameaddress(1).

This works (mostly), but __finally block inlining can break it. For now,
we apply the 'noinline' attribute. If we really want to inline __finally
blocks on 32-bit x86, we should teach the inliner how to untangle
frameescape and framerecover.

Promote the error diagnostic from codegen to sema. It now rejects SEH on
non-Windows platforms. LLVM doesn't implement SEH on non-x86 Windows
platforms, but there's nothing preventing it.

llvm-svn: 236052
2015-04-28 22:19:32 +00:00
Sean Callanan 61ea0571ac Implemented support for testing the ASTImporter's
ability to generate code that CodeGen likes.  Test
cases can use this functionality by calling

// RUN: %clang_cc1 -emit-obj -o /dev/null -ast-merge %t.1.ast -ast-merge %t.2.ast %s

llvm-svn: 236011
2015-04-28 18:24:12 +00:00
Nico Weber 20b0ce3abd Fix typo in comment.
llvm-svn: 236010
2015-04-28 18:19:18 +00:00
Alexey Bataev 6111469a4a [OPENMP] Fix crash on loop control vars explicitly marked as private.
It is allowed to mark loop control vars as private in 'private' or 'lastprivate' clause, so no need to assert here.

llvm-svn: 235985
2015-04-28 13:20:05 +00:00
Bradley Smith ba945626b0 [ARM/AArch64] Enforce alignment for bitfielded structs
When creating a global variable with a type of a struct with bitfields, we must
forcibly set the alignment of the global from the RecordDecl. We must do this so
that the proper bitfield alignment makes its way down to LLVM, since clang will
mangle the bitfields into one large type.

llvm-svn: 235976
2015-04-28 11:24:54 +00:00
Justin Bogner f959febf7a InstrProf: Mark code regions after throw expressions as unreachable
We weren't setting regions as being unreachable after C++ throw
expressions, leading to incorrect count propagations.

llvm-svn: 235967
2015-04-28 06:31:55 +00:00
John McCall f3e86a7a55 ms_struct does not imply the MS base-layout ABI; separate these
conditions in the IRGen struct layout code.

rdar://20636558

llvm-svn: 235949
2015-04-28 00:17:18 +00:00
Eric Christopher f37ab1ca73 Always add the target-cpu and target-features sets if they're non-null.
This makes sure that the front end is specific about what they're expecting
the backend to produce. Update a FIXME with the idea that the target-features
could be more precise using backend knowledge.

llvm-svn: 235936
2015-04-27 23:11:34 +00:00
Artem Belevich 0488d1e4ba [cuda] treat file scope __asm as __host__ and ignore it during device-side compilation.
Currently clang emits file-scope asm during *both* host and device
compilation modes which is usually a wrong thing to do.

There's no way to attach any attribute to an __asm statement, so
there's no way to differentiate between host-side and device-side
file-scope asm.  This patch makes clang to match nvcc behavior and
emit file-scope-asm only during host-side compilation.

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

llvm-svn: 235905
2015-04-27 18:52:00 +00:00
Alexey Bataev c925aa3ab8 [OPENMP] Simplified iteration over clauses, NFC.
llvm-svn: 235838
2015-04-27 08:00:32 +00:00
Alexey Bataev 8b8e202a33 [OPENMP] Codegen for 'taskwait' directive.
Emit the following code for 'taskwait' directive within tied task:
call i32 @__kmpc_omp_taskwait(<loc>, i32 <thread_id>);
Differential Revision: http://reviews.llvm.org/D9245

llvm-svn: 235836
2015-04-27 05:22:09 +00:00
Alexey Bataev a89adf22db [OPENMP] Codegen for 'reduction' clause in 'sections' directive.
Emit a code for reduction clause. Next code should be emitted for reductions:

static kmp_critical_name lock = { 0 };

void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
    *(Type0*)lhs[0] = ReductionOperation0(*(Type0*)lhs[0], *(Type0*)rhs[0]);
      ...
        *(Type<n>-1*)lhs[<n>-1] =
          ReductionOperation<n>-1(*(Type<n>-1*)lhs[<n>-1],
            *(Type<n>-1*)rhs[<n>-1]);
}

...
void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n>-1]};
switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList), RedList, reduce_func, &<lock>)) {
case 1:
  <LHSExprs>[0] = ReductionOperation0(*<LHSExprs>[0], *<RHSExprs>[0]);
  ...
  <LHSExprs>[<n>-1] = ReductionOperation<n>-1(*<LHSExprs>[<n>-1], *<RHSExprs>[<n>-1]);
  __kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
  break;
case 2:
  Atomic(<LHSExprs>[0] = ReductionOperation0(*<LHSExprs>[0], *<RHSExprs>[0]));
  ...
  Atomic(<LHSExprs>[<n>-1] = ReductionOperation<n>-1(*<LHSExprs>[<n>-1], *<RHSExprs>[<n>-1]));
  break;
default:;
}
Reduction variables are a kind of a private variables, they have private copies, but initial values are chosen in accordance with the reduction operation.
If sections directive has only single section, then original shared variables are used instead with barrier at the end of the directive.
Differential Revision: http://reviews.llvm.org/D9242

llvm-svn: 235835
2015-04-27 05:04:13 +00:00
Alexey Bataev 9efc03b6f7 [OPENMP] Codegen for 'lastprivate' clause in 'sections' directive.
#pragma omp sections lastprivate(<var>)
<BODY>;
This construct is translated into something like:

<last_iter> = alloca i32
<init for lastprivates>;
<last_iter> = 0
; No initializer for simple variables or a default constructor is called for objects.
; For arrays perform element by element initialization by the call of the default constructor.
...
OMP_FOR_START(...,<last_iter>, ..); sets <last_iter> to 1 if this is the last iteration.
<BODY>
...
OMP_FOR_END
if (<last_iter> != 0) {
  <final copy for lastprivate>; Update original variable with the lastprivate value.
}
call __kmpc_cancel_barrier() ; an implicit barrier to avoid possible data race.
If there is only one section, there is no special code generation, original shared variables are used + barrier is emitted at the end of the directive.
Differential Revision: http://reviews.llvm.org/D9240

llvm-svn: 235834
2015-04-27 04:34:03 +00:00
Alexey Bataev 7387083d95 [OPENMP] Codegen for 'private' clause in 'sections' directive.
If there are 2 or more sections in a 'section' directive the following code is generated:

<default init for privates>
@__kmpc_for_static_init_4();
<BODY for sections directive>
@__kmpc_for_static_fini()
If there is only one section, the following code is generated:

if (@__kmpc_single()) {
  <default init for privates>
  @__kmpc_end_single();
}
Differential Revision: http://reviews.llvm.org/D9239

llvm-svn: 235833
2015-04-27 04:12:12 +00:00
Alexey Bataev 59c654aa43 [OPENMP] Codegen for 'private' clause in 'single' directive.
Emit the following code for 'single' directive with 'private' clause:

if (@__kmpc_single()) {
  <default init for privates>
  @__kmpc_end_single();
}
Differential Revision: http://reviews.llvm.org/D9238

llvm-svn: 235832
2015-04-27 03:48:52 +00:00
John McCall 9fc700e76d Correctly handle zero-sized but non-empty base classes in IRGen.
Fixes rdar://20621065.

A more elegant fix would preclude this case by defining the
rules such that zero-size classes are always formally empty.
I believe the only extensions which create zero-size classes
right now are flexible arrays and zero-length arrays; it's
not abstractly unreasonable to say that those don't count
as members for the purposes of emptiness, just as zero-width
bitfields don't count.  But that's an ABI-affecting change
and requires further discussion; in the meantime, let's not
assert / miscompile.

llvm-svn: 235815
2015-04-26 04:43:26 +00:00
Justin Bogner e3654ce7ab InstrProf: Fix coverage maps for conditional operators
This fixes a crash when we're emitting coverage and a macro appears
between two binary conditional operators, ie, "foo ?: MACRO ?: bar",
and fixes the interaction of macros and conditional operators in
general.

llvm-svn: 235793
2015-04-24 23:37:57 +00:00
Alexey Bataev 5521d78532 [OPENMP] Codegen for 'firstprivate' clause in 'single' directive.
Emit the following code for 'single' directive with 'firtstprivate' clause:

if (@__kmpc_single()) {
  <init for firstprivates>
  @__kmpc_end_single();
}
@__kmpc_cancel_barrier(); // To avoid data race in firstprivate init
Differential Revision: http://reviews.llvm.org/D9223

llvm-svn: 235694
2015-04-24 04:21:15 +00:00
Alexey Bataev 8b72566eec [OPENMP] Do not emit implicit barrier for single directive with 'copyprivate' clause(s).
Runtime function for 'copyprivate' directive generates implicit barriers, so no need to emit it.
Differential Revision: http://reviews.llvm.org/D9215

llvm-svn: 235692
2015-04-24 04:00:39 +00:00
Alexey Bataev 2cb9b95adf [OPENMP] Codegen for 'firstprivate' clause in 'sections' directive.
If there are 2 or more sections in a 'section' directive the following code is generated:

<init for firstprivates>
@__kmpc_cancel_barrier();// To avoid data race in firstprivate init
@__kmpc_for_static_init_4();
<BODY for sections directive>
@__kmpc_for_static_fini()
If there is only one section, the following code is generated:

if (@__kmpc_single()) {
  <init for firstprivates>
  @__kmpc_end_single();
}
@__kmpc_cancel_barrier(); // To avoid data race in firstprivate init
Differential Revision: http://reviews.llvm.org/D9214

llvm-svn: 235691
2015-04-24 03:37:03 +00:00
David Majnemer 5fd33e0d1a Replace getPointeeType()->isFunctionType with isMemberDataPointerType
llvm-svn: 235682
2015-04-24 01:25:08 +00:00
David Majnemer e154456d4a [MS ABI] Fix the preferred alignment of member pointers
Member pointers in the MS ABI have different alignment depending on
whether they were created on the stack or live in a record.

llvm-svn: 235681
2015-04-24 01:25:05 +00:00
Justin Bogner 66242d6c5e InstrProf: Stop using RegionCounter outside of CodeGenPGO (NFC)
The RegionCounter type does a lot of legwork, but most of it is only
meaningful within the implementation of CodeGenPGO. The uses elsewhere
in CodeGen generally just want to increment or read counters, so do
that directly.

llvm-svn: 235664
2015-04-23 23:06:47 +00:00
Reid Kleckner 1ef49218b3 Don't emit lifetime markers when msan is enabled
In r235553, Clang started emitting lifetime markers more often. This
caused false negative in MSan, because MSan only poisons all allocas
once at function entry. Eventually, MSan should poison allocas at
lifetime start and probably also lifetime end, but until then, let's not
emit markers that aren't going to be useful.

llvm-svn: 235613
2015-04-23 18:07:13 +00:00
Alexey Bataev 5e018f9e29 [OPENMP] Codegen for 'atomic capture'.
Adds codegen for 'atomic capture' constructs with the following forms of expressions/statements:

v = x binop= expr;
v = x++;
v = ++x;
v = x--;
v = --x;
v = x = x binop expr;
v = x = expr binop x;
{v = x; x = binop= expr;}
{v = x; x++;}
{v = x; ++x;}
{v = x; x--;}
{v = x; --x;}
{x = x binop expr; v = x;}
{x binop= expr; v = x;}
{x++; v = x;}
{++x; v = x;}
{x--; v = x;}
{--x; v = x;}
{x = x binop expr; v = x;}
{x = expr binop x; v = x;}
{v = x; x = expr;}
If x and expr are integer and binop is associative or x is a LHS in a RHS of the assignment expression, and atomics are allowed for type of x on the target platform atomicrmw instruction is emitted.
Otherwise compare-and-swap sequence is emitted.
Update of 'v' is not required to be be atomic with respect to the read or write of the 'x'.

bb:
...
atomic load <x>
cont:
<expected> = phi [ <x>, label %bb ], [ <new_failed>, %cont ]
<desired> = <expected> binop <expr>
<res> = cmpxchg atomic &<x>, desired, expected
<new_failed> = <res>.field1;
br <res>field2, label %exit, label %cont
exit:
atomic store <old/new x>, <v>
...
Differential Revision: http://reviews.llvm.org/D9049

llvm-svn: 235573
2015-04-23 06:35:10 +00:00
Alexey Samsonov f624650354 Unify the way we report overflow in increment/decrement operator.
Summary:
Make sure signed overflow in "x--" is checked with
llvm.ssub.with.overflow intrinsic and is reported as:
  "-2147483648 - 1 cannot be represented in type 'int'"
instead of:
  "-2147483648 + -1 cannot be represented in type 'int'"
, like we do for unsigned overflow.

Test Plan: clang + compiler-rt regression test suite

Reviewers: rsmith

Subscribers: cfe-commits

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

llvm-svn: 235568
2015-04-23 01:50:45 +00:00
Justin Bogner 60d852ba5b InstrProf: Fix a shadowing error that would break length of profile names
We try to use the member variable "FuncName" here, but we've also used
that name as a parameter. This ends with us getting the length of the
function name wrong when we generate the coverage data.

llvm-svn: 235565
2015-04-23 00:31:16 +00:00
Reid Kleckner 7d4bc9c0fb [WinEH] Don't emit an exceptional cleanup for llvm.eh.endcatch
These extra endcatch markers aren't helping identify regions to outline,
so let's get rid of them.  LLVM outlines (more or less) from begincatch
to endcatch.  Any unwind edge from an enclosed invoke is a transition to
a new exception handler, which has it's own outlining markers.

llvm-svn: 235562
2015-04-22 23:39:15 +00:00
David Majnemer dc012fa266 Revert "Revert r234581, it might have caused a few miscompiles in Chromium."
This reverts commit r234700.  It turns out that the lifetime markers
were not the cause of Chromium failing but a bug which was uncovered by
optimizations exposed by the markers.

llvm-svn: 235553
2015-04-22 21:38:15 +00:00
Reid Kleckner 787dc438c9 Set normal LLVM function attributes on global initializer functions
Otherwise -fno-omit-frame-pointer and other flags like it aren't
applied.

Basic idea taken from Gao's patch, thanks!

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

llvm-svn: 235537
2015-04-22 19:37:32 +00:00
Alexey Bataev 1d67713b44 [OPENMP] Codegen for 'if' clause in 'task' directive.
If condition evaluates to true, the code executes task by calling @__kmpc_omp_task() runtime function.
If condition evaluates to false, the code executes serial version of the code by executing the following code:

call void @__kmpc_omp_task_begin_if0(<loc>, <threadid>, <task_t_ptr, returned by @__kmpc_omp_task_alloc()>);
proxy_task_entry(<gtid>, <task_t_ptr, returned by @__kmpc_omp_task_alloc()>);
call void @__kmpc_omp_task_complete_if0(<loc>, <threadid>, <task_t_ptr, returned by @__kmpc_omp_task_alloc()>);
Also it checks if the condition is constant and if it is constant it evaluates its value and then generates either parallel version of the code (if the condition evaluates to true), or the serial version of the code (if the condition evaluates to false).
Differential Revision: http://reviews.llvm.org/D9143

llvm-svn: 235507
2015-04-22 13:57:31 +00:00
Alexey Bataev 7ebe5fddac [OPENMP] Codegen for 'reduction' clause in 'for' directive.
Emit a code for reduction clause. Next code should be emitted for reductions:

static kmp_critical_name lock = { 0 };

void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
    *(Type0*)lhs[0] = ReductionOperation0(*(Type0*)lhs[0], *(Type0*)rhs[0]);
      ...
        *(Type<n>-1*)lhs[<n>-1] =
          ReductionOperation<n>-1(*(Type<n>-1*)lhs[<n>-1],
            *(Type<n>-1*)rhs[<n>-1]);
}

 ...
  void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n>-1]};
   switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList), RedList, reduce_func, &<lock>)) {
      case 1:
        <LHSExprs>[0] = ReductionOperation0(*<LHSExprs>[0], *<RHSExprs>[0]);
          ...
            <LHSExprs>[<n>-1] = ReductionOperation<n>-1(*<LHSExprs>[<n>-1], *<RHSExprs>[<n>-1]);
             __kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
              break;
               case 2:
                 Atomic(<LHSExprs>[0] = ReductionOperation0(*<LHSExprs>[0], *<RHSExprs>[0]));
                   ...
                     Atomic(<LHSExprs>[<n>-1] = ReductionOperation<n>-1(*<LHSExprs>[<n>-1], *<RHSExprs>[<n>-1]));
                      break;
                       default:;
                        }
                        Reduction variables are a kind of a private variables, they have private copies, but initial values are chosen in accordance with the reduction operation.
Differential Revision: http://reviews.llvm.org/D9139

llvm-svn: 235506
2015-04-22 13:43:03 +00:00
Alexey Bataev 50a6458870 [OPENMP] Codegen for 'private' clause in 'for' directive.
This patch generates helper variables which used as a private copies of the corresponding original variables inside an OpenMP 'for' directive. These generated variables are initialized by default (with the default constructor, if any). In OpenMP region references to original variables are replaced by the references to these private helper variables.
Differential Revision: http://reviews.llvm.org/D9106

llvm-svn: 235503
2015-04-22 12:24:45 +00:00
Alexey Bataev 62dbb979c0 [OPENMP] Fix use of unsigned counters in loops with zero trip count.
Patch fixes bugs in codegen for loops with unsigned counters and zero trip count. Previously preconditions for all loops were built using logic (Upper - Lower) > 0. But if the loop is a loop with zero trip count, then Upper - Lower is < 0 only for signed integer, for unsigned we're running into an underflow situation.
In this patch we're using original Lower<Upper condition to check that loop body can be executed at least once. Also this allows to skip code generation for loops, if it is known that preconditions for the loop are always false.
Differential Revision: http://reviews.llvm.org/D9103

llvm-svn: 235500
2015-04-22 11:59:37 +00:00
Alexey Bataev 98eb6e3d41 [OPENMP] Codegen for 'ordered' directive.
Add codegen for 'ordered' directive:

__kmpc_ordered(ident_t *, gtid);
<associated statement>;
__kmpc_end_ordered(ident_t *, gtid);
Also for 'for' directives with the dynamic scheduling and an 'ordered' clause added a call to '__kmpc_dispatch_fini_(4|8)[u]()' function after increment expression for loop control variable:

while(__kmpc_dispatch_next(&LB, &UB)) {
  idx = LB;
  while (idx <= UB) { BODY; ++idx;
    __kmpc_dispatch_fini_(4|8)[u](); // For ordered loops only.
  } // inner loop
}
Differential Revision: http://reviews.llvm.org/D9070

llvm-svn: 235496
2015-04-22 11:15:40 +00:00
Artem Belevich 7093e40641 [cuda] Allow using integral non-type template parameters as launch_bounds attribute arguments.
- Changed CUDALaunchBounds arguments from integers to Expr* so they can
   be saved in AST for instantiation.
 - Added support for template instantiation of launch_bounds attrubute.
 - Moved evaluation of launch_bounds arguments to NVPTXTargetCodeGenInfo::
   SetTargetAttributes() where it can be done after template instantiation.
 - Added a warning on negative launch_bounds arguments.
 - Amended test cases.

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

llvm-svn: 235452
2015-04-21 22:55:54 +00:00
Duncan P. N. Exon Smith 8e47da4f5b DebugInfo: Prepare for removal of DIArray and DITypeArray typedefs
An upcoming LLVM commit will remove the `DIArray` and `DITypeArray`
typedefs that shadow `DebugNodeArray` and `MDTypeRefArray`,
respectively.  Use those types directly.

llvm-svn: 235412
2015-04-21 20:07:29 +00:00
Duncan P. N. Exon Smith dadc2b627d DebugInfo: Prepare for deletion of DIDescriptor subclasses
An upcoming LLVM commit will delete all the remaining subclasses of (the
already deleted) `DIDescriptor`.  Stop using them.

llvm-svn: 235403
2015-04-21 18:43:54 +00:00
Ulrich Weigand 4608438386 Provide alignment info on LLVM external symbols
Code in CodeGenModule::GetOrCreateLLVMGlobal that sets up GlobalValue
object for LLVM external symbols has this comment:

    // FIXME: This code is overly simple and should be merged with other global
    // handling.

One part does seems to be "overly simple" currently is that this code
never sets any alignment info on the GlobalValue, so that the emitted
IR does not have any align attribute on external globals.  This can
lead to unnecessarily inefficient code generation.

This patch adds a GV->setAlignment call to set alignment info.

llvm-svn: 235396
2015-04-21 17:27:59 +00:00
Duncan P. N. Exon Smith a7fbcbfe00 DebugInfo: Prepare for deletion of subclasses of DIScope
Prepare for the deletion in LLVM of the subclasses of (the already
deleted) `DIScope` by using the raw pointers they were wrapping
directly.

llvm-svn: 235355
2015-04-20 22:09:57 +00:00
Duncan P. N. Exon Smith c09c548bf9 DebugInfo: Prepare for deletion of subclasses of DIType
Subclasses of (the already deleted) `DIType` will be deleted by an
upcoming LLVM commit.  Remove references.

While `DICompositeType` wraps `MDCompositeTypeBase` and `DIDerivedType`
wraps `MDDerivedTypeBase`, most uses of each really meant the more
specific `MDCompositeType` and `MDDerivedType`.  I updated accordingly.

llvm-svn: 235350
2015-04-20 21:17:26 +00:00
Duncan P. N. Exon Smith 0b6c369697 DebugInfo: Prepare for deletion of DIType
`DIType` is going to be deleted by an upcoming LLVM commit, so replace
uses with `MDType*`.

llvm-svn: 235330
2015-04-20 18:51:48 +00:00
Duncan P. N. Exon Smith fc8d9d9a20 DebugInfo: Prepare for deletion of DIScope
An upcoming LLVM commit will delete `DIScope`, so update users to
`MDScope*`.

llvm-svn: 235326
2015-04-20 18:32:15 +00:00
Benjamin Kramer 5df7c1a4eb Make helper function static. NFC.
llvm-svn: 235253
2015-04-18 10:00:10 +00:00
Duncan P. N. Exon Smith edc76a7ede Remove dead code, NFC
llvm-svn: 235246
2015-04-18 00:26:49 +00:00
Duncan P. N. Exon Smith d899f6e4de DebugInfo: Prepare for deletion of DIDescriptor
Prepare for upcoming LLVM change to delete `DIDescriptor`.

llvm-svn: 235245
2015-04-18 00:07:30 +00:00
Pete Cooper 635b509dee Change AArch64 i128 returns to use [2 x i64] when possible.
Something like { void*, void * } would be passed to a function as a [2 x i64], but returned as an i128.  This patch unifies the 2 behaviours so that we also return it as a [2 x i64].

This is better for the quality of the IR, and the size of the final LLVM binary as we tend to want to insert/extract values from these types and do so with the insert/extract instructions is less IR than shifting, truncating, and or'ing values.

Reviewed by Tim Northover.

llvm-svn: 235231
2015-04-17 22:16:24 +00:00
David Majnemer 2ccba83401 [MS ABI] Use the right types for filter and finally blocks
The type for abnormal_termination can't be an i1, it an i8.
Filter functions return 'LONG', not 'int'.

llvm-svn: 235161
2015-04-17 06:57:25 +00:00
Duncan P. N. Exon Smith 4078ad4122 DebugInfo: Update for LLVM API change in DIBuilder (r235111)
LLVM r235111 changed the `DIBuilder` API to stop using `DIDescriptor`
and its subclasses.  Rolled into this was some tightening up of types:

  - Scopes: `DIDescriptor` => `MDScope*`.
  - Generic debug nodes: `DIDescriptor` => `DebugNode*`.
  - Subroutine types: `DICompositeType` => `MDSubroutineType*`.
  - Composite types: `DICompositeType` => `MDCompositeType*`.

Note that `DIDescriptor` wraps `MDNode`, and `DICompositeType` wraps
`MDCompositeTypeBase`.

It's this new type strictness that requires changes here.

llvm-svn: 235112
2015-04-16 16:36:45 +00:00
Alexey Bataev f56f98c925 [OPENMP] Codegen for 'copyin' clause in 'parallel' directive.
Emits the following code for the clause at the beginning of the outlined function for implicit threads:

if (<not a master thread>) {
  ...
  <thread local copy of var> = <master thread local copy of var>;
  ...
}
<sync point>;
Checking for a non-master thread is performed by comparing of the address of the thread local variable with the address of the master's variable. Master thread always uses original variables, so you always know the address of the variable in the master thread.
Differential Revision: http://reviews.llvm.org/D9026

llvm-svn: 235075
2015-04-16 05:39:01 +00:00
Alexey Bataev 38e8953352 [OPENMP] Codegen for 'lastprivate' clause in 'for' directive.
#pragma omp for lastprivate(<var>)
for (i = a; i < b; ++b)
  <BODY>;

This construct is translated into something like:

  <last_iter> = alloca i32
  <lastprivate_var> = alloca <type>
  <last_iter> = 0
  ; No initializer for simple variables or a default constructor is called for objects.
  ; For arrays perform element by element initialization by the call of the default constructor.
  ...
  OMP_FOR_START(...,<last_iter>, ..); sets <last_iter> to 1 if this is the last iteration.
  <BODY>
  ...
  OMP_FOR_END
  if (<last_iter> != 0) {
    <var> = <lastprivate_var> ; Update original variable with the lastprivate value.
  }
  call __kmpc_cancel_barrier() ; an implicit barrier to avoid possible data race.

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

llvm-svn: 235074
2015-04-16 04:54:05 +00:00
Duncan P. N. Exon Smith 526ab07e3c DebugInfo: Prepare for DIDescriptor to be gutted in LLVM
All the API is about to be dropped from `DIDescriptor` in LLVM, so stop
using it.

llvm-svn: 235068
2015-04-16 01:53:23 +00:00
Duncan P. N. Exon Smith 373ee85966 DebugInfo: Prepare for DIScope to be gutted in LLVM
An upcoming LLVM commit will gut `DIScope`, so just use `MDScope*`
directly.

llvm-svn: 235066
2015-04-16 01:36:36 +00:00
Duncan P. N. Exon Smith 4caa7f2a9c DebugInfo: Prepare for DIType to be gutted
`DIType` and its subclasses are about to be gutted in LLVM.  Prepare for
that by treating these like the raw pointers they wrap.

llvm-svn: 235063
2015-04-16 01:00:56 +00:00
Duncan P. N. Exon Smith b747023081 DebugInfo: Prepare for LLVM change removing DIType::isValid()
This is being replaced with a null check.

llvm-svn: 235058
2015-04-15 23:48:50 +00:00
Duncan P. N. Exon Smith 798d565fd8 DebugInfo: Prepare for LLVM gutting DICompileUnit/DIFile
An upcoming LLVM commit will gut `DICompileUnit` and `DIFile`, so start
treating them more like pointers.

llvm-svn: 235054
2015-04-15 23:19:15 +00:00
Nico Weber 608e768d8d Don't crash when a selectany symbol would get common linkage
Things can't both be in comdats and have common linkage, so never give things
in comdats common linkage. Common linkage is only used in .c files, and the
only thing that can trigger a comdat in c is selectany from what I can tell.
Fixes PR23243.

Also address an over-the-shoulder review comment from rnk by moving the
hasAttr<SelectAnyAttr>() in Decl.cpp around a bit. It only makes a minor
difference for selectany on global variables, so it goes well with the rest of
this patch.

http://reviews.llvm.org/D9042

llvm-svn: 235053
2015-04-15 23:04:24 +00:00
Duncan P. N. Exon Smith fe88b48632 DebugInfo: Pass DebugLocs when creating intrinsics
Update for LLVM API change r235041 that makes `DIBuilder` require a
`DebugLoc` to create a debug info intrinsic.

llvm-svn: 235042
2015-04-15 21:18:30 +00:00
Renato Golin c640ff63e2 Revert "[CodeGen] Fix crash with duplicated mangled name."
This reverts commit r234767, as it was breaking all ARM buildbots for two days and the
assert is not in the code, making it difficult to spot the error, which would keep the
bots red for a few more days. New errors were silently introduced because of this bug,
and we don't want this to escalate.

llvm-svn: 234983
2015-04-15 08:44:40 +00:00
Alexey Bataev 69c62a9bdb [OPENMP] Codegen for 'firstprivate' clause in 'for' directive.
Adds proper codegen for 'firstprivate' clause in for directive. Initially codegen for 'firstprivate' clause was implemented for 'parallel' directive only.
Also this patch emits sync point only after initialization of firstprivate variables, not all private variables. This sync point is not required for privates, lastprivates etc., only for initialization of firstprivate variables.
Differential Revision: http://reviews.llvm.org/D8660

llvm-svn: 234978
2015-04-15 04:52:20 +00:00
Duncan P. N. Exon Smith fda02091e6 uselistorder: Remove dead include
Forgot to remove the include in r234970

llvm-svn: 234972
2015-04-15 03:04:45 +00:00
Duncan P. N. Exon Smith bb9cadf4eb uselistorder: -mllvm -preserve-ll-use-list-order => -emit-llvm-uselists
Follow up to r234962, start respecting `-emit-llvm-uselists even for
LLVM assembly.  Note that the driver never passes this flag; this is
just a interface convenience/consistency for those using `-cc1`
directly.  This required LLVM r234969 (and predecessors).

llvm-svn: 234970
2015-04-15 02:45:28 +00:00
Richard Trieu b58413323d Change range-based for-loops to be -Wrange-loop-analysis clean.
No functionality change.

llvm-svn: 234964
2015-04-15 01:21:42 +00:00
Duncan P. N. Exon Smith bb61825cd5 uselistorder: -mllvm -preserve-bc-use-list-order => -emit-llvm-uselists
Stop relying on `cl::opt` to pass along the driver's decision to
preserve use-lists.  Create a new `-cc1` option called
`-emit-llvm-uselists` that does the right thing (when -emit-llvm-bc).
Note that despite its generic name, it *doesn't* do the right thing when
-emit-llvm (LLVM assembly) yet.  I'll hook that up soon.

This doesn't really change the behaviour of the driver.  The default is
still to preserve use-lists for `clang -emit-llvm` and `clang
-save-temps`, and nothing else.  But it stops relying on global state
(and also is a nicer interface for hackers using `clang -cc1`).

llvm-svn: 234962
2015-04-15 01:16:18 +00:00
Reid Kleckner e07140eb3f Move the logic to avoid double global emission from Sema to CodeGen
Reverts the code changes from r234675 but keeps the test case.

We were already maintaining a DenseMap of globals with dynamic
initializers anyway.

Fixes the test case from PR23234.

llvm-svn: 234961
2015-04-15 01:08:06 +00:00
Duncan P. N. Exon Smith 58927f1aa2 uselistorder: Update for LLVM API change in r234959
Now that `addBitcodeWriterPass()` requires an explicit bit to preserve
use-list order, send it in from `clang`.  It looks like I'll be able to
push this up to the `-cc1` options.

llvm-svn: 234960
2015-04-15 00:36:14 +00:00
Reid Kleckner ebaf28d13d Reland r234613 (and follow-ups 234614, 234616, 234618)
The frameescape intrinsic cannot be inlined, so I fixed the inliner in
r234937. This should address PR23216.

llvm-svn: 234942
2015-04-14 20:59:00 +00:00
Rafael Espindola 2f16bc1095 Use raw_pwrite_stream in clang.
This is a small improvement to -emit-pth and allows llvm to start requiring it.

llvm-svn: 234897
2015-04-14 15:15:49 +00:00
Alexey Bataev 420d45b2dd [OPENMP] Fixed codegen for arrays in 'copyprivate' clause.
Fixed a bug with codegen of variables with array types specified in 'copyprivate' clause of 'single' directive.
Differential Revision: http://reviews.llvm.org/D8914

llvm-svn: 234856
2015-04-14 05:11:24 +00:00
Alexey Bataev 68adb7da1a [OPENMP] Initial codegen for 'parallel sections' directive.
Emits code for outlined 'parallel' directive with the implicitly inlined 'sections' directive:

...
call __kmpc_fork_call(..., outlined_function, ...);
...

define internal void outlined_function(...) {
    <code for implicit sections directive>;
}
Differential Revision: http://reviews.llvm.org/D8997

llvm-svn: 234849
2015-04-14 03:29:22 +00:00
Duncan P. N. Exon Smith 87afdeb8f5 DebugInfo: Prepare for DISubprogram/DILexicalBlock* to be gutted
An upcoming LLVM commit will remove this API, so stop using it.  Just
access the raw pointers using `operator->()`.

llvm-svn: 234848
2015-04-14 03:24:14 +00:00
Nico Weber ad108337cf Revert r234613 (and follow-ups 234614, 234616, 234618), it caused PR23216.
llvm-svn: 234789
2015-04-13 20:04:22 +00:00
Nico Weber f2a39a7b4e Revert r234786, it contained a bunch of stuff I did not mean to commit.
llvm-svn: 234787
2015-04-13 20:03:03 +00:00
Nico Weber b31abb05fb Revert r234613 (and follow-ups 234614, 234616, 234618), it caused PR23216.
llvm-svn: 234786
2015-04-13 20:01:20 +00:00
Argyrios Kyrtzidis 6f1fadf989 [CodeGen] Fix crash with duplicated mangled name.
Patch by Yunzhong Gao!

llvm-svn: 234767
2015-04-13 17:40:46 +00:00
Justin Bogner 1c21c28b9e InstrProf: Simplify getStmtCount by using an Optional
llvm-svn: 234750
2015-04-13 12:23:19 +00:00
Alexey Bataev 671605e85b [OPENMP] Initial codegen for 'parallel for' directive.
Allows generation of combined 'parallel for' directive that represents 'parallel' region with internal implicit 'for' worksharing region.
Differential Revision: http://reviews.llvm.org/D8631

llvm-svn: 234722
2015-04-13 05:28:11 +00:00
Nico Weber 1c565c31b1 Revert r234581, it might have caused a few miscompiles in Chromium.
If the revert helps, I'll get a repro this Monday.  Else I'll put the change
back in.

llvm-svn: 234700
2015-04-11 23:51:38 +00:00
Duncan P. N. Exon Smith 497d4d465b DebugInfo: Switch from replaceAllUsesWith() to replaceTemporary()
Stop using `DIDescriptor`'s wrapper around
`MDNode::replaceAllUsesWith()` (which is going away).  The new home for
this logic is `DIBuilder::replaceTemporary()`, added in LLVM r234695.

llvm-svn: 234696
2015-04-11 19:05:04 +00:00
Benjamin Kramer 8017237277 Remove empty non-virtual destructors or mark them =default when non-public
These add no value but can make a class non-trivially copyable. NFC.

llvm-svn: 234689
2015-04-11 15:58:30 +00:00
Alexander Kornienko 34eb20725d Use 'override/final' instead of 'virtual' for overridden methods
Summary:
The patch is generated using clang-tidy misc-use-override check.

This command was used:

  tools/clang/tools/extra/clang-tidy/tool/run-clang-tidy.py \
    -checks='-*,misc-use-override' -header-filter='llvm|clang' -j=32 -fix

Reviewers: dblaikie

Reviewed By: dblaikie

Subscribers: klimek, cfe-commits

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

llvm-svn: 234678
2015-04-11 02:00:23 +00:00
Ahmed Bougacha 256a869d31 [Driver] Properly support -mglobal-merge using explicit options.
Follow-up to r234666.  With this, the -m[no-]global-merge options
have the expected behavior. Previously, -mglobal-merge was ignored,
and there was no way of enabling the optimization.

llvm-svn: 234668
2015-04-11 00:10:44 +00:00
Reid Kleckner 11859afd5f [SEH] Re-land r234532, but use internal linkage for all SEH helpers
Even though these symbols are in a comdat group, the Microsoft linker
really wants them to have internal linkage.

I'm planning to tweak the mangling in a follow-up change. This is a
straight revert with a 1-line fix.

llvm-svn: 234613
2015-04-10 17:34:52 +00:00
Benjamin Kramer c19cde119d Don't rely on implicit CallSite construction.
llvm-svn: 234600
2015-04-10 14:49:31 +00:00
Alexey Bataev 794ba0dcb7 [OPENMP] Codegen for 'reduction' clause in 'parallel' directive.
Emit a code for reduction clause. Next code should be emitted for reductions:

static kmp_critical_name lock = { 0 };

void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
  ...
  *(Type<i> *)lhs[i] = RedOp<i>(*(Type<i> *)lhs[i], *(Type<i> *)rhs[i]);
  ...
}

... void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n> - 1]};
switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList), RedList, reduce_func, &<lock>)) {
case 1:
  ...
  <LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
  ...
  __kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
  break;
case 2:
  ...
  Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
  ...
  break;
default:
  ;
}
Reduction variables are a kind of a private variables, they have private copies, but initial values are chosen in accordance with the reduction operation.

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

llvm-svn: 234583
2015-04-10 10:43:45 +00:00
Arnaud A. de Grandmaison 047a686d53 Remove threshold for inserting lifetime markers for named temporaries
Now that TailRecursionElimination has been fixed with r222354, the
threshold on size for lifetime marker insertion can be removed. This
only affects named temporary though, as the patch for unnamed temporaries
is still in progress.

My previous commit (r222993) was not handling debuginfo correctly, but
this could only be seen with some asan tests. Basically, lifetime markers
are just instrumentation for the compiler's usage and should not affect
debug information; however, the cleanup infrastructure was assuming it
contained only destructors, i.e. actual code to be executed, and was
setting the breakpoint for the end of the function to the closing '}', and
not the return statement, in order to show some destructors have been
called when leaving the function. This is wrong when the cleanups are only
lifetime markers, and this is now fixed.

llvm-svn: 234581
2015-04-10 10:13:52 +00:00
Alexey Bataev 3e6124bc4d [OPENMP] Fixed cleanup of OpenMP code.
llvm-svn: 234575
2015-04-10 07:48:12 +00:00
Alexey Bataev d7614fb7e0 [OPENMP] Fixing troubles with lambdas in cleanups.
llvm-svn: 234572
2015-04-10 06:33:45 +00:00
Alexey Bataev d3ae853c3d [OPENMP] Fixed incompatibility with MSVC, NFC.
llvm-svn: 234568
2015-04-10 05:32:31 +00:00
Alexey Bataev 6f1ffc069b [OPENMP] Refactoring of codegen for OpenMP directives.
Refactored API of OpenMPRuntime for compatibility with combined directives.
Differential Revision: http://reviews.llvm.org/D8859

llvm-svn: 234564
2015-04-10 04:50:10 +00:00
Nico Weber bd51a6a99f Revert r234532 for a bit, it very likely caused http://crbug.com/475768
llvm-svn: 234563
2015-04-10 04:33:03 +00:00
Benjamin Kramer f3e67de85a [CodeGen] Do a more principled fix for PR231653, always use the inner type.
We were still using the MaterializeTemporaryExpr's type to check if the
transform is legal. Always use the inner Expr type.

llvm-svn: 234543
2015-04-09 22:50:07 +00:00
Rafael Espindola 4dedcd7eab Update for LLVM api changes.
llvm-svn: 234536
2015-04-09 21:06:11 +00:00
Reid Kleckner 0dbecf2b78 [SEH] Outline finally blocks using the new variable capture support
WinEHPrepare was going to have to pattern match the control flow merge
and split that the old lowering used, and that wasn't really feasible.

Now we can teach WinEHPrepare to pattern match this, which is much
simpler:
  %fp = call i8* @llvm.frameaddress(i32 0)
  call void @func(iN [01], i8* %fp)

This prototype happens to match the prototype used by the Win64 SEH
personality function, so this is really simple.

llvm-svn: 234532
2015-04-09 20:37:24 +00:00
Benjamin Kramer b2b81439a3 [CodeGen] When promoting a reference temporary to a global use the inner type to fold it.
The MaterializeTemporaryExpr can have a different type than the inner
expression, miscompiling the constant. PR23165.

llvm-svn: 234499
2015-04-09 16:09:29 +00:00
Sanjay Patel 359b105745 Process the -freciprocal-math optimization flag (PR20912)
The driver currently accepts but ignores the -freciprocal-math flag.
This patch passes the flag through and enables 'arcp' fast-math-flag
generation in IR.

Note that this change does not actually enable the optimization for
any target. The reassociation optimization that this flag specifies
was implemented by http://reviews.llvm.org/D6334 :
http://llvm.org/viewvc/llvm-project?view=revision&revision=222510

Because the optimization is done in the backend rather than IR,
the backend must be modified to understand instruction-level
fast-math-flags or a new function-level attribute must be created.

Also note that -freciprocal-math is independent of any target-specific
usage of reciprocal estimate hardware instructions. That requires
its own flag ('-mrecip').

https://llvm.org/bugs/show_bug.cgi?id=20912

llvm-svn: 234493
2015-04-09 15:03:23 +00:00
Reid Kleckner e5b064205a [WinEH] Don't wrap cleanups in terminate actions
_CxxFrameHandler3 calls terminate if a cleanup action throws, regardless
of what bits you put in the xdata tables. There's no need to model this
in the IR, since we just have to take it out later.

llvm-svn: 234448
2015-04-08 22:48:50 +00:00
Reid Kleckner 31a1bb0c14 Reland "[SEH] Implement filter capturing in CodeGen"
The test should be fixed. It was failing in NDEBUG builds due to a
missing '*' character in a regex. In asserts builds, the pattern matched
a single digit value, which became a double digit value in NDEBUG
builds. Go figure.

This reverts commit r234261.

llvm-svn: 234447
2015-04-08 22:23:48 +00:00
Duncan P. N. Exon Smith 373285892b Revert "Fix a compiler error under MSVC"
This reverts the bandaid commit in r234308 now that I have a proper fix
in LLVM as of r234326.

llvm-svn: 234339
2015-04-07 18:41:26 +00:00
Duncan P. N. Exon Smith ebad0aa3ba DebugInfo: LLVM API change in r234326 for array-like tuple wrappers
Update a few calls to `DIBuilder` now that `MDTuple` array-wrappers
don't have implicit conversions to `MDTuple*`.  I may circle back and
update `DIBuilder` to take arrays here, to make it easier for the
callers.

llvm-svn: 234327
2015-04-07 16:50:49 +00:00
Timur Iskhodzhanov 90639edd3d Fix a compiler error under MSVC
Error message was:
CGDebugInfo.cpp(1047) : error C2666: 'llvm::MDTypeRefArray::operator []' : 2 overloads have similar conversions
  DebugInfoMetadata.h(106): could be 'llvm::MDTypeRef llvm::MDTypeRefArray::operator [](unsigned int) const'
  while trying to match the argument list '(llvm::DITypeArray, int)'

llvm-svn: 234308
2015-04-07 11:26:00 +00:00
Daniel Jasper 303c3ac925 Revert "[SEH] Implement filter capturing in CodeGen"
Test fails:
http://lab.llvm.org:8080/green/job/clang-stage2-configure-Rlto_check/3182/

llvm-svn: 234306
2015-04-07 10:07:47 +00:00
Duncan P. N. Exon Smith a98fac64ea DebugInfo: Update for LLVM change in r234290
The API for `DIArray` changed; use the new one.

llvm-svn: 234291
2015-04-07 04:14:45 +00:00
Reid Kleckner 67cf035a99 [WinEH] Don't create an alloca for unnamed catch parameters
The catch object parameter to llvm.eh.begincatch is optional, and can be
null. We can save some ourselves the stack space, copy ctor, and dtor
calls if we pass null.

llvm-svn: 234264
2015-04-07 00:09:59 +00:00
Reid Kleckner 0ada50f17f [SEH] Implement filter capturing in CodeGen
While capturing filters aren't very common, we'd like to outline
__finally blocks in the frontend to simplify -O0 EH preparation and
reduce code size. Finally blocks are usually have captures, and this is
the first step towards that.

Currently we don't support capturing 'this' or VLAs.

Reviewers: majnemer

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

llvm-svn: 234261
2015-04-06 23:51:44 +00:00
Duncan P. N. Exon Smith c755128673 CGDebugInfo: Stop using DIDescriptor::is*() and auto-casting
The clang edition of r234255: use built-in `isa<>`, `dyn_cast<>`, etc.,
and only build `DIDescriptor`s from pointers that are correctly typed.

llvm-svn: 234256
2015-04-06 23:21:33 +00:00
Duncan P. N. Exon Smith ee55fac1d4 DebugInfo: Use DILexicalBlockFile::getContext() over getScope()
`getScope()` passes the scope back through a `DILexicalBlock` even
though the underlying pointer may be an incompatible `MDSubprogram`.
Just use `getContext()` directly.

llvm-svn: 234245
2015-04-06 22:04:18 +00:00
Nico Weber 176efac95b Don't crash when passing a non-existent file to -fprofile-instr-use=.
Fixes a regression from r229434.

llvm-svn: 234141
2015-04-06 04:16:48 +00:00
David Blaikie 2e80428dc5 clang-format my last commit
(sorry, keep forgetting that)

llvm-svn: 234129
2015-04-05 22:47:07 +00:00
David Blaikie 1ed728c499 [opaque pointer type] More GEP API migrations
Looks like the VTable code in particular will need some work to pass
around the pointee type explicitly.

llvm-svn: 234128
2015-04-05 22:45:47 +00:00
David Blaikie 17ea266bac [opaque pointer type] More GEP API migrations
llvm-svn: 234109
2015-04-04 21:07:17 +00:00
David Blaikie fb901c7abf [opaque pointer type] more GEP API migrations
llvm-svn: 234097
2015-04-04 15:12:29 +00:00
David Majnemer f205f5324b [MS ABI] A pointer-to-function cannot be caught as a pointer-to-void
Don't assume that all pointers are convertible to void pointer.
Instead correctly respect [conv.ptr]p2; only allow pointer types with an
object pointee type to be caught as pointer-to-void.

llvm-svn: 234090
2015-04-04 05:37:48 +00:00
David Blaikie 5e259a8c6d [opaque pointer type] Explicitly specify some types for GEP
Not all of them (there's still a fallback for this specific function
that omits the type parameter) but it's some I bothered to do now.

llvm-svn: 234063
2015-04-03 22:54:16 +00:00
Manman Ren 2738278b7f [i386 ABI] expand small C like structs in C++, just like how we handle small
C structs.

This comes up when we have a function that takes a struct and is defined in a
C++ file and used in a C file.

Before this commit, we will generate byval for C++ and will expand the struct
for C, thus causing difference at IR level. We will use bitcast of function type
at the callsite, which causes the inliner to not inline the function.

This commit changes how we handle small C like structs at IR level, but at
backend, we should generate the same argument passing before and after the
commit.

Note that the condition for expanding is still over conservative. We should be
able to expand type that is spelled with “class” and types that are not C-like.
But this commit fixes the inconsistent argument passing between C/C++.

Reviewed by John.

rdar://20121030

llvm-svn: 234033
2015-04-03 18:10:29 +00:00
David Blaikie 6b2a8306a5 [opaque pointer type] Explicitly specify type to CreateGEP
llvm-svn: 234032
2015-04-03 17:47:16 +00:00
David Blaikie e3b172afc3 [opaque pointer type] Update for GEP API changes in LLVM
Now the GEP constant utility functions require the type to be explicitly
passed (since eventually the pointer type will be opaque and not convey
the required type information). For now callers can still pass nullptr
(though none were needed here in Clang, which is nice) if
convenienc/necessary, but eventually that will be disallowed as well.

llvm-svn: 233937
2015-04-02 18:55:21 +00:00
Peter Collingbourne 1a7488afaa Implement CFI type checks for non-virtual calls.
This uses the same class metadata currently used for virtual call and
cast checks.

The new flag is -fsanitize=cfi-nvcall. For consistency, the -fsanitize=cfi-vptr
flag has been renamed -fsanitize=cfi-vcall.

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

llvm-svn: 233874
2015-04-02 00:23:30 +00:00
Ulrich Weigand 3a610ebf1e [SystemZ] Support transactional execution on zEC12
The zEC12 provides the transactional-execution facility.  This is exposed
to users via a set of builtin routines on other compilers.  This patch
adds clang support to enable those builtins.  In partciular, the patch:

- enables the transactional-execution feature by default on zEC12
- allows to override presence of that feature via the -mhtm/-mno-htm options
- adds a predefined macro __HTM__ if the feature is enabled
- adds support for the transactional-execution GCC builtins
- adds Sema checking to verify the __builtin_tabort abort code
- adds the s390intrin.h header file (for GCC compatibility)
- adds s390 sections to the htmintrin.h and htmxlintrin.h header files

Since this is first use of target-specific intrinsics on the platform,
the patch creates the include/clang/Basic/BuiltinsSystemZ.def file and
hooks it up in TargetBuiltins.h and lib/Basic/Targets.cpp.

An associated LLVM patch adds the required LLVM IR intrinsics.

For reference, the transactional-execution instructions are documented
in the z/Architecture Principles of Operation for the zEC12:
http://publibfp.boulder.ibm.com/cgi-bin/bookmgr/download/DZ9ZR009.pdf
The associated builtins are documented in the GCC manual:
http://gcc.gnu.org/onlinedocs/gcc/S_002f390-System-z-Built-in-Functions.html
The htmxlintrin.h intrinsics provided for compatibility with the IBM XL
compiler are documented in the "z/OS XL C/C++ Programming Guide".

llvm-svn: 233804
2015-04-01 12:54:25 +00:00
David Majnemer 1f192e26fd [MS ABI] Disregard restrictive exception specifications
MSVC treats all non-empty exception specifications the same way: all
exceptions are permitted.  The .xdata tables provide a way to
efficiently lower exception specifications *but* this probably has to be
implemented as a catch-all/rethrow mechanism instead of the Itanium way.

This fixes PR23092.

llvm-svn: 233787
2015-04-01 04:45:52 +00:00
Fariborz Jahanian 6a9c46bc3f [Objective-C metadata patch]. Patch to allocate one more space for
Protocol objects in OBJC2. rdar://20286356

llvm-svn: 233766
2015-03-31 22:22:40 +00:00
Duncan P. N. Exon Smith 2809cc7493 DebugInfo: Use new LLVM API for DebugLoc
Use the new API for `DebugLoc` added in r233573 before the old one
disappears.

llvm-svn: 233589
2015-03-30 20:01:41 +00:00
Kit Barton e50adcb6b1 [PPC] Move argument range checks for HTM and crypto builtins to Sema
The argument range checks for the HTM and Crypto builtins were implemented in
CGBuiltin.cpp, not in Sema. This change moves them to the appropriate location
in SemaChecking.cpp. It requires the creation of a new method in the Sema class
to do checks for PPC-specific builtins.

http://reviews.llvm.org/D8672

llvm-svn: 233586
2015-03-30 19:40:59 +00:00
Ulrich Weigand 759449c76a [SystemZ] Fix some ABI corner cases
Running the GCC's inter-compiler ABI compatibility test suite uncovered
a couple of errors in clang's SystemZ ABI implementation.  These all
affect only rare corner cases:

- Short vector types

GCC synthetic vector types defined with __attribute__ ((vector_size ...))
are always passed and returned by reference.  (This is not documented in
the official ABI document, but is the de-facto ABI implemented by GCC.)
clang would do that only for vector sizes >= 16 bytes, but not for shorter
vector types.

- Float-like aggregates and empty bitfields

clang would consider any aggregate containing an empty bitfield as
first element to be a float-like aggregate.  That's obviously wrong.
According to the ABI doc, the presence of an empty bitfield makes
an aggregate to be *not* float-like.  However, due to a bug in GCC,
empty bitfields are ignored in C++; this patch changes clang to be
compatible with this "feature" of GCC.

- Float-like aggregates and va_arg

The va_arg implementation would mis-detect some aggregates as float-like
that aren't actually passed as such.  This applies to aggregates that
have only a single element of type float or double, but using an aligned
attribute that increases the total struct size to more than 8 bytes.

This error occurred because the va_arg implement used to have an copy
of the float-like aggregate detection logic (i.e. it would call the
isFPArgumentType routine, but not perform the size check).

To simplify the logic, this patch removes the duplicated logic and
instead simply checks the (possibly coerced) LLVM argument type as
already determined by classifyArgumentType.

llvm-svn: 233543
2015-03-30 13:49:01 +00:00
Alexey Bataev b4505a7229 [OPENMP] Codegen for 'atomic update' construct.
Adds atomic update codegen for the following forms of expressions:

x binop= expr;
x++;
++x;
x--;
--x;
x = x binop expr;
x = expr binop x;
If x and expr are integer and binop is associative or x is a LHS in a RHS of the assignment expression, and atomics are allowed for type of x on the target platform atomicrmw instruction is emitted.
Otherwise compare-and-swap sequence is emitted:

bb:
...
atomic load <x>
cont:
<expected> = phi [ <x>, label %bb ], [ <new_failed>, %cont ]
<desired> = <expected> binop <expr>
<res> = cmpxchg atomic &<x>, desired, expected
<new_failed> = <res>.field1;
br <res>field2, label %exit, label %cont
exit:
...

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

llvm-svn: 233513
2015-03-30 05:20:59 +00:00
Alexey Bataev f268568447 [OPENMP] Improved codegen for implicit/explicit 'barrier' constructs.
Replace boolean IsExplicit parameter of OpenMPRuntime::emitBarrierCall() method by OpenMPDirectiveKind Kind for better compatibility with the runtime library. Also add processing of 'nowait' clause on worksharing directives.
Differential Revision: http://reviews.llvm.org/D8659

llvm-svn: 233511
2015-03-30 04:30:22 +00:00
David Majnemer 37b417f1ed [MS ABI] Rework .xdata HandlerType emission
Utilizing IMAGEREL relocations for synthetic IR constructs isn't
valuable, just clutter.  While we are here, simplify HandlerType names
by making the numeric value for the 'adjective' part of the mangled name
instead of appending '.const', etc.  The old scheme made for very long
global names and leads to wordy things like '.std_bad_alloc'

llvm-svn: 233503
2015-03-29 21:55:10 +00:00
Duncan P. N. Exon Smith 5043f91657 DebugInfo: Don't call DIBuilder::retainType(nullptr)
An upcoming LLVM commit will make calling
`DIBuilder::retainType(nullptr)` illegal (actually, it already was, but
it wasn't verified).  Check for null before calling.

This triggered in test/CodeGenObjC/debug-info-block-helper.m.

llvm-svn: 233443
2015-03-27 22:58:05 +00:00
Eric Christopher 70c1665d83 Reapply r232888 after applying a fix for -msse4 code generation.
As a note, any target that uses fake target features via command
line options will have similar problems.

llvm-svn: 233227
2015-03-25 23:14:47 +00:00
Jingyue Wu 4f7b9eb217 Fix addrspace when emitting constructors of static local variables
Summary:
Due to CUDA's implicit address space casting, the type of a static local
variable may be more specific (i.e. with address space qualifiers) than
the type expected by the constructor. Emit an addrspacecast in that
case.

Test Plan: Clang used to crash on the added test.

Reviewers: nlewycky, pcc, eliben, rsmith

Reviewed By: eliben, rsmith

Subscribers: llvm-commits

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

llvm-svn: 233208
2015-03-25 20:06:28 +00:00
Kit Barton 8246f28237 Add Hardware Transactional Memory (HTM) Support
This patch adds Hardware Transaction Memory (HTM) support supported by ISA 2.07
(POWER8). The intrinsic support is based on GCC one [1], with both 'PowerPC HTM
Low Level Built-in Functions' and 'PowerPC HTM High Level Inline Functions'
implemented.

Along with builtins a new driver switch is added to enable/disable HTM
instruction support (-mhtm) and a header with common definitions (mostly to
parse the TFHAR register value). The HTM switch also sets a preprocessor builtin
HTM.

The HTM usage requires a recently newer kernel with PPC HTM enabled. Tested on
powerpc64 and powerpc64le.

This is send along a llvm patch to enabled the builtins and option switch.

[1]
https://gcc.gnu.org/onlinedocs/gcc/PowerPC-Hardware-Transactional-Memory-Built-in-Functions.html

Phabricator Review: http://reviews.llvm.org/D8248

llvm-svn: 233205
2015-03-25 19:41:41 +00:00
Justin Bogner f14b207882 InstrProf: Handle whitespace and comments at the ends of macros
When we try to find the end loc for a token, we have to re-lex the
token. This was running into a problem when we'd store the end loc of
a macro's coverage region, since we wouldn't actually be at the
beginning of a token when we tried to re-lex it, leading us to do
silly things (and eventually assert) when whitespace or comments
followed.

This pushes our use of getPreciseTokenLocEnd earlier, so that we won't
call it when it doesn't make sense to. It also removes an unnecessary
adjustment by 1 that was working around this problem in some cases.

llvm-svn: 233169
2015-03-25 04:13:49 +00:00
Ahmed Bougacha 6ba3831ebe [CodeGen] Support native half inc/dec amounts.
We previously defaulted to long double, but it's also possible to have
a half inc/dec amount, when LangOpts NativeHalfType is set.
Currently, that's only true for OpenCL.

llvm-svn: 233135
2015-03-24 23:44:42 +00:00
Ahmed Bougacha d1801afeac [CodeGen] Properly support the half FP type with non-native operations.
On AArch64, the -fallow-half-args-and-returns option is the default.
With it, the half type is considered legal (rather than the i16 used
normally for __fp16), but no operation is, except conversions and
load/stores and such.

The previous behavior was tantamount to saying LangOpts.NativeHalfType
was implied by LangOpts.HalfArgsAndReturns, which isn't true.
Instead, teach the various parts of CodeGen that already know about
half (using the intrinsics or not) about this weird in-between case,
where the "half" type is legal, but operations on it aren't.

This is a smaller intermediate step to the end-goal of removing the
intrinsic, always using "half", and letting the backend legalize.

Builds on r232968.
rdar://20045970, rdar://17468714
Differential Revision: http://reviews.llvm.org/D8367

llvm-svn: 232971
2015-03-23 17:54:16 +00:00
Ahmed Bougacha 47ec2c7479 [CodeGen] Convert double -> __fp16 in one step.
Fix the CodeGen so that for types bigger than float, instead of
converting to fp16 via the sequence "InTy -> float -> fp16", we
perform conversions in just one step.  This avoids the double
rounding which potentially changes results from a natural
IEEE-754 operation.

rdar://17594379, rdar://17468714
Differential Revision: http://reviews.llvm.org/D4602
Part of: http://reviews.llvm.org/D8367

llvm-svn: 232968
2015-03-23 17:48:07 +00:00
Alexey Bataev a63048e4fd [OPENMP] Codegen for 'copyprivate' clause ('single' directive).
If there is at least one 'copyprivate' clause is associated with the single directive, the following code is generated:

```
i32 did_it = 0;                                  \\ for 'copyprivate' clause
if(__kmpc_single(ident_t *, gtid)) {
  SingleOpGen();
  __kmpc_end_single(ident_t *, gtid);
  did_it = 1;                                    \\ for 'copyprivate' clause
}
<copyprivate_list>[0] = &var0;
...
<copyprivate_list>[n] = &varn;
call __kmpc_copyprivate(ident_t *, gtid, <copyprivate_list_size>,
                        <copyprivate_list>, <copy_func>, did_it);

...

void<copy_func>(void *LHSArg, void *RHSArg) {
  Dst = (void * [n])(LHSArg);
  Src = (void * [n])(RHSArg);
  Dst[0] = Src[0];
  ... Dst[n] = Src[n];
}
```
All list items from all 'copyprivate' clauses are gathered into single <copyprivate list> (<copyprivate_list_size> is a size in bytes of this list) and <copy_func> is used to propagate values of private or threadprivate variables from the 'single' region to other implicit threads from outer 'parallel' region.
Differential Revision: http://reviews.llvm.org/D8410

llvm-svn: 232932
2015-03-23 06:18:07 +00:00
Daniel Jasper 17ae9f0206 Revert "Add CodeGen support for adding cpu attributes on functions based on"
This breaks CodeGen for an internal target. I'll get repro instructions
to you.

llvm-svn: 232930
2015-03-23 05:52:28 +00:00
Alexander Musman 3276a27b5c [OPENMP] CodeGen of the 'linear' clause for the 'omp simd' directive.
The linear variable is privatized (similar to 'private') and its
value on current iteration is calculated, similar to the loop
counter variables.
Differential revision: http://reviews.llvm.org/D8375

llvm-svn: 232890
2015-03-21 10:12:56 +00:00
Eric Christopher ea00c2a06f Add CodeGen support for adding cpu attributes on functions based on
the target-cpu, if different from the triple's cpu, and
target-features as they're written that are passed down from the
driver.

Together with LLVM r232885 this should allow the LTO'ing of binaries
that contain modules compiled with different code generation options
on a subset of architectures with full backend support (x86, powerpc,
aarch64).

llvm-svn: 232888
2015-03-21 06:15:15 +00:00
David Majnemer c403a1ce32 MS ABI: Accept calls to an unprototyped declaration of _setjmp
This fixes PR22961.

llvm-svn: 232824
2015-03-20 17:03:35 +00:00
Justin Bogner e9fe0a298c InstrProf: Make profile variables private to reduce binary size overhead
When we instrument a program for profiling, we copy the linkage of an
instrumented function so that our datastructures merge in the same way
as the function. This avoids redundant copies for things like
linkonce, but ends up emitting names we never need to reference for
normal and internal symbols. Promoting internal and external linkage
to private for these variables reduces the size overhead of profiling
drastically.

llvm-svn: 232799
2015-03-20 06:34:38 +00:00
Duncan P. N. Exon Smith 7ea96c222f DebugInfo: Check for null before using DIType
A WIP patch to turn on stricter `DIDescriptor` accessor checks fires
here; it's obvious from the code that `T` can be null, so add an
explicit check.  Caught by dozens of current testcases.

llvm-svn: 232791
2015-03-20 00:53:40 +00:00
Reid Kleckner 7ffc3fbb2f C++14: Disable sized deallocation by default due to ABI breakage
There are no widely deployed standard libraries providing sized
deallocation functions, so we have to punt and ask the user if they want
us to use sized deallocation. In the future, when such libraries are
deployed, we can teach the driver to detect them and enable this
feature.

N3536 claimed that a weak thunk from sized to unsized deallocation could
be emitted to avoid breaking backwards compatibility with standard
libraries not providing sized deallocation. However, this approach and
other variations don't work in practice.

With the weak function approach, the thunk has to have default
visibility in order to ensure that it is overridden by other DSOs
providing sized deallocation. Weak, default visibility symbols are
particularly expensive on MachO, so John McCall was considering
disabling this feature by default on Darwin. It also changes behavior
ELF linking behavior, causing certain otherwise unreferenced object
files from an archive to be pulled into the link.

Our second approach was to use an extern_weak function declaration and
do an inline conditional branch at the deletion call site. This doesn't
work because extern_weak only works on MachO if you have some archive
providing the default value of the extern_weak symbol. Arranging to
provide such an archive has the same challenges as providing the symbol
in the standard library. Not to mention that extern_weak doesn't really
work on COFF.

Reviewers: rsmith, rjmccall

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

llvm-svn: 232788
2015-03-20 00:31:07 +00:00
Duncan P. N. Exon Smith f80840f784 Clang follow-up to LLVM r232772
-verify-di is dead! Long live -verify!

llvm-svn: 232779
2015-03-19 22:43:38 +00:00
Chandler Carruth c66deafb73 [Modules] Implement __builtin_isinf_sign in Clang.
Somehow, we never managed to implement this fully. We could constant
fold it like crazy, including constant folding complex arguments, etc.
But if you actually needed to generate code for it, error.

I've implemented it using the somewhat obvious lowering. Happy for
suggestions on a more clever way to lower this.

Now, what you might ask does this have to do with modules? Fun story. So
it turns out that libstdc++ actually uses __builtin_isinf_sign to
implement std::isinf when in C++98 mode, but only inside of a template.
So if we're lucky, and we never instantiate that, everything is good.
But once we try to instantiate that template function, we need this
builtin. All of my customers at least are using C++11 and so they never
hit this code path.

But what does that have to do with modules? Fun story. So it turns out
that with modules we actually observe a bunch of bugs in libstdc++ where
their <cmath> header clobbers things exposed by <math.h>. To fix these,
we have to provide global function definitions to replace the macros
that C99 would have used. And it turns out that ::isinf needs to be
implemented using the exact semantics used by the C++98 variant of
std::isinf. And so I started to fix this bug in libstdc++ and ceased to
be able to compile libstdc++ with Clang.

The yaks are legion.

llvm-svn: 232778
2015-03-19 22:39:51 +00:00
Artem Belevich f3d3db65de Remove .CUDAIsDevice flags from CodeGenOpts as it's already
available in LangOpts.

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

llvm-svn: 232749
2015-03-19 18:58:18 +00:00
Reid Kleckner 7270ef5705 Revert "Improvement on sized deallocation from r230160"
This reverts commit r230580.

extern_weak functions don't appear to work on Darwin (PR22951), so we'll
need to come up with a new approach.

llvm-svn: 232731
2015-03-19 17:03:58 +00:00
Alexey Bataev 87b1302a84 [OPENMP] Fixed bug in codegen of 'atomic write'.
Fixed codegen for exit/continue order after success/failed atomic cmpxchg instruction for 'atomic write' construct.

llvm-svn: 232712
2015-03-19 08:44:10 +00:00
David Majnemer a03849b2e7 MS ABI: Don't try to emit VF/VB-Tables for extern class templates
There will be an explicit template instantiation in another translation
unit which will provide the definition of the VF/VB-Tables.

This fixes PR22932.

llvm-svn: 232680
2015-03-18 22:04:43 +00:00
Alexey Bataev 91797559ac [OPENMP] Fix crash on code emitting if errors are found.
Codegen for threadprivate variables (and in some other cases) may cause crash of the compiler if some diagnostic is produced later. This happens because some of the autogenerated globals are not removed from InternalVars StringMap when llvm::Module is reset.
Differential Revision: http://reviews.llvm.org/D8360

llvm-svn: 232610
2015-03-18 04:13:55 +00:00
Nick Lewycky 84146bee6c Fix the LLVM type used when lowering initializer list reference temporaries to global variables. Reapplies r232454 with fix for PR22940.
llvm-svn: 232579
2015-03-18 01:06:24 +00:00
Justin Bogner 0729afa4a6 MS ABI: Fix a couple of -Winconsistent-missing-override warnings
llvm-svn: 232559
2015-03-17 22:31:34 +00:00
Reid Kleckner 93f661a1da MS ABI: Build C++ default argument exprs for exported template classes
This was an omission from r232229.

llvm-svn: 232554
2015-03-17 21:51:43 +00:00
David Majnemer 5f0dd6162c MS ABI: Emit HandlerMap entries for C++ catch
The HandlerMap describes, to the runtime, what sort of catches surround
the try.  In principle, this structure has to be emitted by the backend
because only it knows the layout of the stack (the runtime needs to know
where on the stack the destination of a copy lives, etc.) but there is
some C++ specific information that the backend can't reason about.

Stick this information in special LLVM globals with the relevant
"const", "volatile", "reference" info mangled into the name.

llvm-svn: 232538
2015-03-17 20:35:05 +00:00
David Majnemer 443250f08d WIP
llvm-svn: 232537
2015-03-17 20:35:00 +00:00
Michael Zolotukhin c888dd0cb8 Add fveclib option.
Review: http://reviews.llvm.org/D8097
llvm-svn: 232533
2015-03-17 20:03:11 +00:00
Reid Kleckner bba3cb95cc MS ABI: Delay default constructor closure checking until the outermost class scope ends
Previously, we would error out on this code because the default argument
wasn't parsed until the end of Outer:

  struct __declspec(dllexport) Outer {
    struct __declspec(dllexport) Inner {
      Inner(void *p = 0);
    };
  };

Now we do the checking on the closing brace of Outer instead of Inner.

llvm-svn: 232519
2015-03-17 19:00:50 +00:00
Hans Wennborg f9d865b059 Revert r232454 and r232456: "Fix the LLVM type used when lowering initializer list reference temporaries to global variables."
This caused PR22940.

llvm-svn: 232496
2015-03-17 16:38:58 +00:00
Nick Lewycky cf191adaf5 Fix the LLVM type used when lowering initializer list reference temporaries to global variables.
llvm-svn: 232454
2015-03-17 02:21:31 +00:00
Justin Bogner 4e46237c6d GCOV: Expose the -coverage-exit-block-before-body flag in clang -cc1
This exposes the optional exit block placement logic from r232438 as a
clang -cc1 option. There is a test on the llvm side, but there isn't
really a way to inspect the gcov options from clang to test it here as
well.

llvm-svn: 232439
2015-03-16 23:52:21 +00:00
Alexander Musman 7931b98735 [OPENMP] Enable codegen of the ‘private’ clause for ‘omp simd’ directive
llvm-svn: 232353
2015-03-16 07:14:41 +00:00
David Majnemer ad803d4b76 MS ABI: Don't use qualified pointee types for 'catch' EH TypeDescriptors
Qualifiers are located next to the TypeDescriptor in order to properly
ensure that a pointer type can only be caught by a more qualified catch
handler.  This means that a catch handler of type 'const int *' requires
an RTTI object for 'int *'.  We got this correct for 'throw' but not for
'catch'.

N.B.  We don't currently have the means to store the qualifiers because
LLVM's EH strategy is tailored to the Itanium scheme.  The Itanium ABI
stores qualifiers inside the type descriptor in such a way that the
manner of qualification is stored in addition to the pointee type's
descriptor.  Perhaps the best way of modeling this for the MS ABI is
using an aggregate type to bundle the qualifiers with the descriptor?
This is tricky because we want to make it clear to the optimization
passes which catch handlers invalidate other handlers.

My current thoughts on a design for this is along the lines of:
  { { TypeDescriptor* TD, i32 QualifierFlags }, i32 MiscFlags }

The idea is that the inner most aggregate is all that is needed to
communicate that one catch handler might supercede another.  The
'MiscFlags' field would be used to hold the bitpattern for the notion
that the 'catch' handler does not need to invoke a copy-constructor
because we are catching by reference.

llvm-svn: 232318
2015-03-15 07:10:01 +00:00
David Majnemer 9ced3dd64c MS ABI: Tidy up references to the ASTContext
CGCXXABI has a handy getContext() method.  Use that instead of
explicitly going through the CodeGenModule.

llvm-svn: 232289
2015-03-14 23:44:48 +00:00
David Majnemer 8062eb6bed CodeGen: Correctly initialize bitfields with non-constant initializers
It is possible to construct an initializer for a bitfield which is not
constant.  Instead of emitting code to initialize the field before the
execution of main, clang would crash.

llvm-svn: 232285
2015-03-14 22:24:38 +00:00
Peter Collingbourne d2926c91d5 Implement bad cast checks using control flow integrity information.
This scheme checks that pointer and lvalue casts are made to an object of
the correct dynamic type; that is, the dynamic type of the object must be
a derived class of the pointee type of the cast. The checks are currently
only introduced where the class being casted to is a polymorphic class.

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

llvm-svn: 232241
2015-03-14 02:42:25 +00:00
David Majnemer 37fd66e78b MS ABI: Generate default constructor closures
The MS ABI utilizes a compiler generated function called the "vector
constructor iterator" to construct arrays of objects with
non-trivial constructors/destructors.  For this to work, the constructor
must follow a specific calling convention.  A thunk must be created if
the default constructor has default arguments, is variadic or is
otherwise incompatible.  This thunk is called the default constructor
closure.

N.B.  Default constructor closures are only generated if the default
constructor is exported because clang itself does not utilize vector
constructor iterators.  Failing to export the default constructor
closure will result in link/load failure if a translation unit compiled
with MSVC is on the import side.

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

llvm-svn: 232229
2015-03-13 22:36:55 +00:00
David Majnemer ba3e5ecf07 MS ABI: Implement __GetExceptionInfo for std::make_exception_ptr
std::make_exception_ptr calls std::__GetExceptionInfo in order to figure
out how to properly copy the exception object.

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

llvm-svn: 232188
2015-03-13 18:26:17 +00:00
Alexander Musman 21212e4198 [OPENMP] Re-factor __kmpc_for_static_init_* routine generation.
llvm-svn: 232154
2015-03-13 10:38:23 +00:00
Joerg Sonnenberger dfd511e9bc Simplify.
llvm-svn: 232130
2015-03-13 00:54:30 +00:00
Benjamin Kramer 7f1f6b5370 Disambiguate call for GCC.
llvm-svn: 232122
2015-03-12 23:46:55 +00:00
Benjamin Kramer 51680bccda CodeGen: Base the conditional cleanup machinery on variadic templates
This is complicated by the fact that we can't simply use side-effecting
calls in an argument list without losing all guarantees about the order
they're emitted. To keep things deterministic we use tuples and brace
initialization, which thankfully guarantees evaluation order.

No functionality change intended.

llvm-svn: 232121
2015-03-12 23:41:40 +00:00
David Majnemer a1aea9aad4 MS ABI: Allow a nullptr_t exception to be caught by void * catch handler
A nullptr exception object can be caught by any pointer type catch
handler.  However, it is not possible to express this in the exception
info for the MS ABI.  As a middle ground, allow such exception objects
to be caught with pointer-to-void catch handlers.

llvm-svn: 232069
2015-03-12 17:44:49 +00:00
Aaron Ballman 0c22d5a339 Instead of dereferencing std::vector::end() (which is UB and causes failed assertions in debug builds with Visual Studio), use data() + size() to calculate the end iterator. Amends r231952.
llvm-svn: 232037
2015-03-12 13:49:45 +00:00
Alexander Musman 92bdaabf97 [OPENMP] CodeGen - 'omp for' with dynamic schedule kinds.
Differential Revision: http://reviews.llvm.org/D7138

llvm-svn: 232036
2015-03-12 13:37:50 +00:00
Alexey Bataev 2df54a07bf [OPENMP] Initial codegen for 'omp sections' and 'omp section' directives.
If only one section is found in the sections region, it is emitted just like single region.
Otherwise it is emitted as a static non-chunked loop.

#pragma omp sections
{
#pragma omp section
  {1}
  ...
  #pragma omp section
  {n}
}
is translated to something like

i32 <iter_var>
i32 <last_iter> = 0
i32 <lower_bound> = 0
i32 <upper_bound> = n-1
i32 <stride> = 1
call void @__kmpc_for_static_init_4(<loc>, i32 <gtid>, i32 34/*static non-chunked*/, i32* <last_iter>, i32* <lower_bound>, i32* <upper_bound>, i32* <stride>, i32 1/*increment always 1*/, i32 1/*chunk always 1*/)
<upper_bound> = min(<upper_bound>, n-1)
<iter_var> = <lb>
check:
br <iter_var> <= <upper_bound>, label cont, label exit
continue:
switch (IV) {
  case 0:
  {1};
  break;
  ...
  case <NumSection> - 1:
  {n};
  break;
  }
  ++<iter_var>
  br label check
  exit:
  call void @__kmpc_for_static_fini(<loc>, i32 <gtid>)
Differential Revision: http://reviews.llvm.org/D8244

llvm-svn: 232021
2015-03-12 08:53:29 +00:00
Joerg Sonnenberger 27173288c2 Under duress, move check for target support of __builtin_setjmp/
__builtin_longjmp to Sema as requested by John McCall.

llvm-svn: 231986
2015-03-11 23:46:32 +00:00
Hal Finkel 0d0a1a53e3 [PowerPC] ABI support for the QPX vector instruction set
Support for the QPX vector instruction set, used on the IBM BG/Q supercomputer,
has recently been added to the LLVM PowerPC backend. This vector instruction
set requires some ABI modifications because the ABI on the BG/Q expects
<4 x double> vectors to be provided with 32-byte stack alignment, and to be
handled as native vector types (similar to how Altivec vectors are handled on
mainline PPC systems). I've named this ABI variant elfv1-qpx, have made this
the default ABI when QPX is supported, and have updated the ABI handling code
to provide QPX vectors with the correct stack alignment and associated
register-assignment logic.

llvm-svn: 231960
2015-03-11 19:14:15 +00:00
David Majnemer dfa6d2067c MS ABI: Implement copy-ctor closures, finish implementing throw
This adds support for copy-constructor closures.  These are generated
when the C++ runtime has to call a copy-constructor with a particular
calling convention or with default arguments substituted in to the call.

Because the runtime has no mechanism to call the function with a
different calling convention or know-how to evaluate the default
arguments at run-time, we create a thunk which will do all the
appropriate work and package it in a way the runtime can use.

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

llvm-svn: 231952
2015-03-11 18:36:39 +00:00
Alexey Bataev 10fec57e5a [OPENMP] Fix for ExprWithCleanups in 'omp atomic' constructs.
This patch allows using of ExprWithCleanups expressions and other complex expressions in 'omp atomic' construct
Differential Revision: http://reviews.llvm.org/D8200

llvm-svn: 231905
2015-03-11 04:48:56 +00:00
NAKAMURA Takumi 7304a2427e CGOpenMPRuntime.h: Fix an incorrect \param on emitTaskOutlinedFunction(). [-Wdocumentation]
llvm-svn: 231903
2015-03-11 03:51:40 +00:00
David Majnemer 999cbf9d21 MS ABI: Mangle the location of the catchable type into it's name
Because the catchable type has a reference to its name, mangle the
location to ensure that two catchable types with different locations are
distinct.

llvm-svn: 231819
2015-03-10 19:01:51 +00:00
Alexey Bataev 62b63b197d [OPENMP] Initial codegen for 'omp task' directive.
The task region is emmitted in several steps:

Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32 gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds, kmp_routine_entry_t *task_entry).
Here task_entry is a pointer to the function:
kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
    TaskFunction(gtid, tt->part_id, tt->shareds);
      return 0;
}
Copy a list of shared variables to field shareds of the resulting structure kmp_task_t returned by the previous call (if any).
Copy a pointer to destructions function to field destructions of the resulting structure kmp_task_t.
Emit a call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid, kmp_task_t *new_task), where new_task is a resulting structure from previous items.
Differential Revision: http://reviews.llvm.org/D7560

llvm-svn: 231762
2015-03-10 07:28:44 +00:00
Alexey Bataev 36bf011e83 [OPENMP] Improved code for generating debug info + generation of all OpenMP regions in termination scope
Patch adds proper generation of debug info for all OpenMP regions. Also, all OpenMP regions are generated in a termination scope, because standard does not allow to throw exceptions out of structured blocks, associated with the OpenMP regions
Differential Revision: http://reviews.llvm.org/D7935

llvm-svn: 231757
2015-03-10 05:15:26 +00:00
Rafael Espindola eb26ddf559 Revert "[OPENMP] Improved code for generating debug info + generation of all OpenMP regions in termination scope Patch adds proper generation of debug info for all OpenMP regions. Also, all OpenMP regions are generated in a termination scope, because standard does not allow to throw exceptions out of structured blocks, associated with the OpenMP regions Differential Revision: http://reviews.llvm.org/D7935"
This reverts commit r231752.

It was failing to link with cmake:

lib64/libclangCodeGen.a(CGOpenMPRuntime.cpp.o):/home/espindola/llvm/llvm/tools/clang/lib/CodeGen/CGOpenMPRuntime.cpp:function clang::CodeGen::InlinedOpenMPRegionRAII::~InlinedOpenMPRegionRAII(): error: undefined reference to 'clang::CodeGen::EHScopeStack::popTerminate()'
clang-3.7: error: linker command failed with exit code 1 (use -v to see invocation)

llvm-svn: 231754
2015-03-10 04:40:21 +00:00
Alexey Bataev 7ab2cc178f [OPENMP] Improved code for generating debug info + generation of all OpenMP regions in termination scope
Patch adds proper generation of debug info for all OpenMP regions. Also, all OpenMP regions are generated in a termination scope, because standard does not allow to throw exceptions out of structured blocks, associated with the OpenMP regions
Differential Revision: http://reviews.llvm.org/D7935

llvm-svn: 231752
2015-03-10 04:22:11 +00:00
Mehdi Amini b3d5209927 Update for LLVM API change: getOrEnforceKnownAlignment() requires a DataLayout
From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 231739
2015-03-10 02:36:43 +00:00
Alexey Samsonov 21d2dda3d2 [UBSan] Split -fsanitize=shift into -fsanitize=shift-base and -fsanitize=shift-exponent.
This is a recommit of r231150, reverted in r231409. Turns out
that -fsanitize=shift-base check implementation only works if the
shift exponent is valid, otherwise it contains undefined behavior
itself.

Make sure we check that exponent is valid before we proceed to
check the base. Make sure that we actually report invalid values
of base or exponent if -fsanitize=shift-base or
-fsanitize=shift-exponent is specified, respectively.

llvm-svn: 231711
2015-03-09 21:50:19 +00:00
Tim Northover d157e19562 ARM: use ABI-specified alignment for byval parameters.
When passing a type with large alignment byval, we were specifying the type's
alignment rather than the alignment that the backend is actually capable of
producing (ABIAlign).

This would be OK (if odd) assuming the backend dealt with it prooperly,
unfortunately it doesn't and trying to pass types with "byval align 16" can
cause it to set fp incorrectly and trash the stack during the prologue. I'll be
fixing that in a separate patch, but Clang should still be emitting IR that's
as close to its intent as possible.

rdar://20059039

llvm-svn: 231706
2015-03-09 21:40:42 +00:00
Benjamin Kramer f8b86964ca Reapply r231508 "CodeGen: Emit constant temporaries into read-only globals."
I disabled putting the new global into the same COMDAT as the function for now.
There's a fundamental problem when we inline references to the global but still
have the global in a COMDAT linked to the inlined function. Since this is only
an optimization there may be other versions of the COMDAT around that are
missing the new global and hell breaks loose at link time.

I hope the chromium build doesn't break this time :)

llvm-svn: 231564
2015-03-07 13:37:13 +00:00
Hans Wennborg cd8f011157 Revert r231508 "CodeGen: Emit constant temporaries into read-only globals."
This broke the Chromium build. Links were failing with messages like:

obj/dbus/libdbus_test_support.a(obj/dbus/dbus_test_support.mock_object_proxy.o):../../dbus/mock_object_proxy.cc:function dbus::MockObjectProxy::Detach(): warning: relocation refers to discarded section
/usr/local/google/work/chromium/src/third_party/binutils/Linux_x64/Release/bin/ld.gold: error: treating warnings as errors

llvm-svn: 231541
2015-03-07 00:46:19 +00:00
Richard Smith f19e12794d Replace Sema's map of locally-scoped extern "C" declarations with a DeclContext
of extern "C" declarations. This is simpler and vastly more efficient for
modules builds (we no longer need to load *all* extern "C" declarations to
determine if we have a redeclaration).

No functionality change intended.

llvm-svn: 231538
2015-03-07 00:04:49 +00:00
David Majnemer 322fe4188f MS ABI: Stick throw-related data into the .xdata section
This is a little nicer as it keeps the contents of .xdata away from
normal .rdata; we expect .xdata to be far colder than .rdata.

llvm-svn: 231534
2015-03-06 23:45:23 +00:00
David Majnemer d3d7669ced MS ABI: Correctly generate throw-info for pointer to const qual types
We didn't create type info based on the unqualified pointee type,
causing RTTI mismatches.

llvm-svn: 231533
2015-03-06 23:45:20 +00:00
Benjamin Kramer 3d8aa5c77d CodeGen: Emit constant temporaries into read-only globals.
Instead of creating a copy on the stack just stash them in a private
constant global. This saves both the copying overhead and the stack
space, and gives the optimizer more room to constant fold.

This tries to make array temporaries more similar to regular arrays,
they can't use the same logic because a temporary has no VarDecl to be
bound to so we roll our own version here.

The original use case for this optimization was code like
  for (int i : {1, 2, 3, 4, 5, 6, 7, 8, 10})
    foo(i);
where without this patch (assuming that the loop is not unrolled) we
would alloca an array on the stack, copy the 10 values over and
iterate on that. With this patch we put the array in .text use it
directly. Apart from that case this helps on virtually any passing of
a constant std::initializer_list as a function argument.

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

llvm-svn: 231508
2015-03-06 20:00:03 +00:00
David Majnemer e7a818fec8 MS ABI: Insert copy-constructors into the CatchableType
Find all unambiguous public classes of the exception object's class type
and reference all of their copy constructors.  Yes, this is not
conforming but it is necessary in order to implement their ABI.  This is
because the copy constructor is actually referenced by the metadata
describing which catch handlers are eligible to handle the exception
object.

N.B.  This doesn't yet handle the copy constructor closure case yet,
that work is ongoing.

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

llvm-svn: 231499
2015-03-06 18:53:55 +00:00
Alexey Samsonov 48a9db034a Revert "[UBSan] Split -fsanitize=shift into -fsanitize=shift-base and -fsanitize=shift-exponent."
It's not that easy. If we're only checking -fsanitize=shift-base we
still need to verify that exponent has sane value, otherwise
UBSan-inserted checks for base will contain undefined behavior
themselves.

llvm-svn: 231409
2015-03-05 21:57:35 +00:00
David Majnemer 7c23707174 MS ABI: Implement support for throwing a C++ exception
Throwing a C++ exception, under the MS ABI, is implemented using three
components:
- ThrowInfo structure which contains information like CV qualifiers,
  what destructor to call and a pointer to the CatchableTypeArray.
- In a significant departure from the Itanium ABI, copying by-value
  occurs in the runtime and not at the catch site.  This means we need
  to enumerate all possible types that this exception could be caught as
  and encode the necessary information to convert from the exception
  object's type to the catch handler's type.  This includes complicated
  derived to base conversions and the execution of copy-constructors.

N.B. This implementation doesn't support the execution of a
copy-constructor from within the runtime for now.  Adding support for
that functionality is quite difficult due to things like default
argument expressions which may evaluate arbitrary code hiding in the
copy-constructor's parameters.

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

llvm-svn: 231328
2015-03-05 00:46:22 +00:00
Nemanja Ivanovic 55e757db4a Add Clang support for PPC cryptography builtins
Review: http://reviews.llvm.org/D7951

llvm-svn: 231291
2015-03-04 21:48:22 +00:00
Reid Kleckner 533bd17268 Fix test/CodeGen/builtins.c for platforms that don't lower sjlj
Opt in Win64 to supporting sjlj lowering. We have the backend lowering,
so I think this was just an oversight because WinX86_64TargetCodeGenInfo
doesn't inherit from X86_64TargetCodeGenInfo.

llvm-svn: 231280
2015-03-04 19:24:16 +00:00
Reid Kleckner 77b1811fde Try to fix the build after removing DataLayoutPass
llvm-svn: 231278
2015-03-04 19:10:41 +00:00
Joerg Sonnenberger 244a577754 Adjust the changes from r230255 to bail out if the backend can't lower
__builtin_setjmp/__builtin_longjmp and don't fall back to the libc
functions.

llvm-svn: 231245
2015-03-04 14:25:35 +00:00
Alexey Samsonov 783b8174ad [UBSan] Split -fsanitize=shift into -fsanitize=shift-base and -fsanitize=shift-exponent.
-fsanitize=shift is now a group that includes both these checks, so
exisiting users should not be affected.

This change introduces two new UBSan kinds that sanitize only left-hand
side and right-hand side of shift operation. In practice, invalid
exponent value (negative or too large) tends to cause more portability
problems, including inconsistencies between different compilers, crashes
and inadequeate results on non-x86 architectures etc. That is,
-fsanitize=shift-exponent failures should generally be addressed first.

As a bonus, this change simplifies CodeGen implementation for emitting left
shift (separate checks for base and exponent are now merged by the
existing generic logic in EmitCheck()), and LLVM IR for these checks
(the number of basic blocks is reduced).

llvm-svn: 231150
2015-03-03 22:15:35 +00:00
Reid Kleckner fff8e7f6ba Split catch IRgen into ItaniumCXXABI and MicrosoftCXXABI
Use llvm.eh.begincatch for Microsoft-style catches.

This moves lots of CGException code into ItaniumCXXABI. Sorry for the
blame pain.

llvm-svn: 231105
2015-03-03 19:21:04 +00:00
Juergen Ributzka 9baa03fc07 Lower _mm256_broadcastsi128_si256 directly to a vector shuffle.
Originally we were using the same GCC builtins to lower this AVX2 vector
intrinsic. Instead we will now lower it directly to a vector shuffle.

This will not only allow LLVM to generate better code, but it will also allow us
to remove the GCC intrinsics.

Reviewed by Andrea

This is related to rdar://problem/18742778.

llvm-svn: 231081
2015-03-03 17:22:53 +00:00
Benjamin Kramer 83b1bf3a27 CodeGen: Fix passing of classes with only one AVX vector member in AVX registers
isSingleElementStruct was a bit too tight in its definition of struct
so we got a mismatch between classify() and the actual code generation.
To make matters worse the code in GetByteVectorType still defaulted to
<2 x double> if it encountered a type it didn't know, making this a
silent miscompilation (PR22753).

Completely remove the "preferred type" stuff from GetByteVectorType and
make it fail an assertion if someone tries to use it with a type not
suitable for a vector register.

llvm-svn: 230971
2015-03-02 16:09:24 +00:00
Benjamin Kramer 39ccabe500 Replace loop with equivalent ArrayRef function. NFC.
llvm-svn: 230949
2015-03-02 11:57:06 +00:00
Peter Collingbourne d251b0a60e DebugInfo: Give externally defined types a size and alignment where
possible. Fixes PR22736.

llvm-svn: 230914
2015-03-01 22:07:04 +00:00
Saleem Abdulrasool cd187f033e DebugInfo: hoist definition into global context when needed
When generating debug info for a static inline member which is initialized for
the DLLExport storage class, hoist the definition into a non-composite type
context. Otherwise, we would trigger an assertion when generating the DIE for
the associated global value as the debug context has a type association. This
addresses PR22669.

Thanks to David Blakie for help in coming up with a solution to this!

llvm-svn: 230816
2015-02-28 00:13:13 +00:00
Aaron Ballman 152ad170b8 Silence an MSVC warning about not all control paths returning a value; NFC.
llvm-svn: 230754
2015-02-27 13:55:58 +00:00
Alexey Bataev b832926176 [OPENMP] Codegen for "#pragma omp atomic write"
For global reg lvalue - use regular store through global register.
For simple lvalue - use simple atomic store.
For bitfields, vector element, extended vector elements - the original value of the whole storage (for vector elements) or of some aligned value (for bitfields) is atomically read, the part of this value for the given lvalue is modified and then use atomic compare-and-exchange operation to try to atomically write modified value (if it was not modified).
Also, changes in this patch fix the bug for '#pragma omp atomic read' applied to extended vector elements.
Differential Revision: http://reviews.llvm.org/D7369

llvm-svn: 230736
2015-02-27 06:33:30 +00:00
David Majnemer 5bc883f39e MS ABI: Simplify the code which performs base adjustments
llvm-svn: 230722
2015-02-27 02:38:02 +00:00
Nico Weber ff62a6a0b7 Don't crash on leaving nested __finally blocks through an EH edge.
The __finally emission block tries to be clever by removing unused continuation
edges if there's an unconditional jump out of the __finally block. With
exception edges, the EH continuation edge isn't always unused though and we'd
crash in a few places.

Just don't be clever. That makes the IR for __finally blocks a bit longer in
some cases (hence small and behavior-preserving changes to existing tests), but
it makes no difference in general and it fixes the last crash from PR22553.

http://reviews.llvm.org/D7918

llvm-svn: 230697
2015-02-26 22:34:33 +00:00
Nico Weber 6307cf0aa3 Wrap to 80 columns. No behavior change.
llvm-svn: 230682
2015-02-26 20:43:00 +00:00
Alexey Bataev 8cbe0a6b62 [OPENMP] Fixed codegen for directives without function outlining.
Fixed crash on codegen for directives like 'omp for', 'omp single' etc. inside of the 'omp parallel', 'omp task' etc. regions.

llvm-svn: 230621
2015-02-26 10:27:34 +00:00
Duncan P. N. Exon Smith a346e03084 CGDebugInfo: Use DIImportedEntity default constructor, NFC
Use the newly minted `DIImportedEntity` default constructor (r230609)
rather than explicitly specifying `nullptr`.  The latter will become
ambiguous when the new debug info hierarchy is committed, since we'll
have both of the following:

    explicit DIImportedEntity(const MDNode *);
    DIImportedEntity(const MDImportedEntity *);

(Currently we just have the former.)

A default constructor is just as clear.

llvm-svn: 230610
2015-02-26 04:44:27 +00:00
Larisse Voufo 697b32a0cb Improvement on sized deallocation from r230160:
Do not declare sized deallocation functions dependently on whether it is found in global scope. Instead, enforce the branching in emitted code by (1) declaring the functions extern_weak and (2) emitting sized delete expressions as a branching between both forms delete.

llvm-svn: 230580
2015-02-25 23:48:43 +00:00
Peter Collingbourne 69b004d987 UBSan: Use the correct function prologue for x32.
llvm-svn: 230571
2015-02-25 23:18:42 +00:00
David Majnemer dbdab4037e MS ABI: Turn throw into std::terminate for now, make try/catch "work"
This lets us compile programs which make use of exceptional constructs
statically without executing any of them dynamically.

llvm-svn: 230568
2015-02-25 23:01:21 +00:00
David Majnemer ced8bdf74a Sema: Parenthesized bound destructor member expressions can be called
We would wrongfully reject (a.~A)() in both the destructor and
pseudo-destructor cases.

This fixes PR22668.

llvm-svn: 230512
2015-02-25 17:36:15 +00:00
Nico Weber e68b9f3e0a Reland r230460 with a test fix for -Asserts builds.
Original CL description:
Produce less broken basic block sequences for __finally blocks.

The way cleanups (such as PerformSEHFinally) get emitted is that codegen
generates some initialization code, then calls the cleanup's Emit() with the
insertion point set to a good place, then the cleanup is supposed to emit its
stuff, and then codegen might tack in a jump or similar to where the insertion
point is after the cleanup.

The PerformSEHFinally cleanup tries to just stash away the block it's supposed
to codegen into, and then does codegen later, into that stashed block.  However,
after codegen'ing the __finally block, it used to set the insertion point to
the finally's continuation block (where the __finally cleanup goes when its body
is completed after regular, non-exceptional control flow).  That's not correct,
as that block can (and generally does) already ends in a jump.  Instead,
remember the insertion point that was current before the __finally got emitted,
and restore that.

Fixes two of the crashes in PR22553.

llvm-svn: 230503
2015-02-25 16:25:00 +00:00
Daniel Jasper cd94c40b10 Revert "Produce less broken basic block sequences for __finally blocks."
The test is broken on buildbots:
http://lab.llvm.org:8080/green/job/clang-stage2-configure-Rlto_check/2279/

This reverts commit adda738b6dc533c42db5f5f5b31344098a3aba7d.

llvm-svn: 230472
2015-02-25 10:07:14 +00:00
Alexey Bataev 3eff5f46d7 [OPENMP] Rename methods of OpenMPRuntime class. NFC.
llvm-svn: 230470
2015-02-25 08:32:46 +00:00
Nico Weber 795bd2d411 Produce less broken basic block sequences for __finally blocks.
The way cleanups (such as PerformSEHFinally) get emitted is that codegen
generates some initialization code, then calls the cleanup's Emit() with the
insertion point set to a good place, then the cleanup is supposed to emit its
stuff, and then codegen might tack in a jump or similar to where the insertion
point is after the cleanup.

The PerformSEHFinally cleanup tries to just stash away the block it's supposed
to codegen into, and then does codegen later, into that stashed block.  However,
after codegen'ing the __finally block, it used to set the insertion point to
the finally's continuation block (where the __finally cleanup goes when its body
is completed after regular, non-exceptional control flow).  That's not correct,
as that block can (and generally does) already ends in a jump.  Instead,
remember the insertion point that was current before the __finally got emitted,
and restore that.

Fixes two of the crashes in PR22553.

llvm-svn: 230460
2015-02-25 04:05:18 +00:00
Nico Weber ebf9a058c6 Add comments for two CleanupKinds.
llvm-svn: 230459
2015-02-25 03:58:36 +00:00
Adrian Prantl cbc368c5b5 Revert "Wrap clang module files in a Mach-O, ELF, or COFF container."
llvm-svn: 230454
2015-02-25 02:44:04 +00:00
Adrian Prantl 8bf7af3de8 Wrap clang module files in a Mach-O, ELF, or COFF container.
This is a necessary prerequisite for debugging with modules.
The .pcm files become containers that hold the serialized AST which allows
us to store debug information in the module file that can be shared by all
object files that were built importing the module.

This reapplies r230044 with a fixed configure+make build and updated
dependencies and testcase requirements. Over the last iteration this
version adds
- missing target requirements for testcases that specify an x86 triple,
- a missing clangCodeGen.a dependency to libClang.a in the make build.

rdar://problem/19104245

llvm-svn: 230423
2015-02-25 01:31:45 +00:00
Tim Northover bc784d1caa ARM: Simplify PCS handling.
The backend should now be able to handle all AAPCS rules based on argument
type, which means Clang no longer has to duplicate the register-counting logic
and the CodeGen can be significantly simplified.

llvm-svn: 230349
2015-02-24 17:22:40 +00:00
Alexey Bataev d76df6d0ff [OPENMP] Update codegen for 'omp flush' directive.
__kmpc_omp_flush() runtime library now has only one argument and is not a vararg
anymore. This update makes the codegen compatible with these changes.

llvm-svn: 230331
2015-02-24 12:55:09 +00:00
Michael Kuperstein 4f818708a8 [WinX86_64 ABI] Treat C99 _Complex as a struct
MSVC does not support C99 _Complex.
ICC, however, does support it on windows x86_64, and treats it, for purposes of parameter passing, as equivalent to a struct containing two fields (for the real and imaginary part). 

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

llvm-svn: 230315
2015-02-24 09:35:58 +00:00