|
@@ -20,7 +20,6 @@ namespace spirv {
|
|
class SpirvFunction;
|
|
class SpirvFunction;
|
|
class SpirvBasicBlock;
|
|
class SpirvBasicBlock;
|
|
class SpirvType;
|
|
class SpirvType;
|
|
-class SpirvBuilder;
|
|
|
|
|
|
|
|
class EmitTypeHandler {
|
|
class EmitTypeHandler {
|
|
public:
|
|
public:
|
|
@@ -82,12 +81,12 @@ public:
|
|
};
|
|
};
|
|
|
|
|
|
public:
|
|
public:
|
|
- EmitTypeHandler(ASTContext &astCtx, SpirvBuilder &builder,
|
|
|
|
|
|
+ EmitTypeHandler(ASTContext &astCtx, SpirvContext &spvContext,
|
|
std::vector<uint32_t> *debugVec,
|
|
std::vector<uint32_t> *debugVec,
|
|
std::vector<uint32_t> *decVec,
|
|
std::vector<uint32_t> *decVec,
|
|
std::vector<uint32_t> *typesVec,
|
|
std::vector<uint32_t> *typesVec,
|
|
const std::function<uint32_t()> &takeNextIdFn)
|
|
const std::function<uint32_t()> &takeNextIdFn)
|
|
- : astContext(astCtx), spirvBuilder(builder), debugBinary(debugVec),
|
|
|
|
|
|
+ : astContext(astCtx), context(spvContext), debugBinary(debugVec),
|
|
annotationsBinary(decVec), typeConstantBinary(typesVec),
|
|
annotationsBinary(decVec), typeConstantBinary(typesVec),
|
|
takeNextIdFunction(takeNextIdFn) {
|
|
takeNextIdFunction(takeNextIdFn) {
|
|
assert(decVec);
|
|
assert(decVec);
|
|
@@ -109,6 +108,12 @@ public:
|
|
// instructions into the annotationsBinary.
|
|
// instructions into the annotationsBinary.
|
|
uint32_t emitType(const SpirvType *, SpirvLayoutRule);
|
|
uint32_t emitType(const SpirvType *, SpirvLayoutRule);
|
|
|
|
|
|
|
|
+ // Emits an OpConstant instruction with uint32 type and returns its result-id.
|
|
|
|
+ // If such constant has already been emitted, just returns its resutl-id.
|
|
|
|
+ // Modifies the curTypeInst. Do not call in the middle of construction of
|
|
|
|
+ // another instruction.
|
|
|
|
+ uint32_t getOrCreateConstantUint32(uint32_t value);
|
|
|
|
+
|
|
private:
|
|
private:
|
|
void initTypeInstruction(spv::Op op);
|
|
void initTypeInstruction(spv::Op op);
|
|
void finalizeTypeInstruction();
|
|
void finalizeTypeInstruction();
|
|
@@ -174,7 +179,7 @@ private:
|
|
|
|
|
|
private:
|
|
private:
|
|
ASTContext &astContext;
|
|
ASTContext &astContext;
|
|
- SpirvBuilder &spirvBuilder;
|
|
|
|
|
|
+ SpirvContext &context;
|
|
std::vector<uint32_t> curTypeInst;
|
|
std::vector<uint32_t> curTypeInst;
|
|
std::vector<uint32_t> curDecorationInst;
|
|
std::vector<uint32_t> curDecorationInst;
|
|
std::vector<uint32_t> *debugBinary;
|
|
std::vector<uint32_t> *debugBinary;
|
|
@@ -182,6 +187,11 @@ private:
|
|
std::vector<uint32_t> *typeConstantBinary;
|
|
std::vector<uint32_t> *typeConstantBinary;
|
|
std::function<uint32_t()> takeNextIdFunction;
|
|
std::function<uint32_t()> takeNextIdFunction;
|
|
|
|
|
|
|
|
+ // The array type requires the result-id of an OpConstant for its length. In
|
|
|
|
+ // order to avoid duplicate OpConstant instructions, we keep a map of constant
|
|
|
|
+ // uint value to the result-id of the OpConstant for that value.
|
|
|
|
+ llvm::DenseMap<uint32_t, uint32_t> UintConstantValueToResultIdMap;
|
|
|
|
+
|
|
// emittedTypes is a map that caches the result-id of types with a given list
|
|
// emittedTypes is a map that caches the result-id of types with a given list
|
|
// of decorations in order to avoid emitting an identical type multiple times.
|
|
// of decorations in order to avoid emitting an identical type multiple times.
|
|
using DecorationSetToTypeIdMap =
|
|
using DecorationSetToTypeIdMap =
|
|
@@ -210,12 +220,11 @@ public:
|
|
|
|
|
|
public:
|
|
public:
|
|
EmitVisitor(ASTContext &astCtx, SpirvContext &spvCtx,
|
|
EmitVisitor(ASTContext &astCtx, SpirvContext &spvCtx,
|
|
- const SpirvCodeGenOptions &opts, SpirvBuilder &builder)
|
|
|
|
|
|
+ const SpirvCodeGenOptions &opts)
|
|
: Visitor(opts, spvCtx), id(0),
|
|
: Visitor(opts, spvCtx), id(0),
|
|
- typeHandler(astCtx, builder, &debugBinary, &annotationsBinary,
|
|
|
|
|
|
+ typeHandler(astCtx, spvCtx, &debugBinary, &annotationsBinary,
|
|
&typeConstantBinary,
|
|
&typeConstantBinary,
|
|
- [this]() -> uint32_t { return takeNextId(); }),
|
|
|
|
- spirvBuilder(builder) {}
|
|
|
|
|
|
+ [this]() -> uint32_t { return takeNextId(); }) {}
|
|
|
|
|
|
// Visit different SPIR-V constructs for emitting.
|
|
// Visit different SPIR-V constructs for emitting.
|
|
bool visit(SpirvModule *, Phase phase);
|
|
bool visit(SpirvModule *, Phase phase);
|
|
@@ -320,8 +329,6 @@ private:
|
|
uint32_t id;
|
|
uint32_t id;
|
|
// Handler for emitting types and their related instructions.
|
|
// Handler for emitting types and their related instructions.
|
|
EmitTypeHandler typeHandler;
|
|
EmitTypeHandler typeHandler;
|
|
- // Use spirvBuilder in case we need to create constants.
|
|
|
|
- SpirvBuilder &spirvBuilder;
|
|
|
|
// Current instruction being built
|
|
// Current instruction being built
|
|
SmallVector<uint32_t, 16> curInst;
|
|
SmallVector<uint32_t, 16> curInst;
|
|
// All preamble instructions in the following order:
|
|
// All preamble instructions in the following order:
|