Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --relax-float-ops and --convert-relaxed-to-half #2808

Merged
merged 1 commit into from
Sep 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ SPVTOOLS_OPT_SRC_FILES := \
source/opt/composite.cpp \
source/opt/const_folding_rules.cpp \
source/opt/constants.cpp \
source/opt/convert_to_half_pass.cpp \
source/opt/copy_prop_arrays.cpp \
source/opt/dead_branch_elim_pass.cpp \
source/opt/dead_insert_elim_pass.cpp \
Expand Down Expand Up @@ -153,6 +154,7 @@ SPVTOOLS_OPT_SRC_FILES := \
source/opt/reduce_load_size.cpp \
source/opt/redundancy_elimination.cpp \
source/opt/register_pressure.cpp \
source/opt/relax_float_ops_pass.cpp \
source/opt/remove_duplicates_pass.cpp \
source/opt/replace_invalid_opc.cpp \
source/opt/scalar_analysis.cpp \
Expand Down
4 changes: 4 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,8 @@ static_library("spvtools_opt") {
"source/opt/const_folding_rules.h",
"source/opt/constants.cpp",
"source/opt/constants.h",
"source/opt/convert_to_half_pass.cpp",
"source/opt/convert_to_half_pass.h",
"source/opt/copy_prop_arrays.cpp",
"source/opt/copy_prop_arrays.h",
"source/opt/dead_branch_elim_pass.cpp",
Expand Down Expand Up @@ -611,6 +613,8 @@ static_library("spvtools_opt") {
"source/opt/reflect.h",
"source/opt/register_pressure.cpp",
"source/opt/register_pressure.h",
"source/opt/relax_float_ops_pass.cpp",
"source/opt/relax_float_ops_pass.h",
"source/opt/remove_duplicates_pass.cpp",
"source/opt/remove_duplicates_pass.h",
"source/opt/replace_invalid_opc.cpp",
Expand Down
16 changes: 16 additions & 0 deletions include/spirv-tools/optimizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,22 @@ Optimizer::PassToken CreateLoopUnrollPass(bool fully_unroll, int factor = 0);
// processed (see IsSSATargetVar for details).
Optimizer::PassToken CreateSSARewritePass();

// Create pass to convert relaxed precision instructions to half precision.
// This pass converts as many relaxed float32 arithmetic operations to half as
// possible. It converts any float32 operands to half if needed. It converts
// any resulting half precision values back to float32 as needed. No variables
// are changed. No image operations are changed.
//
// Best if run late since it will generate better code with unneeded function
// scope loads and stores and composite inserts and extracts removed. Also best
// if followed by instruction simplification, redundancy elimination and DCE.
Optimizer::PassToken CreateConvertRelaxedToHalfPass();

// Create relax float ops pass.
// This pass decorates all float32 result instructions with RelaxedPrecision
// if not already so decorated.
Optimizer::PassToken CreateRelaxFloatOpsPass();

// Create copy propagate arrays pass.
// This pass looks to copy propagate memory references for arrays. It looks
// for specific code patterns to recognize array copies.
Expand Down
4 changes: 4 additions & 0 deletions source/opt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ set(SPIRV_TOOLS_OPT_SOURCES
composite.h
const_folding_rules.h
constants.h
convert_to_half_pass.h
copy_prop_arrays.h
dead_branch_elim_pass.h
dead_insert_elim_pass.h
Expand Down Expand Up @@ -93,6 +94,7 @@ set(SPIRV_TOOLS_OPT_SOURCES
redundancy_elimination.h
reflect.h
register_pressure.h
relax_float_ops_pass.h
remove_duplicates_pass.h
replace_invalid_opc.h
scalar_analysis.h
Expand Down Expand Up @@ -132,6 +134,7 @@ set(SPIRV_TOOLS_OPT_SOURCES
composite.cpp
const_folding_rules.cpp
constants.cpp
convert_to_half_pass.cpp
copy_prop_arrays.cpp
dead_branch_elim_pass.cpp
dead_insert_elim_pass.cpp
Expand Down Expand Up @@ -196,6 +199,7 @@ set(SPIRV_TOOLS_OPT_SOURCES
reduce_load_size.cpp
redundancy_elimination.cpp
register_pressure.cpp
relax_float_ops_pass.cpp
remove_duplicates_pass.cpp
replace_invalid_opc.cpp
scalar_analysis.cpp
Expand Down
Loading