Skip to content

Commit

Permalink
[RelLookupTableConverter] Avoid querying TTI for declarations
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nikic committed Mar 16, 2022
1 parent 09854f2 commit 20531b3
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions llvm/lib/Transforms/Utils/RelLookupTableConverter.cpp
Expand Up @@ -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;

Expand Down

0 comments on commit 20531b3

Please sign in to comment.