@@ -4419,11 +4419,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
4419
4419
} else {
4420
4420
// If this is required to be a constant, constant fold it so that we
4421
4421
// 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()));
4427
4425
}
4428
4426
4429
4427
// If the intrinsic arg type is different from the builtin arg type
@@ -5596,13 +5594,14 @@ Value *CodeGenFunction::EmitCommonNeonBuiltinExpr(
5596
5594
SmallVectorImpl<llvm::Value *> &Ops, Address PtrOp0, Address PtrOp1,
5597
5595
llvm::Triple::ArchType Arch) {
5598
5596
// Get the last argument, which specifies the vector type.
5599
- llvm::APSInt NeonTypeConst;
5600
5597
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)
5602
5601
return nullptr;
5603
5602
5604
5603
// Determine the type of this overloaded NEON intrinsic.
5605
- NeonTypeFlags Type(NeonTypeConst. getZExtValue());
5604
+ NeonTypeFlags Type(NeonTypeConst-> getZExtValue());
5606
5605
bool Usgn = Type.isUnsigned();
5607
5606
bool Quad = Type.isQuad();
5608
5607
const bool HasLegalHalfType = getTarget().hasLegalHalfType();
@@ -6885,10 +6884,9 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID,
6885
6884
} else {
6886
6885
// If this is required to be a constant, constant fold it so that we know
6887
6886
// 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())));
6892
6890
}
6893
6891
}
6894
6892
@@ -7099,9 +7097,9 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID,
7099
7097
7100
7098
// Get the last argument, which specifies the vector type.
7101
7099
assert(HasExtraArg);
7102
- llvm::APSInt Result;
7103
7100
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)
7105
7103
return nullptr;
7106
7104
7107
7105
if (BuiltinID == ARM::BI__builtin_arm_vcvtr_f ||
@@ -7114,7 +7112,7 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID,
7114
7112
Ty = DoubleTy;
7115
7113
7116
7114
// Determine whether this is an unsigned conversion or not.
7117
- bool usgn = Result. getZExtValue() == 1;
7115
+ bool usgn = Result-> getZExtValue() == 1;
7118
7116
unsigned Int = usgn ? Intrinsic::arm_vcvtru : Intrinsic::arm_vcvtr;
7119
7117
7120
7118
// Call the appropriate intrinsic.
@@ -7123,7 +7121,7 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID,
7123
7121
}
7124
7122
7125
7123
// Determine the type of this overloaded NEON intrinsic.
7126
- NeonTypeFlags Type( Result. getZExtValue() );
7124
+ NeonTypeFlags Type = Result-> getZExtValue();
7127
7125
bool usgn = Type.isUnsigned();
7128
7126
bool rightShift = false;
7129
7127
@@ -7267,11 +7265,7 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID,
7267
7265
7268
7266
template<typename Integer>
7269
7267
static 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();
7275
7269
}
7276
7270
7277
7271
static llvm::Value *SignOrZeroExtend(CGBuilderTy &Builder, llvm::Value *V,
@@ -7544,13 +7538,13 @@ static Value *EmitAArch64TblBuiltinExpr(CodeGenFunction &CGF, unsigned BuiltinID
7544
7538
assert(E->getNumArgs() >= 3);
7545
7539
7546
7540
// Get the last argument, which specifies the vector type.
7547
- llvm::APSInt Result;
7548
7541
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)
7550
7544
return nullptr;
7551
7545
7552
7546
// Determine the type of this overloaded NEON intrinsic.
7553
- NeonTypeFlags Type( Result. getZExtValue() );
7547
+ NeonTypeFlags Type = Result-> getZExtValue();
7554
7548
llvm::VectorType *Ty = GetNeonType(&CGF, Type);
7555
7549
if (!Ty)
7556
7550
return nullptr;
@@ -8936,11 +8930,9 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
8936
8930
} else {
8937
8931
// If this is required to be a constant, constant fold it so that we know
8938
8932
// 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())));
8944
8936
}
8945
8937
}
8946
8938
@@ -8955,12 +8947,11 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
8955
8947
return Result;
8956
8948
}
8957
8949
8958
- llvm::APSInt Result;
8959
8950
const Expr *Arg = E->getArg(E->getNumArgs()-1);
8960
8951
NeonTypeFlags Type(0);
8961
- if (Arg->isIntegerConstantExpr(Result, getContext()))
8952
+ if (Optional<llvm::APSInt> Result = Arg->getIntegerConstantExpr( getContext()))
8962
8953
// Determine the type of this overloaded NEON intrinsic.
8963
- Type = NeonTypeFlags(Result. getZExtValue());
8954
+ Type = NeonTypeFlags(Result-> getZExtValue());
8964
8955
8965
8956
bool usgn = Type.isUnsigned();
8966
8957
bool quad = Type.isQuad();
@@ -11791,10 +11782,8 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID,
11791
11782
11792
11783
// If this is required to be a constant, constant fold it so that we know
11793
11784
// 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())));
11798
11787
}
11799
11788
11800
11789
// These exist so that the builtin that takes an immediate can be bounds
@@ -15073,11 +15062,8 @@ Value *CodeGenFunction::EmitSystemZBuiltinExpr(unsigned BuiltinID,
15073
15062
llvm::Type *ResultType = ConvertType(E->getType());
15074
15063
Value *X = EmitScalarExpr(E->getArg(0));
15075
15064
// 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());
15081
15067
// Check whether this instance can be represented via a LLVM standard
15082
15068
// intrinsic. We only support some combinations of M4 and M5.
15083
15069
Intrinsic::ID ID = Intrinsic::not_intrinsic;
@@ -15132,10 +15118,7 @@ Value *CodeGenFunction::EmitSystemZBuiltinExpr(unsigned BuiltinID,
15132
15118
Value *X = EmitScalarExpr(E->getArg(0));
15133
15119
Value *Y = EmitScalarExpr(E->getArg(1));
15134
15120
// 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());
15139
15122
// Check whether this instance can be represented via a LLVM standard
15140
15123
// intrinsic. We only support some values of M4.
15141
15124
Intrinsic::ID ID = Intrinsic::not_intrinsic;
@@ -15169,10 +15152,7 @@ Value *CodeGenFunction::EmitSystemZBuiltinExpr(unsigned BuiltinID,
15169
15152
Value *X = EmitScalarExpr(E->getArg(0));
15170
15153
Value *Y = EmitScalarExpr(E->getArg(1));
15171
15154
// 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());
15176
15156
// Check whether this instance can be represented via a LLVM standard
15177
15157
// intrinsic. We only support some values of M4.
15178
15158
Intrinsic::ID ID = Intrinsic::not_intrinsic;
@@ -15839,10 +15819,11 @@ CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
15839
15819
Address Dst = EmitPointerWithAlignment(E->getArg(0));
15840
15820
Value *Src = EmitScalarExpr(E->getArg(1));
15841
15821
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)
15844
15825
return nullptr;
15845
- bool isColMajor = isColMajorArg. getSExtValue();
15826
+ bool isColMajor = isColMajorArg-> getSExtValue();
15846
15827
NVPTXMmaLdstInfo II = getNVPTXMmaLdstInfo(BuiltinID);
15847
15828
unsigned IID = isColMajor ? II.IID_col : II.IID_row;
15848
15829
if (IID == 0)
@@ -15883,10 +15864,11 @@ CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
15883
15864
Value *Dst = EmitScalarExpr(E->getArg(0));
15884
15865
Address Src = EmitPointerWithAlignment(E->getArg(1));
15885
15866
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)
15888
15870
return nullptr;
15889
- bool isColMajor = isColMajorArg. getSExtValue();
15871
+ bool isColMajor = isColMajorArg-> getSExtValue();
15890
15872
NVPTXMmaLdstInfo II = getNVPTXMmaLdstInfo(BuiltinID);
15891
15873
unsigned IID = isColMajor ? II.IID_col : II.IID_row;
15892
15874
if (IID == 0)
@@ -15933,16 +15915,20 @@ CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
15933
15915
Address SrcA = EmitPointerWithAlignment(E->getArg(1));
15934
15916
Address SrcB = EmitPointerWithAlignment(E->getArg(2));
15935
15917
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)
15938
15921
return nullptr;
15939
- int Layout = LayoutArg. getSExtValue();
15922
+ int Layout = LayoutArg-> getSExtValue();
15940
15923
if (Layout < 0 || Layout > 3)
15941
15924
return nullptr;
15942
15925
llvm::APSInt SatfArg;
15943
15926
if (BuiltinID == NVPTX::BI__bmma_m8n8k128_mma_xor_popc_b1)
15944
15927
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
15946
15932
return nullptr;
15947
15933
bool Satf = SatfArg.getSExtValue();
15948
15934
NVPTXMmaInfo MI = getNVPTXMmaInfo(BuiltinID);
@@ -16271,9 +16257,8 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
16271
16257
case WebAssembly::BI__builtin_wasm_extract_lane_i64x2:
16272
16258
case WebAssembly::BI__builtin_wasm_extract_lane_f32x4:
16273
16259
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());
16277
16262
Value *Vec = EmitScalarExpr(E->getArg(0));
16278
16263
Value *Lane = llvm::ConstantInt::get(getLLVMContext(), LaneConst);
16279
16264
Value *Extract = Builder.CreateExtractElement(Vec, Lane);
@@ -16299,9 +16284,8 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
16299
16284
case WebAssembly::BI__builtin_wasm_replace_lane_i64x2:
16300
16285
case WebAssembly::BI__builtin_wasm_replace_lane_f32x4:
16301
16286
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());
16305
16289
Value *Vec = EmitScalarExpr(E->getArg(0));
16306
16290
Value *Lane = llvm::ConstantInt::get(getLLVMContext(), LaneConst);
16307
16291
Value *Val = EmitScalarExpr(E->getArg(2));
0 commit comments