Skip to content

Commit

Permalink
Remove old pass-manager code
Browse files Browse the repository at this point in the history
Remove the wrappers for the legacy pass manager.
I needed to change one test. -stop-after didn’t work anymore, because
the legacy, code-gen pass manager didn’t find a pass with that name
(because it only exists as a npm pass now).
I think that could be improved by not running code-gen passes when a
-stop-after option is given.

One thing that’s missing in this change to get rid of the legacy code is
moving the code from runImpl functions into the run functions.
  • Loading branch information
Flakebi committed Dec 22, 2022
1 parent 5eb863e commit 069b489
Show file tree
Hide file tree
Showing 96 changed files with 23 additions and 3,335 deletions.
57 changes: 0 additions & 57 deletions lgc/builder/BuilderReplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,42 +41,6 @@
using namespace lgc;
using namespace llvm;

namespace {

// =====================================================================================================================
// Pass to replay Builder calls recorded by BuilderRecorder
class LegacyBuilderReplayer final : public ModulePass, BuilderRecorderMetadataKinds {
public:
LegacyBuilderReplayer() : ModulePass(ID), m_impl(nullptr) {}
LegacyBuilderReplayer(Pipeline *pipeline);

void getAnalysisUsage(AnalysisUsage &analysisUsage) const override {
analysisUsage.addRequired<LegacyPipelineStateWrapper>();
}

bool runOnModule(Module &module) override;

static char ID;

private:
LegacyBuilderReplayer(const LegacyBuilderReplayer &) = delete;
LegacyBuilderReplayer &operator=(const LegacyBuilderReplayer &) = delete;

BuilderReplayer m_impl;
};

} // namespace

char LegacyBuilderReplayer::ID = 0;

// =====================================================================================================================
// Create BuilderReplayer pass
//
// @param pipeline : Pipeline object
ModulePass *lgc::createLegacyBuilderReplayer(Pipeline *pipeline) {
return new LegacyBuilderReplayer(pipeline);
}

// =====================================================================================================================
// Constructor
//
Expand All @@ -98,23 +62,6 @@ bool BuilderReplayer::parsePass(llvm::StringRef params, llvm::ModulePassManager
return true;
}

// =====================================================================================================================
// Constructor
//
// @param pipeline : Pipeline object
LegacyBuilderReplayer::LegacyBuilderReplayer(Pipeline *pipeline) : ModulePass(ID), m_impl(pipeline) {
}

// =====================================================================================================================
// Run the BuilderReplayer pass on a module
//
// @param [in/out] module : LLVM module to be run on
// @returns : True if the module was modified by the transformation and false otherwise
bool LegacyBuilderReplayer::runOnModule(Module &module) {
PipelineState *pipelineState = getAnalysis<LegacyPipelineStateWrapper>().getPipelineState(&module);
return m_impl.runImpl(module, pipelineState);
}

// =====================================================================================================================
// Run the BuilderReplayer pass on a module
//
Expand Down Expand Up @@ -922,7 +869,3 @@ Value *BuilderReplayer::processCall(unsigned opcode, CallInst *call) {
}
}
}

// =====================================================================================================================
// Initializes the pass
INITIALIZE_PASS(LegacyBuilderReplayer, DEBUG_TYPE, "Replay LLPC builder calls", false, false)
2 changes: 1 addition & 1 deletion lgc/docs/LgcOverview.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ The front-end flow is:
- Where the front-end creates a pass manager for its own passes, it should call
`BuilderContext::PreparePassManager` to ensure it is suitably set up. It can optionally
use `PassManager::Create` to create the middle-end's subclass pass manager instead of
using the standard `legacy::PassManager`.
using the standard `PassManager`.
- For a shader compile, you're done: The IR module at this point is the result of
the compile, and can be stored away and kept for later linking with other shaders.

Expand Down
1 change: 1 addition & 0 deletions lgc/elfLinker/GlueShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "FetchShader.h"
#include "NullFragmentShader.h"
#include "lgc/state/PassManagerCache.h"
#include "llvm/IR/LegacyPassManager.h"

using namespace lgc;
using namespace llvm;
Expand Down
12 changes: 0 additions & 12 deletions lgc/include/lgc/builder/BuilderRecorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,6 @@
#include "llvm/IR/ValueHandle.h"
#endif

namespace llvm {

class ModulePass;
class PassRegistry;

void initializeLegacyBuilderReplayerPass(PassRegistry &);

} // namespace llvm

namespace lgc {

class PipelineState;
Expand Down Expand Up @@ -618,7 +609,4 @@ class BuilderRecorder final : public Builder, BuilderRecorderMetadataKinds {
bool m_omitOpcodes; // Omit opcodes on lgc.create.* function declarations
};

// Create BuilderReplayer pass
llvm::ModulePass *createLegacyBuilderReplayer(Pipeline *pipeline);

} // namespace lgc
20 changes: 0 additions & 20 deletions lgc/include/lgc/patch/FragColorExport.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,24 +126,4 @@ class LowerFragColorExport : public llvm::PassInfoMixin<LowerFragColorExport> {
llvm::SmallVector<llvm::Value *, 10> m_exportValues; // The value to be exported indexed by the hw render target.
};

// =====================================================================================================================
// Pass to lower color export calls
class LegacyLowerFragColorExport : public llvm::ModulePass {
public:
LegacyLowerFragColorExport();
LegacyLowerFragColorExport(const LegacyLowerFragColorExport &) = delete;
LegacyLowerFragColorExport &operator=(const LegacyLowerFragColorExport &) = delete;

void getAnalysisUsage(llvm::AnalysisUsage &analysisUsage) const override {
analysisUsage.addRequired<LegacyPipelineStateWrapper>();
analysisUsage.addRequired<LegacyPipelineShaders>();
}

virtual bool runOnModule(llvm::Module &module) override;

static char ID; // ID of this pass
private:
LowerFragColorExport m_impl;
};

} // namespace lgc
106 changes: 0 additions & 106 deletions lgc/include/lgc/patch/Patch.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,98 +37,11 @@
namespace llvm {

class PassBuilder;
class PassRegistry;

namespace legacy {

class PassManager;

} // namespace legacy

void initializeLegacyLowerFragColorExportPass(PassRegistry &);
void initializeLegacyLowerVertexFetchPass(PassRegistry &);
void initializeLegacyPatchBufferOpPass(PassRegistry &);
void initializeLegacyPatchCheckShaderCachePass(PassRegistry &);
void initializeLegacyPatchCopyShaderPass(PassRegistry &);
void initializeLegacyPatchEntryPointMutatePass(PassRegistry &);
void initializeLegacyPatchInOutImportExportPass(PassRegistry &);
void initializeLegacyPatchLlvmIrInclusionPass(PassRegistry &);
void initializeLegacyPatchLoadScalarizerPass(PassRegistry &);
void initializeLegacyPatchLoopMetadataPass(PassRegistry &);
void initializeLegacyPatchNullFragShaderPass(PassRegistry &);
void initializeLegacyPatchPeepholeOptPass(PassRegistry &);
void initializeLegacyPatchPreparePipelineAbiPass(PassRegistry &);
void initializeLegacyPatchResourceCollectPass(PassRegistry &);
void initializeLegacyPatchSetupTargetFeaturesPass(PassRegistry &);
void initializeLegacyPatchWorkaroundsPass(PassRegistry &);
void initializeLegacyPatchReadFirstLanePass(PassRegistry &);
void initializeLegacyPatchWaveSizeAdjustPass(PassRegistry &);
void initializeLegacyPatchImageDerivativesPass(PassRegistry &);
void initializeLegacyPatchInitializeWorkgroupMemoryPass(PassRegistry &);
void initializeLegacyPatchInvariantLoadsPass(PassRegistry &);
#if LLPC_BUILD_GFX11
void initializeLegacyPatchImageOpCollectPass(PassRegistry &);
#endif
} // namespace llvm

namespace lgc {

class LegacyPatchCheckShaderCache;

// Initialize passes for patching
//
// @param passRegistry : Pass registry
inline void initializePatchPasses(llvm::PassRegistry &passRegistry) {
initializeLegacyLowerFragColorExportPass(passRegistry);
initializeLegacyLowerVertexFetchPass(passRegistry);
initializeLegacyPatchBufferOpPass(passRegistry);
initializeLegacyPatchCheckShaderCachePass(passRegistry);
initializeLegacyPatchCopyShaderPass(passRegistry);
initializeLegacyPatchEntryPointMutatePass(passRegistry);
initializeLegacyPatchInOutImportExportPass(passRegistry);
initializeLegacyPatchLlvmIrInclusionPass(passRegistry);
initializeLegacyPatchLoadScalarizerPass(passRegistry);
initializeLegacyPatchLoopMetadataPass(passRegistry);
initializeLegacyPatchNullFragShaderPass(passRegistry);
initializeLegacyPatchPeepholeOptPass(passRegistry);
initializeLegacyPatchPreparePipelineAbiPass(passRegistry);
initializeLegacyPatchResourceCollectPass(passRegistry);
initializeLegacyPatchSetupTargetFeaturesPass(passRegistry);
initializeLegacyPatchWorkaroundsPass(passRegistry);
initializeLegacyPatchReadFirstLanePass(passRegistry);
initializeLegacyPatchWaveSizeAdjustPass(passRegistry);
initializeLegacyPatchImageDerivativesPass(passRegistry);
initializeLegacyPatchInitializeWorkgroupMemoryPass(passRegistry);
initializeLegacyPatchInvariantLoadsPass(passRegistry);
#if LLPC_BUILD_GFX11
initializeLegacyPatchImageOpCollectPass(passRegistry);
#endif
}

llvm::ModulePass *createLegacyLowerFragColorExport();
llvm::ModulePass *createLegacyLowerVertexFetch();
llvm::FunctionPass *createLegacyPatchBufferOp();
#if LLPC_BUILD_GFX11
llvm::ModulePass *createLegacyPatchImageOpCollect();
#endif
LegacyPatchCheckShaderCache *createLegacyPatchCheckShaderCache();
llvm::ModulePass *createLegacyPatchCopyShader();
llvm::ModulePass *createLegacyPatchEntryPointMutate();
llvm::ModulePass *createLegacyPatchInOutImportExport();
llvm::ModulePass *createLegacyPatchLlvmIrInclusion();
llvm::FunctionPass *createLegacyPatchLoadScalarizer();
llvm::LoopPass *createLegacyPatchLoopMetadata();
llvm::ModulePass *createLegacyPatchNullFragShader();
llvm::FunctionPass *createLegacyPatchPeepholeOpt();
llvm::ModulePass *createLegacyPatchPreparePipelineAbi();
llvm::ModulePass *createLegacyPatchResourceCollect();
llvm::ModulePass *createLegacyPatchSetupTargetFeatures();
llvm::ModulePass *createLegacyPatchWorkarounds();
llvm::FunctionPass *createLegacyPatchReadFirstLane();
llvm::ModulePass *createLegacyPatchWaveSizeAdjust();
llvm::ModulePass *createLegacyPatchImageDerivatives();
llvm::ModulePass *createLegacyPatchInitializeWorkgroupMemory();
llvm::FunctionPass *createLegacyPatchInvariantLoads();
class PipelineState;
class PassManager;

Expand Down Expand Up @@ -162,23 +75,4 @@ class Patch {
llvm::Function *m_entryPoint; // Entry-point
};

// =====================================================================================================================
// Represents the pass of LLVM patching operations, as the base class.
class LegacyPatch : public llvm::ModulePass, public Patch {
public:
explicit LegacyPatch(char &pid) : llvm::ModulePass(pid) {}
virtual ~LegacyPatch() {}

static void addPasses(PipelineState *pipelineState, llvm::legacy::PassManager &passMgr,
llvm::ModulePass *replayerPass, llvm::Timer *patchTimer, llvm::Timer *optTimer,
Pipeline::CheckShaderCacheFunc checkShaderCacheFunc, llvm::CodeGenOpt::Level optLevel);

private:
static void addOptimizationPasses(llvm::legacy::PassManager &passMgr, llvm::CodeGenOpt::Level optLevel);

LegacyPatch() = delete;
LegacyPatch(const LegacyPatch &) = delete;
LegacyPatch &operator=(const LegacyPatch &) = delete;
};

} // namespace lgc
19 changes: 0 additions & 19 deletions lgc/include/lgc/patch/PatchBufferOp.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,4 @@ class PatchBufferOp : public llvm::InstVisitor<PatchBufferOp>, public llvm::Pass
static constexpr unsigned MinMemOpLoopBytes = 256;
};

// =====================================================================================================================
// Represents the pass of LLVM patching operations for buffer operations
class LegacyPatchBufferOp final : public llvm::FunctionPass, public llvm::InstVisitor<LegacyPatchBufferOp> {
public:
LegacyPatchBufferOp();

bool runOnFunction(llvm::Function &function) override;

void getAnalysisUsage(llvm::AnalysisUsage &analysisUsage) const override;

static char ID; // NOLINT

private:
LegacyPatchBufferOp(const LegacyPatchBufferOp &) = delete;
LegacyPatchBufferOp &operator=(const LegacyPatchBufferOp &) = delete;

PatchBufferOp m_impl;
};

} // namespace lgc
30 changes: 0 additions & 30 deletions lgc/include/lgc/patch/PatchCheckShaderCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ namespace lgc {
// Represents the pass of LLVM patching operations for checking shader cache
class PatchCheckShaderCache : public Patch, public llvm::PassInfoMixin<PatchCheckShaderCache> {
public:
// NOTE: This constructor is only used by the LegacyPatchCheckShaderCache class and can be removed once
// the switch to the new pass manager is completed.
PatchCheckShaderCache() {}

PatchCheckShaderCache(Pipeline::CheckShaderCacheFunc callbackFunc);
Expand All @@ -62,32 +60,4 @@ class PatchCheckShaderCache : public Patch, public llvm::PassInfoMixin<PatchChec
Pipeline::CheckShaderCacheFunc m_callbackFunc;
};

// =====================================================================================================================
// Represents the pass of LLVM patching operations for checking shader cache
class LegacyPatchCheckShaderCache : public llvm::ModulePass {
public:
LegacyPatchCheckShaderCache();

void getAnalysisUsage(llvm::AnalysisUsage &analysisUsage) const override {
analysisUsage.addRequired<LegacyPipelineStateWrapper>();
analysisUsage.addRequired<LegacyPipelineShaders>();
}

virtual bool runOnModule(llvm::Module &module) override;

// Set the callback function that this pass uses to ask the front-end whether it wants to remove
// any shader stages. The function takes the LLVM IR module and a per-shader-stage array of input/output
// usage checksums, and it returns the shader stage mask with bits removed for shader stages that it wants
// removed.
void setCallbackFunction(Pipeline::CheckShaderCacheFunc callbackFunc) { m_impl.setCallbackFunction(callbackFunc); }

static char ID; // ID of this pass

private:
LegacyPatchCheckShaderCache(const LegacyPatchCheckShaderCache &) = delete;
LegacyPatchCheckShaderCache &operator=(const LegacyPatchCheckShaderCache &) = delete;

PatchCheckShaderCache m_impl;
};

} // namespace lgc
22 changes: 0 additions & 22 deletions lgc/include/lgc/patch/PatchCopyShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,4 @@ class PatchCopyShader : public Patch, public llvm::PassInfoMixin<PatchCopyShader
// the mapped location for each stream
};

// =====================================================================================================================
// Pass to generate copy shader if required
class LegacyPatchCopyShader : public llvm::ModulePass {
public:
static char ID;
LegacyPatchCopyShader();

bool runOnModule(llvm::Module &module) override;

void getAnalysisUsage(llvm::AnalysisUsage &analysisUsage) const override {
analysisUsage.addRequired<LegacyPipelineStateWrapper>();
analysisUsage.addRequired<LegacyPipelineShaders>();
// Pass does not preserve PipelineShaders as it adds a new shader.
}

private:
LegacyPatchCopyShader(const LegacyPatchCopyShader &) = delete;
LegacyPatchCopyShader &operator=(const LegacyPatchCopyShader &) = delete;

PatchCopyShader m_impl;
};

} // namespace lgc
21 changes: 0 additions & 21 deletions lgc/include/lgc/patch/PatchEntryPointMutate.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,25 +152,4 @@ class PatchEntryPointMutate : public Patch, public llvm::PassInfoMixin<PatchEntr
llvm::SmallVector<std::unique_ptr<UserDataUsage>, ShaderStageCount> m_userDataUsage;
};

// =====================================================================================================================
// The entry-point mutation pass
class LegacyPatchEntryPointMutate : public llvm::ModulePass {
public:
LegacyPatchEntryPointMutate();
LegacyPatchEntryPointMutate(const LegacyPatchEntryPointMutate &) = delete;
LegacyPatchEntryPointMutate &operator=(const LegacyPatchEntryPointMutate &) = delete;

void getAnalysisUsage(llvm::AnalysisUsage &analysisUsage) const override {
analysisUsage.addRequired<LegacyPipelineStateWrapper>();
analysisUsage.addRequired<LegacyPipelineShaders>();
// Does not preserve PipelineShaders because it replaces the entrypoints.
}

virtual bool runOnModule(llvm::Module &module) override;

static char ID; // ID of this pass
private:
PatchEntryPointMutate m_impl;
};

} // namespace lgc
Loading

0 comments on commit 069b489

Please sign in to comment.