Skip to content

Commit

Permalink
Introduce temporary CheerpLowerAtomic pass
Browse files Browse the repository at this point in the history
This pass is meant to remove atomics by invoking the existing LowerAtomicPass only on genericjs functions.
  • Loading branch information
Maqrkk committed Dec 18, 2023
1 parent 3b67315 commit 6be5649
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
6 changes: 3 additions & 3 deletions clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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<PromotePass>()));
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) {
Expand Down
18 changes: 18 additions & 0 deletions llvm/include/llvm/Cheerp/CheerpLowerAtomic.h
Original file line number Diff line number Diff line change
@@ -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<CheerpLowerAtomicPass>
{
public:
llvm::PreservedAnalyses run(llvm::Module& M, llvm::ModuleAnalysisManager& MAM);
static bool isRequired() { return true; }
};

}

#endif
1 change: 1 addition & 0 deletions llvm/lib/CheerpUtils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ add_llvm_component_library(LLVMCheerpUtils
BitCastLowering.cpp
JSStringLiteralLowering.cpp
MemoryInit.cpp
CheerpLowerAtomic.cpp
)

add_dependencies(LLVMCheerpUtils intrinsics_gen)
26 changes: 26 additions & 0 deletions llvm/lib/CheerpUtils/CheerpLowerAtomic.cpp
Original file line number Diff line number Diff line change
@@ -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<FunctionAnalysisManagerModuleProxy>(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();
}

0 comments on commit 6be5649

Please sign in to comment.