Path: blob/main/contrib/llvm-project/llvm/lib/Transforms/IPO/InferFunctionAttrs.cpp
35266 views
//===- InferFunctionAttrs.cpp - Infer implicit function attributes --------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "llvm/Transforms/IPO/InferFunctionAttrs.h"9#include "llvm/Analysis/TargetLibraryInfo.h"10#include "llvm/IR/Function.h"11#include "llvm/IR/Module.h"12#include "llvm/Transforms/Utils/BuildLibCalls.h"13#include "llvm/Transforms/Utils/Local.h"14using namespace llvm;1516#define DEBUG_TYPE "inferattrs"1718static bool inferAllPrototypeAttributes(19Module &M, function_ref<TargetLibraryInfo &(Function &)> GetTLI) {20bool Changed = false;2122for (Function &F : M.functions())23// We only infer things using the prototype and the name; we don't need24// definitions. This ensures libfuncs are annotated and also allows our25// CGSCC inference to avoid needing to duplicate the inference from other26// attribute logic on all calls to declarations (as declarations aren't27// explicitly visited by CGSCC passes in the new pass manager.)28if (F.isDeclaration() && !F.hasOptNone()) {29if (!F.hasFnAttribute(Attribute::NoBuiltin))30Changed |= inferNonMandatoryLibFuncAttrs(F, GetTLI(F));31Changed |= inferAttributesFromOthers(F);32}3334return Changed;35}3637PreservedAnalyses InferFunctionAttrsPass::run(Module &M,38ModuleAnalysisManager &AM) {39FunctionAnalysisManager &FAM =40AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();41auto GetTLI = [&FAM](Function &F) -> TargetLibraryInfo & {42return FAM.getResult<TargetLibraryAnalysis>(F);43};4445if (!inferAllPrototypeAttributes(M, GetTLI))46// If we didn't infer anything, preserve all analyses.47return PreservedAnalyses::all();4849// Otherwise, we may have changed fundamental function attributes, so clear50// out all the passes.51return PreservedAnalyses::none();52}535455