Skip to content

Commit c2bd9c1

Browse files
[AIE2P] Extend allocation filter to include only Target MIs
Now we filter by register class and usage. Basically, we exclude here instructions like copies and non-2D/3D ones. Co-Authored-By: Krishnam Tibrewala <[email protected]>
1 parent 5ad2da7 commit c2bd9c1

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

llvm/lib/Target/AIE/AIEBaseTargetMachine.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ cl::opt<bool>
9393
EnableStagedRA("aie-staged-ra", cl::Hidden, cl::init(true),
9494
cl::desc("Enable multi-stage register allocation"));
9595

96+
cl::opt<bool> EnableFineGrainedStagedRA(
97+
"aie-staged-ra-fine-grained-alloc", cl::Hidden, cl::init(true),
98+
cl::desc("Enable multi-stage register allocation with fine-grained "
99+
"selection of live intervals"));
100+
96101
cl::opt<bool>
97102
EnableWAWRegRewrite("aie-wawreg-rewrite",
98103
cl::desc("Enable the WAW Register Renaming in loops"),

llvm/lib/Target/AIE/aie2p/AIE2PTargetMachine.cpp

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
7-
// (c) Copyright 2024 Advanced Micro Devices, Inc. or its affiliates
7+
// (c) Copyright 2024-2025 Advanced Micro Devices, Inc. or its affiliates
88
//
99
//===----------------------------------------------------------------------===//
1010
//
@@ -15,6 +15,7 @@
1515
#include "AIE2PTargetMachine.h"
1616
#include "AIE2PTargetTransformInfo.h"
1717
#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
18+
#include "llvm/CodeGen/TargetRegisterInfo.h"
1819

1920
using namespace llvm;
2021
extern cl::opt<bool> EnableStagedRA;
@@ -25,6 +26,7 @@ extern cl::opt<bool> EnableAddressChaining;
2526
extern cl::opt<bool> EnableGlobalPtrModOptimizer;
2627
extern cl::opt<bool> EnableWAWRegRewrite;
2728
extern cl::opt<bool> EnableAIEIfConversion;
29+
extern cl::opt<bool> EnableFineGrainedStagedRA;
2830

2931
void AIE2PTargetMachine::anchor() {}
3032

@@ -70,17 +72,44 @@ void AIE2PPassConfig::addPreRegBankSelect() {
7072
}
7173
}
7274

75+
static bool isRegUsedBy2DOr3DInstruction(const MachineRegisterInfo &MRI,
76+
const Register &R) {
77+
78+
return std::any_of(
79+
MRI.use_nodbg_instructions(R).begin(),
80+
MRI.use_nodbg_instructions(R).end(), [&](const MachineInstr &MI) {
81+
auto &TII = *static_cast<const AIEBaseInstrInfo *>(
82+
MI.getMF()->getSubtarget().getInstrInfo());
83+
84+
// We should recognize both cases, with and without splitting. A 2D/3D
85+
// instruction will always be split os splittable.
86+
return TII.getOpcodeWithTupleOperands(MI.getOpcode()).has_value() ||
87+
TII.getOpcodeWithAtomicOperands(MI.getOpcode()).has_value();
88+
});
89+
}
90+
7391
static bool onlyAllocate3DRegisters(const TargetRegisterInfo &TRI,
7492
const MachineRegisterInfo &MRI,
7593
const Register &R) {
76-
return AIE2P::eDSRegClass.hasSubClassEq(MRI.getRegClass(R));
94+
95+
const TargetRegisterClass *RegClass = MRI.getRegClass(R);
96+
if (!AIE2P::eDSRegClass.hasSubClassEq(RegClass))
97+
return false;
98+
return EnableFineGrainedStagedRA ? isRegUsedBy2DOr3DInstruction(MRI, R)
99+
: true;
77100
}
101+
78102
static bool onlyAllocate3D2DRegisters(const TargetRegisterInfo &TRI,
79103
const MachineRegisterInfo &MRI,
80104
const Register &R) {
81-
return AIE2P::eDSRegClass.hasSubClassEq(MRI.getRegClass(R)) ||
82-
AIE2P::eDRegClass.hasSubClassEq(MRI.getRegClass(R));
105+
const TargetRegisterClass *RegClass = MRI.getRegClass(R);
106+
if (!AIE2P::eDSRegClass.hasSubClassEq(RegClass) &&
107+
!AIE2P::eDRegClass.hasSubClassEq(RegClass))
108+
return false;
109+
return EnableFineGrainedStagedRA ? isRegUsedBy2DOr3DInstruction(MRI, R)
110+
: true;
83111
}
112+
84113
static bool onlyAllocateMRegisters(const TargetRegisterInfo &TRI,
85114
const MachineRegisterInfo &MRI,
86115
const Register &R) {

0 commit comments

Comments
 (0)