@@ -1063,55 +1063,51 @@ static void emitBinaryParser(raw_ostream &OS, indent Indent,
1063
1063
}
1064
1064
}
1065
1065
1066
- static void emitDecoder (raw_ostream &OS, indent Indent,
1067
- const InstructionEncoding &Encoding) {
1066
+ static std::string getDecoderString (const InstructionEncoding &Encoding) {
1067
+ std::string Decoder;
1068
+ raw_string_ostream OS (Decoder);
1069
+ indent Indent (UseFnTableInDecodeToMCInst ? 2 : 4 );
1070
+
1068
1071
// If a custom instruction decoder was specified, use that.
1069
1072
StringRef DecoderMethod = Encoding.getDecoderMethod ();
1070
1073
if (!DecoderMethod.empty ()) {
1071
1074
OS << Indent << " if (!Check(S, " << DecoderMethod
1072
1075
<< " (MI, insn, Address, Decoder))) { "
1073
1076
<< (Encoding.hasCompleteDecoder () ? " " : " DecodeComplete = false; " )
1074
1077
<< " return MCDisassembler::Fail; }\n " ;
1075
- return ;
1078
+ } else {
1079
+ for (const OperandInfo &Op : Encoding.getOperands ())
1080
+ emitBinaryParser (OS, Indent, Encoding, Op);
1076
1081
}
1077
-
1078
- for (const OperandInfo &Op : Encoding.getOperands ())
1079
- emitBinaryParser (OS, Indent, Encoding, Op);
1082
+ return Decoder;
1080
1083
}
1081
1084
1082
1085
static unsigned getDecoderIndex (const InstructionEncoding &Encoding,
1083
1086
DecoderTableInfo &TableInfo) {
1084
- // Build up the predicate string.
1085
- SmallString<256 > Decoder;
1086
- // FIXME: emitDecoder() function can take a buffer directly rather than
1087
- // a stream.
1088
- raw_svector_ostream S (Decoder);
1089
- indent Indent (UseFnTableInDecodeToMCInst ? 2 : 4 );
1090
- emitDecoder (S, Indent, Encoding);
1091
-
1092
1087
// Using the full decoder string as the key value here is a bit
1093
1088
// heavyweight, but is effective. If the string comparisons become a
1094
1089
// performance concern, we can implement a mangling of the predicate
1095
1090
// data easily enough with a map back to the actual string. That's
1096
1091
// overkill for now, though.
1092
+ std::string Decoder = getDecoderString (Encoding);
1097
1093
TableInfo.insertDecoder (Decoder);
1098
1094
return TableInfo.getDecoderIndex (Decoder);
1099
1095
}
1100
1096
1101
- // Returns true if there was any predicate emitted.
1102
- static bool emitPredicateMatch (raw_ostream &OS,
1103
- const InstructionEncoding &Encoding,
1104
- StringRef TargetName) {
1097
+ static std::string getPredicateString (const InstructionEncoding &Encoding,
1098
+ StringRef TargetName) {
1105
1099
std::vector<const Record *> Predicates =
1106
1100
Encoding.getRecord ()->getValueAsListOfDefs (" Predicates" );
1107
1101
auto It = llvm::find_if (Predicates, [](const Record *R) {
1108
1102
return R->getValueAsBit (" AssemblerMatcherPredicate" );
1109
1103
});
1110
- bool AnyAsmPredicate = It != Predicates.end ();
1111
- if (!AnyAsmPredicate)
1112
- return false ;
1104
+ if (It == Predicates.end ())
1105
+ return std::string ();
1106
+
1107
+ std::string Predicate;
1108
+ raw_string_ostream OS (Predicate);
1113
1109
SubtargetFeatureInfo::emitMCPredicateCheck (OS, TargetName, Predicates);
1114
- return true ;
1110
+ return Predicate ;
1115
1111
}
1116
1112
1117
1113
static unsigned getPredicateIndex (StringRef Predicate,
@@ -1127,15 +1123,13 @@ static unsigned getPredicateIndex(StringRef Predicate,
1127
1123
1128
1124
void DecoderTableBuilder::emitPredicateTableEntry (unsigned EncodingID) const {
1129
1125
const InstructionEncoding &Encoding = Encodings[EncodingID];
1130
- // Build up the predicate string.
1131
- SmallString<256 > Predicate;
1132
- raw_svector_ostream PS (Predicate);
1133
- if (!emitPredicateMatch (PS, Encoding, Target.getName ()))
1126
+ std::string Predicate = getPredicateString (Encoding, Target.getName ());
1127
+ if (Predicate.empty ())
1134
1128
return ;
1135
1129
1136
1130
// Figure out the index into the predicate table for the predicate just
1137
1131
// computed.
1138
- unsigned PIdx = getPredicateIndex (PS. str () , TableInfo);
1132
+ unsigned PIdx = getPredicateIndex (Predicate , TableInfo);
1139
1133
1140
1134
TableInfo.Table .insertOpcode (OPC_CheckPredicate);
1141
1135
TableInfo.Table .insertULEB128 (PIdx);
0 commit comments