This is an archive of the discontinued LLVM Phabricator instance.

[Nios2] Changes in frontend to support Nios2 LLVM target
ClosedPublic

Authored by belickim on May 19 2017, 7:09 AM.

Details

Summary

Hello,

This patch is part of our effort to implement Nios2 architecture support in LLVM and clang (our plans were announced in mailing list thread: "[llvm-dev] [RFC] Nios II backend" form April 12th).

This patch depends on changes introduced by patch D32669.

The patch contains following additions:

  • Nios2 builtins;
  • using -march or -mcpu options to specify Nios2 CPU type (R1 or R2) ;
  • TargetInfo class implementation for Nios2.

Please let me know what you think about proposed change set.

Kind regards,
Mateusz Belicki

Diff Detail

Repository
rL LLVM

Event Timeline

belickim created this revision.May 19 2017, 7:09 AM
joerg added a subscriber: joerg.May 19 2017, 7:15 AM
joerg added inline comments.
lib/Basic/Targets.cpp
7614 ↗(On Diff #99558)

Can you just give the full string and avoid the runtime allocations?

7650 ↗(On Diff #99558)

DefineStd tends to give a lot of namespace pollution, is that intentional here?

belickim added inline comments.May 19 2017, 7:24 AM
lib/Basic/Targets.cpp
7614 ↗(On Diff #99558)

Yes, I will fix this.

7650 ↗(On Diff #99558)

Yes, the usage is intentional: definitions of all four: __nios2, __nios2__, __NIOS2 and __NIOS2__ are part of Nios2 ABI (page 23, https://www.altera.com/content/dam/altera-www/global/en_US/pdfs/literature/hb/nios2/n2cpu_nii51016.pdf).

Additionally this information may be useful in context of this patch: here is specification of Nios2 builtins as implemented in GCC: https://gcc.gnu.org/onlinedocs/gcc/Altera-Nios-II-Built-in-Functions.html

joerg added inline comments.May 19 2017, 7:50 AM
lib/Basic/Targets.cpp
7650 ↗(On Diff #99558)

The problem is that DefineStd will also define the no-underscore version in GNU mode.

belickim added inline comments.May 19 2017, 8:33 AM
lib/Basic/Targets.cpp
7650 ↗(On Diff #99558)

Oh, that definitely is not needed in our case. I will remove the usage of DefineStd(). Looking at implementations of other TargetInfos, I assume that preferred solution would be to manually call Builder.defineMacro() for all four defintions.

joerg added inline comments.May 19 2017, 9:19 AM
lib/Basic/Targets.cpp
7650 ↗(On Diff #99558)

Yes, that's fine/

belickim updated this revision to Diff 100111.May 24 2017, 9:12 AM

I implemented changes suggested by Joerg.

In previous version there was also an additional macro with CPU name that I removed. It was not documented anywhere and is not even used by GCC. So there seems to be no prior usages, that would support its existence. The presence of that macro in previous version of the patch was an oversight.

craig.topper edited edge metadata.May 24 2017, 1:40 PM

Is there enough functional here that there should be tests for? i.e. make sure march/mcpu switches are recognized, that the target is recognized, etc.

belickim updated this revision to Diff 100668.May 30 2017, 12:16 AM

I added test for driver to check if target and CPU flags are recognized, as Craig suggested.

A couple of coding style nits. FYI, LLVM coding standard is documented here:

http://llvm.org/docs/CodingStandards.html

include/clang/Basic/TargetBuiltins.h
154 ↗(On Diff #100668)
lib/Basic/Targets.cpp
7609 ↗(On Diff #100668)

No need for curly braces here.

7631 ↗(On Diff #100668)

You don't need the inner parentheses here and the code below.

7685 ↗(On Diff #100668)

Two space indentation here.

lib/Driver/ToolChains/CommonArgs.cpp
220 ↗(On Diff #100668)

You can just write "if (!A)". Also, you can move up the return statement at the end of the function and do an early return.

if (A!) {
  ...
  return ""
}

const *name = A->getValue();
...
belickim added inline comments.May 30 2017, 1:26 AM
include/clang/Basic/TargetBuiltins.h
154 ↗(On Diff #100668)

I was trying to follow conventions used by other code in this file (this also applies to some extend to other things that you pointed out). I will try to follow LLVM coding conventions over style present in file for any future changes. Thank you for your comments, I will prepare update with all changes that you suggested.

belickim updated this revision to Diff 100674.May 30 2017, 2:20 AM

Thanks Akira for your comments, I made all changes that you suggested.

craig.topper accepted this revision.Jun 6 2017, 8:21 AM

LGTM

lib/Basic/Targets.cpp
7678 ↗(On Diff #100674)

This is indented too far. Can you fix when you commit?

This revision is now accepted and ready to land.Jun 6 2017, 8:21 AM
This revision was automatically updated to reflect the committed changes.