LLVM  6.0.0svn
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 
13 #include "llvm/IR/Function.h"
14 #include "llvm/IR/LLVMContext.h"
15 #include "llvm/IR/Module.h"
16 #include "llvm/Support/Debug.h"
19 using namespace llvm;
20 
21 #define DEBUG_TYPE "inferattrs"
22 
24  const TargetLibraryInfo &TLI) {
25  bool Changed = false;
26 
27  for (Function &F : M.functions())
28  // We only infer things using the prototype and the name; we don't need
29  // definitions.
30  if (F.isDeclaration() && !F.hasFnAttribute((Attribute::OptimizeNone)))
31  Changed |= inferLibFuncAttributes(F, TLI);
32 
33  return Changed;
34 }
35 
38  auto &TLI = AM.getResult<TargetLibraryAnalysis>(M);
39 
40  if (!inferAllPrototypeAttributes(M, TLI))
41  // If we didn't infer anything, preserve all analyses.
42  return PreservedAnalyses::all();
43 
44  // Otherwise, we may have changed fundamental function attributes, so clear
45  // out all the passes.
46  return PreservedAnalyses::none();
47 }
48 
49 namespace {
50 struct InferFunctionAttrsLegacyPass : public ModulePass {
51  static char ID; // Pass identification, replacement for typeid
52  InferFunctionAttrsLegacyPass() : ModulePass(ID) {
55  }
56 
57  void getAnalysisUsage(AnalysisUsage &AU) const override {
59  }
60 
61  bool runOnModule(Module &M) override {
62  if (skipModule(M))
63  return false;
64 
65  auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
66  return inferAllPrototypeAttributes(M, TLI);
67  }
68 };
69 }
70 
72 INITIALIZE_PASS_BEGIN(InferFunctionAttrsLegacyPass, "inferattrs",
73  "Infer set function attributes", false, false)
75 INITIALIZE_PASS_END(InferFunctionAttrsLegacyPass, "inferattrs",
76  "Infer set function attributes", false, false)
77 
79  return new InferFunctionAttrsLegacyPass();
80 }
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:687
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
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:156
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:153
iterator_range< iterator > functions()
Definition: Module.h:583
Represent the analysis usage information of a pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:159
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)