[code-reflection] RFR: [hat][codegen] Parenthesis in Expressions for binaryOps fixed [v6]

Juan Fumero jfumero at openjdk.org
Wed Sep 24 12:19:35 UTC 2025


> HAT Code gen was not generated parenthesis correctly. This PR forces to use an open and closed parenthesis for binaryOps. 
> 
> Code reflection generates code models in SSA form. Therefore, priority is given by computing values first the values before carrying out the result-op to other ops. 
> 
> For instance: 
> 
> 
> final int TN = 2;
> final int TF = 128;
> final int MAX = 1024;
> int c = MAX / (TN * TF);
> 
> 
> Generates the following code model:
> 
> 
>     %10 : java.type:"int" = var.load %9 @loc="50:17";
>     %11 : java.type:"int" = var.load %5 @loc="50:24";
>     %12 : java.type:"int" = var.load %7 @loc="50:29";
>     %13 : java.type:"int" = mul %11 %12 @loc="50:24";    >> mult
>     %14 : java.type:"int" = div %10 %13 @loc="50:17";      >> div
>     %15 : Var<java.type:"int"> = var %14 @loc="50:9" @"c";
> 
> 
> while 
> 
> 
> final int TN = 2;
> final int TF = 128;
> final int MAX = 1024;
> int c = MAX / TN * TF;
> 
> 
> Generates the following code model.
> 
> 
>     %10 : java.type:"int" = var.load %9 @loc="50:17";
>     %11 : java.type:"int" = var.load %5 @loc="50:23";
>     %12 : java.type:"int" = div %10 %11 @loc="50:17";
>     %13 : java.type:"int" = var.load %7 @loc="50:28";
>     %14 : java.type:"int" = mul %12 %13 @loc="50:17";
>     %15 : Var<java.type:"int"> = var %14 @loc="50:9" @"c";
> 
> 
> The issue was that in the HAT codegen, parentheses were computed based on pure precedence of the operator, not based on the dependencies. 
> 
> How to test:
> 
> 
> HAT=SHOW_CODE java @hat/test ffi-opencl oracle.code.hat.TestParenthesis

Juan Fumero has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains nine additional commits since the last revision:

 - [hat] Parenthesis issue revisited
 - Merge branch 'code-reflection' into hat/codegen/parent
 - minor cleanup
 - new Test added in hat.java
 - clean-up
 - clean-up
 - [hat] Another fix for parenthesis
 - [hat] More tests to check nested parenthesis
 - [hat] Expressions for binaryOps fixed

-------------

Changes:
  - all: https://git.openjdk.org/babylon/pull/579/files
  - new: https://git.openjdk.org/babylon/pull/579/files/39fecc10..e87a3ac0

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=babylon&pr=579&range=05
 - incr: https://webrevs.openjdk.org/?repo=babylon&pr=579&range=04-05

  Stats: 681 lines in 43 files changed: 214 ins; 115 del; 352 mod
  Patch: https://git.openjdk.org/babylon/pull/579.diff
  Fetch: git fetch https://git.openjdk.org/babylon.git pull/579/head:pull/579

PR: https://git.openjdk.org/babylon/pull/579


More information about the babylon-dev mailing list