summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Bytecode
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2006-12-03 06:28:54 +0000
committerReid Spencer <rspencer@reidspencer.com>2006-12-03 06:28:54 +0000
commit22504bd6382025ec0021b7b896469f5f12f661af (patch)
treeffd797ce73d28ffe28450fa47301b9ce99fde121 /llvm/lib/Bytecode
parent45e5239008727ec558dffd679ab42154474eab1d (diff)
downloadbcm5719-llvm-22504bd6382025ec0021b7b896469f5f12f661af.tar.gz
bcm5719-llvm-22504bd6382025ec0021b7b896469f5f12f661af.zip
Implement reading and writing of the ICmp and FCmp instructions.
llvm-svn: 32149
Diffstat (limited to 'llvm/lib/Bytecode')
-rw-r--r--llvm/lib/Bytecode/Reader/Reader.cpp12
-rw-r--r--llvm/lib/Bytecode/Writer/Writer.cpp9
2 files changed, 18 insertions, 3 deletions
diff --git a/llvm/lib/Bytecode/Reader/Reader.cpp b/llvm/lib/Bytecode/Reader/Reader.cpp
index 6a5a9ca88c3..d294e9e025e 100644
--- a/llvm/lib/Bytecode/Reader/Reader.cpp
+++ b/llvm/lib/Bytecode/Reader/Reader.cpp
@@ -550,12 +550,11 @@ void BytecodeReader::ParseInstruction(std::vector<unsigned> &Oprnds,
// First, handle the easy binary operators case
if (Opcode >= Instruction::BinaryOpsBegin &&
- Opcode < Instruction::BinaryOpsEnd && Oprnds.size() == 2)
+ Opcode < Instruction::BinaryOpsEnd && Oprnds.size() == 2) {
Result = BinaryOperator::create(Instruction::BinaryOps(Opcode),
getValue(iType, Oprnds[0]),
getValue(iType, Oprnds[1]));
-
- if (!Result) {
+ } else {
// Indicate that we don't think this is a call instruction (yet).
// Process based on the Opcode read
switch (Opcode) {
@@ -700,6 +699,13 @@ void BytecodeReader::ParseInstruction(std::vector<unsigned> &Oprnds,
Result = PN;
break;
}
+ case Instruction::ICmp:
+ case Instruction::FCmp:
+ // These instructions encode the comparison predicate as the 3rd operand.
+ Result = CmpInst::create(Instruction::OtherOps(Opcode),
+ static_cast<unsigned short>(Oprnds[2]),
+ getValue(iType, Oprnds[0]), getValue(iType, Oprnds[1]));
+ break;
case Instruction::Shl:
case Instruction::LShr:
case Instruction::AShr:
diff --git a/llvm/lib/Bytecode/Writer/Writer.cpp b/llvm/lib/Bytecode/Writer/Writer.cpp
index d8bcce82085..9cf61c6ee21 100644
--- a/llvm/lib/Bytecode/Writer/Writer.cpp
+++ b/llvm/lib/Bytecode/Writer/Writer.cpp
@@ -718,6 +718,15 @@ void BytecodeWriter::outputInstruction(const Instruction &I) {
if (Slots[1] > MaxOpSlot) MaxOpSlot = Slots[1];
NumOperands = 2;
}
+ } else if (isa<ICmpInst>(I) || isa<FCmpInst>(I)) {
+ // We need to encode the compare instruction's predicate as the third
+ // operand. Its not really a slot, but we don't want to break the
+ // instruction format for these instructions.
+ NumOperands++;
+ assert(NumOperands == 3 && "CmpInst with wrong number of operands?");
+ Slots[2] = unsigned(cast<CmpInst>(&I)->getPredicate());
+ if (Slots[2] > MaxOpSlot)
+ MaxOpSlot = Slots[2];
} else if (const GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(&I)) {
// We need to encode the type of sequential type indices into their slot #
unsigned Idx = 1;
OpenPOWER on IntegriCloud