Set target triple to "dxil-ms-dx" for DXIL at the end of DXILTranslateMetadata.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
So... this is actually going to be terrible, but we can't do it this way. We rely on the module having a sane triple through MC emission.
What we need to do is change the triple right before DXIL bitcode generation, then change it back so that it is correct through MC.
llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp | ||
---|---|---|
54 ↗ | (On Diff #451921) | This is a bit confusingly named. Probably worth calling this SMVer instead and explaining in a comment that the DXIL and SM minor versions are the same, and the major versions are offset. |
75 ↗ | (On Diff #451921) | nit: Rather than static const constexpr. The later is guaranteed to be compile-time resolved, the former isn't. |
85 ↗ | (On Diff #451921) | |
86 ↗ | (On Diff #451921) | This one really requires you to know the API to know that getMinor() returns an Optional rather than a value. Other places in LLVM use a pattern more like: unsigned Minor = V.getMinor().value_or(0); Which would also be more clear. |
llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.h | ||
78 ↗ | (On Diff #451921) | I know we had talked about where to mutate the triple and I thought WriteDXILToFile made sense, but seeing the code now that we lose the const-ness here I'm rethinking. We only really need the triple to be altered when we're embedding DXIL in the module for emission of a container. I don't even think the WriteDXILPass is ever used (unless it were called manually). It might make more sense to mutate the triple in EmbedDXILPass::runOnModule to preserve the const-ness of the writing function. We can also in a subsequent patch delete the WriteDXILPass. |
Please add a check line to the embed-dxil.ll test to verify that the triple is restored after embedding the DXIL global, otherwise LGTM.