@@ -4425,9 +4425,11 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
4425
4425
} else {
4426
4426
// If this is required to be a constant, constant fold it so that we
4427
4427
// know that the generated intrinsic gets a ConstantInt.
4428
- ArgValue = llvm::ConstantInt::get(
4429
- getLLVMContext(),
4430
- *E->getArg(i)->getIntegerConstantExpr(getContext()));
4428
+ llvm::APSInt Result;
4429
+ bool IsConst = E->getArg(i)->isIntegerConstantExpr(Result,getContext());
4430
+ assert(IsConst && "Constant arg isn't actually constant?");
4431
+ (void)IsConst;
4432
+ ArgValue = llvm::ConstantInt::get(getLLVMContext(), Result);
4431
4433
}
4432
4434
4433
4435
// If the intrinsic arg type is different from the builtin arg type
@@ -5600,14 +5602,13 @@ Value *CodeGenFunction::EmitCommonNeonBuiltinExpr(
5600
5602
SmallVectorImpl<llvm::Value *> &Ops, Address PtrOp0, Address PtrOp1,
5601
5603
llvm::Triple::ArchType Arch) {
5602
5604
// Get the last argument, which specifies the vector type.
5605
+ llvm::APSInt NeonTypeConst;
5603
5606
const Expr *Arg = E->getArg(E->getNumArgs() - 1);
5604
- Optional<llvm::APSInt> NeonTypeConst =
5605
- Arg->getIntegerConstantExpr(getContext());
5606
- if (!NeonTypeConst)
5607
+ if (!Arg->isIntegerConstantExpr(NeonTypeConst, getContext()))
5607
5608
return nullptr;
5608
5609
5609
5610
// Determine the type of this overloaded NEON intrinsic.
5610
- NeonTypeFlags Type(NeonTypeConst-> getZExtValue());
5611
+ NeonTypeFlags Type(NeonTypeConst. getZExtValue());
5611
5612
bool Usgn = Type.isUnsigned();
5612
5613
bool Quad = Type.isQuad();
5613
5614
const bool HasLegalHalfType = getTarget().hasLegalHalfType();
@@ -6890,9 +6891,10 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID,
6890
6891
} else {
6891
6892
// If this is required to be a constant, constant fold it so that we know
6892
6893
// that the generated intrinsic gets a ConstantInt.
6893
- Ops.push_back(llvm::ConstantInt::get(
6894
- getLLVMContext(),
6895
- *E->getArg(i)->getIntegerConstantExpr(getContext())));
6894
+ llvm::APSInt Result;
6895
+ bool IsConst = E->getArg(i)->isIntegerConstantExpr(Result, getContext());
6896
+ assert(IsConst && "Constant arg isn't actually constant?"); (void)IsConst;
6897
+ Ops.push_back(llvm::ConstantInt::get(getLLVMContext(), Result));
6896
6898
}
6897
6899
}
6898
6900
@@ -7103,9 +7105,9 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID,
7103
7105
7104
7106
// Get the last argument, which specifies the vector type.
7105
7107
assert(HasExtraArg);
7108
+ llvm::APSInt Result;
7106
7109
const Expr *Arg = E->getArg(E->getNumArgs()-1);
7107
- Optional<llvm::APSInt> Result = Arg->getIntegerConstantExpr(getContext());
7108
- if (!Result)
7110
+ if (!Arg->isIntegerConstantExpr(Result, getContext()))
7109
7111
return nullptr;
7110
7112
7111
7113
if (BuiltinID == ARM::BI__builtin_arm_vcvtr_f ||
@@ -7118,7 +7120,7 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID,
7118
7120
Ty = DoubleTy;
7119
7121
7120
7122
// Determine whether this is an unsigned conversion or not.
7121
- bool usgn = Result-> getZExtValue() == 1;
7123
+ bool usgn = Result. getZExtValue() == 1;
7122
7124
unsigned Int = usgn ? Intrinsic::arm_vcvtru : Intrinsic::arm_vcvtr;
7123
7125
7124
7126
// Call the appropriate intrinsic.
@@ -7127,7 +7129,7 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID,
7127
7129
}
7128
7130
7129
7131
// Determine the type of this overloaded NEON intrinsic.
7130
- NeonTypeFlags Type = Result-> getZExtValue();
7132
+ NeonTypeFlags Type( Result. getZExtValue() );
7131
7133
bool usgn = Type.isUnsigned();
7132
7134
bool rightShift = false;
7133
7135
@@ -7271,7 +7273,11 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID,
7271
7273
7272
7274
template<typename Integer>
7273
7275
static Integer GetIntegerConstantValue(const Expr *E, ASTContext &Context) {
7274
- return E->getIntegerConstantExpr(Context)->getExtValue();
7276
+ llvm::APSInt IntVal;
7277
+ bool IsConst = E->isIntegerConstantExpr(IntVal, Context);
7278
+ assert(IsConst && "Sema should have checked this was a constant");
7279
+ (void)IsConst;
7280
+ return IntVal.getExtValue();
7275
7281
}
7276
7282
7277
7283
static llvm::Value *SignOrZeroExtend(CGBuilderTy &Builder, llvm::Value *V,
@@ -7544,13 +7550,13 @@ static Value *EmitAArch64TblBuiltinExpr(CodeGenFunction &CGF, unsigned BuiltinID
7544
7550
assert(E->getNumArgs() >= 3);
7545
7551
7546
7552
// Get the last argument, which specifies the vector type.
7553
+ llvm::APSInt Result;
7547
7554
const Expr *Arg = E->getArg(E->getNumArgs() - 1);
7548
- Optional<llvm::APSInt> Result = Arg->getIntegerConstantExpr(CGF.getContext());
7549
- if (!Result)
7555
+ if (!Arg->isIntegerConstantExpr(Result, CGF.getContext()))
7550
7556
return nullptr;
7551
7557
7552
7558
// Determine the type of this overloaded NEON intrinsic.
7553
- NeonTypeFlags Type = Result-> getZExtValue();
7559
+ NeonTypeFlags Type( Result. getZExtValue() );
7554
7560
llvm::VectorType *Ty = GetNeonType(&CGF, Type);
7555
7561
if (!Ty)
7556
7562
return nullptr;
@@ -8936,9 +8942,11 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
8936
8942
} else {
8937
8943
// If this is required to be a constant, constant fold it so that we know
8938
8944
// that the generated intrinsic gets a ConstantInt.
8939
- Ops.push_back(llvm::ConstantInt::get(
8940
- getLLVMContext(),
8941
- *E->getArg(i)->getIntegerConstantExpr(getContext())));
8945
+ llvm::APSInt Result;
8946
+ bool IsConst = E->getArg(i)->isIntegerConstantExpr(Result, getContext());
8947
+ assert(IsConst && "Constant arg isn't actually constant?");
8948
+ (void)IsConst;
8949
+ Ops.push_back(llvm::ConstantInt::get(getLLVMContext(), Result));
8942
8950
}
8943
8951
}
8944
8952
@@ -8953,11 +8961,12 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
8953
8961
return Result;
8954
8962
}
8955
8963
8964
+ llvm::APSInt Result;
8956
8965
const Expr *Arg = E->getArg(E->getNumArgs()-1);
8957
8966
NeonTypeFlags Type(0);
8958
- if (Optional<llvm::APSInt> Result = Arg->getIntegerConstantExpr( getContext()))
8967
+ if (Arg->isIntegerConstantExpr(Result, getContext()))
8959
8968
// Determine the type of this overloaded NEON intrinsic.
8960
- Type = NeonTypeFlags(Result-> getZExtValue());
8969
+ Type = NeonTypeFlags(Result. getZExtValue());
8961
8970
8962
8971
bool usgn = Type.isUnsigned();
8963
8972
bool quad = Type.isQuad();
@@ -11788,8 +11797,10 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID,
11788
11797
11789
11798
// If this is required to be a constant, constant fold it so that we know
11790
11799
// that the generated intrinsic gets a ConstantInt.
11791
- Ops.push_back(llvm::ConstantInt::get(
11792
- getLLVMContext(), *E->getArg(i)->getIntegerConstantExpr(getContext())));
11800
+ llvm::APSInt Result;
11801
+ bool IsConst = E->getArg(i)->isIntegerConstantExpr(Result, getContext());
11802
+ assert(IsConst && "Constant arg isn't actually constant?"); (void)IsConst;
11803
+ Ops.push_back(llvm::ConstantInt::get(getLLVMContext(), Result));
11793
11804
}
11794
11805
11795
11806
// These exist so that the builtin that takes an immediate can be bounds
@@ -15068,8 +15079,11 @@ Value *CodeGenFunction::EmitSystemZBuiltinExpr(unsigned BuiltinID,
15068
15079
llvm::Type *ResultType = ConvertType(E->getType());
15069
15080
Value *X = EmitScalarExpr(E->getArg(0));
15070
15081
// Constant-fold the M4 and M5 mask arguments.
15071
- llvm::APSInt M4 = *E->getArg(1)->getIntegerConstantExpr(getContext());
15072
- llvm::APSInt M5 = *E->getArg(2)->getIntegerConstantExpr(getContext());
15082
+ llvm::APSInt M4, M5;
15083
+ bool IsConstM4 = E->getArg(1)->isIntegerConstantExpr(M4, getContext());
15084
+ bool IsConstM5 = E->getArg(2)->isIntegerConstantExpr(M5, getContext());
15085
+ assert(IsConstM4 && IsConstM5 && "Constant arg isn't actually constant?");
15086
+ (void)IsConstM4; (void)IsConstM5;
15073
15087
// Check whether this instance can be represented via a LLVM standard
15074
15088
// intrinsic. We only support some combinations of M4 and M5.
15075
15089
Intrinsic::ID ID = Intrinsic::not_intrinsic;
@@ -15124,7 +15138,10 @@ Value *CodeGenFunction::EmitSystemZBuiltinExpr(unsigned BuiltinID,
15124
15138
Value *X = EmitScalarExpr(E->getArg(0));
15125
15139
Value *Y = EmitScalarExpr(E->getArg(1));
15126
15140
// Constant-fold the M4 mask argument.
15127
- llvm::APSInt M4 = *E->getArg(2)->getIntegerConstantExpr(getContext());
15141
+ llvm::APSInt M4;
15142
+ bool IsConstM4 = E->getArg(2)->isIntegerConstantExpr(M4, getContext());
15143
+ assert(IsConstM4 && "Constant arg isn't actually constant?");
15144
+ (void)IsConstM4;
15128
15145
// Check whether this instance can be represented via a LLVM standard
15129
15146
// intrinsic. We only support some values of M4.
15130
15147
Intrinsic::ID ID = Intrinsic::not_intrinsic;
@@ -15158,7 +15175,10 @@ Value *CodeGenFunction::EmitSystemZBuiltinExpr(unsigned BuiltinID,
15158
15175
Value *X = EmitScalarExpr(E->getArg(0));
15159
15176
Value *Y = EmitScalarExpr(E->getArg(1));
15160
15177
// Constant-fold the M4 mask argument.
15161
- llvm::APSInt M4 = *E->getArg(2)->getIntegerConstantExpr(getContext());
15178
+ llvm::APSInt M4;
15179
+ bool IsConstM4 = E->getArg(2)->isIntegerConstantExpr(M4, getContext());
15180
+ assert(IsConstM4 && "Constant arg isn't actually constant?");
15181
+ (void)IsConstM4;
15162
15182
// Check whether this instance can be represented via a LLVM standard
15163
15183
// intrinsic. We only support some values of M4.
15164
15184
Intrinsic::ID ID = Intrinsic::not_intrinsic;
@@ -15825,11 +15845,10 @@ CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
15825
15845
Address Dst = EmitPointerWithAlignment(E->getArg(0));
15826
15846
Value *Src = EmitScalarExpr(E->getArg(1));
15827
15847
Value *Ldm = EmitScalarExpr(E->getArg(2));
15828
- Optional<llvm::APSInt> isColMajorArg =
15829
- E->getArg(3)->getIntegerConstantExpr(getContext());
15830
- if (!isColMajorArg)
15848
+ llvm::APSInt isColMajorArg;
15849
+ if (!E->getArg(3)->isIntegerConstantExpr(isColMajorArg, getContext()))
15831
15850
return nullptr;
15832
- bool isColMajor = isColMajorArg-> getSExtValue();
15851
+ bool isColMajor = isColMajorArg. getSExtValue();
15833
15852
NVPTXMmaLdstInfo II = getNVPTXMmaLdstInfo(BuiltinID);
15834
15853
unsigned IID = isColMajor ? II.IID_col : II.IID_row;
15835
15854
if (IID == 0)
@@ -15870,11 +15889,10 @@ CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
15870
15889
Value *Dst = EmitScalarExpr(E->getArg(0));
15871
15890
Address Src = EmitPointerWithAlignment(E->getArg(1));
15872
15891
Value *Ldm = EmitScalarExpr(E->getArg(2));
15873
- Optional<llvm::APSInt> isColMajorArg =
15874
- E->getArg(3)->getIntegerConstantExpr(getContext());
15875
- if (!isColMajorArg)
15892
+ llvm::APSInt isColMajorArg;
15893
+ if (!E->getArg(3)->isIntegerConstantExpr(isColMajorArg, getContext()))
15876
15894
return nullptr;
15877
- bool isColMajor = isColMajorArg-> getSExtValue();
15895
+ bool isColMajor = isColMajorArg. getSExtValue();
15878
15896
NVPTXMmaLdstInfo II = getNVPTXMmaLdstInfo(BuiltinID);
15879
15897
unsigned IID = isColMajor ? II.IID_col : II.IID_row;
15880
15898
if (IID == 0)
@@ -15921,20 +15939,16 @@ CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
15921
15939
Address SrcA = EmitPointerWithAlignment(E->getArg(1));
15922
15940
Address SrcB = EmitPointerWithAlignment(E->getArg(2));
15923
15941
Address SrcC = EmitPointerWithAlignment(E->getArg(3));
15924
- Optional<llvm::APSInt> LayoutArg =
15925
- E->getArg(4)->getIntegerConstantExpr(getContext());
15926
- if (!LayoutArg)
15942
+ llvm::APSInt LayoutArg;
15943
+ if (!E->getArg(4)->isIntegerConstantExpr(LayoutArg, getContext()))
15927
15944
return nullptr;
15928
- int Layout = LayoutArg-> getSExtValue();
15945
+ int Layout = LayoutArg. getSExtValue();
15929
15946
if (Layout < 0 || Layout > 3)
15930
15947
return nullptr;
15931
15948
llvm::APSInt SatfArg;
15932
15949
if (BuiltinID == NVPTX::BI__bmma_m8n8k128_mma_xor_popc_b1)
15933
15950
SatfArg = 0; // .b1 does not have satf argument.
15934
- else if (Optional<llvm::APSInt> OptSatfArg =
15935
- E->getArg(5)->getIntegerConstantExpr(getContext()))
15936
- SatfArg = *OptSatfArg;
15937
- else
15951
+ else if (!E->getArg(5)->isIntegerConstantExpr(SatfArg, getContext()))
15938
15952
return nullptr;
15939
15953
bool Satf = SatfArg.getSExtValue();
15940
15954
NVPTXMmaInfo MI = getNVPTXMmaInfo(BuiltinID);
@@ -16263,8 +16277,9 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
16263
16277
case WebAssembly::BI__builtin_wasm_extract_lane_i64x2:
16264
16278
case WebAssembly::BI__builtin_wasm_extract_lane_f32x4:
16265
16279
case WebAssembly::BI__builtin_wasm_extract_lane_f64x2: {
16266
- llvm::APSInt LaneConst =
16267
- *E->getArg(1)->getIntegerConstantExpr(getContext());
16280
+ llvm::APSInt LaneConst;
16281
+ if (!E->getArg(1)->isIntegerConstantExpr(LaneConst, getContext()))
16282
+ llvm_unreachable("Constant arg isn't actually constant?");
16268
16283
Value *Vec = EmitScalarExpr(E->getArg(0));
16269
16284
Value *Lane = llvm::ConstantInt::get(getLLVMContext(), LaneConst);
16270
16285
Value *Extract = Builder.CreateExtractElement(Vec, Lane);
@@ -16290,8 +16305,9 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
16290
16305
case WebAssembly::BI__builtin_wasm_replace_lane_i64x2:
16291
16306
case WebAssembly::BI__builtin_wasm_replace_lane_f32x4:
16292
16307
case WebAssembly::BI__builtin_wasm_replace_lane_f64x2: {
16293
- llvm::APSInt LaneConst =
16294
- *E->getArg(1)->getIntegerConstantExpr(getContext());
16308
+ llvm::APSInt LaneConst;
16309
+ if (!E->getArg(1)->isIntegerConstantExpr(LaneConst, getContext()))
16310
+ llvm_unreachable("Constant arg isn't actually constant?");
16295
16311
Value *Vec = EmitScalarExpr(E->getArg(0));
16296
16312
Value *Lane = llvm::ConstantInt::get(getLLVMContext(), LaneConst);
16297
16313
Value *Val = EmitScalarExpr(E->getArg(2));
0 commit comments