LLVM  14.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/LLVMContext.h"
13 #include "llvm/IR/Module.h"
14 #include "llvm/InitializePasses.h"
15 #include "llvm/Support/Debug.h"
19 using namespace llvm;
20 
21 #define DEBUG_TYPE "inferattrs"
22 
24  Module &M, function_ref<TargetLibraryInfo &(Function &)> GetTLI) {
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. This ensures libfuncs are annotated and also allows our
30  // CGSCC inference to avoid needing to duplicate the inference from other
31  // attribute logic on all calls to declarations (as declarations aren't
32  // explicitly visited by CGSCC passes in the new pass manager.)
33  if (F.isDeclaration() && !F.hasOptNone()) {
34  if (!F.hasFnAttribute(Attribute::NoBuiltin))
35  Changed |= inferLibFuncAttributes(F, GetTLI(F));
36  Changed |= inferAttributesFromOthers(F);
37  }
38 
39  return Changed;
40 }
41 
46  auto GetTLI = [&FAM](Function &F) -> TargetLibraryInfo & {
48  };
49 
50  if (!inferAllPrototypeAttributes(M, GetTLI))
51  // If we didn't infer anything, preserve all analyses.
52  return PreservedAnalyses::all();
53 
54  // Otherwise, we may have changed fundamental function attributes, so clear
55  // out all the passes.
56  return PreservedAnalyses::none();
57 }
58 
59 namespace {
60 struct InferFunctionAttrsLegacyPass : public ModulePass {
61  static char ID; // Pass identification, replacement for typeid
62  InferFunctionAttrsLegacyPass() : ModulePass(ID) {
65  }
66 
67  void getAnalysisUsage(AnalysisUsage &AU) const override {
69  }
70 
71  bool runOnModule(Module &M) override {
72  if (skipModule(M))
73  return false;
74 
75  auto GetTLI = [this](Function &F) -> TargetLibraryInfo & {
76  return this->getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F);
77  };
78  return inferAllPrototypeAttributes(M, GetTLI);
79  }
80 };
81 }
82 
84 INITIALIZE_PASS_BEGIN(InferFunctionAttrsLegacyPass, "inferattrs",
85  "Infer set function attributes", false, false)
87 INITIALIZE_PASS_END(InferFunctionAttrsLegacyPass, "inferattrs",
89 
91  return new InferFunctionAttrsLegacyPass();
92 }
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:155
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
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
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:238
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:769
llvm::initializeInferFunctionAttrsLegacyPassPass
void initializeInferFunctionAttrsLegacyPassPass(PassRegistry &)
llvm::Function
Definition: Function.h:61
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:158
Module.h
llvm::createInferFunctionAttrsLegacyPass
Pass * createInferFunctionAttrsLegacyPass()
Create a legacy pass manager instance of a pass to infer function attributes.
Definition: InferFunctionAttrs.cpp:90
F
#define F(x, y, z)
Definition: MD5.cpp:56
inferattrs
inferattrs
Definition: InferFunctionAttrs.cpp:87
attributes
Infer set function attributes
Definition: InferFunctionAttrs.cpp:88
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:142
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:3348
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: STLExtras.h:168
llvm::TargetLibraryInfoWrapperPass
Definition: TargetLibraryInfo.h:463
INITIALIZE_PASS_DEPENDENCY
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
inferAllPrototypeAttributes
static bool inferAllPrototypeAttributes(Module &M, function_ref< TargetLibraryInfo &(Function &)> GetTLI)
Definition: InferFunctionAttrs.cpp:23
InferFunctionAttrs.h
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:83
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::InferFunctionAttrsPass::run
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Definition: InferFunctionAttrs.cpp:42
llvm::PreservedAnalyses::all
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:161
Function.h
llvm::TargetLibraryInfo
Provides information about what library functions are available for the current target.
Definition: TargetLibraryInfo.h:219
llvm::Pass
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:91
llvm::inferLibFuncAttributes
bool inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI)
Analyze the name and prototype of the given function and set any applicable attributes.
Definition: BuildLibCalls.cpp:218
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:44
llvm::InnerAnalysisManagerProxy
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:926
llvm::AnalysisUsage::addRequired
AnalysisUsage & addRequired()
Definition: PassAnalysisSupport.h:75
LLVMContext.h
raw_ostream.h
InitializePasses.h
BuildLibCalls.h
Debug.h
llvm::TargetLibraryAnalysis
Analysis pass providing the TargetLibraryInfo.
Definition: TargetLibraryInfo.h:438
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:38