Commit 149afc39 by John Kessenich

SPV: More corrections of <id> versus "immediate" operands.

parent 228e964b
...@@ -81,6 +81,7 @@ Id Builder::import(const char* name) ...@@ -81,6 +81,7 @@ Id Builder::import(const char* name)
{ {
Instruction* import = new Instruction(getUniqueId(), NoType, OpExtInstImport); Instruction* import = new Instruction(getUniqueId(), NoType, OpExtInstImport);
import->addStringOperand(name); import->addStringOperand(name);
module.mapInstruction(import);
imports.push_back(std::unique_ptr<Instruction>(import)); imports.push_back(std::unique_ptr<Instruction>(import));
return import->getResultId(); return import->getResultId();
...@@ -1331,7 +1332,7 @@ void Builder::createNoResultOp(Op opCode) ...@@ -1331,7 +1332,7 @@ void Builder::createNoResultOp(Op opCode)
buildPoint->addInstruction(std::unique_ptr<Instruction>(op)); buildPoint->addInstruction(std::unique_ptr<Instruction>(op));
} }
// An opcode that has one operand, no result id, and no type // An opcode that has one id operand, no result id, and no type
void Builder::createNoResultOp(Op opCode, Id operand) void Builder::createNoResultOp(Op opCode, Id operand)
{ {
Instruction* op = new Instruction(opCode); Instruction* op = new Instruction(opCode);
...@@ -1339,12 +1340,16 @@ void Builder::createNoResultOp(Op opCode, Id operand) ...@@ -1339,12 +1340,16 @@ void Builder::createNoResultOp(Op opCode, Id operand)
buildPoint->addInstruction(std::unique_ptr<Instruction>(op)); buildPoint->addInstruction(std::unique_ptr<Instruction>(op));
} }
// An opcode that has one operand, no result id, and no type // An opcode that has multiple operands, no result id, and no type
void Builder::createNoResultOp(Op opCode, const std::vector<Id>& operands) void Builder::createNoResultOp(Op opCode, const std::vector<IdImmediate>& operands)
{ {
Instruction* op = new Instruction(opCode); Instruction* op = new Instruction(opCode);
for (auto it = operands.cbegin(); it != operands.cend(); ++it) for (auto it = operands.cbegin(); it != operands.cend(); ++it) {
op->addIdOperand(*it); if (it->isId)
op->addIdOperand(it->word);
else
op->addImmediateOperand(it->word);
}
buildPoint->addInstruction(std::unique_ptr<Instruction>(op)); buildPoint->addInstruction(std::unique_ptr<Instruction>(op));
} }
...@@ -1428,6 +1433,20 @@ Id Builder::createOp(Op opCode, Id typeId, const std::vector<Id>& operands) ...@@ -1428,6 +1433,20 @@ Id Builder::createOp(Op opCode, Id typeId, const std::vector<Id>& operands)
return op->getResultId(); return op->getResultId();
} }
Id Builder::createOp(Op opCode, Id typeId, const std::vector<IdImmediate>& operands)
{
Instruction* op = new Instruction(getUniqueId(), typeId, opCode);
for (auto it = operands.cbegin(); it != operands.cend(); ++it) {
if (it->isId)
op->addIdOperand(it->word);
else
op->addImmediateOperand(it->word);
}
buildPoint->addInstruction(std::unique_ptr<Instruction>(op));
return op->getResultId();
}
Id Builder::createSpecConstantOp(Op opCode, Id typeId, const std::vector<Id>& operands, const std::vector<unsigned>& literals) Id Builder::createSpecConstantOp(Op opCode, Id typeId, const std::vector<Id>& operands, const std::vector<unsigned>& literals)
{ {
Instruction* op = new Instruction(getUniqueId(), typeId, OpSpecConstantOp); Instruction* op = new Instruction(getUniqueId(), typeId, OpSpecConstantOp);
......
...@@ -295,13 +295,14 @@ public: ...@@ -295,13 +295,14 @@ public:
void createNoResultOp(Op); void createNoResultOp(Op);
void createNoResultOp(Op, Id operand); void createNoResultOp(Op, Id operand);
void createNoResultOp(Op, const std::vector<Id>& operands); void createNoResultOp(Op, const std::vector<IdImmediate>& operands);
void createControlBarrier(Scope execution, Scope memory, MemorySemanticsMask); void createControlBarrier(Scope execution, Scope memory, MemorySemanticsMask);
void createMemoryBarrier(unsigned executionScope, unsigned memorySemantics); void createMemoryBarrier(unsigned executionScope, unsigned memorySemantics);
Id createUnaryOp(Op, Id typeId, Id operand); Id createUnaryOp(Op, Id typeId, Id operand);
Id createBinOp(Op, Id typeId, Id operand1, Id operand2); Id createBinOp(Op, Id typeId, Id operand1, Id operand2);
Id createTriOp(Op, Id typeId, Id operand1, Id operand2, Id operand3); Id createTriOp(Op, Id typeId, Id operand1, Id operand2, Id operand3);
Id createOp(Op, Id typeId, const std::vector<Id>& operands); Id createOp(Op, Id typeId, const std::vector<Id>& operands);
Id createOp(Op, Id typeId, const std::vector<IdImmediate>& operands);
Id createFunctionCall(spv::Function*, const std::vector<spv::Id>&); Id createFunctionCall(spv::Function*, const std::vector<spv::Id>&);
Id createSpecConstantOp(Op, Id typeId, const std::vector<spv::Id>& operands, const std::vector<unsigned>& literals); Id createSpecConstantOp(Op, Id typeId, const std::vector<spv::Id>& operands, const std::vector<unsigned>& literals);
......
...@@ -79,6 +79,11 @@ const MemorySemanticsMask MemorySemanticsAllMemory = ...@@ -79,6 +79,11 @@ const MemorySemanticsMask MemorySemanticsAllMemory =
MemorySemanticsAtomicCounterMemoryMask | MemorySemanticsAtomicCounterMemoryMask |
MemorySemanticsImageMemoryMask); MemorySemanticsImageMemoryMask);
struct IdImmediate {
bool isId; // true if word is an Id, false if word is an immediate
unsigned word;
};
// //
// SPIR-V IR instruction. // SPIR-V IR instruction.
// //
...@@ -349,7 +354,9 @@ public: ...@@ -349,7 +354,9 @@ public:
Instruction* getInstruction(Id id) const { return idToInstruction[id]; } Instruction* getInstruction(Id id) const { return idToInstruction[id]; }
const std::vector<Function*>& getFunctions() const { return functions; } const std::vector<Function*>& getFunctions() const { return functions; }
spv::Id getTypeId(Id resultId) const { return idToInstruction[resultId]->getTypeId(); } spv::Id getTypeId(Id resultId) const {
return idToInstruction[resultId] == nullptr ? NoType : idToInstruction[resultId]->getTypeId();
}
StorageClass getStorageClass(Id typeId) const StorageClass getStorageClass(Id typeId) const
{ {
assert(idToInstruction[typeId]->getOpCode() == spv::OpTypePointer); assert(idToInstruction[typeId]->getOpCode() == spv::OpTypePointer);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment