From 5de3003af561bad33680940ab1809622c428e94b Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Thu, 17 Aug 2017 09:46:19 -0700 Subject: IR generation cleanup work - Make all instructions store their argument count for now, so we can iterate over them easily. - Longer term we might try to optimize for space because the common case is that the operand count is known, but keeping it simpler seems better for now - Split apart the creation of an instruction from adding it to a parent - Use the above capability to make sure that we add a function to its parent *after* all the parameter/result type emission has occured. - Perform simple value numbering for types during IR creation - This logic also tries to pick a good parent for any type instructions, so that types don't get created local to a function unless they really need to - Create all constants at global scope, and re-use when values are identical --- source/slang/lower-to-ir.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'source/slang/lower-to-ir.cpp') diff --git a/source/slang/lower-to-ir.cpp b/source/slang/lower-to-ir.cpp index e00dffa1d..a01279f2e 100644 --- a/source/slang/lower-to-ir.cpp +++ b/source/slang/lower-to-ir.cpp @@ -402,7 +402,7 @@ struct ExprLoweringVisitor : ExprVisitor { IRValue* irBase = base.val; return LoweredValInfo::simple( - getBuilder()->createFieldExtract( + getBuilder()->emitFieldExtract( getSimpleType(fieldType), irBase, fieldIndex)); @@ -517,11 +517,11 @@ struct StmtLoweringVisitor : StmtVisitor { auto loweredExpr = lowerExpr(context, expr); - getBuilder()->createReturn(getSimpleVal(loweredExpr)); + getBuilder()->emitReturn(getSimpleVal(loweredExpr)); } else { - getBuilder()->createReturn(); + getBuilder()->emitReturn(); } } }; @@ -599,7 +599,7 @@ struct DeclLoweringVisitor : DeclVisitor IRFunc* irFunc = subBuilder->createFunc(); subBuilder->parentInst = irFunc; - IRBlock* entryBlock = subBuilder->createBlock(); + IRBlock* entryBlock = subBuilder->emitBlock(); subBuilder->parentInst = entryBlock; IRGenContext subContextStorage = *context; @@ -611,7 +611,7 @@ struct DeclLoweringVisitor : DeclVisitor for( auto paramDecl : decl->GetParameters() ) { IRType* irParamType = lowerSimpleType(context, paramDecl->getType()); - IRParam* irParam = subBuilder->createParam(irParamType); + IRParam* irParam = subBuilder->emitParam(irParamType); DeclRef paramDeclRef = makeDeclRef(paramDecl.Ptr()); @@ -625,6 +625,8 @@ struct DeclLoweringVisitor : DeclVisitor lowerStmt(subContext, decl->Body); + getBuilder()->addInst(irFunc); + return LoweredValInfo::simple(irFunc); } }; @@ -713,13 +715,17 @@ IRModule* lowerEntryPointToIR( context->shared = sharedContext; + SharedIRBuilder sharedBuilderStorage; + SharedIRBuilder* sharedBuilder = &sharedBuilderStorage; + sharedBuilder->module = nullptr; + IRBuilder builderStorage; IRBuilder* builder = &builderStorage; - builder->module = nullptr; + builder->shared = sharedBuilder; builder->parentInst = nullptr; IRModule* module = builder->createModule(); - builder->module = module; + sharedBuilder->module = module; builder->parentInst = module; context->irBuilder = builder; -- cgit v1.2.3