This is an archive of the discontinued LLVM Phabricator instance.

[m68k] Add TLS support
AbandonedPublic

Authored by 0x59616e on Feb 4 2023, 4:06 AM.

Details

Summary

Add TLS support to m68k backend in LLVM

This change introduces support for Thread-Local Storage (TLS) in the m68k backend of LLVM. TLS is implemented using the pseudo instruction TLS_(GD|LD|IE|LE), which is later expanded into the corresponding instruction in AsmPrinter.

Diff Detail

Event Timeline

0x59616e created this revision.Feb 4 2023, 4:06 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 4 2023, 4:06 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
0x59616e requested review of this revision.Feb 4 2023, 4:06 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 4 2023, 4:06 AM
0x59616e edited the summary of this revision. (Show Details)Feb 4 2023, 6:05 PM
0x59616e added reviewers: myhsu, RKSimon, glaubitz, ricky26.
0x59616e edited the summary of this revision. (Show Details)Feb 4 2023, 6:08 PM

Doesn't seem to build at the moment:

/data/home/glaubitz/llvm-project/llvm/lib/Target/M68k/M68kAsmPrinter.cpp: In member function ‘void llvm::M68kAsmPrinter::LowerTLSDynamic(const llvm::MachineInstr*)’:
/data/home/glaubitz/llvm-project/llvm/lib/Target/M68k/M68kAsmPrinter.cpp:124:52: error: ‘ADD32ab’ is not a member of ‘llvm::M68k’
   OutStreamer->emitInstruction(MCInstBuilder(M68k::ADD32ab)
                                                    ^~~~~~~
/data/home/glaubitz/llvm-project/llvm/lib/Target/M68k/M68kAsmPrinter.cpp:124:52: note: suggested alternative: ‘ADD32ar’
   OutStreamer->emitInstruction(MCInstBuilder(M68k::ADD32ab)
                                                    ^~~~~~~
                                                    ADD32ar
/data/home/glaubitz/llvm-project/llvm/lib/Target/M68k/M68kAsmPrinter.cpp:131:52: error: ‘BSR32’ is not a member of ‘llvm::M68k’
   OutStreamer->emitInstruction(MCInstBuilder(M68k::BSR32).addExpr(TlsGetAddr),
                                                    ^~~~~
/data/home/glaubitz/llvm-project/llvm/lib/Target/M68k/M68kAsmPrinter.cpp:131:52: note: suggested alternative: ‘LSR32di’
   OutStreamer->emitInstruction(MCInstBuilder(M68k::BSR32).addExpr(TlsGetAddr),
                                                    ^~~~~
                                                    LSR32di
/data/home/glaubitz/llvm-project/llvm/lib/Target/M68k/M68kAsmPrinter.cpp:142:52: error: ‘ADD32ab’ is not a member of ‘llvm::M68k’
   OutStreamer->emitInstruction(MCInstBuilder(M68k::ADD32ab)
                                                    ^~~~~~~
/data/home/glaubitz/llvm-project/llvm/lib/Target/M68k/M68kAsmPrinter.cpp:142:52: note: suggested alternative: ‘ADD32ar’
   OutStreamer->emitInstruction(MCInstBuilder(M68k::ADD32ab)
                                                    ^~~~~~~
                                                    ADD32ar
/data/home/glaubitz/llvm-project/llvm/lib/Target/M68k/M68kAsmPrinter.cpp: In member function ‘void llvm::M68kAsmPrinter::LowerTLSExec(const llvm::MachineInstr*)’:
/data/home/glaubitz/llvm-project/llvm/lib/Target/M68k/M68kAsmPrinter.cpp:179:54: error: ‘ADD32ab’ is not a member of ‘llvm::M68k’
     OutStreamer->emitInstruction(MCInstBuilder(M68k::ADD32ab)
                                                      ^~~~~~~
/data/home/glaubitz/llvm-project/llvm/lib/Target/M68k/M68kAsmPrinter.cpp:179:54: note: suggested alternative: ‘ADD32ar’
     OutStreamer->emitInstruction(MCInstBuilder(M68k::ADD32ab)
                                                      ^~~~~~~
                                                      ADD32ar
/data/home/glaubitz/llvm-project/llvm/lib/Target/M68k/M68kAsmPrinter.cpp:192:52: error: ‘ADD32ab’ is not a member of ‘llvm::M68k’
   OutStreamer->emitInstruction(MCInstBuilder(M68k::ADD32ab)
                                                    ^~~~~~~
/data/home/glaubitz/llvm-project/llvm/lib/Target/M68k/M68kAsmPrinter.cpp:192:52: note: suggested alternative: ‘ADD32ar’
   OutStreamer->emitInstruction(MCInstBuilder(M68k::ADD32ab)
                                                    ^~~~~~~
                                                    ADD32ar

Doesn't seem to build at the moment:

D143316 and D143315 are required to build this.

jrtc27 added inline comments.Feb 5 2023, 2:58 AM
llvm/lib/Target/M68k/M68kISelDAGToDAG.cpp
671

Yeah, indeed, this should be done in ISelLowering, not in AsmPrinter

myhsu added a comment.Feb 5 2023, 9:24 PM

just skimmed through the patch but I think either ISelLowering (in which case you probably don't need the custom ISD) or the pseudo instruction expanding Pass will be a better place to put the main logics, rather than AsmPrinter.

0x59616e planned changes to this revision.Feb 5 2023, 11:15 PM

Plan to update the code per the advice received

0x59616e updated this revision to Diff 497845.Feb 15 2023, 5:04 PM
0x59616e edited the summary of this revision. (Show Details)

The access model type is disambiguated at ISelLowering, but it still needs to be expanded in AsmPrinter. I am uncertain how to express the Global Offset Table in MachineInstr.

jrtc27 added inline comments.Feb 15 2023, 5:39 PM
llvm/lib/Target/M68k/MCTargetDesc/M68kBaseInfo.h
115

This is how you do GOT accesses…

0x59616e abandoned this revision.Feb 16 2023, 4:00 AM
0x59616e marked an inline comment as done.