Skip to content

[X86] Avoid repeated hash lookups (NFC) #130710

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
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
35 changes: 19 additions & 16 deletions llvm/lib/Target/X86/X86PreTileConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,29 +293,30 @@ bool X86PreTileConfig::runOnMachineFunction(MachineFunction &MF) {
SmallVector<MachineBasicBlock *, 8> CfgLiveInBBs;
for (auto &MBB : MF) {
size_t Pos = 0;
auto &Info = BBVisitedInfo[&MBB];
for (auto &MI : MBB) {
++Pos;
if (isAMXInstruction(MI)) {
// If there's call before the AMX, we need to reload tile config.
if (BBVisitedInfo[&MBB].LastCall)
CfgNeedInsert.insert(BBVisitedInfo[&MBB].LastCall);
if (Info.LastCall)
CfgNeedInsert.insert(Info.LastCall);
else // Otherwise, we need tile config to live in this BB.
BBVisitedInfo[&MBB].NeedTileCfgLiveIn = true;
Info.NeedTileCfgLiveIn = true;
// Always record the first AMX in case there's shape def after it.
if (!BBVisitedInfo[&MBB].FirstAMX)
BBVisitedInfo[&MBB].FirstAMX = MIRef(&MI, &MBB, Pos);
if (!Info.FirstAMX)
Info.FirstAMX = MIRef(&MI, &MBB, Pos);
} else if (MI.isCall() && isDestructiveCall(MI, AMXRegs)) {
// Record the call only if the callee clobbers all AMX registers.
BBVisitedInfo[&MBB].LastCall = MIRef(&MI, &MBB, Pos);
Info.LastCall = MIRef(&MI, &MBB, Pos);
}
}
if (BBVisitedInfo[&MBB].NeedTileCfgLiveIn) {
if (Info.NeedTileCfgLiveIn) {
if (&MBB == &MF.front())
CfgNeedInsert.insert(MIRef(&MBB));
else
CfgLiveInBBs.push_back(&MBB);
}
if (BBVisitedInfo[&MBB].FirstAMX || BBVisitedInfo[&MBB].HasAMXRegLiveIn)
if (Info.FirstAMX || Info.HasAMXRegLiveIn)
for (auto *Succ : MBB.successors())
if (!isLoopBackEdge(Succ, &MBB))
BBVisitedInfo[Succ].HasAMXRegLiveIn = true;
Expand All @@ -325,10 +326,11 @@ bool X86PreTileConfig::runOnMachineFunction(MachineFunction &MF) {
while (!CfgLiveInBBs.empty()) {
MachineBasicBlock *MBB = CfgLiveInBBs.pop_back_val();
for (auto *Pred : MBB->predecessors()) {
auto &Info = BBVisitedInfo[Pred];
if (BBVisitedInfo[Pred].LastCall) {
CfgNeedInsert.insert(BBVisitedInfo[Pred].LastCall);
} else if (!BBVisitedInfo[Pred].NeedTileCfgLiveIn) {
BBVisitedInfo[Pred].NeedTileCfgLiveIn = true;
CfgNeedInsert.insert(Info.LastCall);
} else if (!Info.NeedTileCfgLiveIn) {
Info.NeedTileCfgLiveIn = true;
if (Pred == &MF.front())
CfgNeedInsert.insert(MIRef(Pred));
else
Expand All @@ -344,16 +346,16 @@ bool X86PreTileConfig::runOnMachineFunction(MachineFunction &MF) {
// Avoid to insert ldtilecfg before any shape defs.
SmallVector<MachineBasicBlock *, 8> WorkList;
for (auto &I : ShapeBBs) {
auto &Info = BBVisitedInfo[I.first];
// TODO: We can hoist shapes across BBs here.
if (BBVisitedInfo[I.first].HasAMXRegLiveIn) {
if (Info.HasAMXRegLiveIn) {
// We are not able to config tile registers since the shape to config
// is not defined yet. Emit error message and continue. The function
// would not config tile registers.
emitErrorMsg(MF);
return false;
}
if (BBVisitedInfo[I.first].FirstAMX &&
BBVisitedInfo[I.first].FirstAMX < I.second.back() &&
if (Info.FirstAMX && Info.FirstAMX < I.second.back() &&
!hoistShapesInBB(I.first, I.second)) {
emitErrorMsg(MF);
return false;
Expand All @@ -363,8 +365,9 @@ bool X86PreTileConfig::runOnMachineFunction(MachineFunction &MF) {
while (!WorkList.empty()) {
MachineBasicBlock *MBB = WorkList.pop_back_val();
for (auto *Pred : MBB->predecessors()) {
if (!BBVisitedInfo[Pred].TileCfgForbidden && !isLoopBackEdge(MBB, Pred)) {
BBVisitedInfo[Pred].TileCfgForbidden = true;
auto &Info = BBVisitedInfo[Pred];
if (!Info.TileCfgForbidden && !isLoopBackEdge(MBB, Pred)) {
Info.TileCfgForbidden = true;
WorkList.push_back(Pred);
}
}
Expand Down