This is an archive of the discontinued LLVM Phabricator instance.

Convert finite to builtin
ClosedPublic

Authored by danielcdh on Sep 12 2016, 4:57 PM.

Details

Summary

This patch converts finite/__finite to builtin functions so that it will be inlined by compiler.

Diff Detail

Event Timeline

danielcdh updated this revision to Diff 71079.Sep 12 2016, 4:57 PM
danielcdh retitled this revision from to Convert finite to builtin.
danielcdh updated this object.
danielcdh added reviewers: hfinkel, davidxl.
danielcdh added a subscriber: llvm-commits.
efriedma requested changes to this revision.Sep 12 2016, 5:16 PM
efriedma added a reviewer: efriedma.
efriedma added a subscriber: efriedma.

"finite()" is a BSD function, not a C standard function, so ALL_LANGUAGES isn't appropriate.

I can't seem to find documentation for "__finite()"; where is it defined?

This revision now requires changes to proceed.Sep 12 2016, 5:16 PM

"finite()" is a BSD function, not a C standard function, so ALL_LANGUAGES isn't appropriate.

Thanks for the comment. I'm not quite familiar with BSD function. Could you suggest which flag I should use here? C_LANG?

I can't seem to find documentation for "__finite()"; where is it defined?

It's just that if I include <math.h> and use isfinite(), it will automatically expand to finite() instead of finite(). But if I call finite() directly, it will expand to finite(). Thus I think I need to handle both finite and finite. Any suggestions on this?

Thanks,
Dehao

GNU_LANG is the flag you're looking for.

"it will automatically expand to finite()"

What exactly is your build configuration (operating system, compiler, libc version if applicable)?

Also, this is missing a test (see test/CodeGen/builtins.c).

danielcdh updated this revision to Diff 71086.Sep 12 2016, 5:49 PM
danielcdh edited edge metadata.

update

GNU_LANG is the flag you're looking for.

"it will automatically expand to finite()"

What exactly is your build configuration (operating system, compiler, libc version if applicable)?

I'm running on ubuntu with clang 4.0.

I found that the __finite is expanded from math.h:

define isfinite(x) \

(sizeof (x) == sizeof (float)                                            \
 ? __finitef (x)                                                         \
 : sizeof (x) == sizeof (double)                                         \
 ? __finite (x) : __finitel (x))

finite() is expanded from /usr/include/x86_64-linux-gnu/bits/mathcalls.h

/* Return nonzero if VALUE is finite and not NaN. */
MATHDECL_1 (int,finite,, (_Mdouble_ value)) attribute ((const));

which is expanded to:
extern int finite (double value) throw () attribute__ ((const));

Not sure what is the right thing to do here...

Thanks,
Dehao

Also, this is missing a test (see test/CodeGen/builtins.c).

added

Oh, I see...

It's probably worth adding a comment explaining where __finite comes from, since it isn't obvious. Also, should be okay to mark it ALL_LANGUAGES (since it has a double-underscore prefix).

danielcdh updated this revision to Diff 71280.Sep 13 2016, 6:00 PM
danielcdh edited edge metadata.

update

Thanks for the review, Eli. Do you have other comments about this patch?

Thanks,
Dehao

efriedma accepted this revision.Sep 14 2016, 10:30 AM
efriedma edited edge metadata.

LGTM after you change the comment.

include/clang/Basic/Builtins.def
922

This comment isn't really clear... maybe something more like "glibc's math.h generates calls to __finite"?

This revision is now accepted and ready to land.Sep 14 2016, 10:30 AM
danielcdh updated this revision to Diff 71388.Sep 14 2016, 10:37 AM
danielcdh edited edge metadata.

update comment

danielcdh closed this revision.Sep 14 2016, 10:42 AM