LLVM 22.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
13
14namespace llvm {
15
16static cl::opt<int> CostThreshold("sbvec-cost-threshold", cl::init(0),
18 cl::desc("Vectorization cost threshold."));
19
20namespace sandboxir {
21
23 const auto &SB = 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:245
The main job of the Region is to point to new instructions generated by vectorization passes.
Definition Region.h:96
Context & getContext() const
Definition Region.h:148
const ScoreBoard & getScoreboard() const
\Returns the ScoreBoard data structure that keeps track of instr costs.
Definition Region.h:168
InstructionCost getBeforeCost() const
\Returns the cost of the Removed instructions.
Definition Region.h:48
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:346
bool empty() const
\Returns true if there are no changes tracked.
Definition Tracker.h:480
LLVM_ABI void accept()
Stops tracking and accept changes.
Definition Tracker.cpp:358
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:207
static cl::opt< int > CostThreshold("sbvec-cost-threshold", cl::init(0), cl::Hidden, cl::desc("Vectorization cost threshold."))