Skip to content

Commit 3b8a1d5

Browse files
committed
NFC: Migrate SpeculativeExecution to work on InstructionCost
This patch migrates cost values and arithmetic to work on InstructionCost. When the interfaces to TargetTransformInfo are changed, any InstructionCost state will propagate naturally. See this patch for the introduction of the type: https://reviews.llvm.org/D91174 See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2020-November/146408.html Reviewed By: david-arm Differential Revision: https://reviews.llvm.org/D95356
1 parent 754ab80 commit 3b8a1d5

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

llvm/lib/Transforms/Scalar/SpeculativeExecution.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ bool SpeculativeExecutionPass::runOnBasicBlock(BasicBlock &B) {
210210
return false;
211211
}
212212

213-
static unsigned ComputeSpeculationCost(const Instruction *I,
214-
const TargetTransformInfo &TTI) {
213+
static InstructionCost ComputeSpeculationCost(const Instruction *I,
214+
const TargetTransformInfo &TTI) {
215215
switch (Operator::getOpcode(I)) {
216216
case Instruction::GetElementPtr:
217217
case Instruction::Add:
@@ -255,7 +255,8 @@ static unsigned ComputeSpeculationCost(const Instruction *I,
255255
return TTI.getUserCost(I, TargetTransformInfo::TCK_SizeAndLatency);
256256

257257
default:
258-
return UINT_MAX; // Disallow anything not explicitly listed.
258+
return InstructionCost::getInvalid(); // Disallow anything not explicitly
259+
// listed.
259260
}
260261
}
261262

@@ -288,11 +289,11 @@ bool SpeculativeExecutionPass::considerHoistingFromTo(
288289
return true;
289290
};
290291

291-
unsigned TotalSpeculationCost = 0;
292+
InstructionCost TotalSpeculationCost = 0;
292293
unsigned NotHoistedInstCount = 0;
293294
for (const auto &I : FromBlock) {
294-
const unsigned Cost = ComputeSpeculationCost(&I, *TTI);
295-
if (Cost != UINT_MAX && isSafeToSpeculativelyExecute(&I) &&
295+
const InstructionCost Cost = ComputeSpeculationCost(&I, *TTI);
296+
if (Cost.isValid() && isSafeToSpeculativelyExecute(&I) &&
296297
AllPrecedingUsesFromBlockHoisted(&I)) {
297298
TotalSpeculationCost += Cost;
298299
if (TotalSpeculationCost > SpecExecMaxSpeculationCost)

0 commit comments

Comments
 (0)