LLVM 24.0.0git
InstructionCost.cpp
Go to the documentation of this file.
1//===- InstructionCost.cpp --------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8/// \file
9/// This file includes the function definitions for the InstructionCost class
10/// that is used when calculating the cost of an instruction, or a group of
11/// instructions.
12//===----------------------------------------------------------------------===//
13
16
17using namespace llvm;
18
20 using UnsignedCostType = std::make_unsigned_t<CostType>;
21 if (isValid()) {
22 UnsignedCostType AbsValue =
23 (Value < 0) ? -((UnsignedCostType)Value) : ((UnsignedCostType)Value);
24 UnsignedCostType WholeNumber = AbsValue / CostGranularity;
25 UnsignedCostType Remainder = AbsValue % CostGranularity;
26 if (Value < 0)
27 OS << "-";
28 UnsignedCostType RemainderHundreds = (Remainder * 100) / CostGranularity;
29 while (RemainderHundreds % 10 == 0 && RemainderHundreds)
30 RemainderHundreds /= 10;
31 OS << WholeNumber;
32 if (RemainderHundreds)
33 OS << "." << RemainderHundreds;
34 } else {
35 OS << "Invalid";
36 }
37}
This file defines an InstructionCost class that is used when calculating the cost of an instruction,...
LLVM_ABI void print(raw_ostream &OS) const
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.