Commit Graph

108 Commits

Author SHA1 Message Date
Peter Collingbourne bcf909d737 Update clang for D20348
Differential Revision: http://reviews.llvm.org/D20339

llvm-svn: 272710
2016-06-14 21:02:05 +00:00
Yaxun Liu c564701fbd [OpenCL] Fix __builtin_astype for vec3 types.
__builtin_astype does not generate correct LLVM IR for vec3 types. This patch inserts bitcasts to/from vec4 when necessary in addition to generating vector shuffle. Sema and codegen tests are added.

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

llvm-svn: 272153
2016-06-08 15:11:21 +00:00
Matt Arsenault 250024f905 AMDGPU: Verify subtarget specific builtins
Cleanup setup of subtarget features.

llvm-svn: 272091
2016-06-08 01:56:42 +00:00
Jan Vesely 9efec1f11d Disable warning about core features by default
Reviewers: Anastasia, yaxunl

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

llvm-svn: 271414
2016-06-01 18:04:53 +00:00
Jan Vesely e984cab68f Fixup list of available extensions
Reviewers: Anastasia

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

llvm-svn: 271413
2016-06-01 18:04:50 +00:00
Yaxun Liu f7449a179b [OpenCL] Add to_{global|local|private} builtin functions.
OpenCL builtin functions to_{global|local|private} accepts argument of pointer type to arbitrary pointee type, and return a pointer to the same pointee type in different addr space, i.e.

global gentype *to_global(gentype *p);
It is not desirable to declare it as

global void *to_global(void *);
in opencl header file since it misses diagnostics.

This patch implements these builtin functions as Clang builtin functions. In the builtin def file they are defined to have signature void*(void*). When handling call expressions, their declarations are re-written to have correct parameter type and return type corresponding to the call argument.

In codegen call to addr void *to_addr(void*) is generated with addrcasts or bitcasts to facilitate implementation in builtin library.

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

llvm-svn: 270261
2016-05-20 19:54:38 +00:00
Yaxun Liu c537c8a72b [OpenCL] Allow explicit cast of 0 to event_t.
Patch by Aaron Enye Shi.

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

llvm-svn: 270238
2016-05-20 17:18:16 +00:00
Yaxun Liu 39cf40f6b4 [OpenCL] Add supported OpenCL extensions to target info.
Add supported OpenCL extensions to target info. It serves as default values to save the users of the burden setting each supported extensions and optional core features in command line.

Re-commit after fixing build error due to missing override attribute.

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

llvm-svn: 269670
2016-05-16 17:06:34 +00:00
Yaxun Liu fa1df45c0d Revert "[OpenCL] Add supported OpenCL extensions to target info."
Revert r269431 due to build failure caused by warning msg:

  llvm/tools/clang/lib/Basic/Targets.cpp:2090:9: error: 'setSupportedOpenCLOpts' overrides a member function but is not marked 'override' [-Werror,-Winconsistent-missing-override]
   void setSupportedOpenCLOpts() {

llvm-svn: 269435
2016-05-13 17:16:26 +00:00
Yaxun Liu 64936ce91d [OpenCL] Add supported OpenCL extensions to target info.
Add supported OpenCL extensions to target info. It serves as default values to save the users of the burden setting each supported extensions and optional core features in command line.

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

llvm-svn: 269431
2016-05-13 15:44:37 +00:00
Anastasia Stulova 43ab9a00eb [OpenCL] Output OpenCL version in diagnostics.
Diagnostics should note version dependent issues by giving
a hint about current version being compiled for.

This patch changes diagnostics of static storage class specifier
and generic type qualifier to specify OpenCL version as well as
converts other diagnostics to match the style.

Patch by Vedran Miletic!

Review: http://reviews.llvm.org/D19780
llvm-svn: 269305
2016-05-12 16:28:25 +00:00
Xiuli Pan 2d12e65b6b [OpenCL] Fix pipe type dump.
Summary:
Fix the dump of PipeType.
Now we will have "pipe int" and element type.

Reviewers: yaxunl, Anastasia

Subscribers: cfe-commits, bader

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

llvm-svn: 268364
2016-05-03 05:37:07 +00:00
Manman Ren 99d133482f Block: Fix a crash when we have type attributes or qualifiers with omitted
return type.

Emit a warning instead of crashing in IR generation.

rdar://22762981

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

llvm-svn: 266648
2016-04-18 18:40:51 +00:00
Yaxun Liu a1a87adf59 PR19957: [OpenCL] Incorrectly accepts implicit address space conversion with ternary operator.
Generates addrspacecast instead of bitcast for ternary operator when necessary, and diagnose ternary operator with incompatible second and third operands.

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

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

llvm-svn: 266111
2016-04-12 19:43:36 +00:00
Alexey Bader 954ba21f85 [OpenCL] Complete image types support.
I. Current implementation of images is not conformant to spec in the following points:
  1. It makes no distinction with respect to access qualifiers and therefore allows to use images with different access type interchangeably. The following code would compile just fine:

        void write_image(write_only image2d_t img);
        kernel void foo(read_only image2d_t img) { write_image(img); } // Accepted code

     which is disallowed according to s6.13.14.

  2. It discards access qualifier on generated code, which leads to generated code for the above example:

        call void @write_image(%opencl.image2d_t* %img);

     In OpenCL2.0 however we can have different calls into write_image with read_only and wite_only images.
     Also generally following compiler steps have no easy way to take different path depending on the image access: linking to the right implementation of image types, performing IR opts and backend codegen differently.

  3. Image types are language keywords and can't be redeclared s6.1.9, which can happen currently as they are just typedef names.
  4. Default access qualifier read_only is to be added if not provided explicitly.

II. This patch corrects the above points as follows:
  1. All images are encapsulated into a separate .def file that is inserted in different points where image handling is required. This avoid a lot of code repetition as all images are handled the same way in the code with no distinction of their exact type.
  2. The Cartesian product of image types and image access qualifiers is added to the builtin types. This simplifies a lot handling of access type mismatch as no operations are allowed by default on distinct Builtin types. Also spec intended access qualifier as special type qualifier that are combined with an image type to form a distinct type (see statement above - images can't be created w/o access qualifiers).
  3. Improves testing of images in Clang.

Author: Anastasia Stulova
Reviewers: bader, mgrang.
Subscribers: pxli168, pekka.jaaskelainen, yaxunl.
Differential Revision: http://reviews.llvm.org/D17821

llvm-svn: 265783
2016-04-08 13:40:33 +00:00
Anastasia Stulova c4bb5df4ab [OpenCL] Added nosvm attribute for OpenCL v2.0.
It is not widely used and removed from OpenCL v2.1.

This change modifies Clang to parse the attribute for OpenCL
but ignores it afterwards.

Patch by Liu Yaxun (Sam)!

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

llvm-svn: 265006
2016-03-31 11:07:22 +00:00
Xiuli Pan 0a1c6c2ee5 [OpenCL] Fix pipe builtin bugs
Summary:
1. Diag should be output if types are not the same.
2. Should compare using canonical type.
3. Refine the diag to be more clear.

Reviewers: yaxunl, Anastasia

Subscribers: MatsPetersson, pekka.jaaskelainen, cfe-commits

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

llvm-svn: 264825
2016-03-30 04:46:32 +00:00
Xiuli Pan 4415bdbdc3 [OpenCL] Refine pipe builtin support
Summary:
Refine the type builtin support as the request with
http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20160201/148637.html

Reviewers: pekka.jaaskelainen, Anastasia, yaxunl

Subscribers: rsmith, cfe-commits

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

llvm-svn: 262692
2016-03-04 07:11:16 +00:00
Anastasia Stulova 782d5f43ca [OpenCL] Improve diagnostics of address spaces for variables in function
- Prevent local variables to be declared in global AS
 - Diagnose AS of local variables with an extern storage class
   as if they would be in a program scope

Review: http://reviews.llvm.org/D17345
llvm-svn: 262641
2016-03-03 18:38:40 +00:00
Anastasia Stulova 1f95cc097c [OpenCL] Apply missing restrictions for Blocks in OpenCL v2.0
Applying the following restrictions for block types in OpenCL (v2.0 s6.12.5):
 - __block storage class is disallowed
 - every block declaration must be const qualified and initialized
 - a block can't be used as a return type of a function
 - a blocks can't be used to declare a structure or union field
 - extern speficier is disallowed

Corrected image and sampler types diagnostics with struct and unions.

Review: http://reviews.llvm.org/D16928
llvm-svn: 262616
2016-03-03 13:33:19 +00:00
Matt Arsenault 39edcd0e1d AMDGPU: Add builtins for recently added intrinsics
llvm-svn: 262126
2016-02-27 09:54:43 +00:00
Xiuli Pan 11e13f60ea [OpenCL] Refine OpenCLImageAccessAttr to OpenCLAccessAttr
Summary:
OpenCL access qualifiers are now not only used for image types, refine it to avoid misleading,

Add semacheck for OpenCL access qualifier as well as test caees.

Reviewers: pekka.jaaskelainen, Anastasia, aaron.ballman

Subscribers: aaron.ballman, cfe-commits

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

llvm-svn: 261961
2016-02-26 03:13:03 +00:00
Xiuli Pan 379554ac5b [OpenCL] Add Sema checks for types
Summary:
Add Sema checks for opencl type: image, pipe....
This patch is partitioned from http://reviews.llvm.org/D16047

Reviewers: Anastasia, yaxunl

Subscribers: pekka.jaaskelainen, cfe-commits

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

llvm-svn: 261818
2016-02-25 03:34:20 +00:00
Xiuli Pan 89307aa3e9 [OpenCL] Add Sema checks for OpenCL 2.0 block
Summary:
Add Sema checks for opencl 2.0 new features: Block.
This patch is partitioned from http://reviews.llvm.org/D16047

Reviewers: Anastasia

Subscribers: pekka.jaaskelainen, cfe-commits

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

llvm-svn: 261719
2016-02-24 04:29:36 +00:00
Anastasia Stulova 6bdbcbb3d9 [OpenCL] Generate metadata for opencl_unroll_hint attribute
Add support for opencl_unroll_hint attribute from OpenCL v2.0 s6.11.5.

Reusing most of metadata generation from CGLoopInfo helper class.

The code is based on Khronos OpenCL compiler:
https://github.com/KhronosGroup/SPIR/tree/spirv-1.0

Patch by Liu Yaxun (Sam)!

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

llvm-svn: 261350
2016-02-19 18:30:11 +00:00
Anastasia Stulova 5c1a2c5d3e [OpenCL] Added half type literal with suffix h.
OpenCL Extension v1.2 s9.5 allows half precision floating point
type literals with suffices h or H when cl_khr_fp16 is enabled.

Example:  half x = 1.0h;

Patch by Liu Yaxun (Sam)!

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

llvm-svn: 261084
2016-02-17 11:34:37 +00:00
Anastasia Stulova 1202de3ec8 [OpenCL] Disable C99 standard lib functions
The library functions defined in the C99 standard headers
are not available (OpenCL v1.2 s6.9.f). 

This change stops treating OpenCL builtin functions as standard C lib
functions to eliminate warning messages about printf format string.

Patch by Liu Yaxun (Sam)!

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

llvm-svn: 260671
2016-02-12 12:07:04 +00:00
Anastasia Stulova 735c6cdebd [OpenCL] Adding reserved operator logical xor for OpenCL
This patch adds the reserved operator ^^ when compiling for OpenCL (spec v1.1 s6.3.g),
which results in a more meaningful error message.

Patch by Neil Hickey!

Review: http://reviews.llvm.org/D13280

M    test/SemaOpenCL/unsupported.cl
M    include/clang/Basic/TokenKinds.def
M    include/clang/Basic/DiagnosticParseKinds.td
M    lib/Basic/OperatorPrecedence.cpp
M    lib/Lex/Lexer.cpp
M    lib/Parse/ParseExpr.cpp

llvm-svn: 259651
2016-02-03 15:17:14 +00:00
Anastasia Stulova b607e0f238 [OpenCL] Eliminate warning when declaring OpenCL builtin functions.
OpenCL builtin functions are usually declared in header files.
Currently clang emits warning for OpenCL builtin functions
which have the same name as standard C library functions.

This commit eliminates such warnings by not adding the C standard
includes following the restriction from OpenCL v1.2 s6.9.f.

Patch by Liu Yaxun (Sam)!

Review: http://reviews.llvm.org/D16692
llvm-svn: 259491
2016-02-02 11:29:43 +00:00
George Burgess IV a2f29fa694 [Sema] Make extended vectors of `bool` an error.
In OpenCL, `bool` vectors are a reserved type, and are therefore
illegal.

Outside of OpenCL, if we try to make an extended vector of N `bool`s,
Clang will lower it to an `[N x i1]`. LLVM has no ABI for bitvectors, so
lots of operations on such vectors are thoroughly broken. As a result,
this patch makes them illegal in everything else, as well. :)

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

llvm-svn: 259011
2016-01-28 01:38:18 +00:00
Xiuli Pan bb4d8d30b1 Recommit: R258773 [OpenCL] Pipe builtin functions
Fix arc patch fuzz error.
Summary:
Support for the pipe built-in functions for OpenCL 2.0.
The pipe builtin functions may have infinite kinds of element types, one approach
would be to just generate calls that would always use generic types such as void*.
This patch is based on bader's opencl support patch on SPIR-V branch.

Reviewers: Anastasia, pekka.jaaskelainen

Subscribers: keryell, bader, cfe-commits

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

llvm-svn: 258782
2016-01-26 04:03:48 +00:00
David Majnemer 747f168e8d Revert "[OpenCL] Pipe builtin functions"
This reverts commit r258773, it broke the build bots:
http://bb.pgr.jp/builders/cmake-clang-x86_64-linux/builds/43853

llvm-svn: 258775
2016-01-26 02:22:31 +00:00
Xiuli Pan 3a9952c9e7 [OpenCL] Pipe builtin functions
Summary:
Support for the pipe built-in functions for OpenCL 2.0.
The pipe builtin functions may have infinite kinds of element types, one approach
would be to just generate calls that would always use generic types such as void*.
This patch is based on bader's opencl support patch on SPIR-V branch.

Reviewers: Anastasia, pekka.jaaskelainen

Subscribers: keryell, bader, cfe-commits

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

llvm-svn: 258773
2016-01-26 02:06:04 +00:00
Xiuli Pan 9c14e28211 [OpenCL] Pipe type support
Summary:
Support for OpenCL 2.0 pipe type.
This is a bug-fix version for bader's patch reviews.llvm.org/D14441


Reviewers: pekka.jaaskelainen, Anastasia

Subscribers: bader, Anastasia, cfe-commits

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

llvm-svn: 257254
2016-01-09 12:53:17 +00:00
Anastasia Stulova cf04d04ccf [OpenCL] Disallow taking an address of a function.
An undecorated function designator implies taking the address of a function,
which is illegal in OpenCL. Implementing a check for this earlier to allow
the error to be reported even in the presence of other more obvious errors.

Patch by Neil Hickey!

http://reviews.llvm.org/D15691

llvm-svn: 256838
2016-01-05 14:39:27 +00:00
Anastasia Stulova 2446b8ba8a [OpenCL 2.0] In OpenCL v2.0 s6.5 all pointers are implicitly in generic
address space unless address space is explicitly specified.

Correct the behavior of NULL constant detection -
generic AS void pointer should be accepted as a valid NULL constant.

http://reviews.llvm.org/D15293

llvm-svn: 255346
2015-12-11 17:41:19 +00:00
Anastasia Stulova f016a1bb86 Reverting r255337 as it seems to kill bots. Needs investigation.
llvm-svn: 255339
2015-12-11 15:23:00 +00:00
Anastasia Stulova 12e484e80a [OpenCL 2.0] In OpenCL v2.0 s6.5 all pointers are implicitly in generic
address space unless address space is explicitly specified.

Correct the behavior of NULL constant detection -
generic AS void pointer should be accepted as a valid NULL constant.

http://reviews.llvm.org/D15293

llvm-svn: 255337
2015-12-11 13:49:15 +00:00
Anastasia Stulova 784fb78274 [OpenCL 2.0] Apply default address space (AS).
If AS of a variable/parameter declaration is not set by the source,
OpenCL v2.0 s6.5 defines explicit rules for default ASes:

- The AS of global and local static variables defaults to global;
- All pointers point to generic AS.

http://reviews.llvm.org/D13168

llvm-svn: 253863
2015-11-23 11:14:44 +00:00
Anastasia Stulova bd3c08e301 [OpenCL] Add test for program scope variable restrictions in OpenCL v2.0
http://reviews.llvm.org/D13105

llvm-svn: 250892
2015-10-21 10:37:57 +00:00
Anastasia Stulova bcea69669f [OpenCL 2.0] Enable program scope variables, Section 6.5.1.
- Remove virtual SC_OpenCLWorkGroupLocal storage type specifier
as it conflicts with static local variables now and prevents
diagnosing static local address space variables correctly.

 - Allow static local and global variables (OpenCL2.0 s6.8 and s6.5.1).

 - Improve diagnostics of allowed ASes for variables in different scopes:
(i) Global or static local variables have to be in global
or constant ASes (OpenCL1.2 s6.5, OpenCL2.0 s6.5.1);
(ii) Non-kernel function variables can't be declared in local
or constant ASes (OpenCL1.1 s6.5.2 and s6.5.3).

http://reviews.llvm.org/D13105

llvm-svn: 248906
2015-09-30 14:08:20 +00:00
Alexey Bader f961e755b1 [OpenCL] Improve diagnostics detecting implicit vector conversion.
Reviewers: pekka.jaaskelainen

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

llvm-svn: 246393
2015-08-30 18:06:39 +00:00
Davide Italiano 32cbff7809 [Sema] Be consistent about diagnostic wording: always use "cannot".
Discussed with Richard Smith.

llvm-svn: 245162
2015-08-15 15:23:14 +00:00
Sameer Sahasrabuddhe a75db66eee Restores r228382, which was reverted in r228406.
The original commit failed to handle "shift assign" (<<=), which
broke the test mentioned in r228406. This is now fixed and the
test added to the lit tests under SemaOpenCL.

*** Original commit message from r228382 ***

OpenCL: handle shift operator with vector operands

Introduce a number of checks:
1. If LHS is a scalar, then RHS cannot be a vector.
2. Operands must be of integer type.
3. If both are vectors, then the number of elements must match.

Relax the requirement for "usual arithmetic conversions":
When LHS is a vector, a scalar RHS can simply be expanded into a
vector; OpenCL does not require that its rank be lower than the LHS.
For example, the following code is not an error even if the implicit
type of the constant literal is "int".

  char2 foo(char2 v) { return v << 1; }

Consolidate existing tests under CodeGenOpenCL, and add more tests
under SemaOpenCL.

llvm-svn: 230464
2015-02-25 05:48:23 +00:00
Tom Stellard 96d5dc77fa Revert "OpenCL: handle shift operator with vector operands"
This reverts commit r228382.

This breaks the following case:  Reported by Jeroen Ketema:
http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20150202/122961.html

typedef __attribute__((ext_vector_type(3))) char char3;

void foo() {
 char3 v = {1,1,1};
 char3 w = {1,2,3};

 w <<= v;
}

If I compile with:

 clang -x cl file.c

Then an error is produced:

file.c:10:5: error: expression is not assignable
 w <<= v;
 ~ ^
1 error generated.

llvm-svn: 228406
2015-02-06 17:30:04 +00:00
Sameer Sahasrabuddhe c65605d008 OpenCL: handle shift operator with vector operands
Introduce a number of checks:
1. If LHS is a scalar, then RHS cannot be a vector.
2. Operands must be of integer type.
3. If both are vectors, then the number of elements must match.

Relax the requirement for "usual arithmetic conversions":
When LHS is a vector, a scalar RHS can simply be expanded into a
vector; OpenCL does not require that its rank be lower than the LHS.
For example, the following code is not an error even if the implicit
type of the constant literal is "int".

  char2 foo(char2 v) { return v << 1; }

Consolidate existing tests under CodeGenOpenCL, and add more tests
under SemaOpenCL.

llvm-svn: 228382
2015-02-06 05:44:55 +00:00
Sameer Sahasrabuddhe e8d2aaf320 OpenCL: handle ternary operator when the condition is a vector
When the condition is a vector, OpenCL specifies additional
requirements on the operand types, and also the operations
required to determine the result type of the operator. This is a
combination of OpenCL v1.1 s6.3.i and s6.11.6, and the semantics
remain unchanged in later versions of OpenCL.

llvm-svn: 228118
2015-02-04 06:38:18 +00:00
Fraser Cormack cc6e894587 Fix OpenCL 1.2 double as an optional core feature behaviour
In OpenCL 1.2, using double no longer requires using the pragma cl_khr_fp64,
instead a kernel is allowed to use double, but must first have queried
clGetDeviceInfo's CL_DEVICE_DOUBLE_FP_CONFIG.

Page 197, section 6.1.1 of the OpenCL 1.2 specification has a footnote 23
describing this behaviour.

I've also added test cases such that the pragma must be used if targeting
OpenCL 1.0 or 1.1, but is ignored in 1.2 and 2.0.

Patch by Neil Henning!

Reviewers: Pekka Jääskeläinen

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

llvm-svn: 227565
2015-01-30 10:51:46 +00:00
Matt Arsenault b9e9dc5e89 Workaround attribute ordering issue with kernel only attributes
Placing the attribute after the kernel keyword would incorrectly
reject the attribute, so use the smae workaround that other
kernel only attributes use.

Also add a FIXME because there are two different phrasings now
for the same error, althoug amdgpu_num_[sv]gpr uses a consistent one.

llvm-svn: 223490
2014-12-05 18:03:58 +00:00
Matt Arsenault 43fae6c855 Add attributes for AMDGPU register limits.
This is a performance hint that can be applied to kernels
to attempt to limit the number of used registers.

llvm-svn: 223384
2014-12-04 20:38:18 +00:00