3131#include " llpcSpirvLower.h"
3232#include " llpcContext.h"
3333#include " llpcDebug.h"
34+ #include " llpcSpirvLowerAccessChain.h"
3435#include " llpcSpirvLowerUtil.h"
3536#include " lgc/Builder.h"
3637#include " lgc/LgcContext.h"
4445#include " llvm/Transforms/IPO/AlwaysInliner.h"
4546#include " llvm/Transforms/IPO/ForceFunctionAttrs.h"
4647#include " llvm/Transforms/IPO/FunctionAttrs.h"
48+ #include " llvm/Transforms/IPO/GlobalDCE.h"
4749#include " llvm/Transforms/IPO/InferFunctionAttrs.h"
4850#include " llvm/Transforms/InstCombine/InstCombine.h"
4951#include " llvm/Transforms/Instrumentation.h"
@@ -138,6 +140,30 @@ void SpirvLower::removeConstantExpr(Context *context, GlobalVariable *global) {
138140 replaceConstWithInsts (context, constVal);
139141}
140142
143+ // =====================================================================================================================
144+ // Add per-shader lowering passes to pass manager
145+ //
146+ // @param context : LLPC context
147+ // @param stage : Shader stage
148+ // @param [in/out] passMgr : Pass manager to add passes to
149+ // @param lowerTimer : Timer to time lower passes with, nullptr if not timing
150+ void SpirvLower::addPasses (Context *context, ShaderStage stage, lgc::PassManager &passMgr, Timer *lowerTimer) {
151+ // Manually add a target-aware TLI pass, so optimizations do not think that we have library functions.
152+ context->getLgcContext ()->preparePassManager (passMgr);
153+
154+ // Start timer for lowering passes.
155+ if (lowerTimer)
156+ LgcContext::createAndAddStartStopTimer (passMgr, lowerTimer, true );
157+
158+ // Function inlining. Use the "always inline" pass, since we want to inline all functions, and
159+ // we marked (non-entrypoint) functions as "always inline" just after SPIR-V reading.
160+ passMgr.addPass (AlwaysInlinerPass ());
161+ passMgr.addPass (GlobalDCEPass ());
162+
163+ // Lower SPIR-V access chain
164+ passMgr.addPass (SpirvLowerAccessChain ());
165+ }
166+
141167// =====================================================================================================================
142168// Add per-shader lowering passes to pass manager
143169//
@@ -160,7 +186,7 @@ void LegacySpirvLower::addPasses(Context *context, ShaderStage stage, legacy::Pa
160186 passMgr.add (createGlobalDCEPass ());
161187
162188 // Lower SPIR-V access chain
163- passMgr.add (createSpirvLowerAccessChain ());
189+ passMgr.add (createLegacySpirvLowerAccessChain ());
164190
165191 // Lower SPIR-V terminators
166192 passMgr.add (createSpirvLowerTerminator ());
0 commit comments