diff options
| author | Yong He <yonghe@outlook.com> | 2022-12-07 12:02:30 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-07 12:02:30 -0800 |
| commit | 3a3a8b5f7701109fc413f42692c4de5769870489 (patch) | |
| tree | 909df4a30e69f33a76e0158d92b1823629dc2184 /source/slang/slang-lower-to-ir.cpp | |
| parent | f116f43bd12358e87f351f0d3615628ac4e00921 (diff) | |
Lower-to-ir no longer produce `Construct` inst. (#2553)
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-lower-to-ir.cpp')
| -rw-r--r-- | source/slang/slang-lower-to-ir.cpp | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index f836824f7..7fd0bbee7 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -16,6 +16,7 @@ #include "slang-ir-sccp.h" #include "slang-ir-ssa.h" #include "slang-ir-strip.h" +#include "slang-ir-simplify-cfg.h" #include "slang-ir-validate.h" #include "slang-ir-string-hash.h" #include "slang-ir-clone.h" @@ -721,22 +722,9 @@ LoweredValInfo emitCallToDeclRef( if( auto ctorDeclRef = funcDeclRef.as<ConstructorDecl>() ) { - if(!ctorDeclRef.getDecl()->body && isFromStdLib(ctorDeclRef.decl)) + if(!ctorDeclRef.getDecl()->body && isFromStdLib(ctorDeclRef.decl) && !as<InterfaceDecl>(ctorDeclRef.decl->parentDecl)) { - // HACK: For legacy reasons, all of the built-in initializers - // in the standard library are declared without proper - // intrinsic-op modifiers, so we will assume that an - // initializer without a body should map to `kIROp_Construct`. - // - // TODO: We should make all the initializers in the - // standard library have either a body or a proper - // intrinsic-op modifier. - // - // TODO: We should eliminate `kIROp_Construct` from the - // IR completely, in favor of more detailed/specific ops - // that cover the cases we actually care about. - // - return LoweredValInfo::simple(builder->emitConstructorInst(type, argCount, args)); + SLANG_UNREACHABLE("stdlib error: __init() has no definition."); } } @@ -8328,6 +8316,12 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> getBuilder()->addDecoration(irFunc, kIROp_TreatAsDifferentiableDecoration); } + if (auto intrinsicOp = decl->findModifier<IntrinsicOpModifier>()) + { + auto op = getBuilder()->getIntValue(getBuilder()->getIntType(), intrinsicOp->op); + getBuilder()->addDecoration(irFunc, kIROp_IntrinsicOpDecoration, op); + } + // Register the value now, to avoid any possible infinite recursion when lowering ForwardDerivativeAttribute setGlobalValue(context, decl, LoweredValInfo::simple(findOuterMostGeneric(irFunc))); @@ -9060,12 +9054,10 @@ RefPtr<IRModule> generateIRForTranslationUnit( performMandatoryEarlyInlining(module); // Next, attempt to promote local variables to SSA - // temporaries whenever possible. - constructSSA(module); - - // Do basic constant folding and dead code elimination - // using Sparse Conditional Constant Propagation (SCCP) + // temporaries and do basic simplifications. // + constructSSA(module); + simplifyCFG(module); applySparseConditionalConstantPropagation(module); // Propagate `constexpr`-ness through the dataflow graph (and the |
