//===- RegAllocEvictionAdvisor.h - Interference resolution ------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef LLVM_CODEGEN_REGALLOCEVICTIONADVISOR_H #define LLVM_CODEGEN_REGALLOCEVICTIONADVISOR_H #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallSet.h" #include "llvm/ADT/StringRef.h" #include "llvm/CodeGen/Register.h" #include "llvm/Config/llvm-config.h" #include "llvm/MC/MCRegister.h" #include "llvm/Pass.h" namespace llvm { class AllocationOrder; class LiveInterval; class LiveIntervals; class LiveRegMatrix; class MachineFunction; class MachineRegisterInfo; class RegisterClassInfo; class TargetRegisterInfo; class VirtRegMap; SmallVirtRegSet; // Live ranges pass through a number of stages as we try to allocate them. // Some of the stages may also create new live ranges: // // - Region splitting. // - Per-block splitting. // - Local splitting. // - Spilling. // // Ranges produced by one of the stages skip the previous stages when they are // dequeued. This improves performance because we can skip interference checks // that are unlikely to give any results. It also guarantees that the live // range splitting algorithm terminates, something that is otherwise hard to // ensure. enum LiveRangeStage { … }; /// Cost of evicting interference - used by default advisor, and the eviction /// chain heuristic in RegAllocGreedy. // FIXME: this can be probably made an implementation detail of the default // advisor, if the eviction chain logic can be refactored. struct EvictionCost { … }; /// Interface to the eviction advisor, which is responsible for making a /// decision as to which live ranges should be evicted (if any). class RAGreedy; class RegAllocEvictionAdvisor { … }; /// ImmutableAnalysis abstraction for fetching the Eviction Advisor. We model it /// as an analysis to decouple the user from the implementation insofar as /// dependencies on other analyses goes. The motivation for it being an /// immutable pass is twofold: /// - in the ML implementation case, the evaluator is stateless but (especially /// in the development mode) expensive to set up. With an immutable pass, we set /// it up once. /// - in the 'development' mode ML case, we want to capture the training log /// during allocation (this is a log of features encountered and decisions /// made), and then measure a score, potentially a few steps after allocation /// completes. So we need the properties of an immutable pass to keep the logger /// state around until we can make that measurement. /// /// Because we need to offer additional services in 'development' mode, the /// implementations of this analysis need to implement RTTI support. class RegAllocEvictionAdvisorAnalysis : public ImmutablePass { … }; /// Specialization for the API used by the analysis infrastructure to create /// an instance of the eviction advisor. template <> Pass *callDefaultCtor<RegAllocEvictionAdvisorAnalysis>(); RegAllocEvictionAdvisorAnalysis *createReleaseModeAdvisor(); RegAllocEvictionAdvisorAnalysis *createDevelopmentModeAdvisor(); // TODO: move to RegAllocEvictionAdvisor.cpp when we move implementation // out of RegAllocGreedy.cpp class DefaultEvictionAdvisor : public RegAllocEvictionAdvisor { … }; } // namespace llvm #endif // LLVM_CODEGEN_REGALLOCEVICTIONADVISOR_H