Commit Graph

170 Commits

Author SHA1 Message Date
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 Blaikie bdf40a62a7 Test case updates for explicit type parameter to the gep operator
llvm-svn: 232187
2015-03-13 18:21:46 +00:00
Alexey Bataev 1d160b1945 [OPENMP] Additional sema analysis for 'omp atomic[ update]'.
Adds additional semantic analysis + generation of helper expressions for proper codegen.

llvm-svn: 232164
2015-03-13 12:27:31 +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
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
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
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 da19af4f42 [OPENMP] Fixed tests for non-debug builds. NFC.
llvm-svn: 231758
2015-03-10 05:28:46 +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
David Blaikie a953f2825b Update Clang tests to handle explicitly typed load changes in LLVM.
llvm-svn: 230795
2015-02-27 21:19:58 +00:00
David Blaikie 218b783192 Update Clang tests to handle explicitly typed gep changes in LLVM.
llvm-svn: 230783
2015-02-27 19:18:17 +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
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
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
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
David Majnemer a5b195a1dc Revert "Revert r229082 for a bit, it caused PR22577."
This reverts commit r229123.  It was a red herring, the bug was present
without r229082.

llvm-svn: 229205
2015-02-14 01:35:12 +00:00
Nico Weber 7ce96b853d Revert r229082 for a bit, it caused PR22577.
llvm-svn: 229123
2015-02-13 16:27:00 +00:00
David Majnemer abc482effc MS ABI: Implement /volatile:ms
The /volatile:ms semantics turn volatile loads and stores into atomic
acquire and release operations.  This distinction is important because
volatile memory operations do not form a happens-before relationship
with non-atomic memory.  This means that a volatile store is not
sufficient for implementing a mutex unlock routine.

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

llvm-svn: 229082
2015-02-13 07:55:47 +00:00
Alexey Bataev 6956e2e683 [OPENMP] Initial codegen for 'single' directive.
This patch emits the following code for the single directive:

#pragma omp single
<body>
<---->

if(__kmpc_single(...)) {
    <body>
      __kmpc_end_single(...);
}
Differential Revision: http://reviews.llvm.org/D7045

llvm-svn: 228275
2015-02-05 06:35:41 +00:00
Alexey Bataev 9f797f32e2 [OPENMP] Codegen for 'taskyield' directive
For 'taskyield' directive emit call to kmp_int32 __kmpc_omp_taskyield(ident_t *,
kmp_int32 global_tid, int end_part); runtime function call with end_part arg set
to 0 (it is ignored).
Differential Revision: http://reviews.llvm.org/D7047

llvm-svn: 228272
2015-02-05 05:57:51 +00:00
Alexander Musman df7a8e2bc8 Support ‘omp for’ with static chunked schedule kind.
Differential Revision: http://reviews.llvm.org/D7006

llvm-svn: 226795
2015-01-22 08:49:35 +00:00
Alexey Bataev b57056f483 [OPENMP] CodeGen for "omp atomic read [seq_cst]" directive.
"omp atomic read [seq_cst]" accepts expressions "v=x;". In this patch we perform
an atomic load of "x" (using builtin atomic loading instructions or a call to
"atomic_load()" for simple lvalues and "kmpc_atomic_start();load
<x>;kmpc_atomic_end();" for other lvalues), convert the result of loading to
type of "v" (using EmitScalarConversion() for simple types and
EmitComplexToScalarConversion() for conversions from complex to scalar) and then
store the result in "v".)
Differential Revision: http://reviews.llvm.org/D6431

llvm-svn: 226788
2015-01-22 06:17:56 +00:00
Alexey Bataev 02e1ec6966 Revert commit revision 226786
Need to add initialization of AtomicInfo::EvaluationKind field

llvm-svn: 226787
2015-01-22 06:09:48 +00:00
Alexey Bataev 92efdce503 [OPENMP] CodeGen for "omp atomic read [seq_cst]" directive.
"omp atomic read [seq_cst]" accepts expressions "v=x;". In this patch we perform
an atomic load of "x" (using builtin atomic loading instructions or a call to
"atomic_load()" for simple lvalues and "kmpc_atomic_start();load
<x>;kmpc_atomic_end();" for other lvalues), convert the result of loading to
type of "v" (using EmitScalarConversion() for simple types and
EmitComplexToScalarConversion() for conversions from complex to scalar) and then
store the result in "v".)
Differential Revision: http://reviews.llvm.org/D6431

llvm-svn: 226786
2015-01-22 05:44:37 +00:00
Alexey Bataev 137421c8a9 Revert commit r226784.
Accidentally modified file SemaType.cpp must be restored to its original state. 

llvm-svn: 226785
2015-01-22 05:35:53 +00:00
Alexey Bataev 13c7c4930c [OPENMP] CodeGen for "omp atomic read [seq_cst]" directive.
"omp atomic read [seq_cst]" accepts expressions "v=x;". In this patch we perform
an atomic load of "x" (using builtin atomic loading instructions or a call to
"atomic_load()" for simple lvalues and "kmpc_atomic_start();load
<x>;kmpc_atomic_end();" for other lvalues), convert the result of loading to
type of "v" (using EmitScalarConversion() for simple types and
EmitComplexToScalarConversion() for conversions from complex to scalar) and then
store the result in "v".
Differential Revision: http://reviews.llvm.org/D6431

llvm-svn: 226784
2015-01-22 05:29:28 +00:00
Reid Kleckner 1d59f99f5c Initial support for Win64 SEH IR emission
The lowering looks a lot like normal EH lowering, with the exception
that the exceptions are caught by executing filter expression code
instead of matching typeinfo globals. The filter expressions are
outlined into functions which are used in landingpad clauses where
typeinfo would normally go.

Major aspects that still need work:
- Non-call exceptions in __try bodies won't work yet. The plan is to
  outline the __try block in the frontend to keep things simple.
- Filter expressions cannot use local variables until capturing is
  implemented.
- __finally blocks will not run after exceptions. Fixing this requires
  work in the LLVM SEH preparation pass.

The IR lowering looks like this:

// C code:
bool safe_div(int n, int d, int *r) {
  __try {
    *r = normal_div(n, d);
  } __except(_exception_code() == EXCEPTION_INT_DIVIDE_BY_ZERO) {
    return false;
  }
  return true;
}

; LLVM IR:
define i32 @filter(i8* %e, i8* %fp) {
  %ehptrs = bitcast i8* %e to i32**
  %ehrec = load i32** %ehptrs
  %code = load i32* %ehrec
  %matches = icmp eq i32 %code, i32 u0xC0000094
  %matches.i32 = zext i1 %matches to i32
  ret i32 %matches.i32
}

define i1 zeroext @safe_div(i32 %n, i32 %d, i32* %r) {
  %rr = invoke i32 @normal_div(i32 %n, i32 %d)
      to label %normal unwind to label %lpad

normal:
  store i32 %rr, i32* %r
  ret i1 1

lpad:
  %ehvals = landingpad {i8*, i32} personality i32 (...)* @__C_specific_handler
      catch i8* bitcast (i32 (i8*, i8*)* @filter to i8*)
  %ehptr = extractvalue {i8*, i32} %ehvals, i32 0
  %sel = extractvalue {i8*, i32} %ehvals, i32 1
  %filter_sel = call i32 @llvm.eh.seh.typeid.for(i8* bitcast (i32 (i8*, i8*)* @filter to i8*))
  %matches = icmp eq i32 %sel, %filter_sel
  br i1 %matches, label %eh.except, label %eh.resume

eh.except:
  ret i1 false

eh.resume:
  resume
}

Reviewers: rjmccall, rsmith, majnemer

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

llvm-svn: 226760
2015-01-22 01:36:17 +00:00
Alexey Bataev 42971a3342 [OPENMP] Fixed DSA processing for predetermined shared variables.
This patch allows to use predetermined shared variables in private clauses in
parallel or tasks regions.

llvm-svn: 226549
2015-01-20 07:03:46 +00:00
Alexey Bataev 3255bf3aac [OPENMP] Disable copyprivate an nowait clauses in 'single' directive.
The copyprivate clause must not be used with the nowait clause in single
directive.

llvm-svn: 226429
2015-01-19 05:20:46 +00:00
Alexey Bataev 24b04aa393 [OPENMP] Fixed data-sharing attributes processing for variables with global
storage.
This fix allows to use non-constant global variables, static local variables and static data
members in data-sharing attribute clauses in parallel and task regions.

llvm-svn: 226250
2015-01-16 07:11:33 +00:00
Alexey Bataev 26a3924a4f [OPENMP] Consider global named register variables as threadprivate by default.
Register are thread-local by default, so we have to consider them as threadprivate.

llvm-svn: 225759
2015-01-13 03:35:30 +00:00
Duncan P. N. Exon Smith 4bbe428cc5 IR: Add 'distinct' MDNodes to bitcode and assembly (clang)
Update testcases for LLVM change in r225474 to make `MDNode`s explicitly
distinct (when they aren't uniqued).

Part of PR22111.

llvm-svn: 225475
2015-01-08 22:39:28 +00:00
Alexey Bataev f841bd9fcd [OPENMP] Bugfix for processing of global variables in OpenMP regions.
Currently, if global variable is marked as a private OpenMP variable, the compiler crashes in debug version or generates incorrect code in release version. It happens because in the OpenMP region the original global variable is used instead of the generated private copy. It happens because currently globals variables are not captured in the OpenMP region.
This patch adds capturing of global variables iff private copy of the global variable must be used in the OpenMP region.
Differential Revision: http://reviews.llvm.org/D6259

llvm-svn: 224323
2014-12-16 07:00:22 +00:00
Duncan P. N. Exon Smith b3a66691f8 IR: Make metadata typeless in assembly, clang side
Match LLVM changes from r224257.

llvm-svn: 224259
2014-12-15 19:10:08 +00:00
Alexander Musman 51eb1308bd Test for 'omp for' (for r224233).
llvm-svn: 224234
2014-12-15 07:08:38 +00:00
Alexey Bataev 39bd119842 [OPENMP] Test for 'omp barrier' directive
llvm-svn: 223445
2014-12-05 04:10:27 +00:00
Alexey Bataev 8f7c1b0b9d [OPENMP] Codegen for 'omp barrier' directive.
Adds generation of call to "i32 kmpc_cancel_barrier(ident_t *, i32)" libcall for explicitly specified barriers (OMP_IDENT_BARRIER_EXPL flag is added to "flags" field of "ident_t" structure).
Also this patch replaces all calls to "kmpc_barrier" function by calls of "__kmpc_cancel_barrier" function which provides additional functionality for OpenMP 4.0.
Also, library specific enum OpenMPLocationFlags moved to private section of CGOpenMPRuntime class to make it more independent from library implementation.
Differential Revision: http://reviews.llvm.org/D6447

llvm-svn: 223444
2014-12-05 04:09:23 +00:00
Alexey Bataev 8d690650e8 [OPENMP] Codegen for 'omp master' directive
Patch adds 2 library functions to OpenMPRuntime class - int32 kmpc_master(ident_t *, int32 gtid) and void kmpc_end_master(ident_t *, int32 gtid);
For 'omp master' directive the next code is generated:

if (__kmpc_master(loc, gtid)) {
    <Associated structured block>;
      __kmpc_end_master(log, gtid);
}

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

llvm-svn: 223342
2014-12-04 07:23:53 +00:00
Alexey Bataev f33eba6573 [OPENMP] Additional processing of 'omp atomic write' directive.
According to OpenMP standard, Section 2.12.6, atomic Construct, '#pragma omp atomic write' is allowed to be used only for expression statements of form 'x = expr;', where x is a lvalue expression and expr is an expression with scalar type. Patch adds checks for it.

llvm-svn: 222913
2014-11-28 07:21:40 +00:00
Daniel Sanders 1f07d06d61 Support matching signext attribute in the parallel_num_threads_codegen test to appease clang-cmake-mips builder.
The Mips target adds the signext attribute to signed 32-bit integers in order
to support the N32/N64 correctly. Integers must be promoted to 64-bit bit on
these ABI's.

llvm-svn: 222618
2014-11-22 16:21:18 +00:00
Alexey Bataev cc37cc1db2 [OPENMP] Codegen for "omp flush" directive.
For each "omp flush" directive a call to "void kmpc_flush(ident_t *, ...)" function is generated.
Directive "omp flush" may have an associated list of variables to flush, but currently runtime function ignores them. So the patch generates just "call kmpc_flush(ident_t *<loc>, i32 0)".
Differential Revision: http://reviews.llvm.org/D6292

llvm-svn: 222409
2014-11-20 04:34:54 +00:00
Alexey Bataev 62cec44ca4 [OPENMP] Additional processing of 'omp atomic read' directive.
According to OpenMP standard, Section 2.12.6, atomic Construct, '#pragma omp atomic read' is allowed to be used only for expression statements of form 'v = x;', where x and v (as applicable) are both l-value expressions with scalar type. Patch adds checks for it.

llvm-svn: 222231
2014-11-18 10:14:22 +00:00
Alexey Bataev 9aba41c822 [OPENMP] Temporary fix for processing of global variables in loops.
Currently there is a bug in processing of global variables used as loop control variables in 'omp for/simd' constructs: these globals must be captured as private variables, but currently they are nor. This is a temporary bug fix for this problem until the correct solution is prepared. If a global var used as lcv without explicit mark as a private/linear/lastprivate the error message is emitted.

llvm-svn: 221970
2014-11-14 04:08:45 +00:00
Alexey Bataev 9772000a22 [OPENMP] Codegen for threadprivate variables
For all threadprivate variables which have constructor/destructor emit call to void __kmpc_threadprivate_register(ident_t * <Current Location>, void *<Original Global Addr>, kmpc_ctor <Constructor>, kmpc_cctor NULL, kmpc_dtor <Destructor>); 
In expressions all references to such variables are replaced by calls to void *__kmpc_threadprivate_cached(ident_t *<Current Location>, kmp_int32 <Current Thread Id>, void *<Original Global Addr>, size_t <Size of Data>, void ***<Pointer to autogenerated cache – array of private copies of threadprivate variable>);
Test test/OpenMP/threadprivate_codegen.cpp checks that codegen is correct. Also it checks that codegen is correct after serialization/deserialization and one of passes verifies debug info.
Differential Revision: http://reviews.llvm.org/D4002

llvm-svn: 221663
2014-11-11 04:05:39 +00:00
Alexey Bataev 03b340a3a5 [OPENMP] Codegen for 'private' clause in 'parallel' directive.
This patch generates some helper variables which used as a private copies of the corresponding original variables inside an OpenMP 'parallel' directive. These generated variables are initialized by default (with the default constructor, if any). In outlined function references to original variables are replaced by the references to these private helper variables. At the end of the initialization of the private variables and implicit barier is set by calling __kmpc_barrier(...) runtime function to be sure that all threads were initialized using original values of the variables.
Differential Revision: http://reviews.llvm.org/D4752

llvm-svn: 220262
2014-10-21 03:16:40 +00:00
Ulrich Weigand 799c3d3a04 More OpenMP test case compatibility fixes
Allow "signext" in a couple of more places in recently
added test cases to fix failures on SystemZ.

llvm-svn: 219615
2014-10-13 13:49:39 +00:00