PIC16TargetAsmInfo::getBSSSectionForGlobal

Hi Sanjiv,

The PIC16TargetAsmInfo::getBSSSectionForGlobal apparently does magic that reinterprets the "section" field of a global in a strange way:

   // If GV has a sectin name or section address create that section now.
   if (GV->hasSection()) {
     std::string SectName = GV->getSection();
     // If address for a variable is specified, get the address and create
     // section.
     std::string AddrStr = "Address=";
     if (SectName.compare(0, AddrStr.length(), AddrStr) == 0) {
       std::string SectAddr = SectName.substr(AddrStr.length());
       S = CreateSectionForGlobal(GV, SectAddr);
     }

Why isn't the front-end handling this, replacing all uses of the global with the address? Does PIC allow initializing random sections of globals like this? I need to heavily refactor all this code, and since there are no testcases at all for PIC16, I'm afraid of breaking something.

-Chris

Substituting the uses of a global with an absolute address would make
all accesses to that global through pointer, which is very inefficient
on PIC16. So we don't change the code generation for that global;
instead we only pass the address information to the linker (home made
linker) through some assembly directives.
What are you trying to do? Are you trying to change the logic of this
part or it is only simple refactoring?

Regards
Ali

From: llvmdev-bounces@cs.uiuc.edu [mailto:llvmdev-bounces@cs.uiuc.edu]

On

Substituting the uses of a global with an absolute address would make
all accesses to that global through pointer, which is very inefficient
on PIC16. So we don't change the code generation for that global;
instead we only pass the address information to the linker (home made
linker) through some assembly directives.
What are you trying to do? Are you trying to change the logic of this
part or it is only simple refactoring?

My short term goal is to make TargetAsmInfo not depend on libvmcore. This means that no methods in it should take GlobalValue*'s for example. There is a suite of GV classification methods that need to be moved somewhere else, probably in TargetLowering or asmprinter. One method in particular (SectionForGlobal) is virtual and only re-implemented for PIC16, which makes it an obvious candidate for changing.

I don't really understand all the section handling logic, but I have to untangle it. It doesn't seem like it is properly factored somehow, so I'd like to simplify it while I'm moving stuff. I don't want to break PIC16, but again, there are no testcases!

-Chris

My short term goal is to make TargetAsmInfo not depend on libvmcore. This means that no methods in it should take GlobalValue*'s for example. There is a suite of GV classification methods that need to be moved somewhere else, probably in TargetLowering or asmprinter. One method in particular (SectionForGlobal) is virtual and only re- implemented for PIC16, which makes it an obvious candidate for changing.

I don't really understand all the section handling logic, but I have to untangle it. It doesn't seem like it is properly factored somehow, so I'd like to simplify it while I'm moving stuff.

PIC16 has a lot of things going on in asmprinter while sectionizing globals.
Let us know if you need to understand anything.

I don't want to break PIC16, but again, there are no testcases!

-Chris
  

We do have a lot of execution tests locally. But we haven't added any to the test/CodeGen because of lack of time.
I can help you testing your patch.

- Sanjiv

Alright. Well I wrote a simple testcase for the most obvious functionality. I'll proceed with my refactoring and not break this test. If I break anything else, you guys can work it out after I'm done (and I'll help).

-Chris