zahiraam wrote:

> > @alexey-bataev - I understand the current implementation is fundamentally 
> > broken. Before implementing a fix, I want to confirm the following correct 
> > approach.
> > Parser:
> > 
> > 1. Parse each variant directive completely including all clauses.
> > 2. Do not parse the associated statement (body).
> > 3. Return complete directive AST nodes with nullptr body.
> > 4. Parse the shared body once after all variants.
> > 5. Pass complete directive (nodes + shared body) to Sema.
> > 
> > Sema:
> > 
> > 1. Receive complete directive ASTs (with all clauses) and shared body.
> > 2. Set the shared body on each variant directive.
> > 3. Build IfStmt branching between complete directive nodes.
> > 4. Wrap in OMPMetaDirective.
> > 
> > Example: #pragma omp metadirective when(user={condition(flag)}: parallel 
> > num_threads(4)) otherwise(single nowait) { foo(); }
> > Parser produces:
> > 
> > * OMPParallelDirective with num_threads(4) clause, body=nullptr
> > * OMPSingleDirective with nowait clause, body=nullptr
> > * Shared body: { foo(); }
> > 
> > Sema produces: IfStmt(flag, then: OMPParallelDirective(num_threads(4)) { 
> > foo(); }, else: OMPSingleDirective(nowait) { foo(); } )
> > Is this the correct approach? Thanks.
> 
> Couple question:
> 
> > 3. Return complete directive AST nodes with nullptr body.
> 
> Why? We have to parse all directives completely, including all clauses, then 
> parse the body and attach to the meta directive, which includes all other 
> directives + clauses, like selectors.
> 
> > 5. Pass complete directive (nodes + shared body) to Sema.
> > 6. Receive complete directive ASTs (with all clauses) and shared body.
> 
> It should be done in Sema, Sema builds AST nodes, Parser just parses it, 
> nothing else.
> 
> > 2. Set the shared body on each variant directive.
> 
> Hmm, why do wee need it? We need to build a metadirective, which will include 
> all the stuff, and the single body should be attached to a metadirective. 
> Upon lowering, metadirective codegen should correctly dispatch this body to 
> the proper lowering function.
> 
> > 3. Build IfStmt branching between complete directive nodes.
> 
> You do not need it in AST, you can do it in codegen.

Thank you for the clarification. Let me confirm my understanding:               
                                                                                
         
  1. Parser: Parse all variant directives completely (including clauses) by 
calling the normal directive parsing path. Parse the body once.
  2. Sema: Build variant directive AST nodes (with clauses but no body). Build 
metadirective containing the variant directives and attach the single body to 
the metadirective itself.                         
  3. AST Structure: Metadirective contains variant directives (templates with 
clauses) + single body. NO IfStmt in AST.                                       
                                                 
  4. Codegen: Generate if-else chain at codegen time, dispatching the 
metadirective's body to the appropriate variant directive's lowering function 
based on conditions.                                       

https://github.com/llvm/llvm-project/pull/192455
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to