This is an archive of the discontinued LLVM Phabricator instance.

[tblgen] GCC/MS builtin to target intrisics map.
ClosedPublic

Authored by speziale.ettore on Mar 20 2017, 1:21 PM.

Details

Reviewers
rnk
Summary

Allow TableGen to generate static functions to perform GCC/MS builtin name to
target specific intrinsic ID mapping.

Diff Detail

Repository
rL LLVM

Event Timeline

This patch would allows backend to make use of the builtin-to-intrinsic mapping function if requested. In the case no builtin names are associated with intrinsics, the builtin-to-instrinsic table is not emitted to avoid warnings about zero-length arrays.

rnk accepted this revision.Mar 20 2017, 1:32 PM

lgtm

Can you give an example of what this would enable?

This revision is now accepted and ready to land.Mar 20 2017, 1:32 PM
In D31150#705628, @rnk wrote:

lgtm

Can you give an example of what this would enable?

The use case is a module which contains function calls a particular backend would like to lower into intrinsic calls. Enabling the builtin-to-intrinsics map would allow to automate a little bit that process.

rnk added a comment.Mar 20 2017, 3:03 PM
In D31150#705628, @rnk wrote:

lgtm

Can you give an example of what this would enable?

The use case is a module which contains function calls a particular backend would like to lower into intrinsic calls. Enabling the builtin-to-intrinsics map would allow to automate a little bit that process.

I mean an example target-specific builtin that you need to map.

I mean an example target-specific builtin that you need to map.

Sorry, I misunderstood your question.

My use case is related to languages where there are a lot of functions which can be lowered into intrinsics calls by backends. For instance in OpenCL there are a set of functions that allow to query the property of the NDRange. For instance the size_t get_global_size(uint x) function allows to get the number of work items along the x dimension:

size_t foo() {
  return get_global_size(1);
}

This is the code generated by clang:

define i64 @foo() local_unnamed_addr #0 {
entry:
  %call = tail call i64 @get_global_size(i32 1) #2
  ret i64 %call
}

Backend for architectures supporting this kind of languages often exposes intrinsics to access those informations, hence I would like to use the builtin-to-intrinsic map to rewrite the call to get_global_size to the call to a target-specify intrinsic before starting the final code generation.

In my case, the backend I'm working on is not upstream, so I cannot give you an example only using upstream code.

Quentin/Reid could you please commit this one if there are no objections? (I do not have commits rights).

Closing, as Aditya already committed this -- see trunk@r300735.