aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2023-12-18 20:30:12 +0000
committerDimitry Andric <dim@FreeBSD.org>2024-04-19 21:12:03 +0000
commitc9157d925c489f07ba9c0b2ce47e5149b75969a5 (patch)
tree08bc4a3d9cad3f9ebffa558ddf140b9d9257b219 /contrib/llvm-project/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
parent2a66844f606a35d68ad8a8061f4bea204274b3bc (diff)
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp26
1 files changed, 18 insertions, 8 deletions
diff --git a/contrib/llvm-project/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp b/contrib/llvm-project/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
index 2c321f4a79af..e2d0aeee092e 100644
--- a/contrib/llvm-project/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
+++ b/contrib/llvm-project/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
@@ -1392,17 +1392,23 @@ static uint64_t rotateSign(APInt Val) {
return I < 0 ? ~(U << 1) : U << 1;
}
-static uint64_t rotateSign(DISubrange::BoundType Val) {
- return rotateSign(Val.get<ConstantInt *>()->getValue());
-}
-
void DXILBitcodeWriter::writeDISubrange(const DISubrange *N,
SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev) {
Record.push_back(N->isDistinct());
+
+ // TODO: Do we need to handle DIExpression here? What about cases where Count
+ // isn't specified but UpperBound and such are?
+ ConstantInt *Count = N->getCount().dyn_cast<ConstantInt *>();
+ assert(Count && "Count is missing or not ConstantInt");
+ Record.push_back(Count->getValue().getSExtValue());
+
+ // TODO: Similarly, DIExpression is allowed here now
+ DISubrange::BoundType LowerBound = N->getLowerBound();
+ assert((LowerBound.isNull() || LowerBound.is<ConstantInt *>()) &&
+ "Lower bound provided but not ConstantInt");
Record.push_back(
- N->getCount().get<ConstantInt *>()->getValue().getSExtValue());
- Record.push_back(rotateSign(N->getLowerBound()));
+ LowerBound ? rotateSign(LowerBound.get<ConstantInt *>()->getValue()) : 0);
Stream.EmitRecord(bitc::METADATA_SUBRANGE, Record, Abbrev);
Record.clear();
@@ -1766,14 +1772,18 @@ unsigned DXILBitcodeWriter::createMetadataStringsAbbrev() {
void DXILBitcodeWriter::writeMetadataStrings(
ArrayRef<const Metadata *> Strings, SmallVectorImpl<uint64_t> &Record) {
+ if (Strings.empty())
+ return;
+
+ unsigned MDSAbbrev = createMetadataStringsAbbrev();
+
for (const Metadata *MD : Strings) {
const MDString *MDS = cast<MDString>(MD);
// Code: [strchar x N]
Record.append(MDS->bytes_begin(), MDS->bytes_end());
// Emit the finished record.
- Stream.EmitRecord(bitc::METADATA_STRING_OLD, Record,
- createMetadataStringsAbbrev());
+ Stream.EmitRecord(bitc::METADATA_STRING_OLD, Record, MDSAbbrev);
Record.clear();
}
}