2012-03-16 05:51:52 +00:00
|
|
|
//===- CodeMetrics.h - Code cost measurements -------------------*- C++ -*-===//
|
2010-06-09 15:11:37 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2011-01-16 00:27:10 +00:00
|
|
|
// This file implements various weight measurements for code, helping
|
|
|
|
// the Inliner and other passes decide whether to duplicate its contents.
|
2010-06-09 15:11:37 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_ANALYSIS_CODEMETRICS_H
|
|
|
|
#define LLVM_ANALYSIS_CODEMETRICS_H
|
|
|
|
|
2011-01-08 08:19:49 +00:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
|
2010-06-09 15:11:37 +00:00
|
|
|
namespace llvm {
|
2011-11-04 18:29:09 +00:00
|
|
|
class BasicBlock;
|
|
|
|
class Function;
|
2011-10-01 01:39:05 +00:00
|
|
|
class TargetData;
|
2011-11-04 18:29:09 +00:00
|
|
|
class Value;
|
2011-10-01 01:39:05 +00:00
|
|
|
|
2012-03-16 05:51:52 +00:00
|
|
|
/// \brief Check whether a call will lower to something small.
|
|
|
|
///
|
|
|
|
/// This tests checks whether calls to this function will lower to something
|
|
|
|
/// significantly cheaper than a traditional call, often a single
|
|
|
|
/// instruction.
|
|
|
|
bool callIsSmall(const Function *F);
|
2010-06-09 15:11:37 +00:00
|
|
|
|
2012-03-16 05:51:52 +00:00
|
|
|
/// \brief Utility to calculate the size and a few similar metrics for a set
|
|
|
|
/// of basic blocks.
|
|
|
|
struct CodeMetrics {
|
|
|
|
/// \brief True if this function contains a call to setjmp or other functions
|
|
|
|
/// with attribute "returns twice" without having the attribute itself.
|
2011-12-18 20:35:43 +00:00
|
|
|
bool exposesReturnsTwice;
|
2010-06-09 15:11:37 +00:00
|
|
|
|
2012-03-16 05:51:52 +00:00
|
|
|
/// \brief True if this function calls itself.
|
2010-06-09 15:11:37 +00:00
|
|
|
bool isRecursive;
|
|
|
|
|
2012-03-16 05:51:52 +00:00
|
|
|
/// \brief True if this function contains one or more indirect branches.
|
2010-06-09 15:11:37 +00:00
|
|
|
bool containsIndirectBr;
|
|
|
|
|
2012-03-16 05:51:52 +00:00
|
|
|
/// \brief True if this function calls alloca (in the C sense).
|
2010-06-09 15:11:37 +00:00
|
|
|
bool usesDynamicAlloca;
|
|
|
|
|
2012-03-16 05:51:52 +00:00
|
|
|
/// \brief Number of instructions in the analyzed blocks.
|
|
|
|
unsigned NumInsts;
|
2010-06-09 15:11:37 +00:00
|
|
|
|
2012-03-16 05:51:52 +00:00
|
|
|
/// \brief Number of analyzed blocks.
|
|
|
|
unsigned NumBlocks;
|
|
|
|
|
|
|
|
/// \brief Keeps track of basic block code size estimates.
|
2010-06-09 15:11:37 +00:00
|
|
|
DenseMap<const BasicBlock *, unsigned> NumBBInsts;
|
|
|
|
|
2012-03-16 05:51:52 +00:00
|
|
|
/// \brief Keep track of the number of calls to 'big' functions.
|
2010-06-09 15:11:37 +00:00
|
|
|
unsigned NumCalls;
|
2011-10-01 01:27:56 +00:00
|
|
|
|
2012-03-16 05:51:52 +00:00
|
|
|
/// \brief The number of calls to internal functions with a single caller.
|
|
|
|
///
|
|
|
|
/// These are likely targets for future inlining, likely exposed by
|
|
|
|
/// interleaved devirtualization.
|
2010-09-09 20:32:23 +00:00
|
|
|
unsigned NumInlineCandidates;
|
2010-06-09 15:11:37 +00:00
|
|
|
|
2012-03-16 05:51:52 +00:00
|
|
|
/// \brief How many instructions produce vector values.
|
|
|
|
///
|
|
|
|
/// The inliner is more aggressive with inlining vector kernels.
|
2010-06-09 15:11:37 +00:00
|
|
|
unsigned NumVectorInsts;
|
|
|
|
|
2012-03-16 05:51:52 +00:00
|
|
|
/// \brief How many 'ret' instructions the blocks contain.
|
2010-06-09 15:11:37 +00:00
|
|
|
unsigned NumRets;
|
|
|
|
|
2011-12-18 20:35:43 +00:00
|
|
|
CodeMetrics() : exposesReturnsTwice(false), isRecursive(false),
|
2011-10-01 01:27:56 +00:00
|
|
|
containsIndirectBr(false), usesDynamicAlloca(false),
|
2010-09-09 20:32:23 +00:00
|
|
|
NumInsts(0), NumBlocks(0), NumCalls(0),
|
2011-10-01 01:27:56 +00:00
|
|
|
NumInlineCandidates(0), NumVectorInsts(0),
|
2010-06-09 15:11:37 +00:00
|
|
|
NumRets(0) {}
|
|
|
|
|
2012-03-16 05:51:52 +00:00
|
|
|
/// \brief Add information about a block to the current state.
|
2011-10-01 01:39:05 +00:00
|
|
|
void analyzeBasicBlock(const BasicBlock *BB, const TargetData *TD = 0);
|
2010-06-09 15:11:37 +00:00
|
|
|
|
2012-03-16 05:51:52 +00:00
|
|
|
/// \brief Add information about a function to the current state.
|
2011-10-01 01:39:05 +00:00
|
|
|
void analyzeFunction(Function *F, const TargetData *TD = 0);
|
2010-06-09 15:11:37 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|