This is an archive of the discontinued LLVM Phabricator instance.

[CUDA] Allow using integral non-type template parameters as launch_bounds attribute arguments.
ClosedPublic

Authored by tra on Apr 10 2015, 3:22 PM.

Details

Summary

Allow using integral non-type template parameters as launch_bounds attribute arguments.

  • Changed CUDALaunchBounds arguments from integers to Expr* so they can be saved in AST for instantiation, if needed.
  • Added support for template instantiation of launch_bounds attrubute.
  • Moved evaluation of launch_bounds arguments to NVPTXTargetCodeGenInfo:: SetTargetAttributes() where it can be done after template instantiation.
  • Amended test cases.

Diff Detail

Repository
rL LLVM

Event Timeline

tra updated this revision to Diff 23630.Apr 10 2015, 3:22 PM
tra retitled this revision from to [CUDA] Allow using integral non-type template parameters as launch_bounds attribute arguments..
tra updated this object.
tra edited the test plan for this revision. (Show Details)
tra added reviewers: rsmith, eliben.
tra added a subscriber: Unknown Object (MLST).
eliben edited edge metadata.Apr 13 2015, 9:40 AM

The change looks fine. I'm not an expert on the template instantiation code, so you'll need to get an OK from Richard or someone else more familiar with this part.

lib/CodeGen/TargetInfo.cpp
5082 ↗(On Diff #23630)

Can you just fold the FD->getAttr into the if () ? [it returns nullptr if the attr isn't there, I think]

5089 ↗(On Diff #23630)

This comment was there before, but ISTM that s/default/optional/ makes more sense. What do you think?

lib/Sema/SemaTemplateInstantiateDecl.cpp
205 ↗(On Diff #23630)

Document this function - what the arguments are, etc.

269 ↗(On Diff #23630)

Fold the dyn_cast into the if condition here?

test/SemaCUDA/launch_bounds.cu
13 ↗(On Diff #23630)

Can you add tests that use actual expressions?

Also a test that catches an invalid expression and complains as expected?

tra updated this revision to Diff 23709.Apr 13 2015, 6:24 PM
tra edited edge metadata.

Addressed review comments by eliben@ and aaron@

  • Improved argument type/value checking.
  • Added a warning on negative launch_bounds arguments and disabled corresponding PTX directive emission when that happens.
  • Added test cases for various invalid launch_bounds arguments.
tra added inline comments.Apr 13 2015, 6:26 PM
lib/CodeGen/TargetInfo.cpp
5082 ↗(On Diff #23630)

Done.

5089 ↗(On Diff #23630)

Indeed. Fixed.

lib/Sema/SemaTemplateInstantiateDecl.cpp
205 ↗(On Diff #23630)

Done.

269 ↗(On Diff #23630)

OK.

test/SemaCUDA/launch_bounds.cu
13 ↗(On Diff #23630)

Done and done.

rsmith added inline comments.Apr 14 2015, 4:01 AM
lib/CodeGen/TargetInfo.cpp
5082–5083 ↗(On Diff #23709)

You can use Expr::EvaluateKnownConstInt here.

5085 ↗(On Diff #23709)

getExtValue will assert if the int is wider than 64 bits. You should either add arbitrary width iN metadata here or put a range check on the value in Sema.

5094 ↗(On Diff #23709)

Likewise.

lib/Sema/SemaDeclAttr.cpp
3490 ↗(On Diff #23709)

It's better to use Sema::DiagnoseUnexpandedParameterPack to diagnose unexpanded packs. (In particular, it's sometimes valid to have an unexpanded pack here, if we're nested within a lambda-expression that is itself within a pack expansion, and DiagnoseUnexpandedParameterPack handles that case.)

3490 ↗(On Diff #23709)

If E->getType() is a dependent type, we presumably shouldn't reject here.

lib/Sema/SemaTemplateInstantiateDecl.cpp
210 ↗(On Diff #23709)

Can you refactor this to reuse the code from SemaDeclAttr rather than duplicating parts of it?

221–223 ↗(On Diff #23709)

As a general rule, if someone hands you an invalid ExprResult, it means they've already produced a diagnostic and you should not do so.

tra updated this revision to Diff 23790.Apr 15 2015, 11:36 AM

Addressed Richard Smith's review comments:

  • Consolidated attribute creation and argument checking into Sema::AddLaunchBoundsAttr() which is now used from both SemaDeclAttr.cpp and SemaTemplateInstantiateDecl.cpp
  • Let Expr::isIntegerConstantExpr() do the job of checking and reporting argument type errors.
  • Use DiagnoseUnexpandedParameterPack() to report parameter packs when we reject them.
tra added inline comments.Apr 15 2015, 11:42 AM
lib/CodeGen/TargetInfo.cpp
5082–5083 ↗(On Diff #23709)

Done.

5085 ↗(On Diff #23709)

Added code in Sema to explicitly check whether result fits in 32 bits.

5094 ↗(On Diff #23709)

Done.

lib/Sema/SemaDeclAttr.cpp
3490 ↗(On Diff #23709)

Removed. isIntegerConstantExpr() does a pretty good job reporting errors in expressions it attempts to evaluate.

3490 ↗(On Diff #23709)

Done.

lib/Sema/SemaTemplateInstantiateDecl.cpp
210 ↗(On Diff #23709)

Done.

221–223 ↗(On Diff #23709)

Fixed.

rsmith accepted this revision.Apr 17 2015, 4:21 PM
rsmith edited edge metadata.

LGTM with minor changes.

lib/Sema/SemaDeclAttr.cpp
3474–3475 ↗(On Diff #23790)

There's no fundamental reason why value dependence must always imply instantiation dependence (and there are cases that should probably be modelled as being value-dependent but not instantiation-dependent, per discussion in the C++ committee, but we don't do so yet). Please also check for value-dependence when you check for instantiation-dependence.

3507 ↗(On Diff #23790)

This comment seems out-of-place since it applies to dependent and non-dependent cases.

lib/Sema/SemaTemplateInstantiateDecl.cpp
213 ↗(On Diff #23790)

This declaration, while correct, looks suspicious because only the second variable is initialized. Maybe declare MaxThreads below at the point where you assign to it, and declare MinBlocks immediately before the if (Attr.getMinBlocks()) line?

267 ↗(On Diff #23790)

Add a newline between these, please.

This revision is now accepted and ready to land.Apr 17 2015, 4:21 PM
tra updated this revision to Diff 23979.Apr 17 2015, 5:17 PM
tra edited edge metadata.

Few more changes to address Richard's comments.

tra added inline comments.Apr 17 2015, 5:18 PM
lib/Sema/SemaDeclAttr.cpp
3474–3475 ↗(On Diff #23790)

Considering that we only care whether we can evaluate the expression or not, I've replaced isInstantiationDependent() with isValueDependent() and removed the assert.

3507 ↗(On Diff #23790)

Removed.

lib/Sema/SemaTemplateInstantiateDecl.cpp
213 ↗(On Diff #23790)

OK.

267 ↗(On Diff #23790)

Done.

This revision was automatically updated to reflect the committed changes.