summaryrefslogtreecommitdiff
path: root/source/slang/ir.h
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2018-09-19 15:27:50 -0400
committerGitHub <noreply@github.com>2018-09-19 15:27:50 -0400
commit653fe976af88fcf86162ca5bb1b46d4378864572 (patch)
tree882307a3377e6a4587231721d681daa061a56c78 /source/slang/ir.h
parenta37b3539d94c434c5d74ab524eae2988e48e0756 (diff)
Support for IRStringLit (#645)
* * Added support for strings in IR with IRStringLit - with storage of chars after it * Added kIRDecorationOp_Transitory - can be used for detecting instructions constructed on stack * Made IRConstant hashing work off type * Fix comment that is out of date about how an instruction is determines to hold a transitory string.
Diffstat (limited to 'source/slang/ir.h')
-rw-r--r--source/slang/ir.h59
1 files changed, 52 insertions, 7 deletions
diff --git a/source/slang/ir.h b/source/slang/ir.h
index a7f2cb4fb..15edb9b6c 100644
--- a/source/slang/ir.h
+++ b/source/slang/ir.h
@@ -128,6 +128,10 @@ enum IRDecorationOp : uint16_t
kIRDecorationOp_Semantic,
kIRDecorationOp_InterpolationMode,
kIRDecorationOp_NameHint,
+ /** The _instruction_ is transitory. Such a decoration should NEVER be found on an output instruction a module.
+ Typically used mark an instruction so can be specially handled - say when creating a IRConstant literal, and the payload of
+ needs to be special cased for lookup. */
+ kIRDecorationOp_Transitory,
};
// represents an object allocated in an IR memory arena
@@ -140,6 +144,14 @@ struct IRObject
// for preserving high-level source information.
struct IRDecoration : public IRObject
{
+ static IRDecoration make(IRDecorationOp opIn, IRDecoration* nextIn = nullptr)
+ {
+ IRDecoration dec;
+ dec.next = nextIn;
+ dec.op = opIn;
+ return dec;
+ }
+
// Next decoration attached to the same instruction
IRDecoration* next;
@@ -173,7 +185,6 @@ struct IRInst : public IRObject
return operandCount;
}
-
// Source location information for this value, if any
SourceLoc sourceLoc;
@@ -427,6 +438,8 @@ struct IRBoolType : IRBasicType
IR_LEAF_ISA(BoolType)
};
+SIMPLE_IR_TYPE(StringType, Type)
+
// Constant Instructions
typedef int64_t IRIntegerValue;
@@ -434,21 +447,47 @@ typedef double IRFloatingPointValue;
struct IRConstant : IRInst
{
- union
+ struct StringValue
+ {
+ uint32_t numChars; ///< The number of chars
+ char chars[1]; ///< Chars added at end. NOTE! Must be last member of struct!
+ };
+ struct StringSliceValue
+ {
+ uint32_t numChars;
+ char* chars;
+ };
+
+ union ValueUnion
{
- IRIntegerValue intVal;
+ IRIntegerValue intVal; ///< Used for integrals and boolean
IRFloatingPointValue floatVal;
- // HACK: allows us to hash the value easily
- void* ptrData[2];
- } u;
+ /// Either of these types could be set with kIROp_StringLit.
+ /// Which is used is currently determined with IRDecorationOp - if a kDecorationOp_Transitory is set, then the transitory StringVal is used, else stringVal
+ // which relies on chars being held after the struct).
+ StringValue stringVal;
+ StringSliceValue transitoryStringVal;
+ };
+
+ /// Returns a string slice (or empty string if not appropriate)
+ UnownedStringSlice getStringSlice() const;
+
+ /// True if constants are equal
+ bool equal(IRConstant& rhs);
+ /// Get the hash
+ int getHashCode();
IR_PARENT_ISA(Constant)
+
+ // Must be last member, because data may be held behind
+ // NOTE! The total size of IRConstant may not be allocated - only enough space is allocated for the value type held in the union.
+ ValueUnion value;
};
struct IRIntLit : IRConstant
{
- IRIntegerValue getValue() { return u.intVal; }
+ IRIntegerValue getValue() { return value.intVal; }
IR_LEAF_ISA(IntLit);
};
@@ -457,6 +496,12 @@ struct IRIntLit : IRConstant
// if it has one, and assert-fail otherwise.
IRIntegerValue GetIntVal(IRInst* inst);
+struct IRStringLit : IRConstant
+{
+
+ IR_LEAF_ISA(StringLit);
+};
+
// A instruction that ends a basic block (usually because of control flow)
struct IRTerminatorInst : IRInst
{