llvm.org GIT mirror llvm / 3046dcb
[asm matcher] Fix incorrect assertion when there are exactly 32 SubtargetFeatures Summary: The minimal type needs to hold a value of '1ULL << 31' but getMinimalTypeForRange() is called with a value of '1ULL << 32'. This patch will also reduce the size of the matcher table when there are 8 or 16 SubtargetFeatures. Also added a dump of the SubtargetFeatures to the -debug output and corrected getMinimalTypeInRange() to consider 0xffffffffull to be a 32-bit value. The testcase is that no existing code is broken and that LLVM still successfully compiles after adding MIPS64r6 CodeGen support. Reviewers: rafael Reviewed By: rafael Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D3787 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209288 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Sanders 5 years ago
1 changed file(s) with 27 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
572572 std::string getEnumName() const {
573573 return "Feature_" + TheDef->getName();
574574 }
575
576 void dump() {
577 errs() << getEnumName() << " " << Index << "\n";
578 TheDef->dump();
579 }
575580 };
576581
577582 struct OperandMatchEntry {
13231328
13241329 unsigned FeatureNo = SubtargetFeatures.size();
13251330 SubtargetFeatures[Pred] = new SubtargetFeatureInfo(Pred, FeatureNo);
1331 DEBUG(SubtargetFeatures[Pred]->dump());
13261332 assert(FeatureNo < 32 && "Too many subtarget features!");
13271333 }
13281334
21982204 OS << "}\n\n";
21992205 }
22002206
2207 static const char *getMinimalTypeForRange(uint64_t Range) {
2208 assert(Range <= 0xFFFFFFFFULL && "Enum too large");
2209 if (Range > 0xFFFF)
2210 return "uint32_t";
2211 if (Range > 0xFF)
2212 return "uint16_t";
2213 return "uint8_t";
2214 }
2215
2216 static const char *getMinimalRequiredFeaturesType(const AsmMatcherInfo &Info) {
2217 uint64_t MaxIndex = Info.SubtargetFeatures.size();
2218 if (MaxIndex > 0)
2219 MaxIndex--;
2220 return getMinimalTypeForRange(1ULL << MaxIndex);
2221 }
2222
22012223 /// emitSubtargetFeatureFlagEnumeration - Emit the subtarget feature flag
22022224 /// definitions.
22032225 static void emitSubtargetFeatureFlagEnumeration(AsmMatcherInfo &Info,
22042226 raw_ostream &OS) {
22052227 OS << "// Flags for subtarget features that participate in "
22062228 << "instruction matching.\n";
2207 OS << "enum SubtargetFeatureFlag {\n";
2229 OS << "enum SubtargetFeatureFlag : " << getMinimalRequiredFeaturesType(Info)
2230 << " {\n";
22082231 for (std::map::const_iterator
22092232 it = Info.SubtargetFeatures.begin(),
22102233 ie = Info.SubtargetFeatures.end(); it != ie; ++it) {
22112234 SubtargetFeatureInfo &SFI = *it->second;
2212 OS << " " << SFI.getEnumName() << " = (1 << " << SFI.Index << "),\n";
2235 OS << " " << SFI.getEnumName() << " = (1U << " << SFI.Index << "),\n";
22132236 }
22142237 OS << " Feature_None = 0\n";
22152238 OS << "};\n\n";
24452468 return true;
24462469 }
24472470
2448 static const char *getMinimalTypeForRange(uint64_t Range) {
2449 assert(Range < 0xFFFFFFFFULL && "Enum too large");
2450 if (Range > 0xFFFF)
2451 return "uint32_t";
2452 if (Range > 0xFF)
2453 return "uint16_t";
2454 return "uint8_t";
2455 }
2456
24572471 static void emitCustomOperandParsing(raw_ostream &OS, CodeGenTarget &Target,
24582472 const AsmMatcherInfo &Info, StringRef ClassName,
24592473 StringToOffsetTable &StringTable,
24682482 // Emit the static custom operand parsing table;
24692483 OS << "namespace {\n";
24702484 OS << " struct OperandMatchEntry {\n";
2471 OS << " " << getMinimalTypeForRange(1ULL << Info.SubtargetFeatures.size())
2485 OS << " " << getMinimalRequiredFeaturesType(Info)
24722486 << " RequiredFeatures;\n";
24732487 OS << " " << getMinimalTypeForRange(MaxMnemonicIndex)
24742488 << " Mnemonic;\n";
28042818 OS << " uint16_t Opcode;\n";
28052819 OS << " " << getMinimalTypeForRange(Info.Matchables.size())
28062820 << " ConvertFn;\n";
2807 OS << " " << getMinimalTypeForRange(1ULL << Info.SubtargetFeatures.size())
2821 OS << " " << getMinimalRequiredFeaturesType(Info)
28082822 << " RequiredFeatures;\n";
28092823 OS << " " << getMinimalTypeForRange(Info.Classes.size())
28102824 << " Classes[" << MaxNumOperands << "];\n";