1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
//===- SPIRVAsm.h - --*- C++ -*-===//
//
// The LLVM/SPIRV Translator
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
/// \file
///
/// This file defines the inline assembler entries defined in SPIRV spec with op
/// codes.
///
//===----------------------------------------------------------------------===//
#ifndef SPIRV_LIBSPIRV_SPIRVASM_H
#define SPIRV_LIBSPIRV_SPIRVASM_H
#include "SPIRVEntry.h"
#include "SPIRVInstruction.h"
#include "SPIRVValue.h"
namespace SPIRV {
class SPIRVAsmTargetINTEL : public SPIRVEntry {
public:
static const SPIRVWord FixedWC = 2;
static const Op OC = OpAsmTargetINTEL;
// Complete constructor
SPIRVAsmTargetINTEL(SPIRVModule *M, SPIRVId TheId,
const std::string &TheTarget)
: SPIRVEntry(M, FixedWC + getSizeInWords(TheTarget), OC, TheId),
Target(TheTarget) {
validate();
}
// Incomplete constructor
SPIRVAsmTargetINTEL() : SPIRVEntry(OC) {}
SPIRVCapVec getRequiredCapability() const override {
return getVec(CapabilityAsmINTEL);
}
std::optional<ExtensionID> getRequiredExtension() const override {
return ExtensionID::SPV_INTEL_inline_assembly;
}
const std::string &getTarget() const { return Target; }
protected:
void validate() const override {
SPIRVEntry::validate();
assert(WordCount > FixedWC);
assert(OpCode == OC);
}
_SPIRV_DEF_ENCDEC2(Id, Target)
std::string Target;
};
class SPIRVAsmINTEL : public SPIRVValue {
public:
static const SPIRVWord FixedWC = 5;
static const Op OC = OpAsmINTEL;
// Complete constructor
SPIRVAsmINTEL(SPIRVModule *M, SPIRVTypeFunction *TheFunctionType,
SPIRVId TheId, SPIRVAsmTargetINTEL *TheTarget,
const std::string &TheInstructions,
const std::string &TheConstraints)
: SPIRVValue(M,
FixedWC + getSizeInWords(TheInstructions) +
getSizeInWords(TheConstraints),
OC, TheFunctionType->getReturnType(), TheId),
Target(TheTarget), FunctionType(TheFunctionType),
Instructions(TheInstructions), Constraints(TheConstraints) {
validate();
}
// Incomplete constructor
SPIRVAsmINTEL() : SPIRVValue(OC) {}
SPIRVCapVec getRequiredCapability() const override {
return getVec(CapabilityAsmINTEL);
}
std::optional<ExtensionID> getRequiredExtension() const override {
return ExtensionID::SPV_INTEL_inline_assembly;
}
const std::string &getInstructions() const { return Instructions; }
const std::string &getConstraints() const { return Constraints; }
SPIRVTypeFunction *getFunctionType() const { return FunctionType; }
protected:
_SPIRV_DEF_ENCDEC6(Type, Id, FunctionType, Target, Instructions, Constraints)
void validate() const override {
SPIRVValue::validate();
assert(WordCount > FixedWC);
assert(OpCode == OC);
}
SPIRVAsmTargetINTEL *Target = nullptr;
SPIRVTypeFunction *FunctionType = nullptr;
std::string Instructions;
std::string Constraints;
};
class SPIRVAsmCallINTEL : public SPIRVInstruction {
public:
static const SPIRVWord FixedWC = 4;
static const Op OC = OpAsmCallINTEL;
// Complete constructor
SPIRVAsmCallINTEL(SPIRVId TheId, SPIRVAsmINTEL *TheAsm,
const std::vector<SPIRVWord> &TheArgs,
SPIRVBasicBlock *TheBB)
: SPIRVInstruction(FixedWC + TheArgs.size(), OC, TheAsm->getType(), TheId,
TheBB),
Asm(TheAsm), Args(TheArgs) {
validate();
}
// Incomplete constructor
SPIRVAsmCallINTEL() : SPIRVInstruction(OC) {}
SPIRVCapVec getRequiredCapability() const override {
return getVec(CapabilityAsmINTEL);
}
std::optional<ExtensionID> getRequiredExtension() const override {
return ExtensionID::SPV_INTEL_inline_assembly;
}
bool isOperandLiteral(unsigned int Index) const override { return false; }
void setWordCount(SPIRVWord TheWordCount) override {
SPIRVEntry::setWordCount(TheWordCount);
Args.resize(TheWordCount - FixedWC);
}
const std::vector<SPIRVWord> &getArguments() const { return Args; }
SPIRVAsmINTEL *getAsm() const { return Asm; }
protected:
_SPIRV_DEF_ENCDEC4(Type, Id, Asm, Args)
void validate() const override {
SPIRVInstruction::validate();
assert(WordCount >= FixedWC);
assert(OpCode == OC);
assert(getBasicBlock() && "Invalid BB");
assert(getBasicBlock()->getModule() == Asm->getModule());
}
SPIRVAsmINTEL *Asm = nullptr;
std::vector<SPIRVWord> Args;
};
} // namespace SPIRV
#endif // SPIRV_LIBSPIRV_SPIRVASM_H
|