aboutsummaryrefslogtreecommitdiff
path: root/lib/Bytecode
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-07-07 08:36:50 +0000
committerChris Lattner <sabre@nondot.org>2001-07-07 08:36:50 +0000
commitc8b25d40cbec063b1ca99cc1adf794399c6d05c0 (patch)
tree8ad1468cb632eb9770206b1bd4bdd45d4e037898 /lib/Bytecode
parentf0d0e9c262b668cf362fbaa8111bb6cc15268909 (diff)
Changed the fundemental architecture of Operands for Instructions. Now
Operands are maintained as a vector<Use> in the User class, and operator iterators are provided as before. Getting an operand no longer requires a virtual function call. WARNING: getOperand(x) where x >= getNumOperands() will now assert instead of returning null! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bytecode')
-rw-r--r--lib/Bytecode/Reader/InstructionReader.cpp18
-rw-r--r--lib/Bytecode/Reader/ReaderInternals.h7
-rw-r--r--lib/Bytecode/Writer/ConstantWriter.cpp2
-rw-r--r--lib/Bytecode/Writer/InstructionWriter.cpp36
4 files changed, 29 insertions, 34 deletions
diff --git a/lib/Bytecode/Reader/InstructionReader.cpp b/lib/Bytecode/Reader/InstructionReader.cpp
index fd919c92a2..dac7d37415 100644
--- a/lib/Bytecode/Reader/InstructionReader.cpp
+++ b/lib/Bytecode/Reader/InstructionReader.cpp
@@ -80,8 +80,11 @@ bool BytecodeParser::ParseRawInst(const uchar *&Buf, const uchar *EndBuf,
break;
}
- //cerr << "NO: " << Result.NumOperands << " opcode: " << Result.Opcode
- // << " Ty: " << Result.Ty->getName() << " arg1: " << Result.Arg1 << endl;
+#if 0
+ cerr << "NO: " << Result.NumOperands << " opcode: " << Result.Opcode
+ << " Ty: " << Result.Ty->getName() << " arg1: " << Result.Arg1
+ << " arg2: " << Result.Arg2 << " arg3: " << Result.Arg3 << endl;
+#endif
return false;
}
@@ -198,13 +201,13 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
return false;
} else if (Raw.Opcode == Instruction::Malloc) {
if (Raw.NumOperands > 2) return true;
- Value *Sz = (Raw.NumOperands == 2) ? getValue(Type::UIntTy, Raw.Arg2) : 0;
- Res = new MallocInst((ConstPoolType*)getValue(Type::TypeTy, Raw.Arg1), Sz);
+ Value *Sz = Raw.NumOperands ? getValue(Type::UIntTy, Raw.Arg1) : 0;
+ Res = new MallocInst(Raw.Ty, Sz);
return false;
} else if (Raw.Opcode == Instruction::Alloca) {
if (Raw.NumOperands > 2) return true;
- Value *Sz = (Raw.NumOperands == 2) ? getValue(Type::UIntTy, Raw.Arg2) : 0;
- Res = new AllocaInst((ConstPoolType*)getValue(Type::TypeTy, Raw.Arg1), Sz);
+ Value *Sz = Raw.NumOperands ? getValue(Type::UIntTy, Raw.Arg1) : 0;
+ Res = new AllocaInst(Raw.Ty, Sz);
return false;
} else if (Raw.Opcode == Instruction::Free) {
Value *Val = getValue(Raw.Ty, Raw.Arg1);
@@ -213,6 +216,7 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
return false;
}
- cerr << "Unrecognized instruction! " << Raw.Opcode << endl;
+ cerr << "Unrecognized instruction! " << Raw.Opcode
+ << " ADDR = 0x" << (void*)Buf << endl;
return true;
}
diff --git a/lib/Bytecode/Reader/ReaderInternals.h b/lib/Bytecode/Reader/ReaderInternals.h
index 3bb0472674..fffcdb83c7 100644
--- a/lib/Bytecode/Reader/ReaderInternals.h
+++ b/lib/Bytecode/Reader/ReaderInternals.h
@@ -94,16 +94,9 @@ public:
struct InstPlaceHolderHelper : public Instruction {
InstPlaceHolderHelper(const Type *Ty) : Instruction(Ty, UserOp1, "") {}
- inline virtual void dropAllReferences() {}
virtual string getOpcode() const { return "placeholder"; }
virtual Instruction *clone() const { abort(); return 0; }
-
- // No "operands"...
- virtual Value *getOperand(unsigned i) { return 0; }
- virtual const Value *getOperand(unsigned i) const { return 0; }
- virtual bool setOperand(unsigned i, Value *Val) { return false; }
- virtual unsigned getNumOperands() const { return 0; }
};
struct BBPlaceHolderHelper : public BasicBlock {
diff --git a/lib/Bytecode/Writer/ConstantWriter.cpp b/lib/Bytecode/Writer/ConstantWriter.cpp
index e65ea45067..5ca0fca0d1 100644
--- a/lib/Bytecode/Writer/ConstantWriter.cpp
+++ b/lib/Bytecode/Writer/ConstantWriter.cpp
@@ -128,7 +128,7 @@ bool BytecodeWriter::outputConstant(const ConstPoolVal *CPV) {
case Type::StructTyID: {
const ConstPoolStruct *CPS = (const ConstPoolStruct*)CPV;
- const vector<ConstPoolUse> &Vals = CPS->getValues();
+ const vector<Use> &Vals = CPS->getValues();
for (unsigned i = 0; i < Vals.size(); ++i) {
int Slot = Table.getValSlot(Vals[i]);
diff --git a/lib/Bytecode/Writer/InstructionWriter.cpp b/lib/Bytecode/Writer/InstructionWriter.cpp
index c7c04efb73..0cd93c04fd 100644
--- a/lib/Bytecode/Writer/InstructionWriter.cpp
+++ b/lib/Bytecode/Writer/InstructionWriter.cpp
@@ -32,14 +32,13 @@ static void outputInstructionFormat0(const Instruction *I,
output_vbr(I->getInstType(), Out); // Instruction Opcode ID
output_vbr(Type, Out); // Result type
- unsigned NumArgs; // Count the number of arguments to the instruction
- for (NumArgs = 0; I->getOperand(NumArgs); NumArgs++) /*empty*/;
+ unsigned NumArgs = I->getNumOperands();
output_vbr(NumArgs, Out);
- for (unsigned i = 0; const Value *N = I->getOperand(i); i++) {
- assert(i < NumArgs && "Count of arguments failed!");
-
+ for (unsigned i = 0; i < NumArgs; ++i) {
+ const Value *N = I->getOperand(i);
int Slot = Table.getValSlot(N);
+ assert(Slot >= 0 && "No slot number for value!?!?");
output_vbr((unsigned)Slot, Out);
}
align32(Out); // We must maintain correct alignment!
@@ -110,25 +109,24 @@ static void outputInstructionFormat3(const Instruction *I,
//
unsigned Opcode = (3 << 30) | (IType << 24) | (Type << 18) |
(Slots[0] << 12) | (Slots[1] << 6) | (Slots[2] << 0);
- // cerr << "3 " << IType << " " << Type << " " << Slots[0] << " "
- // << Slots[1] << " " << Slots[2] << endl;
+ //cerr << "3 " << IType << " " << Type << " " << Slots[0] << " "
+ // << Slots[1] << " " << Slots[2] << endl;
output(Opcode, Out);
}
bool BytecodeWriter::processInstruction(const Instruction *I) {
assert(I->getInstType() < 64 && "Opcode too big???");
- unsigned NumOperands = 0;
+ unsigned NumOperands = I->getNumOperands();
int MaxOpSlot = 0;
- int Slots[3]; Slots[0] = (1 << 12)-1;
+ int Slots[3]; Slots[0] = (1 << 12)-1; // Marker to signify 0 operands
- const Value *Def;
- while ((Def = I->getOperand(NumOperands))) {
+ for (unsigned i = 0; i < NumOperands; ++i) {
+ const Value *Def = I->getOperand(i);
int slot = Table.getValSlot(Def);
assert(slot != -1 && "Broken bytecode!");
if (slot > MaxOpSlot) MaxOpSlot = slot;
- if (NumOperands < 3) Slots[NumOperands] = slot;
- NumOperands++;
+ if (i < 3) Slots[i] = slot;
}
// Figure out which type to encode with the instruction. Typically we want
@@ -137,12 +135,10 @@ bool BytecodeWriter::processInstruction(const Instruction *I) {
// the first param is actually interesting). But if we have no arguments
// we take the type of the instruction itself.
//
-
- const Type *Ty;
- if (NumOperands)
- Ty = I->getOperand(0)->getType();
- else
- Ty = I->getType();
+ const Type *Ty = NumOperands ? I->getOperand(0)->getType() : I->getType();
+ if (I->getInstType() == Instruction::Malloc ||
+ I->getInstType() == Instruction::Alloca)
+ Ty = I->getType(); // Malloc & Alloca ALWAYS want to encode the return type
unsigned Type;
int Slot = Table.getValSlot(Ty);
@@ -179,6 +175,8 @@ bool BytecodeWriter::processInstruction(const Instruction *I) {
break;
}
+ // If we weren't handled before here, we either have a large number of operands
+ // or a large operand index that we are refering to.
outputInstructionFormat0(I, Table, Type, Out);
return false;
}