2004-01-20 19:50:12 +00:00
|
|
|
//===-- Analysis/SlotCalculator.h - Calculate value slots -------*- C++ -*-===//
|
2005-04-21 21:48:46 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
2005-04-21 21:48:46 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
2002-04-07 22:49:37 +00:00
|
|
|
// This class calculates the slots that values will land in. This is useful for
|
|
|
|
// when writing bytecode or assembly out, because you have to know these things.
|
|
|
|
//
|
|
|
|
// Specifically, this class calculates the "type plane numbering" that you see
|
|
|
|
// for a function if you strip out all of the symbols in it. For assembly
|
|
|
|
// writing, this is used when a symbol does not have a name. For bytecode
|
|
|
|
// writing, this is always used, and the symbol table is added on later.
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2004-01-20 19:50:12 +00:00
|
|
|
#ifndef LLVM_ANALYSIS_SLOTCALCULATOR_H
|
|
|
|
#define LLVM_ANALYSIS_SLOTCALCULATOR_H
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2007-02-10 06:38:19 +00:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2007-02-10 07:42:59 +00:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2001-06-06 20:29:01 +00:00
|
|
|
#include <vector>
|
2003-11-11 22:41:34 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2001-07-14 06:08:51 +00:00
|
|
|
class Value;
|
2004-07-04 11:42:49 +00:00
|
|
|
class Type;
|
2001-09-07 16:27:05 +00:00
|
|
|
class Module;
|
2002-03-23 22:51:58 +00:00
|
|
|
class Function;
|
2002-04-09 18:35:38 +00:00
|
|
|
class SymbolTable;
|
2007-01-06 07:24:44 +00:00
|
|
|
class TypeSymbolTable;
|
2007-02-05 20:47:22 +00:00
|
|
|
class ValueSymbolTable;
|
2004-01-14 23:37:43 +00:00
|
|
|
class ConstantArray;
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2007-02-10 06:38:19 +00:00
|
|
|
struct ModuleLevelDenseMapKeyInfo {
|
|
|
|
static inline unsigned getEmptyKey() { return ~0U; }
|
|
|
|
static inline unsigned getTombstoneKey() { return ~1U; }
|
|
|
|
static unsigned getHashValue(unsigned Val) { return Val ^ Val >> 4; }
|
|
|
|
static bool isPod() { return true; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-09-07 16:27:05 +00:00
|
|
|
class SlotCalculator {
|
2001-06-06 20:29:01 +00:00
|
|
|
const Module *TheModule;
|
2007-02-10 07:42:59 +00:00
|
|
|
public:
|
2004-07-04 11:42:49 +00:00
|
|
|
typedef std::vector<const Type*> TypeList;
|
2007-02-10 07:42:59 +00:00
|
|
|
typedef SmallVector<const Value*, 16> TypePlane;
|
|
|
|
private:
|
2002-01-20 22:54:45 +00:00
|
|
|
std::vector<TypePlane> Table;
|
2004-07-04 11:42:49 +00:00
|
|
|
TypeList Types;
|
2007-02-10 07:01:05 +00:00
|
|
|
typedef DenseMap<const Value*, unsigned> NodeMapType;
|
2004-07-04 11:42:49 +00:00
|
|
|
NodeMapType NodeMap;
|
|
|
|
|
2007-02-10 07:06:46 +00:00
|
|
|
typedef DenseMap<const Type*, unsigned> TypeMapType;
|
2004-07-04 11:42:49 +00:00
|
|
|
TypeMapType TypeMap;
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2004-01-14 23:37:43 +00:00
|
|
|
/// ConstantStrings - If we are indexing for a bytecode file, this keeps track
|
|
|
|
/// of all of the constants strings that need to be emitted.
|
|
|
|
std::vector<const ConstantArray*> ConstantStrings;
|
|
|
|
|
|
|
|
/// ModuleLevel - Used to keep track of which values belong to the module,
|
|
|
|
/// and which values belong to the currently incorporated function.
|
|
|
|
///
|
2007-02-10 06:38:19 +00:00
|
|
|
DenseMap<unsigned,unsigned,ModuleLevelDenseMapKeyInfo> ModuleLevel;
|
|
|
|
unsigned NumModuleTypes;
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2004-01-18 21:03:49 +00:00
|
|
|
SlotCalculator(const SlotCalculator &); // DO NOT IMPLEMENT
|
|
|
|
void operator=(const SlotCalculator &); // DO NOT IMPLEMENT
|
2001-06-06 20:29:01 +00:00
|
|
|
public:
|
2006-01-25 23:08:15 +00:00
|
|
|
SlotCalculator(const Module *M);
|
2005-04-21 21:48:46 +00:00
|
|
|
|
2004-01-18 21:03:49 +00:00
|
|
|
/// getSlot - Return the slot number of the specified value in it's type
|
2007-04-09 06:14:31 +00:00
|
|
|
/// plane.
|
2004-01-14 23:37:43 +00:00
|
|
|
///
|
2007-02-10 05:18:35 +00:00
|
|
|
unsigned getSlot(const Value *V) const {
|
2007-02-10 06:42:23 +00:00
|
|
|
NodeMapType::const_iterator I = NodeMap.find(V);
|
2007-02-10 05:18:35 +00:00
|
|
|
assert(I != NodeMap.end() && "Value not in slotcalculator!");
|
|
|
|
return I->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getTypeSlot(const Type* T) const {
|
2007-02-10 06:42:23 +00:00
|
|
|
TypeMapType::const_iterator I = TypeMap.find(T);
|
2007-02-10 05:18:35 +00:00
|
|
|
assert(I != TypeMap.end() && "Type not in slotcalc!");
|
|
|
|
return I->second;
|
|
|
|
}
|
2004-01-18 21:03:49 +00:00
|
|
|
|
Bye, Bye Compaction Tables. The benefit compaction tables provides doesn't
outweight its computational costs. This patch removes all compaction
table handling from the bcreader and bcwriter. For the record, here's the
difference betweeen having and not having compaction tables for some tests:
Test With Without Size Chg
Olden/mst 5,602 5,598 +0.1%
viterbi 18,026 17,795 +1.3%
obsequi 162,133 166,663 -2.8%
burg 224,090 228,148 -1.8%
kimwitu++ 4,933,263 5,121,159 -3.8%
176.gcc 8,470,424 9,141,539 -7.3%
It seems that it is more beneficial to larger files, but even on the largest
test case we have (176.gcc) it only amounts ot an I/O saving of 7.3%.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33661 91177308-0d34-0410-b5e6-96231b3b80d8
2007-01-30 19:36:46 +00:00
|
|
|
inline unsigned getNumPlanes() const { return Table.size(); }
|
|
|
|
inline unsigned getNumTypes() const { return Types.size(); }
|
2004-07-04 11:42:49 +00:00
|
|
|
|
2007-02-09 15:25:50 +00:00
|
|
|
TypePlane &getPlane(unsigned Plane) {
|
|
|
|
// Okay we are just returning an entry out of the main Table. Make sure the
|
|
|
|
// plane exists and return it.
|
|
|
|
if (Plane >= Table.size())
|
|
|
|
Table.resize(Plane+1);
|
|
|
|
return Table[Plane];
|
|
|
|
}
|
|
|
|
|
Bye, Bye Compaction Tables. The benefit compaction tables provides doesn't
outweight its computational costs. This patch removes all compaction
table handling from the bcreader and bcwriter. For the record, here's the
difference betweeen having and not having compaction tables for some tests:
Test With Without Size Chg
Olden/mst 5,602 5,598 +0.1%
viterbi 18,026 17,795 +1.3%
obsequi 162,133 166,663 -2.8%
burg 224,090 228,148 -1.8%
kimwitu++ 4,933,263 5,121,159 -3.8%
176.gcc 8,470,424 9,141,539 -7.3%
It seems that it is more beneficial to larger files, but even on the largest
test case we have (176.gcc) it only amounts ot an I/O saving of 7.3%.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33661 91177308-0d34-0410-b5e6-96231b3b80d8
2007-01-30 19:36:46 +00:00
|
|
|
TypeList& getTypes() { return Types; }
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2004-01-14 23:37:43 +00:00
|
|
|
/// incorporateFunction/purgeFunction - If you'd like to deal with a function,
|
|
|
|
/// use these two methods to get its data into the SlotCalculator!
|
|
|
|
///
|
2002-04-07 22:49:37 +00:00
|
|
|
void incorporateFunction(const Function *F);
|
|
|
|
void purgeFunction();
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2004-01-14 23:37:43 +00:00
|
|
|
/// string_iterator/string_begin/end - Access the list of module-level
|
|
|
|
/// constant strings that have been incorporated. This is only applicable to
|
|
|
|
/// bytecode files.
|
|
|
|
typedef std::vector<const ConstantArray*>::const_iterator string_iterator;
|
|
|
|
string_iterator string_begin() const { return ConstantStrings.begin(); }
|
|
|
|
string_iterator string_end() const { return ConstantStrings.end(); }
|
|
|
|
|
2004-01-18 21:03:49 +00:00
|
|
|
private:
|
2007-02-10 04:54:01 +00:00
|
|
|
void CreateSlotIfNeeded(const Value *V);
|
2007-02-10 05:45:09 +00:00
|
|
|
void CreateFunctionValueSlot(const Value *V);
|
2007-02-10 04:47:51 +00:00
|
|
|
unsigned getOrCreateTypeSlot(const Type *T);
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2002-04-07 22:49:37 +00:00
|
|
|
// processModule - Process all of the module level function declarations and
|
2001-09-07 16:27:05 +00:00
|
|
|
// types that are available.
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
2001-09-07 16:27:05 +00:00
|
|
|
void processModule();
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2001-09-07 16:27:05 +00:00
|
|
|
// processSymbolTable - Insert all of the values in the specified symbol table
|
|
|
|
// into the values table...
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
2007-01-06 07:24:44 +00:00
|
|
|
void processTypeSymbolTable(const TypeSymbolTable *ST);
|
2007-02-05 20:47:22 +00:00
|
|
|
void processValueSymbolTable(const ValueSymbolTable *ST);
|
2004-01-18 21:03:49 +00:00
|
|
|
|
For PR1064:
Implement the arbitrary bit-width integer feature. The feature allows
integers of any bitwidth (up to 64) to be defined instead of just 1, 8,
16, 32, and 64 bit integers.
This change does several things:
1. Introduces a new Derived Type, IntegerType, to represent the number of
bits in an integer. The Type classes SubclassData field is used to
store the number of bits. This allows 2^23 bits in an integer type.
2. Removes the five integer Type::TypeID values for the 1, 8, 16, 32 and
64-bit integers. These are replaced with just IntegerType which is not
a primitive any more.
3. Adjust the rest of LLVM to account for this change.
Note that while this incremental change lays the foundation for arbitrary
bit-width integers, LLVM has not yet been converted to actually deal with
them in any significant way. Most optimization passes, for example, will
still only deal with the byte-width integer types. Future increments
will rectify this situation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33113 91177308-0d34-0410-b5e6-96231b3b80d8
2007-01-12 07:05:14 +00:00
|
|
|
// insertPrimitives - helper for constructors to insert primitive types.
|
|
|
|
void insertPrimitives();
|
2001-06-06 20:29:01 +00:00
|
|
|
};
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
#endif
|