Skip to content

Commit b6de31c

Browse files
lwesiersgfxbot
authored andcommitted
FunctionUpgrader for LinkMultiRateShaders
Change-Id: Ib3f4f4f6fdba2a2267547975f447e10a07292f7d
1 parent 62765df commit b6de31c

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

IGC/Compiler/Optimizer/LinkMultiRateShaders.cpp

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3636
#include "common/LLVMWarningsPop.hpp"
3737
#include "LLVM3DBuilder/BuiltinsFrontend.hpp"
3838

39+
#include "common/FunctionUpgrader.h"
40+
3941
using namespace IGC;
4042
using namespace IGC::IGCMD;
4143
using namespace llvm;
@@ -215,10 +217,14 @@ Function* LinkMultiRateShader::PatchSamplePhaseSignature(
215217
Module* M = samplePhase->getParent();
216218
CodeGenContext* ctx = getAnalysis<CodeGenContextWrapper>().getCodeGenContext();
217219
LLVM3DBuilder<> builder(samplePhase->getContext(), ctx->platform.getPlatformInfo());
218-
220+
221+
FunctionUpgrader FuncUpgrader;
222+
223+
FuncUpgrader.SetFunctionToUpgrade(samplePhase);
224+
219225
// find all the phase inputs
220226
Function* phaseInput = GenISAIntrinsic::getDeclaration(M, GenISAIntrinsic::GenISA_PHASE_INPUT);
221-
Value* sampleIndex = new llvm::Argument(builder.getInt32Ty(), "", samplePhase);
227+
Value* sampleIndex = FuncUpgrader.AddArgument("", builder.getInt32Ty());
222228

223229
SmallVector<Type*, 10> funcSignature;
224230
funcSignature.push_back(builder.getInt32Ty());
@@ -238,7 +244,7 @@ Function* LinkMultiRateShader::PatchSamplePhaseSignature(
238244
}
239245
else
240246
{
241-
arg = new llvm::Argument(inst->getType(), "", samplePhase);
247+
arg = FuncUpgrader.AddArgument("", inst->getType());
242248
funcSignature.push_back(inst->getType());
243249
linkArguments[index] = arg;
244250
linkSignature[index] = inputLocation++;
@@ -247,7 +253,16 @@ Function* LinkMultiRateShader::PatchSamplePhaseSignature(
247253
}
248254
}
249255
}
250-
256+
257+
Function* newSamplePhase = FuncUpgrader.RebuildFunction();
258+
259+
samplePhase->eraseFromParent();
260+
samplePhase = newSamplePhase;
261+
samplePhase->addFnAttr(llvm::Attribute::AlwaysInline);
262+
sampleIndex = FuncUpgrader.GetArgumentFromRebuild(sampleIndex);
263+
264+
FuncUpgrader.Clean();
265+
251266
// Replace sample index intrinsic
252267
Function* SGV = GenISAIntrinsic::getDeclaration(
253268
M,
@@ -325,7 +340,6 @@ Function* LinkMultiRateShader::PatchSamplePhaseSignature(
325340
}
326341
}
327342

328-
329343
Function* rtWrite = GenISAIntrinsic::getDeclaration(
330344
M,
331345
GenISAIntrinsic::GenISA_RTWrite,
@@ -342,7 +356,6 @@ Function* LinkMultiRateShader::PatchSamplePhaseSignature(
342356
}
343357
}
344358

345-
346359
Function* dualBlend = GenISAIntrinsic::getDeclaration(
347360
M,
348361
GenISAIntrinsic::GenISA_RTDualBlendSource,
@@ -359,22 +372,5 @@ Function* LinkMultiRateShader::PatchSamplePhaseSignature(
359372
}
360373
}
361374

362-
// Create new function with the right signature
363-
FunctionType* signature = FunctionType::get(builder.getVoidTy(), funcSignature, false);
364-
Function* newSamplePhase = Function::Create(signature, GlobalValue::PrivateLinkage, "samplePhase", M);
365-
newSamplePhase->addFnAttr(llvm::Attribute::AlwaysInline);
366-
367-
newSamplePhase->getBasicBlockList().splice(
368-
newSamplePhase->begin(),
369-
samplePhase->getBasicBlockList());
370-
for(auto I = samplePhase->arg_begin(), E = samplePhase->arg_end(), I2 = newSamplePhase->arg_begin();
371-
I != E;
372-
++I, ++I2)
373-
{
374-
I->replaceAllUsesWith(&(*I2));
375-
}
376-
377-
samplePhase->eraseFromParent();
378-
379-
return newSamplePhase;
375+
return samplePhase;
380376
}

0 commit comments

Comments
 (0)