llvm.org GIT mirror llvm / abfbf85
further reduce the redundancy of types in the instruction encoding. This shrinks function bodies in kc++ from 891913B to 884073B git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36817 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 12 years ago
2 changed file(s) with 84 addition(s) and 91 deletion(s). Raw diff Collapse all Expand all
11441144 CurBB = FunctionBBs[0];
11451145 continue;
11461146
1147 case bitc::FUNC_CODE_INST_BINOP: { // BINOP: [opcode, ty, opval, opval]
1148 if (Record.size() < 4) return Error("Invalid BINOP record");
1149 const Type *Ty = getTypeByID(Record[1]);
1150 int Opc = GetDecodedBinaryOpcode(Record[0], Ty);
1151 Value *LHS = getFnValueByID(Record[2], Ty);
1152 Value *RHS = getFnValueByID(Record[3], Ty);
1153 if (Opc == -1 || Ty == 0 || LHS == 0 || RHS == 0)
1154 return Error("Invalid BINOP record");
1147 case bitc::FUNC_CODE_INST_BINOP: { // BINOP: [opval, ty, opval, opcode]
1148 unsigned OpNum = 0;
1149 Value *LHS, *RHS;
1150 if (getValueTypePair(Record, OpNum, NextValueNo, LHS) ||
1151 getValue(Record, OpNum, LHS->getType(), RHS) ||
1152 OpNum+1 != Record.size())
1153 return Error("Invalid BINOP record");
1154
1155 int Opc = GetDecodedBinaryOpcode(Record[OpNum], LHS->getType());
1156 if (Opc == -1) return Error("Invalid BINOP record");
11551157 I = BinaryOperator::create((Instruction::BinaryOps)Opc, LHS, RHS);
11561158 break;
11571159 }
1158 case bitc::FUNC_CODE_INST_CAST: { // CAST: [opcode, ty, opty, opval]
1159 if (Record.size() < 4) return Error("Invalid CAST record");
1160 int Opc = GetDecodedCastOpcode(Record[0]);
1161 const Type *ResTy = getTypeByID(Record[1]);
1162 const Type *OpTy = getTypeByID(Record[2]);
1163 Value *Op = getFnValueByID(Record[3], OpTy);
1164 if (Opc == -1 || ResTy == 0 || OpTy == 0 || Op == 0)
1160 case bitc::FUNC_CODE_INST_CAST: { // CAST: [opval, opty, destty, castopc]
1161 unsigned OpNum = 0;
1162 Value *Op;
1163 if (getValueTypePair(Record, OpNum, NextValueNo, Op) ||
1164 OpNum+2 != Record.size())
1165 return Error("Invalid CAST record");
1166
1167 const Type *ResTy = getTypeByID(Record[OpNum]);
1168 int Opc = GetDecodedCastOpcode(Record[OpNum+1]);
1169 if (Opc == -1 || ResTy == 0)
11651170 return Error("Invalid CAST record");
11661171 I = CastInst::create((Instruction::CastOps)Opc, Op, ResTy);
11671172 break;
11841189 break;
11851190 }
11861191
1187 case bitc::FUNC_CODE_INST_SELECT: { // SELECT: [ty, opval, opval, opval]
1188 if (Record.size() < 4) return Error("Invalid SELECT record");
1189 const Type *Ty = getTypeByID(Record[0]);
1190 Value *Cond = getFnValueByID(Record[1], Type::Int1Ty);
1191 Value *LHS = getFnValueByID(Record[2], Ty);
1192 Value *RHS = getFnValueByID(Record[3], Ty);
1193 if (Ty == 0 || Cond == 0 || LHS == 0 || RHS == 0)
1192 case bitc::FUNC_CODE_INST_SELECT: { // SELECT: [opval, ty, opval, opval]
1193 unsigned OpNum = 0;
1194 Value *TrueVal, *FalseVal, *Cond;
1195 if (getValueTypePair(Record, OpNum, NextValueNo, TrueVal) ||
1196 getValue(Record, OpNum, TrueVal->getType(), FalseVal) ||
1197 getValue(Record, OpNum, Type::Int1Ty, Cond))
11941198 return Error("Invalid SELECT record");
1195 I = new SelectInst(Cond, LHS, RHS);
1199
1200 I = new SelectInst(Cond, TrueVal, FalseVal);
11961201 break;
11971202 }
11981203
11991204 case bitc::FUNC_CODE_INST_EXTRACTELT: { // EXTRACTELT: [opty, opval, opval]
1200 if (Record.size() < 3) return Error("Invalid EXTRACTELT record");
1201 const Type *OpTy = getTypeByID(Record[0]);
1202 Value *Vec = getFnValueByID(Record[1], OpTy);
1203 Value *Idx = getFnValueByID(Record[2], Type::Int32Ty);
1204 if (OpTy == 0 || Vec == 0 || Idx == 0)
1205 unsigned OpNum = 0;
1206 Value *Vec, *Idx;
1207 if (getValueTypePair(Record, OpNum, NextValueNo, Vec) ||
1208 getValue(Record, OpNum, Type::Int32Ty, Idx))
12051209 return Error("Invalid EXTRACTELT record");
12061210 I = new ExtractElementInst(Vec, Idx);
12071211 break;
12081212 }
12091213
12101214 case bitc::FUNC_CODE_INST_INSERTELT: { // INSERTELT: [ty, opval,opval,opval]
1211 if (Record.size() < 4) return Error("Invalid INSERTELT record");
1212 const VectorType *OpTy =
1213 dyn_cast_or_null(getTypeByID(Record[0]));
1214 if (OpTy == 0) return Error("Invalid INSERTELT record");
1215 Value *Vec = getFnValueByID(Record[1], OpTy);
1216 Value *Elt = getFnValueByID(Record[2], OpTy->getElementType());
1217 Value *Idx = getFnValueByID(Record[3], Type::Int32Ty);
1218 if (Vec == 0 || Elt == 0 || Idx == 0)
1215 unsigned OpNum = 0;
1216 Value *Vec, *Elt, *Idx;
1217 if (getValueTypePair(Record, OpNum, NextValueNo, Vec) ||
1218 getValue(Record, OpNum,
1219 cast(Vec->getType())->getElementType(), Elt) ||
1220 getValue(Record, OpNum, Type::Int32Ty, Idx))
12191221 return Error("Invalid INSERTELT record");
12201222 I = new InsertElementInst(Vec, Elt, Idx);
12211223 break;
12221224 }
12231225
1224 case bitc::FUNC_CODE_INST_SHUFFLEVEC: {// SHUFFLEVEC: [ty,opval,opval,opval]
1225 if (Record.size() < 4) return Error("Invalid SHUFFLEVEC record");
1226 const VectorType *OpTy =
1227 dyn_cast_or_null(getTypeByID(Record[0]));
1228 if (OpTy == 0) return Error("Invalid SHUFFLEVEC record");
1229 Value *Vec1 = getFnValueByID(Record[1], OpTy);
1230 Value *Vec2 = getFnValueByID(Record[2], OpTy);
1231 Value *Mask = getFnValueByID(Record[3],
1232 VectorType::get(Type::Int32Ty,
1233 OpTy->getNumElements()));
1234 if (Vec1 == 0 || Vec2 == 0 || Mask == 0)
1226 case bitc::FUNC_CODE_INST_SHUFFLEVEC: {// SHUFFLEVEC: [opval,ty,opval,opval]
1227 unsigned OpNum = 0;
1228 Value *Vec1, *Vec2, *Mask;
1229 if (getValueTypePair(Record, OpNum, NextValueNo, Vec1) ||
1230 getValue(Record, OpNum, Vec1->getType(), Vec2))
1231 return Error("Invalid SHUFFLEVEC record");
1232
1233 const Type *MaskTy =
1234 VectorType::get(Type::Int32Ty,
1235 cast(Vec1->getType())->getNumElements());
1236
1237 if (getValue(Record, OpNum, MaskTy, Mask))
12351238 return Error("Invalid SHUFFLEVEC record");
12361239 I = new ShuffleVectorInst(Vec1, Vec2, Mask);
12371240 break;
13561359 case bitc::FUNC_CODE_INST_UNREACHABLE: // UNREACHABLE
13571360 I = new UnreachableInst();
13581361 break;
1359 case bitc::FUNC_CODE_INST_PHI: { // PHI: [ty, #ops, val0,bb0, ...]
1362 case bitc::FUNC_CODE_INST_PHI: { // PHI: [ty, val0,bb0, ...]
13601363 if (Record.size() < 1 || ((Record.size()-1)&1))
13611364 return Error("Invalid PHI record");
13621365 const Type *Ty = getTypeByID(Record[0]);
13861389 I = new MallocInst(Ty->getElementType(), Size, (1 << Align) >> 1);
13871390 break;
13881391 }
1389 case bitc::FUNC_CODE_INST_FREE: { // FREE: [opty, op]
1390 if (Record.size() < 2)
1391 return Error("Invalid FREE record");
1392 const Type *OpTy = getTypeByID(Record[0]);
1393 Value *Op = getFnValueByID(Record[1], OpTy);
1394 if (!OpTy || !Op)
1392 case bitc::FUNC_CODE_INST_FREE: { // FREE: [op, opty]
1393 unsigned OpNum = 0;
1394 Value *Op;
1395 if (getValueTypePair(Record, OpNum, NextValueNo, Op) ||
1396 OpNum != Record.size())
13951397 return Error("Invalid FREE record");
13961398 I = new FreeInst(Op);
13971399 break;
14121414 Value *Op;
14131415 if (getValueTypePair(Record, OpNum, NextValueNo, Op) ||
14141416 OpNum+2 != Record.size())
1415 return Error("Invalid RET record");
1417 return Error("Invalid LOAD record");
14161418
14171419 I = new LoadInst(Op, "", Record[OpNum+1], (1 << Record[OpNum]) >> 1);
14181420 break;
14191421 }
1420 case bitc::FUNC_CODE_INST_STORE: { // STORE:[ptrty,val,ptr, align, vol]
1421 if (Record.size() < 5)
1422 return Error("Invalid LOAD record");
1423 const PointerType *OpTy =
1424 dyn_cast_or_null(getTypeByID(Record[0]));
1425 Value *Op = getFnValueByID(Record[1], OpTy ? OpTy->getElementType() : 0);
1426 Value *Ptr = getFnValueByID(Record[2], OpTy);
1427 if (!OpTy || !Op || !Ptr)
1422 case bitc::FUNC_CODE_INST_STORE: { // STORE:[val, valty, ptr, align, vol]
1423 unsigned OpNum = 0;
1424 Value *Val, *Ptr;
1425 if (getValueTypePair(Record, OpNum, NextValueNo, Val) ||
1426 getValue(Record, OpNum, PointerType::get(Val->getType()), Ptr) ||
1427 OpNum+2 != Record.size())
14281428 return Error("Invalid STORE record");
1429 I = new StoreInst(Op, Ptr, Record[4], (1 << Record[3]) >> 1);
1429
1430 I = new StoreInst(Val, Ptr, Record[OpNum+1], (1 << Record[OpNum]) >> 1);
14301431 break;
14311432 }
14321433 case bitc::FUNC_CODE_INST_CALL: { // CALL: [cc, fnty, fnid, arg0, arg1...]
601601 default:
602602 if (Instruction::isCast(I.getOpcode())) {
603603 Code = bitc::FUNC_CODE_INST_CAST;
604 PushValueAndType(I.getOperand(0), InstID, Vals, VE);
605 Vals.push_back(VE.getTypeID(I.getType()));
604606 Vals.push_back(GetEncodedCastOpcode(I.getOpcode()));
605 Vals.push_back(VE.getTypeID(I.getType()));
606 Vals.push_back(VE.getTypeID(I.getOperand(0)->getType()));
607 Vals.push_back(VE.getValueID(I.getOperand(0)));
608607 } else {
609608 assert(isa(I) && "Unknown instruction!");
610609 Code = bitc::FUNC_CODE_INST_BINOP;
610 PushValueAndType(I.getOperand(0), InstID, Vals, VE);
611 Vals.push_back(VE.getValueID(I.getOperand(1)));
611612 Vals.push_back(GetEncodedBinaryOpcode(I.getOpcode()));
612 Vals.push_back(VE.getTypeID(I.getType()));
613 Vals.push_back(VE.getValueID(I.getOperand(0)));
614 Vals.push_back(VE.getValueID(I.getOperand(1)));
615613 }
616614 break;
617615
622620 break;
623621 case Instruction::Select:
624622 Code = bitc::FUNC_CODE_INST_SELECT;
625 Vals.push_back(VE.getTypeID(I.getType()));
623 PushValueAndType(I.getOperand(1), InstID, Vals, VE);
624 Vals.push_back(VE.getValueID(I.getOperand(2)));
626625 Vals.push_back(VE.getValueID(I.getOperand(0)));
626 break;
627 case Instruction::ExtractElement:
628 Code = bitc::FUNC_CODE_INST_EXTRACTELT;
629 PushValueAndType(I.getOperand(0), InstID, Vals, VE);
630 Vals.push_back(VE.getValueID(I.getOperand(1)));
631 break;
632 case Instruction::InsertElement:
633 Code = bitc::FUNC_CODE_INST_INSERTELT;
634 PushValueAndType(I.getOperand(0), InstID, Vals, VE);
627635 Vals.push_back(VE.getValueID(I.getOperand(1)));
628636 Vals.push_back(VE.getValueID(I.getOperand(2)));
629637 break;
630 case Instruction::ExtractElement:
631 Code = bitc::FUNC_CODE_INST_EXTRACTELT;
632 Vals.push_back(VE.getTypeID(I.getOperand(0)->getType()));
633 Vals.push_back(VE.getValueID(I.getOperand(0)));
634 Vals.push_back(VE.getValueID(I.getOperand(1)));
635 break;
636 case Instruction::InsertElement:
637 Code = bitc::FUNC_CODE_INST_INSERTELT;
638 Vals.push_back(VE.getTypeID(I.getType()));
639 Vals.push_back(VE.getValueID(I.getOperand(0)));
640 Vals.push_back(VE.getValueID(I.getOperand(1)));
641 Vals.push_back(VE.getValueID(I.getOperand(2)));
642 break;
643638 case Instruction::ShuffleVector:
644639 Code = bitc::FUNC_CODE_INST_SHUFFLEVEC;
645 Vals.push_back(VE.getTypeID(I.getType()));
646 Vals.push_back(VE.getValueID(I.getOperand(0)));
640 PushValueAndType(I.getOperand(0), InstID, Vals, VE);
647641 Vals.push_back(VE.getValueID(I.getOperand(1)));
648642 Vals.push_back(VE.getValueID(I.getOperand(2)));
649643 break;
718712
719713 case Instruction::Free:
720714 Code = bitc::FUNC_CODE_INST_FREE;
721 Vals.push_back(VE.getTypeID(I.getOperand(0)->getType()));
722 Vals.push_back(VE.getValueID(I.getOperand(0)));
715 PushValueAndType(I.getOperand(0), InstID, Vals, VE);
723716 break;
724717
725718 case Instruction::Alloca:
739732 break;
740733 case Instruction::Store:
741734 Code = bitc::FUNC_CODE_INST_STORE;
742 Vals.push_back(VE.getTypeID(I.getOperand(1)->getType())); // Pointer
743 Vals.push_back(VE.getValueID(I.getOperand(0))); // val.
744 Vals.push_back(VE.getValueID(I.getOperand(1))); // ptr.
735 PushValueAndType(I.getOperand(0), InstID, Vals, VE); // val.
736 Vals.push_back(VE.getValueID(I.getOperand(1))); // ptr.
745737 Vals.push_back(Log2_32(cast(I).getAlignment())+1);
746738 Vals.push_back(cast(I).isVolatile());
747739 break;