[llvm] [DirectX][NFC] Simplified DXIL Operation mapping to LLVM or DirectX intrinsics in DXIL.td. (PR #83193)
Justin Bogner via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 27 14:36:53 PST 2024
================
@@ -291,49 +246,37 @@ static void emitDXILIntrinsicMap(std::vector<DXILOperationDesc> &Ops,
@param Attr string reference
@return std::string Attribute enum string
*/
-static std::string emitDXILOperationAttr(StringRef Attr) {
- return StringSwitch<std::string>(Attr)
- .Case("ReadNone", "Attribute::ReadNone")
- .Case("ReadOnly", "Attribute::ReadOnly")
- .Default("Attribute::None");
-}
-
-static std::string overloadKindStr(ParameterKind Overload) {
- switch (Overload) {
- case ParameterKind::HALF:
- return "OverloadKind::HALF";
- case ParameterKind::FLOAT:
- return "OverloadKind::FLOAT";
- case ParameterKind::DOUBLE:
- return "OverloadKind::DOUBLE";
- case ParameterKind::I1:
- return "OverloadKind::I1";
- case ParameterKind::I8:
- return "OverloadKind::I8";
- case ParameterKind::I16:
- return "OverloadKind::I16";
- case ParameterKind::I32:
- return "OverloadKind::I32";
- case ParameterKind::I64:
- return "OverloadKind::I64";
- case ParameterKind::VOID:
- return "OverloadKind::VOID";
- default:
- return "OverloadKind::UNKNOWN";
+static std::string emitDXILOperationAttr(SmallVector<std::string> Attrs) {
+ for (auto Attr : Attrs) {
+ // For now just recognize IntrNoMem and IntrReadMem as valid and ignore
+ // others
+ if (Attr == "IntrNoMem") {
+ return "Attribute::ReadNone";
+ } else if (Attr == "IntrReadMem") {
+ return "Attribute::ReadOnly";
+ }
}
+ return "Attribute::None";
}
-static std::string
-getDXILOperationOverloads(SmallVector<ParameterKind> Overloads) {
- // Format is: OverloadKind::FLOAT | OverloadKind::HALF
- auto It = Overloads.begin();
- std::string Result;
- raw_string_ostream OS(Result);
- OS << overloadKindStr(*It);
- for (++It; It != Overloads.end(); ++It) {
- OS << " | " << overloadKindStr(*It);
- }
- return OS.str();
+static std::string emitOverloadKindStr(std::string OpTypeStr) {
+ std::string Result =
+ StringSwitch<std::string>(OpTypeStr)
+ .Case("llvm_i16_ty", "OverloadKind::I16")
+ .Case("llvm_i32_ty", "OverloadKind::I32")
+ .Case("llvm_i64_ty", "OverloadKind::I64")
+ .Case("llvm_anyint_ty",
+ "OverloadKind::I16 | OverloadKind::I32 | OverloadKind::I64")
+ .Case("llvm_half_ty", "OverloadKind::HALF")
+ .Case("llvm_float_ty", "OverloadKind::FLOAT")
+ .Case("llvm_double_ty", "OverloadKind::DOUBLE")
+ .Case(
+ "llvm_anyfloat_ty",
+ "OverloadKind::HALF | OverloadKind::FLOAT | OverloadKind::DOUBLE")
+ .Default("UNHANDLED_TYPE");
----------------
bogner wrote:
Doing all of this with strings seems pretty unfortunate. Should we be leveraging `getValueType` from `CodeGenTarget.h` here?
https://github.com/llvm/llvm-project/pull/83193
More information about the llvm-commits
mailing list