Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:12

0001 //===- CodeMetrics.h - Code cost measurements -------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file implements various weight measurements for code, helping
0010 // the Inliner and other passes decide whether to duplicate its contents.
0011 //
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_ANALYSIS_CODEMETRICS_H
0015 #define LLVM_ANALYSIS_CODEMETRICS_H
0016 
0017 #include "llvm/ADT/DenseMap.h"
0018 #include "llvm/Support/InstructionCost.h"
0019 
0020 namespace llvm {
0021 class AssumptionCache;
0022 class BasicBlock;
0023 class Loop;
0024 class Function;
0025 template <class T> class SmallPtrSetImpl;
0026 class TargetTransformInfo;
0027 class Value;
0028 
0029 enum struct ConvergenceKind { None, Controlled, ExtendedLoop, Uncontrolled };
0030 
0031 /// Utility to calculate the size and a few similar metrics for a set
0032 /// of basic blocks.
0033 struct CodeMetrics {
0034   /// True if this function contains a call to setjmp or other functions
0035   /// with attribute "returns twice" without having the attribute itself.
0036   bool exposesReturnsTwice = false;
0037 
0038   /// True if this function calls itself.
0039   bool isRecursive = false;
0040 
0041   /// True if this function cannot be duplicated.
0042   ///
0043   /// True if this function contains one or more indirect branches, or it contains
0044   /// one or more 'noduplicate' instructions.
0045   bool notDuplicatable = false;
0046 
0047   /// The kind of convergence specified in this function.
0048   ConvergenceKind Convergence = ConvergenceKind::None;
0049 
0050   /// True if this function calls alloca (in the C sense).
0051   bool usesDynamicAlloca = false;
0052 
0053   /// Code size cost of the analyzed blocks.
0054   InstructionCost NumInsts = 0;
0055 
0056   /// Number of analyzed blocks.
0057   unsigned NumBlocks = false;
0058 
0059   /// Keeps track of basic block code size estimates.
0060   DenseMap<const BasicBlock *, InstructionCost> NumBBInsts;
0061 
0062   /// Keep track of the number of calls to 'big' functions.
0063   unsigned NumCalls = false;
0064 
0065   /// The number of calls to internal functions with a single caller.
0066   ///
0067   /// These are likely targets for future inlining, likely exposed by
0068   /// interleaved devirtualization.
0069   unsigned NumInlineCandidates = 0;
0070 
0071   /// How many instructions produce vector values.
0072   ///
0073   /// The inliner is more aggressive with inlining vector kernels.
0074   unsigned NumVectorInsts = 0;
0075 
0076   /// How many 'ret' instructions the blocks contain.
0077   unsigned NumRets = 0;
0078 
0079   /// Add information about a block to the current state.
0080   void analyzeBasicBlock(const BasicBlock *BB, const TargetTransformInfo &TTI,
0081                          const SmallPtrSetImpl<const Value *> &EphValues,
0082                          bool PrepareForLTO = false, const Loop *L = nullptr);
0083 
0084   /// Collect a loop's ephemeral values (those used only by an assume
0085   /// or similar intrinsics in the loop).
0086   static void collectEphemeralValues(const Loop *L, AssumptionCache *AC,
0087                                      SmallPtrSetImpl<const Value *> &EphValues);
0088 
0089   /// Collect a functions's ephemeral values (those used only by an
0090   /// assume or similar intrinsics in the function).
0091   static void collectEphemeralValues(const Function *L, AssumptionCache *AC,
0092                                      SmallPtrSetImpl<const Value *> &EphValues);
0093 };
0094 
0095 }
0096 
0097 #endif