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 = getVectorizeOptions(Rgn.getContext());
21 const auto &SB = cast<RegionWithScore>(Rgn).getScoreboard();
22 [[maybe_unused]] auto CostBefore = SB.getBeforeCost();
23 [[maybe_unused]] auto CostAfter = SB.getAfterCost();
24 InstructionCost CostAfterMinusBefore = SB.getAfterCost() - SB.getBeforeCost();
25 LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "Cost gain: " << CostAfterMinusBefore
26 << " (before/after/threshold: " << CostBefore << "/"
27 << CostAfter << "/" << Opts.sbvec_cost_threshold << ")\n");
28 // TODO: Print costs / write to remarks.
29 auto &Tracker = Rgn.getContext().getTracker();
30 if (CostAfterMinusBefore < -Opts.sbvec_cost_threshold) {
31 bool HasChanges = !Tracker.empty();
33 LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "*** Transaction Accept ***\n");
34 return HasChanges;
35 }
36 // Revert the IR.
37 LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "*** Transaction Revert ***\n");
39 return false;
40}
41
42} // namespace sandboxir
43} // 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: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
const VectorizeOptions & getVectorizeOptions(const LLVMContext &C)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559