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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
64c5e30
committing recent changes.
sualehasif Mar 3, 2021
a2025a6
move some boilerplate over from parse
arvid220u Mar 3, 2021
9fc0a32
cilkforrange working but only cxxforrange
arvid220u Mar 3, 2021
56606b5
implement cilkforrangestmt
sualehasif Mar 3, 2021
3244de7
implement tree transform i think
arvid220u Mar 3, 2021
299df3c
potentially fix treetransform
arvid220u Mar 3, 2021
347e367
add reqd beginloc and endloc
arvid220u Mar 3, 2021
0980963
move getbeginloc and getendloc implementations to .cpp file
arvid220u Mar 3, 2021
3e68033
move more things into .cpp instead of .h
arvid220u Mar 3, 2021
6bf77ca
handle cilkforrange in astreaderstmt
arvid220u Mar 3, 2021
9938405
fix bugs hopefully
arvid220u Mar 3, 2021
499de40
do some casting things
arvid220u Mar 3, 2021
373a389
casting in a better way
arvid220u Mar 3, 2021
93bb184
more for range where it should be
arvid220u Mar 3, 2021
58e3750
do correct casting
arvid220u Mar 3, 2021
7811502
add warning that forrange support is experimental
arvid220u Mar 3, 2021
0ea1aee
add more cases to switch statements
arvid220u Mar 3, 2021
a550c6d
actually wrap the cxxforrangestmt
arvid220u Mar 3, 2021
db7f02b
implement first version of emitcilkforrange
arvid220u Mar 9, 2021
4d8670f
updated everything to use difference type instead.
sualehasif Mar 14, 2021
7df2dc8
fix things
arvid220u Mar 16, 2021
5479509
stupid
arvid220u Mar 16, 2021
9500c4e
stupid again
arvid220u Mar 16, 2021
52aa9a9
should work
arvid220u Mar 16, 2021
fb7b08c
should work 2
arvid220u Mar 16, 2021
b95bd6e
dereference
arvid220u Mar 17, 2021
12f98d2
fix things
arvid220u Mar 17, 2021
073cdb3
test
arvid220u Mar 17, 2021
ee4419c
test
arvid220u Mar 17, 2021
9d3b9dd
test
arvid220u Mar 17, 2021
d8ce9ea
test
arvid220u Mar 17, 2021
5b04bbd
test
arvid220u Mar 17, 2021
e4100bd
remove dumps
arvid220u Mar 17, 2021
c676f92
potentially fix o1
arvid220u Mar 23, 2021
b08119d
fix non random access bug hopefully
arvid220u Mar 23, 2021
75889f6
reformatted StmtCilk.h'
sualehasif Mar 25, 2021
9c73d96
reformatted and refactored StmtCXX
sualehasif Mar 25, 2021
623e81b
cleaned up codegen for cilkforrange
sualehasif Mar 25, 2021
8fc1d9c
reformatted partsing
sualehasif Mar 25, 2021
04f717c
cargo-cult some more
arvid220u Apr 7, 2021
acb7069
remove comments
arvid220u Apr 7, 2021
d2c17a6
more consistency
arvid220u Apr 7, 2021
1c21024
dont make any lasting changes to gitignore
arvid220u Apr 7, 2021
b565060
remove submodules
arvid220u Apr 7, 2021
455009f
whitespaces
arvid220u Apr 7, 2021
c65e3ce
whitespace
arvid220u Apr 7, 2021
5c6764c
more formatting
arvid220u Apr 7, 2021
fd33a63
treetransform
arvid220u Apr 7, 2021
01e1f17
fix whitespace again
arvid220u Apr 7, 2021
b79b205
fix whitespace again
arvid220u Apr 7, 2021
077501a
whitespaceeee
arvid220u Apr 7, 2021
5832b55
simplify loopvar emission
arvid220u Apr 14, 2021
1cc9664
always create a scope
arvid220u Apr 14, 2021
947800d
im just trying anything right now
arvid220u Apr 14, 2021
950b6e6
try 33
arvid220u Apr 14, 2021
9d47aa4
comments
arvid220u Apr 14, 2021
1d0c2fc
add local loop index to sema; behavior should be unchanged
arvid220u Apr 21, 2021
5c7fcb6
fix compile errors
arvid220u Apr 21, 2021
f6defc9
do the actual thing
arvid220u Apr 21, 2021
b63a19f
cleanup
arvid220u Apr 21, 2021
01b6eb9
add comments
arvid220u Apr 21, 2021
82a9928
Merge pull request #9 from arvid220u/arvid/fix-aggregate-types-try-2
arvid220u Apr 21, 2021
df3edbe
Regression tests (#10)
arvid220u Jun 2, 2021
274e6b2
undo clang format errors
arvid220u Jun 2, 2021
87ce260
more cleanup from clang format
arvid220u Jun 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion clang/include/clang-c/Index.h
Original file line number Diff line number Diff line change
Expand Up @@ -2590,7 +2590,11 @@ enum CXCursorKind {
*/
CXCursor_CilkForStmt = 289,

CXCursor_LastStmt = CXCursor_CilkForStmt,
/** A _Cilk_for range statement.
*/
CXCursor_CilkForRangeStmt = 290,

CXCursor_LastStmt = CXCursor_CilkForRangeStmt,

/**
* Cursor that represents the translation unit itself.
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/AST/RecursiveASTVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -2669,6 +2669,7 @@ DEF_TRAVERSE_STMT(CilkSpawnStmt, {})
DEF_TRAVERSE_STMT(CilkSpawnExpr, {})
DEF_TRAVERSE_STMT(CilkSyncStmt, {})
DEF_TRAVERSE_STMT(CilkForStmt, {})
DEF_TRAVERSE_STMT(CilkForRangeStmt, {})

// These operators (all of them) do not need any action except
// iterating over the children.
Expand Down
76 changes: 76 additions & 0 deletions clang/include/clang/AST/StmtCilk.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define LLVM_CLANG_AST_STMTCILK_H

#include "clang/AST/Stmt.h"
#include "clang/AST/StmtCXX.h"
#include "clang/Basic/SourceLocation.h"

namespace clang {
Expand Down Expand Up @@ -84,6 +85,81 @@ class CilkSyncStmt : public Stmt {
}
};

/// CilkForRangeStmt - This represents a '_Cilk_for(range-declarator :
/// range-expression)' or a '_Cilk_for (init-statement range-declarator :
/// range-expression)', based on a CXXForRangeStmt which is a C++0x
/// [stmt.ranged]'s ranged for stmt
///
/// This is stored as a FORRANGE stmt embedded inside a CILKFORRANGE with some
/// other necessary semantic components.
class CilkForRangeStmt : public Stmt {
enum {
FORRANGE,
LOOPINDEX,
LOOPINDEXSTMT,
LOCALLOOPINDEX,
LIMIT,
COND,
INC,
END
};
Stmt *SubExprs[END];

public:
CilkForRangeStmt(const ASTContext &C, CXXForRangeStmt *ForRange,
VarDecl *LoopIndex, DeclStmt *LocalLoopIndex,
DeclStmt *Limit, Expr *Cond, Expr *Inc,
DeclStmt *LoopIndexStmt);

/// \brief Build an empty cilk for range statement.
explicit CilkForRangeStmt(EmptyShell Empty)
: Stmt(CilkForRangeStmtClass, Empty) {}

static bool classof(const Stmt *T) {
return T->getStmtClass() == CilkForRangeStmtClass;
}

CXXForRangeStmt *getCXXForRangeStmt() const;

void setForRange(Stmt *S) { SubExprs[FORRANGE] = S; }

VarDecl *getLoopIndex() const;
void setLoopIndex(const ASTContext &C, VarDecl *V);

VarDecl *getLocalLoopIndex();
const VarDecl *getLocalLoopIndex() const;

Expr *getCond() { return reinterpret_cast<Expr *>(SubExprs[COND]); }
Expr *getInc() { return reinterpret_cast<Expr *>(SubExprs[INC]); }
DeclStmt *getLoopIndexStmt() {
return cast_or_null<DeclStmt>(SubExprs[LOOPINDEXSTMT]);
}
DeclStmt *getLimitStmt() { return cast_or_null<DeclStmt>(SubExprs[LIMIT]); }
DeclStmt *getLocalLoopIndexStmt() {
return cast<DeclStmt>(SubExprs[LOCALLOOPINDEX]);
}

const Expr *getCond() const {
return reinterpret_cast<Expr *>(SubExprs[COND]);
}
const Expr *getInc() const { return reinterpret_cast<Expr *>(SubExprs[INC]); }
const DeclStmt *getLoopIndexStmt() const {
return cast_or_null<DeclStmt>(SubExprs[LOOPINDEXSTMT]);
}
const DeclStmt *getLimitStmt() const {
return cast_or_null<DeclStmt>(SubExprs[LIMIT]);
}
const DeclStmt *getLocalLoopIndexStmt() const {
return cast<DeclStmt>(SubExprs[LOCALLOOPINDEX]);
}

SourceLocation getBeginLoc() const LLVM_READONLY;
SourceLocation getEndLoc() const LLVM_READONLY;

// Iterators
child_range children() { return child_range(&SubExprs[0], &SubExprs[END]); }
};

/// CilkForStmt - This represents a '_Cilk_for(init;cond;inc)' stmt.
class CilkForStmt : public Stmt {
SourceLocation CilkForLoc;
Expand Down
5 changes: 3 additions & 2 deletions clang/include/clang/Basic/DiagnosticParseKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -1221,8 +1221,6 @@ def err_cilk_for_missing_increment: Error<
"missing loop increment expression in '_Cilk_for'">;
def err_cilk_for_missing_semi: Error<
"expected ';' in '_Cilk_for'">;
def err_cilk_for_forrange_loop_not_supported: Error<
"'_Cilk_for' not supported on for-range loops">;
def err_cilk_for_foreach_loop_not_supported: Error<
"'_Cilk_for' not supported on for-each loops">;
def err_pragma_cilk_invalid_option : Error<
Expand All @@ -1235,6 +1233,9 @@ def warn_cilk_for_following_grainsize: Warning<
def warn_pragma_cilk_grainsize_equals: Warning<
"'#pragma cilk grainsize' no longer requires '='">,
InGroup<SourceUsesCilkPlus>;
def warn_cilk_for_forrange_loop_experimental: Warning<
"'_Cilk_for' support for for-range loops is currently EXPERIMENTAL only!">,
InGroup<SourceUsesCilkPlus>;

// OpenMP support.
def warn_pragma_omp_ignored : Warning<
Expand Down
8 changes: 7 additions & 1 deletion clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -9519,7 +9519,13 @@ def note_exits_cilk_for : Note<
"jump exits the scope of a '_Cilk_for'">;
def err_jump_out_of_cilk_for : Error<
"cannot jump out of '_Cilk_for' statement">;
} // end of Cilk category

// Cilk For Range errors

def err_cilk_for_range_end_minus_begin : Error<
"Cannot determine length with '__end - __begin'. Please use a random access iterator.">;
}
// end of Cilk category

let CategoryName = "OpenMP Issue" in {
// OpenMP support.
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/Basic/StmtNodes.td
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ def CilkSyncStmt : StmtNode<Stmt>;
def CilkSpawnStmt : StmtNode<Stmt>;
def CilkSpawnExpr : StmtNode<Expr>;
def CilkForStmt : StmtNode<Stmt>;
def CilkForRangeStmt: StmtNode<Stmt>;

// OpenMP Directives.
def OMPExecutableDirective : StmtNode<Stmt, 1>;
Expand Down
7 changes: 7 additions & 0 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -12093,6 +12093,13 @@ class Sema final {
ConstructorDestructor,
BuiltinFunction
};
StmtResult ActOnCilkForRangeStmt(Scope *S, SourceLocation ForLoc,
Stmt *InitStmt, Stmt *First,
SourceLocation ColonLoc, Expr *Range,
SourceLocation RParenLoc,
BuildForRangeKind Kind);
StmtResult BuildCilkForRangeStmt(CXXForRangeStmt *S);
StmtResult FinishCilkForRangeStmt(Stmt *S, Stmt *B);
};

/// RAII object that enters a new expression evaluation context.
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/Serialization/ASTBitCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1877,6 +1877,7 @@ namespace serialization {
EXPR_CILKSPAWN,
STMT_CILKSYNC,
STMT_CILKFOR,
STMT_CILKFORRANGE,
};

/// The kinds of designators that can occur in a
Expand Down
63 changes: 62 additions & 1 deletion clang/lib/AST/StmtCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
//===----------------------------------------------------------------------===//

#include "clang/AST/StmtCXX.h"

#include "clang/AST/Stmt.h"
#include "clang/AST/StmtCilk.h"
#include "clang/AST/ASTContext.h"

using namespace clang;
Expand Down Expand Up @@ -125,3 +126,63 @@ CoroutineBodyStmt::CoroutineBodyStmt(CoroutineBodyStmt::CtorArgs const &Args)
std::copy(Args.ParamMoves.begin(), Args.ParamMoves.end(),
const_cast<Stmt **>(getParamMoves().data()));
}

/// Constructor for the CilkForRangeStmt
CilkForRangeStmt::CilkForRangeStmt(const ASTContext &C,
CXXForRangeStmt *ForRange,
VarDecl *LoopIndex, DeclStmt *LocalLoopIndex,
DeclStmt *Limit, Expr *Cond, Expr *Inc,
DeclStmt *LoopIndexStmt)
: Stmt(CilkForRangeStmtClass) {
SubExprs[FORRANGE] = ForRange;
setLoopIndex(C, LoopIndex);
SubExprs[LOCALLOOPINDEX] = LocalLoopIndex;
SubExprs[COND] = Cond;
SubExprs[INC] = Inc;
SubExprs[LOOPINDEXSTMT] = LoopIndexStmt;
SubExprs[LIMIT] = Limit;
}

/// Gets the LOOPINDEX as a VarDecl.
/// LOOPINDEX is stored as a DeclStmt for the purpose of clean manipulation.
VarDecl *CilkForRangeStmt::getLoopIndex() const {
if (!SubExprs[LOOPINDEX])
return nullptr;

DeclStmt *DS = cast<DeclStmt>(SubExprs[LOOPINDEX]);
return cast<VarDecl>(DS->getSingleDecl());
}

void CilkForRangeStmt::setLoopIndex(const ASTContext &C, VarDecl *V) {
if (!V) {
SubExprs[LOOPINDEX] = nullptr;
return;
}

SourceRange VarRange = V->getSourceRange();
SubExprs[LOOPINDEX] =
new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(), VarRange.getEnd());
}

VarDecl *CilkForRangeStmt::getLocalLoopIndex() {
Decl *LV = cast<DeclStmt>(getLocalLoopIndexStmt())->getSingleDecl();
assert(LV && "No local loop index in CilkForRangeStmt");
return cast<VarDecl>(LV);
}

const VarDecl *CilkForRangeStmt::getLocalLoopIndex() const {
return const_cast<CilkForRangeStmt *>(this)->getLocalLoopIndex();
}

/// returns the FORRANGE stmt embedded in the CilkForRange. (May be null.)
CXXForRangeStmt *CilkForRangeStmt::getCXXForRangeStmt() const {
return cast_or_null<CXXForRangeStmt>(SubExprs[FORRANGE]);
}

SourceLocation CilkForRangeStmt::getBeginLoc() const {
return getCXXForRangeStmt()->getBeginLoc();
}

SourceLocation CilkForRangeStmt::getEndLoc() const {
return getCXXForRangeStmt()->getEndLoc();
}
18 changes: 18 additions & 0 deletions clang/lib/AST/StmtPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2562,6 +2562,24 @@ void StmtPrinter::VisitCilkForStmt(CilkForStmt *Node) {
Indent() << "}";
}

void StmtPrinter::VisitCilkForRangeStmt(CilkForRangeStmt *Node) {
Indent() << "_Cilk_for (";

if (Node->getCXXForRangeStmt()->getInit())
PrintInitStmt(Node->getCXXForRangeStmt()->getInit(), 5);

PrintingPolicy SubPolicy(Policy);
SubPolicy.SuppressInitializers = true;
Node->getCXXForRangeStmt()->getLoopVariable()->print(OS, SubPolicy,
IndentLevel);

OS << " : ";
PrintExpr(Node->getCXXForRangeStmt()->getRangeInit());
OS << ")";

PrintControlledStmt(Node->getCXXForRangeStmt()->getBody());
}

//===----------------------------------------------------------------------===//
// Stmt method implementations
//===----------------------------------------------------------------------===//
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/AST/StmtProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1982,6 +1982,10 @@ void StmtProfiler::VisitCilkForStmt(const CilkForStmt *S) {
VisitStmt(S);
}

void StmtProfiler::VisitCilkForRangeStmt(const CilkForRangeStmt *S) {
VisitStmt(S);
}

void StmtProfiler::VisitCilkSpawnStmt(const CilkSpawnStmt *S) {
VisitStmt(S);
}
Expand Down
Loading