llvm.org GIT mirror llvm / a0f1ecc
add abbrevs for the constants tables. This shrinks it from 4.49755e6 bits to 3.85972e6 bits in kc++ git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36778 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 12 years ago
1 changed file(s) with 125 addition(s) and 63 deletion(s). Raw diff Collapse all Expand all
3333 VST_ENTRY_8_ABBREV = bitc::FIRST_APPLICATION_ABBREV,
3434 VST_ENTRY_7_ABBREV,
3535 VST_ENTRY_6_ABBREV,
36 VST_BBENTRY_6_ABBREV
36 VST_BBENTRY_6_ABBREV,
37
38 // CONSTANTS_BLOCK abbrev id's.
39 CONSTANTS_SETTYPE_ABBREV = bitc::FIRST_APPLICATION_ABBREV,
40 CONSTANTS_INTEGER_ABBREV,
41 CONSTANTS_CE_CAST_Abbrev,
42 CONSTANTS_NULL_Abbrev
3743 };
3844
3945
395401
396402 static void WriteConstants(unsigned FirstVal, unsigned LastVal,
397403 const ValueEnumerator &VE,
398 BitstreamWriter &Stream) {
404 BitstreamWriter &Stream, bool isGlobal) {
399405 if (FirstVal == LastVal) return;
400406
401 Stream.EnterSubblock(bitc::CONSTANTS_BLOCK_ID, 2);
402
407 Stream.EnterSubblock(bitc::CONSTANTS_BLOCK_ID, 4);
408
409 unsigned AggregateAbbrev = 0;
410 unsigned GEPAbbrev = 0;
411 // If this is a constant pool for the module, emit module-specific abbrevs.
412 if (isGlobal) {
413 // Abbrev for CST_CODE_AGGREGATE.
414 BitCodeAbbrev *Abbv = new BitCodeAbbrev();
415 Abbv->Add(BitCodeAbbrevOp(bitc::CST_CODE_AGGREGATE));
416 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
417 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, Log2_32_Ceil(LastVal+1)));
418 AggregateAbbrev = Stream.EmitAbbrev(Abbv);
419 }
420
403421 // FIXME: Install and use abbrevs to reduce size. Install them globally so
404422 // they don't need to be reemitted for each function body.
405423
413431 if (V->getType() != LastTy) {
414432 LastTy = V->getType();
415433 Record.push_back(VE.getTypeID(LastTy));
416 Stream.EmitRecord(bitc::CST_CODE_SETTYPE, Record);
434 Stream.EmitRecord(bitc::CST_CODE_SETTYPE, Record,
435 CONSTANTS_SETTYPE_ABBREV);
417436 Record.clear();
418437 }
419438
436455 else
437456 Record.push_back((-V << 1) | 1);
438457 Code = bitc::CST_CODE_INTEGER;
458 AbbrevToUse = CONSTANTS_INTEGER_ABBREV;
439459 } else { // Wide integers, > 64 bits in size.
440460 // We have an arbitrary precision integer value to write whose
441461 // bit width is > 64. However, in canonical unsigned integer
465485 Code = bitc::CST_CODE_AGGREGATE;
466486 for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i)
467487 Record.push_back(VE.getValueID(C->getOperand(i)));
488 AbbrevToUse = AggregateAbbrev;
468489 } else if (const ConstantExpr *CE = dyn_cast(C)) {
469490 switch (CE->getOpcode()) {
470491 default:
473494 Record.push_back(GetEncodedCastOpcode(CE->getOpcode()));
474495 Record.push_back(VE.getTypeID(C->getOperand(0)->getType()));
475496 Record.push_back(VE.getValueID(C->getOperand(0)));
497 AbbrevToUse = CONSTANTS_CE_CAST_Abbrev;
476498 } else {
477499 assert(CE->getNumOperands() == 2 && "Unknown constant expr!");
478500 Code = bitc::CST_CODE_CE_BINOP;
487509 Record.push_back(VE.getTypeID(C->getOperand(i)->getType()));
488510 Record.push_back(VE.getValueID(C->getOperand(i)));
489511 }
512 AbbrevToUse = GEPAbbrev;
490513 break;
491514 case Instruction::Select:
492515 Code = bitc::CST_CODE_CE_SELECT;
539562 // We know globalvalues have been emitted by WriteModuleInfo.
540563 for (unsigned i = 0, e = Vals.size(); i != e; ++i) {
541564 if (!isa(Vals[i].first)) {
542 WriteConstants(i, Vals.size(), VE, Stream);
565 WriteConstants(i, Vals.size(), VE, Stream, true);
543566 return;
544567 }
545568 }
820843 // If there are function-local constants, emit them now.
821844 unsigned CstStart, CstEnd;
822845 VE.getFunctionConstantRange(CstStart, CstEnd);
823 WriteConstants(CstStart, CstEnd, VE, Stream);
846 WriteConstants(CstStart, CstEnd, VE, Stream, false);
824847
825848 // Finally, emit all the instructions, in order.
826849 for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
874897 Stream.ExitBlock();
875898 }
876899
877
878 /// WriteModule - Emit the specified module to the bitstream.
879 static void WriteModule(const Module *M, BitstreamWriter &Stream) {
880 Stream.EnterSubblock(bitc::MODULE_BLOCK_ID, 3);
881
882 // Emit the version number if it is non-zero.
883 if (CurVersion) {
884 SmallVector Vals;
885 Vals.push_back(CurVersion);
886 Stream.EmitRecord(bitc::MODULE_CODE_VERSION, Vals);
887 }
888
889 // Analyze the module, enumerating globals, functions, etc.
890 ValueEnumerator VE(M);
891
892 // Emit information about parameter attributes.
893 WriteParamAttrTable(VE, Stream);
894
895 // Emit information describing all of the types in the module.
896 WriteTypeTable(VE, Stream);
897
898 // Emit top-level description of module, including target triple, inline asm,
899 // descriptors for global variables, and function prototype info.
900 WriteModuleInfo(M, VE, Stream);
901
902 // Emit constants.
903 WriteModuleConstants(VE, Stream);
904
905 // If we have any aggregate values in the value table, purge them - these can
906 // only be used to initialize global variables. Doing so makes the value
907 // namespace smaller for code in functions.
908 int NumNonAggregates = VE.PurgeAggregateValues();
909 if (NumNonAggregates != -1) {
910 SmallVector Vals;
911 Vals.push_back(NumNonAggregates);
912 Stream.EmitRecord(bitc::MODULE_CODE_PURGEVALS, Vals);
913 }
914
915 // Emit function bodies.
916 for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
917 if (!I->isDeclaration())
918 WriteFunction(*I, VE, Stream);
919
920 // Emit the type symbol table information.
921 WriteTypeSymbolTable(M->getTypeSymbolTable(), VE, Stream);
922
923 // Emit names for globals/functions etc.
924 WriteValueSymbolTable(M->getValueSymbolTable(), VE, Stream);
925
926 Stream.ExitBlock();
927 }
928
929900 // Emit blockinfo, which defines the standard abbreviations etc.
930 static void WriteBlockInfo(BitstreamWriter &Stream) {
901 static void WriteBlockInfo(const ValueEnumerator &VE, BitstreamWriter &Stream) {
931902 // We only want to emit block info records for blocks that have multiple
932903 // instances: CONSTANTS_BLOCK, FUNCTION_BLOCK and VALUE_SYMTAB_BLOCK. Other
933904 // blocks can defined their abbrevs inline.
975946 assert(0 && "Unexpected abbrev ordering!");
976947 }
977948
949 { // SETTYPE abbrev for CONSTANTS_BLOCK.
950 BitCodeAbbrev *Abbv = new BitCodeAbbrev();
951 Abbv->Add(BitCodeAbbrevOp(bitc::CST_CODE_SETTYPE));
952 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
953 Log2_32_Ceil(VE.getTypes().size()+1)));
954 if (Stream.EmitBlockInfoAbbrev(bitc::CONSTANTS_BLOCK_ID,
955 Abbv) != CONSTANTS_SETTYPE_ABBREV)
956 assert(0 && "Unexpected abbrev ordering!");
957 }
958
959 { // INTEGER abbrev for CONSTANTS_BLOCK.
960 BitCodeAbbrev *Abbv = new BitCodeAbbrev();
961 Abbv->Add(BitCodeAbbrevOp(bitc::CST_CODE_INTEGER));
962 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
963 if (Stream.EmitBlockInfoAbbrev(bitc::CONSTANTS_BLOCK_ID,
964 Abbv) != CONSTANTS_INTEGER_ABBREV)
965 assert(0 && "Unexpected abbrev ordering!");
966 }
967
968 { // CE_CAST abbrev for CONSTANTS_BLOCK.
969 BitCodeAbbrev *Abbv = new BitCodeAbbrev();
970 Abbv->Add(BitCodeAbbrevOp(bitc::CST_CODE_CE_CAST));
971 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // cast opc
972 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, // typeid
973 Log2_32_Ceil(VE.getTypes().size()+1)));
974 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // value id
975
976 if (Stream.EmitBlockInfoAbbrev(bitc::CONSTANTS_BLOCK_ID,
977 Abbv) != CONSTANTS_CE_CAST_Abbrev)
978 assert(0 && "Unexpected abbrev ordering!");
979 }
980 { // NULL abbrev for CONSTANTS_BLOCK.
981 BitCodeAbbrev *Abbv = new BitCodeAbbrev();
982 Abbv->Add(BitCodeAbbrevOp(bitc::CST_CODE_NULL));
983 if (Stream.EmitBlockInfoAbbrev(bitc::CONSTANTS_BLOCK_ID,
984 Abbv) != CONSTANTS_NULL_Abbrev)
985 assert(0 && "Unexpected abbrev ordering!");
986 }
987
988 Stream.ExitBlock();
989 }
990
991
992 /// WriteModule - Emit the specified module to the bitstream.
993 static void WriteModule(const Module *M, BitstreamWriter &Stream) {
994 Stream.EnterSubblock(bitc::MODULE_BLOCK_ID, 3);
995
996 // Emit the version number if it is non-zero.
997 if (CurVersion) {
998 SmallVector Vals;
999 Vals.push_back(CurVersion);
1000 Stream.EmitRecord(bitc::MODULE_CODE_VERSION, Vals);
1001 }
1002
1003 // Analyze the module, enumerating globals, functions, etc.
1004 ValueEnumerator VE(M);
1005
1006 // Emit blockinfo, which defines the standard abbreviations etc.
1007 WriteBlockInfo(VE, Stream);
1008
1009 // Emit information about parameter attributes.
1010 WriteParamAttrTable(VE, Stream);
1011
1012 // Emit information describing all of the types in the module.
1013 WriteTypeTable(VE, Stream);
1014
1015 // Emit top-level description of module, including target triple, inline asm,
1016 // descriptors for global variables, and function prototype info.
1017 WriteModuleInfo(M, VE, Stream);
1018
1019 // Emit constants.
1020 WriteModuleConstants(VE, Stream);
1021
1022 // If we have any aggregate values in the value table, purge them - these can
1023 // only be used to initialize global variables. Doing so makes the value
1024 // namespace smaller for code in functions.
1025 int NumNonAggregates = VE.PurgeAggregateValues();
1026 if (NumNonAggregates != -1) {
1027 SmallVector Vals;
1028 Vals.push_back(NumNonAggregates);
1029 Stream.EmitRecord(bitc::MODULE_CODE_PURGEVALS, Vals);
1030 }
1031
1032 // Emit function bodies.
1033 for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
1034 if (!I->isDeclaration())
1035 WriteFunction(*I, VE, Stream);
1036
1037 // Emit the type symbol table information.
1038 WriteTypeSymbolTable(M->getTypeSymbolTable(), VE, Stream);
1039
1040 // Emit names for globals/functions etc.
1041 WriteValueSymbolTable(M->getValueSymbolTable(), VE, Stream);
1042
9781043 Stream.ExitBlock();
9791044 }
9801045
9951060 Stream.Emit(0xE, 4);
9961061 Stream.Emit(0xD, 4);
9971062
998 // Emit blockinfo, which defines the standard abbreviations etc.
999 WriteBlockInfo(Stream);
1000
10011063 // Emit the module.
10021064 WriteModule(M, Stream);
10031065