From a12480fe49d5ba7c0a9c2ac63363dc76b599ddbd Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Wed, 18 Oct 2017 11:08:47 -0700 Subject: Work on IR-based cross-compilation (#222) There are two big changes here: - Add logic during the initial IR cloning pass for an entry point + target that tries to pick the best possible version of any target-overloaded function. This allows us to pick the intrinsic version of `saturate()` when compiling for HLSL output, but then pick the non-intrinsic version (that is implemented in terms of `clamp()`) when targetting GLSL. - Add an initial specialization pass that tries to deal with generics. This required some fixing work to IR generation, so that we correctly generate explicit operations to specialize a generic for specific types (this is currently implemented as a `specialize` instruction that takes the generic to specialize plus a declaration-reference that represents the specialized form). With that work in place, we can scan for `specialize` instructions inside of non-generic functions, and use them to trigger generation of specialized code. We rely on the name-mangling scheme to help us find pre-existing specializations when possible. There are also a bunch of cleanups encountered along the way: - Don't use the explicit `layout(offset=...)` for uniforms, because it isn't supported by all current drivers. For now we will just assume that our layout rules compute the same values that the driver would for un-marked-up code. We can come back later and try to implement a workaround in the cases where this doesn't apply (e.g., by re-running the layout logic as part of emission, and dropping layout modifiers from variables that don't need explicit layout). - Fix some issues in IR dump printing so that we print function declarations more nicely. - Testing: print out failing pixel when image-diff fails --- source/slang/ir.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'source/slang/ir.h') diff --git a/source/slang/ir.h b/source/slang/ir.h index ecc77dbc4..2477c987f 100644 --- a/source/slang/ir.h +++ b/source/slang/ir.h @@ -12,6 +12,7 @@ namespace Slang { class Decl; +class GenericDecl; class FuncType; class Layout; class Type; @@ -98,6 +99,7 @@ enum IRDecorationOp : uint16_t kIRDecorationOp_HighLevelDecl, kIRDecorationOp_Layout, kIRDecorationOp_LoopControl, + kIRDecorationOp_Target, }; // A "decoration" that gets applied to an instruction. @@ -197,6 +199,11 @@ struct IRInst : IRValue // Remove this instruction from its parent block, // and then destroy it (it had better have no uses!) void removeAndDeallocate(); + + // Clear out the arguments of this instruction, + // so that we don't appear on the list of uses + // for those values. + void removeArguments(); }; typedef int64_t IRIntegerValue; @@ -321,8 +328,10 @@ struct IRFunc : IRGlobalValue // The type of the IR-level function IRFuncType* getType() { return (IRFuncType*) type.Ptr(); } - // Any generic parameters this function has - List> genericParams; + // If this function is generic, then we store a reference + // to the AST-level generic that defines its parameters + // and their constraints. + RefPtr genericDecl; // Convenience accessors for working with the // function's type. -- cgit v1.2.3