summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Bytecode/Writer/ConstantWriter.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-01-14 23:36:54 +0000
committerChris Lattner <sabre@nondot.org>2004-01-14 23:36:54 +0000
commit6229fbf3287d72b9caae78db43b2f8fd52641409 (patch)
treeda67ce40ffe8f77d1023d1576c6721070f726e48 /llvm/lib/Bytecode/Writer/ConstantWriter.cpp
parent394afe0f903e57d311ab43d4bbec8c50e0c30403 (diff)
downloadbcm5719-llvm-6229fbf3287d72b9caae78db43b2f8fd52641409.tar.gz
bcm5719-llvm-6229fbf3287d72b9caae78db43b2f8fd52641409.zip
The new bytecode format supports emitting strings a special case. This is
intended to save size (and does on small programs), but on big programs it actually increases the size of the program slightly. The deal is that many functions end up using the characters that the string contained, and the characters are no longer in the global constant table, so they have to be emitted in function specific constant pools. This pessimization will be fixed in subsequent patches. llvm-svn: 10864
Diffstat (limited to 'llvm/lib/Bytecode/Writer/ConstantWriter.cpp')
-rw-r--r--llvm/lib/Bytecode/Writer/ConstantWriter.cpp53
1 files changed, 45 insertions, 8 deletions
diff --git a/llvm/lib/Bytecode/Writer/ConstantWriter.cpp b/llvm/lib/Bytecode/Writer/ConstantWriter.cpp
index 12043b048a1..02569ec33d4 100644
--- a/llvm/lib/Bytecode/Writer/ConstantWriter.cpp
+++ b/llvm/lib/Bytecode/Writer/ConstantWriter.cpp
@@ -26,6 +26,12 @@ ConstantBytes("bytecodewriter", "Bytes of constants");
static Statistic<>
NumConstants("bytecodewriter", "Number of constants");
+static Statistic<>
+NumStrConstants("bytecodewriter", "Number of string constants");
+static Statistic<>
+NumStrBytes("bytecodewriter", "Number of string constant bytes");
+
+
void BytecodeWriter::outputType(const Type *T) {
TypeBytes -= Out.size();
output_vbr((unsigned)T->getPrimitiveID(), Out);
@@ -109,7 +115,7 @@ void BytecodeWriter::outputType(const Type *T) {
TypeBytes += Out.size();
}
-bool BytecodeWriter::outputConstant(const Constant *CPV) {
+void BytecodeWriter::outputConstant(const Constant *CPV) {
ConstantBytes -= Out.size();
assert((CPV->getType()->isPrimitiveType() || !CPV->isNullValue()) &&
"Shouldn't output null constants!");
@@ -133,7 +139,7 @@ bool BytecodeWriter::outputConstant(const Constant *CPV) {
output_vbr((unsigned)Slot, Out);
}
ConstantBytes += Out.size();
- return false;
+ return;
} else {
output_vbr(0U, Out); // flag as not a ConstantExpr
}
@@ -166,10 +172,9 @@ bool BytecodeWriter::outputConstant(const Constant *CPV) {
case Type::ArrayTyID: {
const ConstantArray *CPA = cast<ConstantArray>(CPV);
- unsigned size = CPA->getValues().size();
- assert(size == cast<ArrayType>(CPA->getType())->getNumElements()
- && "ConstantArray out of whack!");
- for (unsigned i = 0; i < size; i++) {
+ assert(!CPA->isString() && "Constant strings should be handled specially!");
+
+ for (unsigned i = 0; i != CPA->getNumOperands(); ++i) {
int Slot = Table.getSlot(CPA->getOperand(i));
assert(Slot != -1 && "Constant used but not available!!");
output_vbr((unsigned)Slot, Out);
@@ -215,6 +220,38 @@ bool BytecodeWriter::outputConstant(const Constant *CPV) {
<< " type '" << CPV->getType()->getName() << "'\n";
break;
}
- ConstantBytes += Out.size();
- return false;
+ ConstantBytes += Out.size();
+ return;
+}
+
+void BytecodeWriter::outputConstantStrings() {
+ SlotCalculator::string_iterator I = Table.string_begin();
+ SlotCalculator::string_iterator E = Table.string_end();
+ if (I == E) return; // No strings to emit
+
+ // If we have != 0 strings to emit, output them now. Strings are emitted into
+ // the 'void' type plane.
+ output_vbr(unsigned(E-I), Out);
+ output_vbr(Type::VoidTyID, Out);
+
+ ConstantBytes -= Out.size();
+ NumStrBytes -= Out.size();;
+
+ // Emit all of the strings.
+ for (I = Table.string_begin(); I != E; ++I) {
+ const ConstantArray *Str = *I;
+ int Slot = Table.getSlot(Str->getType());
+ assert(Slot != -1 && "Constant string of unknown type?");
+ output_vbr((unsigned)Slot, Out);
+
+ // Now that we emitted the type (which indicates the size of the string),
+ // emit all of the characters.
+ std::string Val = Str->getAsString();
+ output_data(Val.c_str(), Val.c_str()+Val.size(), Out);
+
+ ++NumConstants;
+ ++NumStrConstants;
+ }
+ ConstantBytes += Out.size();
+ NumStrBytes += Out.size();;
}
OpenPOWER on IntegriCloud