This is an archive of the discontinued LLVM Phabricator instance.

[Sparc] Fixes for the internal assembler
ClosedPublic

Authored by LemonBoy on Apr 15 2020, 4:15 AM.

Details

Summary
  • Prevent the generation of invalid shift instructions by constraining the immediate field. I've limited the shift field to constant values only, adding the R_SPARC_5/R_SPARC_6 relocations is trivial if needed (but I can't really think of a use case for those).
  • Fix the generation of PC-relative call
  • Fix the transformation of jmp sym into jmpl
  • Emit fixups for simm13 operands

I moved the choice of the correct relocation into the code emitter as I've seen the other backends do, it can be definitely cleaner but the aim was to reduce the scope of the patch as much as possible.

Fixes the problems raised by joerg in L254199

Diff Detail

Event Timeline

LemonBoy created this revision.Apr 15 2020, 4:15 AM
LemonBoy updated this revision to Diff 257743.Apr 15 2020, 8:57 AM
brad added a comment.Oct 22 2020, 10:16 PM

Any chance of seeing review on this?

I will try and review it next week.

dcederman accepted this revision.Oct 26 2020, 5:08 AM

It was some time since I worked with LLVM, but this looks good to me. It tries to fix a couple of things, so it would probably been better to divide it up into more than one patch and add some more tests, but this is fine. I compared the result with GAS for V8 and it matches.

llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
289

Is this for grouping? I think it looks better if there is an empty line between them.

384

Same here.

llvm/lib/Target/Sparc/MCTargetDesc/SparcMCCodeEmitter.cpp
161

Can this be false? In similar code there is usually an assert(MO.isExpr()) instead.

181

If we can reach this line then the operand is not an immediate so getImm() would not work.

This revision is now accepted and ready to land.Oct 26 2020, 5:08 AM

It tries to fix a couple of things, so it would probably been better to divide it up into more than one patch and add some more tests, but this is fine. I compared the result with GAS for V8 and it matches.

Sorry about that but splitting the patch into smaller chunks turned up to be harder than writing the patch itself.
I'll send an updated patch soon.

llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
289

Yep, but I have no strong feelings about that. I'll add an empty line in between.

llvm/lib/Target/Sparc/MCTargetDesc/SparcMCCodeEmitter.cpp
161

Good catch, I forgot I added the isImm check before.
I'll re-check a few things and turn it into an assertion.

LemonBoy updated this revision to Diff 301463.Oct 28 2020, 4:02 PM
brad added a comment.Dec 18 2020, 5:34 PM

@dcederman Able to see about getting this in?

I do not currently have commit access, but I have asked to so see if I can get it again and then I will push this patch.

This revision was automatically updated to reflect the committed changes.