[PATCH] D24223: [SelectionDAG] Add SDNode:RawSDNodeBits.
Justin Lebar via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 4 16:35:04 PDT 2016
jlebar created this revision.
jlebar added reviewers: ahatanak, chandlerc.
jlebar added a subscriber: llvm-commits.
Previously we were assuming that SDNodeBits covered all of SDNode's
anonymous subclass data bitfield union. But that's not right; it might
have size 1, in which it clearly doesn't.
This patch adds a field that does cover the whole union and adds
static_asserts to ensure it stays correct.
https://reviews.llvm.org/D24223
Files:
llvm/include/llvm/CodeGen/SelectionDAGNodes.h
Index: llvm/include/llvm/CodeGen/SelectionDAGNodes.h
===================================================================
--- llvm/include/llvm/CodeGen/SelectionDAGNodes.h
+++ llvm/include/llvm/CodeGen/SelectionDAGNodes.h
@@ -463,14 +463,30 @@
};
union {
+ uint16_t RawSDNodeBits;
SDNodeBitfields SDNodeBits;
ConstantSDNodeBitfields ConstantSDNodeBits;
MemSDNodeBitfields MemSDNodeBits;
LSBaseSDNodeBitfields LSBaseSDNodeBits;
LoadSDNodeBitfields LoadSDNodeBits;
StoreSDNodeBitfields StoreSDNodeBits;
};
+ // RawSDNodeBits must cover the entirety of the union. Which means that all
+ // of the union's members must have size <= RawSDNodeBits.
+ static_assert(sizeof(SDNodeBits) <= sizeof(RawSDNodeBits),
+ "SDNodeBits too wide");
+ static_assert(sizeof(ConstantSDNodeBits) <= sizeof(RawSDNodeBits),
+ "ConstantSDNodeBits too wide");
+ static_assert(sizeof(MemSDNodeBits) <= sizeof(RawSDNodeBits),
+ "MemSDNodeBits too wide");
+ static_assert(sizeof(LSBaseSDNodeBits) <= sizeof(RawSDNodeBits),
+ "LSBaseSDNodeBits too wide");
+ static_assert(sizeof(LoadSDNodeBits) <= sizeof(RawSDNodeBits),
+ "LoadSDNodeBits too wide");
+ static_assert(sizeof(StoreSDNodeBits) <= sizeof(RawSDNodeBits),
+ "StoreSDNodeBits too wide");
+
private:
/// Unique id per SDNode in the DAG.
int NodeId;
@@ -876,7 +892,7 @@
: NodeType(Opc), NodeId(-1), OperandList(nullptr), ValueList(VTs.VTs),
UseList(nullptr), NumOperands(0), NumValues(VTs.NumVTs), IROrder(Order),
debugLoc(std::move(dl)) {
- memset(&SDNodeBits, 0, sizeof(SDNodeBits));
+ memset(&RawSDNodeBits, 0, sizeof(RawSDNodeBits));
assert(debugLoc.hasTrivialDestructor() && "Expected trivial destructor");
assert(NumValues == VTs.NumVTs &&
"NumValues wasn't wide enough for its operands!");
@@ -1095,9 +1111,7 @@
/// function should only be used to compute a FoldingSetNodeID value.
unsigned getRawSubclassData() const {
uint16_t Data;
- memcpy(&Data, &SDNodeBits, sizeof(SDNodeBits));
- static_assert(sizeof(SDNodeBits) <= sizeof(uint16_t),
- "SDNodeBits field too large?");
+ memcpy(&Data, &RawSDNodeBits, sizeof(RawSDNodeBits));
return Data;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24223.70299.patch
Type: text/x-patch
Size: 2331 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160904/0baa2ece/attachment.bin>
More information about the llvm-commits
mailing list