xref: /llvm-project/clang/lib/Sema/SemaSystemZ.cpp (revision 8424bf207efd89eacf2fe893b67be98d535e1db6)
1ed35a92cSVlad Serebrennikov //===------ SemaSystemZ.cpp ------ SystemZ target-specific routines -------===//
2ed35a92cSVlad Serebrennikov //
3ed35a92cSVlad Serebrennikov // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4ed35a92cSVlad Serebrennikov // See https://llvm.org/LICENSE.txt for license information.
5ed35a92cSVlad Serebrennikov // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6ed35a92cSVlad Serebrennikov //
7ed35a92cSVlad Serebrennikov //===----------------------------------------------------------------------===//
8ed35a92cSVlad Serebrennikov //
9ed35a92cSVlad Serebrennikov //  This file implements semantic analysis functions specific to SystemZ.
10ed35a92cSVlad Serebrennikov //
11ed35a92cSVlad Serebrennikov //===----------------------------------------------------------------------===//
12ed35a92cSVlad Serebrennikov 
13ed35a92cSVlad Serebrennikov #include "clang/Sema/SemaSystemZ.h"
14ed35a92cSVlad Serebrennikov #include "clang/Basic/DiagnosticSema.h"
15ed35a92cSVlad Serebrennikov #include "clang/Basic/TargetBuiltins.h"
16ed35a92cSVlad Serebrennikov #include "clang/Sema/Sema.h"
17ed35a92cSVlad Serebrennikov #include "llvm/ADT/APSInt.h"
18ed35a92cSVlad Serebrennikov #include <optional>
19ed35a92cSVlad Serebrennikov 
20ed35a92cSVlad Serebrennikov namespace clang {
21ed35a92cSVlad Serebrennikov 
22ed35a92cSVlad Serebrennikov SemaSystemZ::SemaSystemZ(Sema &S) : SemaBase(S) {}
23ed35a92cSVlad Serebrennikov 
24ed35a92cSVlad Serebrennikov bool SemaSystemZ::CheckSystemZBuiltinFunctionCall(unsigned BuiltinID,
25ed35a92cSVlad Serebrennikov                                                   CallExpr *TheCall) {
26ed35a92cSVlad Serebrennikov   if (BuiltinID == SystemZ::BI__builtin_tabort) {
27ed35a92cSVlad Serebrennikov     Expr *Arg = TheCall->getArg(0);
28ed35a92cSVlad Serebrennikov     if (std::optional<llvm::APSInt> AbortCode =
29ed35a92cSVlad Serebrennikov             Arg->getIntegerConstantExpr(getASTContext()))
30ed35a92cSVlad Serebrennikov       if (AbortCode->getSExtValue() >= 0 && AbortCode->getSExtValue() < 256)
31ed35a92cSVlad Serebrennikov         return Diag(Arg->getBeginLoc(), diag::err_systemz_invalid_tabort_code)
32ed35a92cSVlad Serebrennikov                << Arg->getSourceRange();
33ed35a92cSVlad Serebrennikov   }
34ed35a92cSVlad Serebrennikov 
35ed35a92cSVlad Serebrennikov   // For intrinsics which take an immediate value as part of the instruction,
36ed35a92cSVlad Serebrennikov   // range check them here.
37ed35a92cSVlad Serebrennikov   unsigned i = 0, l = 0, u = 0;
38ed35a92cSVlad Serebrennikov   switch (BuiltinID) {
39ed35a92cSVlad Serebrennikov   default: return false;
40ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_lcbb: i = 1; l = 0; u = 15; break;
41*8424bf20SUlrich Weigand   case SystemZ::BI__builtin_s390_veval:
42ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_verimb:
43ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_verimh:
44ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_verimf:
45ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_verimg: i = 3; l = 0; u = 255; break;
46ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vfaeb:
47ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vfaeh:
48ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vfaef:
49ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vfaebs:
50ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vfaehs:
51ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vfaefs:
52ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vfaezb:
53ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vfaezh:
54ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vfaezf:
55ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vfaezbs:
56ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vfaezhs:
57ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vfaezfs: i = 2; l = 0; u = 15; break;
58ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vfisb:
59ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vfidb:
60ed35a92cSVlad Serebrennikov     return SemaRef.BuiltinConstantArgRange(TheCall, 1, 0, 15) ||
61ed35a92cSVlad Serebrennikov            SemaRef.BuiltinConstantArgRange(TheCall, 2, 0, 15);
62ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vftcisb:
63ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vftcidb: i = 1; l = 0; u = 4095; break;
64ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vlbb: i = 1; l = 0; u = 15; break;
65ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vpdi: i = 2; l = 0; u = 15; break;
66ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vsldb: i = 2; l = 0; u = 15; break;
67ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vstrcb:
68ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vstrch:
69ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vstrcf:
70ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vstrczb:
71ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vstrczh:
72ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vstrczf:
73ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vstrcbs:
74ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vstrchs:
75ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vstrcfs:
76ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vstrczbs:
77ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vstrczhs:
78ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vstrczfs: i = 3; l = 0; u = 15; break;
79ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vmslg: i = 3; l = 0; u = 15; break;
80ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vfminsb:
81ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vfmaxsb:
82ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vfmindb:
83ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vfmaxdb: i = 2; l = 0; u = 15; break;
84ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vsld: i = 2; l = 0; u = 7; break;
85ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vsrd: i = 2; l = 0; u = 7; break;
86ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vclfnhs:
87ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vclfnls:
88ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vcfn:
89ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vcnf: i = 1; l = 0; u = 15; break;
90ed35a92cSVlad Serebrennikov   case SystemZ::BI__builtin_s390_vcrnfs: i = 2; l = 0; u = 15; break;
91ed35a92cSVlad Serebrennikov   }
92ed35a92cSVlad Serebrennikov   return SemaRef.BuiltinConstantArgRange(TheCall, i, l, u);
93ed35a92cSVlad Serebrennikov }
94ed35a92cSVlad Serebrennikov 
95ed35a92cSVlad Serebrennikov } // namespace clang
96