From 15de239406bfc0a1dfbd0640490c4bd5d1e0ac33 Mon Sep 17 00:00:00 2001 From: Serge Pavlov Date: Fri, 11 Oct 2024 12:09:10 +0700 Subject: [IR] Allow MDString in operand bundles (#110805) This change implements support of metadata strings in operand bundle values. It makes possible calls like: call void @some_func(i32 %x) [ "foo"(i32 42, metadata !"abc") ] It requires some extension of the bitcode serialization. As SSA values and metadata are stored in different tables, there must be a way to distinguish them during deserialization. It is implemented by putting a special marker before the metadata index. The marker cannot be treated as a reference to any SSA value, so it unambiguously identifies metadata. It allows extending the bitcode serialization without breaking compatibility. Metadata as operand bundle values are intended to be used in floating-point function calls. They would represent the same information as now is passed by the constrained intrinsic arguments. --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp') diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 6f997510b036..8ee93253bc24 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -792,6 +792,24 @@ private: return ResVal == nullptr; } + bool getValueOrMetadata(const SmallVectorImpl &Record, + unsigned &Slot, unsigned InstNum, Value *&ResVal, + BasicBlock *ConstExprInsertBB) { + if (Slot == Record.size()) + return true; + unsigned ValID = Record[Slot++]; + if (ValID != bitc::OB_METADATA) { + unsigned TypeId; + return getValueTypePair(Record, --Slot, InstNum, ResVal, TypeId, + ConstExprInsertBB); + } + if (Slot == Record.size()) + return true; + unsigned ValNo = InstNum - (unsigned)Record[Slot++]; + ResVal = MetadataAsValue::get(Context, getFnMetadataByID(ValNo)); + return false; + } + /// Read a value out of the specified record from slot 'Slot'. Increment Slot /// past the number of slots used by the value in the record. Return true if /// there is an error. @@ -6767,8 +6785,7 @@ Error BitcodeReader::parseFunctionBody(Function *F) { unsigned OpNum = 1; while (OpNum != Record.size()) { Value *Op; - unsigned OpTypeID; - if (getValueTypePair(Record, OpNum, NextValueNo, Op, OpTypeID, CurBB)) + if (getValueOrMetadata(Record, OpNum, NextValueNo, Op, CurBB)) return error("Invalid record"); Inputs.push_back(Op); } -- cgit v1.2.3