diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index b6d114ffc677..b4b2ab17898c 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -28,6 +28,7 @@ #include "llvm/Bitcode/BitcodeWriterPass.h" #include "llvm/Cheerp/NativeRewriter.h" #include "llvm/Cheerp/CFGPasses.h" +#include "llvm/Cheerp/CheerpLowerAtomic.h" #include "llvm/Cheerp/ByValLowering.h" #include "llvm/Cheerp/PassUtility.h" #include "llvm/CodeGen/RegAllocRegistry.h" @@ -87,7 +88,6 @@ #include "llvm/Transforms/Scalar/EarlyCSE.h" #include "llvm/Transforms/Scalar/GVN.h" #include "llvm/Transforms/Scalar/JumpThreading.h" -#include "llvm/Transforms/Scalar/LowerAtomicPass.h" #include "llvm/Transforms/Scalar/LowerMatrixIntrinsics.h" #include "llvm/Transforms/Utils.h" #include "llvm/Transforms/Utils/CanonicalizeAliases.h" @@ -947,8 +947,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline( //We need this to track this in custom constructors for DOM types, such as String::String(const char*) MPM.addPass(createModuleToFunctionPassAdaptor(cheerp::RequiredPassWrapper())); MPM.addPass(createModuleToFunctionPassAdaptor(cheerp::CheerpNativeRewriterPass())); - //Cheerp is single threaded, convert atomic instructions to regular ones - MPM.addPass(createModuleToFunctionPassAdaptor(LowerAtomicPass())); + // This temporary pass will remove atomics from genericjs functions + MPM.addPass(cheerp::CheerpLowerAtomicPass()); }); PB.registerOptimizerLastEPCallback( [](ModulePassManager &MPM, OptimizationLevel Level) { diff --git a/llvm/include/llvm/Cheerp/CheerpLowerAtomic.h b/llvm/include/llvm/Cheerp/CheerpLowerAtomic.h new file mode 100644 index 000000000000..a4b1c98a5ad6 --- /dev/null +++ b/llvm/include/llvm/Cheerp/CheerpLowerAtomic.h @@ -0,0 +1,18 @@ +#ifndef CHEERP_LOWER_ATOMIC_H +#define CHEERP_LOWER_ATOMIC_H + +#include "llvm/IR/PassManager.h" + +namespace cheerp +{ + +class CheerpLowerAtomicPass : public llvm::PassInfoMixin +{ +public: + llvm::PreservedAnalyses run(llvm::Module& M, llvm::ModuleAnalysisManager& MAM); + static bool isRequired() { return true; } +}; + +} + +#endif diff --git a/llvm/lib/CheerpUtils/CMakeLists.txt b/llvm/lib/CheerpUtils/CMakeLists.txt index c7987f9b4da4..74ceb1015ed8 100644 --- a/llvm/lib/CheerpUtils/CMakeLists.txt +++ b/llvm/lib/CheerpUtils/CMakeLists.txt @@ -33,6 +33,7 @@ add_llvm_component_library(LLVMCheerpUtils BitCastLowering.cpp JSStringLiteralLowering.cpp MemoryInit.cpp + CheerpLowerAtomic.cpp ) add_dependencies(LLVMCheerpUtils intrinsics_gen) diff --git a/llvm/lib/CheerpUtils/CheerpLowerAtomic.cpp b/llvm/lib/CheerpUtils/CheerpLowerAtomic.cpp new file mode 100644 index 000000000000..e7d4c5aa330b --- /dev/null +++ b/llvm/lib/CheerpUtils/CheerpLowerAtomic.cpp @@ -0,0 +1,26 @@ +#include "llvm/Cheerp/CheerpLowerAtomic.h" +#include "llvm/Transforms/Scalar/LowerAtomicPass.h" + +using namespace llvm; +using namespace cheerp; +// Module pass that invokes the LLVM LowerAtomicPass on genericjs functions. +PreservedAnalyses CheerpLowerAtomicPass::run(Module& M, ModuleAnalysisManager& MAM) +{ + FunctionAnalysisManager& FAM = MAM.getResult(M).getManager(); + FunctionPassManager FPM; + FPM.addPass(LowerAtomicPass()); + + // Loop over the functions, and only pass genericjs ones to LowerAtomicPass + for (Function& F : M) + { + if (F.isDeclaration()) + continue; + + if (F.getSection() == "asmjs") + continue; + + FPM.run(F, FAM); + } + + return PreservedAnalyses::none(); +}