This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] Add HW_REG_SH_MEM_BASES symbolic name for s_getreg_b32
ClosedPublic

Authored by rampitec on Dec 28 2017, 2:21 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

rampitec created this revision.Dec 28 2017, 2:21 PM
artem.tamazov accepted this revision.Dec 29 2017, 5:23 AM
artem.tamazov added a subscriber: artem.tamazov.

LGTM

This revision is now accepted and ready to land.Dec 29 2017, 5:23 AM
artem.tamazov added a comment.EditedDec 29 2017, 5:29 AM

Actually HW_REG_SH_MEM_BASES is available starting from Gfx9. Is it possible to make it unavailable for Gfx7/8?

artem.tamazov requested changes to this revision.Dec 29 2017, 5:36 AM
artem.tamazov added inline comments.
lib/Target/AMDGPU/Utils/AMDGPUAsmUtils.cpp
71 ↗(On Diff #128307)

nullptr's seem to be unacceptable right away, look at lib\Target\AMDGPU\InstPrinter\AMDGPUInstPrinter.cpp line 1311:

O << "hwreg(";
if (ID_SYMBOLIC_FIRST_ <= Id && Id < ID_SYMBOLIC_LAST_) {
  O << IdSymbolic[Id];
} else {
  O << Id;
}

Also please consider lib\Target\AMDGPU\AsmParser\AMDGPUAsmParser.cpp, line 2950.

This revision now requires changes to proceed.Dec 29 2017, 5:36 AM
artem.tamazov added a comment.EditedDec 29 2017, 5:37 AM

Please also add some testcases to test\MC\AMDGPU\sopk.s and, possibly, to sopk-err.s.

rampitec updated this revision to Diff 128433.Jan 2 2018, 10:39 AM
rampitec marked an inline comment as done.

Updated per review comments.

rampitec updated this revision to Diff 128450.Jan 2 2018, 12:48 PM

Added ID_SYMBOLIC_FIRST_GFX9_ to enum.

rampitec updated this revision to Diff 128459.Jan 2 2018, 1:45 PM

Check for encoding in positive test.

artem.tamazov accepted this revision.Jan 9 2018, 8:20 AM

Some style-related fixes are desirable, otherwise LGTM.

lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
3168 ↗(On Diff #128459)

Just a recommendation:

const int Last = (isSI() || isCI() || isVI()) ? ID_SYMBOLIC_LAST_PRIOR_GFX9_
    : ID_SYMBOLIC_LAST_;

Not ideal anyway, but const at least. Up to you.

lib/Target/AMDGPU/InstPrinter/AMDGPUInstPrinter.cpp
1259 ↗(On Diff #128459)

Ditto.

lib/Target/AMDGPU/SIDefines.h
277 ↗(On Diff #128459)

Recommendation: I would rename ID_SYMBOLIC_FIRST_GFX9_ to ID_SYMBOLIC_LAST_PRIOR_GFX9_ or alike.

277 ↗(On Diff #128459)

Value should be set to 8, as it was prior these changes.

This revision is now accepted and ready to land.Jan 9 2018, 8:20 AM
rampitec added inline comments.Jan 15 2018, 10:04 AM
lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
3168 ↗(On Diff #128459)

With more values added in the future this expression would become hardly readable.

lib/Target/AMDGPU/SIDefines.h
277 ↗(On Diff #128459)

If it will be 8 the patch would not work. We shall recognize sh_mem_bases on GFX9.

277 ↗(On Diff #128459)

ID_SYMBOLIC_LAST_PRIOR_GFX9_

To me that would be cryptic ;)

This revision was automatically updated to reflect the committed changes.

Let's reach consensus.

lib/Target/AMDGPU/SIDefines.h
277 ↗(On Diff #128459)

I mean that ID_SYMBOLIC_LAST_PRIOR_GFX9_ shall be set to 8 (which is currently named ID_SYMBOLIC_FIRST_GFX9_). That enum member is not used on Gfx9, as far as I see, and does not prevent ID_MEM_BASES from being recognized.

Am I wrong somewhere?

277 ↗(On Diff #128459)
ID_SYMBOLIC_LAST_PRIOR_GFX9_

To me that would be cryptic ;)

To me, what is really cryptic is when ...FIRST... is assigned to Last in lib/Target/AMDGPU/InstPrinter/AMDGPUInstPrinter.cpp#1259 and lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp#3168, like this:

unsigned Last = ID_SYMBOLIC_LAST_;
  if (AMDGPU::isSI(STI) || AMDGPU::isCI(STI) || AMDGPU::isVI(STI))
    Last = ID_SYMBOLIC_FIRST_GFX9_;

I believe the source of inconsistency is the original definition of ID_SYMBOLIC_LAST_, which does not point to a last value in the enum, but a last + 1. This can be changed in a separate patch.

I believe the source of inconsistency is the original definition of ID_SYMBOLIC_LAST_, which does not point to a last value in the enum, but a last + 1. This can be changed in a separate patch.

Yes, the names are not consistent with an original idea. However, I recommend renaming *FIRST*/*LAST* to *BEGIN*/*END* to better express iterator-like semantics. Thanks for catching this.