aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
diff options
context:
space:
mode:
authorSerge Pavlov <sepavloff@gmail.com>2024-10-11 12:09:10 +0700
committerGitHub <noreply@github.com>2024-10-11 12:09:10 +0700
commit15de239406bfc0a1dfbd0640490c4bd5d1e0ac33 (patch)
treeb0dcd6f643ab771b6a9cc62502a06d02d178a267 /llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
parentbf81bd800fbcf1d11f149d897f55409e27ec59fb (diff)
downloadllvm-15de239406bfc0a1dfbd0640490c4bd5d1e0ac33.zip
llvm-15de239406bfc0a1dfbd0640490c4bd5d1e0ac33.tar.gz
llvm-15de239406bfc0a1dfbd0640490c4bd5d1e0ac33.tar.bz2
[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.
Diffstat (limited to 'llvm/lib/Bitcode/Writer/BitcodeWriter.cpp')
-rw-r--r--llvm/lib/Bitcode/Writer/BitcodeWriter.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index d9086bf..bec0cae 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<unsigned> &Vals);
+ bool pushValueOrMetadata(const Value *V, unsigned InstID,
+ SmallVectorImpl<unsigned> &Vals);
void writeOperandBundles(const CallBase &CB, unsigned InstID);
void pushValue(const Value *V, unsigned InstID,
SmallVectorImpl<unsigned> &Vals);
@@ -2931,6 +2933,19 @@ bool ModuleBitcodeWriter::pushValueAndType(const Value *V, unsigned InstID,
return false;
}
+bool ModuleBitcodeWriter::pushValueOrMetadata(const Value *V, unsigned InstID,
+ SmallVectorImpl<unsigned> &Vals) {
+ bool IsMetadata = V->getType()->isMetadataTy();
+ if (IsMetadata) {
+ Vals.push_back(bitc::OB_METADATA);
+ Metadata *MD = cast<MetadataAsValue>(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<unsigned, 64> 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();