llvm.org GIT mirror llvm / 6209869
Speedup bitcode writer. Do not walk all values for all functions to emit function local metadata. In one testcase, probably worst case scenario, the 70x speed up is seen. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@105360 91177308-0d34-0410-b5e6-96231b3b80d8 Devang Patel 9 years ago
3 changed file(s) with 16 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
576576 BitstreamWriter &Stream) {
577577 bool StartedMetadataBlock = false;
578578 SmallVector Record;
579 const ValueEnumerator::ValueList &Vals = VE.getMDValues();
580
579 const SmallVector &Vals = VE.getFunctionLocalMDValues();
581580 for (unsigned i = 0, e = Vals.size(); i != e; ++i)
582 if (const MDNode *N = dyn_cast(Vals[i].first))
581 if (const MDNode *N = Vals[i])
583582 if (N->isFunctionLocal() && N->getFunction() == &F) {
584583 if (!StartedMetadataBlock) {
585584 Stream.EnterSubblock(bitc::METADATA_BLOCK_ID, 3);
587586 }
588587 WriteMDNode(N, VE, Stream, Record);
589588 }
590
589
591590 if (StartedMetadataBlock)
592591 Stream.ExitBlock();
593592 }
256256 else
257257 EnumerateType(Type::getVoidTy(MD->getContext()));
258258 }
259 if (N->isFunctionLocal() && N->getFunction())
260 FunctionLocalMDs.push_back(N);
259261 return;
260262 }
261263
413415
414416 FirstInstID = Values.size();
415417
416 SmallVector FunctionLocalMDs;
418 FunctionLocalMDs.clear();
419 SmallVector FnLocalMDVector;
417420 // Add all of the instructions.
418421 for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
419422 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E; ++I) {
422425 if (MDNode *MD = dyn_cast(*OI))
423426 if (MD->isFunctionLocal() && MD->getFunction())
424427 // Enumerate metadata after the instructions they might refer to.
425 FunctionLocalMDs.push_back(MD);
428 FnLocalMDVector.push_back(MD);
426429 }
427430 if (!I->getType()->isVoidTy())
428431 EnumerateValue(I);
430433 }
431434
432435 // Add all of the function-local metadata.
433 for (unsigned i = 0, e = FunctionLocalMDs.size(); i != e; ++i)
434 EnumerateOperandType(FunctionLocalMDs[i]);
436 for (unsigned i = 0, e = FnLocalMDVector.size(); i != e; ++i)
437 EnumerateOperandType(FnLocalMDVector[i]);
435438 }
436439
437440 void ValueEnumerator::purgeFunction() {
1414 #define VALUE_ENUMERATOR_H
1515
1616 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/ADT/SmallVector.h"
1718 #include "llvm/Attributes.h"
1819 #include
1920
2526 class BasicBlock;
2627 class Function;
2728 class Module;
28 class MetadataBase;
29 class MDNode;
2930 class NamedMDNode;
3031 class AttrListPtr;
3132 class TypeSymbolTable;
4849 ValueMapType ValueMap;
4950 ValueList Values;
5051 ValueList MDValues;
52 SmallVector FunctionLocalMDs;
5153 ValueMapType MDValueMap;
5254
5355 typedef DenseMap AttributeMapType;
104106
105107 const ValueList &getValues() const { return Values; }
106108 const ValueList &getMDValues() const { return MDValues; }
109 const SmallVector &getFunctionLocalMDValues() const {
110 return FunctionLocalMDs;
111 }
107112 const TypeList &getTypes() const { return Types; }
108113 const std::vector &getBasicBlocks() const {
109114 return BasicBlocks;