LLVM 17.0.0git
Go to the documentation of this file.
1//===- InferFunctionAttrs.cpp - Infer implicit function attributes --------===//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
11#include "llvm/IR/Function.h"
12#include "llvm/IR/Module.h"
16using namespace llvm;
18#define DEBUG_TYPE "inferattrs"
22 bool Changed = false;
24 for (Function &F : M.functions())
25 // We only infer things using the prototype and the name; we don't need
26 // definitions. This ensures libfuncs are annotated and also allows our
27 // CGSCC inference to avoid needing to duplicate the inference from other
28 // attribute logic on all calls to declarations (as declarations aren't
29 // explicitly visited by CGSCC passes in the new pass manager.)
30 if (F.isDeclaration() && !F.hasOptNone()) {
31 if (!F.hasFnAttribute(Attribute::NoBuiltin))
32 Changed |= inferNonMandatoryLibFuncAttrs(F, GetTLI(F));
33 Changed |= inferAttributesFromOthers(F);
34 }
36 return Changed;
43 auto GetTLI = [&FAM](Function &F) -> TargetLibraryInfo & {
45 };
47 if (!inferAllPrototypeAttributes(M, GetTLI))
48 // If we didn't infer anything, preserve all analyses.
51 // Otherwise, we may have changed fundamental function attributes, so clear
52 // out all the passes.
static bool inferAllPrototypeAttributes(Module &M, function_ref< TargetLibraryInfo &(Function &)> GetTLI)
Interfaces for passes which infer implicit function attributes from the name and signature of functio...
#define F(x, y, z)
Definition: MD5.cpp:55
Module.h This file contains the declarations for the Module class.
FunctionAnalysisManager FAM
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:620
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:774
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:933
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:152
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition: PassManager.h:155
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:158
Analysis pass providing the TargetLibraryInfo.
Provides information about what library functions are available for the current target.
An efficient, type-erasing, non-owning reference to a callable.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
bool inferNonMandatoryLibFuncAttrs(Module *M, StringRef Name, const TargetLibraryInfo &TLI)
Analyze the name and prototype of the given function and set any applicable attributes.
bool inferAttributesFromOthers(Function &F)
If we can infer one attribute from another on the declaration of a function, explicitly materialize t...
Definition: Local.cpp:3508
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)