Index: include/llvm/Target/Target.td =================================================================== --- include/llvm/Target/Target.td +++ include/llvm/Target/Target.td @@ -141,7 +141,10 @@ // of Operand's that are legal as type qualifiers in DAG patterns. This should // only ever be used for defining multiclasses that are polymorphic over both // RegisterClass's and other Operand's. -class DAGOperand { } +class DAGOperand { + string OperandNamespace = "MCOI"; + string DecoderMethod = ""; +} // RegisterClass - Now that all of the registers are defined, and aliases // between registers are defined, specify which registers belong to which @@ -639,9 +642,7 @@ ValueType Type = ty; string PrintMethod = "printOperand"; string EncoderMethod = ""; - string DecoderMethod = ""; bit hasCompleteDecoder = 1; - string OperandNamespace = "MCOI"; string OperandType = "OPERAND_UNKNOWN"; dag MIOperandInfo = (ops); @@ -679,7 +680,6 @@ // should declare the other operand as one of its super classes. AsmOperandClass ParserMatchClass; - string OperandNamespace = "MCOI"; string OperandType = "OPERAND_REGISTER"; } Index: utils/TableGen/FixedLenDecoderEmitter.cpp =================================================================== --- utils/TableGen/FixedLenDecoderEmitter.cpp +++ utils/TableGen/FixedLenDecoderEmitter.cpp @@ -1692,6 +1692,39 @@ } } +static std::string findOperandDecoderMethod(TypedInit *TI) { + std::string Decoder = ""; + + // At this point, we can locate the field, but we need to know how to + // interpret it. As a first step, require the target to provide callbacks + // for decoding register classes. + // FIXME: This need to be extended to handle instructions with custom + // decoder methods, and operands with (simple) MIOperandInfo's. + RecordRecTy *Type = cast(TI->getType()); + Record *TypeRecord = Type->getRecord(); + + RecordVal *DecoderString = TypeRecord->getValue("DecoderMethod"); + StringInit *String = DecoderString ? + dyn_cast(DecoderString->getValue()) : nullptr; + if (String) { + Decoder = String->getValue(); + if (!Decoder.empty()) + return Decoder; + } + + if (TypeRecord->isSubClassOf("RegisterOperand")) + TypeRecord = TypeRecord->getValueAsDef("RegClass"); + + if (TypeRecord->isSubClassOf("RegisterClass")) { + Decoder = "Decode" + TypeRecord->getName() + "RegisterClass"; + } else if (TypeRecord->isSubClassOf("PointerLikeRegClass")) { + Decoder = "DecodePointerLikeRegClass" + + utostr(TypeRecord->getValueAsInt("RegClassKind")); + } + + return Decoder; +} + static bool populateInstruction(CodeGenTarget &Target, const CodeGenInstruction &CGI, unsigned Opc, std::map > &Operands){ @@ -1917,33 +1950,9 @@ continue; } - std::string Decoder = ""; - - // At this point, we can locate the field, but we need to know how to - // interpret it. As a first step, require the target to provide callbacks - // for decoding register classes. - // FIXME: This need to be extended to handle instructions with custom - // decoder methods, and operands with (simple) MIOperandInfo's. TypedInit *TI = cast(Op.first); - RecordRecTy *Type = cast(TI->getType()); - Record *TypeRecord = Type->getRecord(); - bool isReg = false; - if (TypeRecord->isSubClassOf("RegisterOperand")) - TypeRecord = TypeRecord->getValueAsDef("RegClass"); - if (TypeRecord->isSubClassOf("RegisterClass")) { - Decoder = "Decode" + TypeRecord->getName() + "RegisterClass"; - isReg = true; - } else if (TypeRecord->isSubClassOf("PointerLikeRegClass")) { - Decoder = "DecodePointerLikeRegClass" + - utostr(TypeRecord->getValueAsInt("RegClassKind")); - isReg = true; - } - - RecordVal *DecoderString = TypeRecord->getValue("DecoderMethod"); - StringInit *String = DecoderString ? - dyn_cast(DecoderString->getValue()) : nullptr; - if (!isReg && String && String->getValue() != "") - Decoder = String->getValue(); + std::string Decoder = findOperandDecoderMethod(TI); + Record *TypeRecord = cast(TI->getType())->getRecord(); RecordVal *HasCompleteDecoderVal = TypeRecord->getValue("hasCompleteDecoder");