LLVM  15.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"
13 #include "llvm/InitializePasses.h"
16 using namespace llvm;
17 
18 #define DEBUG_TYPE "inferattrs"
19 
21  Module &M, function_ref<TargetLibraryInfo &(Function &)> GetTLI) {
22  bool Changed = false;
23 
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  }
35 
36  return Changed;
37 }
38 
43  auto GetTLI = [&FAM](Function &F) -> TargetLibraryInfo & {
45  };
46 
47  if (!inferAllPrototypeAttributes(M, GetTLI))
48  // If we didn't infer anything, preserve all analyses.
49  return PreservedAnalyses::all();
50 
51  // Otherwise, we may have changed fundamental function attributes, so clear
52  // out all the passes.
53  return PreservedAnalyses::none();
54 }
55 
56 namespace {
57 struct InferFunctionAttrsLegacyPass : public ModulePass {
58  static char ID; // Pass identification, replacement for typeid
59  InferFunctionAttrsLegacyPass() : ModulePass(ID) {
62  }
63 
64  void getAnalysisUsage(AnalysisUsage &AU) const override {
66  }
67 
68  bool runOnModule(Module &M) override {
69  if (skipModule(M))
70  return false;
71 
72  auto GetTLI = [this](Function &F) -> TargetLibraryInfo & {
73  return this->getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F);
74  };
75  return inferAllPrototypeAttributes(M, GetTLI);
76  }
77 };
78 }
79 
81 INITIALIZE_PASS_BEGIN(InferFunctionAttrsLegacyPass, "inferattrs",
82  "Infer set function attributes", false, false)
84 INITIALIZE_PASS_END(InferFunctionAttrsLegacyPass, "inferattrs",
86 
88  return new InferFunctionAttrsLegacyPass();
89 }
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:152
set
We currently generate a but we really shouldn eax ecx xorl edx divl ecx eax divl ecx movl eax ret A similar code sequence works for division We currently compile i32 v2 eax eax jo LBB1_2 atomic and others It is also currently not done for read modify write instructions It is also current not done if the OF or CF flags are needed The shift operators have the complication that when the shift count is EFLAGS is not set
Definition: README.txt:1277
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::ModulePass
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:248
llvm::AnalysisManager::getResult
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:780
llvm::initializeInferFunctionAttrsLegacyPassPass
void initializeInferFunctionAttrsLegacyPassPass(PassRegistry &)
llvm::Function
Definition: Function.h:60
Local.h
FAM
FunctionAnalysisManager FAM
Definition: PassBuilderBindings.cpp:59
llvm::PreservedAnalyses::none
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition: PassManager.h:155
Module.h
llvm::createInferFunctionAttrsLegacyPass
Pass * createInferFunctionAttrsLegacyPass()
Create a legacy pass manager instance of a pass to infer function attributes.
Definition: InferFunctionAttrs.cpp:87
F
#define F(x, y, z)
Definition: MD5.cpp:55
inferattrs
inferattrs
Definition: InferFunctionAttrs.cpp:84
attributes
Infer set function attributes
Definition: InferFunctionAttrs.cpp:85
llvm::PassRegistry::getPassRegistry
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Definition: PassRegistry.cpp:31
INITIALIZE_PASS_BEGIN
INITIALIZE_PASS_BEGIN(InferFunctionAttrsLegacyPass, "inferattrs", "Infer set function attributes", false, false) INITIALIZE_PASS_END(InferFunctionAttrsLegacyPass
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
TargetLibraryInfo.h
false
Definition: StackSlotColoring.cpp:141
llvm::inferAttributesFromOthers
bool inferAttributesFromOthers(Function &F)
If we can infer one attribute from another on the declaration of a function, explicitly materialize t...
Definition: Local.cpp:3374
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
INITIALIZE_PASS_END
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:58
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLFunctionalExtras.h:36
llvm::TargetLibraryInfoWrapperPass
Definition: TargetLibraryInfo.h:468
INITIALIZE_PASS_DEPENDENCY
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
inferAllPrototypeAttributes
static bool inferAllPrototypeAttributes(Module &M, function_ref< TargetLibraryInfo &(Function &)> GetTLI)
Definition: InferFunctionAttrs.cpp:20
InferFunctionAttrs.h
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:82
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::InferFunctionAttrsPass::run
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Definition: InferFunctionAttrs.cpp:39
llvm::PreservedAnalyses::all
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:158
Function.h
llvm::TargetLibraryInfo
Provides information about what library functions are available for the current target.
Definition: TargetLibraryInfo.h:222
llvm::Pass
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:91
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:42
llvm::InnerAnalysisManagerProxy
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:937
llvm::inferNonMandatoryLibFuncAttrs
bool inferNonMandatoryLibFuncAttrs(Module *M, StringRef Name, const TargetLibraryInfo &TLI)
Analyze the name and prototype of the given function and set any applicable attributes.
Definition: BuildLibCalls.cpp:249
llvm::AnalysisUsage::addRequired
AnalysisUsage & addRequired()
Definition: PassAnalysisSupport.h:75
InitializePasses.h
BuildLibCalls.h
llvm::TargetLibraryAnalysis
Analysis pass providing the TargetLibraryInfo.
Definition: TargetLibraryInfo.h:443
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37