mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-28 06:24:57 +00:00
IR: Add assembly/bitcode support for function metadata attachments
Add serialization support for function metadata attachments (added in r235783). The syntax is: define @foo() !attach !0 { Metadata attachments are only allowed on functions with bodies. Since they come before the `{`, they're not really part of the body; since they require a body, they're not really part of the header. In `LLParser` I gave them a separate function called from `ParseDefine()`, `ParseOptionalFunctionMetadata()`. In bitcode, I'm using the same `METADATA_ATTACHMENT` record used by instructions. Instruction metadata attachments are included in a special "attachment" block at the end of a `Function`. The attachment records are laid out like this: InstID (KindID MetadataID)+ Note that these records always have an odd number of fields. The new code takes advantage of this to recognize function attachments (which don't need an instruction ID): (KindID MetadataID)+ This means we can use the same attachment block already used for instructions. This is part of PR23340. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235785 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -1279,6 +1279,15 @@ static void WriteMetadataAttachment(const Function &F,
|
||||
// Write metadata attachments
|
||||
// METADATA_ATTACHMENT - [m x [value, [n x [id, mdnode]]]
|
||||
SmallVector<std::pair<unsigned, MDNode *>, 4> MDs;
|
||||
F.getAllMetadata(MDs);
|
||||
if (!MDs.empty()) {
|
||||
for (const auto &I : MDs) {
|
||||
Record.push_back(I.first);
|
||||
Record.push_back(VE.getMetadataID(I.second));
|
||||
}
|
||||
Stream.EmitRecord(bitc::METADATA_ATTACHMENT, Record, 0);
|
||||
Record.clear();
|
||||
}
|
||||
|
||||
for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
|
||||
for (BasicBlock::const_iterator I = BB->begin(), E = BB->end();
|
||||
@ -2091,7 +2100,7 @@ static void WriteFunction(const Function &F, ValueEnumerator &VE,
|
||||
// Keep a running idea of what the instruction ID is.
|
||||
unsigned InstID = CstEnd;
|
||||
|
||||
bool NeedsMetadataAttachment = false;
|
||||
bool NeedsMetadataAttachment = F.hasMetadata();
|
||||
|
||||
MDLocation *LastDL = nullptr;
|
||||
|
||||
|
@ -348,6 +348,11 @@ ValueEnumerator::ValueEnumerator(const Module &M,
|
||||
for (const Argument &A : F.args())
|
||||
EnumerateType(A.getType());
|
||||
|
||||
// Enumerate metadata attached to this function.
|
||||
F.getAllMetadata(MDs);
|
||||
for (const auto &I : MDs)
|
||||
EnumerateMetadata(I.second);
|
||||
|
||||
for (const BasicBlock &BB : F)
|
||||
for (const Instruction &I : BB) {
|
||||
for (const Use &Op : I.operands()) {
|
||||
|
Reference in New Issue
Block a user