[llvm] [TableGen][SubtargetEmitter] Early exit from loop in FindWriteResources and FindReadAdvance (PR #92202)
Michael Maitland via llvm-commits
llvm-commits at lists.llvm.org
Wed May 15 10:30:05 PDT 2024
https://github.com/michaelmaitland updated https://github.com/llvm/llvm-project/pull/92202
>From 9235b8d019c754b1a56a55ec157c10d522f7c2b1 Mon Sep 17 00:00:00 2001
From: Michael Maitland <michaeltmaitland at gmail.com>
Date: Tue, 14 May 2024 18:53:54 -0700
Subject: [PATCH 1/6] [TableGen][SubtargetEmitter] Early exit from loop in
FindWriteResources
This gives us a 26% speed improvement in our downstream.
---
llvm/utils/TableGen/SubtargetEmitter.cpp | 25 ++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/llvm/utils/TableGen/SubtargetEmitter.cpp b/llvm/utils/TableGen/SubtargetEmitter.cpp
index 9e32d2de19b2c..737b1bdfd58b6 100644
--- a/llvm/utils/TableGen/SubtargetEmitter.cpp
+++ b/llvm/utils/TableGen/SubtargetEmitter.cpp
@@ -904,14 +904,17 @@ SubtargetEmitter::FindWriteResources(const CodeGenSchedRW &SchedWrite,
continue;
if (AliasDef == WR->getValueAsDef("WriteType") ||
SchedWrite.TheDef == WR->getValueAsDef("WriteType")) {
- if (ResDef) {
- PrintFatalError(WR->getLoc(), "Resources are defined for both "
- "SchedWrite and its alias on processor " +
- ProcModel.ModelName);
- }
ResDef = WR;
+ break;
}
}
+
+ if (ResDef && AliasDef) {
+ PrintFatalError(ResDef->getLoc(), "Resources are defined for both "
+ "SchedWrite and its alias on processor " +
+ ProcModel.ModelName);
+ }
+
// TODO: If ProcModel has a base model (previous generation processor),
// then call FindWriteResources recursively with that model here.
if (!ResDef) {
@@ -958,14 +961,16 @@ Record *SubtargetEmitter::FindReadAdvance(const CodeGenSchedRW &SchedRead,
continue;
if (AliasDef == RA->getValueAsDef("ReadType") ||
SchedRead.TheDef == RA->getValueAsDef("ReadType")) {
- if (ResDef) {
- PrintFatalError(RA->getLoc(), "Resources are defined for both "
- "SchedRead and its alias on processor " +
- ProcModel.ModelName);
- }
ResDef = RA;
+ break;
}
}
+ if (ResDef && AliasDef) {
+ PrintFatalError(ResDef->getLoc(), "Resources are defined for both "
+ "SchedRead and its alias on processor " +
+ ProcModel.ModelName);
+ }
+
// TODO: If ProcModel has a base model (previous generation processor),
// then call FindReadAdvance recursively with that model here.
if (!ResDef && SchedRead.TheDef->getName() != "ReadDefault") {
>From 6b710d0a16602f012377fe469d0992fd64caaf64 Mon Sep 17 00:00:00 2001
From: Michael Maitland <michaeltmaitland at gmail.com>
Date: Wed, 15 May 2024 10:13:07 -0700
Subject: [PATCH 2/6] fixup! make sure we PrintFatalError
---
llvm/utils/TableGen/SubtargetEmitter.cpp | 37 ++++++++++++++----------
1 file changed, 21 insertions(+), 16 deletions(-)
diff --git a/llvm/utils/TableGen/SubtargetEmitter.cpp b/llvm/utils/TableGen/SubtargetEmitter.cpp
index 737b1bdfd58b6..9892f101d0fff 100644
--- a/llvm/utils/TableGen/SubtargetEmitter.cpp
+++ b/llvm/utils/TableGen/SubtargetEmitter.cpp
@@ -902,19 +902,21 @@ SubtargetEmitter::FindWriteResources(const CodeGenSchedRW &SchedWrite,
for (Record *WR : ProcModel.WriteResDefs) {
if (!WR->isSubClassOf("WriteRes"))
continue;
- if (AliasDef == WR->getValueAsDef("WriteType") ||
- SchedWrite.TheDef == WR->getValueAsDef("WriteType")) {
+ // If there is no AliasDef and we find a match, we can early exit since
+ // there is no need to verify whether there are resources defined for both
+ // SchedWrite and its alias.
+ if (!AliasDef && SchedWrite.TheDef == WR->getValueAsDef("WriteType")) {
ResDef = WR;
break;
- }
- }
-
- if (ResDef && AliasDef) {
- PrintFatalError(ResDef->getLoc(), "Resources are defined for both "
+ } else if (AliasDef == WR->getValueAsDef("WriteType")) {
+ if (ResDef) {
+ PrintFatalError(WR->getLoc(), "Resources are defined for both "
"SchedWrite and its alias on processor " +
ProcModel.ModelName);
+ }
+ ResDef = WR;
+ }
}
-
// TODO: If ProcModel has a base model (previous generation processor),
// then call FindWriteResources recursively with that model here.
if (!ResDef) {
@@ -959,18 +961,21 @@ Record *SubtargetEmitter::FindReadAdvance(const CodeGenSchedRW &SchedRead,
for (Record *RA : ProcModel.ReadAdvanceDefs) {
if (!RA->isSubClassOf("ReadAdvance"))
continue;
- if (AliasDef == RA->getValueAsDef("ReadType") ||
- SchedRead.TheDef == RA->getValueAsDef("ReadType")) {
- ResDef = RA;
+ // If there is no AliasDef and we find a match, we can early exit since
+ // there is no need to verify whether there are resources defined for both
+ // SchedWrite and its alias.
+ if (!AliasDef && AliasDef == RA->getValueAsDef("ReadType")) {
+ ResDef = WR;
break;
- }
- }
- if (ResDef && AliasDef) {
- PrintFatalError(ResDef->getLoc(), "Resources are defined for both "
+ } else if (SchedRead.TheDef == RA->getValueAsDef("ReadType")) {
+ if (ResDef) {
+ PrintFatalError(RA->getLoc(), "Resources are defined for both "
"SchedRead and its alias on processor " +
ProcModel.ModelName);
+ }
+ ResDef = RA;
+ }
}
-
// TODO: If ProcModel has a base model (previous generation processor),
// then call FindReadAdvance recursively with that model here.
if (!ResDef && SchedRead.TheDef->getName() != "ReadDefault") {
>From 5212ee108819263c0c56e1e9d2022a5f12e91114 Mon Sep 17 00:00:00 2001
From: Michael Maitland <michaeltmaitland at gmail.com>
Date: Wed, 15 May 2024 10:20:44 -0700
Subject: [PATCH 3/6] fixup! fix typo
---
llvm/utils/TableGen/SubtargetEmitter.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/utils/TableGen/SubtargetEmitter.cpp b/llvm/utils/TableGen/SubtargetEmitter.cpp
index 9892f101d0fff..fb06d05c26f38 100644
--- a/llvm/utils/TableGen/SubtargetEmitter.cpp
+++ b/llvm/utils/TableGen/SubtargetEmitter.cpp
@@ -965,7 +965,7 @@ Record *SubtargetEmitter::FindReadAdvance(const CodeGenSchedRW &SchedRead,
// there is no need to verify whether there are resources defined for both
// SchedWrite and its alias.
if (!AliasDef && AliasDef == RA->getValueAsDef("ReadType")) {
- ResDef = WR;
+ ResDef = RA;
break;
} else if (SchedRead.TheDef == RA->getValueAsDef("ReadType")) {
if (ResDef) {
>From a802de7dd659639c701bfcccf19d9f08d8a7a0ef Mon Sep 17 00:00:00 2001
From: Michael Maitland <michaeltmaitland at gmail.com>
Date: Wed, 15 May 2024 10:26:54 -0700
Subject: [PATCH 4/6] fixup! no else after break
---
llvm/utils/TableGen/SubtargetEmitter.cpp | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/llvm/utils/TableGen/SubtargetEmitter.cpp b/llvm/utils/TableGen/SubtargetEmitter.cpp
index fb06d05c26f38..2c7e0c923cff8 100644
--- a/llvm/utils/TableGen/SubtargetEmitter.cpp
+++ b/llvm/utils/TableGen/SubtargetEmitter.cpp
@@ -908,7 +908,8 @@ SubtargetEmitter::FindWriteResources(const CodeGenSchedRW &SchedWrite,
if (!AliasDef && SchedWrite.TheDef == WR->getValueAsDef("WriteType")) {
ResDef = WR;
break;
- } else if (AliasDef == WR->getValueAsDef("WriteType")) {
+ }
+ if (AliasDef == WR->getValueAsDef("WriteType")) {
if (ResDef) {
PrintFatalError(WR->getLoc(), "Resources are defined for both "
"SchedWrite and its alias on processor " +
@@ -967,7 +968,8 @@ Record *SubtargetEmitter::FindReadAdvance(const CodeGenSchedRW &SchedRead,
if (!AliasDef && AliasDef == RA->getValueAsDef("ReadType")) {
ResDef = RA;
break;
- } else if (SchedRead.TheDef == RA->getValueAsDef("ReadType")) {
+ }
+ if (SchedRead.TheDef == RA->getValueAsDef("ReadType")) {
if (ResDef) {
PrintFatalError(RA->getLoc(), "Resources are defined for both "
"SchedRead and its alias on processor " +
>From 56d79aa4211658237593a485158e4ab6d4cea050 Mon Sep 17 00:00:00 2001
From: Michael Maitland <michaeltmaitland at gmail.com>
Date: Wed, 15 May 2024 10:28:36 -0700
Subject: [PATCH 5/6] fixup! swap conditions
---
llvm/utils/TableGen/SubtargetEmitter.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/utils/TableGen/SubtargetEmitter.cpp b/llvm/utils/TableGen/SubtargetEmitter.cpp
index 2c7e0c923cff8..12ed3392fe405 100644
--- a/llvm/utils/TableGen/SubtargetEmitter.cpp
+++ b/llvm/utils/TableGen/SubtargetEmitter.cpp
@@ -965,11 +965,11 @@ Record *SubtargetEmitter::FindReadAdvance(const CodeGenSchedRW &SchedRead,
// If there is no AliasDef and we find a match, we can early exit since
// there is no need to verify whether there are resources defined for both
// SchedWrite and its alias.
- if (!AliasDef && AliasDef == RA->getValueAsDef("ReadType")) {
+ if (!AliasDef && SchedRead.TheDef == RA->getValueAsDef("ReadType")) {
ResDef = RA;
break;
- }
- if (SchedRead.TheDef == RA->getValueAsDef("ReadType")) {
+ }
+ if (AliasDef == RA->getValueAsDef("ReadType")) {
if (ResDef) {
PrintFatalError(RA->getLoc(), "Resources are defined for both "
"SchedRead and its alias on processor " +
>From d70b2015c53b1247e876b49aa44c45c5edd43d2c Mon Sep 17 00:00:00 2001
From: Michael Maitland <michaeltmaitland at gmail.com>
Date: Wed, 15 May 2024 10:29:51 -0700
Subject: [PATCH 6/6] fixup! SchedWrite -> SchedRead typo
---
llvm/utils/TableGen/SubtargetEmitter.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/utils/TableGen/SubtargetEmitter.cpp b/llvm/utils/TableGen/SubtargetEmitter.cpp
index 12ed3392fe405..4409e6bb40b29 100644
--- a/llvm/utils/TableGen/SubtargetEmitter.cpp
+++ b/llvm/utils/TableGen/SubtargetEmitter.cpp
@@ -964,7 +964,7 @@ Record *SubtargetEmitter::FindReadAdvance(const CodeGenSchedRW &SchedRead,
continue;
// If there is no AliasDef and we find a match, we can early exit since
// there is no need to verify whether there are resources defined for both
- // SchedWrite and its alias.
+ // SchedRead and its alias.
if (!AliasDef && SchedRead.TheDef == RA->getValueAsDef("ReadType")) {
ResDef = RA;
break;
More information about the llvm-commits
mailing list