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

Range-based cilk_for #55

Open
wants to merge 65 commits into
base: release/10.x
Choose a base branch
from

Conversation

arvid220u
Copy link

@arvid220u arvid220u commented Jun 2, 2021

Overview

Implements a range-based cilk_for syntax supporting containers with random access iterators.

For example, this PR adds support for syntax on the form:

vector<int> v;
cilk_for (auto x : v) {
    f(x);
}

Previously, you had to do:

vector<int> v;
cilk_for (int i = 0; i < v.size(); i++) {
    f(v[i]);
}

Implementation

We introduce a new AST type, CilkForRangeStmt, taking inspiration from both CilkForStmt and CXXForRangeStmt.

The CilkForRangeStmt internally stores a CXXForRangeStmt, and lets the CXXForRangeStmt handle the parsing of the for loop. It then outputs IR similar to a CilkForStmt. The loop control differs from what one might expect: instead of having the loop variable be an iterator going from container.begin() to container.end() as in a normal for range loop, we emit a loop index of type difference_type going from 0 to container.end() - container.begin(). This makes it possible for the Tapir loop pass to transform the loop into a divide and conquer.

Testing

  1. Diagnostics tested in clang/test/Cilk/rangelooptest.cpp.
  2. Correct IR output tested in clang/test/Cilk/cilkforrange-ir.cpp.
  3. Tested on the example files from arvid220u/llvmurop/examples, involving simple examples including random access iterators and non-random access iterators.
  4. Each example above has been compiled using -fsanitize=cilk (Cilksan), reporting 0 determinancy races.
  5. Benchmarked on the microbenchmarks from arvid220u/llvmurop/microbenchmarks, being 10% slower on O0, and having no observable difference on any higher optimization levels.

sualehasif and others added 30 commits April 6, 2021 21:54
* add range loop test

* add

* frewrite-includes

* fix range loop test

* addworkingalmostrangelooptest

* address some warnings

* add more expected warnings and notes

* ignore notes

* cilkforrange ir

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* add more isinvalid checks

* add more errors

* add more errors

* add more errors

* add more errors

* add more errors

* add more errors

* idk

* idk

* idk

* idk

* idk

* vector mock

* better vector mock

* dont actually malloc

* fix?

* fix?

* fix?

* fix?

* fix?

* rangelooptest all mocked out

* pragma allowed for forrange too

* pragma cilk allowed too

* fix ir

* ir fix

* ir fix

* fix ir

* fix ir

* bug

* bug

* regexify

* regexify

* more tests

* fix name mangling

* fix test

* auto test

* name mangling

* final test

* name mangling

* clang format

Co-authored-by:  <[email protected]>
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.

2 participants