Skip to content

Commit a502108

Browse files
committed
Change to builder callback
1 parent d5e295e commit a502108

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

llvm/include/llvm/Passes/CodeGenPassBuilder.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -507,12 +507,14 @@ template <typename DerivedT, typename TargetMachineT> class CodeGenPassBuilder {
507507
/// regalloc pass.
508508
void addRegAllocPass(AddMachinePass &, bool Optimized) const;
509509
/// Read the --regalloc-npm option to add the next pass in line.
510+
/// Returns false if no pass is left in the option.
510511
bool addRegAllocPassFromOpt(AddMachinePass &,
511512
StringRef MatchPassTo = StringRef{}) const;
512-
/// Add the next pass in the cli option, or return false if there is no pass
513+
/// Add the next pass in the cli option or the pass specified if no pass is
513514
/// left in the option.
514-
template <typename RegAllocPassT>
515-
void addRegAllocPassOrOpt(AddMachinePass &, RegAllocPassT Pass) const;
515+
template <typename RegAllocPassBuilderT>
516+
void addRegAllocPassOrOpt(AddMachinePass &,
517+
RegAllocPassBuilderT PassBuilder) const;
516518

517519
/// Add core register alloator passes which do the actual register assignment
518520
/// and rewriting. \returns true if any passes were added.
@@ -1112,11 +1114,11 @@ void CodeGenPassBuilder<Derived, TargetMachineT>::addTargetRegisterAllocator(
11121114
}
11131115

11141116
template <typename Derived, typename TargetMachineT>
1115-
template <typename RegAllocPassT>
1117+
template <typename RegAllocPassBuilderT>
11161118
void CodeGenPassBuilder<Derived, TargetMachineT>::addRegAllocPassOrOpt(
1117-
AddMachinePass &addPass, RegAllocPassT Pass) const {
1119+
AddMachinePass &addPass, RegAllocPassBuilderT PassBuilder) const {
11181120
if (!addRegAllocPassFromOpt(addPass))
1119-
addPass(std::move(Pass));
1121+
addPass(std::move(PassBuilder()));
11201122
}
11211123

11221124
template <typename Derived, typename TargetMachineT>

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,7 +2210,8 @@ Error AMDGPUCodeGenPassBuilder::addRegAssignmentOptimized(
22102210
AddMachinePass &addPass) const {
22112211
addPass(GCNPreRALongBranchRegPass());
22122212

2213-
addRegAllocPassOrOpt(addPass, RAGreedyPass({onlyAllocateSGPRs, "sgpr"}));
2213+
addRegAllocPassOrOpt(
2214+
addPass, []() { return RAGreedyPass({onlyAllocateSGPRs, "sgpr"}); });
22142215

22152216
// Commit allocated register changes. This is mostly necessary because too
22162217
// many things rely on the use lists of the physical registers, such as the
@@ -2230,13 +2231,15 @@ Error AMDGPUCodeGenPassBuilder::addRegAssignmentOptimized(
22302231
addPass(SIPreAllocateWWMRegsPass());
22312232

22322233
// For allocating other wwm register operands.
2233-
addRegAllocPassOrOpt(addPass, RAGreedyPass({onlyAllocateWWMRegs, "wwm"}));
2234+
addRegAllocPassOrOpt(
2235+
addPass, []() { return RAGreedyPass({onlyAllocateWWMRegs, "wwm"}); });
22342236
addPass(SILowerWWMCopiesPass());
22352237
addPass(VirtRegRewriterPass(false));
22362238
addPass(AMDGPUReserveWWMRegsPass());
22372239

22382240
// For allocating per-thread VGPRs.
2239-
addRegAllocPassOrOpt(addPass, RAGreedyPass({onlyAllocateVGPRs, "vgpr"}));
2241+
addRegAllocPassOrOpt(
2242+
addPass, []() { return RAGreedyPass({onlyAllocateVGPRs, "vgpr"}); });
22402243

22412244
// TODO: addPreRewrite();
22422245
addPass(VirtRegRewriterPass(false));

llvm/lib/Target/X86/X86CodeGenPassBuilder.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ class X86CodeGenPassBuilder
3939
Error X86CodeGenPassBuilder::addRegAssignmentOptimized(
4040
AddMachinePass &addPass) const {
4141
if (EnableTileRAPass) {
42-
addRegAllocPassOrOpt(addPass,
43-
RAGreedyPass({onlyAllocateTileRegisters, "tile-reg"}));
42+
addRegAllocPassOrOpt(addPass, []() {
43+
return RAGreedyPass({onlyAllocateTileRegisters, "tile-reg"});
44+
});
4445
// TODO: addPass(X86TileConfigPass());
4546
}
4647
return Base::addRegAssignmentOptimized(addPass);

0 commit comments

Comments
 (0)