Skip to content

[CodeGen] Port GCLowering to new pass manager #75305

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

Merged
merged 1 commit into from
Jan 9, 2024
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
1 change: 1 addition & 0 deletions llvm/include/llvm/CodeGen/CodeGenPassBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ Error CodeGenPassBuilder<Derived>::buildPipeline(
AddIRPass addIRPass(MPM, Opt.DebugPM);
// `ProfileSummaryInfo` is always valid.
addIRPass(RequireAnalysisPass<ProfileSummaryAnalysis, Module>());
addIRPass(RequireAnalysisPass<CollectorMetadataAnalysis, Module>());
addISelPasses(addIRPass);

AddMachinePass addPass(MFPM);
Expand Down
11 changes: 11 additions & 0 deletions llvm/include/llvm/CodeGen/GCMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,17 @@ class GCFunctionAnalysis : public AnalysisInfoMixin<GCFunctionAnalysis> {
Result run(Function &F, FunctionAnalysisManager &FAM);
};

/// LowerIntrinsics - This pass rewrites calls to the llvm.gcread or
/// llvm.gcwrite intrinsics, replacing them with simple loads and stores as
/// directed by the GCStrategy. It also performs automatic root initialization
/// and custom intrinsic lowering.
///
/// This pass requires `CollectorMetadataAnalysis`.
class GCLoweringPass : public PassInfoMixin<GCLoweringPass> {
public:
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
};

/// An analysis pass which caches information about the entire Module.
/// Records both the function level information used by GCRoots and a
/// cache of the 'active' gc strategy objects for the current Module.
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/MachinePassRegistry.def
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ FUNCTION_PASS("expand-large-fp-convert", ExpandLargeFpConvertPass, (TM))
FUNCTION_PASS("expand-memcmp", ExpandMemCmpPass, (TM))
FUNCTION_PASS("expand-reductions", ExpandReductionsPass, ())
FUNCTION_PASS("expandvp", ExpandVectorPredicationPass, ())
FUNCTION_PASS("gc-lowering", GCLoweringPass, ())
FUNCTION_PASS("indirectbr-expand", IndirectBrExpandPass, (TM))
FUNCTION_PASS("interleaved-access", InterleavedAccessPass, (TM))
FUNCTION_PASS("interleaved-load-combine", InterleavedLoadCombinePass, (TM))
Expand Down Expand Up @@ -133,7 +134,6 @@ MACHINE_FUNCTION_ANALYSIS("pass-instrumentation", PassInstrumentationAnalysis,
#endif
DUMMY_FUNCTION_PASS("atomic-expand", AtomicExpandPass, ())
DUMMY_FUNCTION_PASS("codegenprepare", CodeGenPreparePass, ())
DUMMY_FUNCTION_PASS("gc-lowering", GCLoweringPass, ())
DUMMY_FUNCTION_PASS("stack-protector", StackProtectorPass, ())
#undef DUMMY_FUNCTION_PASS

Expand Down
33 changes: 23 additions & 10 deletions llvm/lib/CodeGen/GCRootLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,22 @@

using namespace llvm;

/// Lower barriers out of existence (if the associated GCStrategy hasn't
/// already done so...), and insert initializing stores to roots as a defensive
/// measure. Given we're going to report all roots live at all safepoints, we
/// need to be able to ensure each root has been initialized by the point the
/// first safepoint is reached. This really should have been done by the
/// frontend, but the old API made this non-obvious, so we do a potentially
/// redundant store just in case.
static bool DoLowering(Function &F, GCStrategy &S);

namespace {

/// LowerIntrinsics - This pass rewrites calls to the llvm.gcread or
/// llvm.gcwrite intrinsics, replacing them with simple loads and stores as
/// directed by the GCStrategy. It also performs automatic root initialization
/// and custom intrinsic lowering.
class LowerIntrinsics : public FunctionPass {
bool DoLowering(Function &F, GCStrategy &S);

public:
static char ID;

Expand Down Expand Up @@ -72,6 +79,19 @@ class GCMachineCodeAnalysis : public MachineFunctionPass {
};
}

PreservedAnalyses GCLoweringPass::run(Function &F,
FunctionAnalysisManager &FAM) {
auto &Info = FAM.getResult<GCFunctionAnalysis>(F);

bool Changed = DoLowering(F, Info.getStrategy());

if (!Changed)
return PreservedAnalyses::all();
PreservedAnalyses PA;
PA.preserve<DominatorTreeAnalysis>();
return PA;
}

// -----------------------------------------------------------------------------

INITIALIZE_PASS_BEGIN(LowerIntrinsics, "gc-lowering", "GC Lowering", false,
Expand Down Expand Up @@ -178,14 +198,7 @@ bool LowerIntrinsics::runOnFunction(Function &F) {
return DoLowering(F, S);
}

/// Lower barriers out of existance (if the associated GCStrategy hasn't
/// already done so...), and insert initializing stores to roots as a defensive
/// measure. Given we're going to report all roots live at all safepoints, we
/// need to be able to ensure each root has been initialized by the point the
/// first safepoint is reached. This really should have been done by the
/// frontend, but the old API made this non-obvious, so we do a potentially
/// redundant store just in case.
bool LowerIntrinsics::DoLowering(Function &F, GCStrategy &S) {
bool DoLowering(Function &F, GCStrategy &S) {
SmallVector<AllocaInst *, 32> Roots;

bool MadeChange = false;
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Passes/PassRegistry.def
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ FUNCTION_PASS("expand-memcmp", ExpandMemCmpPass(TM))
FUNCTION_PASS("fix-irreducible", FixIrreduciblePass())
FUNCTION_PASS("flattencfg", FlattenCFGPass())
FUNCTION_PASS("float2int", Float2IntPass())
FUNCTION_PASS("gc-lowering", GCLoweringPass())
FUNCTION_PASS("guard-widening", GuardWideningPass())
FUNCTION_PASS("gvn-hoist", GVNHoistPass())
FUNCTION_PASS("gvn-sink", GVNSinkPass())
Expand Down