Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions ast/member_expr.c2
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public type MemberExpr struct @(opaque) {
public fn MemberExpr* MemberExpr.create(ast_context.Context* c, Expr* base, const Ref* refs, u32 refcount) {
u32 size = sizeof(MemberExpr) + refcount * sizeof(MemberRef) + (refcount - 1) * sizeof(u32);
if (base) size += sizeof(MemberRef);
size = (size + 7) & ~0x7; // round to 8-byte (temp)
MemberExpr* e = c.alloc(size);
e.base.init(ExprKind.Member, refs[0].loc, 0, 0, 0, ValType.NValue);
e.base.base.memberExprBits.num_refs = refcount;
Expand Down Expand Up @@ -99,9 +98,7 @@ fn Expr* MemberExpr.instantiate(MemberExpr* e, Instantiator* inst) {
u32 refcount = e.base.base.memberExprBits.num_refs;
Expr* base = e.getExprBase();
u32 size = sizeof(MemberExpr) + refcount * sizeof(MemberRef) + (refcount - 1) * sizeof(u32);

if (base) size += sizeof(MemberRef);
size = (size + 7) & ~0x7; // round to 8-byte (temp)
MemberExpr* e2 = inst.c.alloc(size);

string.memcpy(e2, e, size);
Expand Down
46 changes: 36 additions & 10 deletions ast/statistics.c2
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ module ast;
import string;
import stdio local;

const u32 NCat = 1;
const u32 NCat = 1; // 32 for fine grained analysis
const u32 BucketWidth = 8; // 4 or less for slack analysis

type Stat struct {
u32[NCat] count;
Expand All @@ -32,19 +33,22 @@ type Stats struct {
Stat[elemsof(StmtKind)] stmts;
Stat[elemsof(DeclKind)] decls;
Stat[3] others; // 0=ArrayValue, 1=StaticAssert, 2=SwitchCase
//Stat arrayValues;
//Stat staticAsserts;
}

fn void Stats.reset(Stats* s) {
string.memset(s, 0, sizeof(Stats));
}

fn void Stat.add(Stat* ss, u32 size) {
u32 cat = (size + 7) >> 3;
if (cat >= NCat) cat = NCat - 1;
ss.count[cat]++;
ss.size[cat] += size;
if (NCat > 1) {
u32 cat = (size + BucketWidth - 1) / BucketWidth;
if (cat >= NCat) cat = NCat - 1;
ss.count[cat]++;
ss.size[cat] += (size + 7) & ~0x7;
} else {
ss.count[0]++;
ss.size[0] += (size + 7) & ~0x7;
}
}

fn void Stats.addType(TypeKind kind, u32 size) {
Expand Down Expand Up @@ -77,6 +81,17 @@ fn void Stats.addSwitchCase(u32 size) {
globals.stats.others[2].add(size);
}

fn void Stat.slack(const Stat* ss, u32* countp, u32* totalp) {
if (BucketWidth & 0x7) {
for (u32 cat = 0; cat < NCat; cat++) {
if (u32 frac = (cat * BucketWidth) & 0x7) {
*countp += ss.count[cat];
*totalp += ss.count[cat] * (8 - frac);
}
}
}
}

fn void Stat.dump(const Stat* ss, const char* name, u32* countp, u32* totalp) {
u32 count = 0;
u32 size = 0;
Expand All @@ -90,10 +105,10 @@ fn void Stat.dump(const Stat* ss, const char* name, u32* countp, u32* totalp) {
if (!ss.count[cat]) continue;
if (count == ss.count[cat]) {
// no repeat if single category
if (NCat > 1) printf(" %d", cat * 8);
if (NCat > 1) printf(" %d", cat * BucketWidth);
break;
}
printf(" %d:%d/%d", cat * 8, ss.count[cat], ss.size[cat]);
printf(" %d:%d/%d", cat * BucketWidth, ss.count[cat], ss.size[cat]);
}
printf("\n");
*countp += count;
Expand Down Expand Up @@ -151,7 +166,18 @@ fn void Stats.dump(const Stats* s) {
u32 totalCount = typesCount + exprCount + stmtCount + declCount + otherCount;
u32 totalSize = typesTotal + exprTotal + stmtTotal + declTotal + otherTotal;
printf(" %20s %6d %7d\n", "objects", totalCount, totalSize);

if (NCat > 1 && BucketWidth < 8) {
u32 slackCount = 0;
u32 slackTotal = 0;
u32 nStats = sizeof(Stats) / sizeof(Stat);
Stat* sp = (Stat*)s;
for (u32 i = 0; i < nStats; i++) {
sp[i].slack(&slackCount, &slackTotal);
}
if (slackCount) {
printf(" %20s %6d %7d\n", "slack", slackCount, slackTotal);
}
}
printf("---------------------------------------\n");
}

Expand Down
1 change: 0 additions & 1 deletion ast/struct_type_decl.c2
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ public fn StructTypeDecl* StructTypeDecl.create(ast_context.Context* c,
u32 size = sizeof(StructTypeDecl) + num_members * sizeof(Decl*);
size += sizeof(StructLayout);
size += num_members * sizeof(StructMemberLayout); // to store StructMemberLayouts
size = (size + 7) & ~0x7; // round to 8-byte (temp)
StructTypeDecl* d = c.alloc(size);
StructType* stype = StructType.create(c, d);
QualType qt = QualType.create(stype.asType());
Expand Down
4 changes: 1 addition & 3 deletions ast/var_decl.c2
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public fn VarDecl* VarDecl.create(ast_context.Context* c,
// Note: for incremental arrays, the initValue will be set later
if (initValue || ref.isIncrArray() || has_embed) size += sizeof(VarDeclInit);
assert (kind != VarDeclKind.StructMember);
size = (size + 7) & ~0x7; // round to 8-byte (temp)

VarDecl* d = c.alloc(size);
d.base.init(DeclKind.Variable, name, loc, is_public, QualType_Invalid, ast_idx);
Expand Down Expand Up @@ -131,7 +130,6 @@ public fn VarDecl* VarDecl.createStructMember(ast_context.Context* c,
{
u32 size = sizeof(VarDecl) + ref.getExtraSize();
if (bitfield) size += sizeof(BitFieldInfo); // see above
size = (size + 7) & ~0x7; // round to 8-byte (temp)

VarDecl* d = c.alloc(size);
d.base.init(DeclKind.Variable, name, loc, is_public, QualType_Invalid, ast_idx);
Expand Down Expand Up @@ -160,7 +158,7 @@ fn VarDecl* VarDecl.instantiate(const VarDecl* vd, Instantiator* inst)
if (vd.base.varDeclBits.has_init) extra += sizeof(VarDeclInit);
if (vd.base.varDeclBits.is_bitfield) extra += sizeof(BitFieldInfo);
u32 size = sizeof(VarDecl) + extra;
size = (size + 7) & ~0x7; // round to 8-byte (temp)

VarDecl* vd2 = inst.c.alloc(size);
vd2.base = vd.base;
vd2.typeRef.instantiate(&vd.typeRef, inst);
Expand Down