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.
// 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;