@@ -152,6 +152,24 @@ static void testGPRLimits(const char *RegName, bool TestW32W64,
152152 EXPECT_TRUE (ErrStr.empty ()) << ErrStr;
153153}
154154
155+ static void testDynamicVGPRLimits (StringRef CPUName, StringRef FS,
156+ TestFuncTy test) {
157+ auto TM = createAMDGPUTargetMachine (" amdgcn-amd-" , CPUName,
158+ " +dynamic-vgpr," + FS.str ());
159+ ASSERT_TRUE (TM) << " No target machine" ;
160+
161+ GCNSubtarget ST (TM->getTargetTriple (), std::string (TM->getTargetCPU ()),
162+ std::string (TM->getTargetFeatureString ()), *TM);
163+ ASSERT_TRUE (ST.getFeatureBits ().test (AMDGPU::FeatureDynamicVGPR));
164+
165+ std::stringstream Table;
166+ bool Success = testAndRecord (Table, ST, test);
167+ EXPECT_TRUE (Success && !PrintCpuRegLimits)
168+ << CPUName << " dynamic VGPR " << FS
169+ << " :\n Occ MinVGPR MaxVGPR\n "
170+ << Table.str () << ' \n ' ;
171+ }
172+
155173TEST (AMDGPU, TestVGPRLimitsPerOccupancy) {
156174 auto test = [](std::stringstream &OS, unsigned Occ, const GCNSubtarget &ST) {
157175 unsigned MaxVGPRNum = ST.getAddressableNumVGPRs ();
@@ -163,4 +181,48 @@ TEST(AMDGPU, TestVGPRLimitsPerOccupancy) {
163181 };
164182
165183 testGPRLimits (" VGPR" , true , test);
184+
185+ testDynamicVGPRLimits (" gfx1200" , " +wavefrontsize32" , test);
186+ testDynamicVGPRLimits (" gfx1200" ,
187+ " +wavefrontsize32,+dynamic-vgpr-block-size-32" , test);
188+ }
189+
190+ static void testAbsoluteLimits (StringRef CPUName, StringRef FS,
191+ unsigned ExpectedMinOcc, unsigned ExpectedMaxOcc,
192+ unsigned ExpectedMaxVGPRs) {
193+ auto TM = createAMDGPUTargetMachine (" amdgcn-amd-" , CPUName, FS);
194+ ASSERT_TRUE (TM) << " No target machine" ;
195+
196+ GCNSubtarget ST (TM->getTargetTriple (), std::string (TM->getTargetCPU ()),
197+ std::string (TM->getTargetFeatureString ()), *TM);
198+
199+ // Test function without attributes.
200+ LLVMContext Context;
201+ Module M (" " , Context);
202+ Function *Func =
203+ Function::Create (FunctionType::get (Type::getVoidTy (Context), false ),
204+ GlobalValue::ExternalLinkage, " testFunc" , &M);
205+ Func->setCallingConv (CallingConv::AMDGPU_CS_Chain);
206+ Func->addFnAttr (" amdgpu-flat-work-group-size" , " 1,32" );
207+
208+ auto Range = ST.getWavesPerEU (*Func);
209+ EXPECT_EQ (ExpectedMinOcc, Range.first ) << CPUName << ' ' << FS;
210+ EXPECT_EQ (ExpectedMaxOcc, Range.second ) << CPUName << ' ' << FS;
211+ EXPECT_EQ (ExpectedMaxVGPRs, ST.getMaxNumVGPRs (*Func)) << CPUName << ' ' << FS;
212+ EXPECT_EQ (ExpectedMaxVGPRs, ST.getAddressableNumVGPRs ())
213+ << CPUName << ' ' << FS;
214+
215+ // Function with requested 'amdgpu-waves-per-eu' in a valid range.
216+ Func->addFnAttr (" amdgpu-waves-per-eu" , " 10,12" );
217+ Range = ST.getWavesPerEU (*Func);
218+ EXPECT_EQ (10u , Range.first ) << CPUName << ' ' << FS;
219+ EXPECT_EQ (12u , Range.second ) << CPUName << ' ' << FS;
220+ }
221+
222+ TEST (AMDGPU, TestOccupancyAbsoluteLimits) {
223+ testAbsoluteLimits (" gfx1200" , " +wavefrontsize32" , 1 , 16 , 256 );
224+ testAbsoluteLimits (" gfx1200" , " +wavefrontsize32,+dynamic-vgpr" , 1 , 16 , 128 );
225+ testAbsoluteLimits (
226+ " gfx1200" , " +wavefrontsize32,+dynamic-vgpr,+dynamic-vgpr-block-size-32" ,
227+ 1 , 16 , 256 );
166228}
0 commit comments