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
17cl::opt<int> CostThreshold("sbvec-cost-threshold", cl::init(0), cl::Hidden,
18 cl::desc("Vectorization cost threshold."));
19
20namespace sandboxir {
21
23 const auto &SB = cast<RegionWithScore>(Rgn).getScoreboard();
24 [[maybe_unused]] auto CostBefore = SB.getBeforeCost();
25 [[maybe_unused]] auto CostAfter = SB.getAfterCost();
26 InstructionCost CostAfterMinusBefore = SB.getAfterCost() - SB.getBeforeCost();
27 LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "Cost gain: " << CostAfterMinusBefore
28 << " (before/after/threshold: " << CostBefore << "/"
29 << CostAfter << "/" << CostThreshold << ")\n");
30 // TODO: Print costs / write to remarks.
31 auto &Tracker = Rgn.getContext().getTracker();
32 if (CostAfterMinusBefore < -CostThreshold) {
33 bool HasChanges = !Tracker.empty();
35 LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "*** Transaction Accept ***\n");
36 return HasChanges;
37 }
38 // Revert the IR.
39 LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "*** Transaction Revert ***\n");
41 return false;
42}
43
44} // namespace sandboxir
45} // 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:248
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:450
LLVM_ABI void revert(bool RevertAll=false)
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:485
LLVM_ABI void accept(bool AcceptAll=false)
Stops tracking and accept changes.
Definition Tracker.cpp:371
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))