[clang] Add Documentation for Execution Results Handling in Clang-Repl (PR #65650)
Krishna-13-cyber wrote: Ping. https://github.com/llvm/llvm-project/pull/65650 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add Documentation for Execution Results Handling in Clang-Repl (PR #65650)
https://github.com/Krishna-13-cyber updated https://github.com/llvm/llvm-project/pull/65650 >From 145ff3877b588aebd811f26b6d596257ea889957 Mon Sep 17 00:00:00 2001 From: Krishna-13-cyber Date: Thu, 7 Sep 2023 22:35:53 +0530 Subject: [PATCH 1/2] Add Documentation for Execution Results Handling in Clang-Repl --- clang/docs/CMakeLists.txt | 7 + clang/docs/ClangRepl.rst | 405 ++ clang/docs/conf.py| 1 + 3 files changed, 413 insertions(+) diff --git a/clang/docs/CMakeLists.txt b/clang/docs/CMakeLists.txt index 4163dd2d90ad5b3..356814f994c32cd 100644 --- a/clang/docs/CMakeLists.txt +++ b/clang/docs/CMakeLists.txt @@ -103,6 +103,13 @@ function (gen_rst_file_from_td output_file td_option source docs_targets) endfunction() if (LLVM_ENABLE_SPHINX) + llvm_find_program(dot) + if (HAVE_DOT) +set(DOT ${LLVM_PATH_DOT}) + else() +message(FATAL_ERROR "Cannot find DOT") + endif() + include(AddSphinxTarget) if (SPHINX_FOUND AND (${SPHINX_OUTPUT_HTML} OR ${SPHINX_OUTPUT_MAN})) # Copy rst files to build directory before generating the html diff --git a/clang/docs/ClangRepl.rst b/clang/docs/ClangRepl.rst index bd99bc82f17..47513dec18f04e7 100644 --- a/clang/docs/ClangRepl.rst +++ b/clang/docs/ClangRepl.rst @@ -213,6 +213,411 @@ concept helps support advanced use cases such as template instantiations on dema automatic language interoperability. It also helps static languages such as C/C++ become apt for data science. +Execution Results Handling in Clang-Repl + + +Execution Results Handling features discussed below help extend the Clang-Repl +functionality by creating an interface between the execution results of a +program and the compiled program. + +1. **Capture Execution Results**: This feature helps capture the execution results +of a program and bring them back to the compiled program. + +2. **Dump Captured Execution Results**: This feature helps create a temporary dump +for Value Printing/Automatic Printf, that is, to display the value and type of +the captured data. + + +1. Capture Execution Results + + +In many cases, it is useful to bring back the program execution result to the +compiled program. This result can be stored in an object of type **Value**. + +How Execution Results are captured (Value Synthesis): +- + +The synthesizer chooses which expression to synthesize, and then it replaces +the original expression with the synthesized expression. Depending on the +expression type, it may choose to save an object (``LastValue``) of type 'value' +while allocating memory to it (``SetValueWithAlloc()``), or not ( +``SetValueNoAlloc()``). + +.. graphviz:: +:name: valuesynthesis +:caption: Value Synthesis +:alt: Shows how an object of type 'Value' is synthesized +:align: center + + digraph "valuesynthesis" { + rankdir="LR"; + graph [fontname="Verdana", fontsize="12"]; + node [fontname="Verdana", fontsize="12"]; + edge [fontname="Sans", fontsize="9"]; + + start [label=" Create an Object \n 'Last Value' \n of type 'Value' ", shape="note", fontcolor=white, fillcolor="#ff", style=filled]; + assign [label=" Assign the result \n to the 'LastValue' \n (based on respective \n Memory Allocation \n scenario) ", shape="box"] + print [label=" Pretty Print \n the Value Object ", shape="Msquare", fillcolor="yellow", style=filled]; + start -> assign; + assign -> print; + + subgraph SynthesizeExpression { + synth [label=" SynthesizeExpr() ", shape="note", fontcolor=white, fillcolor="#ff", style=filled]; + mem [label=" New Memory \n Allocation? ", shape="diamond"]; + withaloc [label=" SetValueWithAlloc() ", shape="box"]; + noaloc [label=" SetValueNoAlloc() ", shape="box"]; + right [label=" 1. RValue Structure \n (a temporary value)", shape="box"]; + left2 [label=" 2. LValue Structure \n (a variable with \n an address)", shape="box"]; + left3 [label=" 3. Built-In Type \n (int, float, etc.)", shape="box"]; + output [label=" move to 'Assign' step ", shape="box"]; + + synth -> mem; + mem -> withaloc [label="Yes"]; + mem -> noaloc [label="No"]; + withaloc -> right; + noaloc -> left2; + noaloc -> left3; + right -> output; + left2 -> output; + left3 -> output; + } +output -> assign + } + +Where is the captured result stored? + + +``LastValue`` holds the last result of the value printing. It is a class member +because it can be accessed even after subsequent inputs. + +**Note:** If no value printing happens, then it is in an invalid state. + +Improving Efficien
[clang] Add Documentation for Execution Results Handling in Clang-Repl (PR #65650)
https://github.com/Krishna-13-cyber updated https://github.com/llvm/llvm-project/pull/65650 >From 63b41d9498a71e090cbf1fdca2d87f368aeb809c Mon Sep 17 00:00:00 2001 From: Krishna-13-cyber Date: Thu, 7 Sep 2023 22:35:53 +0530 Subject: [PATCH 1/2] Add Documentation for Execution Results Handling in Clang-Repl --- clang/docs/CMakeLists.txt | 7 + clang/docs/ClangRepl.rst | 405 ++ clang/docs/conf.py| 1 + 3 files changed, 413 insertions(+) diff --git a/clang/docs/CMakeLists.txt b/clang/docs/CMakeLists.txt index 4163dd2d90ad5b3..356814f994c32cd 100644 --- a/clang/docs/CMakeLists.txt +++ b/clang/docs/CMakeLists.txt @@ -103,6 +103,13 @@ function (gen_rst_file_from_td output_file td_option source docs_targets) endfunction() if (LLVM_ENABLE_SPHINX) + llvm_find_program(dot) + if (HAVE_DOT) +set(DOT ${LLVM_PATH_DOT}) + else() +message(FATAL_ERROR "Cannot find DOT") + endif() + include(AddSphinxTarget) if (SPHINX_FOUND AND (${SPHINX_OUTPUT_HTML} OR ${SPHINX_OUTPUT_MAN})) # Copy rst files to build directory before generating the html diff --git a/clang/docs/ClangRepl.rst b/clang/docs/ClangRepl.rst index bd99bc82f17..47513dec18f04e7 100644 --- a/clang/docs/ClangRepl.rst +++ b/clang/docs/ClangRepl.rst @@ -213,6 +213,411 @@ concept helps support advanced use cases such as template instantiations on dema automatic language interoperability. It also helps static languages such as C/C++ become apt for data science. +Execution Results Handling in Clang-Repl + + +Execution Results Handling features discussed below help extend the Clang-Repl +functionality by creating an interface between the execution results of a +program and the compiled program. + +1. **Capture Execution Results**: This feature helps capture the execution results +of a program and bring them back to the compiled program. + +2. **Dump Captured Execution Results**: This feature helps create a temporary dump +for Value Printing/Automatic Printf, that is, to display the value and type of +the captured data. + + +1. Capture Execution Results + + +In many cases, it is useful to bring back the program execution result to the +compiled program. This result can be stored in an object of type **Value**. + +How Execution Results are captured (Value Synthesis): +- + +The synthesizer chooses which expression to synthesize, and then it replaces +the original expression with the synthesized expression. Depending on the +expression type, it may choose to save an object (``LastValue``) of type 'value' +while allocating memory to it (``SetValueWithAlloc()``), or not ( +``SetValueNoAlloc()``). + +.. graphviz:: +:name: valuesynthesis +:caption: Value Synthesis +:alt: Shows how an object of type 'Value' is synthesized +:align: center + + digraph "valuesynthesis" { + rankdir="LR"; + graph [fontname="Verdana", fontsize="12"]; + node [fontname="Verdana", fontsize="12"]; + edge [fontname="Sans", fontsize="9"]; + + start [label=" Create an Object \n 'Last Value' \n of type 'Value' ", shape="note", fontcolor=white, fillcolor="#ff", style=filled]; + assign [label=" Assign the result \n to the 'LastValue' \n (based on respective \n Memory Allocation \n scenario) ", shape="box"] + print [label=" Pretty Print \n the Value Object ", shape="Msquare", fillcolor="yellow", style=filled]; + start -> assign; + assign -> print; + + subgraph SynthesizeExpression { + synth [label=" SynthesizeExpr() ", shape="note", fontcolor=white, fillcolor="#ff", style=filled]; + mem [label=" New Memory \n Allocation? ", shape="diamond"]; + withaloc [label=" SetValueWithAlloc() ", shape="box"]; + noaloc [label=" SetValueNoAlloc() ", shape="box"]; + right [label=" 1. RValue Structure \n (a temporary value)", shape="box"]; + left2 [label=" 2. LValue Structure \n (a variable with \n an address)", shape="box"]; + left3 [label=" 3. Built-In Type \n (int, float, etc.)", shape="box"]; + output [label=" move to 'Assign' step ", shape="box"]; + + synth -> mem; + mem -> withaloc [label="Yes"]; + mem -> noaloc [label="No"]; + withaloc -> right; + noaloc -> left2; + noaloc -> left3; + right -> output; + left2 -> output; + left3 -> output; + } +output -> assign + } + +Where is the captured result stored? + + +``LastValue`` holds the last result of the value printing. It is a class member +because it can be accessed even after subsequent inputs. + +**Note:** If no value printing happens, then it is in an invalid state. + +Improving Efficien
[clang] Add Documentation for Execution Results Handling in Clang-Repl (PR #65650)
https://github.com/Krishna-13-cyber updated https://github.com/llvm/llvm-project/pull/65650 >From 001c8fe5627bb83c71a11535889d3c717a869df5 Mon Sep 17 00:00:00 2001 From: Krishna-13-cyber Date: Thu, 7 Sep 2023 22:35:53 +0530 Subject: [PATCH] Add Documentation for Execution Results Handling in Clang-Repl --- clang/docs/CMakeLists.txt | 7 + clang/docs/ClangRepl.rst | 405 ++ clang/docs/conf.py| 1 + 3 files changed, 413 insertions(+) diff --git a/clang/docs/CMakeLists.txt b/clang/docs/CMakeLists.txt index 4163dd2d90ad5b3..356814f994c32cd 100644 --- a/clang/docs/CMakeLists.txt +++ b/clang/docs/CMakeLists.txt @@ -103,6 +103,13 @@ function (gen_rst_file_from_td output_file td_option source docs_targets) endfunction() if (LLVM_ENABLE_SPHINX) + llvm_find_program(dot) + if (HAVE_DOT) +set(DOT ${LLVM_PATH_DOT}) + else() +message(FATAL_ERROR "Cannot find DOT") + endif() + include(AddSphinxTarget) if (SPHINX_FOUND AND (${SPHINX_OUTPUT_HTML} OR ${SPHINX_OUTPUT_MAN})) # Copy rst files to build directory before generating the html diff --git a/clang/docs/ClangRepl.rst b/clang/docs/ClangRepl.rst index bd99bc82f17..5399036c123fbbf 100644 --- a/clang/docs/ClangRepl.rst +++ b/clang/docs/ClangRepl.rst @@ -213,6 +213,411 @@ concept helps support advanced use cases such as template instantiations on dema automatic language interoperability. It also helps static languages such as C/C++ become apt for data science. +Execution Results Handling in Clang-Repl + + +Execution Results Handling features discussed below help extend the Clang-Repl +functionality by creating an interface between the execution results of a +program and the compiled program. + +1. **Capture Execution Results**: This feature helps capture the execution results +of a program and bring them back to the compiled program. + +2. **Dump Captured Execution Results**: This feature helps create a temporary dump +for Value Printing/Automatic Printf, that is, to display the value and type of +the captured data. + + +1. Capture Execution Results + + +In many cases, it is useful to bring back the program execution result to the +compiled program. This result can be stored in an object of type **Value**. + +How Execution Results are captured (Value Synthesis): +- + +The synthesizer chooses which expression to synthesize, and then it replaces +the original expression with the synthesized expression. Depending on the +expression type, it may choose to save an object (``LastValue``) of type 'value' +while allocating memory to it (``SetValueWithAlloc()``), or not ( +``SetValueNoAlloc()``). + +.. graphviz:: +:name: valuesynthesis +:caption: Value Synthesis +:alt: Shows how an object of type 'Value' is synthesized +:align: center + + digraph "valuesynthesis" { + rankdir="LR"; + graph [fontname="Verdana", fontsize="12"]; + node [fontname="Verdana", fontsize="12"]; + edge [fontname="Sans", fontsize="9"]; + + start [label=" Create an Object \n 'Last Value' \n of type 'Value' ", shape="note", fontcolor=white, fillcolor="#ff", style=filled]; + assign [label=" Assign the result \n to the 'LastValue' \n (based on respective \n Memory Allocation \n scenario) ", shape="box"] + print [label=" Pretty Print \n the Value Object ", shape="Msquare", fillcolor="yellow", style=filled]; + start -> assign; + assign -> print; + + subgraph SynthesizeExpression { + synth [label=" SynthesizeExpr() ", shape="note", fontcolor=white, fillcolor="#ff", style=filled]; + mem [label=" New Memory \n Allocation? ", shape="diamond"]; + withaloc [label=" SetValueWithAlloc() ", shape="box"]; + noaloc [label=" SetValueNoAlloc() ", shape="box"]; + right [label=" 1. RValue Structure \n (a temporary value)", shape="box"]; + left2 [label=" 2. LValue Structure \n (a variable with \n an address)", shape="box"]; + left3 [label=" 3. Built-In Type \n (int, float, etc.)", shape="box"]; + output [label=" move to 'Assign' step ", shape="box"]; + + synth -> mem; + mem -> withaloc [label="Yes"]; + mem -> noaloc [label="No"]; + withaloc -> right; + noaloc -> left2; + noaloc -> left3; + right -> output; + left2 -> output; + left3 -> output; + } +output -> assign + } + +Where is the captured result stored? + + +``LastValue`` holds the last result of the value printing. It is a class member +because it can be accessed even after subsequent inputs. + +**Note:** If no value printing happens, then it is in an invalid state. + +Improving Efficiency a
[clang] Add Documentation for Execution Results Handling in Clang-Repl (PR #65650)
https://github.com/Krishna-13-cyber updated https://github.com/llvm/llvm-project/pull/65650 >From 967d465083c2bf0887be14380b82aac69175b47e Mon Sep 17 00:00:00 2001 From: Krishna-13-cyber Date: Thu, 7 Sep 2023 22:35:53 +0530 Subject: [PATCH 1/2] Add Documentation for Execution Results Handling in Clang-Repl --- clang/docs/CMakeLists.txt | 7 + clang/docs/ClangRepl.rst | 405 ++ clang/docs/conf.py| 1 + 3 files changed, 413 insertions(+) diff --git a/clang/docs/CMakeLists.txt b/clang/docs/CMakeLists.txt index 4163dd2d90ad5b3..356814f994c32cd 100644 --- a/clang/docs/CMakeLists.txt +++ b/clang/docs/CMakeLists.txt @@ -103,6 +103,13 @@ function (gen_rst_file_from_td output_file td_option source docs_targets) endfunction() if (LLVM_ENABLE_SPHINX) + llvm_find_program(dot) + if (HAVE_DOT) +set(DOT ${LLVM_PATH_DOT}) + else() +message(FATAL_ERROR "Cannot find DOT") + endif() + include(AddSphinxTarget) if (SPHINX_FOUND AND (${SPHINX_OUTPUT_HTML} OR ${SPHINX_OUTPUT_MAN})) # Copy rst files to build directory before generating the html diff --git a/clang/docs/ClangRepl.rst b/clang/docs/ClangRepl.rst index bd99bc82f17..5399036c123fbbf 100644 --- a/clang/docs/ClangRepl.rst +++ b/clang/docs/ClangRepl.rst @@ -213,6 +213,411 @@ concept helps support advanced use cases such as template instantiations on dema automatic language interoperability. It also helps static languages such as C/C++ become apt for data science. +Execution Results Handling in Clang-Repl + + +Execution Results Handling features discussed below help extend the Clang-Repl +functionality by creating an interface between the execution results of a +program and the compiled program. + +1. **Capture Execution Results**: This feature helps capture the execution results +of a program and bring them back to the compiled program. + +2. **Dump Captured Execution Results**: This feature helps create a temporary dump +for Value Printing/Automatic Printf, that is, to display the value and type of +the captured data. + + +1. Capture Execution Results + + +In many cases, it is useful to bring back the program execution result to the +compiled program. This result can be stored in an object of type **Value**. + +How Execution Results are captured (Value Synthesis): +- + +The synthesizer chooses which expression to synthesize, and then it replaces +the original expression with the synthesized expression. Depending on the +expression type, it may choose to save an object (``LastValue``) of type 'value' +while allocating memory to it (``SetValueWithAlloc()``), or not ( +``SetValueNoAlloc()``). + +.. graphviz:: +:name: valuesynthesis +:caption: Value Synthesis +:alt: Shows how an object of type 'Value' is synthesized +:align: center + + digraph "valuesynthesis" { + rankdir="LR"; + graph [fontname="Verdana", fontsize="12"]; + node [fontname="Verdana", fontsize="12"]; + edge [fontname="Sans", fontsize="9"]; + + start [label=" Create an Object \n 'Last Value' \n of type 'Value' ", shape="note", fontcolor=white, fillcolor="#ff", style=filled]; + assign [label=" Assign the result \n to the 'LastValue' \n (based on respective \n Memory Allocation \n scenario) ", shape="box"] + print [label=" Pretty Print \n the Value Object ", shape="Msquare", fillcolor="yellow", style=filled]; + start -> assign; + assign -> print; + + subgraph SynthesizeExpression { + synth [label=" SynthesizeExpr() ", shape="note", fontcolor=white, fillcolor="#ff", style=filled]; + mem [label=" New Memory \n Allocation? ", shape="diamond"]; + withaloc [label=" SetValueWithAlloc() ", shape="box"]; + noaloc [label=" SetValueNoAlloc() ", shape="box"]; + right [label=" 1. RValue Structure \n (a temporary value)", shape="box"]; + left2 [label=" 2. LValue Structure \n (a variable with \n an address)", shape="box"]; + left3 [label=" 3. Built-In Type \n (int, float, etc.)", shape="box"]; + output [label=" move to 'Assign' step ", shape="box"]; + + synth -> mem; + mem -> withaloc [label="Yes"]; + mem -> noaloc [label="No"]; + withaloc -> right; + noaloc -> left2; + noaloc -> left3; + right -> output; + left2 -> output; + left3 -> output; + } +output -> assign + } + +Where is the captured result stored? + + +``LastValue`` holds the last result of the value printing. It is a class member +because it can be accessed even after subsequent inputs. + +**Note:** If no value printing happens, then it is in an invalid state. + +Improving Efficien
[clang] Add Documentation for Execution Results Handling in Clang-Repl (PR #65650)
https://github.com/Krishna-13-cyber updated https://github.com/llvm/llvm-project/pull/65650 >From b14c1890e4d5ecf4ebd9d0aefe9f73a0b3a12f5f Mon Sep 17 00:00:00 2001 From: Krishna-13-cyber Date: Thu, 7 Sep 2023 22:35:53 +0530 Subject: [PATCH] Add Documentation for Execution Results Handling in Clang-Repl --- clang/docs/CMakeLists.txt | 7 + clang/docs/ClangRepl.rst | 405 ++ clang/docs/conf.py| 2 +- 3 files changed, 413 insertions(+), 1 deletion(-) diff --git a/clang/docs/CMakeLists.txt b/clang/docs/CMakeLists.txt index 4163dd2d90ad5b3..356814f994c32cd 100644 --- a/clang/docs/CMakeLists.txt +++ b/clang/docs/CMakeLists.txt @@ -103,6 +103,13 @@ function (gen_rst_file_from_td output_file td_option source docs_targets) endfunction() if (LLVM_ENABLE_SPHINX) + llvm_find_program(dot) + if (HAVE_DOT) +set(DOT ${LLVM_PATH_DOT}) + else() +message(FATAL_ERROR "Cannot find DOT") + endif() + include(AddSphinxTarget) if (SPHINX_FOUND AND (${SPHINX_OUTPUT_HTML} OR ${SPHINX_OUTPUT_MAN})) # Copy rst files to build directory before generating the html diff --git a/clang/docs/ClangRepl.rst b/clang/docs/ClangRepl.rst index bd99bc82f17..5399036c123fbbf 100644 --- a/clang/docs/ClangRepl.rst +++ b/clang/docs/ClangRepl.rst @@ -213,6 +213,411 @@ concept helps support advanced use cases such as template instantiations on dema automatic language interoperability. It also helps static languages such as C/C++ become apt for data science. +Execution Results Handling in Clang-Repl + + +Execution Results Handling features discussed below help extend the Clang-Repl +functionality by creating an interface between the execution results of a +program and the compiled program. + +1. **Capture Execution Results**: This feature helps capture the execution results +of a program and bring them back to the compiled program. + +2. **Dump Captured Execution Results**: This feature helps create a temporary dump +for Value Printing/Automatic Printf, that is, to display the value and type of +the captured data. + + +1. Capture Execution Results + + +In many cases, it is useful to bring back the program execution result to the +compiled program. This result can be stored in an object of type **Value**. + +How Execution Results are captured (Value Synthesis): +- + +The synthesizer chooses which expression to synthesize, and then it replaces +the original expression with the synthesized expression. Depending on the +expression type, it may choose to save an object (``LastValue``) of type 'value' +while allocating memory to it (``SetValueWithAlloc()``), or not ( +``SetValueNoAlloc()``). + +.. graphviz:: +:name: valuesynthesis +:caption: Value Synthesis +:alt: Shows how an object of type 'Value' is synthesized +:align: center + + digraph "valuesynthesis" { + rankdir="LR"; + graph [fontname="Verdana", fontsize="12"]; + node [fontname="Verdana", fontsize="12"]; + edge [fontname="Sans", fontsize="9"]; + + start [label=" Create an Object \n 'Last Value' \n of type 'Value' ", shape="note", fontcolor=white, fillcolor="#ff", style=filled]; + assign [label=" Assign the result \n to the 'LastValue' \n (based on respective \n Memory Allocation \n scenario) ", shape="box"] + print [label=" Pretty Print \n the Value Object ", shape="Msquare", fillcolor="yellow", style=filled]; + start -> assign; + assign -> print; + + subgraph SynthesizeExpression { + synth [label=" SynthesizeExpr() ", shape="note", fontcolor=white, fillcolor="#ff", style=filled]; + mem [label=" New Memory \n Allocation? ", shape="diamond"]; + withaloc [label=" SetValueWithAlloc() ", shape="box"]; + noaloc [label=" SetValueNoAlloc() ", shape="box"]; + right [label=" 1. RValue Structure \n (a temporary value)", shape="box"]; + left2 [label=" 2. LValue Structure \n (a variable with \n an address)", shape="box"]; + left3 [label=" 3. Built-In Type \n (int, float, etc.)", shape="box"]; + output [label=" move to 'Assign' step ", shape="box"]; + + synth -> mem; + mem -> withaloc [label="Yes"]; + mem -> noaloc [label="No"]; + withaloc -> right; + noaloc -> left2; + noaloc -> left3; + right -> output; + left2 -> output; + left3 -> output; + } +output -> assign + } + +Where is the captured result stored? + + +``LastValue`` holds the last result of the value printing. It is a class member +because it can be accessed even after subsequent inputs. + +**Note:** If no value printing happens, then it is in an invalid state. + +Improv
[clang] Add Documentation for Execution Results Handling in Clang-Repl (PR #65650)
https://github.com/Krishna-13-cyber created https://github.com/llvm/llvm-project/pull/65650: [clang-repl] Add Documentation for Execution Results Handling. This patch adds documentation for execution results handling in Clang-REPL with the below features: - Automatic Printf feature - Value Synthesis feature - Pretty Printing feature Continuing this work https://reviews.llvm.org/D156858 with this PR. I am issuing this patch on behalf of Saqib. Reviewers: @vgvassilev @junaire >From 145ff3877b588aebd811f26b6d596257ea889957 Mon Sep 17 00:00:00 2001 From: Krishna-13-cyber Date: Thu, 7 Sep 2023 22:35:53 +0530 Subject: [PATCH] Add Documentation for Execution Results Handling in Clang-Repl --- clang/docs/CMakeLists.txt | 7 + clang/docs/ClangRepl.rst | 405 ++ clang/docs/conf.py| 1 + 3 files changed, 413 insertions(+) diff --git a/clang/docs/CMakeLists.txt b/clang/docs/CMakeLists.txt index 4163dd2d90ad5b..356814f994c32c 100644 --- a/clang/docs/CMakeLists.txt +++ b/clang/docs/CMakeLists.txt @@ -103,6 +103,13 @@ function (gen_rst_file_from_td output_file td_option source docs_targets) endfunction() if (LLVM_ENABLE_SPHINX) + llvm_find_program(dot) + if (HAVE_DOT) +set(DOT ${LLVM_PATH_DOT}) + else() +message(FATAL_ERROR "Cannot find DOT") + endif() + include(AddSphinxTarget) if (SPHINX_FOUND AND (${SPHINX_OUTPUT_HTML} OR ${SPHINX_OUTPUT_MAN})) # Copy rst files to build directory before generating the html diff --git a/clang/docs/ClangRepl.rst b/clang/docs/ClangRepl.rst index bd99bc82f1..47513dec18f04e 100644 --- a/clang/docs/ClangRepl.rst +++ b/clang/docs/ClangRepl.rst @@ -213,6 +213,411 @@ concept helps support advanced use cases such as template instantiations on dema automatic language interoperability. It also helps static languages such as C/C++ become apt for data science. +Execution Results Handling in Clang-Repl + + +Execution Results Handling features discussed below help extend the Clang-Repl +functionality by creating an interface between the execution results of a +program and the compiled program. + +1. **Capture Execution Results**: This feature helps capture the execution results +of a program and bring them back to the compiled program. + +2. **Dump Captured Execution Results**: This feature helps create a temporary dump +for Value Printing/Automatic Printf, that is, to display the value and type of +the captured data. + + +1. Capture Execution Results + + +In many cases, it is useful to bring back the program execution result to the +compiled program. This result can be stored in an object of type **Value**. + +How Execution Results are captured (Value Synthesis): +- + +The synthesizer chooses which expression to synthesize, and then it replaces +the original expression with the synthesized expression. Depending on the +expression type, it may choose to save an object (``LastValue``) of type 'value' +while allocating memory to it (``SetValueWithAlloc()``), or not ( +``SetValueNoAlloc()``). + +.. graphviz:: +:name: valuesynthesis +:caption: Value Synthesis +:alt: Shows how an object of type 'Value' is synthesized +:align: center + + digraph "valuesynthesis" { + rankdir="LR"; + graph [fontname="Verdana", fontsize="12"]; + node [fontname="Verdana", fontsize="12"]; + edge [fontname="Sans", fontsize="9"]; + + start [label=" Create an Object \n 'Last Value' \n of type 'Value' ", shape="note", fontcolor=white, fillcolor="#ff", style=filled]; + assign [label=" Assign the result \n to the 'LastValue' \n (based on respective \n Memory Allocation \n scenario) ", shape="box"] + print [label=" Pretty Print \n the Value Object ", shape="Msquare", fillcolor="yellow", style=filled]; + start -> assign; + assign -> print; + + subgraph SynthesizeExpression { + synth [label=" SynthesizeExpr() ", shape="note", fontcolor=white, fillcolor="#ff", style=filled]; + mem [label=" New Memory \n Allocation? ", shape="diamond"]; + withaloc [label=" SetValueWithAlloc() ", shape="box"]; + noaloc [label=" SetValueNoAlloc() ", shape="box"]; + right [label=" 1. RValue Structure \n (a temporary value)", shape="box"]; + left2 [label=" 2. LValue Structure \n (a variable with \n an address)", shape="box"]; + left3 [label=" 3. Built-In Type \n (int, float, etc.)", shape="box"]; + output [label=" move to 'Assign' step ", shape="box"]; + + synth -> mem; + mem -> withaloc [label="Yes"]; + mem -> noaloc [label="No"]; + withaloc -> right; + noaloc -> left2; + noaloc -> left3; + right -> output; + left2 -> output; +
[clang] Add Documentation for Execution Results Handling in Clang-Repl (PR #65650)
https://github.com/Krishna-13-cyber review_requested https://github.com/llvm/llvm-project/pull/65650 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][CodeGen] Optimised LLVM IR for atomic increments/decrements on floats (PR #89362)
https://github.com/Krishna-13-cyber created https://github.com/llvm/llvm-project/pull/89362 Addresses #53079 >From 4e649d105a2af038e6dbd0e93b457eebea2e543a Mon Sep 17 00:00:00 2001 From: Krishna-13-cyber Date: Fri, 19 Apr 2024 15:09:26 +0530 Subject: [PATCH] Add optimised LLVM IR for atomic increments/decrements on floats --- clang/lib/CodeGen/CGExprScalar.cpp| 13 + clang/test/CodeGen/X86/x86-atomic-float.c | 97 +++ .../test/CodeGen/X86/x86-atomic-long_double.c | 609 +- 3 files changed, 410 insertions(+), 309 deletions(-) create mode 100644 clang/test/CodeGen/X86/x86-atomic-float.c diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index 1f18e0d5ba409a..e97bb5c7e9dd16 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -2792,6 +2792,19 @@ ScalarExprEmitter::EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV, llvm::AtomicOrdering::SequentiallyConsistent); return isPre ? Builder.CreateBinOp(op, old, amt) : old; } +// Special case for atomic increment/decrement on floats +if (type->isFloatingType()) { + llvm::AtomicRMWInst::BinOp aop = + isInc ? llvm::AtomicRMWInst::FAdd : llvm::AtomicRMWInst::FSub; + llvm::Instruction::BinaryOps op = + isInc ? llvm::Instruction::FAdd : llvm::Instruction::FSub; + llvm::Value *amt = llvm::ConstantFP::get( + VMContext, llvm::APFloat(static_cast(amount))); + llvm::Value *old = + Builder.CreateAtomicRMW(aop, LV.getAddress(CGF), amt, + llvm::AtomicOrdering::SequentiallyConsistent); + return isPre ? Builder.CreateBinOp(op, old, amt) : old; +} value = EmitLoadOfLValue(LV, E->getExprLoc()); input = value; // For every other atomic operation, we need to emit a load-op-cmpxchg loop diff --git a/clang/test/CodeGen/X86/x86-atomic-float.c b/clang/test/CodeGen/X86/x86-atomic-float.c new file mode 100644 index 00..89a2605ed44461 --- /dev/null +++ b/clang/test/CodeGen/X86/x86-atomic-float.c @@ -0,0 +1,97 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4 +// RUN: %clang_cc1 -triple x86_64-linux-gnu -target-cpu core2 %s -S -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -triple i686-linux-gnu -target-cpu core2 %s -S -emit-llvm -o - | FileCheck -check-prefix=CHECK32 %s + +// CHECK-LABEL: define dso_local i32 @test_int_inc( +// CHECK-SAME: ) #[[ATTR0:[0-9]+]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[TMP0:%.*]] = atomicrmw add ptr @test_int_inc.n, i32 1 seq_cst, align 4 +// CHECK-NEXT:ret i32 [[TMP0]] +// +// CHECK32-LABEL: define dso_local i32 @test_int_inc( +// CHECK32-SAME: ) #[[ATTR0:[0-9]+]] { +// CHECK32-NEXT: entry: +// CHECK32-NEXT:[[TMP0:%.*]] = atomicrmw add ptr @test_int_inc.n, i32 1 seq_cst, align 4 +// CHECK32-NEXT:ret i32 [[TMP0]] +// +int test_int_inc() +{ +static _Atomic int n; +return n++; +} + +// CHECK-LABEL: define dso_local float @test_float_post_inc( +// CHECK-SAME: ) #[[ATTR0]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[TMP0:%.*]] = atomicrmw fadd ptr @test_float_post_inc.n, float 1.00e+00 seq_cst, align 4 +// CHECK-NEXT:ret float [[TMP0]] +// +// CHECK32-LABEL: define dso_local float @test_float_post_inc( +// CHECK32-SAME: ) #[[ATTR0]] { +// CHECK32-NEXT: entry: +// CHECK32-NEXT:[[TMP0:%.*]] = atomicrmw fadd ptr @test_float_post_inc.n, float 1.00e+00 seq_cst, align 4 +// CHECK32-NEXT:ret float [[TMP0]] +// +float test_float_post_inc() +{ +static _Atomic float n; +return n++; +} + +// CHECK-LABEL: define dso_local float @test_float_post_dc( +// CHECK-SAME: ) #[[ATTR0]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[TMP0:%.*]] = atomicrmw fsub ptr @test_float_post_dc.n, float -1.00e+00 seq_cst, align 4 +// CHECK-NEXT:ret float [[TMP0]] +// +// CHECK32-LABEL: define dso_local float @test_float_post_dc( +// CHECK32-SAME: ) #[[ATTR0]] { +// CHECK32-NEXT: entry: +// CHECK32-NEXT:[[TMP0:%.*]] = atomicrmw fsub ptr @test_float_post_dc.n, float -1.00e+00 seq_cst, align 4 +// CHECK32-NEXT:ret float [[TMP0]] +// +float test_float_post_dc() +{ +static _Atomic float n; +return n--; +} + +// CHECK-LABEL: define dso_local float @test_float_pre_dc( +// CHECK-SAME: ) #[[ATTR0]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[TMP0:%.*]] = atomicrmw fsub ptr @test_float_pre_dc.n, float -1.00e+00 seq_cst, align 4 +// CHECK-NEXT:[[TMP1:%.*]] = fsub float [[TMP0]], -1.00e+00 +// CHECK-NEXT:ret float [[TMP1]] +// +// CHECK32-LABEL: define dso_local float @test_float_pre_dc( +// CHECK32-SAME: ) #[[ATTR0]] { +// CHECK32-NEXT: entry: +// CHECK32-NEXT:[[TMP0:%.*]] = atomicrmw fsub ptr @test_float_pre_dc.n, float -1.00e+00 seq_cst, align 4 +// CHECK32-NEXT:[[TMP1:%.*]] = fsub float [[TMP0]], -1.00e+00 +// CH
[clang] [Clang][CodeGen] Optimised LLVM IR for atomic increments/decrements on floats (PR #89362)
https://github.com/Krishna-13-cyber converted_to_draft https://github.com/llvm/llvm-project/pull/89362 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][CodeGen] Optimised LLVM IR for atomic increments/decrements on floats (PR #89362)
https://github.com/Krishna-13-cyber updated https://github.com/llvm/llvm-project/pull/89362 >From 4e649d105a2af038e6dbd0e93b457eebea2e543a Mon Sep 17 00:00:00 2001 From: Krishna-13-cyber Date: Fri, 19 Apr 2024 15:09:26 +0530 Subject: [PATCH 1/2] Add optimised LLVM IR for atomic increments/decrements on floats --- clang/lib/CodeGen/CGExprScalar.cpp| 13 + clang/test/CodeGen/X86/x86-atomic-float.c | 97 +++ .../test/CodeGen/X86/x86-atomic-long_double.c | 609 +- 3 files changed, 410 insertions(+), 309 deletions(-) create mode 100644 clang/test/CodeGen/X86/x86-atomic-float.c diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index 1f18e0d5ba409a..e97bb5c7e9dd16 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -2792,6 +2792,19 @@ ScalarExprEmitter::EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV, llvm::AtomicOrdering::SequentiallyConsistent); return isPre ? Builder.CreateBinOp(op, old, amt) : old; } +// Special case for atomic increment/decrement on floats +if (type->isFloatingType()) { + llvm::AtomicRMWInst::BinOp aop = + isInc ? llvm::AtomicRMWInst::FAdd : llvm::AtomicRMWInst::FSub; + llvm::Instruction::BinaryOps op = + isInc ? llvm::Instruction::FAdd : llvm::Instruction::FSub; + llvm::Value *amt = llvm::ConstantFP::get( + VMContext, llvm::APFloat(static_cast(amount))); + llvm::Value *old = + Builder.CreateAtomicRMW(aop, LV.getAddress(CGF), amt, + llvm::AtomicOrdering::SequentiallyConsistent); + return isPre ? Builder.CreateBinOp(op, old, amt) : old; +} value = EmitLoadOfLValue(LV, E->getExprLoc()); input = value; // For every other atomic operation, we need to emit a load-op-cmpxchg loop diff --git a/clang/test/CodeGen/X86/x86-atomic-float.c b/clang/test/CodeGen/X86/x86-atomic-float.c new file mode 100644 index 00..89a2605ed44461 --- /dev/null +++ b/clang/test/CodeGen/X86/x86-atomic-float.c @@ -0,0 +1,97 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4 +// RUN: %clang_cc1 -triple x86_64-linux-gnu -target-cpu core2 %s -S -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -triple i686-linux-gnu -target-cpu core2 %s -S -emit-llvm -o - | FileCheck -check-prefix=CHECK32 %s + +// CHECK-LABEL: define dso_local i32 @test_int_inc( +// CHECK-SAME: ) #[[ATTR0:[0-9]+]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[TMP0:%.*]] = atomicrmw add ptr @test_int_inc.n, i32 1 seq_cst, align 4 +// CHECK-NEXT:ret i32 [[TMP0]] +// +// CHECK32-LABEL: define dso_local i32 @test_int_inc( +// CHECK32-SAME: ) #[[ATTR0:[0-9]+]] { +// CHECK32-NEXT: entry: +// CHECK32-NEXT:[[TMP0:%.*]] = atomicrmw add ptr @test_int_inc.n, i32 1 seq_cst, align 4 +// CHECK32-NEXT:ret i32 [[TMP0]] +// +int test_int_inc() +{ +static _Atomic int n; +return n++; +} + +// CHECK-LABEL: define dso_local float @test_float_post_inc( +// CHECK-SAME: ) #[[ATTR0]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[TMP0:%.*]] = atomicrmw fadd ptr @test_float_post_inc.n, float 1.00e+00 seq_cst, align 4 +// CHECK-NEXT:ret float [[TMP0]] +// +// CHECK32-LABEL: define dso_local float @test_float_post_inc( +// CHECK32-SAME: ) #[[ATTR0]] { +// CHECK32-NEXT: entry: +// CHECK32-NEXT:[[TMP0:%.*]] = atomicrmw fadd ptr @test_float_post_inc.n, float 1.00e+00 seq_cst, align 4 +// CHECK32-NEXT:ret float [[TMP0]] +// +float test_float_post_inc() +{ +static _Atomic float n; +return n++; +} + +// CHECK-LABEL: define dso_local float @test_float_post_dc( +// CHECK-SAME: ) #[[ATTR0]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[TMP0:%.*]] = atomicrmw fsub ptr @test_float_post_dc.n, float -1.00e+00 seq_cst, align 4 +// CHECK-NEXT:ret float [[TMP0]] +// +// CHECK32-LABEL: define dso_local float @test_float_post_dc( +// CHECK32-SAME: ) #[[ATTR0]] { +// CHECK32-NEXT: entry: +// CHECK32-NEXT:[[TMP0:%.*]] = atomicrmw fsub ptr @test_float_post_dc.n, float -1.00e+00 seq_cst, align 4 +// CHECK32-NEXT:ret float [[TMP0]] +// +float test_float_post_dc() +{ +static _Atomic float n; +return n--; +} + +// CHECK-LABEL: define dso_local float @test_float_pre_dc( +// CHECK-SAME: ) #[[ATTR0]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[TMP0:%.*]] = atomicrmw fsub ptr @test_float_pre_dc.n, float -1.00e+00 seq_cst, align 4 +// CHECK-NEXT:[[TMP1:%.*]] = fsub float [[TMP0]], -1.00e+00 +// CHECK-NEXT:ret float [[TMP1]] +// +// CHECK32-LABEL: define dso_local float @test_float_pre_dc( +// CHECK32-SAME: ) #[[ATTR0]] { +// CHECK32-NEXT: entry: +// CHECK32-NEXT:[[TMP0:%.*]] = atomicrmw fsub ptr @test_float_pre_dc.n, float -1.00e+00 seq_cst, align 4 +// CHECK32-NEXT:[[TMP1:%.*]] = fsub float [[TMP0]], -1.00e+00 +// CHECK32-NEXT:
[clang] [Clang][CodeGen] Optimised LLVM IR for atomic increments/decrements on floats (PR #89362)
https://github.com/Krishna-13-cyber ready_for_review https://github.com/llvm/llvm-project/pull/89362 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][CodeGen] Optimised LLVM IR for atomic increments/decrements on floats (PR #89362)
https://github.com/Krishna-13-cyber updated https://github.com/llvm/llvm-project/pull/89362 >From 4e649d105a2af038e6dbd0e93b457eebea2e543a Mon Sep 17 00:00:00 2001 From: Krishna-13-cyber Date: Fri, 19 Apr 2024 15:09:26 +0530 Subject: [PATCH 1/3] Add optimised LLVM IR for atomic increments/decrements on floats --- clang/lib/CodeGen/CGExprScalar.cpp| 13 + clang/test/CodeGen/X86/x86-atomic-float.c | 97 +++ .../test/CodeGen/X86/x86-atomic-long_double.c | 609 +- 3 files changed, 410 insertions(+), 309 deletions(-) create mode 100644 clang/test/CodeGen/X86/x86-atomic-float.c diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index 1f18e0d5ba409a..e97bb5c7e9dd16 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -2792,6 +2792,19 @@ ScalarExprEmitter::EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV, llvm::AtomicOrdering::SequentiallyConsistent); return isPre ? Builder.CreateBinOp(op, old, amt) : old; } +// Special case for atomic increment/decrement on floats +if (type->isFloatingType()) { + llvm::AtomicRMWInst::BinOp aop = + isInc ? llvm::AtomicRMWInst::FAdd : llvm::AtomicRMWInst::FSub; + llvm::Instruction::BinaryOps op = + isInc ? llvm::Instruction::FAdd : llvm::Instruction::FSub; + llvm::Value *amt = llvm::ConstantFP::get( + VMContext, llvm::APFloat(static_cast(amount))); + llvm::Value *old = + Builder.CreateAtomicRMW(aop, LV.getAddress(CGF), amt, + llvm::AtomicOrdering::SequentiallyConsistent); + return isPre ? Builder.CreateBinOp(op, old, amt) : old; +} value = EmitLoadOfLValue(LV, E->getExprLoc()); input = value; // For every other atomic operation, we need to emit a load-op-cmpxchg loop diff --git a/clang/test/CodeGen/X86/x86-atomic-float.c b/clang/test/CodeGen/X86/x86-atomic-float.c new file mode 100644 index 00..89a2605ed44461 --- /dev/null +++ b/clang/test/CodeGen/X86/x86-atomic-float.c @@ -0,0 +1,97 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4 +// RUN: %clang_cc1 -triple x86_64-linux-gnu -target-cpu core2 %s -S -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -triple i686-linux-gnu -target-cpu core2 %s -S -emit-llvm -o - | FileCheck -check-prefix=CHECK32 %s + +// CHECK-LABEL: define dso_local i32 @test_int_inc( +// CHECK-SAME: ) #[[ATTR0:[0-9]+]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[TMP0:%.*]] = atomicrmw add ptr @test_int_inc.n, i32 1 seq_cst, align 4 +// CHECK-NEXT:ret i32 [[TMP0]] +// +// CHECK32-LABEL: define dso_local i32 @test_int_inc( +// CHECK32-SAME: ) #[[ATTR0:[0-9]+]] { +// CHECK32-NEXT: entry: +// CHECK32-NEXT:[[TMP0:%.*]] = atomicrmw add ptr @test_int_inc.n, i32 1 seq_cst, align 4 +// CHECK32-NEXT:ret i32 [[TMP0]] +// +int test_int_inc() +{ +static _Atomic int n; +return n++; +} + +// CHECK-LABEL: define dso_local float @test_float_post_inc( +// CHECK-SAME: ) #[[ATTR0]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[TMP0:%.*]] = atomicrmw fadd ptr @test_float_post_inc.n, float 1.00e+00 seq_cst, align 4 +// CHECK-NEXT:ret float [[TMP0]] +// +// CHECK32-LABEL: define dso_local float @test_float_post_inc( +// CHECK32-SAME: ) #[[ATTR0]] { +// CHECK32-NEXT: entry: +// CHECK32-NEXT:[[TMP0:%.*]] = atomicrmw fadd ptr @test_float_post_inc.n, float 1.00e+00 seq_cst, align 4 +// CHECK32-NEXT:ret float [[TMP0]] +// +float test_float_post_inc() +{ +static _Atomic float n; +return n++; +} + +// CHECK-LABEL: define dso_local float @test_float_post_dc( +// CHECK-SAME: ) #[[ATTR0]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[TMP0:%.*]] = atomicrmw fsub ptr @test_float_post_dc.n, float -1.00e+00 seq_cst, align 4 +// CHECK-NEXT:ret float [[TMP0]] +// +// CHECK32-LABEL: define dso_local float @test_float_post_dc( +// CHECK32-SAME: ) #[[ATTR0]] { +// CHECK32-NEXT: entry: +// CHECK32-NEXT:[[TMP0:%.*]] = atomicrmw fsub ptr @test_float_post_dc.n, float -1.00e+00 seq_cst, align 4 +// CHECK32-NEXT:ret float [[TMP0]] +// +float test_float_post_dc() +{ +static _Atomic float n; +return n--; +} + +// CHECK-LABEL: define dso_local float @test_float_pre_dc( +// CHECK-SAME: ) #[[ATTR0]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[TMP0:%.*]] = atomicrmw fsub ptr @test_float_pre_dc.n, float -1.00e+00 seq_cst, align 4 +// CHECK-NEXT:[[TMP1:%.*]] = fsub float [[TMP0]], -1.00e+00 +// CHECK-NEXT:ret float [[TMP1]] +// +// CHECK32-LABEL: define dso_local float @test_float_pre_dc( +// CHECK32-SAME: ) #[[ATTR0]] { +// CHECK32-NEXT: entry: +// CHECK32-NEXT:[[TMP0:%.*]] = atomicrmw fsub ptr @test_float_pre_dc.n, float -1.00e+00 seq_cst, align 4 +// CHECK32-NEXT:[[TMP1:%.*]] = fsub float [[TMP0]], -1.00e+00 +// CHECK32-NEXT:
[clang] [Clang][CodeGen] Optimised LLVM IR for atomic increments/decrements on floats (PR #89362)
@@ -0,0 +1,64 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4 +// RUN: %clang_cc1 -triple x86_64-linux-gnu -target-cpu core2 %s -S -emit-llvm -o - | FileCheck %s Krishna-13-cyber wrote: Yes I added the test, I misinterpreted the earlier review. Thanks! https://github.com/llvm/llvm-project/pull/89362 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][CodeGen] Optimised LLVM IR for atomic increments/decrements on floats (PR #89362)
Krishna-13-cyber wrote: Hi @RKSimon, any more changes required for this!? https://github.com/llvm/llvm-project/pull/89362 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][CodeGen] Optimised LLVM IR for atomic increments/decrements on floats (PR #89362)
https://github.com/Krishna-13-cyber updated https://github.com/llvm/llvm-project/pull/89362 >From 4e649d105a2af038e6dbd0e93b457eebea2e543a Mon Sep 17 00:00:00 2001 From: Krishna-13-cyber Date: Fri, 19 Apr 2024 15:09:26 +0530 Subject: [PATCH 1/4] Add optimised LLVM IR for atomic increments/decrements on floats --- clang/lib/CodeGen/CGExprScalar.cpp| 13 + clang/test/CodeGen/X86/x86-atomic-float.c | 97 +++ .../test/CodeGen/X86/x86-atomic-long_double.c | 609 +- 3 files changed, 410 insertions(+), 309 deletions(-) create mode 100644 clang/test/CodeGen/X86/x86-atomic-float.c diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index 1f18e0d5ba409a..e97bb5c7e9dd16 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -2792,6 +2792,19 @@ ScalarExprEmitter::EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV, llvm::AtomicOrdering::SequentiallyConsistent); return isPre ? Builder.CreateBinOp(op, old, amt) : old; } +// Special case for atomic increment/decrement on floats +if (type->isFloatingType()) { + llvm::AtomicRMWInst::BinOp aop = + isInc ? llvm::AtomicRMWInst::FAdd : llvm::AtomicRMWInst::FSub; + llvm::Instruction::BinaryOps op = + isInc ? llvm::Instruction::FAdd : llvm::Instruction::FSub; + llvm::Value *amt = llvm::ConstantFP::get( + VMContext, llvm::APFloat(static_cast(amount))); + llvm::Value *old = + Builder.CreateAtomicRMW(aop, LV.getAddress(CGF), amt, + llvm::AtomicOrdering::SequentiallyConsistent); + return isPre ? Builder.CreateBinOp(op, old, amt) : old; +} value = EmitLoadOfLValue(LV, E->getExprLoc()); input = value; // For every other atomic operation, we need to emit a load-op-cmpxchg loop diff --git a/clang/test/CodeGen/X86/x86-atomic-float.c b/clang/test/CodeGen/X86/x86-atomic-float.c new file mode 100644 index 00..89a2605ed44461 --- /dev/null +++ b/clang/test/CodeGen/X86/x86-atomic-float.c @@ -0,0 +1,97 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4 +// RUN: %clang_cc1 -triple x86_64-linux-gnu -target-cpu core2 %s -S -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -triple i686-linux-gnu -target-cpu core2 %s -S -emit-llvm -o - | FileCheck -check-prefix=CHECK32 %s + +// CHECK-LABEL: define dso_local i32 @test_int_inc( +// CHECK-SAME: ) #[[ATTR0:[0-9]+]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[TMP0:%.*]] = atomicrmw add ptr @test_int_inc.n, i32 1 seq_cst, align 4 +// CHECK-NEXT:ret i32 [[TMP0]] +// +// CHECK32-LABEL: define dso_local i32 @test_int_inc( +// CHECK32-SAME: ) #[[ATTR0:[0-9]+]] { +// CHECK32-NEXT: entry: +// CHECK32-NEXT:[[TMP0:%.*]] = atomicrmw add ptr @test_int_inc.n, i32 1 seq_cst, align 4 +// CHECK32-NEXT:ret i32 [[TMP0]] +// +int test_int_inc() +{ +static _Atomic int n; +return n++; +} + +// CHECK-LABEL: define dso_local float @test_float_post_inc( +// CHECK-SAME: ) #[[ATTR0]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[TMP0:%.*]] = atomicrmw fadd ptr @test_float_post_inc.n, float 1.00e+00 seq_cst, align 4 +// CHECK-NEXT:ret float [[TMP0]] +// +// CHECK32-LABEL: define dso_local float @test_float_post_inc( +// CHECK32-SAME: ) #[[ATTR0]] { +// CHECK32-NEXT: entry: +// CHECK32-NEXT:[[TMP0:%.*]] = atomicrmw fadd ptr @test_float_post_inc.n, float 1.00e+00 seq_cst, align 4 +// CHECK32-NEXT:ret float [[TMP0]] +// +float test_float_post_inc() +{ +static _Atomic float n; +return n++; +} + +// CHECK-LABEL: define dso_local float @test_float_post_dc( +// CHECK-SAME: ) #[[ATTR0]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[TMP0:%.*]] = atomicrmw fsub ptr @test_float_post_dc.n, float -1.00e+00 seq_cst, align 4 +// CHECK-NEXT:ret float [[TMP0]] +// +// CHECK32-LABEL: define dso_local float @test_float_post_dc( +// CHECK32-SAME: ) #[[ATTR0]] { +// CHECK32-NEXT: entry: +// CHECK32-NEXT:[[TMP0:%.*]] = atomicrmw fsub ptr @test_float_post_dc.n, float -1.00e+00 seq_cst, align 4 +// CHECK32-NEXT:ret float [[TMP0]] +// +float test_float_post_dc() +{ +static _Atomic float n; +return n--; +} + +// CHECK-LABEL: define dso_local float @test_float_pre_dc( +// CHECK-SAME: ) #[[ATTR0]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[TMP0:%.*]] = atomicrmw fsub ptr @test_float_pre_dc.n, float -1.00e+00 seq_cst, align 4 +// CHECK-NEXT:[[TMP1:%.*]] = fsub float [[TMP0]], -1.00e+00 +// CHECK-NEXT:ret float [[TMP1]] +// +// CHECK32-LABEL: define dso_local float @test_float_pre_dc( +// CHECK32-SAME: ) #[[ATTR0]] { +// CHECK32-NEXT: entry: +// CHECK32-NEXT:[[TMP0:%.*]] = atomicrmw fsub ptr @test_float_pre_dc.n, float -1.00e+00 seq_cst, align 4 +// CHECK32-NEXT:[[TMP1:%.*]] = fsub float [[TMP0]], -1.00e+00 +// CHECK32-NEXT:
[clang] [Clang][CodeGen] Optimised LLVM IR for atomic increments/decrements on floats (PR #89362)
Krishna-13-cyber wrote: > LGTM Thanks! https://github.com/llvm/llvm-project/pull/89362 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits