44 #define DEBUG_TYPE "wasm-fastisel" 48 class WebAssemblyFastISel final :
public FastISel {
52 using BaseKind =
enum { RegBase, FrameIndexBase };
55 BaseKind
Kind = RegBase;
68 void setKind(BaseKind K) {
69 assert(!isSet() &&
"Can't change kind with non-zero base");
72 BaseKind getKind()
const {
return Kind; }
73 bool isRegBase()
const {
return Kind == RegBase; }
74 bool isFIBase()
const {
return Kind == FrameIndexBase; }
75 void setReg(
unsigned Reg) {
76 assert(isRegBase() &&
"Invalid base register access!");
77 assert(
Base.Reg == 0 &&
"Overwriting non-zero register");
81 assert(isRegBase() &&
"Invalid base register access!");
84 void setFI(
unsigned FI) {
85 assert(isFIBase() &&
"Invalid base frame index access!");
86 assert(
Base.FI == 0 &&
"Overwriting non-zero frame index");
89 unsigned getFI()
const {
90 assert(isFIBase() &&
"Invalid base frame index access!");
94 void setOffset(int64_t NewOffset) {
95 assert(NewOffset >= 0 &&
"Offsets must be non-negative");
100 const GlobalValue *getGlobalValue()
const {
return GV; }
103 return Base.Reg != 0;
118 EVT VT = TLI.getValueType(DL, Ty,
true);
154 void materializeLoadStoreOperands(
Address &Addr);
157 unsigned maskI1Value(
unsigned Reg,
const Value *V);
158 unsigned getRegForI1Value(
const Value *V,
bool &Not);
159 unsigned zeroExtendToI32(
unsigned Reg,
const Value *V,
161 unsigned signExtendToI32(
unsigned Reg,
const Value *V,
167 unsigned getRegForUnsignedValue(
const Value *V);
168 unsigned getRegForSignedValue(
const Value *V);
169 unsigned getRegForPromotedValue(
const Value *V,
bool IsSigned);
170 unsigned notValue(
unsigned Reg);
171 unsigned copyValue(
unsigned Reg);
174 unsigned fastMaterializeAlloca(
const AllocaInst *AI)
override;
175 unsigned fastMaterializeConstant(
const Constant *
C)
override;
176 bool fastLowerArguments()
override;
197 :
FastISel(FuncInfo, LibInfo,
true) {
202 bool fastSelectInstruction(
const Instruction *I)
override;
204 #include "WebAssemblyGenFastISel.inc" 209 bool WebAssemblyFastISel::computeAddress(
const Value *Obj,
Address &Addr) {
210 const User *U =
nullptr;
211 unsigned Opcode = Instruction::UserOp1;
212 if (
const auto *
I = dyn_cast<Instruction>(Obj)) {
215 if (FuncInfo.StaticAllocaMap.count(static_cast<const AllocaInst *>(Obj)) ||
216 FuncInfo.MBBMap[
I->getParent()] == FuncInfo.MBB) {
217 Opcode =
I->getOpcode();
220 }
else if (
const auto *
C = dyn_cast<ConstantExpr>(Obj)) {
225 if (
auto *Ty = dyn_cast<PointerType>(Obj->
getType()))
226 if (Ty->getAddressSpace() > 255)
231 if (
const auto *GV = dyn_cast<GlobalValue>(Obj)) {
232 if (TLI.isPositionIndependent())
234 if (Addr.getGlobalValue())
236 if (GV->isThreadLocal())
238 Addr.setGlobalValue(GV);
245 case Instruction::BitCast: {
247 return computeAddress(U->
getOperand(0), Addr);
249 case Instruction::IntToPtr: {
252 TLI.getPointerTy(DL))
253 return computeAddress(U->
getOperand(0), Addr);
256 case Instruction::PtrToInt: {
258 if (TLI.getValueType(DL, U->
getType()) == TLI.getPointerTy(DL))
259 return computeAddress(U->
getOperand(0), Addr);
262 case Instruction::GetElementPtr: {
264 uint64_t TmpOffset = Addr.getOffset();
266 if (!cast<GEPOperator>(U)->isInBounds())
267 goto unsupported_gep;
272 const Value *
Op = GTI.getOperand();
273 if (
StructType *STy = GTI.getStructTypeOrNull()) {
275 unsigned Idx = cast<ConstantInt>(
Op)->getZExtValue();
278 uint64_t S = DL.getTypeAllocSize(GTI.getIndexedType());
280 if (
const auto *CI = dyn_cast<ConstantInt>(Op)) {
282 TmpOffset += CI->getSExtValue() * S;
285 if (S == 1 && Addr.isRegBase() && Addr.getReg() == 0) {
287 unsigned Reg = getRegForValue(Op);
293 if (canFoldAddIntoGEP(U, Op)) {
295 auto *CI = cast<ConstantInt>(cast<AddOperator>(
Op)->getOperand(1));
296 TmpOffset += CI->getSExtValue() * S;
298 Op = cast<AddOperator>(
Op)->getOperand(0);
302 goto unsupported_gep;
307 if (int64_t(TmpOffset) >= 0) {
309 Addr.setOffset(TmpOffset);
318 case Instruction::Alloca: {
319 const auto *AI = cast<AllocaInst>(Obj);
321 FuncInfo.StaticAllocaMap.find(AI);
322 if (SI != FuncInfo.StaticAllocaMap.end()) {
326 Addr.setKind(Address::FrameIndexBase);
327 Addr.setFI(SI->second);
337 if (isa<ConstantInt>(LHS))
340 if (
const auto *CI = dyn_cast<ConstantInt>(RHS)) {
341 uint64_t TmpOffset = Addr.getOffset() + CI->getSExtValue();
342 if (int64_t(TmpOffset) >= 0) {
343 Addr.setOffset(TmpOffset);
344 return computeAddress(LHS, Addr);
349 if (computeAddress(LHS, Addr) && computeAddress(RHS, Addr))
355 case Instruction::Sub: {
360 if (
const auto *CI = dyn_cast<ConstantInt>(RHS)) {
361 int64_t TmpOffset = Addr.getOffset() - CI->getSExtValue();
362 if (TmpOffset >= 0) {
363 Addr.setOffset(TmpOffset);
364 return computeAddress(LHS, Addr);
373 unsigned Reg = getRegForValue(Obj);
377 return Addr.getReg() != 0;
380 void WebAssemblyFastISel::materializeLoadStoreOperands(
Address &Addr) {
381 if (Addr.isRegBase()) {
382 unsigned Reg = Addr.getReg();
384 Reg = createResultReg(Subtarget->hasAddr64() ? &WebAssembly::I64RegClass
385 : &WebAssembly::I32RegClass);
386 unsigned Opc = Subtarget->hasAddr64() ? WebAssembly::CONST_I64
387 : WebAssembly::CONST_I32;
388 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc),
Reg)
395 void WebAssemblyFastISel::addLoadStoreOperands(
const Address &Addr,
405 MIB.
addImm(Addr.getOffset());
407 if (Addr.isRegBase())
408 MIB.
addReg(Addr.getReg());
415 unsigned WebAssemblyFastISel::maskI1Value(
unsigned Reg,
const Value *V) {
416 return zeroExtendToI32(Reg, V,
MVT::i1);
419 unsigned WebAssemblyFastISel::getRegForI1Value(
const Value *V,
bool &Not) {
420 if (
const auto *ICmp = dyn_cast<ICmpInst>(V))
421 if (
const ConstantInt *
C = dyn_cast<ConstantInt>(ICmp->getOperand(1)))
423 Not = ICmp->isTrueWhenEqual();
424 return getRegForValue(ICmp->getOperand(0));
430 return getRegForValue(NotV);
434 unsigned Reg = getRegForValue(V);
437 return maskI1Value(Reg, V);
440 unsigned WebAssemblyFastISel::zeroExtendToI32(
unsigned Reg,
const Value *V,
450 if (V !=
nullptr && isa<Argument>(V) && cast<Argument>(V)->hasZExtAttr())
451 return copyValue(Reg);
457 return copyValue(Reg);
462 unsigned Imm = createResultReg(&WebAssembly::I32RegClass);
463 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
464 TII.get(WebAssembly::CONST_I32), Imm)
467 unsigned Result = createResultReg(&WebAssembly::I32RegClass);
468 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
469 TII.get(WebAssembly::AND_I32), Result)
476 unsigned WebAssemblyFastISel::signExtendToI32(
unsigned Reg,
const Value *V,
487 return copyValue(Reg);
492 unsigned Imm = createResultReg(&WebAssembly::I32RegClass);
493 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
494 TII.get(WebAssembly::CONST_I32), Imm)
497 unsigned Left = createResultReg(&WebAssembly::I32RegClass);
498 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
499 TII.get(WebAssembly::SHL_I32), Left)
503 unsigned Right = createResultReg(&WebAssembly::I32RegClass);
504 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
505 TII.get(WebAssembly::SHR_S_I32), Right)
512 unsigned WebAssemblyFastISel::zeroExtend(
unsigned Reg,
const Value *V,
517 return copyValue(Reg);
519 Reg = zeroExtendToI32(Reg, V,
From);
521 unsigned Result = createResultReg(&WebAssembly::I64RegClass);
522 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
523 TII.get(WebAssembly::I64_EXTEND_U_I32), Result)
529 return zeroExtendToI32(Reg, V,
From);
534 unsigned WebAssemblyFastISel::signExtend(
unsigned Reg,
const Value *V,
539 return copyValue(Reg);
541 Reg = signExtendToI32(Reg, V,
From);
543 unsigned Result = createResultReg(&WebAssembly::I64RegClass);
544 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
545 TII.get(WebAssembly::I64_EXTEND_S_I32), Result)
551 return signExtendToI32(Reg, V,
From);
556 unsigned WebAssemblyFastISel::getRegForUnsignedValue(
const Value *V) {
559 unsigned VReg = getRegForValue(V);
562 return zeroExtend(VReg, V, From, To);
565 unsigned WebAssemblyFastISel::getRegForSignedValue(
const Value *V) {
568 unsigned VReg = getRegForValue(V);
571 return signExtend(VReg, V, From, To);
574 unsigned WebAssemblyFastISel::getRegForPromotedValue(
const Value *V,
576 return IsSigned ? getRegForSignedValue(V) : getRegForUnsignedValue(V);
579 unsigned WebAssemblyFastISel::notValue(
unsigned Reg) {
580 assert(
MRI.getRegClass(Reg) == &WebAssembly::I32RegClass);
582 unsigned NotReg = createResultReg(&WebAssembly::I32RegClass);
583 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
584 TII.get(WebAssembly::EQZ_I32), NotReg)
589 unsigned WebAssemblyFastISel::copyValue(
unsigned Reg) {
590 unsigned ResultReg = createResultReg(
MRI.getRegClass(Reg));
591 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(WebAssembly::COPY),
597 unsigned WebAssemblyFastISel::fastMaterializeAlloca(
const AllocaInst *AI) {
599 FuncInfo.StaticAllocaMap.find(AI);
601 if (SI != FuncInfo.StaticAllocaMap.
end()) {
603 createResultReg(Subtarget->hasAddr64() ? &WebAssembly::I64RegClass
604 : &WebAssembly::I32RegClass);
606 Subtarget->hasAddr64() ? WebAssembly::COPY_I64 : WebAssembly::COPY_I32;
607 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), ResultReg)
608 .addFrameIndex(SI->second);
615 unsigned WebAssemblyFastISel::fastMaterializeConstant(
const Constant *
C) {
616 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(C)) {
617 if (TLI.isPositionIndependent())
619 if (GV->isThreadLocal())
622 createResultReg(Subtarget->hasAddr64() ? &WebAssembly::I64RegClass
623 : &WebAssembly::I32RegClass);
624 unsigned Opc = Subtarget->hasAddr64() ? WebAssembly::CONST_I64
625 : WebAssembly::CONST_I32;
626 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), ResultReg)
627 .addGlobalAddress(GV);
635 bool WebAssemblyFastISel::fastLowerArguments() {
636 if (!FuncInfo.CanLowerReturn)
644 for (
auto const &
Arg : F->
args()) {
656 if (!Subtarget->hasSIMD128() && ArgTy->
isVectorTy())
661 switch (getSimpleType(ArgTy)) {
666 Opc = WebAssembly::ARGUMENT_i32;
667 RC = &WebAssembly::I32RegClass;
670 Opc = WebAssembly::ARGUMENT_i64;
671 RC = &WebAssembly::I64RegClass;
674 Opc = WebAssembly::ARGUMENT_f32;
675 RC = &WebAssembly::F32RegClass;
678 Opc = WebAssembly::ARGUMENT_f64;
679 RC = &WebAssembly::F64RegClass;
682 Opc = WebAssembly::ARGUMENT_v16i8;
683 RC = &WebAssembly::V128RegClass;
686 Opc = WebAssembly::ARGUMENT_v8i16;
687 RC = &WebAssembly::V128RegClass;
690 Opc = WebAssembly::ARGUMENT_v4i32;
691 RC = &WebAssembly::V128RegClass;
694 Opc = WebAssembly::ARGUMENT_v2i64;
695 RC = &WebAssembly::V128RegClass;
698 Opc = WebAssembly::ARGUMENT_v4f32;
699 RC = &WebAssembly::V128RegClass;
702 Opc = WebAssembly::ARGUMENT_v2f64;
703 RC = &WebAssembly::V128RegClass;
706 Opc = WebAssembly::ARGUMENT_exnref;
707 RC = &WebAssembly::EXNREFRegClass;
712 unsigned ResultReg = createResultReg(RC);
713 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), ResultReg)
715 updateValueMap(&
Arg, ResultReg);
720 MRI.addLiveIn(WebAssembly::ARGUMENTS);
723 for (
auto const &
Arg : F->
args()) {
726 MFI->clearParamsAndResults();
729 MFI->addParam(ArgTy);
736 MFI->clearParamsAndResults();
739 MFI->addResult(RetTy);
745 bool WebAssemblyFastISel::selectCall(
const Instruction *
I) {
746 const auto *Call = cast<CallInst>(
I);
749 if (Call->isMustTailCall() || Call->isInlineAsm() ||
750 Call->getFunctionType()->isVarArg())
753 Function *Func = Call->getCalledFunction();
757 bool IsDirect = Func !=
nullptr;
758 if (!IsDirect && isa<ConstantExpr>(Call->getCalledValue()))
766 Opc = IsDirect ? WebAssembly::CALL_VOID : WebAssembly::PCALL_INDIRECT_VOID;
768 if (!Subtarget->hasSIMD128() && Call->getType()->isVectorTy())
777 Opc = IsDirect ? WebAssembly::CALL_i32 : WebAssembly::PCALL_INDIRECT_i32;
778 ResultReg = createResultReg(&WebAssembly::I32RegClass);
781 Opc = IsDirect ? WebAssembly::CALL_i64 : WebAssembly::PCALL_INDIRECT_i64;
782 ResultReg = createResultReg(&WebAssembly::I64RegClass);
785 Opc = IsDirect ? WebAssembly::CALL_f32 : WebAssembly::PCALL_INDIRECT_f32;
786 ResultReg = createResultReg(&WebAssembly::F32RegClass);
789 Opc = IsDirect ? WebAssembly::CALL_f64 : WebAssembly::PCALL_INDIRECT_f64;
790 ResultReg = createResultReg(&WebAssembly::F64RegClass);
793 Opc = IsDirect ? WebAssembly::CALL_v16i8
794 : WebAssembly::PCALL_INDIRECT_v16i8;
795 ResultReg = createResultReg(&WebAssembly::V128RegClass);
798 Opc = IsDirect ? WebAssembly::CALL_v8i16
799 : WebAssembly::PCALL_INDIRECT_v8i16;
800 ResultReg = createResultReg(&WebAssembly::V128RegClass);
803 Opc = IsDirect ? WebAssembly::CALL_v4i32
804 : WebAssembly::PCALL_INDIRECT_v4i32;
805 ResultReg = createResultReg(&WebAssembly::V128RegClass);
808 Opc = IsDirect ? WebAssembly::CALL_v2i64
809 : WebAssembly::PCALL_INDIRECT_v2i64;
810 ResultReg = createResultReg(&WebAssembly::V128RegClass);
813 Opc = IsDirect ? WebAssembly::CALL_v4f32
814 : WebAssembly::PCALL_INDIRECT_v4f32;
815 ResultReg = createResultReg(&WebAssembly::V128RegClass);
818 Opc = IsDirect ? WebAssembly::CALL_v2f64
819 : WebAssembly::PCALL_INDIRECT_v2f64;
820 ResultReg = createResultReg(&WebAssembly::V128RegClass);
823 Opc = IsDirect ? WebAssembly::CALL_exnref
824 : WebAssembly::PCALL_INDIRECT_exnref;
825 ResultReg = createResultReg(&WebAssembly::EXNREFRegClass);
833 for (
unsigned I = 0,
E = Call->getNumArgOperands(); I <
E; ++
I) {
834 Value *V = Call->getArgOperand(I);
850 Reg = getRegForSignedValue(V);
852 Reg = getRegForUnsignedValue(V);
854 Reg = getRegForValue(V);
862 unsigned CalleeReg = 0;
864 CalleeReg = getRegForValue(Call->getCalledValue());
869 auto MIB =
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc));
879 for (
unsigned ArgReg : Args)
883 updateValueMap(Call, ResultReg);
887 bool WebAssemblyFastISel::selectSelect(
const Instruction *I) {
888 const auto *
Select = cast<SelectInst>(
I);
891 unsigned CondReg = getRegForI1Value(
Select->getCondition(), Not);
895 unsigned TrueReg = getRegForValue(
Select->getTrueValue());
899 unsigned FalseReg = getRegForValue(
Select->getFalseValue());
908 switch (getSimpleType(
Select->getType())) {
913 Opc = WebAssembly::SELECT_I32;
914 RC = &WebAssembly::I32RegClass;
917 Opc = WebAssembly::SELECT_I64;
918 RC = &WebAssembly::I64RegClass;
921 Opc = WebAssembly::SELECT_F32;
922 RC = &WebAssembly::F32RegClass;
925 Opc = WebAssembly::SELECT_F64;
926 RC = &WebAssembly::F64RegClass;
929 Opc = WebAssembly::SELECT_EXNREF;
930 RC = &WebAssembly::EXNREFRegClass;
936 unsigned ResultReg = createResultReg(RC);
937 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), ResultReg)
942 updateValueMap(
Select, ResultReg);
946 bool WebAssemblyFastISel::selectTrunc(
const Instruction *I) {
947 const auto *Trunc = cast<TruncInst>(
I);
949 unsigned Reg = getRegForValue(Trunc->getOperand(0));
953 if (Trunc->getOperand(0)->getType()->isIntegerTy(64)) {
954 unsigned Result = createResultReg(&WebAssembly::I32RegClass);
955 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
956 TII.get(WebAssembly::I32_WRAP_I64), Result)
961 updateValueMap(Trunc, Reg);
965 bool WebAssemblyFastISel::selectZExt(
const Instruction *I) {
966 const auto *ZExt = cast<ZExtInst>(
I);
968 const Value *
Op = ZExt->getOperand(0);
971 unsigned In = getRegForValue(Op);
974 unsigned Reg = zeroExtend(In, Op, From, To);
978 updateValueMap(ZExt, Reg);
982 bool WebAssemblyFastISel::selectSExt(
const Instruction *I) {
983 const auto *SExt = cast<SExtInst>(
I);
985 const Value *
Op = SExt->getOperand(0);
988 unsigned In = getRegForValue(Op);
991 unsigned Reg = signExtend(In, Op, From, To);
995 updateValueMap(SExt, Reg);
999 bool WebAssemblyFastISel::selectICmp(
const Instruction *I) {
1000 const auto *ICmp = cast<ICmpInst>(
I);
1002 bool I32 = getSimpleType(ICmp->getOperand(0)->getType()) !=
MVT::i64;
1004 bool IsSigned =
false;
1005 switch (ICmp->getPredicate()) {
1007 Opc = I32 ? WebAssembly::EQ_I32 : WebAssembly::EQ_I64;
1010 Opc = I32 ? WebAssembly::NE_I32 : WebAssembly::NE_I64;
1013 Opc = I32 ? WebAssembly::GT_U_I32 : WebAssembly::GT_U_I64;
1016 Opc = I32 ? WebAssembly::GE_U_I32 : WebAssembly::GE_U_I64;
1019 Opc = I32 ? WebAssembly::LT_U_I32 : WebAssembly::LT_U_I64;
1022 Opc = I32 ? WebAssembly::LE_U_I32 : WebAssembly::LE_U_I64;
1025 Opc = I32 ? WebAssembly::GT_S_I32 : WebAssembly::GT_S_I64;
1029 Opc = I32 ? WebAssembly::GE_S_I32 : WebAssembly::GE_S_I64;
1033 Opc = I32 ? WebAssembly::LT_S_I32 : WebAssembly::LT_S_I64;
1037 Opc = I32 ? WebAssembly::LE_S_I32 : WebAssembly::LE_S_I64;
1044 unsigned LHS = getRegForPromotedValue(ICmp->getOperand(0), IsSigned);
1048 unsigned RHS = getRegForPromotedValue(ICmp->getOperand(1), IsSigned);
1052 unsigned ResultReg = createResultReg(&WebAssembly::I32RegClass);
1053 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), ResultReg)
1056 updateValueMap(ICmp, ResultReg);
1060 bool WebAssemblyFastISel::selectFCmp(
const Instruction *I) {
1061 const auto *FCmp = cast<FCmpInst>(
I);
1063 unsigned LHS = getRegForValue(FCmp->getOperand(0));
1067 unsigned RHS = getRegForValue(FCmp->getOperand(1));
1071 bool F32 = getSimpleType(FCmp->getOperand(0)->getType()) !=
MVT::f64;
1074 switch (FCmp->getPredicate()) {
1076 Opc = F32 ? WebAssembly::EQ_F32 : WebAssembly::EQ_F64;
1079 Opc = F32 ? WebAssembly::NE_F32 : WebAssembly::NE_F64;
1082 Opc = F32 ? WebAssembly::GT_F32 : WebAssembly::GT_F64;
1085 Opc = F32 ? WebAssembly::GE_F32 : WebAssembly::GE_F64;
1088 Opc = F32 ? WebAssembly::LT_F32 : WebAssembly::LT_F64;
1091 Opc = F32 ? WebAssembly::LE_F32 : WebAssembly::LE_F64;
1094 Opc = F32 ? WebAssembly::LE_F32 : WebAssembly::LE_F64;
1098 Opc = F32 ? WebAssembly::LT_F32 : WebAssembly::LT_F64;
1102 Opc = F32 ? WebAssembly::GE_F32 : WebAssembly::GE_F64;
1106 Opc = F32 ? WebAssembly::GT_F32 : WebAssembly::GT_F64;
1113 unsigned ResultReg = createResultReg(&WebAssembly::I32RegClass);
1114 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), ResultReg)
1119 ResultReg = notValue(ResultReg);
1121 updateValueMap(FCmp, ResultReg);
1125 bool WebAssemblyFastISel::selectBitCast(
const Instruction *I) {
1130 EVT RetVT = TLI.getValueType(DL, I->
getType());
1140 updateValueMap(I, In);
1150 assert(Iter->isBitcast());
1152 updateValueMap(I, Reg);
1156 bool WebAssemblyFastISel::selectLoad(
const Instruction *I) {
1157 const auto *
Load = cast<LoadInst>(
I);
1158 if (
Load->isAtomic())
1160 if (!Subtarget->hasSIMD128() &&
Load->getType()->isVectorTy())
1164 if (!computeAddress(
Load->getPointerOperand(), Addr))
1171 switch (getSimpleType(
Load->getType())) {
1174 Opc = WebAssembly::LOAD8_U_I32;
1175 RC = &WebAssembly::I32RegClass;
1178 Opc = WebAssembly::LOAD16_U_I32;
1179 RC = &WebAssembly::I32RegClass;
1182 Opc = WebAssembly::LOAD_I32;
1183 RC = &WebAssembly::I32RegClass;
1186 Opc = WebAssembly::LOAD_I64;
1187 RC = &WebAssembly::I64RegClass;
1190 Opc = WebAssembly::LOAD_F32;
1191 RC = &WebAssembly::F32RegClass;
1194 Opc = WebAssembly::LOAD_F64;
1195 RC = &WebAssembly::F64RegClass;
1201 materializeLoadStoreOperands(Addr);
1203 unsigned ResultReg = createResultReg(RC);
1204 auto MIB =
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc),
1207 addLoadStoreOperands(Addr, MIB, createMachineMemOperandFor(
Load));
1209 updateValueMap(
Load, ResultReg);
1213 bool WebAssemblyFastISel::selectStore(
const Instruction *I) {
1214 const auto *
Store = cast<StoreInst>(
I);
1215 if (
Store->isAtomic())
1217 if (!Subtarget->hasSIMD128() &&
1218 Store->getValueOperand()->getType()->isVectorTy())
1222 if (!computeAddress(
Store->getPointerOperand(), Addr))
1226 bool VTIsi1 =
false;
1227 switch (getSimpleType(
Store->getValueOperand()->getType())) {
1232 Opc = WebAssembly::STORE8_I32;
1235 Opc = WebAssembly::STORE16_I32;
1238 Opc = WebAssembly::STORE_I32;
1241 Opc = WebAssembly::STORE_I64;
1244 Opc = WebAssembly::STORE_F32;
1247 Opc = WebAssembly::STORE_F64;
1253 materializeLoadStoreOperands(Addr);
1255 unsigned ValueReg = getRegForValue(
Store->getValueOperand());
1259 ValueReg = maskI1Value(ValueReg,
Store->getValueOperand());
1261 auto MIB =
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc));
1263 addLoadStoreOperands(Addr, MIB, createMachineMemOperandFor(
Store));
1265 MIB.addReg(ValueReg);
1269 bool WebAssemblyFastISel::selectBr(
const Instruction *I) {
1270 const auto *Br = cast<BranchInst>(
I);
1271 if (Br->isUnconditional()) {
1273 fastEmitBranch(MSucc, Br->getDebugLoc());
1281 unsigned CondReg = getRegForI1Value(Br->getCondition(), Not);
1285 unsigned Opc = WebAssembly::BR_IF;
1287 Opc = WebAssembly::BR_UNLESS;
1289 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc))
1293 finishCondBranch(Br->getParent(), TBB, FBB);
1297 bool WebAssemblyFastISel::selectRet(
const Instruction *I) {
1298 if (!FuncInfo.CanLowerReturn)
1301 const auto *
Ret = cast<ReturnInst>(
I);
1303 if (
Ret->getNumOperands() == 0) {
1304 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1310 if (
Ret->getNumOperands() > 1)
1317 switch (getSimpleType(RV->
getType())) {
1338 if (FuncInfo.Fn->getAttributes().hasAttribute(0, Attribute::SExt))
1339 Reg = getRegForSignedValue(RV);
1340 else if (FuncInfo.Fn->getAttributes().hasAttribute(0, Attribute::ZExt))
1341 Reg = getRegForUnsignedValue(RV);
1343 Reg = getRegForValue(RV);
1348 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1354 bool WebAssemblyFastISel::selectUnreachable(
const Instruction *I) {
1355 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1356 TII.get(WebAssembly::UNREACHABLE));
1360 bool WebAssemblyFastISel::fastSelectInstruction(
const Instruction *I) {
1367 return selectSelect(I);
1368 case Instruction::Trunc:
1369 return selectTrunc(I);
1370 case Instruction::ZExt:
1371 return selectZExt(I);
1372 case Instruction::SExt:
1373 return selectSExt(I);
1374 case Instruction::ICmp:
1375 return selectICmp(I);
1376 case Instruction::FCmp:
1377 return selectFCmp(I);
1378 case Instruction::BitCast:
1379 return selectBitCast(I);
1381 return selectLoad(I);
1383 return selectStore(I);
1384 case Instruction::Br:
1387 return selectRet(I);
1388 case Instruction::Unreachable:
1389 return selectUnreachable(I);
1395 return selectOperator(I, I->
getOpcode());
1400 return new WebAssemblyFastISel(FuncInfo, LibInfo);
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
This class represents lattice values for constants.
unsigned getSizeInBits(Register Reg, const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI) const
Get the size in bits of Reg.
void push_back(const T &Elt)
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
gep_type_iterator gep_type_end(const User *GEP)
0 1 0 0 True if ordered and less than
1 1 1 0 True if unordered or not equal
unsigned const TargetRegisterInfo * TRI
bool isVectorTy() const
True if this is an instance of VectorType.
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end...
bool match(Val *V, const Pattern &P)
FastISel * createFastISel(FunctionLoweringInfo &funcInfo, const TargetLibraryInfo *libInfo)
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
A description of a memory reference used in the backend.
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
const HexagonInstrInfo * TII
Class to represent struct types.
bool isIntegerTy() const
True if this is an instance of IntegerType.
0 1 0 1 True if ordered and less than or equal
bool hasUnimplementedSIMD128() const
This is a fast-path instruction selection class that generates poor code and doesn't support illegal ...
Class to represent function types.
This file declares the WebAssembly-specific subclass of TargetMachine.
Type * getType() const
All values are typed, get the type of this value.
const MachineInstrBuilder & addGlobalAddress(const GlobalValue *GV, int64_t Offset=0, unsigned TargetFlags=0) const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
AttributeList getAttributes() const
Return the attribute list for this Function.
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
Value * getOperand(unsigned i) const
bool isVoidTy() const
Return true if this is 'void'.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
Type * getReturnType() const
Returns the type of the ret val.
unsigned const MachineRegisterInfo * MRI
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
This file provides WebAssembly-specific target descriptions.
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
const MachineInstrBuilder & addFrameIndex(int Idx) const
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
1 1 0 1 True if unordered, less than, or equal
0 0 1 0 True if ordered and greater than
This file declares the WebAssembly-specific subclass of TargetSubtarget.
bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
Equivalent to hasAttribute(ArgNo + FirstArgIndex, Kind).
This is the shared class of boolean and integer constants.
BlockVerifier::State From
1 1 0 0 True if unordered or less than
Provides information about what library functions are available for the current target.
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
Type * getReturnType() const
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
This file defines the FastISel class.
This class is derived from MachineFunctionInfo and contains private WebAssembly-specific information ...
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
uint64_t getElementOffset(unsigned Idx) const
unsigned greater or equal
FunctionLoweringInfo - This contains information that is global to a function that is used when lower...
This file declares WebAssembly-specific per-machine-function information.
1 0 1 0 True if unordered or greater than
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
0 0 0 1 True if ordered and equal
LLVM Value Representation.
1 0 1 1 True if unordered, greater than, or equal
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
bool hasOneUse() const
Return true if there is exactly one user of this value.
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
0 0 1 1 True if ordered and greater than or equal
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
BinaryOp_match< ValTy, cst_pred_ty< is_all_ones >, Instruction::Xor, true > m_Not(const ValTy &V)
Matches a 'Not' as 'xor V, -1' or 'xor -1, V'.
iterator_range< arg_iterator > args()
Wrapper class representing virtual and physical registers.
bool isStructTy() const
True if this is an instance of StructType.
bool isArrayTy() const
True if this is an instance of ArrayType.
an instruction to allocate memory on the stack
gep_type_iterator gep_type_begin(const User *GEP)