Skip to content

Commit 20531b3

Browse files
committed
[RelLookupTableConverter] Avoid querying TTI for declarations
This code queries TTI on a single function, which is considered to be representative. This is a bit odd, but probably fine in practice. However, I think we should at least avoid querying declarations, which e.g. will generally lack target attributes, and for which we don't seem to ever query TTI in other places.
1 parent 09854f2 commit 20531b3

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

llvm/lib/Transforms/Utils/RelLookupTableConverter.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,17 @@ static void convertToRelLookupTable(GlobalVariable &LookupTable) {
170170
// Convert lookup tables to relative lookup tables in the module.
171171
static bool convertToRelativeLookupTables(
172172
Module &M, function_ref<TargetTransformInfo &(Function &)> GetTTI) {
173-
Module::iterator FI = M.begin();
174-
if (FI == M.end())
175-
return false;
173+
for (Function &F : M) {
174+
if (F.isDeclaration())
175+
continue;
176176

177-
// Check if we have a target that supports relative lookup tables.
178-
if (!GetTTI(*FI).shouldBuildRelLookupTables())
179-
return false;
177+
// Check if we have a target that supports relative lookup tables.
178+
if (!GetTTI(F).shouldBuildRelLookupTables())
179+
return false;
180+
181+
// We assume that the result is independent of the checked function.
182+
break;
183+
}
180184

181185
bool Changed = false;
182186

0 commit comments

Comments
 (0)