summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDavid Bolvansky <david.bolvansky@gmail.com>2018-07-31 14:25:24 +0000
committerDavid Bolvansky <david.bolvansky@gmail.com>2018-07-31 14:25:24 +0000
commit99862d39d7c23ff9efdb3f3a309840a03b924d66 (patch)
tree6250db676537cbefaf400fb2630fd6cd2af639b3 /include
parent8838d03a84a1ff78cf07270dd4e8f64e1915bad7 (diff)
Enrich inline messages
Summary: This patch improves Inliner to provide causes/reasons for negative inline decisions. 1. It adds one new message field to InlineCost to report causes for Always and Never instances. All Never and Always instantiations must provide a simple message. 2. Several functions that used to return the inlining results as boolean are changed to return InlineResult which carries the cause for negative decision. 3. Changed remark priniting and debug output messages to provide the additional messages and related inline cost. 4. Adjusted tests for changed printing. Patch by: yrouban (Yevgeny Rouban) Reviewers: craig.topper, sammccall, sgraenitz, NutshellySima, shchenz, chandlerc, apilipenko, javed.absar, tejohnson, dblaikie, sanjoy, eraman, xbolva00 Reviewed By: tejohnson, xbolva00 Subscribers: xbolva00, llvm-commits, arsenm, mehdi_amini, eraman, haicheng, steven_wu, dexonsmith Differential Revision: https://reviews.llvm.org/D49412 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338387 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/Analysis/InlineCost.h35
-rw-r--r--include/llvm/IR/DiagnosticInfo.h1
-rw-r--r--include/llvm/Transforms/Utils/Cloning.h18
3 files changed, 42 insertions, 12 deletions
diff --git a/include/llvm/Analysis/InlineCost.h b/include/llvm/Analysis/InlineCost.h
index 8c412057fb8..529fb75bec9 100644
--- a/include/llvm/Analysis/InlineCost.h
+++ b/include/llvm/Analysis/InlineCost.h
@@ -74,8 +74,15 @@ class InlineCost {
/// The adjusted threshold against which this cost was computed.
const int Threshold;
+ /// Must be set for Always and Never instances.
+ const char *Reason = nullptr;
+
// Trivial constructor, interesting logic in the factory functions below.
- InlineCost(int Cost, int Threshold) : Cost(Cost), Threshold(Threshold) {}
+ InlineCost(int Cost, int Threshold, const char *Reason = nullptr)
+ : Cost(Cost), Threshold(Threshold), Reason(Reason) {
+ assert((isVariable() || Reason) &&
+ "Reason must be provided for Never or Always");
+ }
public:
static InlineCost get(int Cost, int Threshold) {
@@ -83,11 +90,11 @@ public:
assert(Cost < NeverInlineCost && "Cost crosses sentinel value");
return InlineCost(Cost, Threshold);
}
- static InlineCost getAlways() {
- return InlineCost(AlwaysInlineCost, 0);
+ static InlineCost getAlways(const char *Reason) {
+ return InlineCost(AlwaysInlineCost, 0, Reason);
}
- static InlineCost getNever() {
- return InlineCost(NeverInlineCost, 0);
+ static InlineCost getNever(const char *Reason) {
+ return InlineCost(NeverInlineCost, 0, Reason);
}
/// Test whether the inline cost is low enough for inlining.
@@ -112,12 +119,30 @@ public:
return Threshold;
}
+ /// Get the reason of Always or Never.
+ const char *getReason() const {
+ assert((Reason || isVariable()) &&
+ "InlineCost reason must be set for Always or Never");
+ return Reason;
+ }
+
/// Get the cost delta from the threshold for inlining.
/// Only valid if the cost is of the variable kind. Returns a negative
/// value if the cost is too high to inline.
int getCostDelta() const { return Threshold - getCost(); }
};
+/// InlineResult is basically true or false. For false results the message
+/// describes a reason why it is decided not to inline.
+struct InlineResult {
+ const char *message = nullptr;
+ InlineResult(bool result, const char *message = nullptr)
+ : message(result ? nullptr : (message ? message : "cost > threshold")) {}
+ InlineResult(const char *message = nullptr) : message(message) {}
+ operator bool() const { return !message; }
+ operator const char *() const { return message; }
+};
+
/// Thresholds to tune inline cost analysis. The inline cost analysis decides
/// the condition to apply a threshold and applies it. Otherwise,
/// DefaultThreshold is used. If a threshold is Optional, it is applied only
diff --git a/include/llvm/IR/DiagnosticInfo.h b/include/llvm/IR/DiagnosticInfo.h
index 81d4ae84bf0..b8fdae2fcad 100644
--- a/include/llvm/IR/DiagnosticInfo.h
+++ b/include/llvm/IR/DiagnosticInfo.h
@@ -414,6 +414,7 @@ public:
Argument(StringRef Key, const Value *V);
Argument(StringRef Key, const Type *T);
Argument(StringRef Key, StringRef S);
+ Argument(StringRef Key, const char *S) : Argument(Key, StringRef(S)) {};
Argument(StringRef Key, int N);
Argument(StringRef Key, float N);
Argument(StringRef Key, long N);
diff --git a/include/llvm/Transforms/Utils/Cloning.h b/include/llvm/Transforms/Utils/Cloning.h
index 7531fb2d69b..e4d6053b70b 100644
--- a/include/llvm/Transforms/Utils/Cloning.h
+++ b/include/llvm/Transforms/Utils/Cloning.h
@@ -22,6 +22,7 @@
#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/AssumptionCache.h"
+#include "llvm/Analysis/InlineCost.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/ValueHandle.h"
#include "llvm/Transforms/Utils/ValueMapper.h"
@@ -232,13 +233,16 @@ public:
/// and all varargs at the callsite will be passed to any calls to
/// ForwardVarArgsTo. The caller of InlineFunction has to make sure any varargs
/// are only used by ForwardVarArgsTo.
-bool InlineFunction(CallInst *C, InlineFunctionInfo &IFI,
- AAResults *CalleeAAR = nullptr, bool InsertLifetime = true);
-bool InlineFunction(InvokeInst *II, InlineFunctionInfo &IFI,
- AAResults *CalleeAAR = nullptr, bool InsertLifetime = true);
-bool InlineFunction(CallSite CS, InlineFunctionInfo &IFI,
- AAResults *CalleeAAR = nullptr, bool InsertLifetime = true,
- Function *ForwardVarArgsTo = nullptr);
+InlineResult InlineFunction(CallInst *C, InlineFunctionInfo &IFI,
+ AAResults *CalleeAAR = nullptr,
+ bool InsertLifetime = true);
+InlineResult InlineFunction(InvokeInst *II, InlineFunctionInfo &IFI,
+ AAResults *CalleeAAR = nullptr,
+ bool InsertLifetime = true);
+InlineResult InlineFunction(CallSite CS, InlineFunctionInfo &IFI,
+ AAResults *CalleeAAR = nullptr,
+ bool InsertLifetime = true,
+ Function *ForwardVarArgsTo = nullptr);
/// Clones a loop \p OrigLoop. Returns the loop and the blocks in \p
/// Blocks.