LLVM 24.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
17namespace sandboxir {
18
20 const VectorizeOptions &Opts =
21 Rgn.getContext().getLibraryOptions().get<VectorizeOptions>();
22 const auto &SB = cast<RegionWithScore>(Rgn).getScoreboard();
23 [[maybe_unused]] auto CostBefore = SB.getBeforeCost();
24 [[maybe_unused]] auto CostAfter = SB.getAfterCost();
25 InstructionCost CostAfterMinusBefore = SB.getAfterCost() - SB.getBeforeCost();
26 LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "Cost gain: " << CostAfterMinusBefore
27 << " (before/after/threshold: " << CostBefore << "/"
28 << CostAfter << "/" << Opts.sbvec_cost_threshold << ")\n");
29 // TODO: Print costs / write to remarks.
30 auto &Tracker = Rgn.getContext().getTracker();
31 if (CostAfterMinusBefore < -Opts.sbvec_cost_threshold) {
32 bool HasChanges = !Tracker.empty();
34 LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "*** Transaction Accept ***\n");
35 return HasChanges;
36 }
37 // Revert the IR.
38 LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "*** Transaction Revert ***\n");
40 return false;
41}
42
43} // namespace sandboxir
44} // 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
cl::LibraryOptionsContext & getLibraryOptions() const
Definition Context.h:240
Tracker & getTracker()
Definition Context.h:243
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.
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