[RelLookupTableConverter] Avoid querying TTI for declarations
authorNikita Popov <npopov@redhat.com>
Wed, 16 Mar 2022 09:36:00 +0000 (10:36 +0100)
committerNikita Popov <npopov@redhat.com>
Wed, 16 Mar 2022 09:39:28 +0000 (10:39 +0100)
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.

llvm/lib/Transforms/Utils/RelLookupTableConverter.cpp

index fd52285124c1b91331ac9adea84f9d77ea01e79f..037f42f5b0509194c35121589c11030d0c43b28e 100644 (file)
@@ -170,13 +170,17 @@ static void convertToRelLookupTable(GlobalVariable &LookupTable) {
 // Convert lookup tables to relative lookup tables in the module.
 static bool convertToRelativeLookupTables(
     Module &M, function_ref<TargetTransformInfo &(Function &)> GetTTI) {
-  Module::iterator FI = M.begin();
-  if (FI == M.end())
-    return false;
+  for (Function &F : M) {
+    if (F.isDeclaration())
+      continue;
 
-  // Check if we have a target that supports relative lookup tables.
-  if (!GetTTI(*FI).shouldBuildRelLookupTables())
-    return false;
+    // Check if we have a target that supports relative lookup tables.
+    if (!GetTTI(F).shouldBuildRelLookupTables())
+      return false;
+
+    // We assume that the result is independent of the checked function.
+    break;
+  }
 
   bool Changed = false;