This is an archive of the discontinued LLVM Phabricator instance.

[TableGen][DirectX] Add tableGen backend to generate map from llvm intrinsic to DXIL operation.
ClosedPublic

Authored by python3kgae on May 12 2022, 10:18 PM.

Details

Summary

A new tableGen backend gen-dxil-intrinsic-map is added to generate map from llvm intrinsic to DXIL operation.

A new file "DXILIntrinsicMap.inc" will be generated when build DirectX target which include the map.

The generated map will replace the manually created map when find DXIL operation from llvm intrinsic.

Diff Detail

Event Timeline

python3kgae created this revision.May 12 2022, 10:18 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 12 2022, 10:18 PM
python3kgae requested review of this revision.May 12 2022, 10:18 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 12 2022, 10:18 PM

Running TableGen multiple times is a bit annoying for LLVM build times. Have you considered packing all outputs into the same .inc file?

Running TableGen multiple times is a bit annoying for LLVM build times. Have you considered packing all outputs into the same .inc file?

Sure. I'll make all these things into one '.inc` file.
Thanks for the suggestion.

Move EmitDXILIntrinsicMap into EmitDXILOperation.

Add static for internal function.

bogner accepted this revision.Jun 15 2022, 3:56 PM
bogner added a subscriber: bogner.
bogner added inline comments.
llvm/lib/Target/DirectX/DXILOpLowering.cpp
67

Why do this? Since the switch statement covers all values of the enum there are nice warnings (at least if you build with clang) if someone adds another OverloadKind, and forgets to update here, whereas with the default statement that's not the case.

I guess some compilers might warn that not all paths return a value though if they think we can fall out of the switch. If you're just trying to handle that warning then it's probably best to move the llvm_unreachable + return statement out of the switch and just put break here, to get the best of both worlds.

llvm/utils/TableGen/DXILEmitter.cpp
84

Might be worth an assert that the intrinsic name starts with "int_" just in case someone makes a mistake in the td. OTOH I think we'll already error in that case because map_intrinsic won't find anything, so maybe it's fine.

165

Probably better done as a separate change, but is a SmallDenseMap really the best option here? We could probably just store this as an array of pairs and pre-sort it, then query it with std::lower_bound on the keys instead.

This revision is now accepted and ready to land.Jun 15 2022, 3:56 PM
python3kgae marked 2 inline comments as done.

Update to match the comments.

python3kgae marked an inline comment as done.Jun 15 2022, 5:24 PM
python3kgae added inline comments.
llvm/utils/TableGen/DXILEmitter.cpp
165

Tried to change to array. But find it hard to get intrinsic ID in tableGen for pre-sort.
Leave it for future change.

This revision was landed with ongoing or failed builds.Jun 15 2022, 7:41 PM
This revision was automatically updated to reflect the committed changes.
python3kgae marked an inline comment as done.