[llvm-commits] [PATCH 09/20] [AVX] Make IntInit Unique
Jakob Stoklund Olesen
stoklund at 2pi.dk
Wed Jul 20 08:43:43 PDT 2011
On Jul 19, 2011, at 1:11 PM, David Greene wrote:
> Use a DenseMap to make sure only one IntInit of any value exists.
> ---
> utils/TableGen/Record.cpp | 14 +++++++++++++-
> 1 files changed, 13 insertions(+), 1 deletions(-)
>
> diff --git oldutils/TableGen/Record.cpp newutils/TableGen/Record.cpp
> index 4c019d3..dda0b71 100644
> --- oldutils/TableGen/Record.cpp
> +++ newutils/TableGen/Record.cpp
> @@ -491,7 +491,19 @@ const Init *BitsInit::resolveReferences(Record &R, const RecordVal *RV) const {
> }
>
> const IntInit *IntInit::get(int64_t V) {
> - return new IntInit(V);
> + typedef DenseMap<int64_t, IntInit *> Pool;
> + static Pool ThePool;
> +
> + Pool::iterator Result = ThePool.find(V);
> +
> + if (Result == ThePool.end()) {
> + IntInit *New = new IntInit(V);
> + bool Inserted = false;
> + tie(Result, Inserted) = ThePool.insert(std::make_pair(V, New));
> + assert(Inserted && "Did not insert new Init into pool!");
> + }
> +
> + return Result->second;
> }
This pattern is faster and simpler:
const IntInit *&I = ThePool[V];
if (!I) I = new IntInit(V);
return I;
/jakob
More information about the llvm-commits
mailing list