Commit Graph

81 Commits

Author SHA1 Message Date
Andrew Woloszyn
4ddb431b16 Fixed internal compiler error in gcc-4.9.
This showed up in mips and mips64 builds. A combination of templates
and the error reporting were causing gcc to crash. This splits up the
functionality in a way that now successfully compiles.
2016-02-17 13:07:33 -05:00
David Neto
31c0870367 Configure gmock locally only if not already configured.
Allows an enclosing project to have already configured gmock, even
if the developer has placed the googletest sources under this
project's external/googletest directory.

Describe how to enable the tests in the two essential scenarios:
where SPIR-V Tools is standalone, or where SPIR-V Tools is configured
as a part of a larger project.
2016-02-16 11:52:15 -05:00
Dejan Mircevski
6428933408 Enable ctest. 2016-02-02 16:05:11 -05:00
Dejan Mircevski
0c8bdfe163 Use AssemblyGrammar for capability validation.
Also:
- ForEach() for spv_capability_mask_t.
- Add capability min/max constants.
- Move max definition from validate_types.cpp to spirv_definition.h.
2016-02-02 11:40:05 -05:00
Dejan Mircevski
8177fbea06 Fix in-function storage class validation.
Move tests into a fixture that properly turns on the relevant passes.
2016-01-29 16:30:23 -05:00
Umar Arshad
61a627586b Initial capability implementation and unit tests
* Register capabilility and checks
* Add validate storage class capabilities checks and tests
* Instruction pass refactor
  - More generic form of capability checking by checking operands
    instead of instructions
* Execution Model capabilities checks
* Decorate BuiltIn capability checks
* Addressing Model capability checks
* Memory Model capability checks
* Execution Mode capability checks
* Dim capability checks
* SamplerAddressingMode capability checks
2016-01-27 08:37:23 -05:00
Lei Zhang
3fade33c06 Qualify CMake function names with "spvtools" to avoid conflictions.
If a third-party project defines a CMake function with the same
name, by importing that project's CMake configuration, we may end
up overwriting our own copy. Qualify all defined functions to
reduce that probability.
2016-01-26 18:04:55 -05:00
Dejan Mircevski
961f5dc544 Track uses and defs during parsing.
Replace two other, imperfect mechanisms for use-def tracking.

Use ValidationState_t::entry_points to track entry points.

Concentrate undefined-ID diagnostics in a single place.

Move validate_types.h content into validate.h due to increased
inter-dependency.

Track uses of all IDs: TYPE_ID, SCOPE_ID, ...

Also update some blurbs.

Fix entry-point accumulation and move it outside ProcessIds().

Remove validate_types.h from CMakeLists.txt.

Blurb for spvIsIdType.

Remove redundant diagnostics for undefined IDs.

Join "can not" and reformat.
2016-01-20 17:00:58 -05:00
David Neto
e8b1d12c2f Disable warnings C4503 on MSVC for test code
C4503 is "decorated name length exceeded", triggered
by some heavily templated types.
2016-01-15 10:43:39 -05:00
Umar Arshad
1ddeb246eb Validation refactor
* Organize passes into seperate files
* Remove module layout logic from Cfg pass
* Remove module layout logic from Functions class
* Refactor ModuleLayoutPass for readability
* Adapt consistent naming of layout sections (Stage/Section -> Section)
2016-01-14 21:59:28 -05:00
David Neto
5d30edb36d spvDiagnosticDestroy is safe to call on nullptr
Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/62
2016-01-11 14:26:46 -05:00
Andrew Woloszyn
7a35473573 Made compilation with gcc and clang more strict.
Added additional compilation flags to gcc and clang builds.
Adds -Wall -Wextra -Wno-long-long -Wshadow -Wundef -Wconversion
-WNo-sign-conversion and -Wno-missing-field-initializers
where appropriate.

Does not add -Wundef to tests, because GTEST tests undefined
macros all over the place.
2016-01-11 10:54:20 -05:00
Dejan Mircevski
b6fe02fc39 Extend copyright to 2016. 2016-01-07 13:44:22 -05:00
David Neto
1a3734d265 Avoid relative path in #include
Adds CMAKE_CURRENT_SOURCE_DIR to the include path for UnitSPIRV
2016-01-04 13:07:45 -05:00
David Neto
4c21571728 Rename endian.h to spirv_endian.h
If we later add a source/ as an -I include directory,
then avoid confusing other headers that want to include the
standard "endian.h" from /usr/include.

Also rename source/endian.cpp to source/spirv_endian.cpp
2016-01-04 10:47:27 -05:00
Umar Arshad
a3d0d3c719 Initial logical layout validation
* Validates module level instructions for logical layout
  conformance
* Does not validate:
  1. Function logical layout
  2. Minor cases with OpVariable
  3. Missing MemoryModel instruction in module
  4. Order of function definition and function declaration
* 782 unit tests for logical layout

Addressed feedback
2015-12-17 15:58:09 -05:00
Umar Arshad
6d37e3c5f3 Refactor validation types into another file 2015-12-17 15:56:58 -05:00
David Neto
411de16386 Fix setting of off-by-default cmake options
An enclosing CMake project should be able to set the
off-by-default CMake options in SPIRV-Tools by just doing:
  set(SPIRV_SKIP_EXECUTABLES ON)
instead of
  set(SPIRV_SKIP_EXECUTABLES ON CACHE BOOL "" FORCE)

Also, fix the SPIRV_WARN_EVERYTHING so it understands which options
to send to Clang vs. GCC.

Note: With SPIRV_WARN_EVERYTHING enabled, the code doesn't
compil with either Clang or GCC.
2015-12-10 10:33:51 -05:00
Umar Arshad
f76e0f5231 Basic SSA Validation
Most uses of an ID must occur after the definition
of the ID.  Forward references are allowed for
things like OpName, OpDecorate, and various cases
of control-flow instructions such as OpBranch, OpPhi,
and OpFunctionCall.

TODO: Use CFG analysis for SSA checks.  In particular,
an ID defined inside a function body is only usable inside
that function body.  Also, use dominator info to catch
some failing cases.

Also:
* Validator test cases use (standard) assignment form.
* Update style to more closely follow the Google C++ style guide
* Remove color-diagnostics flag.
  This is enabled by default on terminals with color. Prints
  hidden ASCII for terminals that can't handle color(Emacs)
* Pass functors to SSAPass to check if the
  operand can be forward referenced based on its index value
* Return SPV_ERROR_INVALID_ID for ID related errors
  spvBinaryParse returned SPV_ERROR_INVALID_BINARY for all types of
  errors. Since spvBinaryParse does some ID validation, this was
  returning inappropriate error codes for some tests.
* Common fixture for validation tests.
  It only runs certian validation passes.
* Add a SPV_VALIDATE_SSA_BIT for testing purposes
* Fixtures now return error codes
* Add OpName support in diag message and unit tests
* Binary parsing can fail with invalid ID or invalid binary error code

Tests include:
* OpDecorate
* OpName
* OpMemberName
* OpBranchConditional
* OpSelectionMerge
* OpMemberDecorate
* OpGroupDecorate
* OpDeviceEnqueue
* Enable several tests failing in ID validation.
2015-12-09 16:15:00 -05:00
David Neto
292acb5b41 Don't add -frtti for tests. Use newer googletest.
Using -frtti caused link failures when both of the following are
in effect:
	-DDISABLE_EXCEPTIONS=ON
	-DDISABLE_RTTI=ON

The correct fix is to use tip-of-tree googletest.
Specifically, we need a version of googletest with the fix in
https://github.com/google/googletest/pull/612
In particular, it must be later than googletest 1.7.0.
2015-12-01 12:19:09 -05:00
David Neto
bdc50b5d62 Add -frtti for tests that use mocking
The tests now use mocked methods.  This requires runtime type
information for those test classes.
https://github.com/google/googletest/issues/610

This has been fixed recently upstream in googletest.  Until we pick
up that fix, add -frtti for the the test executable only.
2015-12-01 10:01:33 -05:00
Andrew Woloszyn
3a4bc7e61a Turned warnings-as-errors on by default.
Fixed a few warnings that appear in builds on VS2013 and VS2015.
2015-11-19 09:46:59 -05:00
Lei Zhang
8bd75d650e Clean up CMake configuration and address compiler warnings.
- Removed dead configuration in CMakeLists.txt.
- Used target_compile_options() instead of CMAKE_{C|CXX}_FLAGS.
- Turned on warnings on tests.
- Fixed various warnings for comparing signed with unsigned values.
- Removed dead code exposed by compiler warnings.
2015-11-18 16:32:41 -05:00
Pierre Moreau
01a3b9ce36 CMake: Respect user-defined install path 2015-11-18 10:04:04 -05:00
David Neto
748d585a9a Object files should depend on spirv.h and friends
Don't use SYSTEM attribute on include_directories directive
for the SPIR-V standard header files.  When you do, object files
are not considered dependent on those headers.

Checked by looking at the dependency file source/disassemble.cpp.o.d,
and by trying to compile after a trivial edit to spirv.h

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/7

Also, use "" inclusion instead of <> inclusion for standard SPIR-V
headers.
2015-11-17 18:04:12 -05:00
David Neto
56fb3f016b Revamp the README for public release.
Reorganize the README, and update its contents to more accurately
reflect the public release.
Remove the incremental "Changes" section.

Rename readme.md to README.md
Rename license.txt to LICENSE

Update the assembler tool to support -h, and make its help look
more consistent with the disassembler.

Change the target and library name to SPIRV-Tools.  To better
match the GitHub repo name.  Also, it's not SHOUTING.
2015-11-13 12:35:39 -06:00
Lei Zhang
972788bf23 Use opaque context object to hold SPIR-V info tables.
Previously the opcode table is declared as an global array and we
have spvOpcodeTableInitialize() modifying it. That can result in
race condition. Now spvOpcodeTabelGet() copies the whole underlying
array.
2015-11-12 16:27:51 -05:00
David Neto
9a5ac08bcf spirv-dis prints to stdout by default.
Color printing is enabled only for printing to stdout.
Add --no-color to turn off color printing.
2015-11-12 16:27:50 -05:00
Lei Zhang
8984f6f31f Move internal macros/structs for SPIR-V to a separate header. 2015-11-12 09:43:20 -05:00
Lei Zhang
aa056cd8c7 Move SPIR-V constants/limits to a separate header. 2015-11-12 09:43:09 -05:00
Lei Zhang
04736e7878 Move spv*TableGet() functions out of libspirv.h.
This is a part of the effort to clean up libspirv.h.
2015-11-12 09:42:55 -05:00
David Neto
2ae4a68fe8 Fix handling of OpExtInstImport
The assembler tracks mapping of extended instruction import Id
to extended instruction type.

Adds a few new ways to fail.
2015-11-10 15:58:07 -05:00
David Neto
201caf7001 spv_operand_type_t cleanup.
- Concrete operand types are never optional.
  Split them to make this so, e.g. add SPV_OPERAND_TYPE_IMAGE
  since there was SPV_OPERAND_TYPE_OPTIONAL_IMAGE.
  Similarly for SPV_OPERAND_TYPE_MEMORY_ACCESS.
  This entails duplicating two operand table entries.

- The above, plus some rearranging of enums, allows us to define
  first and last optional operand types, and first and last
  variable operand types.
  This lets us simplify the code for spvOperandIsOptional, and
  spvOperandIsVariable.

- Replace SPV_OPERAND_TYPE_MULTIWORD_LITERAL_NUMBER with the
  more accurately named SPV_OPERAND_TYPE_TYPED_LITERAL_NUMBER.
  Its special characteristic is that the type of the literal
  number is determined by some previous operand in the instruction.
  This is used for literals in OpSwitch, OpConstant, and OpSpecConstant.
  This lets us refactor operand parsing cases in the assembler.

- Remove the special required-thing-in-optional-tuple in favour of
  the corresponding concrete operand type:
        SPV_OPERAND_TYPE_ID_IN_OPTIONAL_TUPLE
    --> SPV_OPERAND_TYPE_ID
        SPV_OPERAND_TYPE_INTEGER_LITERAL_IN_OPTIONAL_TUPLE
    --> SPV_OPERAND_TYPE_INTEGER_LITERAL

- Constrain spvOpeandTypeStr to only have to work for non-variable
  operand types.  Add a test for this.
2015-11-10 15:57:45 -05:00
David Neto
0ca6b59bfd Refactor the binary parser.
The binary parser has a C API, described in binary.h.
Eventually we will make it public in libspirv.h.
The API is event-driven in the sense that a callback is called
when a valid header is parsed, and for each parsed instruction.

Classify some operand types as "concrete".  The binary parser uses
only concrete operand types to describe parsed instructions.

The old disassembler APIs are moved into disassemble.cpp

TODO: Add unit tests for spvBinaryParse.
2015-11-10 15:57:33 -05:00
David Neto
ea324e4a23 Move spvBinaryToText into new disassembler file.
This begins the refactoring of the disassembler into
two parts: A binary decoder in binary.cpp, and an
event-driven converter to text in disassemble.cpp
2015-11-10 15:57:19 -05:00
Andrew Woloszyn
c2887f98bc Added HexFloat helper class to print out floating point numbers.
TODO Add double tests before we actually use this.
2015-11-02 13:52:25 -05:00
David Neto
db901b622e Move endian utilities to their own file. 2015-11-02 13:52:12 -05:00
David Neto
fcc7d58353 Move AssemblyGrammar into its own source files 2015-11-02 13:52:05 -05:00
David Neto
1780fc4fcf Update to latest registered generator enums
The registry is at:
https://www.khronos.org/registry/spir-v/api/spir-v.xml
2015-11-02 13:51:54 -05:00
Andrew Woloszyn
f731cbf6c4 Added set_bits<> to bitutils.
This allows us to get a constant with the given bits set at
compile-time. This is needed for a future patch for HexFloat.
2015-11-02 13:51:51 -05:00
Dejan Mircevski
d846247fd2 Fix GMOCK directory in CMakeLists.txt. 2015-10-26 12:55:33 -04:00
David Neto
21c4ad4b22 Add OpenCL extended instructions.
Versions 1.2, 2.0, and 2.1 all use the same
extended instruction list.

Updated the source code patch for the SPIR-V doc generator,
so it can both generate the core syntax table, and also the
OpenCL extended instructions table.

Tested the Math and Common functions.
TODO: test the remaining entries.
2015-10-26 12:55:33 -04:00
Lei Zhang
6483bd7132 Enforce suitable literal number operands to be unsigned integers.
Except for OpConstant and OpSpecConstant, all other literal number
operands are indeed unsigned integers. So,

* Rename all *LITERAL_NUMBER* operand types to *LITERAL_INTEGER*.
* Expect unsigned integers for *LITERAL_INTEGER* operands.
* Keep MULITPLE_WORD_LITERAL untouched since it is only used by
  OpConstant and OpSpecConstant.

And we want to provide the capability to specify floating-point
numbers after !<integer> in the alternate parsing mode. So,
OPTIONAL_LITERAL_NUMBER is reserved for OPTIONAL_CIV.
2015-10-26 12:55:33 -04:00
David Neto
005a11a4ac Use SPIRV_PERF=1 when performance tuning.
It tells the compiler to keep frame pointers, so you have good
call stacks in your profiles.
2015-10-26 12:55:33 -04:00
Andrew Woloszyn
e59e6b72f9 Added proper string escaping to the disassembler.
The disassembler now generates correct string when encountering
quotes and slashes.
2015-10-26 12:55:33 -04:00
David Neto
ac508b0d80 DiagnosticStream can convert to a stored error code
Use this to shorten error return code in the assembler.

For example, change this:

   if (error = something()) {
      diagnostic() << " Bad integer literal " << value;
      return SPV_ERROR_INVALID_VALUE;
   }

to this:

   if (error = something())
      return diagnostic() << " Bad integer literal " << value;

Also shorten code due to the fact that binaryEncodeU32 and
binaryCodeU64 can't fail (short of failure to expand a std::vector).
2015-10-26 12:55:33 -04:00
David Neto
b5dc8fcd5d Support strings with up to 65535 chars, and null.
Move the definition of spv_instruction_t to an internal
header file, since it now depends on C++ and is not
used by the external interface.

Use a std::vector<uint32_t> in spv_instruction_t
instead of a fixed size array.
2015-10-26 12:55:33 -04:00
David Neto
ddda85a5c5 Fix capabilities for enums in Rev32, sec 3.3-3.20 2015-10-26 12:55:33 -04:00
David Neto
ff5dce48a1 Add assembler test for OpEnqueueKernel.
Adds a form of spvtest::MakeInstruction which takes two vectors
of operands.  That leads to simpler test code.
We can clean up some other test code, in another CL.
2015-10-26 12:55:33 -04:00
Andrew Woloszyn
71fc05587b Refactored dynamic and static state out of text processing.
This reduces the number of arguments required to be passed
to every single function. This is in preparation for adding
id tracking.
2015-10-26 12:55:33 -04:00