Merge pull request #702 from resetnow/master

SpvBuilder: add const specifier to vector reference arguments
This commit is contained in:
John Kessenich 2017-01-26 11:51:31 -07:00 committed by GitHub
commit 24ed24dd0a
2 changed files with 24 additions and 23 deletions

View File

@ -819,7 +819,7 @@ Id Builder::makeFloat16Constant(float f16, bool specConstant)
} }
#endif #endif
Id Builder::findCompositeConstant(Op typeClass, std::vector<Id>& comps) const Id Builder::findCompositeConstant(Op typeClass, const std::vector<Id>& comps) const
{ {
Instruction* constant = 0; Instruction* constant = 0;
bool found = false; bool found = false;
@ -848,7 +848,7 @@ Id Builder::findCompositeConstant(Op typeClass, std::vector<Id>& comps) const
} }
// Comments in header // Comments in header
Id Builder::makeCompositeConstant(Id typeId, std::vector<Id>& members, bool specConstant) Id Builder::makeCompositeConstant(Id typeId, const std::vector<Id>& members, bool specConstant)
{ {
Op opcode = specConstant ? OpSpecConstantComposite : OpConstantComposite; Op opcode = specConstant ? OpSpecConstantComposite : OpConstantComposite;
assert(typeId); assert(typeId);
@ -1098,7 +1098,7 @@ Id Builder::createLoad(Id lValue)
} }
// Comments in header // Comments in header
Id Builder::createAccessChain(StorageClass storageClass, Id base, std::vector<Id>& offsets) Id Builder::createAccessChain(StorageClass storageClass, Id base, const std::vector<Id>& offsets)
{ {
// Figure out the final resulting type. // Figure out the final resulting type.
spv::Id typeId = getTypeId(base); spv::Id typeId = getTypeId(base);
@ -1148,7 +1148,7 @@ Id Builder::createCompositeExtract(Id composite, Id typeId, unsigned index)
return extract->getResultId(); return extract->getResultId();
} }
Id Builder::createCompositeExtract(Id composite, Id typeId, std::vector<unsigned>& indexes) Id Builder::createCompositeExtract(Id composite, Id typeId, const std::vector<unsigned>& indexes)
{ {
// Generate code for spec constants if in spec constant operation // Generate code for spec constants if in spec constant operation
// generation mode. // generation mode.
@ -1175,7 +1175,7 @@ Id Builder::createCompositeInsert(Id object, Id composite, Id typeId, unsigned i
return insert->getResultId(); return insert->getResultId();
} }
Id Builder::createCompositeInsert(Id object, Id composite, Id typeId, std::vector<unsigned>& indexes) Id Builder::createCompositeInsert(Id object, Id composite, Id typeId, const std::vector<unsigned>& indexes)
{ {
Instruction* insert = new Instruction(getUniqueId(), typeId, OpCompositeInsert); Instruction* insert = new Instruction(getUniqueId(), typeId, OpCompositeInsert);
insert->addIdOperand(object); insert->addIdOperand(object);
@ -1326,7 +1326,7 @@ Id Builder::createSpecConstantOp(Op opCode, Id typeId, const std::vector<Id>& op
return op->getResultId(); return op->getResultId();
} }
Id Builder::createFunctionCall(spv::Function* function, std::vector<spv::Id>& args) Id Builder::createFunctionCall(spv::Function* function, const std::vector<spv::Id>& args)
{ {
Instruction* op = new Instruction(getUniqueId(), function->getReturnType(), OpFunctionCall); Instruction* op = new Instruction(getUniqueId(), function->getReturnType(), OpFunctionCall);
op->addIdOperand(function->getId()); op->addIdOperand(function->getId());
@ -1338,7 +1338,7 @@ Id Builder::createFunctionCall(spv::Function* function, std::vector<spv::Id>& ar
} }
// Comments in header // Comments in header
Id Builder::createRvalueSwizzle(Decoration precision, Id typeId, Id source, std::vector<unsigned>& channels) Id Builder::createRvalueSwizzle(Decoration precision, Id typeId, Id source, const std::vector<unsigned>& channels)
{ {
if (channels.size() == 1) if (channels.size() == 1)
return setPrecision(createCompositeExtract(source, typeId, channels.front()), precision); return setPrecision(createCompositeExtract(source, typeId, channels.front()), precision);
@ -1360,7 +1360,7 @@ Id Builder::createRvalueSwizzle(Decoration precision, Id typeId, Id source, std:
} }
// Comments in header // Comments in header
Id Builder::createLvalueSwizzle(Id typeId, Id target, Id source, std::vector<unsigned>& channels) Id Builder::createLvalueSwizzle(Id typeId, Id target, Id source, const std::vector<unsigned>& channels)
{ {
if (channels.size() == 1 && getNumComponents(source) == 1) if (channels.size() == 1 && getNumComponents(source) == 1)
return createCompositeInsert(source, target, typeId, channels.front()); return createCompositeInsert(source, target, typeId, channels.front());
@ -1446,7 +1446,7 @@ Id Builder::smearScalar(Decoration precision, Id scalar, Id vectorType)
} }
// Comments in header // Comments in header
Id Builder::createBuiltinCall(Id resultType, Id builtins, int entryPoint, std::vector<Id>& args) Id Builder::createBuiltinCall(Id resultType, Id builtins, int entryPoint, const std::vector<Id>& args)
{ {
Instruction* inst = new Instruction(getUniqueId(), resultType, OpExtInst); Instruction* inst = new Instruction(getUniqueId(), resultType, OpExtInst);
inst->addIdOperand(builtins); inst->addIdOperand(builtins);
@ -1794,7 +1794,7 @@ Id Builder::createCompositeCompare(Decoration precision, Id value1, Id value2, b
} }
// OpCompositeConstruct // OpCompositeConstruct
Id Builder::createCompositeConstruct(Id typeId, std::vector<Id>& constituents) Id Builder::createCompositeConstruct(Id typeId, const std::vector<Id>& constituents)
{ {
assert(isAggregateType(typeId) || (getNumTypeConstituents(typeId) > 1 && getNumTypeConstituents(typeId) == (int)constituents.size())); assert(isAggregateType(typeId) || (getNumTypeConstituents(typeId) > 1 && getNumTypeConstituents(typeId) == (int)constituents.size()));
@ -2011,7 +2011,8 @@ void Builder::If::makeEndIf()
} }
// Comments in header // Comments in header
void Builder::makeSwitch(Id selector, int numSegments, std::vector<int>& caseValues, std::vector<int>& valueIndexToSegment, int defaultSegment, void Builder::makeSwitch(Id selector, int numSegments, const std::vector<int>& caseValues,
const std::vector<int>& valueIndexToSegment, int defaultSegment,
std::vector<Block*>& segmentBlocks) std::vector<Block*>& segmentBlocks)
{ {
Function& function = buildPoint->getParent(); Function& function = buildPoint->getParent();

View File

@ -196,7 +196,7 @@ public:
#endif #endif
// Turn the array of constants into a proper spv constant of the requested type. // Turn the array of constants into a proper spv constant of the requested type.
Id makeCompositeConstant(Id type, std::vector<Id>& comps, bool specConst = false); Id makeCompositeConstant(Id type, const std::vector<Id>& comps, bool specConst = false);
// Methods for adding information outside the CFG. // Methods for adding information outside the CFG.
Instruction* addEntryPoint(ExecutionModel, Function*, const char* name); Instruction* addEntryPoint(ExecutionModel, Function*, const char* name);
@ -244,16 +244,16 @@ public:
Id createLoad(Id lValue); Id createLoad(Id lValue);
// Create an OpAccessChain instruction // Create an OpAccessChain instruction
Id createAccessChain(StorageClass, Id base, std::vector<Id>& offsets); Id createAccessChain(StorageClass, Id base, const std::vector<Id>& offsets);
// Create an OpArrayLength instruction // Create an OpArrayLength instruction
Id createArrayLength(Id base, unsigned int member); Id createArrayLength(Id base, unsigned int member);
// Create an OpCompositeExtract instruction // Create an OpCompositeExtract instruction
Id createCompositeExtract(Id composite, Id typeId, unsigned index); Id createCompositeExtract(Id composite, Id typeId, unsigned index);
Id createCompositeExtract(Id composite, Id typeId, std::vector<unsigned>& indexes); Id createCompositeExtract(Id composite, Id typeId, const std::vector<unsigned>& indexes);
Id createCompositeInsert(Id object, Id composite, Id typeId, unsigned index); Id createCompositeInsert(Id object, Id composite, Id typeId, unsigned index);
Id createCompositeInsert(Id object, Id composite, Id typeId, std::vector<unsigned>& indexes); Id createCompositeInsert(Id object, Id composite, Id typeId, const std::vector<unsigned>& indexes);
Id createVectorExtractDynamic(Id vector, Id typeId, Id componentIndex); Id createVectorExtractDynamic(Id vector, Id typeId, Id componentIndex);
Id createVectorInsertDynamic(Id vector, Id typeId, Id component, Id componentIndex); Id createVectorInsertDynamic(Id vector, Id typeId, Id component, Id componentIndex);
@ -267,18 +267,18 @@ public:
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 createFunctionCall(spv::Function*, 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);
// Take an rvalue (source) and a set of channels to extract from it to // Take an rvalue (source) and a set of channels to extract from it to
// make a new rvalue, which is returned. // make a new rvalue, which is returned.
Id createRvalueSwizzle(Decoration precision, Id typeId, Id source, std::vector<unsigned>& channels); Id createRvalueSwizzle(Decoration precision, Id typeId, Id source, const std::vector<unsigned>& channels);
// Take a copy of an lvalue (target) and a source of components, and set the // Take a copy of an lvalue (target) and a source of components, and set the
// source components into the lvalue where the 'channels' say to put them. // source components into the lvalue where the 'channels' say to put them.
// An updated version of the target is returned. // An updated version of the target is returned.
// (No true lvalue or stores are used.) // (No true lvalue or stores are used.)
Id createLvalueSwizzle(Id typeId, Id target, Id source, std::vector<unsigned>& channels); Id createLvalueSwizzle(Id typeId, Id target, Id source, const std::vector<unsigned>& channels);
// If both the id and precision are valid, the id // If both the id and precision are valid, the id
// gets tagged with the requested precision. // gets tagged with the requested precision.
@ -311,7 +311,7 @@ public:
Id smearScalar(Decoration precision, Id scalarVal, Id vectorType); Id smearScalar(Decoration precision, Id scalarVal, Id vectorType);
// Create a call to a built-in function. // Create a call to a built-in function.
Id createBuiltinCall(Id resultType, Id builtins, int entryPoint, std::vector<Id>& args); Id createBuiltinCall(Id resultType, Id builtins, int entryPoint, const std::vector<Id>& args);
// List of parameters used to create a texture operation // List of parameters used to create a texture operation
struct TextureParameters { struct TextureParameters {
@ -346,7 +346,7 @@ public:
Id createCompositeCompare(Decoration precision, Id, Id, bool /* true if for equal, false if for not-equal */); Id createCompositeCompare(Decoration precision, Id, Id, bool /* true if for equal, false if for not-equal */);
// OpCompositeConstruct // OpCompositeConstruct
Id createCompositeConstruct(Id typeId, std::vector<Id>& constituents); Id createCompositeConstruct(Id typeId, const std::vector<Id>& constituents);
// vector or scalar constructor // vector or scalar constructor
Id createConstructor(Decoration precision, const std::vector<Id>& sources, Id resultTypeId); Id createConstructor(Decoration precision, const std::vector<Id>& sources, Id resultTypeId);
@ -388,8 +388,8 @@ public:
// Returns the right set of basic blocks to start each code segment with, so that the caller's // Returns the right set of basic blocks to start each code segment with, so that the caller's
// recursion stack can hold the memory for it. // recursion stack can hold the memory for it.
// //
void makeSwitch(Id condition, int numSegments, std::vector<int>& caseValues, std::vector<int>& valueToSegment, int defaultSegment, void makeSwitch(Id condition, int numSegments, const std::vector<int>& caseValues,
std::vector<Block*>& segmentBB); // return argument const std::vector<int>& valueToSegment, int defaultSegment, std::vector<Block*>& segmentBB); // return argument
// Add a branch to the innermost switch's merge block. // Add a branch to the innermost switch's merge block.
void addSwitchBreak(); void addSwitchBreak();
@ -545,7 +545,7 @@ public:
Id makeInt64Constant(Id typeId, unsigned long long value, bool specConstant); Id makeInt64Constant(Id typeId, unsigned long long value, bool specConstant);
Id findScalarConstant(Op typeClass, Op opcode, Id typeId, unsigned value) const; Id findScalarConstant(Op typeClass, Op opcode, Id typeId, unsigned value) const;
Id findScalarConstant(Op typeClass, Op opcode, Id typeId, unsigned v1, unsigned v2) const; Id findScalarConstant(Op typeClass, Op opcode, Id typeId, unsigned v1, unsigned v2) const;
Id findCompositeConstant(Op typeClass, std::vector<Id>& comps) const; Id findCompositeConstant(Op typeClass, const std::vector<Id>& comps) const;
Id collapseAccessChain(); Id collapseAccessChain();
void transferAccessChainSwizzle(bool dynamic); void transferAccessChainSwizzle(bool dynamic);
void simplifyAccessChainSwizzle(); void simplifyAccessChainSwizzle();