[llvm] [polly] [TableGen] Refactor Intrinsic handling in TableGen (PR #103980)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 15 07:50:43 PDT 2024
================
@@ -54,61 +54,44 @@ CodeGenIntrinsicTable::CodeGenIntrinsicTable(const RecordKeeper &RC) {
Targets.back().Count = Intrinsics.size() - Targets.back().Offset;
}
-CodeGenIntrinsic::CodeGenIntrinsic(Record *R,
- ArrayRef<Record *> DefaultProperties) {
- TheDef = R;
- std::string DefName = std::string(R->getName());
+CodeGenIntrinsic::CodeGenIntrinsic(const Record *R,
+ ArrayRef<const Record *> DefaultProperties)
+ : TheDef(R) {
+ StringRef DefName = TheDef->getName();
ArrayRef<SMLoc> DefLoc = R->getLoc();
- Properties = 0;
- isOverloaded = false;
- isCommutative = false;
- canThrow = false;
- isNoReturn = false;
- isNoCallback = false;
- isNoSync = false;
- isNoFree = false;
- isWillReturn = false;
- isCold = false;
- isNoDuplicate = false;
- isNoMerge = false;
- isConvergent = false;
- isSpeculatable = false;
- hasSideEffects = false;
- isStrictFP = false;
- if (DefName.size() <= 4 || DefName.substr(0, 4) != "int_")
+ if (!DefName.starts_with("int_"))
PrintFatalError(DefLoc,
"Intrinsic '" + DefName + "' does not start with 'int_'!");
EnumName = DefName.substr(4);
- if (R->getValue(
- "ClangBuiltinName")) // Ignore a missing ClangBuiltinName field.
- ClangBuiltinName = std::string(R->getValueAsString("ClangBuiltinName"));
- if (R->getValue("MSBuiltinName")) // Ignore a missing MSBuiltinName field.
- MSBuiltinName = std::string(R->getValueAsString("MSBuiltinName"));
+ // Ignore a missing ClangBuiltinName field.
+ ClangBuiltinName =
+ R->getValueAsOptionalString("ClangBuiltinName").value_or("");
+ // Ignore a missing MSBuiltinName field.
+ MSBuiltinName = R->getValueAsOptionalString("MSBuiltinName").value_or("");
- TargetPrefix = std::string(R->getValueAsString("TargetPrefix"));
- Name = std::string(R->getValueAsString("LLVMName"));
+ TargetPrefix = R->getValueAsString("TargetPrefix");
+ Name = R->getValueAsString("LLVMName").str();
if (Name == "") {
// If an explicit name isn't specified, derive one from the DefName.
- Name = "llvm.";
-
- for (unsigned i = 0, e = EnumName.size(); i != e; ++i)
- Name += (EnumName[i] == '_') ? '.' : EnumName[i];
+ Name = "llvm." + EnumName.str();
+ llvm::replace(Name, '_', '.');
} else {
// Verify it starts with "llvm.".
- if (Name.size() <= 5 || Name.substr(0, 5) != "llvm.")
+ if (!StringRef(Name).starts_with("llvm."))
PrintFatalError(DefLoc, "Intrinsic '" + DefName +
"'s name does not start with 'llvm.'!");
}
// If TargetPrefix is specified, make sure that Name starts with
// "llvm.<targetprefix>.".
if (!TargetPrefix.empty()) {
- if (Name.size() < 6 + TargetPrefix.size() ||
- Name.substr(5, 1 + TargetPrefix.size()) != (TargetPrefix + "."))
+ StringRef Prefix = StringRef(Name).drop_front(5); // Drop llvm.
----------------
arsenm wrote:
You can use combine with above with consume_front
https://github.com/llvm/llvm-project/pull/103980
More information about the llvm-commits
mailing list