LLVM  10.0.0svn
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/LLVMContext.h"
13 #include "llvm/IR/Module.h"
14 #include "llvm/Support/Debug.h"
17 using namespace llvm;
18 
19 #define DEBUG_TYPE "inferattrs"
20 
22  Module &M, function_ref<TargetLibraryInfo &(Function &)> GetTLI) {
23  bool Changed = false;
24 
25  for (Function &F : M.functions())
26  // We only infer things using the prototype and the name; we don't need
27  // definitions.
28  if (F.isDeclaration() && !F.hasOptNone())
29  Changed |= inferLibFuncAttributes(F, GetTLI(F));
30 
31  return Changed;
32 }
33 
38  auto GetTLI = [&FAM](Function &F) -> TargetLibraryInfo & {
39  return FAM.getResult<TargetLibraryAnalysis>(F);
40  };
41 
42  if (!inferAllPrototypeAttributes(M, GetTLI))
43  // If we didn't infer anything, preserve all analyses.
44  return PreservedAnalyses::all();
45 
46  // Otherwise, we may have changed fundamental function attributes, so clear
47  // out all the passes.
48  return PreservedAnalyses::none();
49 }
50 
51 namespace {
52 struct InferFunctionAttrsLegacyPass : public ModulePass {
53  static char ID; // Pass identification, replacement for typeid
54  InferFunctionAttrsLegacyPass() : ModulePass(ID) {
57  }
58 
59  void getAnalysisUsage(AnalysisUsage &AU) const override {
61  }
62 
63  bool runOnModule(Module &M) override {
64  if (skipModule(M))
65  return false;
66 
67  auto GetTLI = [this](Function &F) -> TargetLibraryInfo & {
68  return this->getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F);
69  };
70  return inferAllPrototypeAttributes(M, GetTLI);
71  }
72 };
73 }
74 
76 INITIALIZE_PASS_BEGIN(InferFunctionAttrsLegacyPass, "inferattrs",
77  "Infer set function attributes", false, false)
79 INITIALIZE_PASS_END(InferFunctionAttrsLegacyPass, "inferattrs",
80  "Infer set function attributes", false, false)
81 
83  return new InferFunctionAttrsLegacyPass();
84 }
Pass interface - Implemented by all &#39;passes&#39;.
Definition: Pass.h:80
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:777
This class represents lattice values for constants.
Definition: AllocatorList.h:23
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:66
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:104
F(f)
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:50
void initializeInferFunctionAttrsLegacyPassPass(PassRegistry &)
Infer set function attributes
INITIALIZE_PASS_BEGIN(InferFunctionAttrsLegacyPass, "inferattrs", "Infer set function attributes", false, false) INITIALIZE_PASS_END(InferFunctionAttrsLegacyPass
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition: PassManager.h:157
bool inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI)
Analyze the name and prototype of the given function and set any applicable attributes.
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:154
iterator_range< iterator > functions()
Definition: Module.h:610
Represent the analysis usage information of a pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:160
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
Module.h This file contains the declarations for the Module class.
Provides information about what library functions are available for the current target.
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...
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:224
Pass * createInferFunctionAttrsLegacyPass()
Create a legacy pass manager instance of a pass to infer function attributes.
Analysis pass providing the TargetLibraryInfo.
print Print MemDeps of function
A container for analyses that lazily runs them and caches their results.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:1045