From da3d76b4cfbb5ebeb79e03a0abeabd403fe9260a Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Fri, 28 Sep 2012 16:44:29 +0000 Subject: [PATCH] Avoid malloc thrashing in the uninitialized value analysis. - The size of the packed vector is often small, save mallocs using SmallBitVector. - Copying SmallBitVectors is also cheap, remove a level of indirection. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164827 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/UninitializedValues.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/Analysis/UninitializedValues.cpp b/lib/Analysis/UninitializedValues.cpp index 8ebee9614a..b2e27cad1f 100644 --- a/lib/Analysis/UninitializedValues.cpp +++ b/lib/Analysis/UninitializedValues.cpp @@ -13,6 +13,7 @@ #include #include "llvm/ADT/Optional.h" +#include "llvm/ADT/SmallBitVector.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/PackedVector.h" #include "llvm/ADT/DenseMap.h" @@ -98,22 +99,21 @@ static bool isAlwaysUninit(const Value v) { namespace { -typedef llvm::PackedVector ValueVector; +typedef llvm::PackedVector ValueVector; class CFGBlockValues { const CFG &cfg; - std::vector vals; + SmallVector vals; ValueVector scratch; DeclToIndex declToIndex; public: CFGBlockValues(const CFG &cfg); - ~CFGBlockValues(); unsigned getNumEntries() const { return declToIndex.size(); } void computeSetOfDeclarations(const DeclContext &dc); ValueVector &getValueVector(const CFGBlock *block) { - return *vals[block->getBlockID()]; + return vals[block->getBlockID()]; } void setAllScratchValues(Value V); @@ -139,12 +139,6 @@ public: CFGBlockValues::CFGBlockValues(const CFG &c) : cfg(c), vals(0) {} -CFGBlockValues::~CFGBlockValues() { - for (std::vector::iterator I = vals.begin(), E = vals.end(); - I != E; ++I) - delete *I; -} - void CFGBlockValues::computeSetOfDeclarations(const DeclContext &dc) { declToIndex.computeMap(dc); unsigned decls = declToIndex.size(); @@ -154,7 +148,7 @@ void CFGBlockValues::computeSetOfDeclarations(const DeclContext &dc) { return; vals.resize(n); for (unsigned i = 0; i < n; ++i) - vals[i] = new ValueVector(decls); + vals[i].resize(decls); } #if DEBUG_LOGGING -- 2.40.0