This is an archive of the discontinued LLVM Phabricator instance.

Refactor duplicate functions
ClosedPublic

Authored by bogden on Nov 21 2013, 8:19 AM.

Details

Summary

getARMCPU and getLLVMArchSuffixForARM existed as very similar functions
in both ToolChain.cpp and Tools.cpp. Create a single implementation of
each in Tools.cpp, eliminate the duplicate and share via Tools.h.

Creates an 'arm' namespace in Tools.h to be used by any ARM-targetting tools.

GetArmArchForMArch and GetArmArchForMCpu seem to do similar things, but
specialised for Darwin. I've opted to leave them alone.

This addresses http://llvm.org/bugs/show_bug.cgi?id=17120, at least in part.

Depends on D2062

Fixes http://llvm.org/bugs/show_bug.cgi?id=17120

Diff Detail

Event Timeline

bogden planned changes to this revision.Nov 21 2013, 8:19 AM

bogden typed the wrong arc rune and does not actually plan changes to this revision.

I'm not altogether sure about adding the 'arm' namespace in Tools. The intent of these functions is that they can be used by _any_ arm-targetting toolchain, rather than being limited to some arm-specific toolchain. So possibly I'm breaking with the intent of this file.

If not, we get to eliminate two duplicate functions, which would be nice.

I'm not altogether sure about adding the 'arm' namespace in Tools. The intent of these functions is that they can be used by _any_ arm-targetting toolchain, rather than being limited to some arm-specific toolchain. So possibly I'm breaking with the intent of this file.

If not, we get to eliminate two duplicate functions, which would be nice.

Hi Bernie,

Thanks very much for taking a stab at this. I'm quite happy with the "arm" namespace myself, but have a reservation about Darwin:

lib/Driver/ToolChain.cpp
167–169

It's a little difficult to tell because the patch no longer applies cleanly to trunk, but I suspect this comment has misled you. Darwin *does* take note of -mcpu, and I suspect this patch might disable that.

bogden updated this revision to Unknown Object (????).Nov 22 2013, 6:31 AM

Break up the factored-out function to preserve a behaviour used
in one instance but not the other. Add a unit test for this
behaviour.

You're right, I've failed to preserve the behaviour. I've uploaded a new version of the patch.

I don't suppose you know if that "don't check CPU" behaviour is correct? The effect seems to be -

Non-Darwin: Arch for cpu specified with -mcpu takes precendence over arch specified by -arch/-march
Darwin: Arch specified with -arch/-march takes precendence over arch specified by -mcpu

Though it's perhaps better described by the unit test.

-----Original Message-----
From: Tim Northover [mailto:t.p.northover@gmail.com]
Sent: 22 November 2013 12:18
To: Bernard Ogden
Cc: cfe-commits@cs.uiuc.edu; renato.golin@linaro.org;
t.p.northover@gmail.com; Amara Emerson
Subject: Re: [PATCH] Refactor duplicate functions

   Hi Bernie,

   Thanks very much for taking a stab at this. I'm quite happy with the

"arm" namespace myself, but have a reservation about Darwin:

================
Comment at: lib/Driver/ToolChain.cpp:167-169
@@ -166,5 @@

  • const llvm::Triple &Triple) {
  • // For Darwin targets, the -arch option (which is translated to a
  • // corresponding -march option) should determine the architecture
  • // (and the Mach-O slice) regardless of any -mcpu options.
  • if (!Triple.isOSDarwin()) {
    • It's a little difficult to tell because the patch no longer applies cleanly to trunk, but I suspect this comment has misled you. Darwin *does* take note of -mcpu, and I suspect this patch might disable that.

http://llvm-reviews.chandlerc.com/D2243

ARCANIST PROJECT

clang
  • IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

ARM Limited, Registered office 110 Fulbourn Road, Cambridge CB1 9NJ, Registered in England & Wales, Company No: 2557590
ARM Holdings plc, Registered office 110 Fulbourn Road, Cambridge CB1 9NJ, Registered in England & Wales, Company No: 2548782

rengolin accepted this revision.Dec 12 2013, 6:50 AM

committed in 197153

lib/Driver/ToolChain.cpp
192

This is very cryptic, but still better than before. I'd recommend a comment before that explaining a bit of why this is like that. Better names for those functions would also be good, even if a little verbose.

rengolin closed this revision.Dec 12 2013, 6:50 AM

Very true. I'll take a look at this next time I get some coding time.

-----Original Message-----
From: Renato Golin [mailto:renato.golin@linaro.org]
Sent: 12 December 2013 14:51
To: t.p.northover@gmail.com; Bernard Ogden
Cc: cfe-commits@cs.uiuc.edu; Amara Emerson

Subject: Re: [PATCH] Refactor duplicate functions

Comment at: lib/Driver/ToolChain.cpp:192
@@ -299,1 +191,3 @@
+ ?
tools::arm::getLLVMArchSuffixForARM(tools::arm::getARMCPUForMArch(Args,
Triple))
+ :
tools::arm::getLLVMArchSuffixForARM(tools::arm::getARMTargetCPU(Args,
Triple));

bool ThumbDefault = Suffix.startswith("v6m") ||

Suffix.startswith("v7m") ||

This is very cryptic, but still better than before. I'd recommend a
comment before that explaining a bit of why this is like that. Better
names for those functions would also be good, even if a little verbose.

  • IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

ARM Limited, Registered office 110 Fulbourn Road, Cambridge CB1 9NJ, Registered in England & Wales, Company No: 2557590
ARM Holdings plc, Registered office 110 Fulbourn Road, Cambridge CB1 9NJ, Registered in England & Wales, Company No: 2548782