| 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 | |
| 14 | #include "llvm/Support/InstructionCost.h" |
| 15 | #include "llvm/Support/Format.h" |
| 16 | #include "llvm/Support/raw_ostream.h" |
| 17 | |
| 18 | using namespace llvm; |
| 19 | |
| 20 | void InstructionCost::print(raw_ostream &OS) const { |
| 21 | using UnsignedCostType = std::make_unsigned_t<CostType>; |
| 22 | if (isValid()) { |
| 23 | UnsignedCostType AbsValue = |
| 24 | (Value < 0) ? -((UnsignedCostType)Value) : ((UnsignedCostType)Value); |
| 25 | UnsignedCostType WholeNumber = AbsValue / CostGranularity; |
| 26 | UnsignedCostType Remainder = AbsValue % CostGranularity; |
| 27 | if (Value < 0) |
| 28 | OS << "-"; |
| 29 | UnsignedCostType RemainderHundreds = (Remainder * 100) / CostGranularity; |
| 30 | while (RemainderHundreds % 10 == 0 && RemainderHundreds) |
| 31 | RemainderHundreds /= 10; |
| 32 | OS << WholeNumber; |
| 33 | if (RemainderHundreds) |
| 34 | OS << "."<< RemainderHundreds; |
| 35 | } else { |
| 36 | OS << "Invalid"; |
| 37 | } |
| 38 | } |
| 39 |