[spirv] Remove usage of LiteralTypeHint (for array index).
This commit is contained in:
Родитель
3225c33f3b
Коммит
66133978c3
|
@ -24,8 +24,15 @@ namespace spirv {
|
|||
// -- SpirvSpecConstantBinaryOp
|
||||
// -- SpirvSpecConstantUnaryOp
|
||||
|
||||
// SpirvConstantComposite
|
||||
// SpirvComposite
|
||||
bool LiteralTypeVisitor::isLiteralLargerThan32Bits(
|
||||
SpirvConstantInteger *constant) {
|
||||
assert(constant->hasAstResultType());
|
||||
QualType type = constant->getAstResultType();
|
||||
const bool isSigned = type->isSignedIntegerType();
|
||||
const llvm::APInt &value = constant->getValue();
|
||||
return (isSigned && !value.isSignedIntN(32)) ||
|
||||
(!isSigned && !value.isIntN(32));
|
||||
}
|
||||
|
||||
bool LiteralTypeVisitor::canDeduceTypeFromLitType(QualType litType,
|
||||
QualType newType) {
|
||||
|
@ -354,5 +361,19 @@ bool LiteralTypeVisitor::updateTypeForCompositeMembers(
|
|||
return true;
|
||||
}
|
||||
|
||||
bool LiteralTypeVisitor::visit(SpirvAccessChain *inst) {
|
||||
for (auto *index : inst->getIndexes()) {
|
||||
if (auto *constInt = dyn_cast<SpirvConstantInteger>(index)) {
|
||||
if (!isLiteralLargerThan32Bits(constInt)) {
|
||||
updateTypeForInstruction(
|
||||
constInt, constInt->getAstResultType()->isSignedIntegerType()
|
||||
? astContext.IntTy
|
||||
: astContext.UnsignedIntTy);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // end namespace spirv
|
||||
} // namespace clang
|
||||
|
|
|
@ -38,6 +38,7 @@ public:
|
|||
bool visit(SpirvConstantComposite *);
|
||||
bool visit(SpirvComposite *);
|
||||
bool visit(SpirvCompositeExtract *);
|
||||
bool visit(SpirvAccessChain *);
|
||||
|
||||
/// The "sink" visit function for all instructions.
|
||||
///
|
||||
|
@ -60,6 +61,10 @@ private:
|
|||
bool updateTypeForCompositeMembers(
|
||||
QualType compositeType, llvm::ArrayRef<SpirvInstruction *> constituents);
|
||||
|
||||
/// Returns true if the given constant integer instruction contains a value
|
||||
/// that cannot fit in 32 bits.
|
||||
bool isLiteralLargerThan32Bits(SpirvConstantInteger *);
|
||||
|
||||
private:
|
||||
const ASTContext &astContext;
|
||||
};
|
||||
|
|
|
@ -5917,10 +5917,6 @@ const Expr *SPIRVEmitter::collectArrayStructIndices(
|
|||
return base;
|
||||
}
|
||||
|
||||
// Provide a hint to the TypeTranslator that the integer literal used to
|
||||
// index into the following cases should be translated as a 32-bit integer.
|
||||
TypeTranslator::LiteralTypeHint hint(typeTranslator, astContext.IntTy);
|
||||
|
||||
if (const auto *indexing = dyn_cast<ArraySubscriptExpr>(expr)) {
|
||||
if (rawIndex)
|
||||
return nullptr; // TODO: handle constant array index
|
||||
|
|
Загрузка…
Ссылка в новой задаче