LLVM 23.0.0git
TransactionAcceptOrRevert.cpp
Go to the documentation of this file.
1//===- TransactionAcceptOrRevert.cpp - Check cost and accept/revert region ===//
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
14
15namespace llvm {
16
17static cl::opt<int> CostThreshold("sbvec-cost-threshold", cl::init(0),
19 cl::desc("Vectorization cost threshold."));
20
21namespace sandboxir {
22
24 const auto &SB = cast<RegionWithScore>(Rgn).getScoreboard();
25 [[maybe_unused]] auto CostBefore = SB.getBeforeCost();
26 [[maybe_unused]] auto CostAfter = SB.getAfterCost();
27 InstructionCost CostAfterMinusBefore = SB.getAfterCost() - SB.getBeforeCost();
28 LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "Cost gain: " << CostAfterMinusBefore
29 << " (before/after/threshold: " << CostBefore << "/"
30 << CostAfter << "/" << CostThreshold << ")\n");
31 // TODO: Print costs / write to remarks.
32 auto &Tracker = Rgn.getContext().getTracker();
33 if (CostAfterMinusBefore < -CostThreshold) {
34 bool HasChanges = !Tracker.empty();
36 LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "*** Transaction Accept ***\n");
37 return HasChanges;
38 }
39 // Revert the IR.
40 LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "*** Transaction Revert ***\n");
42 return false;
43}
44
45} // namespace sandboxir
46} // namespace llvm
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file defines an InstructionCost class that is used when calculating the cost of an instruction,...
#define LLVM_DEBUG(...)
Definition Debug.h:119
#define DEBUG_PREFIX
Definition Debug.h:19
Tracker & getTracker()
Definition Context.h:247
Context & getContext() const
Definition Region.h:169
The tracker collects all the change objects and implements the main API for saving / reverting / acce...
Definition Tracker.h:442
LLVM_ABI void revert()
Stops tracking and reverts to saved state.
Definition Tracker.cpp:341
bool empty() const
\Returns true if there are no changes tracked.
Definition Tracker.h:477
LLVM_ABI void accept()
Stops tracking and accept changes.
Definition Tracker.cpp:361
bool runOnRegion(Region &Rgn, const Analyses &A) final
\Returns true if it modifies R.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
static cl::opt< unsigned > CostThreshold("dfa-cost-threshold", cl::desc("Maximum cost accepted for the transformation"), cl::Hidden, cl::init(50))