aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
diff options
context:
space:
mode:
authorMircea Trofin <mtrofin@google.com>2020-07-22 09:24:15 -0700
committerMircea Trofin <mtrofin@google.com>2020-07-22 09:24:15 -0700
commit44a6bda19b40f2dfcbe92fc3d58bb6276c71ef78 (patch)
treeb5489851068f22e13b70b4afbe84aa5e161434b6 /llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
parent02f58373634fb87c728eb289a35b0819d7aafeee (diff)
downloadllvm-44a6bda19b40f2dfcbe92fc3d58bb6276c71ef78.zip
llvm-44a6bda19b40f2dfcbe92fc3d58bb6276c71ef78.tar.gz
llvm-44a6bda19b40f2dfcbe92fc3d58bb6276c71ef78.tar.bz2
Rename InlineFeatureAnalysis to FunctionPropertiesAnalysis
Rename the pass to be able to extend it to function properties other than inliner features. Reviewed By: mtrofin Differential Revision: https://reviews.llvm.org/D82044
Diffstat (limited to 'llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp')
-rw-r--r--llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp b/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
new file mode 100644
index 0000000..a0fc017
--- /dev/null
+++ b/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
@@ -0,0 +1,42 @@
+//===- FunctionPropertiesAnalysis.cpp - Function properties extraction ----===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements an analysis extracting function features, which may be
+// used by ML-driven policies, for example.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Analysis/FunctionPropertiesAnalysis.h"
+#include "llvm/IR/Instructions.h"
+
+using namespace llvm;
+
+AnalysisKey FunctionPropertiesAnalysis::Key;
+
+FunctionPropertiesAnalysis::Result
+FunctionPropertiesAnalysis::run(const Function &F,
+ FunctionAnalysisManager &FAM) {
+ Result Ret;
+ Ret.Uses = ((!F.hasLocalLinkage()) ? 1 : 0) + F.getNumUses();
+ for (const auto &BB : F) {
+ ++Ret.BasicBlockCount;
+ if (const auto *BI = dyn_cast<BranchInst>(BB.getTerminator())) {
+ if (BI->isConditional())
+ Ret.BlocksReachedFromConditionalInstruction += BI->getNumSuccessors();
+ } else if (const auto *SI = dyn_cast<SwitchInst>(BB.getTerminator()))
+ Ret.BlocksReachedFromConditionalInstruction +=
+ (SI->getNumCases() + (nullptr != SI->getDefaultDest()));
+ for (const auto &I : BB)
+ if (auto *CS = dyn_cast<CallBase>(&I)) {
+ const auto *Callee = CS->getCalledFunction();
+ if (Callee && !Callee->isIntrinsic() && !Callee->isDeclaration())
+ ++Ret.DirectCallsToDefinedFunctions;
+ }
+ }
+ return Ret;
+} \ No newline at end of file