aboutsummaryrefslogtreecommitdiff
path: root/lib/Bytecode/Writer/InstructionWriter.cpp
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/Writer/InstructionWriter.cpp
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/Writer/InstructionWriter.cpp')
-rw-r--r--lib/Bytecode/Writer/InstructionWriter.cpp36
1 files changed, 17 insertions, 19 deletions
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;
}