Skip to content

Commit 33aa80b

Browse files
committed
Actually use the passed in bitcode libfuncs
1 parent 0434173 commit 33aa80b

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

llvm/lib/LTO/LTOBackend.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ createTargetMachine(const Config &Conf, const Target *TheTarget, Module &M) {
239239
static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
240240
unsigned OptLevel, bool IsThinLTO,
241241
ModuleSummaryIndex *ExportSummary,
242-
const ModuleSummaryIndex *ImportSummary) {
242+
const ModuleSummaryIndex *ImportSummary,
243+
const DenseSet<StringRef> &BitcodeLibFuncs) {
243244
std::optional<PGOOptions> PGOOpt;
244245
if (!Conf.SampleProfile.empty())
245246
PGOOpt = PGOOptions(Conf.SampleProfile, "", Conf.ProfileRemapping,
@@ -283,14 +284,23 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
283284
TLII->disableAllFunctions();
284285

285286
TargetLibraryInfo TLI(*TLII);
286-
for (unsigned I = 0, E = static_cast<unsigned>(LibFunc::NumLibFuncs);
287-
I != E; ++I) {
287+
for (unsigned I = 0, E = static_cast<unsigned>(LibFunc::NumLibFuncs); I != E;
288+
++I) {
288289
LibFunc F = static_cast<LibFunc>(I);
289-
GlobalValue *Val = Mod.getNamedValue(TLI.getName(F));
290+
StringRef Name = TLI.getName(F);
291+
GlobalValue *Val = Mod.getNamedValue(Name);
292+
293+
// LibFuncs present in the current TU can always be referenced.
294+
if (Val && !Val->isDeclaration())
295+
continue;
296+
297+
// LibFuncs not implemented in bitcode can always be referenced.
298+
if (!BitcodeLibFuncs.contains(Name))
299+
continue;
300+
290301
// TODO: Non-lto functions should not be disabled, nor should functions that
291302
// are somewhere in a ThinLTO link (just not imported in this module).
292-
if (!Val || Val->isDeclaration())
293-
TLII->setUnavailable(F);
303+
TLII->setUnavailable(F);
294304
}
295305

296306
FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); });
@@ -402,9 +412,12 @@ bool lto::opt(const Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod,
402412
// analysis in the case of a ThinLTO build where this might be an empty
403413
// regular LTO combined module, with a large combined index from ThinLTO.
404414
if (!isEmptyModule(Mod)) {
415+
DenseSet<StringRef> BitcodeLibFuncsSet;
416+
for (const char *F : BitcodeLibFuncs)
417+
BitcodeLibFuncsSet.insert(F);
405418
// FIXME: Plumb the combined index into the new pass manager.
406419
runNewPMPasses(Conf, Mod, TM, Conf.OptLevel, IsThinLTO, ExportSummary,
407-
ImportSummary);
420+
ImportSummary, BitcodeLibFuncsSet);
408421
}
409422
return !Conf.PostOptModuleHook || Conf.PostOptModuleHook(Task, Mod);
410423
}

0 commit comments

Comments
 (0)