[llvm-commits] CVS: llvm/lib/Bytecode/Reader/ConstantReader.cpp InstructionReader.cpp Reader.cpp ReaderInternals.h
Chris Lattner
lattner at cs.uiuc.edu
Sun Apr 4 20:28:01 PDT 2004
Changes in directory llvm/lib/Bytecode/Reader:
ConstantReader.cpp updated: 1.75 -> 1.76
InstructionReader.cpp updated: 1.69 -> 1.70
Reader.cpp updated: 1.105 -> 1.106
ReaderInternals.h updated: 1.78 -> 1.79
---
Log message:
Implement support for a new LLVM 1.3 bytecode format, which uses uint's
to index into structure types and allows arbitrary 32- and 64-bit integer
types to index into sequential types.
---
Diffs of the changes: (+59 -7)
Index: llvm/lib/Bytecode/Reader/ConstantReader.cpp
diff -u llvm/lib/Bytecode/Reader/ConstantReader.cpp:1.75 llvm/lib/Bytecode/Reader/ConstantReader.cpp:1.76
--- llvm/lib/Bytecode/Reader/ConstantReader.cpp:1.75 Tue Mar 30 20:53:59 2004
+++ llvm/lib/Bytecode/Reader/ConstantReader.cpp Sun Apr 4 20:27:22 2004
@@ -15,6 +15,7 @@
#include "ReaderInternals.h"
#include "llvm/Module.h"
#include "llvm/Constants.h"
+#include "llvm/Support/GetElementPtrTypeIterator.h"
#include <algorithm>
using namespace llvm;
@@ -164,6 +165,20 @@
return ConstantExpr::getCast(ArgVec[0], getType(TypeID));
} else if (Opcode == Instruction::GetElementPtr) { // GetElementPtr
std::vector<Constant*> IdxList(ArgVec.begin()+1, ArgVec.end());
+
+ if (hasRestrictedGEPTypes) {
+ const Type *BaseTy = ArgVec[0]->getType();
+ generic_gep_type_iterator<std::vector<Constant*>::iterator>
+ GTI = gep_type_begin(BaseTy, IdxList.begin(), IdxList.end()),
+ E = gep_type_end(BaseTy, IdxList.begin(), IdxList.end());
+ for (unsigned i = 0; GTI != E; ++GTI, ++i)
+ if (isa<StructType>(*GTI)) {
+ if (IdxList[i]->getType() != Type::UByteTy)
+ throw std::string("Invalid index for getelementptr!");
+ IdxList[i] = ConstantExpr::getCast(IdxList[i], Type::UIntTy);
+ }
+ }
+
return ConstantExpr::getGetElementPtr(ArgVec[0], IdxList);
} else if (Opcode == Instruction::Select) {
assert(ArgVec.size() == 3);
Index: llvm/lib/Bytecode/Reader/InstructionReader.cpp
diff -u llvm/lib/Bytecode/Reader/InstructionReader.cpp:1.69 llvm/lib/Bytecode/Reader/InstructionReader.cpp:1.70
--- llvm/lib/Bytecode/Reader/InstructionReader.cpp:1.69 Sat Apr 3 17:43:42 2004
+++ llvm/lib/Bytecode/Reader/InstructionReader.cpp Sun Apr 4 20:27:22 2004
@@ -308,10 +308,35 @@
for (unsigned i = 1, e = Args.size(); i != e; ++i) {
const CompositeType *TopTy = dyn_cast_or_null<CompositeType>(NextTy);
if (!TopTy) throw std::string("Invalid getelementptr instruction!");
- // FIXME: when PR82 is resolved.
- unsigned IdxTy = isa<StructType>(TopTy) ? Type::UByteTyID :Type::LongTyID;
-
- Idx.push_back(getValue(IdxTy, Args[i]));
+
+ unsigned ValIdx = Args[i];
+ unsigned IdxTy;
+ if (!hasRestrictedGEPTypes) {
+ // Struct indices are always uints, sequential type indices can be any
+ // of the 32 or 64-bit integer types. The actual choice of type is
+ // encoded in the low two bits of the slot number.
+ if (isa<StructType>(TopTy))
+ IdxTy = Type::UIntTyID;
+ else {
+ switch (ValIdx & 3) {
+ case 0: IdxTy = Type::UIntTyID; break;
+ case 1: IdxTy = Type::IntTyID; break;
+ case 2: IdxTy = Type::ULongTyID; break;
+ case 3: IdxTy = Type::LongTyID; break;
+ }
+ ValIdx >>= 2;
+ }
+ } else {
+ IdxTy = isa<StructType>(TopTy) ? Type::UByteTyID : Type::LongTyID;
+ }
+
+ Idx.push_back(getValue(IdxTy, ValIdx));
+
+ // Convert ubyte struct indices into uint struct indices.
+ if (isa<StructType>(TopTy) && hasRestrictedGEPTypes)
+ if (ConstantUInt *C = dyn_cast<ConstantUInt>(Idx.back()))
+ Idx[Idx.size()-1] = ConstantExpr::getCast(C, Type::UIntTy);
+
NextTy = GetElementPtrInst::getIndexedType(InstTy, Idx, true);
}
Index: llvm/lib/Bytecode/Reader/Reader.cpp
diff -u llvm/lib/Bytecode/Reader/Reader.cpp:1.105 llvm/lib/Bytecode/Reader/Reader.cpp:1.106
--- llvm/lib/Bytecode/Reader/Reader.cpp:1.105 Sat Apr 3 17:43:42 2004
+++ llvm/lib/Bytecode/Reader/Reader.cpp Sun Apr 4 20:27:22 2004
@@ -647,12 +647,10 @@
// Default values for the current bytecode version
hasInconsistentModuleGlobalInfo = false;
hasExplicitPrimitiveZeros = false;
+ hasRestrictedGEPTypes = false;
switch (RevisionNum) {
case 0: // LLVM 1.0, 1.1 release version
- // Compared to rev #2, we added support for weak linkage, a more dense
- // encoding, and better varargs support.
-
// Base LLVM 1.0 bytecode format.
hasInconsistentModuleGlobalInfo = true;
hasExplicitPrimitiveZeros = true;
@@ -663,6 +661,13 @@
// Also, it fixed the problem where the size of the ModuleGlobalInfo block
// included the size for the alignment at the end, where the rest of the
// blocks did not.
+
+ // LLVM 1.2 and before required that GEP indices be ubyte constants for
+ // structures and longs for sequential types.
+ hasRestrictedGEPTypes = true;
+
+ // FALL THROUGH
+ case 2: // LLVM 1.3 release version
break;
default:
Index: llvm/lib/Bytecode/Reader/ReaderInternals.h
diff -u llvm/lib/Bytecode/Reader/ReaderInternals.h:1.78 llvm/lib/Bytecode/Reader/ReaderInternals.h:1.79
--- llvm/lib/Bytecode/Reader/ReaderInternals.h:1.78 Sat Apr 3 17:43:42 2004
+++ llvm/lib/Bytecode/Reader/ReaderInternals.h Sun Apr 4 20:27:22 2004
@@ -108,6 +108,13 @@
// int/sbyte/etc.
bool hasExplicitPrimitiveZeros;
+ // Flags to control features specific the LLVM 1.2 and before (revision #1)
+
+ // LLVM 1.2 and earlier required that getelementptr structure indices were
+ // ubyte constants and that sequential type indices were longs.
+ bool hasRestrictedGEPTypes;
+
+
typedef std::vector<ValueList*> ValueTable;
ValueTable Values;
ValueTable ModuleValues;
More information about the llvm-commits
mailing list