Free memory associated with SPIR-V generation.
diff --git a/SPIRV/SpvBuilder.cpp b/SPIRV/SpvBuilder.cpp
index 969a6d7..7b17e17 100755
--- a/SPIRV/SpvBuilder.cpp
+++ b/SPIRV/SpvBuilder.cpp
@@ -77,7 +77,7 @@
Instruction* import = new Instruction(getUniqueId(), NoType, OpExtInstImport);
import->addStringOperand(name);
- imports.push_back(import);
+ imports.push_back(std::unique_ptr<Instruction>(import));
return import->getResultId();
}
@@ -88,7 +88,7 @@
if (groupedTypes[OpTypeVoid].size() == 0) {
type = new Instruction(getUniqueId(), NoType, OpTypeVoid);
groupedTypes[OpTypeVoid].push_back(type);
- constantsTypesGlobals.push_back(type);
+ constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(type));
module.mapInstruction(type);
} else
type = groupedTypes[OpTypeVoid].back();
@@ -102,7 +102,7 @@
if (groupedTypes[OpTypeBool].size() == 0) {
type = new Instruction(getUniqueId(), NoType, OpTypeBool);
groupedTypes[OpTypeBool].push_back(type);
- constantsTypesGlobals.push_back(type);
+ constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(type));
module.mapInstruction(type);
} else
type = groupedTypes[OpTypeBool].back();
@@ -116,7 +116,7 @@
if (groupedTypes[OpTypeSampler].size() == 0) {
type = new Instruction(getUniqueId(), NoType, OpTypeSampler);
groupedTypes[OpTypeSampler].push_back(type);
- constantsTypesGlobals.push_back(type);
+ constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(type));
module.mapInstruction(type);
} else
type = groupedTypes[OpTypeSampler].back();
@@ -140,7 +140,7 @@
type->addImmediateOperand(storageClass);
type->addIdOperand(pointee);
groupedTypes[OpTypePointer].push_back(type);
- constantsTypesGlobals.push_back(type);
+ constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(type));
module.mapInstruction(type);
return type->getResultId();
@@ -162,7 +162,7 @@
type->addImmediateOperand(width);
type->addImmediateOperand(hasSign ? 1 : 0);
groupedTypes[OpTypeInt].push_back(type);
- constantsTypesGlobals.push_back(type);
+ constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(type));
module.mapInstruction(type);
return type->getResultId();
@@ -182,7 +182,7 @@
type = new Instruction(getUniqueId(), NoType, OpTypeFloat);
type->addImmediateOperand(width);
groupedTypes[OpTypeFloat].push_back(type);
- constantsTypesGlobals.push_back(type);
+ constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(type));
module.mapInstruction(type);
return type->getResultId();
@@ -202,7 +202,7 @@
for (int op = 0; op < (int)members.size(); ++op)
type->addIdOperand(members[op]);
groupedTypes[OpTypeStruct].push_back(type);
- constantsTypesGlobals.push_back(type);
+ constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(type));
module.mapInstruction(type);
addName(type->getResultId(), name);
@@ -249,7 +249,7 @@
type->addIdOperand(component);
type->addImmediateOperand(size);
groupedTypes[OpTypeVector].push_back(type);
- constantsTypesGlobals.push_back(type);
+ constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(type));
module.mapInstruction(type);
return type->getResultId();
@@ -275,7 +275,7 @@
type->addIdOperand(column);
type->addImmediateOperand(cols);
groupedTypes[OpTypeMatrix].push_back(type);
- constantsTypesGlobals.push_back(type);
+ constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(type));
module.mapInstruction(type);
return type->getResultId();
@@ -305,7 +305,7 @@
type->addIdOperand(element);
type->addIdOperand(sizeId);
groupedTypes[OpTypeArray].push_back(type);
- constantsTypesGlobals.push_back(type);
+ constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(type));
module.mapInstruction(type);
return type->getResultId();
@@ -315,7 +315,7 @@
{
Instruction* type = new Instruction(getUniqueId(), NoType, OpTypeRuntimeArray);
type->addIdOperand(element);
- constantsTypesGlobals.push_back(type);
+ constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(type));
module.mapInstruction(type);
return type->getResultId();
@@ -346,7 +346,7 @@
for (int p = 0; p < (int)paramTypes.size(); ++p)
type->addIdOperand(paramTypes[p]);
groupedTypes[OpTypeFunction].push_back(type);
- constantsTypesGlobals.push_back(type);
+ constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(type));
module.mapInstruction(type);
return type->getResultId();
@@ -379,7 +379,7 @@
type->addImmediateOperand((unsigned int)format);
groupedTypes[OpTypeImage].push_back(type);
- constantsTypesGlobals.push_back(type);
+ constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(type));
module.mapInstruction(type);
return type->getResultId();
@@ -400,7 +400,7 @@
type->addIdOperand(imageType);
groupedTypes[OpTypeSampledImage].push_back(type);
- constantsTypesGlobals.push_back(type);
+ constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(type));
module.mapInstruction(type);
return type->getResultId();
@@ -594,7 +594,7 @@
// Make it
Instruction* c = new Instruction(getUniqueId(), typeId, opcode);
- constantsTypesGlobals.push_back(c);
+ constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(c));
groupedConstants[OpTypeBool].push_back(c);
module.mapInstruction(c);
@@ -610,7 +610,7 @@
Instruction* c = new Instruction(getUniqueId(), typeId, opcode);
c->addImmediateOperand(value);
- constantsTypesGlobals.push_back(c);
+ constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(c));
groupedConstants[OpTypeInt].push_back(c);
module.mapInstruction(c);
@@ -628,7 +628,7 @@
Instruction* c = new Instruction(getUniqueId(), typeId, opcode);
c->addImmediateOperand(value);
- constantsTypesGlobals.push_back(c);
+ constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(c));
groupedConstants[OpTypeFloat].push_back(c);
module.mapInstruction(c);
@@ -649,7 +649,7 @@
Instruction* c = new Instruction(getUniqueId(), typeId, opcode);
c->addImmediateOperand(op1);
c->addImmediateOperand(op2);
- constantsTypesGlobals.push_back(c);
+ constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(c));
groupedConstants[OpTypeFloat].push_back(c);
module.mapInstruction(c);
@@ -708,7 +708,7 @@
Instruction* c = new Instruction(getUniqueId(), typeId, OpConstantComposite);
for (int op = 0; op < (int)members.size(); ++op)
c->addIdOperand(members[op]);
- constantsTypesGlobals.push_back(c);
+ constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(c));
groupedConstants[typeClass].push_back(c);
module.mapInstruction(c);
@@ -722,7 +722,7 @@
entryPoint->addIdOperand(function->getId());
entryPoint->addStringOperand(name);
- entryPoints.push_back(entryPoint);
+ entryPoints.push_back(std::unique_ptr<Instruction>(entryPoint));
return entryPoint;
}
@@ -740,7 +740,7 @@
if (value3 >= 0)
instr->addImmediateOperand(value3);
- executionModes.push_back(instr);
+ executionModes.push_back(std::unique_ptr<Instruction>(instr));
}
void Builder::addName(Id id, const char* string)
@@ -749,7 +749,7 @@
name->addIdOperand(id);
name->addStringOperand(string);
- names.push_back(name);
+ names.push_back(std::unique_ptr<Instruction>(name));
}
void Builder::addMemberName(Id id, int memberNumber, const char* string)
@@ -759,7 +759,7 @@
name->addImmediateOperand(memberNumber);
name->addStringOperand(string);
- names.push_back(name);
+ names.push_back(std::unique_ptr<Instruction>(name));
}
void Builder::addLine(Id target, Id fileName, int lineNum, int column)
@@ -770,7 +770,7 @@
line->addImmediateOperand(lineNum);
line->addImmediateOperand(column);
- lines.push_back(line);
+ lines.push_back(std::unique_ptr<Instruction>(line));
}
void Builder::addDecoration(Id id, Decoration decoration, int num)
@@ -783,7 +783,7 @@
if (num >= 0)
dec->addImmediateOperand(num);
- decorations.push_back(dec);
+ decorations.push_back(std::unique_ptr<Instruction>(dec));
}
void Builder::addMemberDecoration(Id id, unsigned int member, Decoration decoration, int num)
@@ -795,7 +795,7 @@
if (num >= 0)
dec->addImmediateOperand(num);
- decorations.push_back(dec);
+ decorations.push_back(std::unique_ptr<Instruction>(dec));
}
// Comments in header
@@ -827,6 +827,8 @@
if (name)
addName(function->getId(), name);
+ functions.push_back(std::unique_ptr<Function>(function));
+
return function;
}
@@ -836,9 +838,9 @@
if (retVal) {
Instruction* inst = new Instruction(NoResult, NoType, OpReturnValue);
inst->addIdOperand(retVal);
- buildPoint->addInstruction(inst);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(inst));
} else
- buildPoint->addInstruction(new Instruction(NoResult, NoType, OpReturn));
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(new Instruction(NoResult, NoType, OpReturn)));
if (! implicit)
createAndSetNoPredecessorBlock("post-return");
@@ -878,7 +880,7 @@
// Comments in header
void Builder::makeDiscard()
{
- buildPoint->addInstruction(new Instruction(OpKill));
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(new Instruction(OpKill)));
createAndSetNoPredecessorBlock("post-discard");
}
@@ -892,11 +894,11 @@
switch (storageClass) {
case StorageClassFunction:
// Validation rules require the declaration in the entry block
- buildPoint->getParent().addLocalVariable(inst);
+ buildPoint->getParent().addLocalVariable(std::unique_ptr<Instruction>(inst));
break;
default:
- constantsTypesGlobals.push_back(inst);
+ constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(inst));
module.mapInstruction(inst);
break;
}
@@ -911,7 +913,7 @@
Id Builder::createUndefined(Id type)
{
Instruction* inst = new Instruction(getUniqueId(), type, OpUndef);
- buildPoint->addInstruction(inst);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(inst));
return inst->getResultId();
}
@@ -921,7 +923,7 @@
Instruction* store = new Instruction(OpStore);
store->addIdOperand(lValue);
store->addIdOperand(rValue);
- buildPoint->addInstruction(store);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(store));
}
// Comments in header
@@ -929,7 +931,7 @@
{
Instruction* load = new Instruction(getUniqueId(), getDerefTypeId(lValue), OpLoad);
load->addIdOperand(lValue);
- buildPoint->addInstruction(load);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(load));
return load->getResultId();
}
@@ -955,7 +957,7 @@
chain->addIdOperand(base);
for (int i = 0; i < (int)offsets.size(); ++i)
chain->addIdOperand(offsets[i]);
- buildPoint->addInstruction(chain);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(chain));
return chain->getResultId();
}
@@ -965,7 +967,7 @@
Instruction* length = new Instruction(getUniqueId(), makeIntType(32), OpArrayLength);
length->addIdOperand(base);
length->addImmediateOperand(member);
- buildPoint->addInstruction(length);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(length));
return length->getResultId();
}
@@ -975,7 +977,7 @@
Instruction* extract = new Instruction(getUniqueId(), typeId, OpCompositeExtract);
extract->addIdOperand(composite);
extract->addImmediateOperand(index);
- buildPoint->addInstruction(extract);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(extract));
return extract->getResultId();
}
@@ -986,7 +988,7 @@
extract->addIdOperand(composite);
for (int i = 0; i < (int)indexes.size(); ++i)
extract->addImmediateOperand(indexes[i]);
- buildPoint->addInstruction(extract);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(extract));
return extract->getResultId();
}
@@ -997,7 +999,7 @@
insert->addIdOperand(object);
insert->addIdOperand(composite);
insert->addImmediateOperand(index);
- buildPoint->addInstruction(insert);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(insert));
return insert->getResultId();
}
@@ -1009,7 +1011,7 @@
insert->addIdOperand(composite);
for (int i = 0; i < (int)indexes.size(); ++i)
insert->addImmediateOperand(indexes[i]);
- buildPoint->addInstruction(insert);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(insert));
return insert->getResultId();
}
@@ -1019,7 +1021,7 @@
Instruction* extract = new Instruction(getUniqueId(), typeId, OpVectorExtractDynamic);
extract->addIdOperand(vector);
extract->addIdOperand(componentIndex);
- buildPoint->addInstruction(extract);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(extract));
return extract->getResultId();
}
@@ -1030,7 +1032,7 @@
insert->addIdOperand(vector);
insert->addIdOperand(component);
insert->addIdOperand(componentIndex);
- buildPoint->addInstruction(insert);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(insert));
return insert->getResultId();
}
@@ -1039,7 +1041,7 @@
void Builder::createNoResultOp(Op opCode)
{
Instruction* op = new Instruction(opCode);
- buildPoint->addInstruction(op);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(op));
}
// An opcode that has one operand, no result id, and no type
@@ -1047,7 +1049,7 @@
{
Instruction* op = new Instruction(opCode);
op->addIdOperand(operand);
- buildPoint->addInstruction(op);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(op));
}
// An opcode that has one operand, no result id, and no type
@@ -1056,7 +1058,7 @@
Instruction* op = new Instruction(opCode);
for (auto operand : operands)
op->addIdOperand(operand);
- buildPoint->addInstruction(op);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(op));
}
void Builder::createControlBarrier(Scope execution, Scope memory, MemorySemanticsMask semantics)
@@ -1065,7 +1067,7 @@
op->addImmediateOperand(makeUintConstant(execution));
op->addImmediateOperand(makeUintConstant(memory));
op->addImmediateOperand(makeUintConstant(semantics));
- buildPoint->addInstruction(op);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(op));
}
void Builder::createMemoryBarrier(unsigned executionScope, unsigned memorySemantics)
@@ -1073,7 +1075,7 @@
Instruction* op = new Instruction(OpMemoryBarrier);
op->addImmediateOperand(makeUintConstant(executionScope));
op->addImmediateOperand(makeUintConstant(memorySemantics));
- buildPoint->addInstruction(op);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(op));
}
// An opcode that has one operands, a result id, and a type
@@ -1081,7 +1083,7 @@
{
Instruction* op = new Instruction(getUniqueId(), typeId, opCode);
op->addIdOperand(operand);
- buildPoint->addInstruction(op);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(op));
return op->getResultId();
}
@@ -1091,7 +1093,7 @@
Instruction* op = new Instruction(getUniqueId(), typeId, opCode);
op->addIdOperand(left);
op->addIdOperand(right);
- buildPoint->addInstruction(op);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(op));
return op->getResultId();
}
@@ -1102,7 +1104,7 @@
op->addIdOperand(op1);
op->addIdOperand(op2);
op->addIdOperand(op3);
- buildPoint->addInstruction(op);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(op));
return op->getResultId();
}
@@ -1112,7 +1114,7 @@
Instruction* op = new Instruction(getUniqueId(), typeId, opCode);
for (auto operand : operands)
op->addIdOperand(operand);
- buildPoint->addInstruction(op);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(op));
return op->getResultId();
}
@@ -1123,7 +1125,7 @@
op->addIdOperand(function->getId());
for (int a = 0; a < (int)args.size(); ++a)
op->addIdOperand(args[a]);
- buildPoint->addInstruction(op);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(op));
return op->getResultId();
}
@@ -1140,7 +1142,7 @@
swizzle->addIdOperand(source);
for (int i = 0; i < (int)channels.size(); ++i)
swizzle->addImmediateOperand(channels[i]);
- buildPoint->addInstruction(swizzle);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(swizzle));
return swizzle->getResultId();
}
@@ -1171,7 +1173,7 @@
// finish the instruction with these components selectors
for (int i = 0; i < numTargetComponents; ++i)
swizzle->addImmediateOperand(components[i]);
- buildPoint->addInstruction(swizzle);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(swizzle));
return swizzle->getResultId();
}
@@ -1202,7 +1204,7 @@
Instruction* smear = new Instruction(getUniqueId(), vectorType, OpCompositeConstruct);
for (int c = 0; c < numComponents; ++c)
smear->addIdOperand(scalar);
- buildPoint->addInstruction(smear);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(smear));
return smear->getResultId();
}
@@ -1216,7 +1218,7 @@
for (int arg = 0; arg < (int)args.size(); ++arg)
inst->addIdOperand(args[arg]);
- buildPoint->addInstruction(inst);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(inst));
return inst->getResultId();
}
@@ -1344,7 +1346,7 @@
for (int op = optArgNum + 1; op < numArgs; ++op)
textureInst->addIdOperand(texArgs[op]);
setPrecision(textureInst->getResultId(), precision);
- buildPoint->addInstruction(textureInst);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(textureInst));
Id resultId = textureInst->getResultId();
@@ -1412,7 +1414,7 @@
query->addIdOperand(parameters.coords);
if (parameters.lod)
query->addIdOperand(parameters.lod);
- buildPoint->addInstruction(query);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(query));
return query->getResultId();
}
@@ -1494,7 +1496,7 @@
Instruction* op = new Instruction(getUniqueId(), typeId, OpCompositeConstruct);
for (int c = 0; c < (int)constituents.size(); ++c)
op->addIdOperand(constituents[c]);
- buildPoint->addInstruction(op);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(op));
return op->getResultId();
}
@@ -1710,7 +1712,7 @@
switchInst->addImmediateOperand(caseValues[i]);
switchInst->addIdOperand(segmentBlocks[valueIndexToSegment[i]]->getId());
}
- buildPoint->addInstruction(switchInst);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(switchInst));
// push the merge block
switchMerges.push(mergeBlock);
@@ -1781,7 +1783,7 @@
// but we don't yet know where they will come from.
loop.isFirstIteration->addIdOperand(makeBoolConstant(true));
loop.isFirstIteration->addIdOperand(preheader->getId());
- getBuildPoint()->addInstruction(loop.isFirstIteration);
+ getBuildPoint()->addInstruction(std::unique_ptr<Instruction>(loop.isFirstIteration));
// Mark the end of the structured loop. This must exist in the loop header block.
createLoopMerge(loop.merge, loop.header, LoopControlMaskNone);
@@ -2203,7 +2205,7 @@
{
Instruction* branch = new Instruction(OpBranch);
branch->addIdOperand(block->getId());
- buildPoint->addInstruction(branch);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(branch));
block->addPredecessor(buildPoint);
}
@@ -2212,7 +2214,7 @@
Instruction* merge = new Instruction(OpSelectionMerge);
merge->addIdOperand(mergeBlock->getId());
merge->addImmediateOperand(control);
- buildPoint->addInstruction(merge);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(merge));
}
void Builder::createLoopMerge(Block* mergeBlock, Block* continueBlock, unsigned int control)
@@ -2221,7 +2223,7 @@
merge->addIdOperand(mergeBlock->getId());
merge->addIdOperand(continueBlock->getId());
merge->addImmediateOperand(control);
- buildPoint->addInstruction(merge);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(merge));
}
void Builder::createConditionalBranch(Id condition, Block* thenBlock, Block* elseBlock)
@@ -2230,12 +2232,12 @@
branch->addIdOperand(condition);
branch->addIdOperand(thenBlock->getId());
branch->addIdOperand(elseBlock->getId());
- buildPoint->addInstruction(branch);
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(branch));
thenBlock->addPredecessor(buildPoint);
elseBlock->addPredecessor(buildPoint);
}
-void Builder::dumpInstructions(std::vector<unsigned int>& out, const std::vector<Instruction*>& instructions) const
+void Builder::dumpInstructions(std::vector<unsigned int>& out, const std::vector<std::unique_ptr<Instruction> >& instructions) const
{
for (int i = 0; i < (int)instructions.size(); ++i) {
instructions[i]->dump(out);