#include "llvm/Support/Debug.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/raw_ostream.h"
+#include <climits>
#include <limits>
using namespace llvm;
/// FIXME: if it is necessary to derive from InlineCostCallAnalyzer, note
/// the FIXME in onLoweredCall, when instantiating an InlineCostCallAnalyzer
class InlineCostCallAnalyzer final : public CallAnalyzer {
- const int CostUpperBound = INT_MAX - InlineConstants::InstrCost - 1;
const bool ComputeFullInlineCost;
int LoadEliminationCost = 0;
/// Bonus to be applied when percentage of vector instructions in callee is
BlockFrequencyInfo *CallerBFI);
/// Handle a capped 'int' increment for Cost.
- void addCost(int64_t Inc, int64_t UpperBound = INT_MAX) {
- assert(UpperBound > 0 && UpperBound <= INT_MAX && "invalid upper bound");
- Cost = std::min<int>(UpperBound, Cost + Inc);
+ void addCost(int64_t Inc) {
+ Inc = std::max<int64_t>(std::min<int64_t>(INT_MAX, Inc), INT_MIN);
+ Cost = std::max<int64_t>(std::min<int64_t>(INT_MAX, Inc + Cost), INT_MIN);
}
void onDisableSROA(AllocaInst *Arg) override {
static_cast<int64_t>(JumpTableSize) * InlineConstants::InstrCost +
4 * InlineConstants::InstrCost;
- addCost(JTCost, static_cast<int64_t>(CostUpperBound));
+ addCost(JTCost);
return;
}
int64_t SwitchCost =
ExpectedNumberOfCompare * 2 * InlineConstants::InstrCost;
- addCost(SwitchCost, static_cast<int64_t>(CostUpperBound));
+ addCost(SwitchCost);
}
void onMissedSimplification() override {
addCost(InlineConstants::InstrCost);