In supporting opaque pointers we need to re-materialize typed pointers
in bitcode emission. Because of how the value-enumerator pre-allocates
types and instructions we need to insert some no-op bitcasts in the
places that we'll need bitcasts for the pointer types.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Unit Tests
Event Timeline
Updateing DXIL-prepare to rely on dxil::TypedPointerType, and to properly handle function types.
llvm/lib/Target/DirectX/DXILPrepare.cpp | ||
---|---|---|
141 | Why bitcasts need to be at top of the block? | |
154 | Cannot find the check for only have one type. | |
155–160 | Could we have shouldOmit function and createNoOpBitcast function? The same code happened 3 times. |
llvm/lib/Target/DirectX/DXILPrepare.cpp | ||
---|---|---|
141 | Good point. I will adjust. | |
154 | That comment isn't great. The pointer analysis assigns one type to each value based on how it is used. If the type of the user and the type assigned by pointer analysis match, we don't need a bitcast because the value will be assigned that type. If they don't match, we need a bitcast so that the user gets the correct typed pointer. |
llvm/lib/Target/DirectX/DXILPrepare.cpp | ||
---|---|---|
155–160 | The code here is actually not the same in all three places. The first two are super similar except that Inst is different types in both cases. The third is different because the interfaces for GEP instructions aren't the same. |
llvm/lib/Target/DirectX/DXILPrepare.cpp | ||
---|---|---|
105–106 | nit: If you want to revisit this in a future patch, I think you can use enum_seq here: https://llvm.org/doxygen/Sequence_8h.html | |
113 | I know this is existing code, but a tiny nit: I think the coding style prefers the end value to be calculated only once, e.g., for (size_t i = 0, e = size(); i != e; ++i) ... | |
127 | nit: missing . at the end of the comment | |
133 | Since I is a reference, it cannot be null, so we should use plain dyn_cast. | |
134 | nit: missing . at the end of the comment | |
135–136 | It is shadowed by other iterator variables below. Can we give it a more descriptive/unique name? | |
151 | same here | |
152 | also here | |
168 | same here | |
169 | also here | |
170–179 | This pattern seems pretty repetitive: for each type, we check if the pointer operand is in the type, adjust the inter point, and emit a bitcast. Could we move it to a generic helper function? Something like: if (Value *Bitcast = createNoopBitcast(Inst, Inst->getPointerOperand(), Inst->getPointerOperandType()) { // Update or replace Inst. continue; } |
llvm/test/CodeGen/DirectX/omit-bitcast-insert.ll | ||
---|---|---|
26 | I think it would be also worth having some tests where we do insert bitcasts for geps. |
nit: If you want to revisit this in a future patch, I think you can use enum_seq here: https://llvm.org/doxygen/Sequence_8h.html