aboutsummaryrefslogtreecommitdiff
path: root/lib/Bytecode/Writer/SlotCalculator.cpp
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2007-01-12 07:05:14 +0000
committerReid Spencer <rspencer@reidspencer.com>2007-01-12 07:05:14 +0000
commita54b7cbd452b3adb2f51346140d996b29c2cdb30 (patch)
tree00514e24a3fab3804f1a99557ebd343382d0dc27 /lib/Bytecode/Writer/SlotCalculator.cpp
parented3098989580ecaee7fc89de548afb4c811bea31 (diff)
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
Diffstat (limited to 'lib/Bytecode/Writer/SlotCalculator.cpp')
-rw-r--r--lib/Bytecode/Writer/SlotCalculator.cpp75
1 files changed, 48 insertions, 27 deletions
diff --git a/lib/Bytecode/Writer/SlotCalculator.cpp b/lib/Bytecode/Writer/SlotCalculator.cpp
index fdf7174b85..2d4cd0c4cb 100644
--- a/lib/Bytecode/Writer/SlotCalculator.cpp
+++ b/lib/Bytecode/Writer/SlotCalculator.cpp
@@ -31,26 +31,45 @@
#include <functional>
using namespace llvm;
-#if 0
+#ifndef NDEBUG
#include "llvm/Support/Streams.h"
-#define SC_DEBUG(X) cerr << X
+#include "llvm/Support/CommandLine.h"
+static cl::opt<bool> SlotCalculatorDebugOption("scdebug",cl::init(false),
+ cl::desc("Enable SlotCalculator debug output"), cl::Hidden);
+#define SC_DEBUG(X) if (SlotCalculatorDebugOption) cerr << X
#else
#define SC_DEBUG(X)
#endif
+void SlotCalculator::insertPrimitives() {
+ // Preload the table with the built-in types. These built-in types are
+ // inserted first to ensure that they have low integer indices which helps to
+ // keep bytecode sizes small. Note that the first group of indices must match
+ // the Type::TypeIDs for the primitive types. After that the integer types are
+ // added, but the order and value is not critical. What is critical is that
+ // the indices of these "well known" slot numbers be properly maintained in
+ // Reader.h which uses them directly to extract values of these types.
+ SC_DEBUG("Inserting primitive types:\n");
+ // See WellKnownTypeSlots in Reader.h
+ insertType(Type::VoidTy, true); // 0: VoidTySlot
+ insertType(Type::FloatTy, true); // 1: FloatTySlot
+ insertType(Type::DoubleTy, true); // 2: DoubleTySlot
+ insertType(Type::LabelTy, true); // 3: LabelTySlot
+ assert(TypeMap.size() == Type::FirstDerivedTyID && "Invalid primitive insert");
+ // Above here *must* correspond 1:1 with the primitive types.
+ insertType(Type::Int1Ty, true); // 4: BoolTySlot
+ insertType(Type::Int8Ty, true); // 5: Int8TySlot
+ insertType(Type::Int16Ty, true); // 6: Int16TySlot
+ insertType(Type::Int32Ty, true); // 7: Int32TySlot
+ insertType(Type::Int64Ty, true); // 8: Int64TySlot
+}
+
SlotCalculator::SlotCalculator(const Module *M ) {
ModuleContainsAllFunctionConstants = false;
ModuleTypeLevel = 0;
TheModule = M;
- // Preload table... Make sure that all of the primitive types are in the table
- // and that their Primitive ID is equal to their slot #
- //
- SC_DEBUG("Inserting primitive types:\n");
- for (unsigned i = 0; i < Type::FirstDerivedTyID; ++i) {
- assert(Type::getPrimitiveType((Type::TypeID)i));
- insertType(Type::getPrimitiveType((Type::TypeID)i), true);
- }
+ insertPrimitives();
if (M == 0) return; // Empty table...
processModule();
@@ -60,14 +79,7 @@ SlotCalculator::SlotCalculator(const Function *M ) {
ModuleContainsAllFunctionConstants = false;
TheModule = M ? M->getParent() : 0;
- // Preload table... Make sure that all of the primitive types are in the table
- // and that their Primitive ID is equal to their slot #
- //
- SC_DEBUG("Inserting primitive types:\n");
- for (unsigned i = 0; i < Type::FirstDerivedTyID; ++i) {
- assert(Type::getPrimitiveType((Type::TypeID)i));
- insertType(Type::getPrimitiveType((Type::TypeID)i), true);
- }
+ insertPrimitives();
if (TheModule == 0) return; // Empty table...
@@ -423,15 +435,14 @@ unsigned SlotCalculator::getOrCreateCompactionTableSlot(const Value *V) {
/// getOrCreateCompactionTableSlot - This method is used to build up the initial
/// approximation of the compaction table.
unsigned SlotCalculator::getOrCreateCompactionTableSlot(const Type *T) {
- std::map<const Type*, unsigned>::iterator I =
- CompactionTypeMap.lower_bound(T);
+ CompactionTypeMapType::iterator I = CompactionTypeMap.lower_bound(T);
if (I != CompactionTypeMap.end() && I->first == T)
return I->second; // Already exists?
unsigned SlotNo = CompactionTypes.size();
- SC_DEBUG("Inserting Compaction Type #" << SlotNo << ": " << T << "\n");
+ SC_DEBUG("Inserting Compaction Type #" << SlotNo << ": " << *T << "\n");
CompactionTypes.push_back(T);
- CompactionTypeMap.insert(std::make_pair(T, SlotNo));
+ CompactionTypeMap[T] = SlotNo;
return SlotNo;
}
@@ -452,6 +463,16 @@ void SlotCalculator::buildCompactionTable(const Function *F) {
CompactionTypes.push_back(PrimTy);
CompactionTypeMap[PrimTy] = i;
}
+ CompactionTypeMap[Type::Int1Ty] = CompactionTypes.size();
+ CompactionTypes.push_back(Type::Int1Ty);
+ CompactionTypeMap[Type::Int8Ty] = CompactionTypes.size();
+ CompactionTypes.push_back(Type::Int8Ty);
+ CompactionTypeMap[Type::Int16Ty] = CompactionTypes.size();
+ CompactionTypes.push_back(Type::Int16Ty);
+ CompactionTypeMap[Type::Int32Ty] = CompactionTypes.size();
+ CompactionTypes.push_back(Type::Int32Ty);
+ CompactionTypeMap[Type::Int64Ty] = CompactionTypes.size();
+ CompactionTypes.push_back(Type::Int64Ty);
// Next, include any types used by function arguments.
for (Function::const_arg_iterator I = F->arg_begin(), E = F->arg_end();
@@ -485,7 +506,7 @@ void SlotCalculator::buildCompactionTable(const Function *F) {
if (CompactionTable[i].empty() && (i != Type::VoidTyID) &&
i != Type::LabelTyID) {
const Type *Ty = CompactionTypes[i];
- SC_DEBUG("Getting Null Value #" << i << " for Type " << Ty << "\n");
+ SC_DEBUG("Getting Null Value #" << i << " for Type " << *Ty << "\n");
assert(Ty->getTypeID() != Type::VoidTyID);
assert(Ty->getTypeID() != Type::LabelTyID);
getOrCreateCompactionTableSlot(Constant::getNullValue(Ty));
@@ -618,7 +639,8 @@ void SlotCalculator::pruneCompactionTable() {
/// to determine if its actually empty.
bool SlotCalculator::CompactionTableIsEmpty() const {
// Check a degenerate case, just in case.
- if (CompactionTable.size() == 0) return true;
+ if (CompactionTable.size() == 0)
+ return true;
// Check each plane
for (unsigned i = 0, e = CompactionTable.size(); i < e; ++i) {
@@ -830,7 +852,7 @@ int SlotCalculator::doInsertValue(const Value *D) {
unsigned DestSlot = NodeMap[D] = Table[Ty].size();
Table[Ty].push_back(D);
- SC_DEBUG(" Inserting value [" << Ty << "] = " << D << " slot=" <<
+ SC_DEBUG(" Inserting value [" << Ty << "] = " << *D << " slot=" <<
DestSlot << " [");
// G = Global, C = Constant, T = Type, F = Function, o = other
SC_DEBUG((isa<GlobalVariable>(D) ? "G" : (isa<Constant>(D) ? "C" :
@@ -848,7 +870,6 @@ int SlotCalculator::doInsertType(const Type *Ty) {
unsigned DestSlot = TypeMap[Ty] = Types.size();
Types.push_back(Ty);
- SC_DEBUG(" Inserting type [" << DestSlot << "] = " << Ty << "\n" );
+ SC_DEBUG(" Inserting type [" << DestSlot << "] = " << *Ty << "\n" );
return (int)DestSlot;
}
-