diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2018-09-20 08:14:25 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-09-20 08:14:25 -0700 |
| commit | 738bcb82d0327c463625ee6fcdf14b52e766cedc (patch) | |
| tree | 2651348121b6550fba8b312382416f435f3027ef /source/slang/mangle.cpp | |
| parent | 653fe976af88fcf86162ca5bb1b46d4378864572 (diff) | |
Improve support for non-32-bit types. (#643)
The main change here is to fill out the `BaseType` enumeration so that it covers the full range of 8/16/32/64-bit signed and unsigned integers, as well as 16/32/64-bit floating-point numbers, and then propagate that completion through various places in the code.
More details:
* The current `half`, `float`, `double`, `int`, and `uint` types are still the default names for their types, so things like `float16_t` and `int32_t` were added as `typedef`s.
* We still need to generate the full gamut of vector/matrix `typedef`s for the new types, so that things like `float16_t4x3` will work (yes, I know that is ugly as sin, but that's the HLSL syntax...).
* A few pieces of dead code from earlier in the compiler's life got removed, since I did a find-in-files for `BaseType::` and tried to either update or delete every site.
* A few call sites that were enumerating integer base types in an ad-hoc fashion were changed to use a single `isIntegerBaseType()` function that I added in `check.cpp`
* When compiling with dxc for shader model 6.2 and up, we enable the compiler's support for native 16-bit types via a flag.
* The public API enumeration for reflection of scalar types added cases for 8- and 16-bit integers (it already exposed the other cases we need)
* The lexer was updated to be extremely liberal in what kinds of suffixes it allows on literals. I also removed the logic that was treating, e.g., `0f` as a floating-point literal (it doesn't seem to be the right behavior). That would now be an integer literal with an invalid suffix.
* The logic in the parser that applies types to literals was updated to handle a few more cases: `LL` and `ULL` for 64-bit integers, and `H` for 16-bit floats.
* The mangling logic needed to be updated to handle the new cases, and I consolidated the handling of those types in their front-end and IR forms.
* Removed the explicit `BasicExpressionType::ToString` logic, since all basic types are `DeclRefType`s in the front end, and we can just print them out as such.
* As a bit of a gross hack, fudged the conversion costs so that `int` to `int64_t` conversion is a bit more costly. The problem there is that given an operation like `int(0) + uint(0)`, the best applicable candidates ended up being `+(uint,uint)` and `+(int64_t,int64_t)` because the cost of a single `int`-to-`uint` conversion was the same as the sum of the cost of an `int`-to-`int64_t` and a `uint`-to-`int64_t`. A better long-term fix here is to completely change our overload resolution strategy, but that is obviously way too big to squeeze into this change.
* Type layout computation was updated to handle all the new types and give them their natural size/alignment. Note that this does *not* work for down-level HLSL where `half` is treated as a synonym for `float`. It also doesn't deal with the fact that many of these types aren't actually allowed in constant buffers for certain shader models. A future change should work to add error messages for unsupported stuff during type layout (or just make the types themselves require support for certain capabilities)
Diffstat (limited to 'source/slang/mangle.cpp')
| -rw-r--r-- | source/slang/mangle.cpp | 59 |
1 files changed, 31 insertions, 28 deletions
diff --git a/source/slang/mangle.cpp b/source/slang/mangle.cpp index dc2738d8f..c35ad1e14 100644 --- a/source/slang/mangle.cpp +++ b/source/slang/mangle.cpp @@ -78,6 +78,33 @@ namespace Slang emitVal(context, val); } + void emitBaseType( + ManglingContext* context, + BaseType baseType) + { + switch( baseType ) + { + case BaseType::Void: emitRaw(context, "V"); break; + case BaseType::Bool: emitRaw(context, "b"); break; + case BaseType::Int8: emitRaw(context, "c"); break; + case BaseType::Int16: emitRaw(context, "s"); break; + case BaseType::Int: emitRaw(context, "i"); break; + case BaseType::Int64: emitRaw(context, "I"); break; + case BaseType::UInt8: emitRaw(context, "C"); break; + case BaseType::UInt16: emitRaw(context, "S"); break; + case BaseType::UInt: emitRaw(context, "u"); break; + case BaseType::UInt64: emitRaw(context, "U"); break; + case BaseType::Half: emitRaw(context, "h"); break; + case BaseType::Float: emitRaw(context, "f"); break; + case BaseType::Double: emitRaw(context, "d"); break; + break; + + default: + SLANG_UNEXPECTED("unimplemented case in mangling"); + break; + } + } + void emitType( ManglingContext* context, Type* type) @@ -86,22 +113,7 @@ namespace Slang if( auto basicType = dynamic_cast<BasicExpressionType*>(type) ) { - switch( basicType->baseType ) - { - case BaseType::Void: emitRaw(context, "V"); break; - case BaseType::Bool: emitRaw(context, "b"); break; - case BaseType::Int: emitRaw(context, "i"); break; - case BaseType::UInt: emitRaw(context, "u"); break; - case BaseType::UInt64: emitRaw(context, "U"); break; - case BaseType::Half: emitRaw(context, "h"); break; - case BaseType::Float: emitRaw(context, "f"); break; - case BaseType::Double: emitRaw(context, "d"); break; - break; - - default: - SLANG_UNEXPECTED("unimplemented case in mangling"); - break; - } + emitBaseType(context, basicType->baseType); } else if( auto vecType = dynamic_cast<VectorExpressionType*>(type) ) { @@ -212,19 +224,10 @@ namespace Slang ManglingContext* context, IRInst* inst) { - switch (inst->op) + if(auto basicType = as<IRBasicType>(inst) ) { - case kIROp_VoidType: emitRaw(context, "V"); return; - case kIROp_BoolType: emitRaw(context, "b"); return; - case kIROp_IntType: emitRaw(context, "i"); return; - case kIROp_UIntType: emitRaw(context, "u"); return; - case kIROp_UInt64Type: emitRaw(context, "U"); return; - case kIROp_HalfType: emitRaw(context, "h"); return; - case kIROp_FloatType: emitRaw(context, "f"); return; - case kIROp_DoubleType: emitRaw(context, "d"); return; - - default: - break; + emitBaseType(context, basicType->getBaseType()); + return; } if (auto globalVal = as<IRGlobalValue>(inst)) |
