[AMDGPU] Move AMDGPUCodeGenPassBuilder into AMDGPUTargetMachine(NFC) (#103720)
This will allow us to reuse the existing flags and the static functions while building the pipeline for new pass manager.
This commit is contained in:
committed by
GitHub
parent
c60da1a271
commit
a566635915
@@ -1,97 +0,0 @@
|
||||
//===- lib/Target/AMDGPU/AMDGPUCodeGenPassBuilder.cpp ---------------------===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "AMDGPUCodeGenPassBuilder.h"
|
||||
#include "AMDGPU.h"
|
||||
#include "AMDGPUISelDAGToDAG.h"
|
||||
#include "AMDGPUPerfHintAnalysis.h"
|
||||
#include "AMDGPUTargetMachine.h"
|
||||
#include "AMDGPUUnifyDivergentExitNodes.h"
|
||||
#include "SIFixSGPRCopies.h"
|
||||
#include "llvm/Analysis/UniformityAnalysis.h"
|
||||
#include "llvm/Transforms/Scalar/FlattenCFG.h"
|
||||
#include "llvm/Transforms/Scalar/Sink.h"
|
||||
#include "llvm/Transforms/Scalar/StructurizeCFG.h"
|
||||
#include "llvm/Transforms/Utils/FixIrreducible.h"
|
||||
#include "llvm/Transforms/Utils/LCSSA.h"
|
||||
#include "llvm/Transforms/Utils/UnifyLoopExits.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
AMDGPUCodeGenPassBuilder::AMDGPUCodeGenPassBuilder(
|
||||
GCNTargetMachine &TM, const CGPassBuilderOption &Opts,
|
||||
PassInstrumentationCallbacks *PIC)
|
||||
: CodeGenPassBuilder(TM, Opts, PIC) {
|
||||
Opt.RequiresCodeGenSCCOrder = true;
|
||||
// Exceptions and StackMaps are not supported, so these passes will never do
|
||||
// anything.
|
||||
// Garbage collection is not supported.
|
||||
disablePass<StackMapLivenessPass, FuncletLayoutPass,
|
||||
ShadowStackGCLoweringPass>();
|
||||
}
|
||||
|
||||
void AMDGPUCodeGenPassBuilder::addPreISel(AddIRPass &addPass) const {
|
||||
const bool LateCFGStructurize = AMDGPUTargetMachine::EnableLateStructurizeCFG;
|
||||
const bool DisableStructurizer = AMDGPUTargetMachine::DisableStructurizer;
|
||||
const bool EnableStructurizerWorkarounds =
|
||||
AMDGPUTargetMachine::EnableStructurizerWorkarounds;
|
||||
|
||||
if (TM.getOptLevel() > CodeGenOptLevel::None)
|
||||
addPass(FlattenCFGPass());
|
||||
|
||||
if (TM.getOptLevel() > CodeGenOptLevel::None)
|
||||
addPass(SinkingPass());
|
||||
|
||||
addPass(AMDGPULateCodeGenPreparePass(TM));
|
||||
|
||||
// Merge divergent exit nodes. StructurizeCFG won't recognize the multi-exit
|
||||
// regions formed by them.
|
||||
|
||||
addPass(AMDGPUUnifyDivergentExitNodesPass());
|
||||
|
||||
if (!LateCFGStructurize && !DisableStructurizer) {
|
||||
if (EnableStructurizerWorkarounds) {
|
||||
addPass(FixIrreduciblePass());
|
||||
addPass(UnifyLoopExitsPass());
|
||||
}
|
||||
|
||||
addPass(StructurizeCFGPass(/*SkipUniformRegions=*/false));
|
||||
}
|
||||
|
||||
addPass(AMDGPUAnnotateUniformValuesPass());
|
||||
|
||||
if (!LateCFGStructurize && !DisableStructurizer) {
|
||||
addPass(SIAnnotateControlFlowPass(TM));
|
||||
|
||||
// TODO: Move this right after structurizeCFG to avoid extra divergence
|
||||
// analysis. This depends on stopping SIAnnotateControlFlow from making
|
||||
// control flow modifications.
|
||||
addPass(AMDGPURewriteUndefForPHIPass());
|
||||
}
|
||||
|
||||
addPass(LCSSAPass());
|
||||
|
||||
if (TM.getOptLevel() > CodeGenOptLevel::Less)
|
||||
addPass(AMDGPUPerfHintAnalysisPass(TM));
|
||||
|
||||
// FIXME: Why isn't this queried as required from AMDGPUISelDAGToDAG, and why
|
||||
// isn't this in addInstSelector?
|
||||
addPass(RequireAnalysisPass<UniformityInfoAnalysis, Function>());
|
||||
}
|
||||
|
||||
void AMDGPUCodeGenPassBuilder::addAsmPrinter(AddMachinePass &addPass,
|
||||
CreateMCStreamer) const {
|
||||
// TODO: Add AsmPrinter.
|
||||
}
|
||||
|
||||
Error AMDGPUCodeGenPassBuilder::addInstSelector(AddMachinePass &addPass) const {
|
||||
addPass(AMDGPUISelDAGToDAGPass(TM));
|
||||
addPass(SIFixSGPRCopiesPass());
|
||||
addPass(SILowerI1CopiesPass());
|
||||
return Error::success();
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
//===- lib/Target/AMDGPU/AMDGPUCodeGenPassBuilder.h -----------*- 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_LIB_TARGET_AMDGPU_AMDGPUCODEGENPASSBUILDER_H
|
||||
#define LLVM_LIB_TARGET_AMDGPU_AMDGPUCODEGENPASSBUILDER_H
|
||||
|
||||
#include "llvm/MC/MCStreamer.h"
|
||||
#include "llvm/Passes/CodeGenPassBuilder.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
class GCNTargetMachine;
|
||||
|
||||
class AMDGPUCodeGenPassBuilder
|
||||
: public CodeGenPassBuilder<AMDGPUCodeGenPassBuilder, GCNTargetMachine> {
|
||||
public:
|
||||
AMDGPUCodeGenPassBuilder(GCNTargetMachine &TM,
|
||||
const CGPassBuilderOption &Opts,
|
||||
PassInstrumentationCallbacks *PIC);
|
||||
|
||||
void addPreISel(AddIRPass &addPass) const;
|
||||
void addAsmPrinter(AddMachinePass &, CreateMCStreamer) const;
|
||||
Error addInstSelector(AddMachinePass &) const;
|
||||
};
|
||||
|
||||
} // namespace llvm
|
||||
|
||||
#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUCODEGENPASSBUILDER_H
|
||||
@@ -7,15 +7,16 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
/// \file
|
||||
/// The AMDGPU target machine contains all of the hardware specific
|
||||
/// information needed to emit code for SI+ GPUs.
|
||||
/// This file contains both AMDGPU target machine and the CodeGen pass builder.
|
||||
/// The AMDGPU target machine contains all of the hardware specific information
|
||||
/// needed to emit code for SI+ GPUs in the legacy pass manager pipeline. The
|
||||
/// CodeGen pass builder handles the pass pipeline for new pass manager.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "AMDGPUTargetMachine.h"
|
||||
#include "AMDGPU.h"
|
||||
#include "AMDGPUAliasAnalysis.h"
|
||||
#include "AMDGPUCodeGenPassBuilder.h"
|
||||
#include "AMDGPUCtorDtorLowering.h"
|
||||
#include "AMDGPUExportClustering.h"
|
||||
#include "AMDGPUIGroupLP.h"
|
||||
@@ -40,6 +41,7 @@
|
||||
#include "Utils/AMDGPUBaseInfo.h"
|
||||
#include "llvm/Analysis/CGSCCPassManager.h"
|
||||
#include "llvm/Analysis/CallGraphSCCPass.h"
|
||||
#include "llvm/Analysis/UniformityAnalysis.h"
|
||||
#include "llvm/CodeGen/GlobalISel/CSEInfo.h"
|
||||
#include "llvm/CodeGen/GlobalISel/IRTranslator.h"
|
||||
#include "llvm/CodeGen/GlobalISel/InstructionSelect.h"
|
||||
@@ -64,10 +66,16 @@
|
||||
#include "llvm/Transforms/IPO/GlobalDCE.h"
|
||||
#include "llvm/Transforms/IPO/Internalize.h"
|
||||
#include "llvm/Transforms/Scalar.h"
|
||||
#include "llvm/Transforms/Scalar/FlattenCFG.h"
|
||||
#include "llvm/Transforms/Scalar/GVN.h"
|
||||
#include "llvm/Transforms/Scalar/InferAddressSpaces.h"
|
||||
#include "llvm/Transforms/Scalar/Sink.h"
|
||||
#include "llvm/Transforms/Scalar/StructurizeCFG.h"
|
||||
#include "llvm/Transforms/Utils.h"
|
||||
#include "llvm/Transforms/Utils/FixIrreducible.h"
|
||||
#include "llvm/Transforms/Utils/LCSSA.h"
|
||||
#include "llvm/Transforms/Utils/SimplifyLibCalls.h"
|
||||
#include "llvm/Transforms/Utils/UnifyLoopExits.h"
|
||||
#include "llvm/Transforms/Vectorize/LoadStoreVectorizer.h"
|
||||
#include <optional>
|
||||
|
||||
@@ -930,7 +938,7 @@ Error GCNTargetMachine::buildCodeGenPipeline(
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// AMDGPU Pass Setup
|
||||
// AMDGPU Legacy Pass Setup
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
std::unique_ptr<CSEConfigBase> llvm::AMDGPUPassConfig::getCSEConfig() const {
|
||||
@@ -1214,7 +1222,7 @@ MachineFunctionInfo *R600TargetMachine::createMachineFunctionInfo(
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// GCN Pass Setup
|
||||
// GCN Legacy Pass Setup
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
ScheduleDAGInstrs *GCNPassConfig::createMachineScheduler(
|
||||
@@ -1751,3 +1759,80 @@ bool GCNTargetMachine::parseMachineFunctionInfo(
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// AMDGPU CodeGen Pass Builder interface.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
AMDGPUCodeGenPassBuilder::AMDGPUCodeGenPassBuilder(
|
||||
GCNTargetMachine &TM, const CGPassBuilderOption &Opts,
|
||||
PassInstrumentationCallbacks *PIC)
|
||||
: CodeGenPassBuilder(TM, Opts, PIC) {
|
||||
Opt.RequiresCodeGenSCCOrder = true;
|
||||
// Exceptions and StackMaps are not supported, so these passes will never do
|
||||
// anything.
|
||||
// Garbage collection is not supported.
|
||||
disablePass<StackMapLivenessPass, FuncletLayoutPass,
|
||||
ShadowStackGCLoweringPass>();
|
||||
}
|
||||
|
||||
void AMDGPUCodeGenPassBuilder::addPreISel(AddIRPass &addPass) const {
|
||||
const bool LateCFGStructurize = AMDGPUTargetMachine::EnableLateStructurizeCFG;
|
||||
const bool DisableStructurizer = AMDGPUTargetMachine::DisableStructurizer;
|
||||
const bool EnableStructurizerWorkarounds =
|
||||
AMDGPUTargetMachine::EnableStructurizerWorkarounds;
|
||||
|
||||
if (TM.getOptLevel() > CodeGenOptLevel::None)
|
||||
addPass(FlattenCFGPass());
|
||||
|
||||
if (TM.getOptLevel() > CodeGenOptLevel::None)
|
||||
addPass(SinkingPass());
|
||||
|
||||
addPass(AMDGPULateCodeGenPreparePass(TM));
|
||||
|
||||
// Merge divergent exit nodes. StructurizeCFG won't recognize the multi-exit
|
||||
// regions formed by them.
|
||||
|
||||
addPass(AMDGPUUnifyDivergentExitNodesPass());
|
||||
|
||||
if (!LateCFGStructurize && !DisableStructurizer) {
|
||||
if (EnableStructurizerWorkarounds) {
|
||||
addPass(FixIrreduciblePass());
|
||||
addPass(UnifyLoopExitsPass());
|
||||
}
|
||||
|
||||
addPass(StructurizeCFGPass(/*SkipUniformRegions=*/false));
|
||||
}
|
||||
|
||||
addPass(AMDGPUAnnotateUniformValuesPass());
|
||||
|
||||
if (!LateCFGStructurize && !DisableStructurizer) {
|
||||
addPass(SIAnnotateControlFlowPass(TM));
|
||||
|
||||
// TODO: Move this right after structurizeCFG to avoid extra divergence
|
||||
// analysis. This depends on stopping SIAnnotateControlFlow from making
|
||||
// control flow modifications.
|
||||
addPass(AMDGPURewriteUndefForPHIPass());
|
||||
}
|
||||
|
||||
addPass(LCSSAPass());
|
||||
|
||||
if (TM.getOptLevel() > CodeGenOptLevel::Less)
|
||||
addPass(AMDGPUPerfHintAnalysisPass(TM));
|
||||
|
||||
// FIXME: Why isn't this queried as required from AMDGPUISelDAGToDAG, and why
|
||||
// isn't this in addInstSelector?
|
||||
addPass(RequireAnalysisPass<UniformityInfoAnalysis, Function>());
|
||||
}
|
||||
|
||||
void AMDGPUCodeGenPassBuilder::addAsmPrinter(AddMachinePass &addPass,
|
||||
CreateMCStreamer) const {
|
||||
// TODO: Add AsmPrinter.
|
||||
}
|
||||
|
||||
Error AMDGPUCodeGenPassBuilder::addInstSelector(AddMachinePass &addPass) const {
|
||||
addPass(AMDGPUISelDAGToDAGPass(TM));
|
||||
addPass(SIFixSGPRCopiesPass());
|
||||
addPass(SILowerI1CopiesPass());
|
||||
return Error::success();
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
#include "GCNSubtarget.h"
|
||||
#include "llvm/CodeGen/TargetPassConfig.h"
|
||||
#include "llvm/MC/MCStreamer.h"
|
||||
#include "llvm/Passes/CodeGenPassBuilder.h"
|
||||
#include "llvm/Target/TargetMachine.h"
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
@@ -47,7 +49,8 @@ public:
|
||||
~AMDGPUTargetMachine() override;
|
||||
|
||||
const TargetSubtargetInfo *getSubtargetImpl() const;
|
||||
const TargetSubtargetInfo *getSubtargetImpl(const Function &) const override = 0;
|
||||
const TargetSubtargetInfo *
|
||||
getSubtargetImpl(const Function &) const override = 0;
|
||||
|
||||
TargetLoweringObjectFile *getObjFileLowering() const override {
|
||||
return TLOF.get();
|
||||
@@ -94,9 +97,7 @@ public:
|
||||
|
||||
TargetTransformInfo getTargetTransformInfo(const Function &F) const override;
|
||||
|
||||
bool useIPRA() const override {
|
||||
return true;
|
||||
}
|
||||
bool useIPRA() const override { return true; }
|
||||
|
||||
Error buildCodeGenPipeline(ModulePassManager &MPM, raw_pwrite_stream &Out,
|
||||
raw_pwrite_stream *DwoOut,
|
||||
@@ -120,7 +121,7 @@ public:
|
||||
};
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// AMDGPU Pass Setup
|
||||
// AMDGPU Pass Setup - For Legacy Pass Manager.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
class AMDGPUPassConfig : public TargetPassConfig {
|
||||
@@ -158,6 +159,22 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// AMDGPU CodeGen Pass Builder interface.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
class AMDGPUCodeGenPassBuilder
|
||||
: public CodeGenPassBuilder<AMDGPUCodeGenPassBuilder, GCNTargetMachine> {
|
||||
public:
|
||||
AMDGPUCodeGenPassBuilder(GCNTargetMachine &TM,
|
||||
const CGPassBuilderOption &Opts,
|
||||
PassInstrumentationCallbacks *PIC);
|
||||
|
||||
void addPreISel(AddIRPass &addPass) const;
|
||||
void addAsmPrinter(AddMachinePass &, CreateMCStreamer) const;
|
||||
Error addInstSelector(AddMachinePass &) const;
|
||||
};
|
||||
|
||||
} // end namespace llvm
|
||||
|
||||
#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUTARGETMACHINE_H
|
||||
|
||||
@@ -51,7 +51,6 @@ add_llvm_target(AMDGPUCodeGen
|
||||
AMDGPUAtomicOptimizer.cpp
|
||||
AMDGPUAttributor.cpp
|
||||
AMDGPUCallLowering.cpp
|
||||
AMDGPUCodeGenPassBuilder.cpp
|
||||
AMDGPUCodeGenPrepare.cpp
|
||||
AMDGPUCombinerHelper.cpp
|
||||
AMDGPUCtorDtorLowering.cpp
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "R600TargetMachine.h"
|
||||
#include "AMDGPUTargetMachine.h"
|
||||
#include "R600.h"
|
||||
#include "R600CodeGenPassBuilder.h"
|
||||
#include "R600MachineScheduler.h"
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
#include "SIMachineFunctionInfo.h"
|
||||
#include "AMDGPUSubtarget.h"
|
||||
#include "AMDGPUTargetMachine.h"
|
||||
#include "GCNSubtarget.h"
|
||||
#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
|
||||
#include "SIRegisterInfo.h"
|
||||
|
||||
Reference in New Issue
Block a user