aboutsummaryrefslogtreecommitdiff
path: root/lib/Bytecode/Writer/Writer.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/Writer.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/Writer.cpp')
-rw-r--r--lib/Bytecode/Writer/Writer.cpp62
1 files changed, 33 insertions, 29 deletions
diff --git a/lib/Bytecode/Writer/Writer.cpp b/lib/Bytecode/Writer/Writer.cpp
index 9a04428007..c7003cdd7f 100644
--- a/lib/Bytecode/Writer/Writer.cpp
+++ b/lib/Bytecode/Writer/Writer.cpp
@@ -200,16 +200,18 @@ inline BytecodeBlock::~BytecodeBlock() { // Do backpatch when block goes out
void BytecodeWriter::outputType(const Type *T) {
const StructType* STy = dyn_cast<StructType>(T);
if(STy && STy->isPacked())
- output_vbr((unsigned)Type::BC_ONLY_PackedStructTyID);
+ output_vbr((unsigned)Type::PackedStructTyID);
else
output_vbr((unsigned)T->getTypeID());
// That's all there is to handling primitive types...
- if (T->isPrimitiveType()) {
+ if (T->isPrimitiveType())
return; // We might do this if we alias a prim type: %x = type int
- }
switch (T->getTypeID()) { // Handle derived types now.
+ case Type::IntegerTyID:
+ output_vbr(cast<IntegerType>(T)->getBitWidth());
+ break;
case Type::FunctionTyID: {
const FunctionType *MT = cast<FunctionType>(T);
int Slot = Table.getSlot(MT->getReturnType());
@@ -290,8 +292,8 @@ void BytecodeWriter::outputType(const Type *T) {
}
void BytecodeWriter::outputConstant(const Constant *CPV) {
- assert((CPV->getType()->isPrimitiveType() || !CPV->isNullValue()) &&
- "Shouldn't output null constants!");
+ assert(((CPV->getType()->isPrimitiveType() || CPV->getType()->isIntegral()) ||
+ !CPV->isNullValue()) && "Shouldn't output null constants!");
// We must check for a ConstantExpr before switching by type because
// a ConstantExpr can be of any type, and has no explicit value.
@@ -321,19 +323,21 @@ void BytecodeWriter::outputConstant(const Constant *CPV) {
}
switch (CPV->getType()->getTypeID()) {
- case Type::Int1TyID: // Boolean Types
- if (cast<ConstantInt>(CPV)->getZExtValue())
- output_vbr(1U);
- else
- output_vbr(0U);
- break;
-
- case Type::Int8TyID: // Unsigned integer types...
- case Type::Int16TyID:
- case Type::Int32TyID:
- case Type::Int64TyID:
- output_vbr(cast<ConstantInt>(CPV)->getZExtValue());
+ case Type::IntegerTyID: { // Integer types...
+ unsigned NumBits = cast<IntegerType>(CPV->getType())->getBitWidth();
+ if (NumBits == 1)
+ if (cast<ConstantInt>(CPV)->getZExtValue())
+ output_vbr(1U);
+ else
+ output_vbr(0U);
+ else if (NumBits <= 32)
+ output_vbr(uint32_t(cast<ConstantInt>(CPV)->getZExtValue()));
+ else if (NumBits <= 64)
+ output_vbr(uint64_t(cast<ConstantInt>(CPV)->getZExtValue()));
+ else
+ assert("Integer types > 64 bits not supported.");
break;
+ }
case Type::ArrayTyID: {
const ConstantArray *CPA = cast<ConstantArray>(CPV);
@@ -484,12 +488,12 @@ void BytecodeWriter::outputInstructionFormat0(const Instruction *I,
assert(Slot >= 0 && "No slot number for value!?!?");
if (isa<SequentialType>(*TI)) {
- unsigned IdxId;
- switch (I->getOperand(Idx)->getType()->getTypeID()) {
- default: assert(0 && "Unknown index type!");
- case Type::Int32TyID: IdxId = 0; break;
- case Type::Int64TyID: IdxId = 1; break;
- }
+ // These should be either 32-bits or 64-bits, however, with bit
+ // accurate types we just distinguish between less than or equal to
+ // 32-bits or greater than 32-bits.
+ const IntegerType *IdxTy =
+ cast<IntegerType>(I->getOperand(Idx)->getType());
+ unsigned IdxId = IdxTy->getBitWidth() <= 32 ? 0 : 1;
Slot = (Slot << 1) | IdxId;
}
output_vbr(unsigned(Slot));
@@ -735,12 +739,12 @@ void BytecodeWriter::outputInstruction(const Instruction &I) {
for (gep_type_iterator I = gep_type_begin(GEP), E = gep_type_end(GEP);
I != E; ++I, ++Idx)
if (isa<SequentialType>(*I)) {
- unsigned IdxId;
- switch (GEP->getOperand(Idx)->getType()->getTypeID()) {
- default: assert(0 && "Unknown index type!");
- case Type::Int32TyID: IdxId = 0; break;
- case Type::Int64TyID: IdxId = 1; break;
- }
+ // These should be either 32-bits or 64-bits, however, with bit
+ // accurate types we just distinguish between less than or equal to
+ // 32-bits or greater than 32-bits.
+ const IntegerType *IdxTy =
+ cast<IntegerType>(GEP->getOperand(Idx)->getType());
+ unsigned IdxId = IdxTy->getBitWidth() <= 32 ? 0 : 1;
Slots[Idx] = (Slots[Idx] << 1) | IdxId;
if (Slots[Idx] > MaxOpSlot) MaxOpSlot = Slots[Idx];
}