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);
137 if (Subtarget->hasSIMD128())
146 void materializeLoadStoreOperands(
Address &Addr);
149 unsigned maskI1Value(
unsigned Reg,
const Value *V);
150 unsigned getRegForI1Value(
const Value *V,
bool &Not);
151 unsigned zeroExtendToI32(
unsigned Reg,
const Value *V,
153 unsigned signExtendToI32(
unsigned Reg,
const Value *V,
155 unsigned zeroExtend(
unsigned Reg,
const Value *V,
158 unsigned signExtend(
unsigned Reg,
const Value *V,
161 unsigned getRegForUnsignedValue(
const Value *V);
162 unsigned getRegForSignedValue(
const Value *V);
163 unsigned getRegForPromotedValue(
const Value *V,
bool IsSigned);
164 unsigned notValue(
unsigned Reg);
165 unsigned copyValue(
unsigned Reg);
168 unsigned fastMaterializeAlloca(
const AllocaInst *AI)
override;
169 unsigned fastMaterializeConstant(
const Constant *
C)
override;
170 bool fastLowerArguments()
override;
191 :
FastISel(FuncInfo, LibInfo,
true) {
196 bool fastSelectInstruction(
const Instruction *I)
override;
198 #include "WebAssemblyGenFastISel.inc"
203 bool WebAssemblyFastISel::computeAddress(
const Value *Obj,
Address &Addr) {
205 const User *U =
nullptr;
206 unsigned Opcode = Instruction::UserOp1;
207 if (
const Instruction *
I = dyn_cast<Instruction>(Obj)) {
210 if (FuncInfo.StaticAllocaMap.count(static_cast<const AllocaInst *>(Obj)) ||
211 FuncInfo.MBBMap[
I->getParent()] == FuncInfo.MBB) {
212 Opcode =
I->getOpcode();
215 }
else if (
const ConstantExpr *
C = dyn_cast<ConstantExpr>(Obj)) {
216 Opcode =
C->getOpcode();
220 if (
auto *Ty = dyn_cast<PointerType>(Obj->
getType()))
221 if (Ty->getAddressSpace() > 255)
226 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(Obj)) {
227 if (Addr.getGlobalValue())
229 Addr.setGlobalValue(GV);
236 case Instruction::BitCast: {
238 return computeAddress(U->
getOperand(0), Addr);
240 case Instruction::IntToPtr: {
243 TLI.getPointerTy(
DL))
244 return computeAddress(U->
getOperand(0), Addr);
247 case Instruction::PtrToInt: {
249 if (TLI.getValueType(
DL, U->
getType()) == TLI.getPointerTy(
DL))
250 return computeAddress(U->
getOperand(0), Addr);
253 case Instruction::GetElementPtr: {
255 uint64_t TmpOffset = Addr.getOffset();
257 if (!cast<GEPOperator>(U)->isInBounds())
258 goto unsupported_gep;
263 const Value *
Op = GTI.getOperand();
264 if (
StructType *STy = GTI.getStructTypeOrNull()) {
266 unsigned Idx = cast<ConstantInt>(
Op)->getZExtValue();
271 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(Op)) {
273 TmpOffset += CI->getSExtValue() * S;
276 if (S == 1 && Addr.isRegBase() && Addr.getReg() == 0) {
278 Addr.setReg(getRegForValue(Op));
281 if (canFoldAddIntoGEP(U, Op)) {
284 cast<ConstantInt>(cast<AddOperator>(
Op)->getOperand(1));
287 Op = cast<AddOperator>(
Op)->getOperand(0);
291 goto unsupported_gep;
296 if (int64_t(TmpOffset) >= 0) {
298 Addr.setOffset(TmpOffset);
307 case Instruction::Alloca: {
310 FuncInfo.StaticAllocaMap.find(AI);
311 if (SI != FuncInfo.StaticAllocaMap.end()) {
315 Addr.setKind(Address::FrameIndexBase);
316 Addr.setFI(SI->second);
326 if (isa<ConstantInt>(LHS))
329 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(RHS)) {
330 uint64_t TmpOffset = Addr.getOffset() + CI->getSExtValue();
331 if (int64_t(TmpOffset) >= 0) {
332 Addr.setOffset(TmpOffset);
333 return computeAddress(LHS, Addr);
338 if (computeAddress(LHS, Addr) && computeAddress(RHS, Addr))
344 case Instruction::Sub: {
349 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(RHS)) {
350 int64_t TmpOffset = Addr.getOffset() - CI->getSExtValue();
351 if (TmpOffset >= 0) {
352 Addr.setOffset(TmpOffset);
353 return computeAddress(LHS, Addr);
362 Addr.setReg(getRegForValue(Obj));
363 return Addr.getReg() != 0;
366 void WebAssemblyFastISel::materializeLoadStoreOperands(
Address &Addr) {
367 if (Addr.isRegBase()) {
368 unsigned Reg = Addr.getReg();
370 Reg = createResultReg(Subtarget->hasAddr64() ?
371 &WebAssembly::I64RegClass :
372 &WebAssembly::I32RegClass);
373 unsigned Opc = Subtarget->hasAddr64() ?
374 WebAssembly::CONST_I64 :
375 WebAssembly::CONST_I32;
376 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc),
Reg)
383 void WebAssemblyFastISel::addLoadStoreOperands(
const Address &Addr,
393 MIB.
addImm(Addr.getOffset());
395 if (Addr.isRegBase())
396 MIB.
addReg(Addr.getReg());
403 unsigned WebAssemblyFastISel::maskI1Value(
unsigned Reg,
const Value *V) {
404 return zeroExtendToI32(Reg, V,
MVT::i1);
407 unsigned WebAssemblyFastISel::getRegForI1Value(
const Value *V,
bool &Not) {
408 if (
const ICmpInst *ICmp = dyn_cast<ICmpInst>(V))
409 if (
const ConstantInt *
C = dyn_cast<ConstantInt>(ICmp->getOperand(1)))
410 if (ICmp->isEquality() &&
C->isZero() &&
C->getType()->isIntegerTy(32)) {
411 Not = ICmp->isTrueWhenEqual();
412 return getRegForValue(ICmp->getOperand(0));
421 return maskI1Value(getRegForValue(V), V);
424 unsigned WebAssemblyFastISel::zeroExtendToI32(
unsigned Reg,
const Value *V,
433 if (From ==
MVT::i1 && V !=
nullptr) {
434 if (isa<CmpInst>(V) ||
435 (isa<Argument>(V) && cast<Argument>(V)->hasZExtAttr()))
436 return copyValue(Reg);
442 return copyValue(Reg);
447 unsigned Imm = createResultReg(&WebAssembly::I32RegClass);
448 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
449 TII.get(WebAssembly::CONST_I32), Imm)
452 unsigned Result = createResultReg(&WebAssembly::I32RegClass);
453 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
454 TII.get(WebAssembly::AND_I32), Result)
461 unsigned WebAssemblyFastISel::signExtendToI32(
unsigned Reg,
const Value *V,
472 return copyValue(Reg);
477 unsigned Imm = createResultReg(&WebAssembly::I32RegClass);
478 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
479 TII.get(WebAssembly::CONST_I32), Imm)
482 unsigned Left = createResultReg(&WebAssembly::I32RegClass);
483 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
488 unsigned Right = createResultReg(&WebAssembly::I32RegClass);
489 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
490 TII.get(WebAssembly::SHR_S_I32), Right)
497 unsigned WebAssemblyFastISel::zeroExtend(
unsigned Reg,
const Value *V,
502 return copyValue(Reg);
504 Reg = zeroExtendToI32(Reg, V, From);
506 unsigned Result = createResultReg(&WebAssembly::I64RegClass);
507 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
508 TII.get(WebAssembly::I64_EXTEND_U_I32), Result)
513 return zeroExtendToI32(Reg, V, From);
516 unsigned WebAssemblyFastISel::signExtend(
unsigned Reg,
const Value *V,
521 return copyValue(Reg);
523 Reg = signExtendToI32(Reg, V, From);
525 unsigned Result = createResultReg(&WebAssembly::I64RegClass);
526 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
527 TII.get(WebAssembly::I64_EXTEND_S_I32), Result)
532 return signExtendToI32(Reg, V, From);
535 unsigned WebAssemblyFastISel::getRegForUnsignedValue(
const Value *V) {
538 return zeroExtend(getRegForValue(V), V, From, To);
541 unsigned WebAssemblyFastISel::getRegForSignedValue(
const Value *V) {
544 return zeroExtend(getRegForValue(V), V, From, To);
547 unsigned WebAssemblyFastISel::getRegForPromotedValue(
const Value *V,
549 return IsSigned ? getRegForSignedValue(V) :
550 getRegForUnsignedValue(V);
553 unsigned WebAssemblyFastISel::notValue(
unsigned Reg) {
554 assert(
MRI.getRegClass(Reg) == &WebAssembly::I32RegClass);
556 unsigned NotReg = createResultReg(&WebAssembly::I32RegClass);
557 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
558 TII.get(WebAssembly::EQZ_I32), NotReg)
563 unsigned WebAssemblyFastISel::copyValue(
unsigned Reg) {
564 unsigned ResultReg = createResultReg(
MRI.getRegClass(Reg));
565 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
566 TII.get(WebAssembly::COPY), ResultReg)
571 unsigned WebAssemblyFastISel::fastMaterializeAlloca(
const AllocaInst *AI) {
573 FuncInfo.StaticAllocaMap.
find(AI);
575 if (SI != FuncInfo.StaticAllocaMap.
end()) {
576 unsigned ResultReg = createResultReg(Subtarget->hasAddr64() ?
577 &WebAssembly::I64RegClass :
578 &WebAssembly::I32RegClass);
579 unsigned Opc = Subtarget->hasAddr64() ?
580 WebAssembly::COPY_I64 :
581 WebAssembly::COPY_I32;
582 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), ResultReg)
583 .addFrameIndex(SI->second);
590 unsigned WebAssemblyFastISel::fastMaterializeConstant(
const Constant *
C) {
591 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(C)) {
592 unsigned ResultReg = createResultReg(Subtarget->hasAddr64() ?
593 &WebAssembly::I64RegClass :
594 &WebAssembly::I32RegClass);
595 unsigned Opc = Subtarget->hasAddr64() ?
596 WebAssembly::CONST_I64 :
597 WebAssembly::CONST_I32;
598 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), ResultReg)
599 .addGlobalAddress(GV);
607 bool WebAssemblyFastISel::fastLowerArguments() {
608 if (!FuncInfo.CanLowerReturn)
616 for (
auto const &Arg : F->
args()) {
625 Type *ArgTy = Arg.getType();
628 if (!Subtarget->hasSIMD128() && ArgTy->
isVectorTy())
633 switch (getSimpleType(ArgTy)) {
638 Opc = WebAssembly::ARGUMENT_I32;
639 RC = &WebAssembly::I32RegClass;
642 Opc = WebAssembly::ARGUMENT_I64;
643 RC = &WebAssembly::I64RegClass;
646 Opc = WebAssembly::ARGUMENT_F32;
647 RC = &WebAssembly::F32RegClass;
650 Opc = WebAssembly::ARGUMENT_F64;
651 RC = &WebAssembly::F64RegClass;
654 Opc = WebAssembly::ARGUMENT_v16i8;
655 RC = &WebAssembly::V128RegClass;
658 Opc = WebAssembly::ARGUMENT_v8i16;
659 RC = &WebAssembly::V128RegClass;
662 Opc = WebAssembly::ARGUMENT_v4i32;
663 RC = &WebAssembly::V128RegClass;
666 Opc = WebAssembly::ARGUMENT_v4f32;
667 RC = &WebAssembly::V128RegClass;
672 unsigned ResultReg = createResultReg(RC);
673 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), ResultReg)
675 updateValueMap(&Arg, ResultReg);
680 MRI.addLiveIn(WebAssembly::ARGUMENTS);
683 for (
auto const &Arg : F->
args())
684 MFI->
addParam(getLegalType(getSimpleType(Arg.getType())));
687 MFI->addResult(getLegalType(getSimpleType(F->
getReturnType())));
692 bool WebAssemblyFastISel::selectCall(
const Instruction *
I) {
705 bool IsDirect = Func !=
nullptr;
709 Opc = IsDirect ? WebAssembly::CALL_VOID : WebAssembly::PCALL_INDIRECT_VOID;
720 Opc = IsDirect ? WebAssembly::CALL_I32 : WebAssembly::PCALL_INDIRECT_I32;
721 ResultReg = createResultReg(&WebAssembly::I32RegClass);
724 Opc = IsDirect ? WebAssembly::CALL_I64 : WebAssembly::PCALL_INDIRECT_I64;
725 ResultReg = createResultReg(&WebAssembly::I64RegClass);
728 Opc = IsDirect ? WebAssembly::CALL_F32 : WebAssembly::PCALL_INDIRECT_F32;
729 ResultReg = createResultReg(&WebAssembly::F32RegClass);
732 Opc = IsDirect ? WebAssembly::CALL_F64 : WebAssembly::PCALL_INDIRECT_F64;
733 ResultReg = createResultReg(&WebAssembly::F64RegClass);
737 IsDirect ? WebAssembly::CALL_v16i8 : WebAssembly::PCALL_INDIRECT_v16i8;
738 ResultReg = createResultReg(&WebAssembly::V128RegClass);
742 IsDirect ? WebAssembly::CALL_v8i16 : WebAssembly::PCALL_INDIRECT_v8i16;
743 ResultReg = createResultReg(&WebAssembly::V128RegClass);
747 IsDirect ? WebAssembly::CALL_v4i32 : WebAssembly::PCALL_INDIRECT_v4i32;
748 ResultReg = createResultReg(&WebAssembly::V128RegClass);
752 IsDirect ? WebAssembly::CALL_v4f32 : WebAssembly::PCALL_INDIRECT_v4f32;
753 ResultReg = createResultReg(&WebAssembly::V128RegClass);
778 Reg = getRegForSignedValue(V);
780 Reg = getRegForUnsignedValue(V);
782 Reg = getRegForValue(V);
790 auto MIB =
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc));
800 for (
unsigned ArgReg : Args)
804 updateValueMap(Call, ResultReg);
808 bool WebAssemblyFastISel::selectSelect(
const Instruction *I) {
812 unsigned CondReg = getRegForI1Value(Select->
getCondition(), Not);
816 unsigned TrueReg = getRegForValue(Select->
getTrueValue());
829 switch (getSimpleType(Select->
getType())) {
834 Opc = WebAssembly::SELECT_I32;
835 RC = &WebAssembly::I32RegClass;
838 Opc = WebAssembly::SELECT_I64;
839 RC = &WebAssembly::I64RegClass;
842 Opc = WebAssembly::SELECT_F32;
843 RC = &WebAssembly::F32RegClass;
846 Opc = WebAssembly::SELECT_F64;
847 RC = &WebAssembly::F64RegClass;
853 unsigned ResultReg = createResultReg(RC);
854 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), ResultReg)
859 updateValueMap(Select, ResultReg);
863 bool WebAssemblyFastISel::selectTrunc(
const Instruction *I) {
866 unsigned Reg = getRegForValue(Trunc->
getOperand(0));
871 unsigned Result = createResultReg(&WebAssembly::I32RegClass);
872 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
873 TII.get(WebAssembly::I32_WRAP_I64), Result)
878 updateValueMap(Trunc, Reg);
882 bool WebAssemblyFastISel::selectZExt(
const Instruction *I) {
883 const ZExtInst *ZExt = cast<ZExtInst>(
I);
888 unsigned Reg = zeroExtend(getRegForValue(Op), Op, From, To);
892 updateValueMap(ZExt, Reg);
896 bool WebAssemblyFastISel::selectSExt(
const Instruction *I) {
897 const SExtInst *SExt = cast<SExtInst>(
I);
902 unsigned Reg = signExtend(getRegForValue(Op), Op, From, To);
906 updateValueMap(SExt, Reg);
910 bool WebAssemblyFastISel::selectICmp(
const Instruction *I) {
911 const ICmpInst *ICmp = cast<ICmpInst>(
I);
915 bool isSigned =
false;
918 Opc = I32 ? WebAssembly::EQ_I32 : WebAssembly::EQ_I64;
921 Opc = I32 ? WebAssembly::NE_I32 : WebAssembly::NE_I64;
924 Opc = I32 ? WebAssembly::GT_U_I32 : WebAssembly::GT_U_I64;
927 Opc = I32 ? WebAssembly::GE_U_I32 : WebAssembly::GE_U_I64;
930 Opc = I32 ? WebAssembly::LT_U_I32 : WebAssembly::LT_U_I64;
933 Opc = I32 ? WebAssembly::LE_U_I32 : WebAssembly::LE_U_I64;
936 Opc = I32 ? WebAssembly::GT_S_I32 : WebAssembly::GT_S_I64;
940 Opc = I32 ? WebAssembly::GE_S_I32 : WebAssembly::GE_S_I64;
944 Opc = I32 ? WebAssembly::LT_S_I32 : WebAssembly::LT_S_I64;
948 Opc = I32 ? WebAssembly::LE_S_I32 : WebAssembly::LE_S_I64;
951 default:
return false;
954 unsigned LHS = getRegForPromotedValue(ICmp->
getOperand(0), isSigned);
958 unsigned RHS = getRegForPromotedValue(ICmp->
getOperand(1), isSigned);
962 unsigned ResultReg = createResultReg(&WebAssembly::I32RegClass);
963 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), ResultReg)
966 updateValueMap(ICmp, ResultReg);
970 bool WebAssemblyFastISel::selectFCmp(
const Instruction *I) {
971 const FCmpInst *FCmp = cast<FCmpInst>(
I);
973 unsigned LHS = getRegForValue(FCmp->
getOperand(0));
977 unsigned RHS = getRegForValue(FCmp->
getOperand(1));
986 Opc = F32 ? WebAssembly::EQ_F32 : WebAssembly::EQ_F64;
989 Opc = F32 ? WebAssembly::NE_F32 : WebAssembly::NE_F64;
992 Opc = F32 ? WebAssembly::GT_F32 : WebAssembly::GT_F64;
995 Opc = F32 ? WebAssembly::GE_F32 : WebAssembly::GE_F64;
998 Opc = F32 ? WebAssembly::LT_F32 : WebAssembly::LT_F64;
1001 Opc = F32 ? WebAssembly::LE_F32 : WebAssembly::LE_F64;
1004 Opc = F32 ? WebAssembly::LE_F32 : WebAssembly::LE_F64;
1008 Opc = F32 ? WebAssembly::LT_F32 : WebAssembly::LT_F64;
1012 Opc = F32 ? WebAssembly::GE_F32 : WebAssembly::GE_F64;
1016 Opc = F32 ? WebAssembly::GT_F32 : WebAssembly::GT_F64;
1023 unsigned ResultReg = createResultReg(&WebAssembly::I32RegClass);
1024 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc), ResultReg)
1029 ResultReg = notValue(ResultReg);
1031 updateValueMap(FCmp, ResultReg);
1035 bool WebAssemblyFastISel::selectBitCast(
const Instruction *I) {
1046 updateValueMap(I, getRegForValue(I->
getOperand(0)));
1057 assert(Iter->isBitcast());
1059 updateValueMap(I, Reg);
1063 bool WebAssemblyFastISel::selectLoad(
const Instruction *I) {
1078 switch (getSimpleType(Load->
getType())) {
1081 Opc = WebAssembly::LOAD8_U_I32;
1082 RC = &WebAssembly::I32RegClass;
1085 Opc = WebAssembly::LOAD16_U_I32;
1086 RC = &WebAssembly::I32RegClass;
1089 Opc = WebAssembly::LOAD_I32;
1090 RC = &WebAssembly::I32RegClass;
1093 Opc = WebAssembly::LOAD_I64;
1094 RC = &WebAssembly::I64RegClass;
1097 Opc = WebAssembly::LOAD_F32;
1098 RC = &WebAssembly::F32RegClass;
1101 Opc = WebAssembly::LOAD_F64;
1102 RC = &WebAssembly::F64RegClass;
1108 materializeLoadStoreOperands(Addr);
1110 unsigned ResultReg = createResultReg(RC);
1111 auto MIB =
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc),
1114 addLoadStoreOperands(Addr, MIB, createMachineMemOperandFor(Load));
1116 updateValueMap(Load, ResultReg);
1120 bool WebAssemblyFastISel::selectStore(
const Instruction *I) {
1124 if (!Subtarget->hasSIMD128() &&
1133 bool VTIsi1 =
false;
1138 Opc = WebAssembly::STORE8_I32;
1141 Opc = WebAssembly::STORE16_I32;
1144 Opc = WebAssembly::STORE_I32;
1147 Opc = WebAssembly::STORE_I64;
1150 Opc = WebAssembly::STORE_F32;
1153 Opc = WebAssembly::STORE_F64;
1155 default:
return false;
1158 materializeLoadStoreOperands(Addr);
1166 auto MIB =
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc));
1168 addLoadStoreOperands(Addr, MIB, createMachineMemOperandFor(Store));
1170 MIB.addReg(ValueReg);
1174 bool WebAssemblyFastISel::selectBr(
const Instruction *I) {
1186 unsigned CondReg = getRegForI1Value(Br->
getCondition(), Not);
1190 unsigned Opc = WebAssembly::BR_IF;
1192 Opc = WebAssembly::BR_UNLESS;
1194 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc))
1198 finishCondBranch(Br->
getParent(), TBB, FBB);
1202 bool WebAssemblyFastISel::selectRet(
const Instruction *I) {
1203 if (!FuncInfo.CanLowerReturn)
1209 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1210 TII.get(WebAssembly::RETURN_VOID));
1219 switch (getSimpleType(RV->
getType())) {
1222 Opc = WebAssembly::RETURN_I32;
1225 Opc = WebAssembly::RETURN_I64;
1228 Opc = WebAssembly::RETURN_F32;
1231 Opc = WebAssembly::RETURN_F64;
1234 Opc = WebAssembly::RETURN_v16i8;
1237 Opc = WebAssembly::RETURN_v8i16;
1240 Opc = WebAssembly::RETURN_v4i32;
1243 Opc = WebAssembly::RETURN_v4f32;
1245 default:
return false;
1249 if (FuncInfo.Fn->getAttributes().hasAttribute(0, Attribute::SExt))
1250 Reg = getRegForSignedValue(RV);
1251 else if (FuncInfo.Fn->getAttributes().hasAttribute(0, Attribute::ZExt))
1252 Reg = getRegForUnsignedValue(RV);
1254 Reg = getRegForValue(RV);
1259 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(Opc)).addReg(Reg);
1263 bool WebAssemblyFastISel::selectUnreachable(
const Instruction *I) {
1264 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1265 TII.get(WebAssembly::UNREACHABLE));
1269 bool WebAssemblyFastISel::fastSelectInstruction(
const Instruction *I) {
1276 case Instruction::Trunc:
return selectTrunc(I);
1277 case Instruction::ZExt:
return selectZExt(I);
1278 case Instruction::SExt:
return selectSExt(I);
1279 case Instruction::ICmp:
return selectICmp(I);
1280 case Instruction::FCmp:
return selectFCmp(I);
1281 case Instruction::BitCast:
return selectBitCast(I);
1284 case Instruction::Br:
return selectBr(I);
1286 case Instruction::Unreachable:
return selectUnreachable(I);
1291 return selectOperator(I, I->
getOpcode());
1296 return new WebAssemblyFastISel(FuncInfo, LibInfo);
Return a value (possibly void), from a function.
Value * getValueOperand()
const Value * getCalledValue() const
Get a pointer to the function that is invoked by this instruction.
void push_back(const T &Elt)
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
This class represents zero extension of integer types.
unsigned getNumOperands() const
This class represents a function call, abstracting a target machine's calling convention.
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
gep_type_iterator gep_type_end(const User *GEP)
0 1 0 0 True if ordered and less than
unsigned getSizeInBits() const
1 1 1 0 True if unordered or not equal
This class represents a sign extension of integer types.
An instruction for reading from memory.
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end...
AttributeList getAttributes() const
Return the attribute list for this Function.
FastISel * createFastISel(FunctionLoweringInfo &funcInfo, const TargetLibraryInfo *libInfo)
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
bool isUnconditional() const
A description of a memory reference used in the backend.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
This class represents the LLVM 'select' instruction.
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
const HexagonInstrInfo * TII
const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
Class to represent struct types.
unsigned getNumArgOperands() const
Return the number of call arguments.
Reg
All possible values of the reg field in the ModR/M byte.
0 1 0 1 True if ordered and less than or equal
bool isMustTailCall() const
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
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.
bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
Equivalent to hasAttribute(ArgNo + FirstArgIndex, Kind).
This instruction compares its operands according to the predicate given to the constructor.
BasicBlock * getSuccessor(unsigned i) const
An instruction for storing to memory.
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
bool isArrayTy() const
True if this is an instance of ArrayType.
This class represents a truncation of integer types.
bool isAtomic() const
Return true if this instruction has an AtomicOrdering of unordered or higher.
static const Value * getNotArgument(const Value *BinOp)
iterator find(const_arg_type_t< KeyT > Val)
uint64_t getElementOffset(unsigned Idx) const
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
Type * getReturnType() const
Returns the type of the ret val.
unsigned const MachineRegisterInfo * MRI
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.
bool isVectorTy() const
True if this is an instance of VectorType.
static unsigned getSizeInBits(unsigned Reg, const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI)
Get the size in bits of Reg.
This is an important base class in LLVM.
const Value * getCondition() const
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
This file provides WebAssembly-specific target descriptions.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
This instruction compares its operands according to the predicate given to the constructor.
Value * getOperand(unsigned i) const
Value * getPointerOperand()
static bool isNot(const Value *V)
Predicate getPredicate() const
Return the predicate for this instruction.
const Value * getTrueValue() const
1 1 0 1 True if unordered, less than, or equal
FunctionType * getFunctionType() const
0 0 1 0 True if ordered and greater than
This file declares the WebAssembly-specific subclass of TargetSubtarget.
This is the shared class of boolean and integer constants.
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
1 1 0 0 True if unordered or less than
Type * getType() const
All values are typed, get the type of this value.
Provides information about what library functions are available for the current target.
Function * getCalledFunction() const
Return the function called, or null if this is an indirect function invocation.
const MachineInstrBuilder & addFrameIndex(int Idx) const
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
bool isIntegerTy() const
True if this is an instance of IntegerType.
This file defines the FastISel class.
bool isInlineAsm() const
Check if this call is an inline asm statement.
const MachineInstrBuilder & addGlobalAddress(const GlobalValue *GV, int64_t Offset=0, unsigned char TargetFlags=0) const
bool isStructTy() const
True if this is an instance of StructType.
This class is derived from MachineFunctionInfo and contains private WebAssembly-specific information ...
Value * getCondition() const
unsigned greater or equal
AttributeList getAttributes() const
Return the parameter attributes for this call.
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
bool hasOneUse() const
Return true if there is exactly one user of this value.
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
Type * getReturnType() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
0 0 0 1 True if ordered and equal
LLVM Value Representation.
1 0 1 1 True if unordered, greater than, or equal
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
const Value * getFalseValue() const
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
0 0 1 1 True if ordered and greater than or equal
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Value * getPointerOperand()
const BasicBlock * getParent() const
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
iterator_range< arg_iterator > args()
bool isVoidTy() const
Return true if this is 'void'.
an instruction to allocate memory on the stack
gep_type_iterator gep_type_begin(const User *GEP)