@@ -4419,11 +4419,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
44194419 } else {
44204420 // If this is required to be a constant, constant fold it so that we
44214421 // know that the generated intrinsic gets a ConstantInt.
4422- llvm::APSInt Result;
4423- bool IsConst = E->getArg(i)->isIntegerConstantExpr(Result,getContext());
4424- assert(IsConst && "Constant arg isn't actually constant?");
4425- (void)IsConst;
4426- ArgValue = llvm::ConstantInt::get(getLLVMContext(), Result);
4422+ ArgValue = llvm::ConstantInt::get(
4423+ getLLVMContext(),
4424+ *E->getArg(i)->getIntegerConstantExpr(getContext()));
44274425 }
44284426
44294427 // If the intrinsic arg type is different from the builtin arg type
@@ -5596,13 +5594,14 @@ Value *CodeGenFunction::EmitCommonNeonBuiltinExpr(
55965594 SmallVectorImpl<llvm::Value *> &Ops, Address PtrOp0, Address PtrOp1,
55975595 llvm::Triple::ArchType Arch) {
55985596 // Get the last argument, which specifies the vector type.
5599- llvm::APSInt NeonTypeConst;
56005597 const Expr *Arg = E->getArg(E->getNumArgs() - 1);
5601- if (!Arg->isIntegerConstantExpr(NeonTypeConst, getContext()))
5598+ Optional<llvm::APSInt> NeonTypeConst =
5599+ Arg->getIntegerConstantExpr(getContext());
5600+ if (!NeonTypeConst)
56025601 return nullptr;
56035602
56045603 // Determine the type of this overloaded NEON intrinsic.
5605- NeonTypeFlags Type(NeonTypeConst. getZExtValue());
5604+ NeonTypeFlags Type(NeonTypeConst-> getZExtValue());
56065605 bool Usgn = Type.isUnsigned();
56075606 bool Quad = Type.isQuad();
56085607 const bool HasLegalHalfType = getTarget().hasLegalHalfType();
@@ -6885,10 +6884,9 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID,
68856884 } else {
68866885 // If this is required to be a constant, constant fold it so that we know
68876886 // that the generated intrinsic gets a ConstantInt.
6888- llvm::APSInt Result;
6889- bool IsConst = E->getArg(i)->isIntegerConstantExpr(Result, getContext());
6890- assert(IsConst && "Constant arg isn't actually constant?"); (void)IsConst;
6891- Ops.push_back(llvm::ConstantInt::get(getLLVMContext(), Result));
6887+ Ops.push_back(llvm::ConstantInt::get(
6888+ getLLVMContext(),
6889+ *E->getArg(i)->getIntegerConstantExpr(getContext())));
68926890 }
68936891 }
68946892
@@ -7099,9 +7097,9 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID,
70997097
71007098 // Get the last argument, which specifies the vector type.
71017099 assert(HasExtraArg);
7102- llvm::APSInt Result;
71037100 const Expr *Arg = E->getArg(E->getNumArgs()-1);
7104- if (!Arg->isIntegerConstantExpr(Result, getContext()))
7101+ Optional<llvm::APSInt> Result = Arg->getIntegerConstantExpr(getContext());
7102+ if (!Result)
71057103 return nullptr;
71067104
71077105 if (BuiltinID == ARM::BI__builtin_arm_vcvtr_f ||
@@ -7114,7 +7112,7 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID,
71147112 Ty = DoubleTy;
71157113
71167114 // Determine whether this is an unsigned conversion or not.
7117- bool usgn = Result. getZExtValue() == 1;
7115+ bool usgn = Result-> getZExtValue() == 1;
71187116 unsigned Int = usgn ? Intrinsic::arm_vcvtru : Intrinsic::arm_vcvtr;
71197117
71207118 // Call the appropriate intrinsic.
@@ -7123,7 +7121,7 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID,
71237121 }
71247122
71257123 // Determine the type of this overloaded NEON intrinsic.
7126- NeonTypeFlags Type( Result. getZExtValue() );
7124+ NeonTypeFlags Type = Result-> getZExtValue();
71277125 bool usgn = Type.isUnsigned();
71287126 bool rightShift = false;
71297127
@@ -7267,11 +7265,7 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID,
72677265
72687266template<typename Integer>
72697267static Integer GetIntegerConstantValue(const Expr *E, ASTContext &Context) {
7270- llvm::APSInt IntVal;
7271- bool IsConst = E->isIntegerConstantExpr(IntVal, Context);
7272- assert(IsConst && "Sema should have checked this was a constant");
7273- (void)IsConst;
7274- return IntVal.getExtValue();
7268+ return E->getIntegerConstantExpr(Context)->getExtValue();
72757269}
72767270
72777271static llvm::Value *SignOrZeroExtend(CGBuilderTy &Builder, llvm::Value *V,
@@ -7544,13 +7538,13 @@ static Value *EmitAArch64TblBuiltinExpr(CodeGenFunction &CGF, unsigned BuiltinID
75447538 assert(E->getNumArgs() >= 3);
75457539
75467540 // Get the last argument, which specifies the vector type.
7547- llvm::APSInt Result;
75487541 const Expr *Arg = E->getArg(E->getNumArgs() - 1);
7549- if (!Arg->isIntegerConstantExpr(Result, CGF.getContext()))
7542+ Optional<llvm::APSInt> Result = Arg->getIntegerConstantExpr(CGF.getContext());
7543+ if (!Result)
75507544 return nullptr;
75517545
75527546 // Determine the type of this overloaded NEON intrinsic.
7553- NeonTypeFlags Type( Result. getZExtValue() );
7547+ NeonTypeFlags Type = Result-> getZExtValue();
75547548 llvm::VectorType *Ty = GetNeonType(&CGF, Type);
75557549 if (!Ty)
75567550 return nullptr;
@@ -8936,11 +8930,9 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
89368930 } else {
89378931 // If this is required to be a constant, constant fold it so that we know
89388932 // that the generated intrinsic gets a ConstantInt.
8939- llvm::APSInt Result;
8940- bool IsConst = E->getArg(i)->isIntegerConstantExpr(Result, getContext());
8941- assert(IsConst && "Constant arg isn't actually constant?");
8942- (void)IsConst;
8943- Ops.push_back(llvm::ConstantInt::get(getLLVMContext(), Result));
8933+ Ops.push_back(llvm::ConstantInt::get(
8934+ getLLVMContext(),
8935+ *E->getArg(i)->getIntegerConstantExpr(getContext())));
89448936 }
89458937 }
89468938
@@ -8955,12 +8947,11 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
89558947 return Result;
89568948 }
89578949
8958- llvm::APSInt Result;
89598950 const Expr *Arg = E->getArg(E->getNumArgs()-1);
89608951 NeonTypeFlags Type(0);
8961- if (Arg->isIntegerConstantExpr(Result, getContext()))
8952+ if (Optional<llvm::APSInt> Result = Arg->getIntegerConstantExpr( getContext()))
89628953 // Determine the type of this overloaded NEON intrinsic.
8963- Type = NeonTypeFlags(Result. getZExtValue());
8954+ Type = NeonTypeFlags(Result-> getZExtValue());
89648955
89658956 bool usgn = Type.isUnsigned();
89668957 bool quad = Type.isQuad();
@@ -11791,10 +11782,8 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID,
1179111782
1179211783 // If this is required to be a constant, constant fold it so that we know
1179311784 // that the generated intrinsic gets a ConstantInt.
11794- llvm::APSInt Result;
11795- bool IsConst = E->getArg(i)->isIntegerConstantExpr(Result, getContext());
11796- assert(IsConst && "Constant arg isn't actually constant?"); (void)IsConst;
11797- Ops.push_back(llvm::ConstantInt::get(getLLVMContext(), Result));
11785+ Ops.push_back(llvm::ConstantInt::get(
11786+ getLLVMContext(), *E->getArg(i)->getIntegerConstantExpr(getContext())));
1179811787 }
1179911788
1180011789 // These exist so that the builtin that takes an immediate can be bounds
@@ -15073,11 +15062,8 @@ Value *CodeGenFunction::EmitSystemZBuiltinExpr(unsigned BuiltinID,
1507315062 llvm::Type *ResultType = ConvertType(E->getType());
1507415063 Value *X = EmitScalarExpr(E->getArg(0));
1507515064 // Constant-fold the M4 and M5 mask arguments.
15076- llvm::APSInt M4, M5;
15077- bool IsConstM4 = E->getArg(1)->isIntegerConstantExpr(M4, getContext());
15078- bool IsConstM5 = E->getArg(2)->isIntegerConstantExpr(M5, getContext());
15079- assert(IsConstM4 && IsConstM5 && "Constant arg isn't actually constant?");
15080- (void)IsConstM4; (void)IsConstM5;
15065+ llvm::APSInt M4 = *E->getArg(1)->getIntegerConstantExpr(getContext());
15066+ llvm::APSInt M5 = *E->getArg(2)->getIntegerConstantExpr(getContext());
1508115067 // Check whether this instance can be represented via a LLVM standard
1508215068 // intrinsic. We only support some combinations of M4 and M5.
1508315069 Intrinsic::ID ID = Intrinsic::not_intrinsic;
@@ -15132,10 +15118,7 @@ Value *CodeGenFunction::EmitSystemZBuiltinExpr(unsigned BuiltinID,
1513215118 Value *X = EmitScalarExpr(E->getArg(0));
1513315119 Value *Y = EmitScalarExpr(E->getArg(1));
1513415120 // Constant-fold the M4 mask argument.
15135- llvm::APSInt M4;
15136- bool IsConstM4 = E->getArg(2)->isIntegerConstantExpr(M4, getContext());
15137- assert(IsConstM4 && "Constant arg isn't actually constant?");
15138- (void)IsConstM4;
15121+ llvm::APSInt M4 = *E->getArg(2)->getIntegerConstantExpr(getContext());
1513915122 // Check whether this instance can be represented via a LLVM standard
1514015123 // intrinsic. We only support some values of M4.
1514115124 Intrinsic::ID ID = Intrinsic::not_intrinsic;
@@ -15169,10 +15152,7 @@ Value *CodeGenFunction::EmitSystemZBuiltinExpr(unsigned BuiltinID,
1516915152 Value *X = EmitScalarExpr(E->getArg(0));
1517015153 Value *Y = EmitScalarExpr(E->getArg(1));
1517115154 // Constant-fold the M4 mask argument.
15172- llvm::APSInt M4;
15173- bool IsConstM4 = E->getArg(2)->isIntegerConstantExpr(M4, getContext());
15174- assert(IsConstM4 && "Constant arg isn't actually constant?");
15175- (void)IsConstM4;
15155+ llvm::APSInt M4 = *E->getArg(2)->getIntegerConstantExpr(getContext());
1517615156 // Check whether this instance can be represented via a LLVM standard
1517715157 // intrinsic. We only support some values of M4.
1517815158 Intrinsic::ID ID = Intrinsic::not_intrinsic;
@@ -15839,10 +15819,11 @@ CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
1583915819 Address Dst = EmitPointerWithAlignment(E->getArg(0));
1584015820 Value *Src = EmitScalarExpr(E->getArg(1));
1584115821 Value *Ldm = EmitScalarExpr(E->getArg(2));
15842- llvm::APSInt isColMajorArg;
15843- if (!E->getArg(3)->isIntegerConstantExpr(isColMajorArg, getContext()))
15822+ Optional<llvm::APSInt> isColMajorArg =
15823+ E->getArg(3)->getIntegerConstantExpr(getContext());
15824+ if (!isColMajorArg)
1584415825 return nullptr;
15845- bool isColMajor = isColMajorArg. getSExtValue();
15826+ bool isColMajor = isColMajorArg-> getSExtValue();
1584615827 NVPTXMmaLdstInfo II = getNVPTXMmaLdstInfo(BuiltinID);
1584715828 unsigned IID = isColMajor ? II.IID_col : II.IID_row;
1584815829 if (IID == 0)
@@ -15883,10 +15864,11 @@ CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
1588315864 Value *Dst = EmitScalarExpr(E->getArg(0));
1588415865 Address Src = EmitPointerWithAlignment(E->getArg(1));
1588515866 Value *Ldm = EmitScalarExpr(E->getArg(2));
15886- llvm::APSInt isColMajorArg;
15887- if (!E->getArg(3)->isIntegerConstantExpr(isColMajorArg, getContext()))
15867+ Optional<llvm::APSInt> isColMajorArg =
15868+ E->getArg(3)->getIntegerConstantExpr(getContext());
15869+ if (!isColMajorArg)
1588815870 return nullptr;
15889- bool isColMajor = isColMajorArg. getSExtValue();
15871+ bool isColMajor = isColMajorArg-> getSExtValue();
1589015872 NVPTXMmaLdstInfo II = getNVPTXMmaLdstInfo(BuiltinID);
1589115873 unsigned IID = isColMajor ? II.IID_col : II.IID_row;
1589215874 if (IID == 0)
@@ -15933,16 +15915,20 @@ CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
1593315915 Address SrcA = EmitPointerWithAlignment(E->getArg(1));
1593415916 Address SrcB = EmitPointerWithAlignment(E->getArg(2));
1593515917 Address SrcC = EmitPointerWithAlignment(E->getArg(3));
15936- llvm::APSInt LayoutArg;
15937- if (!E->getArg(4)->isIntegerConstantExpr(LayoutArg, getContext()))
15918+ Optional<llvm::APSInt> LayoutArg =
15919+ E->getArg(4)->getIntegerConstantExpr(getContext());
15920+ if (!LayoutArg)
1593815921 return nullptr;
15939- int Layout = LayoutArg. getSExtValue();
15922+ int Layout = LayoutArg-> getSExtValue();
1594015923 if (Layout < 0 || Layout > 3)
1594115924 return nullptr;
1594215925 llvm::APSInt SatfArg;
1594315926 if (BuiltinID == NVPTX::BI__bmma_m8n8k128_mma_xor_popc_b1)
1594415927 SatfArg = 0; // .b1 does not have satf argument.
15945- else if (!E->getArg(5)->isIntegerConstantExpr(SatfArg, getContext()))
15928+ else if (Optional<llvm::APSInt> OptSatfArg =
15929+ E->getArg(5)->getIntegerConstantExpr(getContext()))
15930+ SatfArg = *OptSatfArg;
15931+ else
1594615932 return nullptr;
1594715933 bool Satf = SatfArg.getSExtValue();
1594815934 NVPTXMmaInfo MI = getNVPTXMmaInfo(BuiltinID);
@@ -16271,9 +16257,8 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
1627116257 case WebAssembly::BI__builtin_wasm_extract_lane_i64x2:
1627216258 case WebAssembly::BI__builtin_wasm_extract_lane_f32x4:
1627316259 case WebAssembly::BI__builtin_wasm_extract_lane_f64x2: {
16274- llvm::APSInt LaneConst;
16275- if (!E->getArg(1)->isIntegerConstantExpr(LaneConst, getContext()))
16276- llvm_unreachable("Constant arg isn't actually constant?");
16260+ llvm::APSInt LaneConst =
16261+ *E->getArg(1)->getIntegerConstantExpr(getContext());
1627716262 Value *Vec = EmitScalarExpr(E->getArg(0));
1627816263 Value *Lane = llvm::ConstantInt::get(getLLVMContext(), LaneConst);
1627916264 Value *Extract = Builder.CreateExtractElement(Vec, Lane);
@@ -16299,9 +16284,8 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
1629916284 case WebAssembly::BI__builtin_wasm_replace_lane_i64x2:
1630016285 case WebAssembly::BI__builtin_wasm_replace_lane_f32x4:
1630116286 case WebAssembly::BI__builtin_wasm_replace_lane_f64x2: {
16302- llvm::APSInt LaneConst;
16303- if (!E->getArg(1)->isIntegerConstantExpr(LaneConst, getContext()))
16304- llvm_unreachable("Constant arg isn't actually constant?");
16287+ llvm::APSInt LaneConst =
16288+ *E->getArg(1)->getIntegerConstantExpr(getContext());
1630516289 Value *Vec = EmitScalarExpr(E->getArg(0));
1630616290 Value *Lane = llvm::ConstantInt::get(getLLVMContext(), LaneConst);
1630716291 Value *Val = EmitScalarExpr(E->getArg(2));
0 commit comments