static void writeModuleMetadata(const Module &M,
const ValueEnumerator &VE,
BitstreamWriter &Stream) {
- if (VE.getMDs().empty() && M.named_metadata_empty())
+ if (!VE.hasMDs() && M.named_metadata_empty())
return;
Stream.EnterSubblock(bitc::METADATA_BLOCK_ID, 3);
static void writeFunctionMetadata(const Function &F, const ValueEnumerator &VE,
BitstreamWriter &Stream) {
- ArrayRef<const Metadata *> MDs = VE.getFunctionMDs();
- if (MDs.empty())
+ if (!VE.hasMDs())
return;
Stream.EnterSubblock(bitc::METADATA_BLOCK_ID, 3);
SmallVector<uint64_t, 64> Record;
- writeMetadataRecords(MDs, VE, Stream, Record);
+ assert(VE.getMDStrings().empty() &&
+ "Unexpected strings at the function-level");
+ writeMetadataRecords(VE.getNonMDStrings(), VE, Stream, Record);
Stream.ExitBlock();
}
std::vector<const Metadata *> MDs;
typedef DenseMap<const Metadata *, unsigned> MetadataMapType;
MetadataMapType MetadataMap;
- unsigned NumMDStrings = 0;
bool ShouldPreserveUseListOrder;
typedef DenseMap<AttributeSet, unsigned> AttributeGroupMapType;
/// When a function is incorporated, this is the size of the Metadatas list
/// before incorporation.
- unsigned NumModuleMDs;
+ unsigned NumModuleMDs = 0;
+ unsigned NumMDStrings = 0;
unsigned FirstFuncConstantID;
unsigned FirstInstID;
}
const ValueList &getValues() const { return Values; }
- const std::vector<const Metadata *> &getMDs() const { return MDs; }
+
+ /// Check whether the current block has any metadata to emit.
+ bool hasMDs() const { return NumModuleMDs < MDs.size(); }
+
+ // Get the MDString metadata for this block.
ArrayRef<const Metadata *> getMDStrings() const {
- return makeArrayRef(MDs).slice(0, NumMDStrings);
+ return makeArrayRef(MDs).slice(NumModuleMDs, NumMDStrings);
}
+
+ // Get the non-MDString metadata for this block.
ArrayRef<const Metadata *> getNonMDStrings() const {
- return makeArrayRef(MDs).slice(NumMDStrings);
- }
- ArrayRef<const Metadata *> getFunctionMDs() const {
- return makeArrayRef(MDs).slice(NumModuleMDs);
+ return makeArrayRef(MDs).slice(NumModuleMDs).slice(NumMDStrings);
}
const TypeList &getTypes() const { return Types; }