This is an archive of the discontinued LLVM Phabricator instance.

[GlobalISel][NFC] Gardening: Factor out code for simple unary intrinsics
ClosedPublic

Authored by paquette on Feb 5 2019, 11:32 AM.

Details

Summary

I noticed that there was a lot of duplicated code for unary intrinsics in translateKnownIntrinsic, and thought it would be nice to factor it out into its own function.

This adds a function and a lookup table which contains the currently supported simple unary intrinsics. I figured the lookup table would be nice, because if we add one of these, then all we have to do is add the intrinsic and its generic opcode to the mapping.

Also, it would get us out of writing code like this, which seems a little redundant IMO:

case intrinsicA:
    translateFooIntrinsic(OpcodeForA...);
case intrinsicB:
    translateFooIntrinsic(OpcodeForB...);
case intrinsicC:
    translateFooIntrinsic(OpcodeForC...);

Diff Detail

Repository
rL LLVM

Event Timeline

paquette created this revision.Feb 5 2019, 11:32 AM
arsenm added inline comments.Feb 5 2019, 11:37 AM
include/llvm/CodeGen/GlobalISel/IRTranslator.h
166–168 ↗(On Diff #185356)

Why a map instead of a simple switch function?

paquette marked an inline comment as done.Feb 5 2019, 11:40 AM
paquette added inline comments.
include/llvm/CodeGen/GlobalISel/IRTranslator.h
166–168 ↗(On Diff #185356)

Purely personal preference; I don't feel strongly either way so I'm happy to change it.

paquette updated this revision to Diff 185387.Feb 5 2019, 1:09 PM

Use a function containing a switch instead of a map, and move it all into IRTranslator.cpp.

arsenm accepted this revision.Feb 6 2019, 6:08 AM

LGTM with nit

lib/CodeGen/GlobalISel/IRTranslator.cpp
791 ↗(On Diff #185387)

I don't think it's necessary to use Optional here, since you can use Intrinsic::not_intrinsic and that's what places usually do

This revision is now accepted and ready to land.Feb 6 2019, 6:08 AM
paquette updated this revision to Diff 185579.Feb 6 2019, 9:24 AM
paquette marked an inline comment as done.

Update diff to address nit before committing

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 6 2019, 9:26 AM