37#include "llvm/IR/IntrinsicsWebAssembly.h"
42#define DEBUG_TYPE "wasm-fastisel"
46class WebAssemblyFastISel final :
public FastISel {
50 enum BaseKind { RegBase, FrameIndexBase };
53 BaseKind Kind = RegBase;
60 bool IsBaseSet =
false;
69 void setKind(BaseKind
K) {
70 assert(!isSet() &&
"Can't change kind with non-zero base");
73 BaseKind getKind()
const {
return Kind; }
74 bool isRegBase()
const {
return Kind == RegBase; }
75 bool isFIBase()
const {
return Kind == FrameIndexBase; }
76 void setReg(
unsigned Reg) {
77 assert(isRegBase() &&
"Invalid base register access!");
78 assert(!IsBaseSet &&
"Base cannot be reset");
83 assert(isRegBase() &&
"Invalid base register access!");
86 void setFI(
unsigned FI) {
87 assert(isFIBase() &&
"Invalid base frame index access!");
88 assert(!IsBaseSet &&
"Base cannot be reset");
92 unsigned getFI()
const {
93 assert(isFIBase() &&
"Invalid base frame index access!");
97 void setOffset(int64_t NewOffset) {
98 assert(NewOffset >= 0 &&
"Offsets must be non-negative");
103 const GlobalValue *getGlobalValue()
const {
return GV; }
104 bool isSet()
const {
return IsBaseSet; }
114 EVT VT =
TLI.getValueType(
DL, Ty,
true);
154 bool computeAddress(
const Value *Obj, Address &Addr);
155 void materializeLoadStoreOperands(Address &Addr);
159 unsigned maskI1Value(
unsigned Reg,
const Value *
V);
161 unsigned zeroExtendToI32(
unsigned Reg,
const Value *
V,
163 unsigned signExtendToI32(
unsigned Reg,
const Value *
V,
169 unsigned getRegForUnsignedValue(
const Value *
V);
170 unsigned getRegForSignedValue(
const Value *
V);
171 unsigned getRegForPromotedValue(
const Value *
V,
bool IsSigned);
172 unsigned notValue(
unsigned Reg);
173 unsigned copyValue(
unsigned Reg);
178 bool fastLowerArguments()
override;
200 :
FastISel(FuncInfo, LibInfo, LibcallLowering,
205 bool fastSelectInstruction(
const Instruction *
I)
override;
209#include "WebAssemblyGenFastISel.inc"
214bool WebAssemblyFastISel::computeAddress(
const Value *Obj, Address &Addr) {
215 const User *
U =
nullptr;
216 unsigned Opcode = Instruction::UserOp1;
220 if (FuncInfo.StaticAllocaMap.count(
static_cast<const AllocaInst *
>(Obj)) ||
221 FuncInfo.getMBB(
I->getParent()) == FuncInfo.MBB) {
222 Opcode =
I->getOpcode();
226 Opcode =
C->getOpcode();
231 if (Ty->getAddressSpace() > 255)
239 if (Addr.getGlobalValue())
241 if (GV->isThreadLocal())
243 Addr.setGlobalValue(GV);
250 case Instruction::BitCast: {
252 return computeAddress(
U->getOperand(0), Addr);
254 case Instruction::IntToPtr: {
258 return computeAddress(
U->getOperand(0), Addr);
261 case Instruction::PtrToInt: {
264 return computeAddress(
U->getOperand(0), Addr);
267 case Instruction::GetElementPtr: {
269 uint64_t TmpOffset = Addr.getOffset();
272 goto unsupported_gep;
277 const Value *
Op = GTI.getOperand();
278 if (StructType *STy = GTI.getStructTypeOrNull()) {
279 const StructLayout *SL =
DL.getStructLayout(STy);
283 uint64_t S = GTI.getSequentialElementStride(
DL);
287 TmpOffset += CI->getSExtValue() * S;
290 if (S == 1 && Addr.isRegBase() && Addr.getReg() == 0) {
298 if (canFoldAddIntoGEP(U,
Op)) {
301 TmpOffset += CI->getSExtValue() * S;
307 goto unsupported_gep;
312 if (int64_t(TmpOffset) >= 0) {
314 Addr.setOffset(TmpOffset);
315 if (computeAddress(
U->getOperand(0), Addr))
323 case Instruction::Alloca: {
325 auto SI = FuncInfo.StaticAllocaMap.find(AI);
326 if (SI != FuncInfo.StaticAllocaMap.end()) {
330 Addr.setKind(Address::FrameIndexBase);
331 Addr.setFI(
SI->second);
336 case Instruction::Add: {
340 if (!OFBinOp->hasNoUnsignedWrap())
351 uint64_t TmpOffset = Addr.getOffset() + CI->getSExtValue();
352 if (int64_t(TmpOffset) >= 0) {
353 Addr.setOffset(TmpOffset);
354 return computeAddress(
LHS, Addr);
359 if (computeAddress(
LHS, Addr) && computeAddress(
RHS, Addr))
365 case Instruction::Sub: {
369 if (!OFBinOp->hasNoUnsignedWrap())
377 int64_t TmpOffset = Addr.getOffset() - CI->getSExtValue();
378 if (TmpOffset >= 0) {
379 Addr.setOffset(TmpOffset);
380 return computeAddress(
LHS, Addr);
393 return Addr.getReg() != 0;
396void WebAssemblyFastISel::materializeLoadStoreOperands(
Address &Addr) {
397 if (Addr.isRegBase()) {
398 unsigned Reg = Addr.getReg();
400 Reg = createResultReg(
Subtarget->hasAddr64() ? &WebAssembly::I64RegClass
401 : &WebAssembly::I32RegClass);
402 unsigned Opc =
Subtarget->hasAddr64() ? WebAssembly::CONST_I64
403 : WebAssembly::CONST_I32;
411void WebAssemblyFastISel::addLoadStoreOperands(
const Address &Addr,
412 const MachineInstrBuilder &MIB,
413 MachineMemOperand *MMO) {
418 if (
const GlobalValue *GV = Addr.getGlobalValue())
421 MIB.
addImm(Addr.getOffset());
423 if (Addr.isRegBase())
424 MIB.
addReg(Addr.getReg());
431bool WebAssemblyFastISel::emitLoad(
Register ResultReg,
unsigned Opc,
432 const LoadInst *
Load) {
434 if (!computeAddress(
Load->getPointerOperand(), Addr))
437 materializeLoadStoreOperands(Addr);
439 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
TII.get(
Opc), ResultReg);
440 addLoadStoreOperands(Addr, MIB, createMachineMemOperandFor(
Load));
445unsigned WebAssemblyFastISel::maskI1Value(
unsigned Reg,
const Value *
V) {
446 return zeroExtendToI32(
Reg,
V, MVT::i1);
449unsigned WebAssemblyFastISel::getRegForI1Value(
const Value *
V,
450 const BasicBlock *BB,
454 if (ICmp->isEquality() &&
C->isZero() &&
C->getType()->isIntegerTy(32) &&
455 ICmp->getParent() == BB) {
456 Not = ICmp->isTrueWhenEqual();
457 return getRegForValue(ICmp->getOperand(0));
464 return maskI1Value(
Reg,
V);
467unsigned WebAssemblyFastISel::zeroExtendToI32(
unsigned Reg,
const Value *
V,
478 return copyValue(
Reg);
484 return copyValue(
Reg);
489 Register Imm = createResultReg(&WebAssembly::I32RegClass);
490 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
491 TII.get(WebAssembly::CONST_I32),
Imm)
495 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
TII.get(WebAssembly::AND_I32),
503unsigned WebAssemblyFastISel::signExtendToI32(
unsigned Reg,
const Value *
V,
514 return copyValue(
Reg);
520 if (From == MVT::i8 || From == MVT::i16) {
522 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
523 TII.get(From == MVT::i16 ? WebAssembly::I32_EXTEND16_S_I32
524 : WebAssembly::I32_EXTEND8_S_I32),
531 Register Imm = createResultReg(&WebAssembly::I32RegClass);
532 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
533 TII.get(WebAssembly::CONST_I32),
Imm)
534 .
addImm(32 - MVT(From).getSizeInBits());
536 Register Left = createResultReg(&WebAssembly::I32RegClass);
537 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
TII.get(WebAssembly::SHL_I32),
543 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
544 TII.get(WebAssembly::SHR_S_I32),
Right)
551unsigned WebAssemblyFastISel::zeroExtend(
unsigned Reg,
const Value *
V,
554 if (To == MVT::i64) {
555 if (From == MVT::i64)
556 return copyValue(
Reg);
558 Reg = zeroExtendToI32(
Reg,
V, From);
561 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
562 TII.get(WebAssembly::I64_EXTEND_U_I32), Result)
568 return zeroExtendToI32(
Reg,
V, From);
573unsigned WebAssemblyFastISel::signExtend(
unsigned Reg,
const Value *
V,
576 if (To == MVT::i64) {
577 if (From == MVT::i64)
578 return copyValue(
Reg);
586 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
587 TII.get(WebAssembly::I64_EXTEND_U_I32), Result)
591 Result = createResultReg(&WebAssembly::I64RegClass);
593 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
594 TII.get(From == MVT::i8 ? WebAssembly::I64_EXTEND8_S_I64
595 : WebAssembly::I64_EXTEND16_S_I64),
601 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
602 TII.get(WebAssembly::I64_EXTEND_S_I32), Result)
610 Reg = signExtendToI32(
Reg,
V, From);
614 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
615 TII.get(WebAssembly::I64_EXTEND_S_I32), Result)
621 return signExtendToI32(
Reg,
V, From);
626unsigned WebAssemblyFastISel::getRegForUnsignedValue(
const Value *
V) {
634 return zeroExtend(VReg,
V, From, To);
637unsigned WebAssemblyFastISel::getRegForSignedValue(
const Value *
V) {
645 return signExtend(VReg,
V, From, To);
648unsigned WebAssemblyFastISel::getRegForPromotedValue(
const Value *
V,
650 return IsSigned ? getRegForSignedValue(
V) : getRegForUnsignedValue(
V);
653unsigned WebAssemblyFastISel::notValue(
unsigned Reg) {
656 Register NotReg = createResultReg(&WebAssembly::I32RegClass);
657 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
TII.get(WebAssembly::EQZ_I32),
663unsigned WebAssemblyFastISel::copyValue(
unsigned Reg) {
665 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
TII.get(WebAssembly::COPY),
671Register WebAssemblyFastISel::fastMaterializeAlloca(
const AllocaInst *AI) {
672 auto SI = FuncInfo.StaticAllocaMap.find(AI);
674 if (SI != FuncInfo.StaticAllocaMap.end()) {
676 createResultReg(
Subtarget->hasAddr64() ? &WebAssembly::I64RegClass
677 : &WebAssembly::I32RegClass);
679 Subtarget->hasAddr64() ? WebAssembly::COPY_I64 : WebAssembly::COPY_I32;
680 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
TII.get(
Opc), ResultReg)
688Register WebAssemblyFastISel::fastMaterializeConstant(
const Constant *
C) {
692 if (GV->isThreadLocal())
695 createResultReg(
Subtarget->hasAddr64() ? &WebAssembly::I64RegClass
696 : &WebAssembly::I32RegClass);
697 unsigned Opc =
Subtarget->hasAddr64() ? WebAssembly::CONST_I64
698 : WebAssembly::CONST_I32;
699 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
TII.get(
Opc), ResultReg)
708bool WebAssemblyFastISel::fastLowerArguments() {
709 if (!FuncInfo.CanLowerReturn)
716 if (FuncInfo.Fn->getCallingConv() == CallingConv::Swift ||
717 FuncInfo.Fn->getCallingConv() == CallingConv::SwiftTail)
721 for (
auto const &Arg :
F->args()) {
722 const AttributeList &
Attrs =
F->getAttributes();
723 if (
Attrs.hasParamAttr(
I, Attribute::ByVal) ||
724 Attrs.hasParamAttr(
I, Attribute::SwiftSelf) ||
725 Attrs.hasParamAttr(
I, Attribute::SwiftError) ||
726 Attrs.hasParamAttr(
I, Attribute::SwiftAsync) ||
727 Attrs.hasParamAttr(
I, Attribute::InAlloca) ||
728 Attrs.hasParamAttr(
I, Attribute::Nest))
731 Type *ArgTy = Arg.getType();
739 switch (getSimpleType(ArgTy)) {
744 Opc = WebAssembly::ARGUMENT_i32;
745 RC = &WebAssembly::I32RegClass;
748 Opc = WebAssembly::ARGUMENT_i64;
749 RC = &WebAssembly::I64RegClass;
752 Opc = WebAssembly::ARGUMENT_f32;
753 RC = &WebAssembly::F32RegClass;
756 Opc = WebAssembly::ARGUMENT_f64;
757 RC = &WebAssembly::F64RegClass;
760 Opc = WebAssembly::ARGUMENT_v16i8;
761 RC = &WebAssembly::V128RegClass;
764 Opc = WebAssembly::ARGUMENT_v8i16;
765 RC = &WebAssembly::V128RegClass;
768 Opc = WebAssembly::ARGUMENT_v4i32;
769 RC = &WebAssembly::V128RegClass;
772 Opc = WebAssembly::ARGUMENT_v2i64;
773 RC = &WebAssembly::V128RegClass;
776 Opc = WebAssembly::ARGUMENT_v4f32;
777 RC = &WebAssembly::V128RegClass;
780 Opc = WebAssembly::ARGUMENT_v2f64;
781 RC = &WebAssembly::V128RegClass;
784 Opc = WebAssembly::ARGUMENT_funcref;
785 RC = &WebAssembly::FUNCREFRegClass;
788 Opc = WebAssembly::ARGUMENT_externref;
789 RC = &WebAssembly::EXTERNREFRegClass;
792 Opc = WebAssembly::ARGUMENT_exnref;
793 RC = &WebAssembly::EXNREFRegClass;
798 Register ResultReg = createResultReg(RC);
799 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
TII.get(
Opc), ResultReg)
801 updateValueMap(&Arg, ResultReg);
808 auto *MFI = MF->getInfo<WebAssemblyFunctionInfo>();
809 for (
auto const &Arg :
F->args()) {
812 MFI->clearParamsAndResults();
815 MFI->addParam(ArgTy);
818 if (!
F->getReturnType()->isVoidTy()) {
820 getLegalType(getSimpleType(
F->getReturnType()));
822 MFI->clearParamsAndResults();
825 MFI->addResult(RetTy);
831bool WebAssemblyFastISel::selectCall(
const Instruction *
I) {
840 if (Func &&
Func->isIntrinsic())
847 bool IsDirect =
Func !=
nullptr;
852 unsigned Opc = IsDirect ? WebAssembly::CALL : WebAssembly::CALL_INDIRECT;
853 bool IsVoid = FuncTy->getReturnType()->isVoidTy();
865 ResultReg = createResultReg(&WebAssembly::I32RegClass);
868 ResultReg = createResultReg(&WebAssembly::I64RegClass);
871 ResultReg = createResultReg(&WebAssembly::F32RegClass);
874 ResultReg = createResultReg(&WebAssembly::F64RegClass);
877 ResultReg = createResultReg(&WebAssembly::V128RegClass);
880 ResultReg = createResultReg(&WebAssembly::V128RegClass);
883 ResultReg = createResultReg(&WebAssembly::V128RegClass);
886 ResultReg = createResultReg(&WebAssembly::V128RegClass);
889 ResultReg = createResultReg(&WebAssembly::V128RegClass);
892 ResultReg = createResultReg(&WebAssembly::V128RegClass);
895 ResultReg = createResultReg(&WebAssembly::FUNCREFRegClass);
898 ResultReg = createResultReg(&WebAssembly::EXTERNREFRegClass);
901 ResultReg = createResultReg(&WebAssembly::EXNREFRegClass);
908 SmallVector<unsigned, 8>
Args;
917 if (
Attrs.hasParamAttr(
I, Attribute::ByVal) ||
918 Attrs.hasParamAttr(
I, Attribute::SwiftSelf) ||
919 Attrs.hasParamAttr(
I, Attribute::SwiftError) ||
921 Attrs.hasParamAttr(
I, Attribute::InAlloca) ||
922 Attrs.hasParamAttr(
I, Attribute::Nest))
928 Reg = getRegForSignedValue(
V);
930 Reg = getRegForUnsignedValue(
V);
932 Reg = getRegForValue(
V);
940 unsigned CalleeReg = 0;
947 const Value *FuncrefArg =
nullptr;
949 if (Conv->getIntrinsicID() == Intrinsic::wasm_funcref_to_ptr)
950 FuncrefArg = Conv->getArgOperand(0);
952 const bool IsFuncrefCall = FuncrefArg !=
nullptr;
953 MCSymbolWasm *
Table =
nullptr;
956 if (!IsFuncrefCall) {
958 Table = WebAssembly::getOrCreateFunctionTableSymbol(MF->getContext(),
965 Table = WebAssembly::getOrCreateFuncrefCallTableSymbol(MF->getContext(),
967 CalleeReg = getRegForValue(FuncrefArg);
969 unsigned ZeroReg = createResultReg(&WebAssembly::I32RegClass);
970 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
971 TII.get(WebAssembly::CONST_I32), ZeroReg)
973 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
974 TII.get(WebAssembly::TABLE_SET_FUNCREF))
979 CalleeReg = createResultReg(&WebAssembly::I32RegClass);
980 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
981 TII.get(WebAssembly::CONST_I32), CalleeReg)
986 auto MIB =
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
TII.get(
Opc));
989 MIB.
addReg(ResultReg, RegState::Define);
996 if (
Subtarget->hasCallIndirectOverlong()) {
1002 Table->setNoStrip();
1007 for (
unsigned ArgReg : Args)
1013 if (IsFuncrefCall) {
1015 unsigned ZeroReg = createResultReg(&WebAssembly::I32RegClass);
1016 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
1017 TII.get(WebAssembly::CONST_I32), ZeroReg)
1019 unsigned NullReg = createResultReg(&WebAssembly::FUNCREFRegClass);
1020 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
1021 TII.get(WebAssembly::REF_NULL_FUNCREF), NullReg);
1022 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
1023 TII.get(WebAssembly::TABLE_SET_FUNCREF))
1030 updateValueMap(
Call, ResultReg);
1036bool WebAssemblyFastISel::selectSelect(
const Instruction *
I) {
1041 getRegForI1Value(
Select->getCondition(),
I->getParent(), Not);
1058 switch (getSimpleType(
Select->getType())) {
1063 Opc = WebAssembly::SELECT_I32;
1064 RC = &WebAssembly::I32RegClass;
1067 Opc = WebAssembly::SELECT_I64;
1068 RC = &WebAssembly::I64RegClass;
1071 Opc = WebAssembly::SELECT_F32;
1072 RC = &WebAssembly::F32RegClass;
1075 Opc = WebAssembly::SELECT_F64;
1076 RC = &WebAssembly::F64RegClass;
1079 Opc = WebAssembly::SELECT_FUNCREF;
1080 RC = &WebAssembly::FUNCREFRegClass;
1082 case MVT::externref:
1083 Opc = WebAssembly::SELECT_EXTERNREF;
1084 RC = &WebAssembly::EXTERNREFRegClass;
1087 Opc = WebAssembly::SELECT_EXNREF;
1088 RC = &WebAssembly::EXNREFRegClass;
1094 Register ResultReg = createResultReg(RC);
1095 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
TII.get(
Opc), ResultReg)
1100 updateValueMap(
Select, ResultReg);
1104bool WebAssemblyFastISel::selectTrunc(
const Instruction *
I) {
1115 if (From == MVT::i64) {
1117 return copyValue(
Reg);
1119 if (To == MVT::i1 || To == MVT::i8 || To == MVT::i16 || To == MVT::i32) {
1121 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
1122 TII.get(WebAssembly::I32_WRAP_I64), Result)
1128 if (From == MVT::i32)
1129 return copyValue(
Reg);
1134 unsigned Reg = Truncate(In);
1142bool WebAssemblyFastISel::selectZExt(
const Instruction *
I) {
1145 const Value *
Op = ZExt->getOperand(0);
1151 unsigned Reg = zeroExtend(In,
Op, From, To);
1155 updateValueMap(ZExt,
Reg);
1159bool WebAssemblyFastISel::selectSExt(
const Instruction *
I) {
1162 const Value *
Op = SExt->getOperand(0);
1168 unsigned Reg = signExtend(In,
Op, From, To);
1172 updateValueMap(SExt,
Reg);
1176bool WebAssemblyFastISel::selectICmp(
const Instruction *
I) {
1183 if (ICmp->getOperand(0)->getType()->isVectorTy())
1186 bool I32 = getSimpleType(ICmp->getOperand(0)->getType()) != MVT::i64;
1188 bool IsSigned =
false;
1189 switch (ICmp->getPredicate()) {
1190 case ICmpInst::ICMP_EQ:
1191 Opc =
I32 ? WebAssembly::EQ_I32 : WebAssembly::EQ_I64;
1193 case ICmpInst::ICMP_NE:
1194 Opc =
I32 ? WebAssembly::NE_I32 : WebAssembly::NE_I64;
1196 case ICmpInst::ICMP_UGT:
1197 Opc =
I32 ? WebAssembly::GT_U_I32 : WebAssembly::GT_U_I64;
1199 case ICmpInst::ICMP_UGE:
1200 Opc =
I32 ? WebAssembly::GE_U_I32 : WebAssembly::GE_U_I64;
1202 case ICmpInst::ICMP_ULT:
1203 Opc =
I32 ? WebAssembly::LT_U_I32 : WebAssembly::LT_U_I64;
1205 case ICmpInst::ICMP_ULE:
1206 Opc =
I32 ? WebAssembly::LE_U_I32 : WebAssembly::LE_U_I64;
1208 case ICmpInst::ICMP_SGT:
1209 Opc =
I32 ? WebAssembly::GT_S_I32 : WebAssembly::GT_S_I64;
1212 case ICmpInst::ICMP_SGE:
1213 Opc =
I32 ? WebAssembly::GE_S_I32 : WebAssembly::GE_S_I64;
1216 case ICmpInst::ICMP_SLT:
1217 Opc =
I32 ? WebAssembly::LT_S_I32 : WebAssembly::LT_S_I64;
1220 case ICmpInst::ICMP_SLE:
1221 Opc =
I32 ? WebAssembly::LE_S_I32 : WebAssembly::LE_S_I64;
1228 unsigned LHS = getRegForPromotedValue(ICmp->getOperand(0), IsSigned);
1232 unsigned RHS = getRegForPromotedValue(ICmp->getOperand(1), IsSigned);
1236 Register ResultReg = createResultReg(&WebAssembly::I32RegClass);
1237 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
TII.get(
Opc), ResultReg)
1240 updateValueMap(ICmp, ResultReg);
1244bool WebAssemblyFastISel::selectFCmp(
const Instruction *
I) {
1251 if (FCmp->getOperand(0)->getType()->isVectorTy())
1254 Register LHS = getRegForValue(FCmp->getOperand(0));
1258 Register RHS = getRegForValue(FCmp->getOperand(1));
1262 bool F32 = getSimpleType(FCmp->getOperand(0)->getType()) != MVT::f64;
1265 switch (FCmp->getPredicate()) {
1266 case FCmpInst::FCMP_OEQ:
1267 Opc =
F32 ? WebAssembly::EQ_F32 : WebAssembly::EQ_F64;
1269 case FCmpInst::FCMP_UNE:
1270 Opc =
F32 ? WebAssembly::NE_F32 : WebAssembly::NE_F64;
1272 case FCmpInst::FCMP_OGT:
1273 Opc =
F32 ? WebAssembly::GT_F32 : WebAssembly::GT_F64;
1275 case FCmpInst::FCMP_OGE:
1276 Opc =
F32 ? WebAssembly::GE_F32 : WebAssembly::GE_F64;
1278 case FCmpInst::FCMP_OLT:
1279 Opc =
F32 ? WebAssembly::LT_F32 : WebAssembly::LT_F64;
1281 case FCmpInst::FCMP_OLE:
1282 Opc =
F32 ? WebAssembly::LE_F32 : WebAssembly::LE_F64;
1284 case FCmpInst::FCMP_UGT:
1285 Opc =
F32 ? WebAssembly::LE_F32 : WebAssembly::LE_F64;
1288 case FCmpInst::FCMP_UGE:
1289 Opc =
F32 ? WebAssembly::LT_F32 : WebAssembly::LT_F64;
1292 case FCmpInst::FCMP_ULT:
1293 Opc =
F32 ? WebAssembly::GE_F32 : WebAssembly::GE_F64;
1296 case FCmpInst::FCMP_ULE:
1297 Opc =
F32 ? WebAssembly::GT_F32 : WebAssembly::GT_F64;
1304 Register ResultReg = createResultReg(&WebAssembly::I32RegClass);
1305 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
TII.get(
Opc), ResultReg)
1310 ResultReg = notValue(ResultReg);
1312 updateValueMap(FCmp, ResultReg);
1316bool WebAssemblyFastISel::selectBitCast(
const Instruction *
I) {
1331 updateValueMap(
I, In);
1341 assert(Iter->isBitcast());
1342 Iter->setImplicitPhysRegDefsDead();
1343 updateValueMap(
I,
Reg);
1351 return WebAssembly::INSTRUCTION_LIST_END;
1353 return A64 ? WebAssembly::LOAD8_S_I64_A64 : WebAssembly::LOAD8_S_I64_A32;
1355 return A64 ? WebAssembly::LOAD16_S_I64_A64
1356 : WebAssembly::LOAD16_S_I64_A32;
1358 return A64 ? WebAssembly::LOAD32_S_I64_A64
1359 : WebAssembly::LOAD32_S_I64_A32;
1365 return WebAssembly::INSTRUCTION_LIST_END;
1367 return A64 ? WebAssembly::LOAD8_S_I32_A64 : WebAssembly::LOAD8_S_I32_A32;
1369 return A64 ? WebAssembly::LOAD16_S_I32_A64 : WebAssembly::LOAD16_S_I32_A32;
1377 return WebAssembly::INSTRUCTION_LIST_END;
1379 return A64 ? WebAssembly::LOAD8_U_I64_A64 : WebAssembly::LOAD8_U_I64_A32;
1381 return A64 ? WebAssembly::LOAD16_U_I64_A64
1382 : WebAssembly::LOAD16_U_I64_A32;
1384 return A64 ? WebAssembly::LOAD32_U_I64_A64
1385 : WebAssembly::LOAD32_U_I64_A32;
1391 return WebAssembly::INSTRUCTION_LIST_END;
1393 return A64 ? WebAssembly::LOAD8_U_I32_A64 : WebAssembly::LOAD8_U_I32_A32;
1395 return A64 ? WebAssembly::LOAD16_U_I32_A64 : WebAssembly::LOAD16_U_I32_A32;
1403 case WebAssembly::I32_EXTEND8_S_I32:
1404 case WebAssembly::I32_EXTEND16_S_I32:
1405 case WebAssembly::I64_EXTEND8_S_I64:
1406 case WebAssembly::I64_EXTEND16_S_I64:
1407 case WebAssembly::I64_EXTEND32_S_I64:
1408 case WebAssembly::I64_EXTEND_S_I32:
1417 case WebAssembly::I32_EXTEND8_S_I32:
1418 case WebAssembly::I32_EXTEND16_S_I32:
1420 case WebAssembly::I64_EXTEND8_S_I64:
1421 case WebAssembly::I64_EXTEND16_S_I64:
1422 case WebAssembly::I64_EXTEND32_S_I64:
1423 case WebAssembly::I64_EXTEND_S_I32:
1430 unsigned Opc =
MI->getOpcode();
1437 return WebAssembly::INSTRUCTION_LIST_END;
1443 unsigned NarrowOpc) {
1444 if (!
MRI.hasOneNonDBGUse(DestReg))
1450 case WebAssembly::I64_EXTEND_U_I32:
1451 OuterUserMI = UserMI;
1453 case WebAssembly::I64_EXTEND_S_I32:
1454 OuterUserMI = UserMI;
1472 unsigned Opc =
MI->getOpcode();
1473 unsigned NewOpc = WebAssembly::INSTRUCTION_LIST_END;
1474 if (
Opc != WebAssembly::SHL_I32)
1477 Register DestReg =
MI->getOperand(0).getReg();
1478 if (!
MRI.hasOneNonDBGUse(DestReg))
1481 UserMI = &*
MRI.use_instr_nodbg_begin(DestReg);
1483 if (UserOpc != WebAssembly::SHR_S_I32)
1491 Register ShlAmtReg =
MI->getOperand(2).getReg();
1496 return MI &&
MI->getOpcode() == WebAssembly::CONST_I32 &&
1497 MI->getOperand(1).getImm() == ExpectedShiftAmt;
1499 if (!IsExpectedConst(ShlAmtDef) || !IsExpectedConst(ShrAmtDef))
1504 if (NarrowOpc == WebAssembly::INSTRUCTION_LIST_END)
1505 return WebAssembly::INSTRUCTION_LIST_END;
1508 OuterUserMI, NarrowOpc);
1516 if (
MI->getOpcode() != WebAssembly::I64_EXTEND_U_I32)
1517 return WebAssembly::INSTRUCTION_LIST_END;
1520 Register DestReg =
MI->getOperand(0).getReg();
1521 if (!
MRI.hasOneNonDBGUse(DestReg))
1522 return WebAssembly::INSTRUCTION_LIST_END;
1524 UserMI = &*
MRI.use_instr_nodbg_begin(DestReg);
1527 return WebAssembly::INSTRUCTION_LIST_END;
1528 case WebAssembly::I64_EXTEND8_S_I64:
1530 return WebAssembly::INSTRUCTION_LIST_END;
1532 case WebAssembly::I64_EXTEND16_S_I64:
1534 return WebAssembly::INSTRUCTION_LIST_END;
1542 if (
MI->getOpcode() != WebAssembly::COPY)
1543 return WebAssembly::INSTRUCTION_LIST_END;
1547 return WebAssembly::INSTRUCTION_LIST_END;
1549 Register CopyDst =
MI->getOperand(0).getReg();
1550 if (!
MRI.hasOneNonDBGUse(CopyDst))
1551 return WebAssembly::INSTRUCTION_LIST_END;
1553 OuterUserMI = &*
MRI.use_instr_nodbg_begin(CopyDst);
1556 return WebAssembly::INSTRUCTION_LIST_END;
1557 case WebAssembly::I64_EXTEND_U_I32:
1559 case WebAssembly::I64_EXTEND_S_I32:
1567 if (
MI->getOpcode() != WebAssembly::AND_I32 &&
1568 MI->getOpcode() != WebAssembly::AND_I64)
1569 return WebAssembly::INSTRUCTION_LIST_END;
1572 bool IsConstant =
false;
1573 for (
unsigned I = 1;
I <= 2; ++
I) {
1576 if (
DefMI && (
DefMI->getOpcode() == WebAssembly::CONST_I32 ||
1577 DefMI->getOpcode() == WebAssembly::CONST_I64)) {
1578 Mask =
DefMI->getOperand(1).getImm();
1585 return WebAssembly::INSTRUCTION_LIST_END;
1589 return WebAssembly::INSTRUCTION_LIST_END;
1591 if (
MI->getOpcode() == WebAssembly::AND_I64)
1595 if (NarrowOpc == WebAssembly::INSTRUCTION_LIST_END)
1596 return WebAssembly::INSTRUCTION_LIST_END;
1599 OuterUserMI, NarrowOpc);
1602bool WebAssemblyFastISel::tryToFoldLoadIntoMI(MachineInstr *
MI,
unsigned OpNo,
1603 const LoadInst *LI) {
1607 MachineInstr *UserMI =
nullptr;
1608 MachineInstr *OuterUserMI =
nullptr;
1609 unsigned NewOpc = WebAssembly::INSTRUCTION_LIST_END;
1611 WebAssembly::INSTRUCTION_LIST_END) {
1613 }
else if ((NewOpc =
1615 WebAssembly::INSTRUCTION_LIST_END) {
1618 WebAssembly::INSTRUCTION_LIST_END) {
1620 :
MI->getOperand(0).getReg();
1622 WebAssembly::INSTRUCTION_LIST_END) {
1623 ResultReg =
MI->getOperand(0).getReg();
1624 }
else if ((NewOpc =
1626 WebAssembly::INSTRUCTION_LIST_END) {
1633 if (!
emitLoad(ResultReg, NewOpc, LI))
1638 removeDeadCode(OuterIter, std::next(OuterIter));
1643 removeDeadCode(UserIter, std::next(UserIter));
1647 removeDeadCode(Iter, std::next(Iter));
1651bool WebAssemblyFastISel::selectLoad(
const Instruction *
I) {
1653 if (
Load->isAtomic())
1655 if (!WebAssembly::isDefaultAddressSpace(
Load->getPointerAddressSpace()))
1657 if (!
Subtarget->hasSIMD128() &&
Load->getType()->isVectorTy())
1665 switch (getSimpleType(
Load->getType())) {
1668 Opc = A64 ? WebAssembly::LOAD8_U_I32_A64 : WebAssembly::LOAD8_U_I32_A32;
1669 RC = &WebAssembly::I32RegClass;
1672 Opc = A64 ? WebAssembly::LOAD16_U_I32_A64 : WebAssembly::LOAD16_U_I32_A32;
1673 RC = &WebAssembly::I32RegClass;
1676 Opc = A64 ? WebAssembly::LOAD_I32_A64 : WebAssembly::LOAD_I32_A32;
1677 RC = &WebAssembly::I32RegClass;
1680 Opc = A64 ? WebAssembly::LOAD_I64_A64 : WebAssembly::LOAD_I64_A32;
1681 RC = &WebAssembly::I64RegClass;
1684 Opc = A64 ? WebAssembly::LOAD_F32_A64 : WebAssembly::LOAD_F32_A32;
1685 RC = &WebAssembly::F32RegClass;
1688 Opc = A64 ? WebAssembly::LOAD_F64_A64 : WebAssembly::LOAD_F64_A32;
1689 RC = &WebAssembly::F64RegClass;
1695 Register ResultReg = createResultReg(RC);
1699 updateValueMap(
Load, ResultReg);
1703bool WebAssemblyFastISel::selectStore(
const Instruction *
I) {
1705 if (
Store->isAtomic())
1707 if (!WebAssembly::isDefaultAddressSpace(
Store->getPointerAddressSpace()))
1710 Store->getValueOperand()->getType()->isVectorTy())
1714 if (!computeAddress(
Store->getPointerOperand(), Addr))
1718 bool VTIsi1 =
false;
1720 switch (getSimpleType(
Store->getValueOperand()->getType())) {
1725 Opc = A64 ? WebAssembly::STORE8_I32_A64 : WebAssembly::STORE8_I32_A32;
1728 Opc = A64 ? WebAssembly::STORE16_I32_A64 : WebAssembly::STORE16_I32_A32;
1731 Opc = A64 ? WebAssembly::STORE_I32_A64 : WebAssembly::STORE_I32_A32;
1734 Opc = A64 ? WebAssembly::STORE_I64_A64 : WebAssembly::STORE_I64_A32;
1737 Opc = A64 ? WebAssembly::STORE_F32_A64 : WebAssembly::STORE_F32_A32;
1740 Opc = A64 ? WebAssembly::STORE_F64_A64 : WebAssembly::STORE_F64_A32;
1746 materializeLoadStoreOperands(Addr);
1748 Register ValueReg = getRegForValue(
Store->getValueOperand());
1752 ValueReg = maskI1Value(ValueReg,
Store->getValueOperand());
1754 auto MIB =
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
TII.get(
Opc));
1756 addLoadStoreOperands(Addr, MIB, createMachineMemOperandFor(
Store));
1762bool WebAssemblyFastISel::selectCondBr(
const Instruction *
I) {
1765 MachineBasicBlock *
TBB = FuncInfo.getMBB(Br->getSuccessor(0));
1766 MachineBasicBlock *FBB = FuncInfo.getMBB(Br->getSuccessor(1));
1769 unsigned CondReg = getRegForI1Value(Br->getCondition(), Br->getParent(), Not);
1773 unsigned Opc = WebAssembly::BR_IF;
1775 Opc = WebAssembly::BR_UNLESS;
1777 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
TII.get(
Opc))
1781 finishCondBranch(Br->getParent(),
TBB, FBB);
1785bool WebAssemblyFastISel::selectRet(
const Instruction *
I) {
1786 if (!FuncInfo.CanLowerReturn)
1791 if (Ret->getNumOperands() == 0) {
1792 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
1793 TII.get(WebAssembly::RETURN));
1798 if (Ret->getNumOperands() > 1)
1801 Value *RV = Ret->getOperand(0);
1805 switch (getSimpleType(RV->
getType())) {
1820 case MVT::externref:
1828 if (FuncInfo.Fn->getAttributes().hasRetAttr(Attribute::SExt))
1829 Reg = getRegForSignedValue(RV);
1830 else if (FuncInfo.Fn->getAttributes().hasRetAttr(Attribute::ZExt))
1831 Reg = getRegForUnsignedValue(RV);
1833 Reg = getRegForValue(RV);
1838 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
TII.get(WebAssembly::RETURN))
1843bool WebAssemblyFastISel::selectUnreachable(
const Instruction *
I) {
1844 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
1845 TII.get(WebAssembly::UNREACHABLE));
1849bool WebAssemblyFastISel::fastSelectInstruction(
const Instruction *
I) {
1850 switch (
I->getOpcode()) {
1851 case Instruction::Call:
1855 case Instruction::Select:
1856 return selectSelect(
I);
1857 case Instruction::Trunc:
1858 return selectTrunc(
I);
1859 case Instruction::ZExt:
1860 return selectZExt(
I);
1861 case Instruction::SExt:
1862 return selectSExt(
I);
1863 case Instruction::ICmp:
1864 return selectICmp(
I);
1865 case Instruction::FCmp:
1866 return selectFCmp(
I);
1867 case Instruction::BitCast:
1868 return selectBitCast(
I);
1869 case Instruction::Load:
1870 return selectLoad(
I);
1871 case Instruction::Store:
1872 return selectStore(
I);
1873 case Instruction::CondBr:
1874 return selectCondBr(
I);
1875 case Instruction::Ret:
1876 return selectRet(
I);
1877 case Instruction::Unreachable:
1878 return selectUnreachable(
I);
1884 return selectOperator(
I,
I->getOpcode());
1891 return new WebAssemblyFastISel(FuncInfo, LibInfo, LibcallLowering);
MachineInstrBuilder MachineInstrBuilder & DefMI
const AArch64Subtarget & Subtarget
const TargetLowering & TLI
static void emitLoad(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator Pos, const TargetInstrInfo &TII, unsigned Reg1, unsigned Reg2, int Offset, bool IsPostDec)
Emit a load-pair instruction for frame-destroy.
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AMDGPU Register Bank Select
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file defines the FastISel class.
const HexagonInstrInfo * TII
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
Promote Memory to Register
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
MachineRegisterInfo & MRI
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
static bool isFoldableSExtOpcode(unsigned Opc)
static unsigned getSExtLoadOpcode(unsigned LoadSize, bool I64Result, bool A64)
static bool isI64SExtResult(unsigned Opc)
static unsigned matchFoldableCopyToI64Ext(MachineInstr *MI, const LoadInst *LI, MachineRegisterInfo &MRI, bool A64, MachineInstr *&OuterUserMI)
static unsigned matchFoldableSExtFromPromotedI32(MachineInstr *MI, const LoadInst *LI, MachineRegisterInfo &MRI, bool A64, MachineInstr *&UserMI)
static unsigned getZExtLoadOpcode(unsigned LoadSize, bool I64Result, bool A64)
static unsigned matchFoldableShift(MachineInstr *MI, const LoadInst *LI, MachineRegisterInfo &MRI, bool A64, MachineInstr *&UserMI, MachineInstr *&OuterUserMI)
Matches a sign-extension pattern (shl + shr_s) to fold it into a signed load.
static unsigned getFoldedI64LoadOpcode(Register DestReg, const LoadInst *LI, MachineRegisterInfo &MRI, bool A64, MachineInstr *&OuterUserMI, unsigned NarrowOpc)
static unsigned getFoldedLoadOpcode(MachineInstr *MI, MachineRegisterInfo &MRI, const LoadInst *LI, bool A64)
static unsigned matchFoldableAnd(MachineInstr *MI, const LoadInst *LI, MachineRegisterInfo &MRI, bool A64, MachineInstr *&OuterUserMI)
This file provides WebAssembly-specific target descriptions.
This file declares WebAssembly-specific per-machine-function information.
This file declares the WebAssembly-specific subclass of TargetSubtarget.
This file contains the declaration of the WebAssembly-specific utility functions.
an instruction to allocate memory on the stack
LLVM Basic Block Representation.
bool isInlineAsm() const
Check if this call is an inline asm statement.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
CallingConv::ID getCallingConv() const
LLVM_ABI bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Determine whether the argument or parameter has the given attribute.
Value * getCalledOperand() const
Value * getArgOperand(unsigned i) const
FunctionType * getFunctionType() const
unsigned arg_size() const
AttributeList getAttributes() const
Return the attributes for this call.
bool isMustTailCall() const
This is an important base class in LLVM.
This is a fast-path instruction selection class that generates poor code and doesn't support illegal ...
FunctionLoweringInfo - This contains information that is global to a function that is used when lower...
Tracks which library functions to use for a particular subtarget or function.
An instruction for reading from memory.
@ INVALID_SIMPLE_VALUE_TYPE
MachineInstrBundleIterator< MachineInstr > iterator
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addSym(MCSymbol *Sym, unsigned char TargetFlags=0) const
const MachineInstrBuilder & addFrameIndex(int Idx) const
const MachineInstrBuilder & addGlobalAddress(const GlobalValue *GV, int64_t Offset=0, unsigned TargetFlags=0) const
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineOperand & getOperand(unsigned i) const
A description of a memory reference used in the backend.
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
void addLiveIn(MCRegister Reg, Register vreg=Register())
addLiveIn - Add the specified register as a live-in.
Wrapper class representing virtual and physical registers.
TypeSize getElementOffset(unsigned Idx) const
Provides information about what library functions are available for the current target.
EVT getValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const
Return the EVT corresponding to this LLVM type.
virtual MVT getPointerTy(const DataLayout &DL, uint32_t AS=0) const
Return the pointer type for the given address space, defaults to the pointer type from the data layou...
bool isPositionIndependent() const
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM_ABI unsigned getIntegerBitWidth() const
bool isVectorTy() const
True if this is an instance of VectorType.
bool isArrayTy() const
True if this is an instance of ArrayType.
bool isStructTy() const
True if this is an instance of StructType.
LLVM_ABI TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
bool isIntegerTy() const
True if this is an instance of IntegerType.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
Not(const Pred &P) -> Not< Pred >
FastISel * createFastISel(FunctionLoweringInfo &funcInfo, const TargetLibraryInfo *libInfo, const LibcallLoweringInfo *libcallLowering)
@ User
could "use" a pointer
NodeAddr< FuncNode * > Func
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI void diagnoseDontCall(const CallInst &CI)
@ Load
The value being inserted comes from a load (InsertElement only).
@ Store
The extracted value is stored (ExtractElement only).
gep_type_iterator gep_type_end(const User *GEP)
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
generic_gep_type_iterator<> gep_type_iterator
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
gep_type_iterator gep_type_begin(const User *GEP)
constexpr T maskTrailingOnes(unsigned N)
Create a bitmask with the N right-most bits set to 1, and all other bits set to 0.
MCRegisterClass TargetRegisterClass
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.