@@ -2192,7 +2192,71 @@ IRConstant* IRBuilder::_findOrEmitConstant(IRConstant& keyInst)
2192
2192
return irValue;
2193
2193
}
2194
2194
2195
- irValue = getClonedConstantValue (keyInst);
2195
+ // Calculate the minimum object size (ie not including the payload of value)
2196
+ const size_t prefixSize = SLANG_OFFSET_OF (IRConstant, value);
2197
+
2198
+ switch (keyInst.getOp ())
2199
+ {
2200
+ default :
2201
+ SLANG_UNEXPECTED (" missing case for IR constant" );
2202
+ break ;
2203
+
2204
+ case kIROp_BoolLit :
2205
+ case kIROp_IntLit :
2206
+ {
2207
+ const size_t instSize = prefixSize + sizeof (IRIntegerValue);
2208
+ irValue = static_cast <IRConstant*>(
2209
+ _createInst (instSize, keyInst.getFullType (), keyInst.getOp ()));
2210
+ irValue->value .intVal = keyInst.value .intVal ;
2211
+ break ;
2212
+ }
2213
+ case kIROp_FloatLit :
2214
+ {
2215
+ const size_t instSize = prefixSize + sizeof (IRFloatingPointValue);
2216
+ irValue = static_cast <IRConstant*>(
2217
+ _createInst (instSize, keyInst.getFullType (), keyInst.getOp ()));
2218
+ irValue->value .floatVal = keyInst.value .floatVal ;
2219
+ break ;
2220
+ }
2221
+ case kIROp_PtrLit :
2222
+ {
2223
+ const size_t instSize = prefixSize + sizeof (void *);
2224
+ irValue = static_cast <IRConstant*>(
2225
+ _createInst (instSize, keyInst.getFullType (), keyInst.getOp ()));
2226
+ irValue->value .ptrVal = keyInst.value .ptrVal ;
2227
+ break ;
2228
+ }
2229
+ case kIROp_VoidLit :
2230
+ {
2231
+ const size_t instSize = prefixSize + sizeof (void *);
2232
+ irValue = static_cast <IRConstant*>(
2233
+ _createInst (instSize, keyInst.getFullType (), keyInst.getOp ()));
2234
+ irValue->value .ptrVal = keyInst.value .ptrVal ;
2235
+ break ;
2236
+ }
2237
+ case kIROp_BlobLit :
2238
+ case kIROp_StringLit :
2239
+ {
2240
+ const UnownedStringSlice slice = keyInst.getStringSlice ();
2241
+
2242
+ const size_t sliceSize = slice.getLength ();
2243
+ const size_t instSize =
2244
+ prefixSize + offsetof (IRConstant::StringValue, chars) + sliceSize;
2245
+
2246
+ irValue = static_cast <IRConstant*>(
2247
+ _createInst (instSize, keyInst.getFullType (), keyInst.getOp ()));
2248
+
2249
+ IRConstant::StringValue& dstString = irValue->value .stringVal ;
2250
+
2251
+ dstString.numChars = uint32_t (sliceSize);
2252
+ // Turn into pointer to avoid warning of array overrun
2253
+ char * dstChars = dstString.chars ;
2254
+ // Copy the chars
2255
+ memcpy (dstChars, slice.begin (), sliceSize);
2256
+
2257
+ break ;
2258
+ }
2259
+ }
2196
2260
2197
2261
key.inst = irValue;
2198
2262
m_dedupContext->getConstantMap ().add (key, irValue);
@@ -2405,79 +2469,6 @@ IRInst* IRBuilder::getCapabilityValue(CapabilitySet const& caps)
2405
2469
conjunctions.getBuffer ());
2406
2470
}
2407
2471
2408
- IRConstant* IRBuilder::getClonedConstantValue (IRConstant& value)
2409
- {
2410
- IRConstant* irValue = nullptr ;
2411
-
2412
- // Calculate the minimum object size (ie not including the payload of value)
2413
- const size_t prefixSize = SLANG_OFFSET_OF (IRConstant, value);
2414
-
2415
- switch (value.getOp ())
2416
- {
2417
- default :
2418
- SLANG_UNEXPECTED (" missing case for IR constant" );
2419
- break ;
2420
-
2421
- case kIROp_BoolLit :
2422
- case kIROp_IntLit :
2423
- {
2424
- const size_t instSize = prefixSize + sizeof (IRIntegerValue);
2425
- irValue =
2426
- static_cast <IRConstant*>(_createInst (instSize, value.getFullType (), value.getOp ()));
2427
- irValue->value .intVal = value.value .intVal ;
2428
- break ;
2429
- }
2430
- case kIROp_FloatLit :
2431
- {
2432
- const size_t instSize = prefixSize + sizeof (IRFloatingPointValue);
2433
- irValue =
2434
- static_cast <IRConstant*>(_createInst (instSize, value.getFullType (), value.getOp ()));
2435
- irValue->value .floatVal = value.value .floatVal ;
2436
- break ;
2437
- }
2438
- case kIROp_PtrLit :
2439
- {
2440
- const size_t instSize = prefixSize + sizeof (void *);
2441
- irValue =
2442
- static_cast <IRConstant*>(_createInst (instSize, value.getFullType (), value.getOp ()));
2443
- irValue->value .ptrVal = value.value .ptrVal ;
2444
- break ;
2445
- }
2446
- case kIROp_VoidLit :
2447
- {
2448
- const size_t instSize = prefixSize + sizeof (void *);
2449
- irValue =
2450
- static_cast <IRConstant*>(_createInst (instSize, value.getFullType (), value.getOp ()));
2451
- irValue->value .ptrVal = value.value .ptrVal ;
2452
- break ;
2453
- }
2454
- case kIROp_BlobLit :
2455
- case kIROp_StringLit :
2456
- {
2457
- const UnownedStringSlice slice = value.getStringSlice ();
2458
-
2459
- const size_t sliceSize = slice.getLength ();
2460
- const size_t instSize =
2461
- prefixSize + offsetof (IRConstant::StringValue, chars) + sliceSize;
2462
-
2463
- irValue =
2464
- static_cast <IRConstant*>(_createInst (instSize, value.getFullType (), value.getOp ()));
2465
-
2466
- IRConstant::StringValue& dstString = irValue->value .stringVal ;
2467
-
2468
- dstString.numChars = uint32_t (sliceSize);
2469
- // Turn into pointer to avoid warning of array overrun
2470
- char * dstChars = dstString.chars ;
2471
- // Copy the chars
2472
- memcpy (dstChars, slice.begin (), sliceSize);
2473
-
2474
- break ;
2475
- }
2476
- }
2477
-
2478
- return irValue;
2479
- }
2480
-
2481
2472
static void canonicalizeInstOperands (IRBuilder& builder, IROp op, ArrayView<IRInst*> operands)
2482
2473
{
2483
2474
// For Array types, we always want to make sure its element count
@@ -5853,6 +5844,16 @@ IRGlobalConstant* IRBuilder::emitGlobalConstant(IRType* type, IRInst* val)
5853
5844
return inst;
5854
5845
}
5855
5846
5847
+ IRConstant* IRBuilder::emitPtrLit (IRType* type, void * ptrVal)
5848
+ {
5849
+ const size_t prefixSize = SLANG_OFFSET_OF (IRConstant, value);
5850
+ const size_t instSize = prefixSize + sizeof (void *);
5851
+ auto inst = static_cast <IRConstant*>(_createInst (instSize, type, kIROp_PtrLit ));
5852
+ inst->value .ptrVal = ptrVal;
5853
+ addInst (inst);
5854
+ return inst;
5855
+ }
5856
+
5856
5857
IRInst* IRBuilder::emitWaveMaskBallot (IRType* type, IRInst* mask, IRInst* condition)
5857
5858
{
5858
5859
auto inst = createInst<IRInst>(this , kIROp_WaveMaskBallot , type, mask, condition);
0 commit comments