From e98f9258349aeb8414a556326aeee8ba94a7c839 Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Wed, 28 Dec 2016 22:30:28 +0000 Subject: Add an index for Module Metadata record in the bitcode This index record the position for each metadata record in the bitcode, so that the reader will be able to lazy-load on demand each individual record. We also make sure that every abbrev is emitted upfront so that the block can be skipped while reading. I don't plan to commit this before having the reader counterpart, but I figured this can be reviewed mostly independently. Recommit r290684 (was reverted in r290686 because a test was broken) after adding a threshold to avoid emitting the index when unnecessary (little amount of metadata). This optimization "hides" a limitation of the ability to backpatch in the bitstream: we can only backpatch safely when the position has been flushed. So if we emit an index for one metadata, it is possible that (part of) the offset placeholder hasn't been flushed and the backpatch will fail. Differential Revision: https://reviews.llvm.org/D28083 llvm-svn: 290690 --- llvm/test/Bitcode/mdnodes-distinct-in-post-order.ll | 8 +++++++- llvm/test/Bitcode/mdnodes-distinct-nodes-break-cycles.ll | 6 +++++- llvm/test/Bitcode/mdnodes-distinct-nodes-first.ll | 6 +++++- llvm/test/Bitcode/mdnodes-in-post-order.ll | 9 ++++++++- llvm/test/Bitcode/metadata-function-blocks.ll | 5 ++++- 5 files changed, 29 insertions(+), 5 deletions(-) (limited to 'llvm/test/Bitcode') diff --git a/llvm/test/Bitcode/mdnodes-distinct-in-post-order.ll b/llvm/test/Bitcode/mdnodes-distinct-in-post-order.ll index 6e6ba604235..cefc1f5163f 100644 --- a/llvm/test/Bitcode/mdnodes-distinct-in-post-order.ll +++ b/llvm/test/Bitcode/mdnodes-distinct-in-post-order.ll @@ -1,4 +1,5 @@ -; RUN: llvm-as <%s | llvm-bcanalyzer -dump | FileCheck %s +; RUN: llvm-as <%s -bitcode-mdindex-threshold=0 | llvm-bcanalyzer -dump | FileCheck %s -check-prefix=CHECK -check-prefix=MDINDEX +; RUN: llvm-as <%s | llvm-bcanalyzer -dump | FileCheck %s -check-prefix=CHECK ; Check that distinct nodes are emitted in post-order to avoid unnecessary ; forward references. @@ -17,6 +18,11 @@ ; CHECK-NEXT: !4 = distinct !{!1, !3, !2} +; Before the named records we emit the index containing the position of the +; previously emitted records, but only if we have a number of record above +; a threshold (can be controlled through `-bitcode-mdindex-threshold`). +; MDINDEX: !3 = !{!2} +; Before the named records we emit the index containing the position of the +; previously emitted records +; CHECK-NEXT: !2 = !{!1} +; Before the named records we emit the index containing the position of the +; previously emitted records +; CHECK-NEXT: ; CHECK-NEXT: @@ -27,6 +30,10 @@ ; CHECK-NEXT: !6 = !{!3, !5, !4} +; Before the named records we emit the index containing the position of the +; previously emitted records +; CHECK-NEXT: !4 = !{!"named"} -- cgit v1.2.3