@@ -136,15 +136,6 @@ void AMDGPUAsmPrinter::initTargetStreamer(Module &M) {
136
136
getTargetStreamer ()->getPALMetadata ()->readFromIR (M);
137
137
}
138
138
139
- uint64_t AMDGPUAsmPrinter::getMCExprValue (const MCExpr *Value, MCContext &Ctx) {
140
- int64_t Val;
141
- if (!Value->evaluateAsAbsolute (Val)) {
142
- Ctx.reportError (SMLoc (), " could not resolve expression when required." );
143
- return 0 ;
144
- }
145
- return static_cast <uint64_t >(Val);
146
- }
147
-
148
139
void AMDGPUAsmPrinter::emitEndOfAsmFile (Module &M) {
149
140
// Init target streamer if it has not yet happened
150
141
if (!IsTargetStreamerInitialized)
@@ -249,14 +240,14 @@ void AMDGPUAsmPrinter::emitFunctionBodyEnd() {
249
240
getNameWithPrefix (KernelName, &MF->getFunction ());
250
241
getTargetStreamer ()->EmitAmdhsaKernelDescriptor (
251
242
STM, KernelName, getAmdhsaKernelDescriptor (*MF, CurrentProgramInfo),
252
- getMCExprValue ( CurrentProgramInfo.NumVGPRsForWavesPerEU , Context) ,
253
- getMCExprValue (CurrentProgramInfo. NumSGPRsForWavesPerEU , Context) -
254
- IsaInfo::getNumExtraSGPRs (
255
- &STM, getMCExprValue (CurrentProgramInfo. VCCUsed , Context),
256
- getMCExprValue ( CurrentProgramInfo.FlatUsed , Context) ,
257
- getTargetStreamer ()->getTargetID ()->isXnackOnOrAny ()),
258
- getMCExprValue (CurrentProgramInfo. VCCUsed , Context),
259
- getMCExprValue ( CurrentProgramInfo.FlatUsed , Context) );
243
+ CurrentProgramInfo.NumVGPRsForWavesPerEU ,
244
+ MCBinaryExpr::createSub (
245
+ CurrentProgramInfo. NumSGPRsForWavesPerEU ,
246
+ AMDGPUMCExpr::createExtraSGPRs (
247
+ CurrentProgramInfo.VCCUsed , CurrentProgramInfo. FlatUsed ,
248
+ getTargetStreamer ()->getTargetID ()->isXnackOnOrAny (), Context ),
249
+ Context),
250
+ CurrentProgramInfo.VCCUsed , CurrentProgramInfo. FlatUsed );
260
251
261
252
Streamer.popSection ();
262
253
}
@@ -431,9 +422,10 @@ void AMDGPUAsmPrinter::emitCommonFunctionComments(
431
422
false );
432
423
}
433
424
434
- uint16_t AMDGPUAsmPrinter::getAmdhsaKernelCodeProperties (
425
+ const MCExpr * AMDGPUAsmPrinter::getAmdhsaKernelCodeProperties (
435
426
const MachineFunction &MF) const {
436
427
const SIMachineFunctionInfo &MFI = *MF.getInfo <SIMachineFunctionInfo>();
428
+ MCContext &Ctx = MF.getContext ();
437
429
uint16_t KernelCodeProperties = 0 ;
438
430
const GCNUserSGPRUsageInfo &UserSGPRInfo = MFI.getUserSGPRInfo ();
439
431
@@ -470,11 +462,19 @@ uint16_t AMDGPUAsmPrinter::getAmdhsaKernelCodeProperties(
470
462
amdhsa::KERNEL_CODE_PROPERTY_ENABLE_WAVEFRONT_SIZE32;
471
463
}
472
464
473
- if (getMCExprValue (CurrentProgramInfo.DynamicCallStack , MF.getContext ()) &&
474
- CodeObjectVersion >= AMDGPU::AMDHSA_COV5)
475
- KernelCodeProperties |= amdhsa::KERNEL_CODE_PROPERTY_USES_DYNAMIC_STACK;
476
-
477
- return KernelCodeProperties;
465
+ // CurrentProgramInfo.DynamicCallStack is a MCExpr and could be
466
+ // un-evaluatable at this point so it cannot be conditionally checked here.
467
+ // Instead, we'll directly shift the possibly unknown MCExpr into its place
468
+ // and bitwise-or it into KernelCodeProperties.
469
+ const MCExpr *KernelCodePropExpr =
470
+ MCConstantExpr::create (KernelCodeProperties, Ctx);
471
+ const MCExpr *OrValue = MCConstantExpr::create (
472
+ amdhsa::KERNEL_CODE_PROPERTY_USES_DYNAMIC_STACK_SHIFT, Ctx);
473
+ OrValue = MCBinaryExpr::createShl (CurrentProgramInfo.DynamicCallStack ,
474
+ OrValue, Ctx);
475
+ KernelCodePropExpr = MCBinaryExpr::createOr (KernelCodePropExpr, OrValue, Ctx);
476
+
477
+ return KernelCodePropExpr;
478
478
}
479
479
480
480
MCKernelDescriptor
@@ -497,11 +497,15 @@ AMDGPUAsmPrinter::getAmdhsaKernelDescriptor(const MachineFunction &MF,
497
497
498
498
KernelDescriptor.compute_pgm_rsrc1 = PI.getComputePGMRSrc1 (STM, Ctx);
499
499
KernelDescriptor.compute_pgm_rsrc2 = PI.getComputePGMRSrc2 (Ctx);
500
- KernelDescriptor.kernel_code_properties =
501
- MCConstantExpr::create (getAmdhsaKernelCodeProperties (MF), Ctx);
502
-
503
- assert (STM.hasGFX90AInsts () ||
504
- getMCExprValue (CurrentProgramInfo.ComputePGMRSrc3GFX90A , Ctx) == 0 );
500
+ KernelDescriptor.kernel_code_properties = getAmdhsaKernelCodeProperties (MF);
501
+
502
+ int64_t PGRM_Rsrc3 = 1 ;
503
+ bool EvaluatableRsrc3 =
504
+ CurrentProgramInfo.ComputePGMRSrc3GFX90A ->evaluateAsAbsolute (PGRM_Rsrc3);
505
+ (void )PGRM_Rsrc3;
506
+ (void )EvaluatableRsrc3;
507
+ assert (STM.hasGFX90AInsts () || !EvaluatableRsrc3 ||
508
+ static_cast <uint64_t >(PGRM_Rsrc3) == 0 );
505
509
KernelDescriptor.compute_pgm_rsrc3 = CurrentProgramInfo.ComputePGMRSrc3GFX90A ;
506
510
507
511
KernelDescriptor.kernarg_preload = MCConstantExpr::create (
0 commit comments