Skip to content

Commit e7854c2

Browse files
committed
Add type parameter to getPtrValue()
1 parent 2fc210f commit e7854c2

File tree

3 files changed

+10
-25
lines changed

3 files changed

+10
-25
lines changed

source/slang/slang-ir-clone.cpp

+7-9
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,18 @@ IRInst* cloneInstAndOperands(IRCloneEnv* env, IRBuilder* builder, IRInst* oldIns
5151
SLANG_ASSERT(builder);
5252
SLANG_ASSERT(oldInst);
5353

54+
// We start by mapping the type of the orignal instruction
55+
// to its replacement value, if any.
56+
//
57+
auto oldType = oldInst->getFullType();
58+
auto newType = (IRType*)findCloneForOperand(env, oldType);
59+
5460
// Pointer literals need to be handled separately, as they carry other data
5561
// than just the operands.
5662
if (oldInst->getOp() == kIROp_PtrLit)
5763
{
5864
auto oldPtr = as<IRPtrLit>(oldInst);
59-
auto newInst = builder->emitPtrLit(oldPtr->getFullType(), oldPtr->value.ptrVal);
60-
newInst->sourceLoc = oldPtr->sourceLoc;
61-
return newInst;
65+
return builder->getPtrValue(newType, oldPtr->value.ptrVal);
6266
}
6367

6468
// This logic will not handle any instructions
@@ -72,12 +76,6 @@ IRInst* cloneInstAndOperands(IRCloneEnv* env, IRBuilder* builder, IRInst* oldIns
7276
//
7377
SLANG_ASSERT(!as<IRConstant>(oldInst));
7478

75-
// We start by mapping the type of the orignal instruction
76-
// to its replacement value, if any.
77-
//
78-
auto oldType = oldInst->getFullType();
79-
auto newType = (IRType*)findCloneForOperand(env, oldType);
80-
8179
// Next we will iterate over the operands of `oldInst`
8280
// to find their replacements and install them as
8381
// the operands of `newInst`.

source/slang/slang-ir-insts.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -3596,7 +3596,7 @@ struct IRBuilder
35963596
IRInst* getFloatValue(IRType* type, IRFloatingPointValue value);
35973597
IRStringLit* getStringValue(const UnownedStringSlice& slice);
35983598
IRBlobLit* getBlobValue(ISlangBlob* blob);
3599-
IRPtrLit* _getPtrValue(void* ptr);
3599+
IRPtrLit* getPtrValue(IRType* type, void* ptr);
36003600
IRPtrLit* getNullPtrValue(IRType* type);
36013601
IRPtrLit* getNullVoidPtrValue() { return getNullPtrValue(getPtrType(getVoidType())); }
36023602
IRVoidLit* getVoidValue();
@@ -4433,8 +4433,6 @@ struct IRBuilder
44334433

44344434
IRGlobalConstant* emitGlobalConstant(IRType* type, IRInst* val);
44354435

4436-
IRConstant* emitPtrLit(IRType* type, void* ptr);
4437-
44384436
IRInst* emitWaveMaskBallot(IRType* type, IRInst* mask, IRInst* condition);
44394437
IRInst* emitWaveMaskMatch(IRType* type, IRInst* mask, IRInst* value);
44404438

source/slang/slang-ir.cpp

+2-13
Original file line numberDiff line numberDiff line change
@@ -2395,9 +2395,8 @@ IRBlobLit* IRBuilder::getBlobValue(ISlangBlob* blob)
23952395
return static_cast<IRBlobLit*>(_findOrEmitConstant(keyInst));
23962396
}
23972397

2398-
IRPtrLit* IRBuilder::_getPtrValue(void* data)
2398+
IRPtrLit* IRBuilder::getPtrValue(IRType* type, void* data)
23992399
{
2400-
auto type = getPtrType(getVoidType());
24012400
IRConstant keyInst;
24022401
memset(&keyInst, 0, sizeof(keyInst));
24032402
keyInst.m_op = kIROp_PtrLit;
@@ -5844,16 +5843,6 @@ IRGlobalConstant* IRBuilder::emitGlobalConstant(IRType* type, IRInst* val)
58445843
return inst;
58455844
}
58465845

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-
58575846
IRInst* IRBuilder::emitWaveMaskBallot(IRType* type, IRInst* mask, IRInst* condition)
58585847
{
58595848
auto inst = createInst<IRInst>(this, kIROp_WaveMaskBallot, type, mask, condition);
@@ -6334,7 +6323,7 @@ IRDecoration* IRBuilder::addDecoration(
63346323

63356324
void IRBuilder::addHighLevelDeclDecoration(IRInst* inst, Decl* decl)
63366325
{
6337-
auto ptrConst = _getPtrValue(decl);
6326+
auto ptrConst = getPtrValue(getPtrType(getVoidType()), decl);
63386327
addDecoration(inst, kIROp_HighLevelDeclDecoration, ptrConst);
63396328
}
63406329

0 commit comments

Comments
 (0)