summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
Commit message (Collapse)AuthorAgeFilesLines
* [OPENMP] Codegen for 'atomic capture'.Alexey Bataev2015-04-232-43/+167
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Unify the way we report overflow in increment/decrement operator.Alexey Samsonov2015-04-231-31/+29
| | | | | | | | | | | | | | | | | | | | 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
* InstrProf: Fix a shadowing error that would break length of profile namesJustin Bogner2015-04-231-2/+2
| | | | | | | | 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
* [WinEH] Don't emit an exceptional cleanup for llvm.eh.endcatchReid Kleckner2015-04-221-3/+2
| | | | | | | | | 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
* Revert "Revert r234581, it might have caused a few miscompiles in Chromium."David Majnemer2015-04-227-34/+100
| | | | | | | | 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
* Set normal LLVM function attributes on global initializer functionsReid Kleckner2015-04-221-0/+2
| | | | | | | | | | | 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
* [OPENMP] Codegen for 'if' clause in 'task' directive.Alexey Bataev2015-04-223-128/+191
| | | | | | | | | | | | | 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
* [OPENMP] Codegen for 'reduction' clause in 'for' directive.Alexey Bataev2015-04-221-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* [OPENMP] Codegen for 'private' clause in 'for' directive.Alexey Bataev2015-04-221-11/+16
| | | | | | | 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
* [OPENMP] Fix use of unsigned counters in loops with zero trip count.Alexey Bataev2015-04-221-51/+90
| | | | | | | | 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
* [OPENMP] Codegen for 'ordered' directive.Alexey Bataev2015-04-224-32/+148
| | | | | | | | | | | | | | | | | | | 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
* [cuda] Allow using integral non-type template parameters as launch_bounds ↵Artem Belevich2015-04-211-11/+15
| | | | | | | | | | | | | | | | 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
* DebugInfo: Prepare for removal of DIArray and DITypeArray typedefsDuncan P. N. Exon Smith2015-04-212-38/+44
| | | | | | | | An upcoming LLVM commit will remove the `DIArray` and `DITypeArray` typedefs that shadow `DebugNodeArray` and `MDTypeRefArray`, respectively. Use those types directly. llvm-svn: 235412
* DebugInfo: Prepare for deletion of DIDescriptor subclassesDuncan P. N. Exon Smith2015-04-212-59/+47
| | | | | | | An upcoming LLVM commit will delete all the remaining subclasses of (the already deleted) `DIDescriptor`. Stop using them. llvm-svn: 235403
* Provide alignment info on LLVM external symbolsUlrich Weigand2015-04-211-0/+2
| | | | | | | | | | | | | | | | | 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
* DebugInfo: Prepare for deletion of subclasses of DIScopeDuncan P. N. Exon Smith2015-04-202-128/+128
| | | | | | | | 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
* DebugInfo: Prepare for deletion of subclasses of DITypeDuncan P. N. Exon Smith2015-04-202-21/+19
| | | | | | | | | | | 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
* DebugInfo: Prepare for deletion of DITypeDuncan P. N. Exon Smith2015-04-202-242/+229
| | | | | | | `DIType` is going to be deleted by an upcoming LLVM commit, so replace uses with `MDType*`. llvm-svn: 235330
* DebugInfo: Prepare for deletion of DIScopeDuncan P. N. Exon Smith2015-04-202-14/+12
| | | | | | | An upcoming LLVM commit will delete `DIScope`, so update users to `MDScope*`. llvm-svn: 235326
* Make helper function static. NFC.Benjamin Kramer2015-04-181-3/+3
| | | | llvm-svn: 235253
* Remove dead code, NFCDuncan P. N. Exon Smith2015-04-181-3/+0
| | | | llvm-svn: 235246
* DebugInfo: Prepare for deletion of DIDescriptorDuncan P. N. Exon Smith2015-04-182-23/+14
| | | | | | Prepare for upcoming LLVM change to delete `DIDescriptor`. llvm-svn: 235245
* Change AArch64 i128 returns to use [2 x i64] when possible.Pete Cooper2015-04-171-0/+8
| | | | | | | | | | 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
* [MS ABI] Use the right types for filter and finally blocksDavid Majnemer2015-04-171-4/+6
| | | | | | | The type for abnormal_termination can't be an i1, it an i8. Filter functions return 'LONG', not 'int'. llvm-svn: 235161
* DebugInfo: Update for LLVM API change in DIBuilder (r235111)Duncan P. N. Exon Smith2015-04-162-113/+96
| | | | | | | | | | | | | | | | | 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
* [OPENMP] Codegen for 'copyin' clause in 'parallel' directive.Alexey Bataev2015-04-162-2/+74
| | | | | | | | | | | | | | | 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
* [OPENMP] Codegen for 'lastprivate' clause in 'for' directive.Alexey Bataev2015-04-162-5/+132
| | | | | | | | | | | | | | | | | | | | | | | | | | | #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
* DebugInfo: Prepare for DIDescriptor to be gutted in LLVMDuncan P. N. Exon Smith2015-04-161-28/+28
| | | | | | | All the API is about to be dropped from `DIDescriptor` in LLVM, so stop using it. llvm-svn: 235068
* DebugInfo: Prepare for DIScope to be gutted in LLVMDuncan P. N. Exon Smith2015-04-161-2/+2
| | | | | | | An upcoming LLVM commit will gut `DIScope`, so just use `MDScope*` directly. llvm-svn: 235066
* DebugInfo: Prepare for DIType to be guttedDuncan P. N. Exon Smith2015-04-161-17/+14
| | | | | | | `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
* DebugInfo: Prepare for LLVM change removing DIType::isValid()Duncan P. N. Exon Smith2015-04-151-3/+3
| | | | | | This is being replaced with a null check. llvm-svn: 235058
* DebugInfo: Prepare for LLVM gutting DICompileUnit/DIFileDuncan P. N. Exon Smith2015-04-151-9/+10
| | | | | | | An upcoming LLVM commit will gut `DICompileUnit` and `DIFile`, so start treating them more like pointers. llvm-svn: 235054
* Don't crash when a selectany symbol would get common linkageNico Weber2015-04-151-2/+7
| | | | | | | | | | | | | | | | 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
* DebugInfo: Pass DebugLocs when creating intrinsicsDuncan P. N. Exon Smith2015-04-151-24/+21
| | | | | | | Update for LLVM API change r235041 that makes `DIBuilder` require a `DebugLoc` to create a debug info intrinsic. llvm-svn: 235042
* Revert "[CodeGen] Fix crash with duplicated mangled name."Renato Golin2015-04-151-9/+8
| | | | | | | | | 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
* [OPENMP] Codegen for 'firstprivate' clause in 'for' directive.Alexey Bataev2015-04-153-60/+83
| | | | | | | | 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
* uselistorder: Remove dead includeDuncan P. N. Exon Smith2015-04-151-1/+0
| | | | | | Forgot to remove the include in r234970 llvm-svn: 234972
* uselistorder: -mllvm -preserve-ll-use-list-order => -emit-llvm-uselistsDuncan P. N. Exon Smith2015-04-151-1/+2
| | | | | | | | | 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
* Change range-based for-loops to be -Wrange-loop-analysis clean.Richard Trieu2015-04-152-2/+2
| | | | | | No functionality change. llvm-svn: 234964
* uselistorder: -mllvm -preserve-bc-use-list-order => -emit-llvm-uselistsDuncan P. N. Exon Smith2015-04-151-1/+1
| | | | | | | | | | | | | | | 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
* Move the logic to avoid double global emission from Sema to CodeGenReid Kleckner2015-04-152-10/+14
| | | | | | | | | | | 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
* uselistorder: Update for LLVM API change in r234959Duncan P. N. Exon Smith2015-04-151-1/+3
| | | | | | | | 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
* Reland r234613 (and follow-ups 234614, 234616, 234618)Reid Kleckner2015-04-144-135/+168
| | | | | | | The frameescape intrinsic cannot be inlined, so I fixed the inliner in r234937. This should address PR23216. llvm-svn: 234942
* Use raw_pwrite_stream in clang.Rafael Espindola2015-04-142-14/+15
| | | | | | This is a small improvement to -emit-pth and allows llvm to start requiring it. llvm-svn: 234897
* [OPENMP] Fixed codegen for arrays in 'copyprivate' clause.Alexey Bataev2015-04-144-105/+160
| | | | | | | 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
* [OPENMP] Initial codegen for 'parallel sections' directive.Alexey Bataev2015-04-142-26/+37
| | | | | | | | | | | | | | | 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
* DebugInfo: Prepare for DISubprogram/DILexicalBlock* to be guttedDuncan P. N. Exon Smith2015-04-141-9/+8
| | | | | | | An upcoming LLVM commit will remove this API, so stop using it. Just access the raw pointers using `operator->()`. llvm-svn: 234848
* Revert r234613 (and follow-ups 234614, 234616, 234618), it caused PR23216.Nico Weber2015-04-134-168/+135
| | | | llvm-svn: 234789
* Revert r234786, it contained a bunch of stuff I did not mean to commit.Nico Weber2015-04-134-135/+168
| | | | llvm-svn: 234787
* Revert r234613 (and follow-ups 234614, 234616, 234618), it caused PR23216.Nico Weber2015-04-134-168/+135
| | | | llvm-svn: 234786
OpenPOWER on IntegriCloud