xref: /netbsd-src/external/apache2/llvm/dist/llvm/include/llvm/Transforms/IPO/ArgumentPromotion.h (revision 82d56013d7b633d116a93943de88e08335357a7c)
1 //===- ArgumentPromotion.h - Promote by-reference arguments -----*- C++ -*-===//
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 
9 #ifndef LLVM_TRANSFORMS_IPO_ARGUMENTPROMOTION_H
10 #define LLVM_TRANSFORMS_IPO_ARGUMENTPROMOTION_H
11 
12 #include "llvm/Analysis/CGSCCPassManager.h"
13 #include "llvm/Analysis/LazyCallGraph.h"
14 #include "llvm/IR/PassManager.h"
15 
16 namespace llvm {
17 class TargetTransformInfo;
18 
19 /// Argument promotion pass.
20 ///
21 /// This pass walks the functions in each SCC and for each one tries to
22 /// transform it and all of its callers to replace indirect arguments with
23 /// direct (by-value) arguments.
24 class ArgumentPromotionPass : public PassInfoMixin<ArgumentPromotionPass> {
25   unsigned MaxElements;
26 
27 public:
MaxElements(MaxElements)28   ArgumentPromotionPass(unsigned MaxElements = 3u) : MaxElements(MaxElements) {}
29 
30   /// Check if callers and the callee \p F agree how promoted arguments would be
31   /// passed. The ones that they do not agree on are eliminated from the sets but
32   /// the return value has to be observed as well.
33   static bool areFunctionArgsABICompatible(
34       const Function &F, const TargetTransformInfo &TTI,
35       SmallPtrSetImpl<Argument *> &ArgsToPromote,
36       SmallPtrSetImpl<Argument *> &ByValArgsToTransform);
37 
38   /// Checks if a type could have padding bytes.
39   static bool isDenselyPacked(Type *type, const DataLayout &DL);
40 
41   PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM,
42                         LazyCallGraph &CG, CGSCCUpdateResult &UR);
43 };
44 
45 } // end namespace llvm
46 
47 #endif // LLVM_TRANSFORMS_IPO_ARGUMENTPROMOTION_H
48