featuregen.cpp 1012 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <llvm/MC/MCSubtargetInfo.h>
  2. #include <llvm/MC/TargetRegistry.h>
  3. #include <llvm/Support/raw_ostream.h>
  4. #include <llvm/ADT/ArrayRef.h>
  5. #include <llvm/Support/InitLLVM.h>
  6. #include <llvm/Support/TargetSelect.h>
  7. // Dumps the default set of supported features for the given microarch.
  8. int main(int argc, char **argv) {
  9. if (argc < 3) {
  10. llvm::errs() << "Error: first arg should be triple, second should be microarch\n";
  11. return 1;
  12. }
  13. llvm::InitializeAllTargets();
  14. llvm::InitializeAllTargetMCs();
  15. std::string error;
  16. const llvm::Target* target = llvm::TargetRegistry::lookupTarget(argv[1], error);
  17. if (!target) {
  18. llvm::errs() << "Error: " << error << "\n";
  19. return 1;
  20. }
  21. auto STI = target->createMCSubtargetInfo(argv[1], argv[2], "");
  22. std::string plus = "+";
  23. llvm::ArrayRef<llvm::SubtargetFeatureKV> features = STI->getAllProcessorFeatures();
  24. for (const auto& feature : features) {
  25. if (STI->checkFeatures(plus + feature.Key)) {
  26. llvm::outs() << feature.Key << "\n";
  27. }
  28. }
  29. return 0;
  30. }