Skip to content

Commit

Permalink
[compiler] Remove the RemoveFencesPass
Browse files Browse the repository at this point in the history
This pass was originally introduced back in LLVM 7 to account for the
fact that some of our targets couldn't handle the newly added `fence`
instruction. Removing them bypassed the issue.

While it is not semantically correct to remove fence instructions from
LLVM IR in general, we were relying on the fact that the memory model is
under-specified in OpenCL 1.2 and so could assume that fences were
redundant.

The ENORMOUS WARNING above this scheduling of this pass should be reason
enough not to run it. It has not been necessary for several LLVM
versions - it is claimed it is only in the host pipeline to ensure it's
tested. This is not a good enough reason to keep a dodgy unnecessary
pass.

There aren't enough good reasons to keep it around unused in the
codebase (the pass is trivial to implement by a downstream target if
they did require it) so this commit removes the pass.
  • Loading branch information
frasercrmck committed Jan 2, 2024
1 parent 2d186ab commit 5ba3c05
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 107 deletions.
7 changes: 0 additions & 7 deletions doc/modules/compiler/utils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1139,13 +1139,6 @@ Removing this information is useful for debugging since the backend is less
likely to optimize away variables in the stack no longer used, as a result this
pass should only be run on debug builds of the module.

RemoveFencesPass
----------------

Removing memory fences can result in invalid code or incorrect behaviour in
general. This pass is a workaround for backends that do not yet support memory
fences.

RemoveExceptionsPass
--------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
#include <compiler/utils/prepare_barriers_pass.h>
#include <compiler/utils/reduce_to_function_pass.h>
#include <compiler/utils/remove_exceptions_pass.h>
#include <compiler/utils/remove_fences_pass.h>
#include <compiler/utils/remove_lifetime_intrinsics_pass.h>
#include <compiler/utils/rename_builtins_pass.h>
#include <compiler/utils/replace_address_space_qualifier_functions_pass.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ FUNCTION_PASS("software-div", compiler::SoftwareDivisionPass())
FUNCTION_PASS("replace-addrspace-fns", compiler::utils::ReplaceAddressSpaceQualifierFunctionsPass())
FUNCTION_PASS("remove-lifetime", compiler::utils::RemoveLifetimeIntrinsicsPass())
FUNCTION_PASS("remove-exceptions", compiler::utils::RemoveExceptionsPass())
FUNCTION_PASS("remove-fences", compiler::utils::RemoveFencesPass())
FUNCTION_PASS("replace-mem-intrins", compiler::utils::ReplaceMemIntrinsicsPass())
FUNCTION_PASS("print<generic-metadata>", compiler::utils::GenericMetadataPrinterPass(llvm::dbgs()))
FUNCTION_PASS("print<vectorize-metadata>", compiler::utils::VectorizeMetadataPrinterPass(llvm::dbgs()))
Expand Down
15 changes: 0 additions & 15 deletions modules/compiler/targets/host/source/HostPassMachinery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include <compiler/utils/metadata_analysis.h>
#include <compiler/utils/pipeline_parse_helpers.h>
#include <compiler/utils/remove_exceptions_pass.h>
#include <compiler/utils/remove_fences_pass.h>
#include <compiler/utils/remove_lifetime_intrinsics_pass.h>
#include <compiler/utils/replace_address_space_qualifier_functions_pass.h>
#include <compiler/utils/replace_local_module_scope_variables_pass.h>
Expand Down Expand Up @@ -311,20 +310,6 @@ llvm::ModulePassManager HostPassMachinery::getKernelFinalizationPasses(
compiler::utils::RemoveLifetimeIntrinsicsPass()));
}

// ENORMOUS WARNING:
// Removing memory fences can result in invalid code or incorrect behaviour in
// general. This pass is a workaround for backends that do not yet support
// memory fences. This is not required for any of the LLVM backends used by
// host, but the pass is used here to ensure that it is tested.
// The memory model on OpenCL 1.2 is so underspecified that we can get away
// with removing fences. In OpenCL 3.0 the memory model is better defined, and
// just removing fences could result in incorrect behavior for valid 3.0
// OpenCL applications.
if (options.standard != compiler::Standard::OpenCLC30) {
PM.addPass(llvm::createModuleToFunctionPassAdaptor(
compiler::utils::RemoveFencesPass()));
}

PM.addPass(compiler::utils::ComputeLocalMemoryUsagePass());

PM.addPass(compiler::utils::AddMetadataPass<
Expand Down
2 changes: 0 additions & 2 deletions modules/compiler/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ add_ca_library(compiler-utils STATIC
${CMAKE_CURRENT_SOURCE_DIR}/include/compiler/utils/prepare_barriers_pass.h
${CMAKE_CURRENT_SOURCE_DIR}/include/compiler/utils/reduce_to_function_pass.h
${CMAKE_CURRENT_SOURCE_DIR}/include/compiler/utils/remove_exceptions_pass.h
${CMAKE_CURRENT_SOURCE_DIR}/include/compiler/utils/remove_fences_pass.h
${CMAKE_CURRENT_SOURCE_DIR}/include/compiler/utils/remove_lifetime_intrinsics_pass.h
${CMAKE_CURRENT_SOURCE_DIR}/include/compiler/utils/rename_builtins_pass.h
${CMAKE_CURRENT_SOURCE_DIR}/include/compiler/utils/replace_address_space_qualifier_functions_pass.h
Expand Down Expand Up @@ -104,7 +103,6 @@ add_ca_library(compiler-utils STATIC
${CMAKE_CURRENT_SOURCE_DIR}/source/prepare_barriers_pass.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source/reduce_to_function_pass.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source/remove_exceptions_pass.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source/remove_fences_pass.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source/remove_lifetime_intrinsics_pass.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source/rename_builtins_pass.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source/replace_address_space_qualifier_functions_pass.cpp
Expand Down
44 changes: 0 additions & 44 deletions modules/compiler/utils/include/compiler/utils/remove_fences_pass.h

This file was deleted.

37 changes: 0 additions & 37 deletions modules/compiler/utils/source/remove_fences_pass.cpp

This file was deleted.

0 comments on commit 5ba3c05

Please sign in to comment.