clang: include/clang/Sema/SemaOpenACC.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef LLVM_CLANG_SEMA_SEMAOPENACC_H

15#define LLVM_CLANG_SEMA_SEMAOPENACC_H

16

24#include "llvm/ADT/SmallVector.h"

25#include "llvm/Support/Compiler.h"

26#include

27#include

28#include

29#include

30

32class IdentifierInfo;

33class OpenACCClause;

34

36private:

37 struct ComputeConstructInfo {

38

39

40

42

43

45 } ActiveComputeConstructInfo;

46

47 bool isInComputeConstruct() const {

49 }

50

51

52

53

54

55 struct LoopCheckingInfo {

56

57

58

59 LLVM_PREFERRED_TYPE(bool)

60 unsigned TopLevelLoopSeen : 1;

61

62

63

64 LLVM_PREFERRED_TYPE(bool)

65 unsigned CurLevelHasLoopAlready : 1;

66

67 } LoopInfo{false, false};

68

69

70

71

72

73

74

75

76 struct CollapseCheckingInfo {

78

79

80

81

82

83

84 std::optionalllvm::APSInt CurCollapseCount;

85

86

87

88

89 bool CollapseDepthSatisfied = true;

90

91

92

94 } CollapseInfo;

95

96

97

98 struct TileCheckingInfo {

100

101

102

103

104 std::optional CurTileCount;

105

106

107

108

109 bool TileDepthSatisfied = true;

110

111

112

114 } TileInfo;

115

116

117

118

119

120

121

123

124

125 struct ForStmtBeginChecker {

128 bool IsRangeFor = false;

129 std::optional<const CXXForRangeStmt *> RangeFor = nullptr;

130 const Stmt *Init = nullptr;

131 bool InitChanged = false;

132 std::optional<const Stmt *> Cond = nullptr;

133 std::optional<const Stmt *> Inc = nullptr;

134

135 bool AlreadyChecked = false;

136

138 std::optional<const CXXForRangeStmt *> S)

139 : SemaRef(SemaRef), ForLoc(ForLoc), IsRangeFor(true), RangeFor(S) {}

140

142 const Stmt *I, bool InitChanged,

143 std::optional<const Stmt *> C,

144 std::optional<const Stmt *> Inc)

145 : SemaRef(SemaRef), ForLoc(ForLoc), IsRangeFor(false), Init(I),

146 InitChanged(InitChanged), Cond(C), Inc(Inc) {}

147

148

149

150

151 void check();

152

154 void checkCond();

155 void checkInc(const ValueDecl *Init);

156 };

157

158

159 void ForStmtBeginHelper(SourceLocation ForLoc, ForStmtBeginChecker &C);

160

161public:

163 return ActiveComputeConstructInfo;

164 }

165

166

167

168

169

174

175

176

177

178

180

181

182

183

185

186

187

188

189

194

195

197

198

199

200

201

207

208 struct DefaultDetails {

210 };

211

212 struct ConditionDetails {

213 Expr *ConditionExpr;

214 };

215

216 struct IntExprDetails {

218 };

219

220 struct VarListDetails {

222 bool IsReadOnly;

223 bool IsZero;

224 };

225

226 struct WaitDetails {

227 Expr *DevNumExpr;

230 };

231

232 struct DeviceTypeDetails {

234 };

235 struct ReductionDetails {

238 };

239

240 struct CollapseDetails {

241 bool IsForce;

242 Expr *LoopCount;

243 };

244

245 struct GangDetails {

248 };

249

250 std::variant<std::monostate, DefaultDetails, ConditionDetails,

251 IntExprDetails, VarListDetails, WaitDetails, DeviceTypeDetails,

252 ReductionDetails, CollapseDetails, GangDetails>

253 Details = std::monostate{};

254

255 public:

258 : DirKind(DirKind), ClauseKind(ClauseKind), ClauseRange(BeginLoc, {}) {}

259

261

263

265

267

269

272 "Parsed clause is not a default clause");

273 return std::get(Details).DefaultClauseKind;

274 }

275

278 }

279

284 "Parsed clause kind does not have a condition expr");

285

286

287

289 std::holds_alternativestd::monostate(Details))

290 return nullptr;

291

292 return std::get(Details).ConditionExpr;

293 }

294

305 "Parsed clause kind does not have a int exprs");

306

307

308

313 std::holds_alternativestd::monostate(Details))

314 return 0;

315 return std::get(Details).IntExprs.size();

316 }

317

320 "Parsed clause kind does not have a queues location");

321

322 if (std::holds_alternativestd::monostate(Details))

324

325 return std::get(Details).QueuesLoc;

326 }

327

330 "Parsed clause kind does not have a device number expr");

331

332 if (std::holds_alternativestd::monostate(Details))

333 return nullptr;

334

335 return std::get(Details).DevNumExpr;

336 }

337

340 "Parsed clause kind does not have a queue id expr list");

341

342 if (std::holds_alternativestd::monostate(Details))

344

345 return std::get(Details).QueueIdExprs;

346 }

347

359 "Parsed clause kind does not have a int exprs");

360

362

363

364 if (std::holds_alternativestd::monostate(Details))

365 return {};

366 return std::get(Details).IntExprs;

367 }

368

369 return std::get(Details).IntExprs;

370 }

371

374 }

375

377 return std::get(Details).Op;

378 }

379

382 "Parsed clause kind does not have gang kind");

383

384

385 if (std::holds_alternativestd::monostate(Details))

386 return {};

387 return std::get(Details).GangKinds;

388 }

389

417 "Parsed clause kind does not have a var-list");

418

420 return std::get(Details).VarList;

421

422 return std::get(Details).VarList;

423 }

424

427 }

428

433 "Only copyin accepts 'readonly:' tag");

434 return std::get(Details).IsReadOnly;

435 }

436

444 "Only copyout/create accepts 'zero' tag");

445 return std::get(Details).IsZero;

446 }

447

450 "Only 'collapse' has a force tag");

451 return std::get(Details).IsForce;

452 }

453

456 "Only 'collapse' has a loop count");

457 return std::get(Details).LoopCount;

458 }

459

463 "Only 'device_type'/'dtype' has a device-type-arg list");

464 return std::get(Details).Archs;

465 }

466

469

472 "Parsed clause is not a default clause");

473 Details = DefaultDetails{DefKind};

474 }

475

480 "Parsed clause kind does not have a condition expr");

481

482

485 "Condition expression type not scalar/dependent");

486

487 Details = ConditionDetails{ConditionExpr};

488 }

489

500 "Parsed clause kind does not have a int exprs");

501 Details = IntExprDetails{{IntExprs.begin(), IntExprs.end()}};

502 }

513 "Parsed clause kind does not have a int exprs");

514 Details = IntExprDetails{std::move(IntExprs)};

515 }

516

520 "Parsed Clause kind does not have gang details");

521 assert(GKs.size() == IntExprs.size() && "Mismatched kind/size?");

522

523 Details = GangDetails{{GKs.begin(), GKs.end()},

524 {IntExprs.begin(), IntExprs.end()}};

525 }

526

530 "Parsed Clause kind does not have gang details");

531 assert(GKs.size() == IntExprs.size() && "Mismatched kind/size?");

532

533 Details = GangDetails{std::move(GKs), std::move(IntExprs)};

534 }

535

537 bool IsZero) {

563 "Parsed clause kind does not have a var-list");

567 "readonly: tag only valid on copyin");

574 "zero: tag only valid on copyout/create");

575 Details =

576 VarListDetails{{VarList.begin(), VarList.end()}, IsReadOnly, IsZero};

577 }

578

580 bool IsZero) {

606 "Parsed clause kind does not have a var-list");

610 "readonly: tag only valid on copyin");

617 "zero: tag only valid on copyout/create");

618 Details = VarListDetails{std::move(VarList), IsReadOnly, IsZero};

619 }

620

624 "reduction details only valid on reduction");

625 Details = ReductionDetails{Op, std::move(VarList)};

626 }

627

631 "Parsed clause kind does not have a wait-details");

632 Details = WaitDetails{DevNum, QueuesLoc, std::move(IntExprs)};

633 }

634

638 "Only 'device_type'/'dtype' has a device-type-arg list");

639 Details = DeviceTypeDetails{std::move(Archs)};

640 }

641

644 "Only 'collapse' has collapse details");

645 Details = CollapseDetails{IsForce, LoopCount};

646 }

647 };

648

650

651

653

655

656

658 const Stmt *RangeFor);

660

661

663 const Stmt *Second, const Stmt *Third);

666 const Stmt *Second, const Stmt *OldThird,

667 const Stmt *Third);

668

669

670

672

673

675 OpenACCParsedClause &Clause);

676

677

678

679

681

682

683

684

685

688

689

690

691

692

694

695

700

701

702

703

704

705

706

707

708

709

715

716

717

719

720

721

724

725

726

728

729

730

733 Expr *VarExpr);

734

735

736

738

739

741 Expr *LowerBound,

744

746

748

749

753

754

755

762

763

770

773

774

775

778 LoopCheckingInfo OldLoopInfo;

779 CollapseCheckingInfo OldCollapseInfo;

780 TileCheckingInfo OldTileInfo;

781 bool PreserveDepth;

782

783 public:

785 : SemaRef(SemaRef), OldLoopInfo(SemaRef.LoopInfo),

786 OldCollapseInfo(SemaRef.CollapseInfo), OldTileInfo(SemaRef.TileInfo),

787 PreserveDepth(PreserveDepth) {}

789

790

791

792 bool CollapseDepthSatisified =

793 PreserveDepth ? SemaRef.CollapseInfo.CollapseDepthSatisfied

794 : OldCollapseInfo.CollapseDepthSatisfied;

795 bool TileDepthSatisfied = PreserveDepth

796 ? SemaRef.TileInfo.TileDepthSatisfied

797 : OldTileInfo.TileDepthSatisfied;

798 bool CurLevelHasLoopAlready =

799 PreserveDepth ? SemaRef.LoopInfo.CurLevelHasLoopAlready

800 : OldLoopInfo.CurLevelHasLoopAlready;

801

802 SemaRef.LoopInfo = OldLoopInfo;

803 SemaRef.CollapseInfo = OldCollapseInfo;

804 SemaRef.TileInfo = OldTileInfo;

805

806 SemaRef.CollapseInfo.CollapseDepthSatisfied = CollapseDepthSatisified;

807 SemaRef.TileInfo.TileDepthSatisfied = TileDepthSatisfied;

808 SemaRef.LoopInfo.CurLevelHasLoopAlready = CurLevelHasLoopAlready;

809 }

810 };

811

812

813

814

817 ComputeConstructInfo OldActiveComputeConstructInfo;

825

826 public:

837 };

838};

839

840}

841

842#endif

Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.

Defines some OpenACC-specific enums and functions.

Defines the clang::SourceLocation class and associated facilities.

This file defines OpenACC AST classes for statement-level contructs.

This represents one expression.

bool isInstantiationDependent() const

Whether this expression is instantiation-dependent, meaning that it depends in some way on.

This is the base type for all OpenACC Clauses.

Represents a 'collapse' clause on a 'loop' construct.

Helper type for the registration/assignment of constructs that need to 'know' about their parent cons...

void SetTileInfoBeforeAssociatedStmt(ArrayRef< const OpenACCClause * > UnInstClauses, ArrayRef< OpenACCClause * > Clauses)

void SetCollapseInfoBeforeAssociatedStmt(ArrayRef< const OpenACCClause * > UnInstClauses, ArrayRef< OpenACCClause * > Clauses)

Helper type to restore the state of various 'loop' constructs when we run into a loop (for,...

LoopInConstructRAII(SemaOpenACC &SemaRef, bool PreserveDepth=true)

A type to represent all the data for an OpenACC Clause that has been parsed, but not yet created/sema...

ArrayRef< Expr * > getIntExprs()

ArrayRef< Expr * > getQueueIdExprs() const

OpenACCDirectiveKind getDirectiveKind() const

ArrayRef< OpenACCGangKind > getGangKinds() const

OpenACCParsedClause(OpenACCDirectiveKind DirKind, OpenACCClauseKind ClauseKind, SourceLocation BeginLoc)

OpenACCReductionOperator getReductionOp() const

SourceLocation getEndLoc() const

void setLParenLoc(SourceLocation EndLoc)

void setConditionDetails(Expr *ConditionExpr)

void setCollapseDetails(bool IsForce, Expr *LoopCount)

OpenACCClauseKind getClauseKind() const

void setGangDetails(ArrayRef< OpenACCGangKind > GKs, ArrayRef< Expr * > IntExprs)

const Expr * getConditionExpr() const

SourceLocation getLParenLoc() const

ArrayRef< DeviceTypeArgument > getDeviceTypeArchitectures() const

void setIntExprDetails(llvm::SmallVector< Expr * > &&IntExprs)

void setReductionDetails(OpenACCReductionOperator Op, llvm::SmallVector< Expr * > &&VarList)

Expr * getConditionExpr()

ArrayRef< Expr * > getVarList() const

SourceLocation getBeginLoc() const

void setDefaultDetails(OpenACCDefaultClauseKind DefKind)

SourceLocation getQueuesLoc() const

void setVarListDetails(llvm::SmallVector< Expr * > &&VarList, bool IsReadOnly, bool IsZero)

void setVarListDetails(ArrayRef< Expr * > VarList, bool IsReadOnly, bool IsZero)

Expr * getDevNumExpr() const

ArrayRef< Expr * > getVarList()

unsigned getNumIntExprs() const

void setWaitDetails(Expr *DevNum, SourceLocation QueuesLoc, llvm::SmallVector< Expr * > &&IntExprs)

void setEndLoc(SourceLocation EndLoc)

ArrayRef< Expr * > getIntExprs() const

Expr * getLoopCount() const

void setIntExprDetails(ArrayRef< Expr * > IntExprs)

void setDeviceTypeDetails(llvm::SmallVector< DeviceTypeArgument > &&Archs)

void setGangDetails(llvm::SmallVector< OpenACCGangKind > &&GKs, llvm::SmallVector< Expr * > &&IntExprs)

OpenACCDefaultClauseKind getDefaultClauseKind() const

ExprResult ActOnVar(OpenACCClauseKind CK, Expr *VarExpr)

Called when encountering a 'var' for OpenACC, ensures it is actually a declaration reference to a var...

ComputeConstructInfo & getActiveComputeConstructInfo()

bool ActOnStartStmtDirective(OpenACCDirectiveKind K, SourceLocation StartLoc, ArrayRef< const OpenACCClause * > Clauses)

Called after the directive, including its clauses, have been parsed and parsing has consumed the 'ann...

ExprResult BuildOpenACCAsteriskSizeExpr(SourceLocation AsteriskLoc)

ExprResult ActOnIntExpr(OpenACCDirectiveKind DK, OpenACCClauseKind CK, SourceLocation Loc, Expr *IntExpr)

Called when encountering an 'int-expr' for OpenACC, and manages conversions and diagnostics to 'int'.

void ActOnWhileStmt(SourceLocation WhileLoc)

SourceLocation LoopWorkerClauseLoc

If there is a current 'active' loop construct with a 'worker' clause on it (on any sort of construct)...

OpenACCClause * ActOnClause(ArrayRef< const OpenACCClause * > ExistingClauses, OpenACCParsedClause &Clause)

Called after parsing an OpenACC Clause so that it can be checked.

bool ActOnStartDeclDirective(OpenACCDirectiveKind K, SourceLocation StartLoc)

Called after the directive, including its clauses, have been parsed and parsing has consumed the 'ann...

bool CheckVarIsPointerType(OpenACCClauseKind ClauseKind, Expr *VarExpr)

Called to check the 'var' type is a variable of pointer type, necessary for 'deviceptr' and 'attach' ...

struct clang::SemaOpenACC::LoopGangOnKernelTy LoopGangClauseOnKernel

ExprResult CheckReductionVar(OpenACCDirectiveKind DirectiveKind, OpenACCReductionOperator ReductionOp, Expr *VarExpr)

Called while semantically analyzing the reduction clause, ensuring the var is the correct kind of ref...

ExprResult CheckCollapseLoopCount(Expr *LoopCount)

Checks the loop depth value for a collapse clause.

struct clang::SemaOpenACC::LoopWithoutSeqCheckingInfo LoopWithoutSeqInfo

StmtResult ActOnEndStmtDirective(OpenACCDirectiveKind K, SourceLocation StartLoc, SourceLocation DirLoc, SourceLocation LParenLoc, SourceLocation MiscLoc, ArrayRef< Expr * > Exprs, SourceLocation RParenLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult AssocStmt)

Called after the directive has been completely parsed, including the declaration group or associated ...

DeclGroupRef ActOnEndDeclDirective()

Called after the directive has been completely parsed, including the declaration group or associated ...

OpenACCClause * CheckReductionClause(ArrayRef< const OpenACCClause * > ExistingClauses, OpenACCDirectiveKind DirectiveKind, SourceLocation BeginLoc, SourceLocation LParenLoc, OpenACCReductionOperator ReductionOp, ArrayRef< Expr * > Vars, SourceLocation EndLoc)

std::pair< IdentifierInfo *, SourceLocation > DeviceTypeArgument

SourceLocation LoopVectorClauseLoc

If there is a current 'active' loop construct with a 'vector' clause on it (on any sort of construct)...

void ActOnConstruct(OpenACCDirectiveKind K, SourceLocation DirLoc)

Called after the construct has been parsed, but clauses haven't been parsed.

ExprResult ActOnOpenACCAsteriskSizeExpr(SourceLocation AsteriskLoc)

ExprResult CheckGangExpr(ArrayRef< const OpenACCClause * > ExistingClauses, OpenACCDirectiveKind DK, OpenACCGangKind GK, Expr *E)

void ActOnDoStmt(SourceLocation DoLoc)

void ActOnRangeForStmtBegin(SourceLocation ForLoc, const Stmt *OldRangeFor, const Stmt *RangeFor)

void ActOnForStmtEnd(SourceLocation ForLoc, StmtResult Body)

OpenACCClause * CheckGangClause(OpenACCDirectiveKind DirKind, ArrayRef< const OpenACCClause * > ExistingClauses, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< OpenACCGangKind > GangKinds, ArrayRef< Expr * > IntExprs, SourceLocation EndLoc)

StmtResult ActOnAssociatedStmt(SourceLocation DirectiveLoc, OpenACCDirectiveKind K, ArrayRef< const OpenACCClause * > Clauses, StmtResult AssocStmt)

Called when we encounter an associated statement for our construct, this should check legality of the...

void ActOnForStmtBegin(SourceLocation ForLoc, const Stmt *First, const Stmt *Second, const Stmt *Third)

ExprResult ActOnArraySectionExpr(Expr *Base, SourceLocation LBLoc, Expr *LowerBound, SourceLocation ColonLocFirst, Expr *Length, SourceLocation RBLoc)

Checks and creates an Array Section used in an OpenACC construct/clause.

ExprResult CheckTileSizeExpr(Expr *SizeExpr)

Checks a single size expr for a tile clause.

Sema - This implements semantic analysis and AST building for C.

Encodes a location in the source.

A trivial tuple used to represent a source range.

SourceLocation getEnd() const

SourceLocation getBegin() const

void setEnd(SourceLocation e)

Stmt - This represents one statement.

bool isScalarType() const

Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...

The JSON file list parser is used to communicate input to InstallAPI.

OpenACCClauseKind

Represents the kind of an OpenACC clause.

@ Gang

'gang' clause, allowed on 'loop' and Combined constructs.

@ Wait

'wait' clause, allowed on Compute, Data, 'update', and Combined constructs.

@ DevicePtr

'deviceptr' clause, allowed on Compute and Combined Constructs, plus 'data' and 'declare'.

@ PCopyOut

'copyout' clause alias 'pcopyout'. Preserved for diagnostic purposes.

@ VectorLength

'vector_length' clause, allowed on 'parallel', 'kernels', 'parallel loop', and 'kernels loop' constru...

@ Async

'async' clause, allowed on Compute, Data, 'update', 'wait', and Combined constructs.

@ PresentOrCreate

'create' clause alias 'present_or_create'.

@ Collapse

'collapse' clause, allowed on 'loop' and Combined constructs.

@ PresentOrCopy

'copy' clause alias 'present_or_copy'. Preserved for diagnostic purposes.

@ DeviceNum

'device_num' clause, allowed on 'init', 'shutdown', and 'set' constructs.

@ Private

'private' clause, allowed on 'parallel', 'serial', 'loop', 'parallel loop', and 'serial loop' constru...

@ Vector

'vector' clause, allowed on 'loop', Combined, and 'routine' directives.

@ Copy

'copy' clause, allowed on Compute and Combined Constructs, plus 'data' and 'declare'.

@ Worker

'worker' clause, allowed on 'loop', Combined, and 'routine' directives.

@ Create

'create' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...

@ DeviceType

'device_type' clause, allowed on Compute, 'data', 'init', 'shutdown', 'set', update',...

@ DefaultAsync

'default_async' clause, allowed on 'set' construct.

@ Attach

'attach' clause, allowed on Compute and Combined constructs, plus 'data' and 'enter data'.

@ NumGangs

'num_gangs' clause, allowed on 'parallel', 'kernels', parallel loop', and 'kernels loop' constructs.

@ If

'if' clause, allowed on all the Compute Constructs, Data Constructs, Executable Constructs,...

@ Default

'default' clause, allowed on parallel, serial, kernel (and compound) constructs.

@ UseDevice

'use_device' clause, allowed on 'host_data' construct.

@ NoCreate

'no_create' clause, allowed on allowed on Compute and Combined constructs, plus 'data'.

@ PresentOrCopyOut

'copyout' clause alias 'present_or_copyout'.

@ Reduction

'reduction' clause, allowed on Parallel, Serial, Loop, and the combined constructs.

@ Self

'self' clause, allowed on Compute and Combined Constructs, plus 'update'.

@ CopyOut

'copyout' clause, allowed on Compute and Combined constructs, plus 'data', 'exit data',...

@ FirstPrivate

'firstprivate' clause, allowed on 'parallel', 'serial', 'parallel loop', and 'serial loop' constructs...

@ Host

'host' clause, allowed on 'update' construct.

@ PCopy

'copy' clause alias 'pcopy'. Preserved for diagnostic purposes.

@ Tile

'tile' clause, allowed on 'loop' and Combined constructs.

@ PCopyIn

'copyin' clause alias 'pcopyin'. Preserved for diagnostic purposes.

@ PCreate

'create' clause alias 'pcreate'. Preserved for diagnostic purposes.

@ Present

'present' clause, allowed on Compute and Combined constructs, plus 'data' and 'declare'.

@ DType

'dtype' clause, an alias for 'device_type', stored separately for diagnostic purposes.

@ CopyIn

'copyin' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...

@ Device

'device' clause, allowed on the 'update' construct.

@ NumWorkers

'num_workers' clause, allowed on 'parallel', 'kernels', parallel loop', and 'kernels loop' constructs...

@ Detach

'detach' clause, allowed on the 'exit data' construct.

@ Delete

'delete' clause, allowed on the 'exit data' construct.

@ PresentOrCopyIn

'copyin' clause alias 'present_or_copyin'.

If there is a current 'active' loop construct with a 'gang' clause on a 'kernel' construct,...

OpenACCDirectiveKind DirKind

If there is a current 'active' loop construct that does NOT have a 'seq' clause on it,...

OpenACCDirectiveKind Kind