LLVM 20.0.0git
InferFunctionAttrs.cpp
Go to the documentation of this file.
1//===- InferFunctionAttrs.cpp - Infer implicit function attributes --------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
11#include "llvm/IR/Function.h"
12#include "llvm/IR/Module.h"
15using namespace llvm;
16
17#define DEBUG_TYPE "inferattrs"
18
21 bool Changed = false;
22
23 for (Function &F : M.functions())
24 // We only infer things using the prototype and the name; we don't need
25 // definitions. This ensures libfuncs are annotated and also allows our
26 // CGSCC inference to avoid needing to duplicate the inference from other
27 // attribute logic on all calls to declarations (as declarations aren't
28 // explicitly visited by CGSCC passes in the new pass manager.)
29 if (F.isDeclaration() && !F.hasOptNone()) {
30 if (!F.hasFnAttribute(Attribute::NoBuiltin))
31 Changed |= inferNonMandatoryLibFuncAttrs(F, GetTLI(F));
32 Changed |= inferAttributesFromOthers(F);
33 }
34
35 return Changed;
36}
37
42 auto GetTLI = [&FAM](Function &F) -> TargetLibraryInfo & {
44 };
45
46 if (!inferAllPrototypeAttributes(M, GetTLI))
47 // If we didn't infer anything, preserve all analyses.
49
50 // Otherwise, we may have changed fundamental function attributes, so clear
51 // out all the passes.
53}
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:253
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:405
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:563
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: Analysis.h:111
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition: Analysis.h:114
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:117
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:4220
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)