LLVM 23.0.0git
RegionWithScore.cpp
Go to the documentation of this file.
1//===- RegionWithScore.cpp - A Region with score tracking -----------------===//
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
11
12namespace llvm::sandboxir {
13
14InstructionCost ScoreBoard::getCost(Instruction *I) const {
15 auto *LLVMI = cast<llvm::Instruction>(I->Val);
16 SmallVector<const llvm::Value *> Operands(LLVMI->operands());
17 return TTI.getInstructionCost(LLVMI, Operands, CostKind);
18}
19
21 auto Cost = getCost(I);
22 if (Rgn.contains(I))
23 // If `I` is one the newly added ones, then we should adjust `AfterCost`
24 AfterCost -= Cost;
25 else
26 // If `I` is one of the original instructions (outside the region) then it
27 // is part of the original code, so adjust `BeforeCost`.
28 BeforeCost += Cost;
29}
30
31#ifndef NDEBUG
32void ScoreBoard::dump() const { dump(dbgs()); }
33#endif
34
37 const TargetTransformInfo &TTI) {
39 return std::make_unique<RegionWithScore>(F.getContext(), TTI);
40 });
41}
42
43} // namespace llvm::sandboxir
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
A sandboxir::User with operands, opcode and linked with previous/next instructions in an instruction ...
Definition Instruction.h:43
static SmallVector< std::unique_ptr< RegionWithScore > > createRegionsFromMD(Function &F, const TargetTransformInfo &TTI)
static SmallVector< std::unique_ptr< RegionT > > createRegionsFromMD(Function &F, RegionFactoryT Factory)
Definition Region.h:122
LLVM_ABI void remove(Instruction *I)
Mark I as a deleted instruction from the region.
LLVM_DUMP_METHOD void dump() const
InstructionCost Cost
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:207
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
TargetTransformInfo TTI
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559