LLVM  16.0.0git
Classes | Namespaces | Macros | Typedefs | Functions | Variables
MLRegallocEvictAdvisor.cpp File Reference
#include "AllocationOrder.h"
#include "RegAllocEvictionAdvisor.h"
#include "RegAllocGreedy.h"
#include "llvm/Analysis/MLModelRunner.h"
#include "llvm/Analysis/TensorSpec.h"
#include "MLRegallocEvictAdvisor.h"
#include "llvm/Analysis/ReleaseModeModelRunner.h"
#include "llvm/CodeGen/CalcSpillWeights.h"
#include "llvm/CodeGen/LiveRegMatrix.h"
#include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineLoopInfo.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/CodeGen/RegisterClassInfo.h"
#include "llvm/CodeGen/VirtRegMap.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/PassRegistry.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorHandling.h"
#include <array>
#include <memory>
Include dependency graph for MLRegallocEvictAdvisor.cpp:

Go to the source code of this file.

Classes

class  llvm::RegAllocScoring
 

Namespaces

 llvm
 This is an optimization pass for GlobalISel generic memory operations.
 

Macros

#define DEBUG_TYPE   "ml-regalloc"
 
#define RA_EVICT_FEATURES_LIST(M)
 
#define RA_EVICT_FIRST_DEVELOPMENT_FEATURE(M)
 
#define RA_EVICT_REST_DEVELOPMENT_FEATURES(M)
 
#define DecisionName   "index_to_evict"
 
#define _FEATURE_IDX_SIMPLE(_, name, __, ___)   name
 
#define _FEATURE_IDX(A, B, C, D)   _FEATURE_IDX_SIMPLE(A, B, C, D),
 
#define _RESET(TYPE, NAME, SHAPE, __)
 
#define _DECL_FEATURES(type, name, shape, _)   TensorSpec::createSpec<type>(#name, shape),
 
#define SET(ID, TYPE, VAL)
 

Typedefs

using CompiledModelType = NoopSavedModelImpl
 

Functions

FunctionPassllvm::createRegAllocScoringPass ()
 When learning an eviction policy, extract score(reward) information, otherwise this does nothing. More...
 
 INITIALIZE_PASS (RegAllocScoring, "regallocscoringpass", "Register Allocation Scoring Pass", false, false) namespace
 
void extractInstructionFeatures (SmallVectorImpl< LRStartEndInfo > &LRPosInfo, MLModelRunner *RegallocRunner, function_ref< int(SlotIndex)> GetOpcode, function_ref< float(SlotIndex)> GetMBBFreq, function_ref< MachineBasicBlock *(SlotIndex)> GetMBBReference, const int InstructionsIndex, const int InstructionsMappingIndex, const int MBBFreqIndex, const int MBBMappingIndex, const SlotIndex LastIndex)
 
void extractMBBFrequency (const SlotIndex CurrentIndex, const size_t CurrentInstructionIndex, std::map< MachineBasicBlock *, size_t > &VisitedMBBs, function_ref< float(SlotIndex)> GetMBBFreq, MachineBasicBlock *CurrentMBBReference, MLModelRunner *RegallocRunner, const int MBBFreqIndex, const int MBBMappingIndex)
 

Variables

static const bool EnableDevelopmentFeatures = false
 
cl::opt< unsigned > EvictInterferenceCutoff
 

Macro Definition Documentation

◆ _DECL_FEATURES

#define _DECL_FEATURES (   type,
  name,
  shape,
  _ 
)    TensorSpec::createSpec<type>(#name, shape),

◆ _FEATURE_IDX

#define _FEATURE_IDX (   A,
  B,
  C,
  D 
)    _FEATURE_IDX_SIMPLE(A, B, C, D),

◆ _FEATURE_IDX_SIMPLE

#define _FEATURE_IDX_SIMPLE (   _,
  name,
  __,
  ___ 
)    name

◆ _RESET

#define _RESET (   TYPE,
  NAME,
  SHAPE,
  __ 
)
Value:
std::memset(Runner.getTensorUntyped(FeatureIDs::NAME), 0, \
getTotalSize<TYPE>(SHAPE));

◆ DEBUG_TYPE

#define DEBUG_TYPE   "ml-regalloc"

Definition at line 45 of file MLRegallocEvictAdvisor.cpp.

◆ DecisionName

#define DecisionName   "index_to_evict"

◆ RA_EVICT_FEATURES_LIST

#define RA_EVICT_FEATURES_LIST (   M)

◆ RA_EVICT_FIRST_DEVELOPMENT_FEATURE

#define RA_EVICT_FIRST_DEVELOPMENT_FEATURE (   M)

◆ RA_EVICT_REST_DEVELOPMENT_FEATURES

#define RA_EVICT_REST_DEVELOPMENT_FEATURES (   M)

◆ SET

#define SET (   ID,
  TYPE,
  VAL 
)
Value:
do { \
Runner->getTensor<TYPE>(FeatureIDs::ID)[Pos] = static_cast<TYPE>(VAL); \
if (!DoNotNormalize.test(FeatureIDs::ID)) \
Largest[FeatureIDs::ID] = \
std::max(Largest[FeatureIDs::ID], static_cast<float>(VAL)); \
} while (false)

Typedef Documentation

◆ CompiledModelType

Definition at line 52 of file MLRegallocEvictAdvisor.cpp.

Function Documentation

◆ extractInstructionFeatures()

void extractInstructionFeatures ( SmallVectorImpl< LRStartEndInfo > &  LRPosInfo,
MLModelRunner RegallocRunner,
function_ref< int(SlotIndex)>  GetOpcode,
function_ref< float(SlotIndex)>  GetMBBFreq,
function_ref< MachineBasicBlock *(SlotIndex)>  GetMBBReference,
const int  InstructionsIndex,
const int  InstructionsMappingIndex,
const int  MBBFreqIndex,
const int  MBBMappingIndex,
const SlotIndex  LastIndex 
)

Definition at line 933 of file MLRegallocEvictAdvisor.cpp.

References A, B, and llvm::sort().

◆ extractMBBFrequency()

void extractMBBFrequency ( const SlotIndex  CurrentIndex,
const size_t  CurrentInstructionIndex,
std::map< MachineBasicBlock *, size_t > &  VisitedMBBs,
function_ref< float(SlotIndex)>  GetMBBFreq,
MachineBasicBlock CurrentMBBReference,
MLModelRunner RegallocRunner,
const int  MBBFreqIndex,
const int  MBBMappingIndex 
)

◆ INITIALIZE_PASS()

INITIALIZE_PASS ( RegAllocScoring  ,
"regallocscoringpass"  ,
"Register Allocation Scoring Pass ,
false  ,
false   
)

The ML evictor (commonalities between release and development mode)

This just calls Evaluate on the Runner, but in the development mode case, if we're just capturing the log of the default advisor, it needs to call the latter instead, so we need to pass all the necessary parameters for it. In the development case, it will also log.

Load the features of the given VirtReg (allocated or not) at column Pos, but if that can't be evicted, return false instead.

Definition at line 115 of file MLRegallocEvictAdvisor.cpp.

References _DECL_FEATURES, _FEATURE_IDX, _FEATURE_IDX_SIMPLE, _RESET, llvm::AnalysisUsage::addRequired(), llvm::append_range(), assert(), llvm::DecisionName, llvm::drop_begin(), llvm::LLVMContext::emitError(), EnableDevelopmentFeatures, llvm::FeatureCount, llvm::X86AS::FS, llvm::RegAllocEvictionAdvisorAnalysis::getAnalysisUsage(), llvm::Function::getContext(), llvm::MachineFunction::getFunction(), llvm::Value::getName(), llvm::MachineFunction::getName(), I, llvm::InputFeatures, Loops, M, llvm::None, NumberOfInterferences, llvm::PerLiveRangeShape, RA, RA_EVICT_FEATURES_LIST, RA_EVICT_FIRST_DEVELOPMENT_FEATURE, RA_EVICT_REST_DEVELOPMENT_FEATURES, llvm::MipsISD::Ret, T, and llvm::RISCVFenceField::W.

Variable Documentation

◆ EnableDevelopmentFeatures

const bool EnableDevelopmentFeatures = false
static

Definition at line 74 of file MLRegallocEvictAdvisor.cpp.

Referenced by INITIALIZE_PASS().

◆ EvictInterferenceCutoff

cl::opt<unsigned> EvictInterferenceCutoff
llvm::AArch64PACKey::ID
ID
Definition: AArch64BaseInfo.h:818
llvm::max
Expected< ExpressionValue > max(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:337