Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1836)

Unified Diff: src/IceTargetLoweringARM32.cpp

Issue 1775253003: Cache common constants before lowering. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Clean up code. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/IceTargetLoweringARM32.cpp
diff --git a/src/IceTargetLoweringARM32.cpp b/src/IceTargetLoweringARM32.cpp
index e3f46eafd72cde5c683b64d37ca2bdf668ac3b0c..f2be2dde70fa5db09a8e1702a5f087fc58eac9d6 100644
--- a/src/IceTargetLoweringARM32.cpp
+++ b/src/IceTargetLoweringARM32.cpp
@@ -468,24 +468,24 @@ void TargetARM32::genTargetHelperCallFor(Inst *Instr) {
// Technically, ARM has its own aeabi routines, but we can use the
// non-aeabi routine as well. LLVM uses __aeabi_ldivmod for div, but uses
// the more standard __moddi3 for rem.
- Operand *TargetHelper = nullptr;
+ RuntimeHelperFuncKind HelperName = H_Num;
Jim Stichnoth 2016/03/10 00:24:46 Nit: it's more of a HelperID than a HelperName.
Karl 2016/03/16 22:50:52 Changed to HelperID.
switch (Op) {
default:
return;
case InstArithmetic::Udiv:
- TargetHelper = Ctx->getConstantExternSym(H_udiv_i64);
+ HelperName = H_udiv_i64;
break;
case InstArithmetic::Sdiv:
- TargetHelper = Ctx->getConstantExternSym(H_sdiv_i64);
+ HelperName = H_sdiv_i64;
break;
case InstArithmetic::Urem:
- TargetHelper = Ctx->getConstantExternSym(H_urem_i64);
+ HelperName = H_urem_i64;
break;
case InstArithmetic::Srem:
- TargetHelper = Ctx->getConstantExternSym(H_srem_i64);
+ HelperName = H_srem_i64;
break;
}
- assert(TargetHelper != nullptr);
+ Operand *TargetHelper = getRuntimeHelperFunc(HelperName);
ARM32HelpersPreamble[TargetHelper] = &TargetARM32::preambleDivRem;
constexpr SizeT MaxArgs = 2;
auto *Call = Context.insert<InstCall>(MaxArgs, Dest, TargetHelper,
@@ -500,33 +500,29 @@ void TargetARM32::genTargetHelperCallFor(Inst *Instr) {
case IceType_i8: {
const bool HasHWDiv = hasCPUFeature(TargetARM32Features::HWDivArm);
InstCast::OpKind CastKind;
- Operand *TargetHelper;
+ RuntimeHelperFuncKind HelperName = H_Num;
switch (Op) {
default:
return;
case InstArithmetic::Udiv:
- TargetHelper =
- HasHWDiv ? nullptr : Ctx->getConstantExternSym(H_udiv_i32);
+ HelperName = HasHWDiv ? H_Num : H_udiv_i32;
CastKind = InstCast::Zext;
break;
case InstArithmetic::Sdiv:
- TargetHelper =
- HasHWDiv ? nullptr : Ctx->getConstantExternSym(H_sdiv_i32);
+ HelperName = HasHWDiv ? H_Num : H_sdiv_i32;
CastKind = InstCast::Sext;
break;
case InstArithmetic::Urem:
- TargetHelper =
- HasHWDiv ? nullptr : Ctx->getConstantExternSym(H_urem_i32);
+ HelperName = HasHWDiv ? H_Num : H_urem_i32;
CastKind = InstCast::Zext;
break;
case InstArithmetic::Srem:
- TargetHelper =
- HasHWDiv ? nullptr : Ctx->getConstantExternSym(H_srem_i32);
+ HelperName = HasHWDiv ? H_Num : H_srem_i32;
CastKind = InstCast::Sext;
break;
}
- if (TargetHelper == nullptr) {
- // TargetHelper should only ever be nullptr when the processor does not
+ if (HelperName == H_Num) {
+ // HelperName should only ever be undefined when the processor does not
// have a hardware divider. If any other helpers are ever introduced,
// the following assert will have to be modified.
assert(HasHWDiv);
@@ -560,7 +556,7 @@ void TargetARM32::genTargetHelperCallFor(Inst *Instr) {
Src1 = Src1_32;
}
}
- assert(TargetHelper != nullptr);
+ Operand *TargetHelper = getRuntimeHelperFunc(HelperName);
ARM32HelpersPreamble[TargetHelper] = &TargetARM32::preambleDivRem;
constexpr SizeT MaxArgs = 2;
auto *Call = Context.insert<InstCall>(MaxArgs, Dest, TargetHelper,
@@ -578,8 +574,8 @@ void TargetARM32::genTargetHelperCallFor(Inst *Instr) {
return;
}
constexpr SizeT MaxArgs = 2;
- Operand *TargetHelper = Ctx->getConstantExternSym(
- DestTy == IceType_f32 ? H_frem_f32 : H_frem_f64);
+ Operand *TargetHelper =
+ getRuntimeHelperFunc(DestTy == IceType_f32 ? H_frem_f32 : H_frem_f64);
auto *Call = Context.insert<InstCall>(MaxArgs, Dest, TargetHelper,
NoTailCall, IsTargetHelperCall);
Call->addArg(Instr->getSrc(0));
@@ -619,7 +615,7 @@ void TargetARM32::genTargetHelperCallFor(Inst *Instr) {
}
const bool DestIsSigned = CastKind == InstCast::Fptosi;
const bool Src0IsF32 = isFloat32Asserting32Or64(SrcTy);
- Operand *TargetHelper = Ctx->getConstantExternSym(
+ Operand *TargetHelper = getRuntimeHelperFunc(
Src0IsF32 ? (DestIsSigned ? H_fptosi_f32_i64 : H_fptoui_f32_i64)
: (DestIsSigned ? H_fptosi_f64_i64 : H_fptoui_f64_i64));
static constexpr SizeT MaxArgs = 1;
@@ -636,7 +632,7 @@ void TargetARM32::genTargetHelperCallFor(Inst *Instr) {
}
const bool SourceIsSigned = CastKind == InstCast::Sitofp;
const bool DestIsF32 = isFloat32Asserting32Or64(Dest->getType());
- Operand *TargetHelper = Ctx->getConstantExternSym(
+ Operand *TargetHelper = getRuntimeHelperFunc(
DestIsF32 ? (SourceIsSigned ? H_sitofp_i64_f32 : H_uitofp_i64_f32)
: (SourceIsSigned ? H_sitofp_i64_f64 : H_uitofp_i64_f64));
static constexpr SizeT MaxArgs = 1;
@@ -651,7 +647,7 @@ void TargetARM32::genTargetHelperCallFor(Inst *Instr) {
return;
}
Variable *CallDest = Dest;
- const char *HelperName = nullptr;
+ RuntimeHelperFuncKind HelperName = H_Num;
switch (DestTy) {
default:
return;
@@ -682,7 +678,6 @@ void TargetARM32::genTargetHelperCallFor(Inst *Instr) {
Src0 = Src0AsI32;
} break;
}
- assert(HelperName != nullptr);
constexpr SizeT MaxSrcs = 1;
InstCall *Call = makeHelperCall(HelperName, CallDest, MaxSrcs);
Call->addArg(Src0);
@@ -706,7 +701,7 @@ void TargetARM32::genTargetHelperCallFor(Inst *Instr) {
return;
case Intrinsics::Ctpop: {
Operand *Src0 = IntrinsicCall->getArg(0);
- Operand *TargetHelper = Ctx->getConstantExternSym(
+ Operand *TargetHelper = getRuntimeHelperFunc(
isInt32Asserting32Or64(Src0->getType()) ? H_call_ctpop_i32
: H_call_ctpop_i64);
static constexpr SizeT MaxArgs = 1;
@@ -722,7 +717,7 @@ void TargetARM32::genTargetHelperCallFor(Inst *Instr) {
case Intrinsics::Longjmp: {
static constexpr SizeT MaxArgs = 2;
static constexpr Variable *NoDest = nullptr;
- Operand *TargetHelper = Ctx->getConstantExternSym(H_call_longjmp);
+ Operand *TargetHelper = getRuntimeHelperFunc(H_call_longjmp);
auto *Call = Context.insert<InstCall>(MaxArgs, NoDest, TargetHelper,
NoTailCall, IsTargetHelperCall);
Call->addArg(IntrinsicCall->getArg(0));
@@ -735,7 +730,7 @@ void TargetARM32::genTargetHelperCallFor(Inst *Instr) {
// for intrinsic calls w/ a known length.
static constexpr SizeT MaxArgs = 3;
static constexpr Variable *NoDest = nullptr;
- Operand *TargetHelper = Ctx->getConstantExternSym(H_call_memcpy);
+ Operand *TargetHelper = getRuntimeHelperFunc(H_call_memcpy);
auto *Call = Context.insert<InstCall>(MaxArgs, NoDest, TargetHelper,
NoTailCall, IsTargetHelperCall);
Call->addArg(IntrinsicCall->getArg(0));
@@ -747,7 +742,7 @@ void TargetARM32::genTargetHelperCallFor(Inst *Instr) {
case Intrinsics::Memmove: {
static constexpr SizeT MaxArgs = 3;
static constexpr Variable *NoDest = nullptr;
- Operand *TargetHelper = Ctx->getConstantExternSym(H_call_memmove);
+ Operand *TargetHelper = getRuntimeHelperFunc(H_call_memmove);
auto *Call = Context.insert<InstCall>(MaxArgs, NoDest, TargetHelper,
NoTailCall, IsTargetHelperCall);
Call->addArg(IntrinsicCall->getArg(0));
@@ -769,7 +764,7 @@ void TargetARM32::genTargetHelperCallFor(Inst *Instr) {
// decide to use __aeabi_memset.
static constexpr SizeT MaxArgs = 3;
static constexpr Variable *NoDest = nullptr;
- Operand *TargetHelper = Ctx->getConstantExternSym(H_call_memset);
+ Operand *TargetHelper = getRuntimeHelperFunc(H_call_memset);
auto *Call = Context.insert<InstCall>(MaxArgs, NoDest, TargetHelper,
NoTailCall, IsTargetHelperCall);
Call->addArg(IntrinsicCall->getArg(0));
@@ -783,9 +778,9 @@ void TargetARM32::genTargetHelperCallFor(Inst *Instr) {
return;
}
static constexpr SizeT MaxArgs = 0;
- const char *ReadTP =
- SandboxingType == ST_Nonsfi ? "__aeabi_read_tp" : H_call_read_tp;
- Operand *TargetHelper = Ctx->getConstantExternSym(ReadTP);
+ Operand *TargetHelper = SandboxingType == ST_Nonsfi
+ ? Ctx->getConstantExternSym("__aeabi_read_tp")
+ : getRuntimeHelperFunc(H_call_read_tp);
Context.insert<InstCall>(MaxArgs, Dest, TargetHelper, NoTailCall,
IsTargetHelperCall);
Instr->setDeleted();
@@ -793,7 +788,7 @@ void TargetARM32::genTargetHelperCallFor(Inst *Instr) {
}
case Intrinsics::Setjmp: {
static constexpr SizeT MaxArgs = 1;
- Operand *TargetHelper = Ctx->getConstantExternSym(H_call_setjmp);
+ Operand *TargetHelper = getRuntimeHelperFunc(H_call_setjmp);
auto *Call = Context.insert<InstCall>(MaxArgs, Dest, TargetHelper,
NoTailCall, IsTargetHelperCall);
Call->addArg(IntrinsicCall->getArg(0));
@@ -2719,7 +2714,7 @@ void TargetARM32::lowerInt64Arithmetic(InstArithmetic::OpKind Op,
}
Operand *_0 =
- legalize(Ctx->getConstantZero(IceType_i32), Legal_Reg | Legal_Flex);
+ legalize(getConstantZero(IceType_i32), Legal_Reg | Legal_Flex);
_mov(T_Lo, _0);
_mov(DestLo, T_Lo);
return;
@@ -2772,7 +2767,7 @@ void TargetARM32::lowerInt64Arithmetic(InstArithmetic::OpKind Op,
// saturate to the range 0-32, so the negative value will saturate to 32.
Operand *_32 = legalize(Ctx->getConstantInt32(32), Legal_Reg | Legal_Flex);
Operand *_0 =
- legalize(Ctx->getConstantZero(IceType_i32), Legal_Reg | Legal_Flex);
+ legalize(getConstantZero(IceType_i32), Legal_Reg | Legal_Flex);
Variable *T0 = makeReg(IceType_i32);
Variable *T1 = makeReg(IceType_i32);
Variable *T2 = makeReg(IceType_i32);
@@ -2824,8 +2819,8 @@ void TargetARM32::lowerInt64Arithmetic(InstArithmetic::OpKind Op,
Operand *_31 = shAmtImm(31);
_asr(T_Hi, Src0RHi, _31);
} else {
- Operand *_0 = legalize(Ctx->getConstantZero(IceType_i32),
- Legal_Reg | Legal_Flex);
+ Operand *_0 =
+ legalize(getConstantZero(IceType_i32), Legal_Reg | Legal_Flex);
_mov(T_Hi, _0);
}
_mov(DestHi, T_Hi);
@@ -2878,7 +2873,7 @@ void TargetARM32::lowerInt64Arithmetic(InstArithmetic::OpKind Op,
// These are incompatible, therefore we mimic pnacl-llc.
Operand *_32 = legalize(Ctx->getConstantInt32(32), Legal_Reg | Legal_Flex);
Operand *_0 =
- legalize(Ctx->getConstantZero(IceType_i32), Legal_Reg | Legal_Flex);
+ legalize(getConstantZero(IceType_i32), Legal_Reg | Legal_Flex);
Variable *T0 = makeReg(IceType_i32);
Variable *T1 = makeReg(IceType_i32);
Variable *T2 = makeReg(IceType_i32);
@@ -3344,8 +3339,7 @@ void TargetARM32::lowerArithmetic(const InstArithmetic *Instr) {
int32_t Const = Srcs.getConstantValue();
const bool Invert = Const < 0;
const bool MultiplyByZero = Const == 0;
- Operand *_0 =
- legalize(Ctx->getConstantZero(DestTy), Legal_Reg | Legal_Flex);
+ Operand *_0 = legalize(getConstantZero(DestTy), Legal_Reg | Legal_Flex);
if (MultiplyByZero) {
_mov(T, _0);
@@ -3865,7 +3859,7 @@ void TargetARM32::lowerCast(const InstCast *Instr) {
Variable *Src0R = legalizeToReg(Src0);
_sxt(T_Lo, Src0R);
} else {
- Operand *_0 = Ctx->getConstantZero(IceType_i32);
+ Operand *_0 = getConstantZero(IceType_i32);
Operand *_m1 = Ctx->getConstantInt32(-1);
lowerInt1ForSelect(T_Lo, Src0, _m1, _0);
}
@@ -3886,7 +3880,7 @@ void TargetARM32::lowerCast(const InstCast *Instr) {
_sxt(T, Src0R);
_mov(Dest, T);
} else {
- Constant *_0 = Ctx->getConstantZero(IceType_i32);
+ Constant *_0 = getConstantZero(IceType_i32);
Operand *_m1 = Ctx->getConstantInt(Dest->getType(), -1);
Variable *T = makeReg(Dest->getType());
lowerInt1ForSelect(T, Src0, _m1, _0);
@@ -3900,7 +3894,7 @@ void TargetARM32::lowerCast(const InstCast *Instr) {
} else if (Dest->getType() == IceType_i64) {
// t1=uxtb src; dst.lo=t1; dst.hi=0
Operand *_0 =
- legalize(Ctx->getConstantZero(IceType_i32), Legal_Reg | Legal_Flex);
+ legalize(getConstantZero(IceType_i32), Legal_Reg | Legal_Flex);
auto *DestLo = llvm::cast<Variable>(loOperand(Dest));
auto *DestHi = llvm::cast<Variable>(hiOperand(Dest));
Variable *T_Lo = makeReg(DestLo->getType());
@@ -4253,8 +4247,7 @@ void TargetARM32::lowerFcmp(const InstFcmp *Instr) {
Variable *T = makeReg(IceType_i1);
Operand *_1 = legalize(Ctx->getConstantInt32(1), Legal_Reg | Legal_Flex);
- Operand *_0 =
- legalize(Ctx->getConstantZero(IceType_i32), Legal_Reg | Legal_Flex);
+ Operand *_0 = legalize(getConstantZero(IceType_i32), Legal_Reg | Legal_Flex);
CondWhenTrue Cond = lowerFcmpCond(Instr);
@@ -4551,8 +4544,7 @@ void TargetARM32::lowerIcmp(const InstIcmp *Instr) {
return;
}
- Operand *_0 =
- legalize(Ctx->getConstantZero(IceType_i32), Legal_Reg | Legal_Flex);
+ Operand *_0 = legalize(getConstantZero(IceType_i32), Legal_Reg | Legal_Flex);
Operand *_1 = legalize(Ctx->getConstantInt32(1), Legal_Reg | Legal_Flex);
Variable *T = makeReg(IceType_i1);
@@ -4608,7 +4600,7 @@ void TargetARM32::lowerLoadLinkedStoreExclusive(
{ // scoping for loop highlighting.
Variable *Success = makeReg(IceType_i32);
Variable *Tmp = (Ty == IceType_i64) ? makeI64RegPair() : makeReg(Ty);
- auto *_0 = Ctx->getConstantZero(IceType_i32);
+ auto *_0 = getConstantZero(IceType_i32);
Context.insert<InstFakeDef>(Tmp);
Context.insert<InstFakeUse>(Tmp);
@@ -4773,8 +4765,7 @@ void TargetARM32::postambleCtpop64(const InstCall *Instr) {
// user doesn't do that in the IR or doesn't toss the bits via truncate.
auto *DestHi = llvm::cast<Variable>(hiOperand(Instr->getDest()));
Variable *T = makeReg(IceType_i32);
- Operand *_0 =
- legalize(Ctx->getConstantZero(IceType_i32), Legal_Reg | Legal_Flex);
+ Operand *_0 = legalize(getConstantZero(IceType_i32), Legal_Reg | Legal_Flex);
_mov(T, _0);
_mov(DestHi, T);
}
@@ -5064,7 +5055,7 @@ void TargetARM32::lowerIntrinsicCall(const InstIntrinsicCall *Instr) {
}
Variable *TP = legalizeToReg(OperandARM32Mem::create(
Func, getPointerType(), getPhysicalRegister(RegARM32::Reg_r9),
- llvm::cast<ConstantInteger32>(Ctx->getConstantZero(IceType_i32))));
+ llvm::cast<ConstantInteger32>(getConstantZero(IceType_i32))));
_mov(Dest, TP);
return;
}
@@ -5107,7 +5098,7 @@ void TargetARM32::lowerCLZ(Variable *Dest, Variable *ValLoR, Variable *ValHiR) {
auto *DestLo = llvm::cast<Variable>(loOperand(Dest));
auto *DestHi = llvm::cast<Variable>(hiOperand(Dest));
Operand *Zero =
- legalize(Ctx->getConstantZero(IceType_i32), Legal_Reg | Legal_Flex);
+ legalize(getConstantZero(IceType_i32), Legal_Reg | Legal_Flex);
Operand *ThirtyTwo =
legalize(Ctx->getConstantInt32(32), Legal_Reg | Legal_Flex);
_cmp(ValHiR, Zero);
@@ -6051,7 +6042,7 @@ Operand *TargetARM32::legalizeUndef(Operand *From, RegNumT RegNum) {
// lo and hi components will need to go in uninitialized registers.
if (isVectorType(Ty))
return makeVectorOfZeros(Ty, RegNum);
- return Ctx->getConstantZero(Ty);
+ return getConstantZero(Ty);
}
return From;
}
@@ -6071,7 +6062,7 @@ OperandARM32Mem *TargetARM32::formMemoryOperand(Operand *Operand, Type Ty) {
legalize(Operand, Legal_Reg | Legal_Rematerializable));
return OperandARM32Mem::create(
Func, Ty, Base,
- llvm::cast<ConstantInteger32>(Ctx->getConstantZero(IceType_i32)));
+ llvm::cast<ConstantInteger32>(getConstantZero(IceType_i32)));
}
Variable64On32 *TargetARM32::makeI64RegPair() {
@@ -6294,8 +6285,7 @@ TargetARM32::SafeBoolChain TargetARM32::lowerInt1(Variable *Dest,
Operand *Boolean) {
assert(Boolean->getType() == IceType_i1);
Variable *T = makeReg(IceType_i1);
- Operand *_0 =
- legalize(Ctx->getConstantZero(IceType_i1), Legal_Reg | Legal_Flex);
+ Operand *_0 = legalize(getConstantZero(IceType_i1), Legal_Reg | Legal_Flex);
Operand *_1 = legalize(Ctx->getConstantInt1(1), Legal_Reg | Legal_Flex);
SafeBoolChain Safe = SBC_Yes;

Powered by Google App Engine
This is Rietveld 408576698