@@ -2420,43 +2420,36 @@ bool AMDGPULegalizerInfo::legalizeGlobalValue(
24202420 }
24212421
24222422 // TODO: We could emit code to handle the initialization somewhere.
2423- if (!AMDGPUTargetLowering::hasDefinedInitializer (GV)) {
2424- const SITargetLowering *TLI = ST.getTargetLowering ();
2425- if (!TLI->shouldUseLDSConstAddress (GV)) {
2426- MI.getOperand (1 ).setTargetFlags (SIInstrInfo::MO_ABS32_LO);
2427- return true ; // Leave in place;
2428- }
2423+ // We ignore the initializer for now and legalize it to allow selection.
2424+ // The initializer will anyway get errored out during assembly emission.
2425+ const SITargetLowering *TLI = ST.getTargetLowering ();
2426+ if (!TLI->shouldUseLDSConstAddress (GV)) {
2427+ MI.getOperand (1 ).setTargetFlags (SIInstrInfo::MO_ABS32_LO);
2428+ return true ; // Leave in place;
2429+ }
24292430
2430- if (AS == AMDGPUAS::LOCAL_ADDRESS && GV->hasExternalLinkage ()) {
2431- Type *Ty = GV->getValueType ();
2432- // HIP uses an unsized array `extern __shared__ T s[]` or similar
2433- // zero-sized type in other languages to declare the dynamic shared
2434- // memory which size is not known at the compile time. They will be
2435- // allocated by the runtime and placed directly after the static
2436- // allocated ones. They all share the same offset.
2437- if (B.getDataLayout ().getTypeAllocSize (Ty).isZero ()) {
2438- // Adjust alignment for that dynamic shared memory array.
2439- MFI->setDynLDSAlign (B.getDataLayout (), *cast<GlobalVariable>(GV));
2440- LLT S32 = LLT::scalar (32 );
2441- auto Sz =
2442- B.buildIntrinsic (Intrinsic::amdgcn_groupstaticsize, {S32}, false );
2443- B.buildIntToPtr (DstReg, Sz);
2444- MI.eraseFromParent ();
2445- return true ;
2446- }
2431+ if (AS == AMDGPUAS::LOCAL_ADDRESS && GV->hasExternalLinkage ()) {
2432+ Type *Ty = GV->getValueType ();
2433+ // HIP uses an unsized array `extern __shared__ T s[]` or similar
2434+ // zero-sized type in other languages to declare the dynamic shared
2435+ // memory which size is not known at the compile time. They will be
2436+ // allocated by the runtime and placed directly after the static
2437+ // allocated ones. They all share the same offset.
2438+ if (B.getDataLayout ().getTypeAllocSize (Ty).isZero ()) {
2439+ // Adjust alignment for that dynamic shared memory array.
2440+ MFI->setDynLDSAlign (B.getDataLayout (), *cast<GlobalVariable>(GV));
2441+ LLT S32 = LLT::scalar (32 );
2442+ auto Sz =
2443+ B.buildIntrinsic (Intrinsic::amdgcn_groupstaticsize, {S32}, false );
2444+ B.buildIntToPtr (DstReg, Sz);
2445+ MI.eraseFromParent ();
2446+ return true ;
24472447 }
2448-
2449- B.buildConstant (
2450- DstReg,
2451- MFI->allocateLDSGlobal (B.getDataLayout (), *cast<GlobalVariable>(GV)));
2452- MI.eraseFromParent ();
2453- return true ;
24542448 }
24552449
2456- const Function &Fn = MF.getFunction ();
2457- DiagnosticInfoUnsupported BadInit (
2458- Fn, " unsupported initializer for address space" , MI.getDebugLoc ());
2459- Fn.getContext ().diagnose (BadInit);
2450+ B.buildConstant (DstReg, MFI->allocateLDSGlobal (B.getDataLayout (),
2451+ *cast<GlobalVariable>(GV)));
2452+ MI.eraseFromParent ();
24602453 return true ;
24612454 }
24622455
0 commit comments