LLVM  8.0.1
InferFunctionAttrs.cpp
Go to the documentation of this file.
1 //===- InferFunctionAttrs.cpp - Infer implicit function attributes --------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
12 #include "llvm/IR/Function.h"
13 #include "llvm/IR/LLVMContext.h"
14 #include "llvm/IR/Module.h"
15 #include "llvm/Support/Debug.h"
18 using namespace llvm;
19 
20 #define DEBUG_TYPE "inferattrs"
21 
23  const TargetLibraryInfo &TLI) {
24  bool Changed = false;
25 
26  for (Function &F : M.functions())
27  // We only infer things using the prototype and the name; we don't need
28  // definitions.
29  if (F.isDeclaration() && !F.hasFnAttribute((Attribute::OptimizeNone)))
30  Changed |= inferLibFuncAttributes(F, TLI);
31 
32  return Changed;
33 }
34 
37  auto &TLI = AM.getResult<TargetLibraryAnalysis>(M);
38 
39  if (!inferAllPrototypeAttributes(M, TLI))
40  // If we didn't infer anything, preserve all analyses.
41  return PreservedAnalyses::all();
42 
43  // Otherwise, we may have changed fundamental function attributes, so clear
44  // out all the passes.
45  return PreservedAnalyses::none();
46 }
47 
48 namespace {
49 struct InferFunctionAttrsLegacyPass : public ModulePass {
50  static char ID; // Pass identification, replacement for typeid
51  InferFunctionAttrsLegacyPass() : ModulePass(ID) {
54  }
55 
56  void getAnalysisUsage(AnalysisUsage &AU) const override {
58  }
59 
60  bool runOnModule(Module &M) override {
61  if (skipModule(M))
62  return false;
63 
64  auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
65  return inferAllPrototypeAttributes(M, TLI);
66  }
67 };
68 }
69 
71 INITIALIZE_PASS_BEGIN(InferFunctionAttrsLegacyPass, "inferattrs",
72  "Infer set function attributes", false, false)
74 INITIALIZE_PASS_END(InferFunctionAttrsLegacyPass, "inferattrs",
75  "Infer set function attributes", false, false)
76 
78  return new InferFunctionAttrsLegacyPass();
79 }
Pass interface - Implemented by all &#39;passes&#39;.
Definition: Pass.h:81
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:770
This class represents lattice values for constants.
Definition: AllocatorList.h:24
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
F(f)
static bool inferAllPrototypeAttributes(Module &M, const TargetLibraryInfo &TLI)
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:51
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:606
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.
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:225
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)