Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic SSA Validation #27

Closed
wants to merge 21 commits into from
Closed

Basic SSA Validation #27

wants to merge 21 commits into from

Conversation

umar456
Copy link
Contributor

@umar456 umar456 commented Nov 23, 2015

  • Updated validation tests to assignment form
  • Fixed function tests to handle multiple parameters
  • Basic SSA Validation

if (SPV_OPERAND_TYPE_LITERAL_STRING == type) {
spvCheckReturn(spvValidateOperandsString(
words + index, wordCount - index, position, pDiagnostic));
// NOTE: String literals are always at the end of Opcodes
break;
} else if (SPV_OPERAND_TYPE_LITERAL_INTEGER == type) {
spvCheckReturn(spvValidateOperandsLiteral(
words + index, wordCount - index, 2, position, pDiagnostic));
// spvCheckReturn(spvValidateOperandsNumber(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you plan on re-enabling this code, then use:
#if 0
#endif
Around disabled code, and add a TODO(): to re-enable at some point

Otherwise just delete the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed da35d28


INSTANTIATE_TEST_CASE_P(KernelArgs, Validate, ::testing::ValuesIn(cases));

string SetOps(string &str, pair<string, bool> param) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const string &str

@dneto0
Copy link
Collaborator

dneto0 commented Dec 3, 2015

Ok, finished review of latest commit.

  • Must fix the index == 8 bug in checking for allowable forward use of Id with OpFunction
  • Should fix tests so they only fail for the reason being tested. A lots of the test cases are invalid for multiple reasons, even though the validator will only check on of those reasons right now. For example a lot of the tests are missing OpMemoryModel, or have OpConstant or OpTypeInt that occur after the first OpFunction instruction.
  • Nice to fix: Simplify tests to remove extraneous stuff. E.g. a lot of Id checks can be done without any function bodies at all. I've suggested one in detail.
  • Quibble: Some naming things. Like instead of "...MissingLabel..." say "...MissingTarget..." since "Label" is already a first class concept in SPIR-V.

(and maybe other stuff I've forgotten by now.)

@dneto0
Copy link
Collaborator

dneto0 commented Dec 3, 2015

Oh, and I forgot to thank you for making thorough checks for invalidity of each ID operand that can't be forward declared!


if (!param.second) {
regex ndrange_regex("[^\n]%ndval");
out2 = regex_replace(out, ndrange_regex, "");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't compile with GCC g++ 4.8.4

Validate.SSA.cpp:592:48: error: no matching function for call to ‘regex_replace(std::string&, std::regex&, const char [1])’
and later details say template argument deduction/substitution failed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What compilers are we targeting?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VisualStudio 2013. (e.g. no constexpr)
GCC 4.8.2 ; that's what comes with Ubunto 14.04 Trusty LTS.
A recent Clang, but I expect that will be at least as feature rich as the GCC.

I should document this in the README. :-(

FYI. The Chromium project notes gotchas with various compiler's C++11 support:
https://chromium-cpp.appspot.com/
E.g. you can see there that constexpr isn't supported in VisualStudio 2013
But we use more features of C++11 than Chromium allows, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I add a dependency to boost.regex or boost.xpressive?

* Update fixture to only run certian validation
  passes
* Fixtures now return error codes
* Fix fwd index for SpvOpEnqueueKernel
* Add a SPV_VALIDATE_SSA_BIT for testing purposes
* Enable several tests failing in ID validation
* Fix OpEnqueueKernel usage (missing flag arg)
* Formatting SPIR-V
* Simplify test cases
@umar456
Copy link
Contributor Author

umar456 commented Dec 6, 2015

Addressed the feedback thus far.

@umar456
Copy link
Contributor Author

umar456 commented Dec 8, 2015

  • Added additional unit tests (OpPhi, OpLoopMerge)
  • Added support for OpName based diagnostics
  • Unit tests now check for id names in diagnostic message

@dneto0
Copy link
Collaborator

dneto0 commented Dec 8, 2015

Whoops, I was reviewing an older commit. Still looking...

@dneto0
Copy link
Collaborator

dneto0 commented Dec 8, 2015

Done this round.
Issues:

  • Fix the block termination in the OpPhi tests
  • Any ID operand to OpLoopMerge can be forward declared. Either add a TODO for tests for OpLoopMerge or add tests themselves.
  • Missing blurbs in a couple of places. (May as well do it in the PR.)
  • Also add #include to fix compilation on GCC.

Recommend not adding new tests to this PR because they can potentially require further rounds of review.

@umar456
Copy link
Contributor Author

umar456 commented Dec 9, 2015

Addressed feedback so far.

)";
CompileSuccessfully(str);
ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
ASSERT_TRUE(ContainsString(getDiagnosticString(), "missing"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OPTIONAL: Sorry I didn't think of this before. But we tend to use gmock matchers, so this would be:

ASSERT_THAT(getDiagnosticString(), HasSubstr("missing"));

(assuming early in the file you have:

#include "gmock/gmock.h"
using ::testing::HasSubstr

)

See https://github.com/google/googletest/blob/master/googlemock/docs/CheatSheet.md

It can be very powerful since there are so many predicates to apply. In particular, it's great at matching containers, with very good messages when things fail.

Good for future tests you write.

@dneto0
Copy link
Collaborator

dneto0 commented Dec 9, 2015

I'm satisfied with this for now. I plan to rebase and squash before pushing onto master.

Also, I may have a few more OpPhi cases in mind. But they'll be fore later CLs.

@dneto0
Copy link
Collaborator

dneto0 commented Dec 9, 2015

+2

@dneto0
Copy link
Collaborator

dneto0 commented Dec 9, 2015

Rebased, and made the following changes:

  • Avoid std::to_string because that's not available on Android. Reworked some local code to use std::strinstream instead.
  • Did "using std::placeholders::_1" instead of blanket "using namespace std::placeholders" as per Google C++ style guide
  • Wrapped the local functions in anonymous namespace. Avoids polluting the global namespace.
  • For diagnostics generation, changed a C-style cast to uint64_t to static cast to size_t, to fix compilation on Android.
  • Clang-format

@dneto0
Copy link
Collaborator

dneto0 commented Dec 9, 2015

Squashed and pushed onto master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants