Skip to content

Replace raw-string OpenACC clause handling and unparse hacks with typed payloads #12

@ouankou

Description

@ouankou

Goal

Document and fix the string-heavy OpenACC parsing/unparsing so directives/clauses are structural (enum + typed payloads) with no post-unparse hacks, preserving separators/ordering and failing fast on unknowns.

Problems

  • Clause payloads are raw strings (OpenACCClause::addLangExpr, OpenACCVarListClause): async/default_async IDs, device/device_num/num_gangs/num_workers/tile, gang(dim/static/num) args, wait queue lists, routine/bind identifiers, data-like clauses (copy/copyin/copyout/create/present/use_device/link/deviceptr/device_resident/no_create/attach), device selectors, reduction operands, if conditions—none are typed.
  • Clause merging (enable_clause_merging) dedups by kind and var string, dropping distinct self/wait/data clauses or altering order; alias spellings aren’t preserved structurally.
  • Unparser hacks in OpenACCIRToString.cpp: append space/comma then substr trim; pre-open parens then trim when empty. Spacing is fragile (e.g., copyin(...)create(...)).
  • Unknown directives/clauses often flow through generic paths instead of fatal errors, hiding parser/API mismatches.

Impact/Analysis

  • Round-trip spacing/separator bugs and payload loss (queues, gang args, async IDs, data lists) because data is stringly and merged. Aliases (pcreate/create, bind identifiers) are not distinguished.
  • Spacing hacks make output dependent on every toString appending a trailing space/comma, causing regressions when code changes.

Actionable Plan

  1. AST Typing: Add typed structs/enums for all clause payloads (async/default_async IDs, gang args with num/dim/static, wait queue lists with order, bind/routine identifiers, device selectors, device/num_gangs/num_workers/tile, data clause var-sections, reduction operands, if conditions). Record separators and ordering.
  2. Grammar layer: Update ANTLR actions to build typed payloads directly; avoid storing raw strings. Add missing enums in OpenACCKinds.h as the single source of truth.
  3. IR/C API: Expose structured payloads; remove string reparsing. Unknown kinds/payload mismatches should be fatal.
  4. Unparser: Emit from structured data; remove trailing-space/comma substr hacks and only open parens when there is content. Honor recorded separators (comma vs space) and clause order.
  5. Merging: Disable or limit clause merging to spec-allowed cases; keep one clause per appearance for self/wait/data unless a semantic merge is explicitly valid.
  6. Alias fidelity: Preserve original keyword spelling via typed fields (identifier vs string literal) instead of raw strings.
  7. Testing: Strengthen OpenACCV-V round-trip and ctest coverage for async/wait/gang/tile/device/data/reduction/routine/bind cases; require 100% round-trip without spacing hacks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions