#include "llvm/CodeGen/GlobalISel/Legalizer.h"
#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
#include "llvm/CodeGen/GlobalISel/CSEInfo.h"
#include "llvm/CodeGen/GlobalISel/CSEMIRBuilder.h"
#include "llvm/CodeGen/GlobalISel/GISelChangeObserver.h"
#include "llvm/CodeGen/GlobalISel/GISelKnownBits.h"
#include "llvm/CodeGen/GlobalISel/GISelWorkList.h"
#include "llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h"
#include "llvm/CodeGen/GlobalISel/LegalizerHelper.h"
#include "llvm/CodeGen/GlobalISel/LostDebugLocObserver.h"
#include "llvm/CodeGen/GlobalISel/Utils.h"
#include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
#include "llvm/CodeGen/TargetPassConfig.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/InitializePasses.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Error.h"
#define DEBUG_TYPE …
usingnamespacellvm;
static cl::opt<bool>
EnableCSEInLegalizer("enable-cse-in-legalizer",
cl::desc("Should enable CSE in Legalizer"),
cl::Optional, cl::init(false));
static cl::opt<bool> AllowGInsertAsArtifact(
"allow-ginsert-as-artifact",
cl::desc("Allow G_INSERT to be considered an artifact. Hack around AMDGPU "
"test infinite loops."),
cl::Optional, cl::init(true));
enum class DebugLocVerifyLevel { … };
#ifndef NDEBUG
static cl::opt<DebugLocVerifyLevel> VerifyDebugLocs(
"verify-legalizer-debug-locs",
cl::desc("Verify that debug locations are handled"),
cl::values(
clEnumValN(DebugLocVerifyLevel::None, "none", "No verification"),
clEnumValN(DebugLocVerifyLevel::Legalizations, "legalizations",
"Verify legalizations"),
clEnumValN(DebugLocVerifyLevel::LegalizationsAndArtifactCombiners,
"legalizations+artifactcombiners",
"Verify legalizations and artifact combines")),
cl::init(DebugLocVerifyLevel::Legalizations));
#else
static const DebugLocVerifyLevel VerifyDebugLocs = …;
#endif
char Legalizer::ID = …;
INITIALIZE_PASS_BEGIN(Legalizer, DEBUG_TYPE,
"Legalize the Machine IR a function's Machine IR", false,
false)
INITIALIZE_PASS_DEPENDENCY(TargetPassConfig)
INITIALIZE_PASS_DEPENDENCY(GISelCSEAnalysisWrapperPass)
INITIALIZE_PASS_DEPENDENCY(GISelKnownBitsAnalysis)
INITIALIZE_PASS_END(Legalizer, DEBUG_TYPE,
"Legalize the Machine IR a function's Machine IR", false,
false)
Legalizer::Legalizer() : … { … }
void Legalizer::getAnalysisUsage(AnalysisUsage &AU) const { … }
void Legalizer::init(MachineFunction &MF) { … }
static bool isArtifact(const MachineInstr &MI) { … }
InstListTy;
ArtifactListTy;
namespace {
class LegalizerWorkListManager : public GISelChangeObserver { … };
}
Legalizer::MFResult
Legalizer::legalizeMachineFunction(MachineFunction &MF, const LegalizerInfo &LI,
ArrayRef<GISelChangeObserver *> AuxObservers,
LostDebugLocObserver &LocObserver,
MachineIRBuilder &MIRBuilder,
GISelKnownBits *KB) { … }
bool Legalizer::runOnMachineFunction(MachineFunction &MF) { … }