42 #define DEBUG_TYPE "wasm-fastisel" 46 class WebAssemblyFastISel final :
public FastISel {
50 typedef enum { RegBase, FrameIndexBase } BaseKind;
66 void setKind(BaseKind K) {
67 assert(!isSet() &&
"Can't change kind with non-zero base");
70 BaseKind getKind()
const {
return Kind; }
71 bool isRegBase()
const {
return Kind == RegBase; }
72 bool isFIBase()
const {
return Kind == FrameIndexBase; }
73 void setReg(
unsigned Reg) {
74 assert(isRegBase() &&
"Invalid base register access!");
75 assert(
Base.Reg == 0 &&
"Overwriting non-zero register");
79 assert(isRegBase() &&
"Invalid base register access!");
82 void setFI(
unsigned FI) {
83 assert(isFIBase() &&
"Invalid base frame index access!");
84 assert(
Base.FI == 0 &&
"Overwriting non-zero frame index");
87 unsigned getFI()
const {
88 assert(isFIBase() &&
"Invalid base frame index access!");
92 void setOffset(int64_t Offset_) {
93 assert(Offset_ >= 0 &&
"Offsets must be non-negative");
98 const GlobalValue *getGlobalValue()
const {
return GV; }
101 return Base.Reg != 0;
116 EVT VT = TLI.getValueType(DL, Ty,
true);
147 void materializeLoadStoreOperands(
Address &Addr);
150 unsigned maskI1Value(
unsigned Reg,
const Value *V);
151 unsigned getRegForI1Value(
const Value *V,
bool &Not);
152 unsigned zeroExtendToI32(
unsigned Reg,
const Value *V,
154 unsigned signExtendToI32(
unsigned Reg,
const Value *V,
156 unsigned zeroExtend(
unsigned Reg,
const Value *V,
159 unsigned signExtend(
unsigned Reg,
const Value *V,
162 unsigned getRegForUnsignedValue(
const Value *V);
163 unsigned getRegForSignedValue(
const Value *V);
164 unsigned getRegForPromotedValue(
const Value *V,
bool IsSigned);
165 unsigned notValue(
unsigned Reg);
166 unsigned copyValue(
unsigned Reg);
169 unsigned fastMaterializeAlloca(
const AllocaInst *AI)
override;
170 unsigned fastMaterializeConstant(
const Constant *
C)
override;
171 bool fastLowerArguments()
override;
192 :
FastISel(FuncInfo, LibInfo,
true) {
197 bool fastSelectInstruction(
const Instruction *I)
override;
199 #include "WebAssemblyGenFastISel.inc" 204 bool WebAssemblyFastISel::computeAddress(
const Value *Obj,
Address &Addr) {
206 const User *U =
nullptr;
207 unsigned Opcode = Instruction::UserOp1;
208 if (
const Instruction *
I = dyn_cast<Instruction>(Obj)) {
211 if (FuncInfo.StaticAllocaMap.count(static_cast<const AllocaInst *>(Obj)) ||
212 FuncInfo.MBBMap[
I->getParent()] == FuncInfo.MBB) {
213 Opcode =
I->getOpcode();
216 }
else if (
const ConstantExpr *
C = dyn_cast<ConstantExpr>(Obj)) {
221 if (
auto *Ty = dyn_cast<PointerType>(Obj->
getType()))
222 if (Ty->getAddressSpace() > 255)
227 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(Obj)) {
228 if (Addr.getGlobalValue())
230 Addr.setGlobalValue(GV);
237 case Instruction::BitCast: {
239 return computeAddress(U->
getOperand(0), Addr);
241 case Instruction::IntToPtr: {
244 TLI.getPointerTy(DL))
245 return computeAddress(U->
getOperand(0), Addr);
248 case Instruction::PtrToInt: {
250 if (TLI.getValueType(DL, U->
getType()) == TLI.getPointerTy(DL))
251 return computeAddress(U->
getOperand(0), Addr);
254 case Instruction::GetElementPtr: {
256 uint64_t TmpOffset = Addr.getOffset();
258 if (!cast<GEPOperator>(U)->isInBounds())
259 goto unsupported_gep;
264 const Value *
Op = GTI.getOperand();
265 if (
StructType *STy = GTI.getStructTypeOrNull()) {
267 unsigned Idx = cast<ConstantInt>(
Op)->getZExtValue();
270 uint64_t S = DL.getTypeAllocSize(GTI.getIndexedType());
272 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(Op)) {
274 TmpOffset += CI->getSExtValue() * S;
277 if (S == 1 && Addr.isRegBase() && Addr.getReg() == 0) {
279 unsigned Reg = getRegForValue(Op);
285 if (canFoldAddIntoGEP(U, Op)) {
288 cast<ConstantInt>(cast<AddOperator>(
Op)->getOperand(1));
291 Op = cast<AddOperator>(
Op)->getOperand(0);
295 goto unsupported_gep;
300 if (int64_t(TmpOffset) >= 0) {
302 Addr.setOffset(TmpOffset);
311 case Instruction::Alloca: {
314 FuncInfo.StaticAllocaMap.find(AI);
315 if (SI != FuncInfo.StaticAllocaMap.end()) {
319 Addr.setKind(Address::FrameIndexBase);
320 Addr.setFI(SI->second);
330 if (isa<ConstantInt>(LHS))
333 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(RHS)) {
334 uint64_t TmpOffset = Addr.getOffset() + CI->getSExtValue();
335 if (int64_t(TmpOffset) >= 0) {
336 Addr.setOffset(TmpOffset);
337 return computeAddress(LHS, Addr);
342 if (computeAddress(LHS, Addr) && computeAddress(RHS, Addr))
348 case Instruction::Sub: {
353 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(RHS)) {
354 int64_t TmpOffset = Addr.getOffset() - CI->getSExtValue();
355 if (TmpOffset >= 0) {
356 Addr.setOffset(TmpOffset);
357 return computeAddress(LHS, Addr);
366 unsigned Reg = getRegForValue(Obj);
370 return Addr.getReg() != 0;
373 void WebAssemblyFastISel::materializeLoadStoreOperands(
Address &Addr) {
374 if (Addr.isRegBase()) {
375 unsigned Reg = Addr.getReg();
377 Reg = createResultReg(Subtarget->hasAddr64() ?
378 &WebAssembly::I64RegClass :
379 &WebAssembly::I32RegClass);
380 unsigned Opc = Subtarget->hasAddr64() ?
381 WebAssembly::CONST_I64 :
382 WebAssembly::CONST_I32;
383 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc),
Reg)
390 void WebAssemblyFastISel::addLoadStoreOperands(
const Address &Addr,
400 MIB.
addImm(Addr.getOffset());
402 if (Addr.isRegBase())
403 MIB.
addReg(Addr.getReg());
410 unsigned WebAssemblyFastISel::maskI1Value(
unsigned Reg,
const Value *V) {
411 return zeroExtendToI32(Reg, V,
MVT::i1);
414 unsigned WebAssemblyFastISel::getRegForI1Value(
const Value *V,
bool &Not) {
415 if (
const ICmpInst *ICmp = dyn_cast<ICmpInst>(V))
416 if (
const ConstantInt *
C = dyn_cast<ConstantInt>(ICmp->getOperand(1)))
418 Not = ICmp->isTrueWhenEqual();
419 return getRegForValue(ICmp->getOperand(0));
428 unsigned Reg = getRegForValue(V);
431 return maskI1Value(Reg, V);
434 unsigned WebAssemblyFastISel::zeroExtendToI32(
unsigned Reg,
const Value *V,
443 if (From ==
MVT::i1 && V !=
nullptr) {
444 if (isa<CmpInst>(V) ||
445 (isa<Argument>(V) && cast<Argument>(V)->hasZExtAttr()))
446 return copyValue(Reg);
452 return copyValue(Reg);
457 unsigned Imm = createResultReg(&WebAssembly::I32RegClass);
458 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
459 TII.get(WebAssembly::CONST_I32), Imm)
462 unsigned Result = createResultReg(&WebAssembly::I32RegClass);
463 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
464 TII.get(WebAssembly::AND_I32), Result)
471 unsigned WebAssemblyFastISel::signExtendToI32(
unsigned Reg,
const Value *V,
482 return copyValue(Reg);
487 unsigned Imm = createResultReg(&WebAssembly::I32RegClass);
488 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
489 TII.get(WebAssembly::CONST_I32), Imm)
492 unsigned Left = createResultReg(&WebAssembly::I32RegClass);
493 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
494 TII.get(WebAssembly::SHL_I32),
Left)
498 unsigned Right = createResultReg(&WebAssembly::I32RegClass);
499 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
500 TII.get(WebAssembly::SHR_S_I32),
Right)
507 unsigned WebAssemblyFastISel::zeroExtend(
unsigned Reg,
const Value *V,
512 return copyValue(Reg);
514 Reg = zeroExtendToI32(Reg, V, From);
516 unsigned Result = createResultReg(&WebAssembly::I64RegClass);
517 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
518 TII.get(WebAssembly::I64_EXTEND_U_I32), Result)
523 return zeroExtendToI32(Reg, V, From);
526 unsigned WebAssemblyFastISel::signExtend(
unsigned Reg,
const Value *V,
531 return copyValue(Reg);
533 Reg = signExtendToI32(Reg, V, From);
535 unsigned Result = createResultReg(&WebAssembly::I64RegClass);
536 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
537 TII.get(WebAssembly::I64_EXTEND_S_I32), Result)
542 return signExtendToI32(Reg, V, From);
545 unsigned WebAssemblyFastISel::getRegForUnsignedValue(
const Value *V) {
548 unsigned VReg = getRegForValue(V);
551 return zeroExtend(VReg, V, From, To);
554 unsigned WebAssemblyFastISel::getRegForSignedValue(
const Value *V) {
557 unsigned VReg = getRegForValue(V);
560 return signExtend(VReg, V, From, To);
563 unsigned WebAssemblyFastISel::getRegForPromotedValue(
const Value *V,
565 return IsSigned ? getRegForSignedValue(V) :
566 getRegForUnsignedValue(V);
569 unsigned WebAssemblyFastISel::notValue(
unsigned Reg) {
570 assert(
MRI.getRegClass(Reg) == &WebAssembly::I32RegClass);
572 unsigned NotReg = createResultReg(&WebAssembly::I32RegClass);
573 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
574 TII.get(WebAssembly::EQZ_I32), NotReg)
579 unsigned WebAssemblyFastISel::copyValue(
unsigned Reg) {
580 unsigned ResultReg = createResultReg(
MRI.getRegClass(Reg));
581 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
582 TII.get(WebAssembly::COPY), ResultReg)
587 unsigned WebAssemblyFastISel::fastMaterializeAlloca(
const AllocaInst *AI) {
589 FuncInfo.StaticAllocaMap.find(AI);
591 if (SI != FuncInfo.StaticAllocaMap.
end()) {
592 unsigned ResultReg = createResultReg(Subtarget->hasAddr64() ?
593 &WebAssembly::I64RegClass :
594 &WebAssembly::I32RegClass);
595 unsigned Opc = Subtarget->hasAddr64() ?
596 WebAssembly::COPY_I64 :
597 WebAssembly::COPY_I32;
598 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), ResultReg)
599 .addFrameIndex(SI->second);
606 unsigned WebAssemblyFastISel::fastMaterializeConstant(
const Constant *
C) {
607 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(C)) {
608 unsigned ResultReg = createResultReg(Subtarget->hasAddr64() ?
609 &WebAssembly::I64RegClass :
610 &WebAssembly::I32RegClass);
611 unsigned Opc = Subtarget->hasAddr64() ?
612 WebAssembly::CONST_I64 :
613 WebAssembly::CONST_I32;
614 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), ResultReg)
615 .addGlobalAddress(GV);
623 bool WebAssemblyFastISel::fastLowerArguments() {
624 if (!FuncInfo.CanLowerReturn)
632 for (
auto const &
Arg : F->
args()) {
644 if (!Subtarget->hasSIMD128() && ArgTy->
isVectorTy())
649 switch (getSimpleType(ArgTy)) {
654 Opc = WebAssembly::ARGUMENT_I32;
655 RC = &WebAssembly::I32RegClass;
658 Opc = WebAssembly::ARGUMENT_I64;
659 RC = &WebAssembly::I64RegClass;
662 Opc = WebAssembly::ARGUMENT_F32;
663 RC = &WebAssembly::F32RegClass;
666 Opc = WebAssembly::ARGUMENT_F64;
667 RC = &WebAssembly::F64RegClass;
670 Opc = WebAssembly::ARGUMENT_v16i8;
671 RC = &WebAssembly::V128RegClass;
674 Opc = WebAssembly::ARGUMENT_v8i16;
675 RC = &WebAssembly::V128RegClass;
678 Opc = WebAssembly::ARGUMENT_v4i32;
679 RC = &WebAssembly::V128RegClass;
682 Opc = WebAssembly::ARGUMENT_v4f32;
683 RC = &WebAssembly::V128RegClass;
686 Opc = WebAssembly::ARGUMENT_EXCEPT_REF;
687 RC = &WebAssembly::EXCEPT_REFRegClass;
692 unsigned ResultReg = createResultReg(RC);
693 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), ResultReg)
695 updateValueMap(&
Arg, ResultReg);
700 MRI.addLiveIn(WebAssembly::ARGUMENTS);
703 for (
auto const &
Arg : F->
args()) {
706 MFI->clearParamsAndResults();
709 MFI->addParam(ArgTy);
715 MFI->clearParamsAndResults();
718 MFI->addResult(RetTy);
724 bool WebAssemblyFastISel::selectCall(
const Instruction *
I) {
725 const CallInst *Call = cast<CallInst>(
I);
735 bool IsDirect = Func !=
nullptr;
744 Opc = IsDirect ? WebAssembly::CALL_VOID : WebAssembly::PCALL_INDIRECT_VOID;
755 Opc = IsDirect ? WebAssembly::CALL_I32 : WebAssembly::PCALL_INDIRECT_I32;
756 ResultReg = createResultReg(&WebAssembly::I32RegClass);
759 Opc = IsDirect ? WebAssembly::CALL_I64 : WebAssembly::PCALL_INDIRECT_I64;
760 ResultReg = createResultReg(&WebAssembly::I64RegClass);
763 Opc = IsDirect ? WebAssembly::CALL_F32 : WebAssembly::PCALL_INDIRECT_F32;
764 ResultReg = createResultReg(&WebAssembly::F32RegClass);
767 Opc = IsDirect ? WebAssembly::CALL_F64 : WebAssembly::PCALL_INDIRECT_F64;
768 ResultReg = createResultReg(&WebAssembly::F64RegClass);
772 IsDirect ? WebAssembly::CALL_v16i8 : WebAssembly::PCALL_INDIRECT_v16i8;
773 ResultReg = createResultReg(&WebAssembly::V128RegClass);
777 IsDirect ? WebAssembly::CALL_v8i16 : WebAssembly::PCALL_INDIRECT_v8i16;
778 ResultReg = createResultReg(&WebAssembly::V128RegClass);
782 IsDirect ? WebAssembly::CALL_v4i32 : WebAssembly::PCALL_INDIRECT_v4i32;
783 ResultReg = createResultReg(&WebAssembly::V128RegClass);
787 IsDirect ? WebAssembly::CALL_v4f32 : WebAssembly::PCALL_INDIRECT_v4f32;
788 ResultReg = createResultReg(&WebAssembly::V128RegClass);
791 Opc = IsDirect ? WebAssembly::CALL_EXCEPT_REF
792 : WebAssembly::PCALL_INDIRECT_EXCEPT_REF;
793 ResultReg = createResultReg(&WebAssembly::EXCEPT_REFRegClass);
818 Reg = getRegForSignedValue(V);
820 Reg = getRegForUnsignedValue(V);
822 Reg = getRegForValue(V);
830 auto MIB =
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc));
844 for (
unsigned ArgReg : Args)
848 updateValueMap(Call, ResultReg);
852 bool WebAssemblyFastISel::selectSelect(
const Instruction *I) {
856 unsigned CondReg = getRegForI1Value(Select->
getCondition(), Not);
860 unsigned TrueReg = getRegForValue(Select->
getTrueValue());
873 switch (getSimpleType(Select->
getType())) {
878 Opc = WebAssembly::SELECT_I32;
879 RC = &WebAssembly::I32RegClass;
882 Opc = WebAssembly::SELECT_I64;
883 RC = &WebAssembly::I64RegClass;
886 Opc = WebAssembly::SELECT_F32;
887 RC = &WebAssembly::F32RegClass;
890 Opc = WebAssembly::SELECT_F64;
891 RC = &WebAssembly::F64RegClass;
894 Opc = WebAssembly::SELECT_EXCEPT_REF;
895 RC = &WebAssembly::EXCEPT_REFRegClass;
901 unsigned ResultReg = createResultReg(RC);
902 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), ResultReg)
907 updateValueMap(Select, ResultReg);
911 bool WebAssemblyFastISel::selectTrunc(
const Instruction *I) {
914 unsigned Reg = getRegForValue(Trunc->
getOperand(0));
919 unsigned Result = createResultReg(&WebAssembly::I32RegClass);
920 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
921 TII.get(WebAssembly::I32_WRAP_I64), Result)
926 updateValueMap(Trunc, Reg);
930 bool WebAssemblyFastISel::selectZExt(
const Instruction *I) {
931 const ZExtInst *ZExt = cast<ZExtInst>(
I);
936 unsigned In = getRegForValue(Op);
939 unsigned Reg = zeroExtend(In, Op, From, To);
943 updateValueMap(ZExt, Reg);
947 bool WebAssemblyFastISel::selectSExt(
const Instruction *I) {
948 const SExtInst *SExt = cast<SExtInst>(
I);
953 unsigned In = getRegForValue(Op);
956 unsigned Reg = signExtend(In, Op, From, To);
960 updateValueMap(SExt, Reg);
964 bool WebAssemblyFastISel::selectICmp(
const Instruction *I) {
965 const ICmpInst *ICmp = cast<ICmpInst>(
I);
972 Opc = I32 ? WebAssembly::EQ_I32 : WebAssembly::EQ_I64;
975 Opc = I32 ? WebAssembly::NE_I32 : WebAssembly::NE_I64;
978 Opc = I32 ? WebAssembly::GT_U_I32 : WebAssembly::GT_U_I64;
981 Opc = I32 ? WebAssembly::GE_U_I32 : WebAssembly::GE_U_I64;
984 Opc = I32 ? WebAssembly::LT_U_I32 : WebAssembly::LT_U_I64;
987 Opc = I32 ? WebAssembly::LE_U_I32 : WebAssembly::LE_U_I64;
990 Opc = I32 ? WebAssembly::GT_S_I32 : WebAssembly::GT_S_I64;
994 Opc = I32 ? WebAssembly::GE_S_I32 : WebAssembly::GE_S_I64;
998 Opc = I32 ? WebAssembly::LT_S_I32 : WebAssembly::LT_S_I64;
1002 Opc = I32 ? WebAssembly::LE_S_I32 : WebAssembly::LE_S_I64;
1005 default:
return false;
1016 unsigned ResultReg = createResultReg(&WebAssembly::I32RegClass);
1017 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), ResultReg)
1020 updateValueMap(ICmp, ResultReg);
1024 bool WebAssemblyFastISel::selectFCmp(
const Instruction *I) {
1025 const FCmpInst *FCmp = cast<FCmpInst>(
I);
1027 unsigned LHS = getRegForValue(FCmp->
getOperand(0));
1031 unsigned RHS = getRegForValue(FCmp->
getOperand(1));
1040 Opc = F32 ? WebAssembly::EQ_F32 : WebAssembly::EQ_F64;
1043 Opc = F32 ? WebAssembly::NE_F32 : WebAssembly::NE_F64;
1046 Opc = F32 ? WebAssembly::GT_F32 : WebAssembly::GT_F64;
1049 Opc = F32 ? WebAssembly::GE_F32 : WebAssembly::GE_F64;
1052 Opc = F32 ? WebAssembly::LT_F32 : WebAssembly::LT_F64;
1055 Opc = F32 ? WebAssembly::LE_F32 : WebAssembly::LE_F64;
1058 Opc = F32 ? WebAssembly::LE_F32 : WebAssembly::LE_F64;
1062 Opc = F32 ? WebAssembly::LT_F32 : WebAssembly::LT_F64;
1066 Opc = F32 ? WebAssembly::GE_F32 : WebAssembly::GE_F64;
1070 Opc = F32 ? WebAssembly::GT_F32 : WebAssembly::GT_F64;
1077 unsigned ResultReg = createResultReg(&WebAssembly::I32RegClass);
1078 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), ResultReg)
1083 ResultReg = notValue(ResultReg);
1085 updateValueMap(FCmp, ResultReg);
1089 bool WebAssemblyFastISel::selectBitCast(
const Instruction *I) {
1094 EVT RetVT = TLI.getValueType(DL, I->
getType());
1104 updateValueMap(I, In);
1114 assert(Iter->isBitcast());
1116 updateValueMap(I, Reg);
1120 bool WebAssemblyFastISel::selectLoad(
const Instruction *I) {
1135 switch (getSimpleType(Load->
getType())) {
1138 Opc = WebAssembly::LOAD8_U_I32;
1139 RC = &WebAssembly::I32RegClass;
1142 Opc = WebAssembly::LOAD16_U_I32;
1143 RC = &WebAssembly::I32RegClass;
1146 Opc = WebAssembly::LOAD_I32;
1147 RC = &WebAssembly::I32RegClass;
1150 Opc = WebAssembly::LOAD_I64;
1151 RC = &WebAssembly::I64RegClass;
1154 Opc = WebAssembly::LOAD_F32;
1155 RC = &WebAssembly::F32RegClass;
1158 Opc = WebAssembly::LOAD_F64;
1159 RC = &WebAssembly::F64RegClass;
1165 materializeLoadStoreOperands(Addr);
1167 unsigned ResultReg = createResultReg(RC);
1168 auto MIB =
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc),
1171 addLoadStoreOperands(Addr, MIB, createMachineMemOperandFor(Load));
1173 updateValueMap(Load, ResultReg);
1177 bool WebAssemblyFastISel::selectStore(
const Instruction *I) {
1181 if (!Subtarget->hasSIMD128() &&
1190 bool VTIsi1 =
false;
1196 Opc = WebAssembly::STORE8_I32;
1199 Opc = WebAssembly::STORE16_I32;
1202 Opc = WebAssembly::STORE_I32;
1205 Opc = WebAssembly::STORE_I64;
1208 Opc = WebAssembly::STORE_F32;
1211 Opc = WebAssembly::STORE_F64;
1213 default:
return false;
1216 materializeLoadStoreOperands(Addr);
1224 auto MIB =
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc));
1226 addLoadStoreOperands(Addr, MIB, createMachineMemOperandFor(Store));
1228 MIB.addReg(ValueReg);
1232 bool WebAssemblyFastISel::selectBr(
const Instruction *I) {
1244 unsigned CondReg = getRegForI1Value(Br->
getCondition(), Not);
1248 unsigned Opc = WebAssembly::BR_IF;
1250 Opc = WebAssembly::BR_UNLESS;
1252 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc))
1256 finishCondBranch(Br->
getParent(), TBB, FBB);
1260 bool WebAssemblyFastISel::selectRet(
const Instruction *I) {
1261 if (!FuncInfo.CanLowerReturn)
1267 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1268 TII.get(WebAssembly::RETURN_VOID));
1277 switch (getSimpleType(RV->
getType())) {
1280 Opc = WebAssembly::RETURN_I32;
1283 Opc = WebAssembly::RETURN_I64;
1286 Opc = WebAssembly::RETURN_F32;
1289 Opc = WebAssembly::RETURN_F64;
1292 Opc = WebAssembly::RETURN_v16i8;
1295 Opc = WebAssembly::RETURN_v8i16;
1298 Opc = WebAssembly::RETURN_v4i32;
1301 Opc = WebAssembly::RETURN_v4f32;
1304 Opc = WebAssembly::RETURN_EXCEPT_REF;
1306 default:
return false;
1310 if (FuncInfo.Fn->getAttributes().hasAttribute(0, Attribute::SExt))
1311 Reg = getRegForSignedValue(RV);
1312 else if (FuncInfo.Fn->getAttributes().hasAttribute(0, Attribute::ZExt))
1313 Reg = getRegForUnsignedValue(RV);
1315 Reg = getRegForValue(RV);
1320 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc)).addReg(Reg);
1324 bool WebAssemblyFastISel::selectUnreachable(
const Instruction *I) {
1325 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1326 TII.get(WebAssembly::UNREACHABLE));
1330 bool WebAssemblyFastISel::fastSelectInstruction(
const Instruction *I) {
1337 case Instruction::Trunc:
return selectTrunc(I);
1338 case Instruction::ZExt:
return selectZExt(I);
1339 case Instruction::SExt:
return selectSExt(I);
1340 case Instruction::ICmp:
return selectICmp(I);
1341 case Instruction::FCmp:
return selectFCmp(I);
1342 case Instruction::BitCast:
return selectBitCast(I);
1345 case Instruction::Br:
return selectBr(I);
1347 case Instruction::Unreachable:
return selectUnreachable(I);
1352 return selectOperator(I, I->
getOpcode());
1357 return new WebAssemblyFastISel(FuncInfo, LibInfo);
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
Return a value (possibly void), from a function.
Value * getValueOperand()
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
void push_back(const T &Elt)
Function * getCalledFunction() const
Return the function called, or null if this is an indirect function invocation.
Compute iterated dominance frontiers using a linear time algorithm.
bool isAtomic() const
Return true if this instruction has an AtomicOrdering of unordered or higher.
This class represents zero extension of integer types.
This class represents a function call, abstracting a target machine's calling convention.
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
gep_type_iterator gep_type_end(const User *GEP)
const Value * getTrueValue() const
0 1 0 0 True if ordered and less than
1 1 1 0 True if unordered or not equal
BasicBlock * getSuccessor(unsigned i) const
unsigned const TargetRegisterInfo * TRI
This class represents a sign extension of integer types.
An instruction for reading from memory.
Value * getCondition() const
const MachineInstrBuilder & addGlobalAddress(const GlobalValue *GV, int64_t Offset=0, unsigned char TargetFlags=0) const
bool isVectorTy() const
True if this is an instance of VectorType.
bool isMustTailCall() const
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end...
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 class represents the LLVM 'select' instruction.
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
FunctionType * getFunctionType() const
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
unsigned getSizeInBits() const
This is a fast-path instruction selection class that generates poor code and doesn't support illegal ...
Class to represent function types.
A constant value that is initialized with an expression using other constant values.
This file declares the WebAssembly-specific subclass of TargetMachine.
Type * getType() const
All values are typed, get the type of this value.
This instruction compares its operands according to the predicate given to the constructor.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
AttributeList getAttributes() const
Return the attribute list for this Function.
An instruction for storing to memory.
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
AttributeList getAttributes() const
Return the parameter attributes for this call.
This class represents a truncation of integer types.
static const Value * getNotArgument(const Value *BinOp)
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.
Conditional or Unconditional Branch instruction.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
This file provides WebAssembly-specific target descriptions.
This instruction compares its operands according to the predicate given to the constructor.
Value * getPointerOperand()
static bool isNot(const Value *V)
const MachineInstrBuilder & addFrameIndex(int Idx) const
const Value * getCondition() 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.
unsigned getNumOperands() const
bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
Equivalent to hasAttribute(ArgNo + FirstArgIndex, Kind).
This is the shared class of boolean and integer constants.
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.
const Value * getFalseValue() const
amdgpu Simplify well known AMD library false Value Value * Arg
Predicate getPredicate() const
Return the predicate for this instruction.
This class is derived from MachineFunctionInfo and contains private WebAssembly-specific information ...
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
bool isInlineAsm() const
Check if this call is an inline asm statement.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
uint64_t getElementOffset(unsigned Idx) const
unsigned getNumArgOperands() const
Return the number of call arguments.
unsigned greater or equal
static bool isSigned(Value *V)
Can the given value generate sign bits.
FunctionLoweringInfo - This contains information that is global to a function that is used when lower...
This file declares WebAssembly-specific per-machine-function information.
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
bool isUnconditional() const
1 0 1 0 True if unordered or greater than
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
0 0 0 1 True if ordered and equal
LLVM Value Representation.
unsigned getSizeInBits(unsigned Reg, const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI) const
Get the size in bits of Reg.
1 0 1 1 True if unordered, greater than, or equal
const Value * getCalledValue() const
Get a pointer to the function that is invoked by this instruction.
bool hasOneUse() const
Return true if there is exactly one user of this value.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
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
Value * getPointerOperand()
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
iterator_range< arg_iterator > args()
bool isStructTy() const
True if this is an instance of StructType.
bool isArrayTy() const
True if this is an instance of ArrayType.
const BasicBlock * getParent() const
an instruction to allocate memory on the stack
gep_type_iterator gep_type_begin(const User *GEP)