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/Writer/BitcodeWriter.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'llvm/lib/Bitcode/Writer/BitcodeWriter.cpp') diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index d9086bfebbd2..bec0caef58af 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -395,6 +395,8 @@ private: void writeModuleConstants(); bool pushValueAndType(const Value *V, unsigned InstID, SmallVectorImpl &Vals); + bool pushValueOrMetadata(const Value *V, unsigned InstID, + SmallVectorImpl &Vals); void writeOperandBundles(const CallBase &CB, unsigned InstID); void pushValue(const Value *V, unsigned InstID, SmallVectorImpl &Vals); @@ -2931,6 +2933,19 @@ bool ModuleBitcodeWriter::pushValueAndType(const Value *V, unsigned InstID, return false; } +bool ModuleBitcodeWriter::pushValueOrMetadata(const Value *V, unsigned InstID, + SmallVectorImpl &Vals) { + bool IsMetadata = V->getType()->isMetadataTy(); + if (IsMetadata) { + Vals.push_back(bitc::OB_METADATA); + Metadata *MD = cast(V)->getMetadata(); + unsigned ValID = VE.getMetadataID(MD); + Vals.push_back(InstID - ValID); + return false; + } + return pushValueAndType(V, InstID, Vals); +} + void ModuleBitcodeWriter::writeOperandBundles(const CallBase &CS, unsigned InstID) { SmallVector Record; @@ -2941,7 +2956,7 @@ void ModuleBitcodeWriter::writeOperandBundles(const CallBase &CS, Record.push_back(C.getOperandBundleTagID(Bundle.getTagName())); for (auto &Input : Bundle.Inputs) - pushValueAndType(Input, InstID, Record); + pushValueOrMetadata(Input, InstID, Record); Stream.EmitRecord(bitc::FUNC_CODE_OPERAND_BUNDLE, Record); Record.clear(); -- cgit v1.2.3