64#include "llvm/IR/IntrinsicsAMDGPU.h"
93#define DEBUG_TYPE "irtranslator"
99 cl::desc(
"Should enable CSE in irtranslator"),
117 MF.getProperties().setFailedISel();
121 if (!R.getLocation().isValid() || TPC.isGlobalISelAbortEnabled())
122 R << (
" (in function: " + MF.getName() +
")").str();
124 if (TPC.isGlobalISelAbortEnabled())
141 DILocationVerifier() =
default;
142 ~DILocationVerifier() =
default;
144 const Instruction *getCurrentInst()
const {
return CurrInst; }
145 void setCurrentInst(
const Instruction *Inst) { CurrInst = Inst; }
152 assert(getCurrentInst() &&
"Inserted instruction without a current MI");
157 <<
" was copied to " <<
MI);
163 (
MI.getParent()->isEntryBlock() && !
MI.getDebugLoc()) ||
164 (
MI.isDebugInstr())) &&
165 "Line info was not transferred to all instructions");
188IRTranslator::allocateVRegs(
const Value &Val) {
189 auto VRegsIt = VMap.findVRegs(Val);
190 if (VRegsIt != VMap.vregs_end())
191 return *VRegsIt->second;
192 auto *Regs = VMap.getVRegs(Val);
193 auto *Offsets = VMap.getOffsets(Val);
196 Offsets->empty() ? Offsets :
nullptr);
197 for (
unsigned i = 0; i < SplitTys.
size(); ++i)
203 auto VRegsIt = VMap.findVRegs(Val);
204 if (VRegsIt != VMap.vregs_end())
205 return *VRegsIt->second;
208 return *VMap.getVRegs(Val);
211 auto *VRegs = VMap.getVRegs(Val);
212 auto *Offsets = VMap.getOffsets(Val);
216 "Don't know how to create an empty vreg");
220 Offsets->empty() ? Offsets :
nullptr);
222 if (!isa<Constant>(Val)) {
223 for (
auto Ty : SplitTys)
230 auto &
C = cast<Constant>(Val);
232 while (
auto Elt =
C.getAggregateElement(
Idx++)) {
233 auto EltRegs = getOrCreateVRegs(*Elt);
237 assert(SplitTys.size() == 1 &&
"unexpectedly split LLT");
239 bool Success = translate(cast<Constant>(Val), VRegs->front());
244 R <<
"unable to translate constant: " <<
ore::NV(
"Type", Val.
getType());
253int IRTranslator::getOrCreateFrameIndex(
const AllocaInst &AI) {
254 auto [MapEntry,
Inserted] = FrameIndices.try_emplace(&AI);
256 return MapEntry->second;
260 ElementSize * cast<ConstantInt>(AI.
getArraySize())->getZExtValue();
263 Size = std::max<uint64_t>(
Size, 1u);
265 int &FI = MapEntry->second;
271 if (
const StoreInst *SI = dyn_cast<StoreInst>(&
I))
272 return SI->getAlign();
273 if (
const LoadInst *LI = dyn_cast<LoadInst>(&
I))
274 return LI->getAlign();
281 R <<
"unable to translate memop: " <<
ore::NV(
"Opcode", &
I);
288 assert(
MBB &&
"BasicBlock was not encountered before");
293 assert(NewPred &&
"new predecessor must be a real MachineBasicBlock");
294 MachinePreds[
Edge].push_back(NewPred);
301 return U.getType()->getScalarType()->isBFloatTy() ||
303 return V->getType()->getScalarType()->isBFloatTy();
307bool IRTranslator::translateBinaryOp(
unsigned Opcode,
const User &U,
316 Register Op0 = getOrCreateVReg(*
U.getOperand(0));
317 Register Op1 = getOrCreateVReg(*
U.getOperand(1));
320 if (isa<Instruction>(U)) {
329bool IRTranslator::translateUnaryOp(
unsigned Opcode,
const User &U,
334 Register Op0 = getOrCreateVReg(*
U.getOperand(0));
337 if (isa<Instruction>(U)) {
346 return translateUnaryOp(TargetOpcode::G_FNEG, U, MIRBuilder);
349bool IRTranslator::translateCompare(
const User &U,
354 auto *CI = cast<CmpInst>(&U);
355 Register Op0 = getOrCreateVReg(*
U.getOperand(0));
356 Register Op1 = getOrCreateVReg(*
U.getOperand(1));
361 MIRBuilder.
buildICmp(Pred, Res, Op0, Op1, Flags);
369 MIRBuilder.
buildFCmp(Pred, Res, Op0, Op1, Flags);
382 VRegs = getOrCreateVRegs(*Ret);
393 return CLI->
lowerReturn(MIRBuilder, Ret, VRegs, FuncInfo, SwiftErrorVReg);
396void IRTranslator::emitBranchForMergedCondition(
402 if (
const CmpInst *BOp = dyn_cast<CmpInst>(
Cond)) {
405 Condition = InvertCond ? IC->getInversePredicate() : IC->getPredicate();
408 Condition = InvertCond ?
FC->getInversePredicate() :
FC->getPredicate();
412 BOp->getOperand(1),
nullptr,
TBB, FBB, CurBB,
413 CurBuilder->getDebugLoc(), TProb, FProb);
414 SL->SwitchCases.push_back(CB);
422 nullptr,
TBB, FBB, CurBB, CurBuilder->getDebugLoc(), TProb, FProb);
423 SL->SwitchCases.push_back(CB);
428 return I->getParent() == BB;
432void IRTranslator::findMergedConditions(
437 using namespace PatternMatch;
438 assert((
Opc == Instruction::And ||
Opc == Instruction::Or) &&
439 "Expected Opc to be AND/OR");
445 findMergedConditions(NotCond,
TBB, FBB, CurBB, SwitchBB,
Opc, TProb, FProb,
451 const Value *BOpOp0, *BOpOp1;
465 if (BOpc == Instruction::And)
466 BOpc = Instruction::Or;
467 else if (BOpc == Instruction::Or)
468 BOpc = Instruction::And;
474 bool BOpIsInOrAndTree = BOpc && BOpc ==
Opc && BOp->
hasOneUse();
478 emitBranchForMergedCondition(
Cond,
TBB, FBB, CurBB, SwitchBB, TProb, FProb,
489 if (
Opc == Instruction::Or) {
510 auto NewTrueProb = TProb / 2;
511 auto NewFalseProb = TProb / 2 + FProb;
513 findMergedConditions(BOpOp0,
TBB, TmpBB, CurBB, SwitchBB,
Opc, NewTrueProb,
514 NewFalseProb, InvertCond);
520 findMergedConditions(BOpOp1,
TBB, FBB, TmpBB, SwitchBB,
Opc, Probs[0],
521 Probs[1], InvertCond);
523 assert(
Opc == Instruction::And &&
"Unknown merge op!");
543 auto NewTrueProb = TProb + FProb / 2;
544 auto NewFalseProb = FProb / 2;
546 findMergedConditions(BOpOp0, TmpBB, FBB, CurBB, SwitchBB,
Opc, NewTrueProb,
547 NewFalseProb, InvertCond);
553 findMergedConditions(BOpOp1,
TBB, FBB, TmpBB, SwitchBB,
Opc, Probs[0],
554 Probs[1], InvertCond);
558bool IRTranslator::shouldEmitAsBranches(
559 const std::vector<SwitchCG::CaseBlock> &Cases) {
561 if (Cases.size() != 2)
566 if ((Cases[0].CmpLHS == Cases[1].CmpLHS &&
567 Cases[0].CmpRHS == Cases[1].CmpRHS) ||
568 (Cases[0].CmpRHS == Cases[1].CmpLHS &&
569 Cases[0].CmpLHS == Cases[1].CmpRHS)) {
575 if (Cases[0].CmpRHS == Cases[1].CmpRHS &&
576 Cases[0].PredInfo.Pred == Cases[1].PredInfo.Pred &&
577 isa<Constant>(Cases[0].CmpRHS) &&
578 cast<Constant>(Cases[0].CmpRHS)->isNullValue()) {
580 Cases[0].TrueBB == Cases[1].ThisBB)
583 Cases[0].FalseBB == Cases[1].ThisBB)
591 const BranchInst &BrInst = cast<BranchInst>(U);
592 auto &CurMBB = MIRBuilder.
getMBB();
598 !CurMBB.isLayoutSuccessor(Succ0MBB))
603 CurMBB.addSuccessor(&getMBB(*Succ));
629 using namespace PatternMatch;
630 const Instruction *CondI = dyn_cast<Instruction>(CondVal);
632 !BrInst.
hasMetadata(LLVMContext::MD_unpredictable)) {
635 const Value *BOp0, *BOp1;
637 Opcode = Instruction::And;
639 Opcode = Instruction::Or;
643 findMergedConditions(CondI, Succ0MBB, Succ1MBB, &CurMBB, &CurMBB, Opcode,
644 getEdgeProbability(&CurMBB, Succ0MBB),
645 getEdgeProbability(&CurMBB, Succ1MBB),
647 assert(SL->SwitchCases[0].ThisBB == &CurMBB &&
"Unexpected lowering!");
650 if (shouldEmitAsBranches(SL->SwitchCases)) {
652 emitSwitchCase(SL->SwitchCases[0], &CurMBB, *CurBuilder);
653 SL->SwitchCases.erase(SL->SwitchCases.begin());
659 for (
unsigned I = 1, E = SL->SwitchCases.size();
I != E; ++
I)
660 MF->
erase(SL->SwitchCases[
I].ThisBB);
662 SL->SwitchCases.clear();
669 nullptr, Succ0MBB, Succ1MBB, &CurMBB,
670 CurBuilder->getDebugLoc());
674 emitSwitchCase(CB, &CurMBB, *CurBuilder);
682 Src->addSuccessorWithoutProb(Dst);
686 Prob = getEdgeProbability(Src, Dst);
687 Src->addSuccessor(Dst, Prob);
693 const BasicBlock *SrcBB = Src->getBasicBlock();
694 const BasicBlock *DstBB = Dst->getBasicBlock();
698 auto SuccSize = std::max<uint32_t>(
succ_size(SrcBB), 1);
705 using namespace SwitchCG;
710 Clusters.reserve(
SI.getNumCases());
711 for (
const auto &
I :
SI.cases()) {
713 assert(Succ &&
"Could not find successor mbb in mapping");
718 Clusters.push_back(CaseCluster::range(CaseVal, CaseVal, Succ, Prob));
731 if (Clusters.empty()) {
738 SL->findJumpTables(Clusters, &SI, std::nullopt, DefaultMBB,
nullptr,
nullptr);
739 SL->findBitTestClusters(Clusters, &SI);
742 dbgs() <<
"Case clusters: ";
743 for (
const CaseCluster &
C : Clusters) {
744 if (
C.Kind == CC_JumpTable)
746 if (
C.Kind == CC_BitTests)
749 C.Low->getValue().print(
dbgs(),
true);
750 if (
C.Low !=
C.High) {
752 C.High->getValue().print(
dbgs(),
true);
759 assert(!Clusters.empty());
763 auto DefaultProb = getEdgeProbability(SwitchMBB, DefaultMBB);
764 WorkList.push_back({SwitchMBB,
First,
Last,
nullptr,
nullptr, DefaultProb});
766 while (!WorkList.empty()) {
767 SwitchWorkListItem
W = WorkList.pop_back_val();
769 unsigned NumClusters =
W.LastCluster -
W.FirstCluster + 1;
771 if (NumClusters > 3 &&
774 splitWorkItem(WorkList, W,
SI.getCondition(), SwitchMBB, MIB);
778 if (!lowerSwitchWorkItem(W,
SI.getCondition(), SwitchMBB, DefaultMBB, MIB))
788 using namespace SwitchCG;
789 assert(
W.FirstCluster->Low->getValue().slt(
W.LastCluster->Low->getValue()) &&
790 "Clusters not sorted?");
791 assert(
W.LastCluster -
W.FirstCluster + 1 >= 2 &&
"Too small to split!");
793 auto [LastLeft, FirstRight, LeftProb, RightProb] =
794 SL->computeSplitWorkItemInfo(W);
799 assert(PivotCluster >
W.FirstCluster);
800 assert(PivotCluster <=
W.LastCluster);
815 if (FirstLeft == LastLeft && FirstLeft->Kind == CC_Range &&
816 FirstLeft->Low ==
W.GE &&
817 (FirstLeft->High->getValue() + 1LL) == Pivot->
getValue()) {
818 LeftMBB = FirstLeft->MBB;
823 {LeftMBB, FirstLeft, LastLeft,
W.GE, Pivot,
W.DefaultProb / 2});
830 if (FirstRight == LastRight && FirstRight->Kind == CC_Range &&
W.LT &&
831 (FirstRight->High->getValue() + 1ULL) ==
W.LT->getValue()) {
832 RightMBB = FirstRight->MBB;
837 {RightMBB, FirstRight, LastRight, Pivot,
W.LT,
W.DefaultProb / 2});
845 if (
W.MBB == SwitchMBB)
846 emitSwitchCase(CB, SwitchMBB, MIB);
848 SL->SwitchCases.push_back(CB);
854 assert(
JT.Reg &&
"Should lower JT Header first!");
876 Register SwitchOpReg = getOrCreateVReg(SValue);
878 auto Sub = MIB.
buildSub({SwitchTy}, SwitchOpReg, FirstCst);
886 JT.Reg =
Sub.getReg(0);
897 auto Cst = getOrCreateVReg(
934 const auto *CI = dyn_cast<ConstantInt>(CB.
CmpRHS);
952 "Can only handle SLE ranges");
958 if (cast<ConstantInt>(CB.
CmpLHS)->isMinValue(
true)) {
964 auto Sub = MIB.
buildSub({CmpTy}, CmpOpReg, CondLHS);
999 bool FallthroughUnreachable) {
1000 using namespace SwitchCG;
1003 JumpTableHeader *JTH = &SL->JTCases[
I->JTCasesIndex].first;
1009 CurMF->
insert(BBI, JumpMBB);
1019 auto JumpProb =
I->Prob;
1020 auto FallthroughProb = UnhandledProbs;
1028 if (*SI == DefaultMBB) {
1029 JumpProb += DefaultProb / 2;
1030 FallthroughProb -= DefaultProb / 2;
1035 addMachineCFGPred({SwitchMBB->
getBasicBlock(), (*SI)->getBasicBlock()},
1040 if (FallthroughUnreachable)
1041 JTH->FallthroughUnreachable =
true;
1043 if (!JTH->FallthroughUnreachable)
1044 addSuccessorWithProb(CurMBB, Fallthrough, FallthroughProb);
1045 addSuccessorWithProb(CurMBB, JumpMBB, JumpProb);
1050 JTH->HeaderBB = CurMBB;
1051 JT->Default = Fallthrough;
1054 if (CurMBB == SwitchMBB) {
1055 if (!emitJumpTableHeader(*JT, *JTH, CurMBB))
1057 JTH->Emitted =
true;
1064 bool FallthroughUnreachable,
1069 using namespace SwitchCG;
1072 if (
I->Low ==
I->High) {
1088 CaseBlock CB(Pred, FallthroughUnreachable, LHS, RHS, MHS,
I->MBB, Fallthrough,
1091 emitSwitchCase(CB, SwitchMBB, MIB);
1101 Register SwitchOpReg = getOrCreateVReg(*
B.SValue);
1105 auto RangeSub = MIB.
buildSub(SwitchOpTy, SwitchOpReg, MinValReg);
1110 LLT MaskTy = SwitchOpTy;
1126 if (SwitchOpTy != MaskTy)
1134 if (!
B.FallthroughUnreachable)
1135 addSuccessorWithProb(SwitchBB,
B.Default,
B.DefaultProb);
1136 addSuccessorWithProb(SwitchBB,
MBB,
B.Prob);
1140 if (!
B.FallthroughUnreachable) {
1144 RangeSub, RangeCst);
1164 if (PopCount == 1) {
1167 auto MaskTrailingZeros =
1172 }
else if (PopCount == BB.
Range) {
1174 auto MaskTrailingOnes =
1181 auto SwitchVal = MIB.
buildShl(SwitchTy, CstOne, Reg);
1185 auto AndOp = MIB.
buildAnd(SwitchTy, SwitchVal, CstMask);
1192 addSuccessorWithProb(SwitchBB,
B.TargetBB,
B.ExtraProb);
1194 addSuccessorWithProb(SwitchBB, NextMBB, BranchProbToNext);
1212bool IRTranslator::lowerBitTestWorkItem(
1218 bool FallthroughUnreachable) {
1219 using namespace SwitchCG;
1222 BitTestBlock *BTB = &SL->BitTestCases[
I->BTCasesIndex];
1224 for (BitTestCase &BTC : BTB->Cases)
1225 CurMF->
insert(BBI, BTC.ThisBB);
1228 BTB->Parent = CurMBB;
1229 BTB->Default = Fallthrough;
1231 BTB->DefaultProb = UnhandledProbs;
1235 if (!BTB->ContiguousRange) {
1236 BTB->Prob += DefaultProb / 2;
1237 BTB->DefaultProb -= DefaultProb / 2;
1240 if (FallthroughUnreachable)
1241 BTB->FallthroughUnreachable =
true;
1244 if (CurMBB == SwitchMBB) {
1245 emitBitTestHeader(*BTB, SwitchMBB);
1246 BTB->Emitted =
true;
1256 using namespace SwitchCG;
1260 if (++BBI != FuncInfo.
MF->
end())
1269 [](
const CaseCluster &a,
const CaseCluster &b) {
1270 return a.Prob != b.Prob
1272 : a.Low->getValue().slt(b.Low->getValue());
1277 for (CaseClusterIt
I =
W.LastCluster;
I >
W.FirstCluster;) {
1279 if (
I->Prob >
W.LastCluster->Prob)
1281 if (
I->Kind == CC_Range &&
I->MBB == NextMBB) {
1291 for (CaseClusterIt
I =
W.FirstCluster;
I <=
W.LastCluster; ++
I)
1292 UnhandledProbs +=
I->Prob;
1295 for (CaseClusterIt
I =
W.FirstCluster, E =
W.LastCluster;
I <= E; ++
I) {
1296 bool FallthroughUnreachable =
false;
1298 if (
I ==
W.LastCluster) {
1300 Fallthrough = DefaultMBB;
1301 FallthroughUnreachable = isa<UnreachableInst>(
1305 CurMF->
insert(BBI, Fallthrough);
1307 UnhandledProbs -=
I->Prob;
1311 if (!lowerBitTestWorkItem(W, SwitchMBB, CurMBB, DefaultMBB, MIB, BBI,
1312 DefaultProb, UnhandledProbs,
I, Fallthrough,
1313 FallthroughUnreachable)) {
1321 if (!lowerJumpTableWorkItem(W, SwitchMBB, CurMBB, DefaultMBB, MIB, BBI,
1322 UnhandledProbs,
I, Fallthrough,
1323 FallthroughUnreachable)) {
1330 if (!lowerSwitchRangeWorkItem(
I,
Cond, Fallthrough,
1331 FallthroughUnreachable, UnhandledProbs,
1332 CurMBB, MIB, SwitchMBB)) {
1339 CurMBB = Fallthrough;
1345bool IRTranslator::translateIndirectBr(
const User &U,
1359 if (!AddedSuccessors.
insert(Succ).second)
1368 if (
auto Arg = dyn_cast<Argument>(V))
1369 return Arg->hasSwiftErrorAttr();
1370 if (
auto AI = dyn_cast<AllocaInst>(V))
1376 const LoadInst &LI = cast<LoadInst>(U);
1391 assert(Regs.
size() == 1 &&
"swifterror should be single pointer");
1409 for (
unsigned i = 0; i < Regs.
size(); ++i) {
1414 Align BaseAlign = getMemOpAlign(LI);
1438 assert(Vals.
size() == 1 &&
"swifterror should be single pointer");
1441 SI.getPointerOperand());
1448 for (
unsigned i = 0; i < Vals.
size(); ++i) {
1453 Align BaseAlign = getMemOpAlign(SI);
1457 SI.getSyncScopeID(),
SI.getOrdering());
1464 const Value *Src = U.getOperand(0);
1470 Indices.
push_back(ConstantInt::get(Int32Ty, 0));
1473 for (
auto Idx : EVI->indices())
1475 }
else if (
const InsertValueInst *IVI = dyn_cast<InsertValueInst>(&U)) {
1476 for (
auto Idx : IVI->indices())
1483 DL.getIndexedOffsetInType(Src->getType(), Indices));
1486bool IRTranslator::translateExtractValue(
const User &U,
1488 const Value *Src =
U.getOperand(0);
1493 auto &DstRegs = allocateVRegs(U);
1495 for (
unsigned i = 0; i < DstRegs.size(); ++i)
1496 DstRegs[i] = SrcRegs[
Idx++];
1501bool IRTranslator::translateInsertValue(
const User &U,
1503 const Value *Src =
U.getOperand(0);
1505 auto &DstRegs = allocateVRegs(U);
1509 auto *InsertedIt = InsertedRegs.
begin();
1511 for (
unsigned i = 0; i < DstRegs.size(); ++i) {
1512 if (DstOffsets[i] >=
Offset && InsertedIt != InsertedRegs.
end())
1513 DstRegs[i] = *InsertedIt++;
1515 DstRegs[i] = SrcRegs[i];
1521bool IRTranslator::translateSelect(
const User &U,
1523 Register Tst = getOrCreateVReg(*
U.getOperand(0));
1529 if (
const SelectInst *SI = dyn_cast<SelectInst>(&U))
1532 for (
unsigned i = 0; i < ResRegs.
size(); ++i) {
1533 MIRBuilder.
buildSelect(ResRegs[i], Tst, Op0Regs[i], Op1Regs[i], Flags);
1539bool IRTranslator::translateCopy(
const User &U,
const Value &V,
1542 auto &Regs = *VMap.getVRegs(U);
1544 Regs.push_back(Src);
1545 VMap.getOffsets(U)->push_back(0);
1554bool IRTranslator::translateBitCast(
const User &U,
1561 if (isa<ConstantInt>(
U.getOperand(0)))
1562 return translateCast(TargetOpcode::G_CONSTANT_FOLD_BARRIER, U,
1564 return translateCopy(U, *
U.getOperand(0), MIRBuilder);
1567 return translateCast(TargetOpcode::G_BITCAST, U, MIRBuilder);
1570bool IRTranslator::translateCast(
unsigned Opcode,
const User &U,
1585bool IRTranslator::translateGetElementPtr(
const User &U,
1587 Value &Op0 = *
U.getOperand(0);
1600 auto PtrAddFlagsWithConst = [&](int64_t
Offset) {
1610 unsigned VectorWidth = 0;
1614 bool WantSplatVector =
false;
1615 if (
auto *VT = dyn_cast<VectorType>(
U.getType())) {
1616 VectorWidth = cast<FixedVectorType>(VT)->getNumElements();
1618 WantSplatVector = VectorWidth > 1;
1623 if (WantSplatVector && !PtrTy.
isVector()) {
1637 const Value *
Idx = GTI.getOperand();
1638 if (
StructType *StTy = GTI.getStructTypeOrNull()) {
1639 unsigned Field = cast<Constant>(
Idx)->getUniqueInteger().getZExtValue();
1643 uint64_t ElementSize = GTI.getSequentialElementStride(*DL);
1647 if (
const auto *CI = dyn_cast<ConstantInt>(
Idx)) {
1648 if (std::optional<int64_t> Val = CI->getValue().trySExtValue()) {
1649 Offset += ElementSize * *Val;
1658 PtrAddFlagsWithConst(
Offset))
1665 if (IdxTy != OffsetTy) {
1666 if (!IdxTy.
isVector() && WantSplatVector) {
1679 if (ElementSize != 1) {
1690 MIRBuilder.
buildMul(OffsetTy, IdxReg, ElementSizeMIB, ScaleFlags)
1693 GepOffsetReg = IdxReg;
1697 MIRBuilder.
buildPtrAdd(PtrTy, BaseReg, GepOffsetReg, PtrAddFlags)
1706 MIRBuilder.
buildPtrAdd(getOrCreateVReg(U), BaseReg, OffsetMIB.getReg(0),
1707 PtrAddFlagsWithConst(
Offset));
1711 MIRBuilder.
buildCopy(getOrCreateVReg(U), BaseReg);
1715bool IRTranslator::translateMemFunc(
const CallInst &CI,
1720 if (isa<UndefValue>(SrcPtr))
1725 unsigned MinPtrSize = UINT_MAX;
1726 for (
auto AI = CI.
arg_begin(), AE = CI.
arg_end(); std::next(AI) != AE; ++AI) {
1727 Register SrcReg = getOrCreateVReg(**AI);
1730 MinPtrSize = std::min<unsigned>(SrcTy.
getSizeInBits(), MinPtrSize);
1738 if (MRI->
getType(SizeOpReg) != SizeTy)
1752 if (
auto *MCI = dyn_cast<MemCpyInst>(&CI)) {
1753 DstAlign = MCI->getDestAlign().valueOrOne();
1754 SrcAlign = MCI->getSourceAlign().valueOrOne();
1755 CopySize = dyn_cast<ConstantInt>(MCI->getArgOperand(2));
1756 }
else if (
auto *MMI = dyn_cast<MemMoveInst>(&CI)) {
1757 DstAlign = MMI->getDestAlign().valueOrOne();
1758 SrcAlign = MMI->getSourceAlign().valueOrOne();
1759 CopySize = dyn_cast<ConstantInt>(MMI->getArgOperand(2));
1761 auto *MSI = cast<MemSetInst>(&CI);
1762 DstAlign = MSI->getDestAlign().valueOrOne();
1765 if (Opcode != TargetOpcode::G_MEMCPY_INLINE) {
1781 if (AA && CopySize &&
1792 ICall.addMemOperand(
1794 StoreFlags, 1, DstAlign, AAInfo));
1795 if (Opcode != TargetOpcode::G_MEMSET)
1802bool IRTranslator::translateTrap(
const CallInst &CI,
1807 if (TrapFuncName.
empty()) {
1808 if (Opcode == TargetOpcode::G_UBSANTRAP) {
1818 if (Opcode == TargetOpcode::G_UBSANTRAP)
1825 return CLI->
lowerCall(MIRBuilder, Info);
1828bool IRTranslator::translateVectorInterleave2Intrinsic(
1831 "This function can only be called on the interleave2 intrinsic!");
1835 Register Res = getOrCreateVReg(CI);
1844bool IRTranslator::translateVectorDeinterleave2Intrinsic(
1847 "This function can only be called on the deinterleave2 intrinsic!");
1863void IRTranslator::getStackGuard(
Register DstReg,
1868 MIRBuilder.
buildInstr(TargetOpcode::LOAD_STACK_GUARD, {DstReg}, {});
1874 unsigned AddrSpace =
Global->getType()->getPointerAddressSpace();
1882 MIB.setMemRefs({
MemRef});
1885bool IRTranslator::translateOverflowIntrinsic(
const CallInst &CI,
unsigned Op,
1889 Op, {ResRegs[0], ResRegs[1]},
1895bool IRTranslator::translateFixedPointIntrinsic(
unsigned Op,
const CallInst &CI,
1897 Register Dst = getOrCreateVReg(CI);
1901 MIRBuilder.
buildInstr(
Op, {Dst}, { Src0, Src1, Scale });
1909 case Intrinsic::acos:
1910 return TargetOpcode::G_FACOS;
1911 case Intrinsic::asin:
1912 return TargetOpcode::G_FASIN;
1913 case Intrinsic::atan:
1914 return TargetOpcode::G_FATAN;
1915 case Intrinsic::atan2:
1916 return TargetOpcode::G_FATAN2;
1917 case Intrinsic::bswap:
1918 return TargetOpcode::G_BSWAP;
1919 case Intrinsic::bitreverse:
1920 return TargetOpcode::G_BITREVERSE;
1921 case Intrinsic::fshl:
1922 return TargetOpcode::G_FSHL;
1923 case Intrinsic::fshr:
1924 return TargetOpcode::G_FSHR;
1925 case Intrinsic::ceil:
1926 return TargetOpcode::G_FCEIL;
1927 case Intrinsic::cos:
1928 return TargetOpcode::G_FCOS;
1929 case Intrinsic::cosh:
1930 return TargetOpcode::G_FCOSH;
1931 case Intrinsic::ctpop:
1932 return TargetOpcode::G_CTPOP;
1933 case Intrinsic::exp:
1934 return TargetOpcode::G_FEXP;
1935 case Intrinsic::exp2:
1936 return TargetOpcode::G_FEXP2;
1937 case Intrinsic::exp10:
1938 return TargetOpcode::G_FEXP10;
1939 case Intrinsic::fabs:
1940 return TargetOpcode::G_FABS;
1941 case Intrinsic::copysign:
1942 return TargetOpcode::G_FCOPYSIGN;
1943 case Intrinsic::minnum:
1944 return TargetOpcode::G_FMINNUM;
1945 case Intrinsic::maxnum:
1946 return TargetOpcode::G_FMAXNUM;
1947 case Intrinsic::minimum:
1948 return TargetOpcode::G_FMINIMUM;
1949 case Intrinsic::maximum:
1950 return TargetOpcode::G_FMAXIMUM;
1951 case Intrinsic::minimumnum:
1952 return TargetOpcode::G_FMINIMUMNUM;
1953 case Intrinsic::maximumnum:
1954 return TargetOpcode::G_FMAXIMUMNUM;
1955 case Intrinsic::canonicalize:
1956 return TargetOpcode::G_FCANONICALIZE;
1957 case Intrinsic::floor:
1958 return TargetOpcode::G_FFLOOR;
1959 case Intrinsic::fma:
1960 return TargetOpcode::G_FMA;
1961 case Intrinsic::log:
1962 return TargetOpcode::G_FLOG;
1963 case Intrinsic::log2:
1964 return TargetOpcode::G_FLOG2;
1965 case Intrinsic::log10:
1966 return TargetOpcode::G_FLOG10;
1967 case Intrinsic::ldexp:
1968 return TargetOpcode::G_FLDEXP;
1969 case Intrinsic::nearbyint:
1970 return TargetOpcode::G_FNEARBYINT;
1971 case Intrinsic::pow:
1972 return TargetOpcode::G_FPOW;
1973 case Intrinsic::powi:
1974 return TargetOpcode::G_FPOWI;
1975 case Intrinsic::rint:
1976 return TargetOpcode::G_FRINT;
1977 case Intrinsic::round:
1978 return TargetOpcode::G_INTRINSIC_ROUND;
1979 case Intrinsic::roundeven:
1980 return TargetOpcode::G_INTRINSIC_ROUNDEVEN;
1981 case Intrinsic::sin:
1982 return TargetOpcode::G_FSIN;
1983 case Intrinsic::sinh:
1984 return TargetOpcode::G_FSINH;
1985 case Intrinsic::sqrt:
1986 return TargetOpcode::G_FSQRT;
1987 case Intrinsic::tan:
1988 return TargetOpcode::G_FTAN;
1989 case Intrinsic::tanh:
1990 return TargetOpcode::G_FTANH;
1991 case Intrinsic::trunc:
1992 return TargetOpcode::G_INTRINSIC_TRUNC;
1993 case Intrinsic::readcyclecounter:
1994 return TargetOpcode::G_READCYCLECOUNTER;
1995 case Intrinsic::readsteadycounter:
1996 return TargetOpcode::G_READSTEADYCOUNTER;
1997 case Intrinsic::ptrmask:
1998 return TargetOpcode::G_PTRMASK;
1999 case Intrinsic::lrint:
2000 return TargetOpcode::G_INTRINSIC_LRINT;
2001 case Intrinsic::llrint:
2002 return TargetOpcode::G_INTRINSIC_LLRINT;
2004 case Intrinsic::vector_reduce_fmin:
2005 return TargetOpcode::G_VECREDUCE_FMIN;
2006 case Intrinsic::vector_reduce_fmax:
2007 return TargetOpcode::G_VECREDUCE_FMAX;
2008 case Intrinsic::vector_reduce_fminimum:
2009 return TargetOpcode::G_VECREDUCE_FMINIMUM;
2010 case Intrinsic::vector_reduce_fmaximum:
2011 return TargetOpcode::G_VECREDUCE_FMAXIMUM;
2012 case Intrinsic::vector_reduce_add:
2013 return TargetOpcode::G_VECREDUCE_ADD;
2014 case Intrinsic::vector_reduce_mul:
2015 return TargetOpcode::G_VECREDUCE_MUL;
2016 case Intrinsic::vector_reduce_and:
2017 return TargetOpcode::G_VECREDUCE_AND;
2018 case Intrinsic::vector_reduce_or:
2019 return TargetOpcode::G_VECREDUCE_OR;
2020 case Intrinsic::vector_reduce_xor:
2021 return TargetOpcode::G_VECREDUCE_XOR;
2022 case Intrinsic::vector_reduce_smax:
2023 return TargetOpcode::G_VECREDUCE_SMAX;
2024 case Intrinsic::vector_reduce_smin:
2025 return TargetOpcode::G_VECREDUCE_SMIN;
2026 case Intrinsic::vector_reduce_umax:
2027 return TargetOpcode::G_VECREDUCE_UMAX;
2028 case Intrinsic::vector_reduce_umin:
2029 return TargetOpcode::G_VECREDUCE_UMIN;
2030 case Intrinsic::experimental_vector_compress:
2031 return TargetOpcode::G_VECTOR_COMPRESS;
2032 case Intrinsic::lround:
2033 return TargetOpcode::G_LROUND;
2034 case Intrinsic::llround:
2035 return TargetOpcode::G_LLROUND;
2036 case Intrinsic::get_fpenv:
2037 return TargetOpcode::G_GET_FPENV;
2038 case Intrinsic::get_fpmode:
2039 return TargetOpcode::G_GET_FPMODE;
2044bool IRTranslator::translateSimpleIntrinsic(
const CallInst &CI,
2048 unsigned Op = getSimpleIntrinsicOpcode(
ID);
2056 for (
const auto &Arg : CI.
args())
2059 MIRBuilder.
buildInstr(
Op, {getOrCreateVReg(CI)}, VRegs,
2067 case Intrinsic::experimental_constrained_fadd:
2068 return TargetOpcode::G_STRICT_FADD;
2069 case Intrinsic::experimental_constrained_fsub:
2070 return TargetOpcode::G_STRICT_FSUB;
2071 case Intrinsic::experimental_constrained_fmul:
2072 return TargetOpcode::G_STRICT_FMUL;
2073 case Intrinsic::experimental_constrained_fdiv:
2074 return TargetOpcode::G_STRICT_FDIV;
2075 case Intrinsic::experimental_constrained_frem:
2076 return TargetOpcode::G_STRICT_FREM;
2077 case Intrinsic::experimental_constrained_fma:
2078 return TargetOpcode::G_STRICT_FMA;
2079 case Intrinsic::experimental_constrained_sqrt:
2080 return TargetOpcode::G_STRICT_FSQRT;
2081 case Intrinsic::experimental_constrained_ldexp:
2082 return TargetOpcode::G_STRICT_FLDEXP;
2088bool IRTranslator::translateConstrainedFPIntrinsic(
2108std::optional<MCRegister> IRTranslator::getArgPhysReg(
Argument &Arg) {
2109 auto VRegs = getOrCreateVRegs(Arg);
2110 if (VRegs.
size() != 1)
2111 return std::nullopt;
2115 if (!VRegDef || !VRegDef->isCopy())
2116 return std::nullopt;
2120bool IRTranslator::translateIfEntryValueArgument(
bool isDeclare,
Value *Val,
2125 auto *Arg = dyn_cast<Argument>(Val);
2132 std::optional<MCRegister> PhysReg = getArgPhysReg(*Arg);
2134 LLVM_DEBUG(
dbgs() <<
"Dropping dbg." << (isDeclare ?
"declare" :
"value")
2135 <<
": expression is entry_value but "
2136 <<
"couldn't find a physical register\n");
2156 case Intrinsic::experimental_convergence_anchor:
2157 return TargetOpcode::CONVERGENCECTRL_ANCHOR;
2158 case Intrinsic::experimental_convergence_entry:
2159 return TargetOpcode::CONVERGENCECTRL_ENTRY;
2160 case Intrinsic::experimental_convergence_loop:
2161 return TargetOpcode::CONVERGENCECTRL_LOOP;
2165bool IRTranslator::translateConvergenceControlIntrinsic(
2168 Register OutputReg = getOrCreateConvergenceTokenVReg(CI);
2171 if (
ID == Intrinsic::experimental_convergence_loop) {
2173 assert(Bundle &&
"Expected a convergence control token.");
2175 getOrCreateConvergenceTokenVReg(*Bundle->Inputs[0].get());
2184 if (
auto *
MI = dyn_cast<AnyMemIntrinsic>(&CI)) {
2185 if (ORE->enabled()) {
2195 if (translateSimpleIntrinsic(CI,
ID, MIRBuilder))
2201 case Intrinsic::lifetime_start:
2202 case Intrinsic::lifetime_end: {
2208 unsigned Op =
ID == Intrinsic::lifetime_start ? TargetOpcode::LIFETIME_START
2209 : TargetOpcode::LIFETIME_END;
2218 case Intrinsic::fake_use: {
2220 for (
const auto &Arg : CI.
args())
2222 MIRBuilder.
buildInstr(TargetOpcode::FAKE_USE, {}, VRegs);
2226 case Intrinsic::dbg_declare: {
2233 case Intrinsic::dbg_label: {
2239 "Expected inlined-at fields to agree");
2244 case Intrinsic::vaend:
2248 case Intrinsic::vastart: {
2253 MIRBuilder.
buildInstr(TargetOpcode::G_VASTART, {}, {getOrCreateVReg(*
Ptr)})
2256 ListSize, Alignment));
2259 case Intrinsic::dbg_assign:
2266 case Intrinsic::dbg_value: {
2273 case Intrinsic::uadd_with_overflow:
2274 return translateOverflowIntrinsic(CI, TargetOpcode::G_UADDO, MIRBuilder);
2275 case Intrinsic::sadd_with_overflow:
2276 return translateOverflowIntrinsic(CI, TargetOpcode::G_SADDO, MIRBuilder);
2277 case Intrinsic::usub_with_overflow:
2278 return translateOverflowIntrinsic(CI, TargetOpcode::G_USUBO, MIRBuilder);
2279 case Intrinsic::ssub_with_overflow:
2280 return translateOverflowIntrinsic(CI, TargetOpcode::G_SSUBO, MIRBuilder);
2281 case Intrinsic::umul_with_overflow:
2282 return translateOverflowIntrinsic(CI, TargetOpcode::G_UMULO, MIRBuilder);
2283 case Intrinsic::smul_with_overflow:
2284 return translateOverflowIntrinsic(CI, TargetOpcode::G_SMULO, MIRBuilder);
2285 case Intrinsic::uadd_sat:
2286 return translateBinaryOp(TargetOpcode::G_UADDSAT, CI, MIRBuilder);
2287 case Intrinsic::sadd_sat:
2288 return translateBinaryOp(TargetOpcode::G_SADDSAT, CI, MIRBuilder);
2289 case Intrinsic::usub_sat:
2290 return translateBinaryOp(TargetOpcode::G_USUBSAT, CI, MIRBuilder);
2291 case Intrinsic::ssub_sat:
2292 return translateBinaryOp(TargetOpcode::G_SSUBSAT, CI, MIRBuilder);
2293 case Intrinsic::ushl_sat:
2294 return translateBinaryOp(TargetOpcode::G_USHLSAT, CI, MIRBuilder);
2295 case Intrinsic::sshl_sat:
2296 return translateBinaryOp(TargetOpcode::G_SSHLSAT, CI, MIRBuilder);
2297 case Intrinsic::umin:
2298 return translateBinaryOp(TargetOpcode::G_UMIN, CI, MIRBuilder);
2299 case Intrinsic::umax:
2300 return translateBinaryOp(TargetOpcode::G_UMAX, CI, MIRBuilder);
2301 case Intrinsic::smin:
2302 return translateBinaryOp(TargetOpcode::G_SMIN, CI, MIRBuilder);
2303 case Intrinsic::smax:
2304 return translateBinaryOp(TargetOpcode::G_SMAX, CI, MIRBuilder);
2305 case Intrinsic::abs:
2307 return translateUnaryOp(TargetOpcode::G_ABS, CI, MIRBuilder);
2308 case Intrinsic::smul_fix:
2309 return translateFixedPointIntrinsic(TargetOpcode::G_SMULFIX, CI, MIRBuilder);
2310 case Intrinsic::umul_fix:
2311 return translateFixedPointIntrinsic(TargetOpcode::G_UMULFIX, CI, MIRBuilder);
2312 case Intrinsic::smul_fix_sat:
2313 return translateFixedPointIntrinsic(TargetOpcode::G_SMULFIXSAT, CI, MIRBuilder);
2314 case Intrinsic::umul_fix_sat:
2315 return translateFixedPointIntrinsic(TargetOpcode::G_UMULFIXSAT, CI, MIRBuilder);
2316 case Intrinsic::sdiv_fix:
2317 return translateFixedPointIntrinsic(TargetOpcode::G_SDIVFIX, CI, MIRBuilder);
2318 case Intrinsic::udiv_fix:
2319 return translateFixedPointIntrinsic(TargetOpcode::G_UDIVFIX, CI, MIRBuilder);
2320 case Intrinsic::sdiv_fix_sat:
2321 return translateFixedPointIntrinsic(TargetOpcode::G_SDIVFIXSAT, CI, MIRBuilder);
2322 case Intrinsic::udiv_fix_sat:
2323 return translateFixedPointIntrinsic(TargetOpcode::G_UDIVFIXSAT, CI, MIRBuilder);
2324 case Intrinsic::fmuladd: {
2326 Register Dst = getOrCreateVReg(CI);
2335 MIRBuilder.
buildFMA(Dst, Op0, Op1, Op2,
2346 case Intrinsic::convert_from_fp16:
2352 case Intrinsic::convert_to_fp16:
2358 case Intrinsic::frexp: {
2365 case Intrinsic::sincos: {
2372 case Intrinsic::fptosi_sat:
2376 case Intrinsic::fptoui_sat:
2380 case Intrinsic::memcpy_inline:
2381 return translateMemFunc(CI, MIRBuilder, TargetOpcode::G_MEMCPY_INLINE);
2382 case Intrinsic::memcpy:
2383 return translateMemFunc(CI, MIRBuilder, TargetOpcode::G_MEMCPY);
2384 case Intrinsic::memmove:
2385 return translateMemFunc(CI, MIRBuilder, TargetOpcode::G_MEMMOVE);
2386 case Intrinsic::memset:
2387 return translateMemFunc(CI, MIRBuilder, TargetOpcode::G_MEMSET);
2388 case Intrinsic::eh_typeid_for: {
2395 case Intrinsic::objectsize:
2398 case Intrinsic::is_constant:
2401 case Intrinsic::stackguard:
2402 getStackGuard(getOrCreateVReg(CI), MIRBuilder);
2404 case Intrinsic::stackprotector: {
2409 getStackGuard(GuardVal, MIRBuilder);
2414 int FI = getOrCreateFrameIndex(*Slot);
2418 GuardVal, getOrCreateVReg(*Slot),
2425 case Intrinsic::stacksave: {
2426 MIRBuilder.
buildInstr(TargetOpcode::G_STACKSAVE, {getOrCreateVReg(CI)}, {});
2429 case Intrinsic::stackrestore: {
2430 MIRBuilder.
buildInstr(TargetOpcode::G_STACKRESTORE, {},
2434 case Intrinsic::cttz:
2435 case Intrinsic::ctlz: {
2437 bool isTrailing =
ID == Intrinsic::cttz;
2438 unsigned Opcode = isTrailing
2439 ? Cst->
isZero() ? TargetOpcode::G_CTTZ
2440 : TargetOpcode::G_CTTZ_ZERO_UNDEF
2441 : Cst->
isZero() ? TargetOpcode::G_CTLZ
2442 : TargetOpcode::G_CTLZ_ZERO_UNDEF;
2443 MIRBuilder.
buildInstr(Opcode, {getOrCreateVReg(CI)},
2447 case Intrinsic::invariant_start: {
2451 case Intrinsic::invariant_end:
2453 case Intrinsic::expect:
2454 case Intrinsic::expect_with_probability:
2455 case Intrinsic::annotation:
2456 case Intrinsic::ptr_annotation:
2457 case Intrinsic::launder_invariant_group:
2458 case Intrinsic::strip_invariant_group: {
2460 MIRBuilder.
buildCopy(getOrCreateVReg(CI),
2464 case Intrinsic::assume:
2465 case Intrinsic::experimental_noalias_scope_decl:
2466 case Intrinsic::var_annotation:
2467 case Intrinsic::sideeffect:
2470 case Intrinsic::read_volatile_register:
2471 case Intrinsic::read_register: {
2474 .
buildInstr(TargetOpcode::G_READ_REGISTER, {getOrCreateVReg(CI)}, {})
2475 .addMetadata(cast<MDNode>(cast<MetadataAsValue>(Arg)->getMetadata()));
2478 case Intrinsic::write_register: {
2480 MIRBuilder.
buildInstr(TargetOpcode::G_WRITE_REGISTER)
2481 .
addMetadata(cast<MDNode>(cast<MetadataAsValue>(Arg)->getMetadata()))
2485 case Intrinsic::localescape: {
2493 if (isa<ConstantPointerNull>(Arg))
2496 int FI = getOrCreateFrameIndex(*cast<AllocaInst>(Arg));
2511 case Intrinsic::vector_reduce_fadd:
2512 case Intrinsic::vector_reduce_fmul: {
2515 Register Dst = getOrCreateVReg(CI);
2521 Opc =
ID == Intrinsic::vector_reduce_fadd
2522 ? TargetOpcode::G_VECREDUCE_SEQ_FADD
2523 : TargetOpcode::G_VECREDUCE_SEQ_FMUL;
2525 Opc =
ID == Intrinsic::vector_reduce_fadd ? TargetOpcode::G_FADD
2526 : TargetOpcode::G_FMUL;
2534 if (
ID == Intrinsic::vector_reduce_fadd) {
2535 Opc = TargetOpcode::G_VECREDUCE_FADD;
2536 ScalarOpc = TargetOpcode::G_FADD;
2538 Opc = TargetOpcode::G_VECREDUCE_FMUL;
2539 ScalarOpc = TargetOpcode::G_FMUL;
2544 MIRBuilder.
buildInstr(ScalarOpc, {Dst}, {ScalarSrc, Rdx},
2549 case Intrinsic::trap:
2550 return translateTrap(CI, MIRBuilder, TargetOpcode::G_TRAP);
2551 case Intrinsic::debugtrap:
2552 return translateTrap(CI, MIRBuilder, TargetOpcode::G_DEBUGTRAP);
2553 case Intrinsic::ubsantrap:
2554 return translateTrap(CI, MIRBuilder, TargetOpcode::G_UBSANTRAP);
2555 case Intrinsic::allow_runtime_check:
2556 case Intrinsic::allow_ubsan_check:
2557 MIRBuilder.
buildCopy(getOrCreateVReg(CI),
2560 case Intrinsic::amdgcn_cs_chain:
2561 case Intrinsic::amdgcn_call_whole_wave:
2562 return translateCallBase(CI, MIRBuilder);
2563 case Intrinsic::fptrunc_round: {
2568 std::optional<RoundingMode> RoundMode =
2573 .
buildInstr(TargetOpcode::G_INTRINSIC_FPTRUNC_ROUND,
2574 {getOrCreateVReg(CI)},
2576 .addImm((
int)*RoundMode);
2580 case Intrinsic::is_fpclass: {
2585 .
buildInstr(TargetOpcode::G_IS_FPCLASS, {getOrCreateVReg(CI)},
2586 {getOrCreateVReg(*FpValue)})
2591 case Intrinsic::set_fpenv: {
2596 case Intrinsic::reset_fpenv:
2599 case Intrinsic::set_fpmode: {
2604 case Intrinsic::reset_fpmode:
2607 case Intrinsic::get_rounding:
2610 case Intrinsic::vscale: {
2614 case Intrinsic::scmp:
2615 MIRBuilder.
buildSCmp(getOrCreateVReg(CI),
2619 case Intrinsic::ucmp:
2620 MIRBuilder.
buildUCmp(getOrCreateVReg(CI),
2624 case Intrinsic::vector_extract:
2625 return translateExtractVector(CI, MIRBuilder);
2626 case Intrinsic::vector_insert:
2627 return translateInsertVector(CI, MIRBuilder);
2628 case Intrinsic::stepvector: {
2632 case Intrinsic::prefetch: {
2634 unsigned RW = cast<ConstantInt>(CI.
getOperand(1))->getZExtValue();
2635 unsigned Locality = cast<ConstantInt>(CI.
getOperand(2))->getZExtValue();
2636 unsigned CacheType = cast<ConstantInt>(CI.
getOperand(3))->getZExtValue();
2648 case Intrinsic::vector_interleave2:
2649 case Intrinsic::vector_deinterleave2: {
2657 return translateVectorInterleave2Intrinsic(CI, MIRBuilder);
2659 return translateVectorDeinterleave2Intrinsic(CI, MIRBuilder);
2662#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
2663 case Intrinsic::INTRINSIC:
2664#include "llvm/IR/ConstrainedOps.def"
2665 return translateConstrainedFPIntrinsic(cast<ConstrainedFPIntrinsic>(CI),
2667 case Intrinsic::experimental_convergence_anchor:
2668 case Intrinsic::experimental_convergence_entry:
2669 case Intrinsic::experimental_convergence_loop:
2670 return translateConvergenceControlIntrinsic(CI,
ID, MIRBuilder);
2675bool IRTranslator::translateInlineAsm(
const CallBase &CB,
2684 dbgs() <<
"Inline asm lowering is not supported for this target yet\n");
2689 MIRBuilder, CB, [&](
const Value &Val) {
return getOrCreateVRegs(Val); });
2692bool IRTranslator::translateCallBase(
const CallBase &CB,
2699 for (
const auto &Arg : CB.
args()) {
2701 assert(SwiftInVReg == 0 &&
"Expected only one swift error argument");
2705 &CB, &MIRBuilder.
getMBB(), Arg));
2711 Args.push_back(getOrCreateVRegs(*Arg));
2714 if (
auto *CI = dyn_cast<CallInst>(&CB)) {
2715 if (ORE->enabled()) {
2723 std::optional<CallLowering::PtrAuthInfo> PAI;
2728 const Value *
Key = Bundle->Inputs[0];
2735 if (!CalleeCPA || !isa<Function>(CalleeCPA->getPointer()) ||
2736 !CalleeCPA->isKnownCompatibleWith(Key, Discriminator, *DL)) {
2738 Register DiscReg = getOrCreateVReg(*Discriminator);
2746 const auto &Token = *Bundle->Inputs[0].get();
2747 ConvergenceCtrlToken = getOrCreateConvergenceTokenVReg(Token);
2754 MIRBuilder, CB, Res, Args, SwiftErrorVReg, PAI, ConvergenceCtrlToken,
2759 assert(!HasTailCall &&
"Can't tail call return twice from block?");
2771 const CallInst &CI = cast<CallInst>(U);
2776 if (
F && (
F->hasDLLImportStorageClass() ||
2778 F->hasExternalWeakLinkage())))
2786 if (isa<GCStatepointInst, GCRelocateInst, GCResultInst>(U))
2790 return translateInlineAsm(CI, MIRBuilder);
2794 if (translateCallBase(CI, MIRBuilder)) {
2803 if (translateKnownIntrinsic(CI,
ID, MIRBuilder))
2808 ResultRegs = getOrCreateVRegs(CI);
2813 if (isa<FPMathOperator>(CI))
2820 if (
ConstantInt *CI = dyn_cast<ConstantInt>(Arg.value())) {
2823 assert(CI->getBitWidth() <= 64 &&
2824 "large intrinsic immediates not handled");
2825 MIB.
addImm(CI->getSExtValue());
2827 MIB.
addFPImm(cast<ConstantFP>(Arg.value()));
2829 }
else if (
auto *MDVal = dyn_cast<MetadataAsValue>(Arg.value())) {
2830 auto *MD = MDVal->getMetadata();
2831 auto *MDN = dyn_cast<MDNode>(MD);
2833 if (
auto *ConstMD = dyn_cast<ConstantAsMetadata>(MD))
2841 if (VRegs.
size() > 1)
2852 DL->getABITypeAlign(
Info.memVT.getTypeForEVT(
F->getContext())));
2853 LLT MemTy =
Info.memVT.isSimple()
2855 :
LLT::scalar(
Info.memVT.getStoreSizeInBits());
2862 else if (
Info.fallbackAddressSpace)
2871 auto *Token = Bundle->Inputs[0].get();
2872 Register TokenReg = getOrCreateVReg(*Token);
2880bool IRTranslator::findUnwindDestinations(
2900 if (isa<LandingPadInst>(Pad)) {
2902 UnwindDests.emplace_back(&getMBB(*EHPadBB), Prob);
2905 if (isa<CleanupPadInst>(Pad)) {
2908 UnwindDests.emplace_back(&getMBB(*EHPadBB), Prob);
2909 UnwindDests.
back().first->setIsEHScopeEntry();
2910 UnwindDests.back().first->setIsEHFuncletEntry();
2913 if (
auto *CatchSwitch = dyn_cast<CatchSwitchInst>(Pad)) {
2915 for (
const BasicBlock *CatchPadBB : CatchSwitch->handlers()) {
2916 UnwindDests.emplace_back(&getMBB(*CatchPadBB), Prob);
2918 if (IsMSVCCXX || IsCoreCLR)
2919 UnwindDests.back().first->setIsEHFuncletEntry();
2921 UnwindDests.back().first->setIsEHScopeEntry();
2923 NewEHPadBB = CatchSwitch->getUnwindDest();
2929 if (BPI && NewEHPadBB)
2931 EHPadBB = NewEHPadBB;
2936bool IRTranslator::translateInvoke(
const User &U,
2944 const Function *Fn =
I.getCalledFunction();
2951 if (
I.hasDeoptState())
2969 bool LowerInlineAsm =
I.isInlineAsm();
2970 bool NeedEHLabel =
true;
2976 MIRBuilder.
buildInstr(TargetOpcode::G_INVOKE_REGION_START);
2977 BeginSymbol =
Context.createTempSymbol();
2981 if (LowerInlineAsm) {
2982 if (!translateInlineAsm(
I, MIRBuilder))
2984 }
else if (!translateCallBase(
I, MIRBuilder))
2989 EndSymbol =
Context.createTempSymbol();
3000 if (!findUnwindDestinations(EHPadBB, EHPadBBProb, UnwindDests))
3004 &ReturnMBB = getMBB(*ReturnBB);
3006 addSuccessorWithProb(InvokeMBB, &ReturnMBB);
3007 for (
auto &UnwindDest : UnwindDests) {
3008 UnwindDest.first->setIsEHPad();
3009 addSuccessorWithProb(InvokeMBB, UnwindDest.first, UnwindDest.second);
3014 assert(BeginSymbol &&
"Expected a begin symbol!");
3015 assert(EndSymbol &&
"Expected an end symbol!");
3016 MF->
addInvoke(&EHPadMBB, BeginSymbol, EndSymbol);
3019 MIRBuilder.
buildBr(ReturnMBB);
3023bool IRTranslator::translateCallBr(
const User &U,
3029bool IRTranslator::translateLandingPad(
const User &U,
3053 MIRBuilder.
buildInstr(TargetOpcode::EH_LABEL)
3059 if (
auto *RegMask =
TRI.getCustomEHPadPreservedMask(*MF))
3067 for (
Type *Ty : cast<StructType>(LP.
getType())->elements())
3069 assert(Tys.
size() == 2 &&
"Only two-valued landingpads are supported");
3078 MIRBuilder.
buildCopy(ResRegs[0], ExceptionReg);
3086 MIRBuilder.
buildCopy(PtrVReg, SelectorReg);
3087 MIRBuilder.
buildCast(ResRegs[1], PtrVReg);
3092bool IRTranslator::translateAlloca(
const User &U,
3094 auto &AI = cast<AllocaInst>(U);
3100 Register Res = getOrCreateVReg(AI);
3101 int FI = getOrCreateFrameIndex(AI);
3114 if (MRI->
getType(NumElts) != IntPtrTy) {
3124 getOrCreateVReg(*ConstantInt::get(IntPtrIRTy,
DL->getTypeAllocSize(Ty)));
3125 MIRBuilder.
buildMul(AllocSize, NumElts, TySize);
3132 auto AllocAdd = MIRBuilder.
buildAdd(IntPtrTy, AllocSize, SAMinusOne,
3136 auto AlignedAlloc = MIRBuilder.
buildAnd(IntPtrTy, AllocAdd, AlignCst);
3139 if (Alignment <= StackAlign)
3140 Alignment =
Align(1);
3153 MIRBuilder.
buildInstr(TargetOpcode::G_VAARG, {getOrCreateVReg(U)},
3154 {getOrCreateVReg(*
U.getOperand(0)),
3155 DL->getABITypeAlign(
U.getType()).value()});
3159bool IRTranslator::translateUnreachable(
const User &U,
3161 auto &UI = cast<UnreachableInst>(U);
3170bool IRTranslator::translateInsertElement(
const User &U,
3174 if (
auto *FVT = dyn_cast<FixedVectorType>(
U.getType());
3175 FVT && FVT->getNumElements() == 1)
3176 return translateCopy(U, *
U.getOperand(1), MIRBuilder);
3179 Register Val = getOrCreateVReg(*
U.getOperand(0));
3180 Register Elt = getOrCreateVReg(*
U.getOperand(1));
3183 if (
auto *CI = dyn_cast<ConstantInt>(
U.getOperand(2))) {
3184 if (CI->getBitWidth() != PreferredVecIdxWidth) {
3185 APInt NewIdx = CI->getValue().zextOrTrunc(PreferredVecIdxWidth);
3186 auto *NewIdxCI = ConstantInt::get(CI->
getContext(), NewIdx);
3187 Idx = getOrCreateVReg(*NewIdxCI);
3191 Idx = getOrCreateVReg(*
U.getOperand(2));
3200bool IRTranslator::translateInsertVector(
const User &U,
3203 Register Vec = getOrCreateVReg(*
U.getOperand(0));
3204 Register Elt = getOrCreateVReg(*
U.getOperand(1));
3212 CI = ConstantInt::get(CI->
getContext(), NewIdx);
3216 if (
auto *ResultType = dyn_cast<FixedVectorType>(
U.getOperand(1)->getType());
3217 ResultType && ResultType->getNumElements() == 1) {
3218 if (
auto *InputType = dyn_cast<FixedVectorType>(
U.getOperand(0)->getType());
3219 InputType && InputType->getNumElements() == 1) {
3223 return translateCopy(U, *
U.getOperand(0), MIRBuilder);
3225 if (isa<FixedVectorType>(
U.getOperand(0)->getType())) {
3233 if (isa<ScalableVectorType>(
U.getOperand(0)->getType())) {
3238 auto ScaledIndex = MIRBuilder.
buildMul(
3246 getOrCreateVReg(U), getOrCreateVReg(*
U.getOperand(0)),
3251bool IRTranslator::translateExtractElement(
const User &U,
3256 dyn_cast<FixedVectorType>(
U.getOperand(0)->getType()))
3257 if (FVT->getNumElements() == 1)
3258 return translateCopy(U, *
U.getOperand(0), MIRBuilder);
3261 Register Val = getOrCreateVReg(*
U.getOperand(0));
3264 if (
auto *CI = dyn_cast<ConstantInt>(
U.getOperand(1))) {
3267 auto *NewIdxCI = ConstantInt::get(CI->
getContext(), NewIdx);
3268 Idx = getOrCreateVReg(*NewIdxCI);
3272 Idx = getOrCreateVReg(*
U.getOperand(1));
3281bool IRTranslator::translateExtractVector(
const User &U,
3284 Register Vec = getOrCreateVReg(*
U.getOperand(0));
3291 CI = ConstantInt::get(CI->
getContext(), NewIdx);
3295 if (
auto *ResultType = dyn_cast<FixedVectorType>(
U.getType());
3296 ResultType && ResultType->getNumElements() == 1) {
3297 if (
auto *InputType = dyn_cast<FixedVectorType>(
U.getOperand(0)->getType());
3298 InputType && InputType->getNumElements() == 1) {
3301 return translateCopy(U, *
U.getOperand(0), MIRBuilder);
3303 if (isa<FixedVectorType>(
U.getOperand(0)->getType())) {
3311 if (isa<ScalableVectorType>(
U.getOperand(0)->getType())) {
3316 auto ScaledIndex = MIRBuilder.
buildMul(
3324 getOrCreateVReg(*
U.getOperand(0)),
3329bool IRTranslator::translateShuffleVector(
const User &U,
3335 if (
U.getOperand(0)->getType()->isScalableTy()) {
3336 Register Val = getOrCreateVReg(*
U.getOperand(0));
3344 if (
auto *SVI = dyn_cast<ShuffleVectorInst>(&U))
3345 Mask = SVI->getShuffleMask();
3347 Mask = cast<ConstantExpr>(U).getShuffleMask();
3350 .
buildInstr(TargetOpcode::G_SHUFFLE_VECTOR, {getOrCreateVReg(U)},
3351 {getOrCreateVReg(*
U.getOperand(0)),
3352 getOrCreateVReg(*
U.getOperand(1))})
3353 .addShuffleMask(MaskAlloc);
3358 const PHINode &PI = cast<PHINode>(U);
3361 for (
auto Reg : getOrCreateVRegs(PI)) {
3362 auto MIB = MIRBuilder.
buildInstr(TargetOpcode::G_PHI, {
Reg}, {});
3366 PendingPHIs.emplace_back(&PI, std::move(Insts));
3370bool IRTranslator::translateAtomicCmpXchg(
const User &U,
3376 auto Res = getOrCreateVRegs(
I);
3380 Register Cmp = getOrCreateVReg(*
I.getCompareOperand());
3381 Register NewVal = getOrCreateVReg(*
I.getNewValOperand());
3384 OldValRes, SuccessRes,
Addr, Cmp, NewVal,
3387 getMemOpAlign(
I),
I.getAAMetadata(),
nullptr,
I.getSyncScopeID(),
3388 I.getSuccessOrdering(),
I.getFailureOrdering()));
3392bool IRTranslator::translateAtomicRMW(
const User &U,
3402 Register Val = getOrCreateVReg(*
I.getValOperand());
3404 unsigned Opcode = 0;
3405 switch (
I.getOperation()) {
3409 Opcode = TargetOpcode::G_ATOMICRMW_XCHG;
3412 Opcode = TargetOpcode::G_ATOMICRMW_ADD;
3415 Opcode = TargetOpcode::G_ATOMICRMW_SUB;
3418 Opcode = TargetOpcode::G_ATOMICRMW_AND;
3421 Opcode = TargetOpcode::G_ATOMICRMW_NAND;
3424 Opcode = TargetOpcode::G_ATOMICRMW_OR;
3427 Opcode = TargetOpcode::G_ATOMICRMW_XOR;
3430 Opcode = TargetOpcode::G_ATOMICRMW_MAX;
3433 Opcode = TargetOpcode::G_ATOMICRMW_MIN;
3436 Opcode = TargetOpcode::G_ATOMICRMW_UMAX;
3439 Opcode = TargetOpcode::G_ATOMICRMW_UMIN;
3442 Opcode = TargetOpcode::G_ATOMICRMW_FADD;
3445 Opcode = TargetOpcode::G_ATOMICRMW_FSUB;
3448 Opcode = TargetOpcode::G_ATOMICRMW_FMAX;
3451 Opcode = TargetOpcode::G_ATOMICRMW_FMIN;
3454 Opcode = TargetOpcode::G_ATOMICRMW_FMAXIMUM;
3457 Opcode = TargetOpcode::G_ATOMICRMW_FMINIMUM;
3460 Opcode = TargetOpcode::G_ATOMICRMW_UINC_WRAP;
3463 Opcode = TargetOpcode::G_ATOMICRMW_UDEC_WRAP;
3466 Opcode = TargetOpcode::G_ATOMICRMW_USUB_COND;
3469 Opcode = TargetOpcode::G_ATOMICRMW_USUB_SAT;
3474 Opcode, Res,
Addr, Val,
3476 Flags, MRI->
getType(Val), getMemOpAlign(
I),
3477 I.getAAMetadata(),
nullptr,
I.getSyncScopeID(),
3482bool IRTranslator::translateFence(
const User &U,
3484 const FenceInst &Fence = cast<FenceInst>(U);
3490bool IRTranslator::translateFreeze(
const User &U,
3496 "Freeze with different source and destination type?");
3498 for (
unsigned I = 0;
I < DstRegs.
size(); ++
I) {
3505void IRTranslator::finishPendingPhis() {
3511 for (
auto &Phi : PendingPHIs) {
3526 for (
auto *Pred : getMachinePredBBs({IRPred, PI->
getParent()})) {
3530 for (
unsigned j = 0;
j < ValRegs.
size(); ++
j) {
3540void IRTranslator::translateDbgValueRecord(
Value *V,
bool HasArgList,
3546 "Expected inlined-at fields to agree");
3550 if (!V || HasArgList) {
3557 if (
const auto *CI = dyn_cast<Constant>(V)) {
3562 if (
auto *AI = dyn_cast<AllocaInst>(V);
3567 auto ExprOperands =
Expression->getElements();
3568 auto *ExprDerefRemoved =
3574 if (translateIfEntryValueArgument(
false, V, Variable,
Expression, DL,
3577 for (
Register Reg : getOrCreateVRegs(*V)) {
3586void IRTranslator::translateDbgDeclareRecord(
Value *
Address,
bool HasArgList,
3592 LLVM_DEBUG(
dbgs() <<
"Dropping debug info for " << *Variable <<
"\n");
3597 "Expected inlined-at fields to agree");
3598 auto AI = dyn_cast<AllocaInst>(
Address);
3603 getOrCreateFrameIndex(*AI), DL);
3607 if (translateIfEntryValueArgument(
true,
Address, Variable,
3619void IRTranslator::translateDbgInfo(
const Instruction &Inst,
3624 assert(DLR->getLabel() &&
"Missing label");
3625 assert(DLR->getLabel()->isValidLocationForIntrinsic(
3627 "Expected inlined-at fields to agree");
3644bool IRTranslator::translate(
const Instruction &Inst) {
3646 CurBuilder->setPCSections(Inst.
getMetadata(LLVMContext::MD_pcsections));
3647 CurBuilder->setMMRAMetadata(Inst.
getMetadata(LLVMContext::MD_mmra));
3653#define HANDLE_INST(NUM, OPCODE, CLASS) \
3654 case Instruction::OPCODE: \
3655 return translate##OPCODE(Inst, *CurBuilder.get());
3656#include "llvm/IR/Instruction.def"
3665 if (
auto CurrInstDL = CurBuilder->getDL())
3666 EntryBuilder->setDebugLoc(
DebugLoc());
3668 if (
auto CI = dyn_cast<ConstantInt>(&
C)) {
3670 if (isa<VectorType>(CI->
getType()))
3672 EntryBuilder->buildConstant(Reg, *CI);
3673 }
else if (
auto CF = dyn_cast<ConstantFP>(&
C)) {
3675 if (isa<VectorType>(CF->getType()))
3676 CF = ConstantFP::get(CF->getContext(), CF->getValue());
3677 EntryBuilder->buildFConstant(Reg, *CF);
3678 }
else if (isa<UndefValue>(
C))
3679 EntryBuilder->buildUndef(Reg);
3680 else if (isa<ConstantPointerNull>(
C))
3681 EntryBuilder->buildConstant(Reg, 0);
3682 else if (
auto GV = dyn_cast<GlobalValue>(&
C))
3683 EntryBuilder->buildGlobalValue(Reg, GV);
3684 else if (
auto CPA = dyn_cast<ConstantPtrAuth>(&
C)) {
3686 Register AddrDisc = getOrCreateVReg(*CPA->getAddrDiscriminator());
3687 EntryBuilder->buildConstantPtrAuth(Reg, CPA,
Addr, AddrDisc);
3688 }
else if (
auto CAZ = dyn_cast<ConstantAggregateZero>(&
C)) {
3689 Constant &Elt = *CAZ->getElementValue(0u);
3690 if (isa<ScalableVectorType>(CAZ->getType())) {
3691 EntryBuilder->buildSplatVector(Reg, getOrCreateVReg(Elt));
3695 unsigned NumElts = CAZ->getElementCount().getFixedValue();
3697 return translateCopy(
C, Elt, *EntryBuilder);
3699 EntryBuilder->buildSplatBuildVector(Reg, getOrCreateVReg(Elt));
3700 }
else if (
auto CV = dyn_cast<ConstantDataVector>(&
C)) {
3702 if (CV->getNumElements() == 1)
3703 return translateCopy(
C, *CV->getElementAsConstant(0), *EntryBuilder);
3705 for (
unsigned i = 0; i < CV->getNumElements(); ++i) {
3706 Constant &Elt = *CV->getElementAsConstant(i);
3709 EntryBuilder->buildBuildVector(Reg, Ops);
3710 }
else if (
auto CE = dyn_cast<ConstantExpr>(&
C)) {
3711 switch(
CE->getOpcode()) {
3712#define HANDLE_INST(NUM, OPCODE, CLASS) \
3713 case Instruction::OPCODE: \
3714 return translate##OPCODE(*CE, *EntryBuilder.get());
3715#include "llvm/IR/Instruction.def"
3719 }
else if (
auto CV = dyn_cast<ConstantVector>(&
C)) {
3720 if (CV->getNumOperands() == 1)
3721 return translateCopy(
C, *CV->getOperand(0), *EntryBuilder);
3723 for (
unsigned i = 0; i < CV->getNumOperands(); ++i) {
3724 Ops.
push_back(getOrCreateVReg(*CV->getOperand(i)));
3726 EntryBuilder->buildBuildVector(Reg, Ops);
3727 }
else if (
auto *BA = dyn_cast<BlockAddress>(&
C)) {
3728 EntryBuilder->buildBlockAddress(Reg, BA);
3735bool IRTranslator::finalizeBasicBlock(
const BasicBlock &BB,
3737 for (
auto &BTB : SL->BitTestCases) {
3740 emitBitTestHeader(BTB, BTB.Parent);
3743 for (
unsigned j = 0, ej = BTB.Cases.size(); j != ej; ++j) {
3744 UnhandledProb -= BTB.Cases[
j].ExtraProb;
3756 if ((BTB.ContiguousRange || BTB.FallthroughUnreachable) && j + 2 == ej) {
3759 NextMBB = BTB.Cases[
j + 1].TargetBB;
3760 }
else if (j + 1 == ej) {
3762 NextMBB = BTB.Default;
3765 NextMBB = BTB.Cases[
j + 1].ThisBB;
3768 emitBitTestCase(BTB, NextMBB, UnhandledProb, BTB.Reg, BTB.Cases[j],
MBB);
3770 if ((BTB.ContiguousRange || BTB.FallthroughUnreachable) && j + 2 == ej) {
3774 addMachineCFGPred({BTB.Parent->getBasicBlock(),
3775 BTB.Cases[ej - 1].TargetBB->getBasicBlock()},
3778 BTB.Cases.pop_back();
3784 CFGEdge HeaderToDefaultEdge = {BTB.Parent->getBasicBlock(),
3785 BTB.Default->getBasicBlock()};
3786 addMachineCFGPred(HeaderToDefaultEdge, BTB.Parent);
3787 if (!BTB.ContiguousRange) {
3788 addMachineCFGPred(HeaderToDefaultEdge, BTB.Cases.back().ThisBB);
3791 SL->BitTestCases.clear();
3793 for (
auto &JTCase : SL->JTCases) {
3795 if (!JTCase.first.Emitted)
3796 emitJumpTableHeader(JTCase.second, JTCase.first, JTCase.first.HeaderBB);
3798 emitJumpTable(JTCase.second, JTCase.second.MBB);
3800 SL->JTCases.clear();
3802 for (
auto &SwCase : SL->SwitchCases)
3803 emitSwitchCase(SwCase, &CurBuilder->getMBB(), *CurBuilder);
3804 SL->SwitchCases.clear();
3808 if (
SP.shouldEmitSDCheck(BB)) {
3809 bool FunctionBasedInstrumentation =
3811 SPDescriptor.
initialize(&BB, &
MBB, FunctionBasedInstrumentation);
3831 SuccessMBB->
splice(SuccessMBB->
end(), ParentMBB, SplitPoint,
3835 if (!emitSPDescriptorParent(SPDescriptor, ParentMBB))
3840 if (FailureMBB->
empty()) {
3841 if (!emitSPDescriptorFailure(SPDescriptor, FailureMBB))
3853 CurBuilder->setInsertPt(*ParentBB, ParentBB->
end());
3863 Register StackSlotPtr = CurBuilder->buildFrameIndex(PtrTy, FI).getReg(0);
3870 ->buildLoad(PtrMemTy, StackSlotPtr,
3876 LLVM_DEBUG(
dbgs() <<
"Stack protector xor'ing with FP not yet implemented");
3894 assert(FnTy->getNumParams() == 1 &&
"Invalid function signature");
3896 if (GuardCheckFn->hasAttribute(1, Attribute::AttrKind::InReg))
3899 {GuardVal, FnTy->getParamType(0), {
Flags}});
3902 Info.OrigArgs.push_back(GuardArgInfo);
3903 Info.CallConv = GuardCheckFn->getCallingConv();
3906 if (!CLI->
lowerCall(MIRBuilder, Info)) {
3907 LLVM_DEBUG(
dbgs() <<
"Failed to lower call to stack protector check\n");
3919 getStackGuard(Guard, *CurBuilder);
3923 Register GuardPtr = getOrCreateVReg(*IRGuard);
3926 ->buildLoad(PtrMemTy, GuardPtr,
3945 CurBuilder->setInsertPt(*FailureBB, FailureBB->
end());
3947 const RTLIB::Libcall
Libcall = RTLIB::STACKPROTECTOR_CHECK_FAIL;
3955 if (!CLI->
lowerCall(*CurBuilder, Info)) {
3956 LLVM_DEBUG(
dbgs() <<
"Failed to lower call to stack protector fail\n");
3963 CurBuilder->buildInstr(TargetOpcode::G_TRAP);
3968void IRTranslator::finalizeFunction() {
3971 PendingPHIs.clear();
3973 FrameIndices.clear();
3974 MachinePreds.clear();
3978 EntryBuilder.reset();
3993 const auto *CI = dyn_cast<CallInst>(&
I);
3994 return CI && CI->isMustTailCall();
4002 getAnalysis<GISelCSEAnalysisWrapperPass>().getCSEWrapper();
4005 TPC = &getAnalysis<TargetPassConfig>();
4012 EntryBuilder = std::make_unique<CSEMIRBuilder>(CurMF);
4014 EntryBuilder->setCSEInfo(CSEInfo);
4015 CurBuilder = std::make_unique<CSEMIRBuilder>(CurMF);
4016 CurBuilder->setCSEInfo(CSEInfo);
4018 EntryBuilder = std::make_unique<MachineIRBuilder>();
4019 CurBuilder = std::make_unique<MachineIRBuilder>();
4022 CurBuilder->setMF(*MF);
4023 EntryBuilder->setMF(*MF);
4025 DL = &
F.getDataLayout();
4026 ORE = std::make_unique<OptimizationRemarkEmitter>(&
F);
4028 TM.resetTargetOptions(
F);
4032 AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
4033 FuncInfo.
BPI = &getAnalysis<BranchProbabilityInfoWrapperPass>().getBPI();
4036 FuncInfo.
BPI =
nullptr;
4039 AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(
4041 LibInfo = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(
F);
4044 SL = std::make_unique<GISelSwitchLowering>(
this, FuncInfo);
4045 SL->init(*TLI, TM, *
DL);
4047 assert(PendingPHIs.empty() &&
"stale PHIs");
4054 F.getSubprogram(), &
F.getEntryBlock());
4055 R <<
"unable to translate in big endian mode";
4061 auto FinalizeOnReturn =
make_scope_exit([
this]() { finalizeFunction(); });
4066 EntryBuilder->setMBB(*EntryBB);
4068 DebugLoc DbgLoc =
F.getEntryBlock().getFirstNonPHIIt()->getDebugLoc();
4072 bool IsVarArg =
F.isVarArg();
4073 bool HasMustTailInVarArgFn =
false;
4076 FuncInfo.
MBBMap.resize(
F.getMaxBlockNumber());
4086 if (!HasMustTailInVarArgFn)
4093 EntryBB->addSuccessor(&getMBB(
F.front()));
4097 F.getSubprogram(), &
F.getEntryBlock());
4098 R <<
"unable to lower function: "
4099 <<
ore::NV(
"Prototype",
F.getFunctionType());
4107 if (
DL->getTypeStoreSize(Arg.
getType()).isZero())
4112 if (Arg.hasSwiftErrorAttr()) {
4113 assert(VRegs.
size() == 1 &&
"Too many vregs for Swift error");
4120 F.getSubprogram(), &
F.getEntryBlock());
4121 R <<
"unable to lower arguments: "
4122 <<
ore::NV(
"Prototype",
F.getFunctionType());
4129 if (EnableCSE && CSEInfo)
4142 CurBuilder->setMBB(
MBB);
4143 HasTailCall =
false;
4157 translateDbgInfo(Inst, *CurBuilder);
4159 if (translate(Inst))
4164 R <<
"unable to translate instruction: " <<
ore::NV(
"Opcode", &Inst);
4166 if (ORE->allowExtraAnalysis(
"gisel-irtranslator")) {
4167 std::string InstStrStorage;
4171 R <<
": '" << InstStrStorage <<
"'";
4178 if (!finalizeBasicBlock(*BB,
MBB)) {
4180 BB->getTerminator()->getDebugLoc(), BB);
4181 R <<
"unable to translate basic block";
4191 finishPendingPhis();
4198 assert(EntryBB->succ_size() == 1 &&
4199 "Custom BB used for lowering should have only one successor");
4203 "LLVM-IR entry block has a predecessor!?");
4206 NewEntryBB.
splice(NewEntryBB.
begin(), EntryBB, EntryBB->begin(),
4215 EntryBB->removeSuccessor(&NewEntryBB);
4220 "New entry wasn't next in the list of basic block!");
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
amdgpu aa AMDGPU Address space based Alias Analysis Wrapper
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Analysis containing CSE Info
Provides analysis for continuously CSEing during GISel passes.
This file implements a version of MachineIRBuilder which CSEs insts within a MachineBasicBlock.
This file describes how to lower LLVM calls to machine code calls.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This contains common code to allow clients to notify changes to machine instr.
const HexagonInstrInfo * TII
IRTranslator LLVM IR static false void reportTranslationError(MachineFunction &MF, const TargetPassConfig &TPC, OptimizationRemarkEmitter &ORE, OptimizationRemarkMissed &R)
static bool checkForMustTailInVarArgFn(bool IsVarArg, const BasicBlock &BB)
Returns true if a BasicBlock BB within a variadic function contains a variadic musttail call.
static bool containsBF16Type(const User &U)
static unsigned getConvOpcode(Intrinsic::ID ID)
static uint64_t getOffsetFromIndices(const User &U, const DataLayout &DL)
static unsigned getConstrainedOpcode(Intrinsic::ID ID)
static cl::opt< bool > EnableCSEInIRTranslator("enable-cse-in-irtranslator", cl::desc("Should enable CSE in irtranslator"), cl::Optional, cl::init(false))
static bool isValInBlock(const Value *V, const BasicBlock *BB)
static bool isSwiftError(const Value *V)
This file declares the IRTranslator pass.
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
This file describes how to lower LLVM inline asm to machine code INLINEASM.
Legalize the Machine IR a function s Machine IR
Implement a low-level type suitable for MachineInstr level instruction selection.
Implement a low-level type suitable for MachineInstr level instruction selection.
This file declares the MachineIRBuilder class.
Register const TargetRegisterInfo * TRI
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
const SmallVectorImpl< MachineOperand > & Cond
std::pair< BasicBlock *, BasicBlock * > Edge
verify safepoint Safepoint IR Verifier
This file defines the make_scope_exit function, which executes user-defined cleanup logic at scope ex...
This file defines the SmallVector class.
This file describes how to lower LLVM code to machine code.
Target-Independent Code Generator Pass Configuration Options pass.
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object.
bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal=false)
Checks whether the given location points to constant memory, or if OrLocal is true whether it points ...
Class for arbitrary precision integers.
LLVM_ABI APInt zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
an instruction to allocate memory on the stack
bool isSwiftError() const
Return true if this alloca is used as a swifterror argument to a call.
LLVM_ABI bool isStaticAlloca() const
Return true if this alloca is in the entry block of the function and is a constant size.
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
PointerType * getType() const
Overload to return most specific pointer type.
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
const Value * getArraySize() const
Get the number of elements allocated.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
This class represents an incoming formal argument to a Function.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
An immutable pass that tracks lazily created AssumptionCache objects.
An instruction that atomically checks whether a specified value is in a memory location,...
an instruction that atomically reads a memory location, combines it with another value,...
@ USubCond
Subtract only if no unsigned overflow.
@ FMinimum
*p = minimum(old, v) minimum matches the behavior of llvm.minimum.
@ Min
*p = old <signed v ? old : v
@ USubSat
*p = usub.sat(old, v) usub.sat matches the behavior of llvm.usub.sat.
@ FMaximum
*p = maximum(old, v) maximum matches the behavior of llvm.maximum.
@ UIncWrap
Increment one up to a maximum value.
@ Max
*p = old >signed v ? old : v
@ UMin
*p = old <unsigned v ? old : v
@ FMin
*p = minnum(old, v) minnum matches the behavior of llvm.minnum.
@ UMax
*p = old >unsigned v ? old : v
@ FMax
*p = maxnum(old, v) maxnum matches the behavior of llvm.maxnum.
@ UDecWrap
Decrement one until a minimum value or zero.
Attribute getFnAttr(Attribute::AttrKind Kind) const
Return the attribute object that exists for the function.
LLVM_ABI StringRef getValueAsString() const
Return the attribute's value as a string.
LLVM Basic Block Representation.
unsigned getNumber() const
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches,...
LLVM_ABI InstListType::const_iterator getFirstNonPHIIt() const
Returns an iterator to the first instruction in this block that is not a PHINode instruction.
InstListType::const_iterator const_iterator
LLVM_ABI InstListType::const_iterator getFirstNonPHIOrDbg(bool SkipPseudoOp=true) const
Returns a pointer to the first instruction in this block that is not a PHINode or a debug intrinsic,...
const Function * getParent() const
Return the enclosing method, or null if none.
const Instruction & back() const
LLVM_ABI const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
Legacy analysis pass which computes BlockFrequencyInfo.
Conditional or Unconditional Branch instruction.
BasicBlock * getSuccessor(unsigned i) const
bool isUnconditional() const
Value * getCondition() const
Legacy analysis pass which computes BranchProbabilityInfo.
Analysis providing branch probability information.
LLVM_ABI BranchProbability getEdgeProbability(const BasicBlock *Src, unsigned IndexInSuccessors) const
Get an edge's probability, relative to other out-edges of the Src.
static BranchProbability getZero()
static void normalizeProbabilities(ProbabilityIter Begin, ProbabilityIter End)
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
bool isInlineAsm() const
Check if this call is an inline asm statement.
std::optional< OperandBundleUse > getOperandBundle(StringRef Name) const
Return an operand bundle by name, if present.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
LLVM_ABI bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Determine whether the argument or parameter has the given attribute.
User::op_iterator arg_begin()
Return the iterator pointing to the beginning of the argument list.
unsigned countOperandBundlesOfType(StringRef Name) const
Return the number of operand bundles with the tag Name attached to this instruction.
Value * getCalledOperand() const
Value * getArgOperand(unsigned i) const
User::op_iterator arg_end()
Return the iterator pointing to the end of the argument list.
bool isConvergent() const
Determine if the invoke is convergent.
LLVM_ABI Intrinsic::ID getIntrinsicID() const
Returns the intrinsic ID of the intrinsic called or Intrinsic::not_intrinsic if the called function i...
iterator_range< User::op_iterator > args()
Iteration adapter for range-for loops.
unsigned arg_size() const
AttributeList getAttributes() const
Return the attributes for this call.
This class represents a function call, abstracting a target machine's calling convention.
bool checkReturnTypeForCallConv(MachineFunction &MF) const
Toplevel function to check the return type based on the target calling convention.
virtual bool lowerFormalArguments(MachineIRBuilder &MIRBuilder, const Function &F, ArrayRef< ArrayRef< Register > > VRegs, FunctionLoweringInfo &FLI) const
This hook must be implemented to lower the incoming (formal) arguments, described by VRegs,...
virtual bool enableBigEndian() const
For targets which want to use big-endian can enable it with enableBigEndian() hook.
virtual bool supportSwiftError() const
virtual bool lowerReturn(MachineIRBuilder &MIRBuilder, const Value *Val, ArrayRef< Register > VRegs, FunctionLoweringInfo &FLI, Register SwiftErrorVReg) const
This hook must be implemented to lower outgoing return values, described by Val, into the specified v...
virtual bool lowerCall(MachineIRBuilder &MIRBuilder, CallLoweringInfo &Info) const
This hook must be implemented to lower the given call instruction, including argument and return valu...
virtual bool fallBackToDAGISel(const MachineFunction &MF) const
This class is the base class for the comparison instructions.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
@ FCMP_TRUE
1 1 1 1 Always true (always folded)
@ ICMP_SLT
signed less than
@ ICMP_SLE
signed less or equal
@ ICMP_UGT
unsigned greater than
@ ICMP_ULE
unsigned less or equal
@ FCMP_FALSE
0 0 0 0 Always false (always folded)
bool isFPPredicate() const
bool isIntPredicate() const
This is the shared class of boolean and integer constants.
static LLVM_ABI ConstantInt * getTrue(LLVMContext &Context)
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
unsigned getBitWidth() const
getBitWidth - Return the scalar bitwidth of this constant.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
const APInt & getValue() const
Return the constant as an APInt value reference.
This is an important base class in LLVM.
static LLVM_ABI Constant * getAllOnesValue(Type *Ty)
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
This is the common base class for constrained floating point intrinsics.
LLVM_ABI std::optional< fp::ExceptionBehavior > getExceptionBehavior() const
LLVM_ABI unsigned getNonMetadataArgCount() const
LLVM_ABI bool isEntryValue() const
Check if the expression consists of exactly one entry value operand.
static LLVM_ABI DIExpression * append(const DIExpression *Expr, ArrayRef< uint64_t > Ops)
Append the opcodes Ops to DIExpr.
bool isValidLocationForIntrinsic(const DILocation *DL) const
Check that a location is valid for this label.
bool isValidLocationForIntrinsic(const DILocation *DL) const
Check that a location is valid for this variable.
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
unsigned getPointerSizeInBits(unsigned AS=0) const
The size in bits of the pointer representation in a given address space.
LLVM_ABI const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
LLVM_ABI IntegerType * getIndexType(LLVMContext &C, unsigned AddressSpace) const
Returns the type of a GEP index in AddressSpace.
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
TypeSize getTypeSizeInBits(Type *Ty) const
Size examples:
TypeSize getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type.
LLVM_ABI Align getPointerABIAlignment(unsigned AS) const
Layout pointer alignment.
This represents the llvm.dbg.declare instruction.
Value * getAddress() const
This represents the llvm.dbg.label instruction.
DILabel * getLabel() const
Records a position in IR for a source label (DILabel).
Base class for non-instruction debug metadata records that have positions within IR.
DebugLoc getDebugLoc() const
This represents the llvm.dbg.value instruction.
Value * getValue(unsigned OpIdx=0) const
DILocalVariable * getVariable() const
DIExpression * getExpression() const
Record of a variable value-assignment, aka a non instruction representation of the dbg....
DIExpression * getExpression() const
LLVM_ABI Value * getVariableLocationOp(unsigned OpIdx) const
DILocalVariable * getVariable() const
bool isDbgDeclare() const
Class representing an expression and its matching format.
This instruction compares its operands according to the predicate given to the constructor.
An instruction for ordering other memory operations.
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID of this fence instruction.
AtomicOrdering getOrdering() const
Returns the ordering constraint of this fence instruction.
Class to represent fixed width SIMD vectors.
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
BranchProbabilityInfo * BPI
void clear()
clear - Clear out all the function-specific state.
MachineBasicBlock * getMBB(const BasicBlock *BB) const
SmallVector< MachineBasicBlock * > MBBMap
A mapping from LLVM basic block number to their machine block.
bool CanLowerReturn
CanLowerReturn - true iff the function's return value can be lowered to registers.
bool skipFunction(const Function &F) const
Optional passes call this function to check whether the pass should be skipped.
const BasicBlock & getEntryBlock() const
DISubprogram * getSubprogram() const
Get the attached subprogram.
bool hasMinSize() const
Optimize this function for minimum size (-Oz).
Constant * getPersonalityFn() const
Get the personality function associated with this function.
const Function & getFunction() const
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
bool hasOptNone() const
Do not optimize this function (-O0).
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
The actual analysis pass wrapper.
Simple wrapper that does the following.
Abstract class that contains various methods for clients to notify about changes.
Simple wrapper observer that takes several observers, and calls each one for each event.
void removeObserver(GISelChangeObserver *O)
void addObserver(GISelChangeObserver *O)
static StringRef dropLLVMManglingEscape(StringRef Name)
If the given string begins with the GlobalValue name mangling escape character '\1',...
bool hasExternalWeakLinkage() const
bool hasDLLImportStorageClass() const
Module * getParent()
Get the module that this global value is contained inside of...
bool isTailCall(const MachineInstr &MI) const override
This instruction compares its operands according to the predicate given to the constructor.
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
IRTranslator(CodeGenOptLevel OptLevel=CodeGenOptLevel::None)
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Indirect Branch Instruction.
bool lowerInlineAsm(MachineIRBuilder &MIRBuilder, const CallBase &CB, std::function< ArrayRef< Register >(const Value &Val)> GetOrCreateVRegs) const
Lower the given inline asm call instruction GetOrCreateVRegs is a callback to materialize a register ...
This instruction inserts a struct field of array element value into an aggregate value.
iterator_range< simple_ilist< DbgRecord >::iterator > getDbgRecordRange() const
Return a range over the DbgRecords attached to this instruction.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
LLVM_ABI const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
bool hasMetadata() const
Return true if this instruction has any metadata attached to it.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
LLVM_ABI AAMDNodes getAAMetadata() const
Returns the AA metadata for this instruction.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
LLVM_ABI bool hasAllowReassoc() const LLVM_READONLY
Determine whether the allow-reassociation flag is set.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
constexpr LLT changeElementType(LLT NewEltTy) const
If this type is a vector, return a vector with the same number of elements but the new element type.
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
constexpr uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
constexpr bool isVector() const
static constexpr LLT pointer(unsigned AddressSpace, unsigned SizeInBits)
Get a low-level pointer in the given address space.
constexpr TypeSize getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
constexpr bool isPointer() const
constexpr LLT getElementType() const
Returns the vector's element type. Only valid for vector types.
static constexpr LLT fixed_vector(unsigned NumElements, unsigned ScalarSizeInBits)
Get a low-level fixed-width vector of some number of elements and element width.
constexpr bool isFixedVector() const
Returns true if the LLT is a fixed vector.
The landingpad instruction holds all of the information necessary to generate correct exception handl...
An instruction for reading from memory.
Value * getPointerOperand()
AtomicOrdering getOrdering() const
Returns the ordering constraint of this load instruction.
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID of this load instruction.
static LocationSize precise(uint64_t Value)
Context object for machine code objects.
LLVM_ABI MCSymbol * getOrCreateFrameAllocSymbol(const Twine &FuncName, unsigned Idx)
Gets a symbol that will be defined to the final stack offset of a local variable after codegen.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
unsigned pred_size() const
void normalizeSuccProbs()
Normalize probabilities of all successors so that the sum of them becomes one.
void setAddressTakenIRBlock(BasicBlock *BB)
Set this block to reflect that it corresponds to an IR-level basic block with a BlockAddress.
LLVM_ABI instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
LLVM_ABI void setSuccProbability(succ_iterator I, BranchProbability Prob)
Set successor probability of a given iterator.
succ_iterator succ_begin()
LLVM_ABI void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
SmallVectorImpl< MachineBasicBlock * >::iterator succ_iterator
LLVM_ABI void sortUniqueLiveIns()
Sorts and uniques the LiveIns vector.
LLVM_ABI bool isPredecessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a predecessor of this block.
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
void setIsEHPad(bool V=true)
Indicates the block is a landing pad.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
LLVM_ABI int CreateStackObject(uint64_t Size, Align Alignment, bool isSpillSlot, const AllocaInst *Alloca=nullptr, uint8_t ID=0)
Create a new statically sized stack object, returning a nonnegative identifier to represent it.
int getStackProtectorIndex() const
Return the index for the stack protector object.
void setStackProtectorIndex(int I)
LLVM_ABI int CreateVariableSizedObject(Align Alignment, const AllocaInst *Alloca)
Notify the MachineFrameInfo object that a variable sized object has been created.
void setHasMustTailInVarArgFunc(bool B)
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
ArrayRef< int > allocateShuffleMask(ArrayRef< int > Mask)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, LLT MemTy, Align base_alignment, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
unsigned getTypeIDFor(const GlobalValue *TI)
Return the type id for the specified typeinfo. This is function wide.
void push_back(MachineBasicBlock *MBB)
void setHasFakeUses(bool V)
MCContext & getContext() const
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
MCSymbol * addLandingPad(MachineBasicBlock *LandingPad)
Add a new panding pad, and extract the exception handling information from the landingpad instruction...
void deleteMachineBasicBlock(MachineBasicBlock *MBB)
DeleteMachineBasicBlock - Delete the given MachineBasicBlock.
Function & getFunction()
Return the LLVM function that this machine code represents.
void remove(iterator MBBI)
void setVariableDbgInfo(const DILocalVariable *Var, const DIExpression *Expr, int Slot, const DILocation *Loc)
Collect information used to emit debugging information of a variable in a stack slot.
const MachineBasicBlock & front() const
void addInvoke(MachineBasicBlock *LandingPad, MCSymbol *BeginLabel, MCSymbol *EndLabel)
Provide the begin and end labels of an invoke style call and associate it with a try landing pad bloc...
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *BB=nullptr, std::optional< UniqueBBID > BBID=std::nullopt)
CreateMachineBasicBlock - Allocate a new MachineBasicBlock.
void erase(iterator MBBI)
void insert(iterator MBBI, MachineBasicBlock *MBB)
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Helper class to build MachineInstr.
MachineInstrBuilder buildFPTOUI_SAT(const DstOp &Dst, const SrcOp &Src0)
Build and insert Res = G_FPTOUI_SAT Src0.
MachineInstrBuilder buildFMul(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
MachineInstrBuilder buildFreeze(const DstOp &Dst, const SrcOp &Src)
Build and insert Dst = G_FREEZE Src.
MachineInstrBuilder buildBr(MachineBasicBlock &Dest)
Build and insert G_BR Dest.
MachineInstrBuilder buildAdd(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_ADD Op0, Op1.
MachineInstrBuilder buildUndef(const DstOp &Res)
Build and insert Res = IMPLICIT_DEF.
MachineInstrBuilder buildResetFPMode()
Build and insert G_RESET_FPMODE.
MachineInstrBuilder buildFPExt(const DstOp &Res, const SrcOp &Op, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_FPEXT Op.
MachineInstrBuilder buildFPTOSI_SAT(const DstOp &Dst, const SrcOp &Src0)
Build and insert Res = G_FPTOSI_SAT Src0.
MachineInstrBuilder buildUCmp(const DstOp &Res, const SrcOp &Op0, const SrcOp &Op1)
Build and insert a Res = G_UCMP Op0, Op1.
MachineInstrBuilder buildJumpTable(const LLT PtrTy, unsigned JTI)
Build and insert Res = G_JUMP_TABLE JTI.
MachineInstrBuilder buildGetRounding(const DstOp &Dst)
Build and insert Dst = G_GET_ROUNDING.
MachineInstrBuilder buildSCmp(const DstOp &Res, const SrcOp &Op0, const SrcOp &Op1)
Build and insert a Res = G_SCMP Op0, Op1.
MachineInstrBuilder buildFence(unsigned Ordering, unsigned Scope)
Build and insert G_FENCE Ordering, Scope.
MachineInstrBuilder buildSelect(const DstOp &Res, const SrcOp &Tst, const SrcOp &Op0, const SrcOp &Op1, std::optional< unsigned > Flags=std::nullopt)
Build and insert a Res = G_SELECT Tst, Op0, Op1.
MachineInstrBuilder buildFMA(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, const SrcOp &Src2, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_FMA Op0, Op1, Op2.
MachineInstrBuilder buildMul(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_MUL Op0, Op1.
MachineInstrBuilder buildInsertSubvector(const DstOp &Res, const SrcOp &Src0, const SrcOp &Src1, unsigned Index)
Build and insert Res = G_INSERT_SUBVECTOR Src0, Src1, Idx.
MachineInstrBuilder buildAnd(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1)
Build and insert Res = G_AND Op0, Op1.
MachineInstrBuilder buildCast(const DstOp &Dst, const SrcOp &Src)
Build and insert an appropriate cast between two registers of equal size.
MachineInstrBuilder buildICmp(CmpInst::Predicate Pred, const DstOp &Res, const SrcOp &Op0, const SrcOp &Op1, std::optional< unsigned > Flags=std::nullopt)
Build and insert a Res = G_ICMP Pred, Op0, Op1.
MachineBasicBlock::iterator getInsertPt()
Current insertion point for new instructions.
MachineInstrBuilder buildSExtOrTrunc(const DstOp &Res, const SrcOp &Op)
Build and insert Res = G_SEXT Op, Res = G_TRUNC Op, or Res = COPY Op depending on the differing sizes...
MachineInstrBuilder buildAtomicRMW(unsigned Opcode, const DstOp &OldValRes, const SrcOp &Addr, const SrcOp &Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_<Opcode> Addr, Val, MMO.
MachineInstrBuilder buildSub(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_SUB Op0, Op1.
MachineInstrBuilder buildIntrinsic(Intrinsic::ID ID, ArrayRef< Register > Res, bool HasSideEffects, bool isConvergent)
Build and insert a G_INTRINSIC instruction.
MachineInstrBuilder buildVScale(const DstOp &Res, unsigned MinElts)
Build and insert Res = G_VSCALE MinElts.
MachineInstrBuilder buildSplatBuildVector(const DstOp &Res, const SrcOp &Src)
Build and insert Res = G_BUILD_VECTOR with Src replicated to fill the number of elements.
MachineInstrBuilder buildSetFPMode(const SrcOp &Src)
Build and insert G_SET_FPMODE Src.
MachineInstrBuilder buildIndirectDbgValue(Register Reg, const MDNode *Variable, const MDNode *Expr)
Build and insert a DBG_VALUE instruction expressing the fact that the associated Variable lives in me...
MachineInstrBuilder buildConstDbgValue(const Constant &C, const MDNode *Variable, const MDNode *Expr)
Build and insert a DBG_VALUE instructions specifying that Variable is given by C (suitably modified b...
MachineInstrBuilder buildBrCond(const SrcOp &Tst, MachineBasicBlock &Dest)
Build and insert G_BRCOND Tst, Dest.
std::optional< MachineInstrBuilder > materializeObjectPtrOffset(Register &Res, Register Op0, const LLT ValueTy, uint64_t Value)
Materialize and insert an instruction with appropriate flags for addressing some offset of an object,...
MachineInstrBuilder buildExtractVectorElement(const DstOp &Res, const SrcOp &Val, const SrcOp &Idx)
Build and insert Res = G_EXTRACT_VECTOR_ELT Val, Idx.
MachineInstrBuilder buildLoad(const DstOp &Res, const SrcOp &Addr, MachineMemOperand &MMO)
Build and insert Res = G_LOAD Addr, MMO.
MachineInstrBuilder buildPtrAdd(const DstOp &Res, const SrcOp &Op0, const SrcOp &Op1, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_PTR_ADD Op0, Op1.
MachineInstrBuilder buildZExtOrTrunc(const DstOp &Res, const SrcOp &Op)
Build and insert Res = G_ZEXT Op, Res = G_TRUNC Op, or Res = COPY Op depending on the differing sizes...
MachineInstrBuilder buildExtractVectorElementConstant(const DstOp &Res, const SrcOp &Val, const int Idx)
Build and insert Res = G_EXTRACT_VECTOR_ELT Val, Idx.
MachineInstrBuilder buildShl(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
MachineInstrBuilder buildStore(const SrcOp &Val, const SrcOp &Addr, MachineMemOperand &MMO)
Build and insert G_STORE Val, Addr, MMO.
MachineInstrBuilder buildInstr(unsigned Opcode)
Build and insert <empty> = Opcode <empty>.
MachineInstrBuilder buildFrameIndex(const DstOp &Res, int Idx)
Build and insert Res = G_FRAME_INDEX Idx.
MachineInstrBuilder buildDirectDbgValue(Register Reg, const MDNode *Variable, const MDNode *Expr)
Build and insert a DBG_VALUE instruction expressing the fact that the associated Variable lives in Re...
MachineInstrBuilder buildDbgLabel(const MDNode *Label)
Build and insert a DBG_LABEL instructions specifying that Label is given.
MachineInstrBuilder buildBrJT(Register TablePtr, unsigned JTI, Register IndexReg)
Build and insert G_BRJT TablePtr, JTI, IndexReg.
MachineInstrBuilder buildDynStackAlloc(const DstOp &Res, const SrcOp &Size, Align Alignment)
Build and insert Res = G_DYN_STACKALLOC Size, Align.
MachineInstrBuilder buildFIDbgValue(int FI, const MDNode *Variable, const MDNode *Expr)
Build and insert a DBG_VALUE instruction expressing the fact that the associated Variable lives in th...
MachineInstrBuilder buildResetFPEnv()
Build and insert G_RESET_FPENV.
void setDebugLoc(const DebugLoc &DL)
Set the debug location to DL for all the next build instructions.
const MachineBasicBlock & getMBB() const
Getter for the basic block we currently build.
MachineInstrBuilder buildInsertVectorElement(const DstOp &Res, const SrcOp &Val, const SrcOp &Elt, const SrcOp &Idx)
Build and insert Res = G_INSERT_VECTOR_ELT Val, Elt, Idx.
MachineInstrBuilder buildAtomicCmpXchgWithSuccess(const DstOp &OldValRes, const DstOp &SuccessRes, const SrcOp &Addr, const SrcOp &CmpVal, const SrcOp &NewVal, MachineMemOperand &MMO)
Build and insert OldValRes<def>, SuccessRes<def> = G_ATOMIC_CMPXCHG_WITH_SUCCESS Addr,...
void setMBB(MachineBasicBlock &MBB)
Set the insertion point to the end of MBB.
const DebugLoc & getDebugLoc()
Get the current instruction's debug location.
MachineInstrBuilder buildTrap(bool Debug=false)
Build and insert G_TRAP or G_DEBUGTRAP.
MachineInstrBuilder buildFFrexp(const DstOp &Fract, const DstOp &Exp, const SrcOp &Src, std::optional< unsigned > Flags=std::nullopt)
Build and insert Fract, Exp = G_FFREXP Src.
MachineInstrBuilder buildFPTrunc(const DstOp &Res, const SrcOp &Op, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_FPTRUNC Op.
MachineInstrBuilder buildFSincos(const DstOp &Sin, const DstOp &Cos, const SrcOp &Src, std::optional< unsigned > Flags=std::nullopt)
Build and insert Sin, Cos = G_FSINCOS Src.
MachineInstrBuilder buildShuffleVector(const DstOp &Res, const SrcOp &Src1, const SrcOp &Src2, ArrayRef< int > Mask)
Build and insert Res = G_SHUFFLE_VECTOR Src1, Src2, Mask.
MachineInstrBuilder buildInstrNoInsert(unsigned Opcode)
Build but don't insert <empty> = Opcode <empty>.
MachineInstrBuilder buildCopy(const DstOp &Res, const SrcOp &Op)
Build and insert Res = COPY Op.
MachineInstrBuilder buildPrefetch(const SrcOp &Addr, unsigned RW, unsigned Locality, unsigned CacheType, MachineMemOperand &MMO)
Build and insert G_PREFETCH Addr, RW, Locality, CacheType.
MachineInstrBuilder buildExtractSubvector(const DstOp &Res, const SrcOp &Src, unsigned Index)
Build and insert Res = G_EXTRACT_SUBVECTOR Src, Idx0.
const DataLayout & getDataLayout() const
MachineInstrBuilder buildBrIndirect(Register Tgt)
Build and insert G_BRINDIRECT Tgt.
MachineInstrBuilder buildSplatVector(const DstOp &Res, const SrcOp &Val)
Build and insert Res = G_SPLAT_VECTOR Val.
MachineInstrBuilder buildStepVector(const DstOp &Res, unsigned Step)
Build and insert Res = G_STEP_VECTOR Step.
virtual MachineInstrBuilder buildConstant(const DstOp &Res, const ConstantInt &Val)
Build and insert Res = G_CONSTANT Val.
MachineInstrBuilder buildFCmp(CmpInst::Predicate Pred, const DstOp &Res, const SrcOp &Op0, const SrcOp &Op1, std::optional< unsigned > Flags=std::nullopt)
Build and insert a Res = G_FCMP PredOp0, Op1.
MachineInstrBuilder buildFAdd(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_FADD Op0, Op1.
MachineInstrBuilder buildSetFPEnv(const SrcOp &Src)
Build and insert G_SET_FPENV Src.
Register getReg(unsigned Idx) const
Get the register for the operand index.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addMetadata(const MDNode *MD) const
const MachineInstrBuilder & addSym(MCSymbol *Sym, unsigned char TargetFlags=0) const
const MachineInstrBuilder & addFrameIndex(int Idx) const
const MachineInstrBuilder & addFPImm(const ConstantFP *Val) const
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const MachineInstrBuilder & addUse(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register use operand.
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
MachineInstr * getInstr() const
If conversion operators fail, use this method to get the MachineInstr explicitly.
const MachineInstrBuilder & addDef(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register definition operand.
Representation of each machine instruction.
LLVM_ABI void copyIRFlags(const Instruction &I)
Copy all flags to MachineInst MIFlags.
static LLVM_ABI uint32_t copyFlagsFromInstruction(const Instruction &I)
const MachineOperand & getOperand(unsigned i) const
A description of a memory reference used in the backend.
Flags
Flags values. These may be or'd together.
@ MOVolatile
The memory access is volatile.
@ MODereferenceable
The memory access is dereferenceable (i.e., doesn't trap).
@ MOLoad
The memory access reads data.
@ MOInvariant
The memory access always returns the same value (or traps).
@ MOStore
The memory access writes data.
static MachineOperand CreateES(const char *SymName, unsigned TargetFlags=0)
Register getReg() const
getReg - Returns the register number.
static MachineOperand CreateGA(const GlobalValue *GV, int64_t Offset, unsigned TargetFlags=0)
LLVM_ABI MachineInstr * getVRegDef(Register Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
LLT getType(Register Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register.
LLVM_ABI void setRegClass(Register Reg, const TargetRegisterClass *RC)
setRegClass - Set the register class of the specified virtual register.
LLVM_ABI Register createGenericVirtualRegister(LLT Ty, StringRef Name="")
Create and return a new generic virtual register with low-level type Ty.
void addPhysRegsUsedFromRegMask(const uint32_t *RegMask)
addPhysRegsUsedFromRegMask - Mark any registers not in RegMask as used.
Representation for a specific memory location.
A Module instance is used to store all the information related to an LLVM module.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
Class to install both of the above.
Wrapper class representing virtual and physical registers.
MCRegister asMCReg() const
Utility to check-convert this value to a MCRegister.
Return a value (possibly void), from a function.
Value * getReturnValue() const
Convenience accessor. Returns null if there is no return value.
This class represents the LLVM 'select' instruction.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Encapsulates all of the information needed to generate a stack protector check, and signals to isel w...
void initialize(const BasicBlock *BB, MachineBasicBlock *MBB, bool FunctionBasedInstrumentation)
Initialize the stack protector descriptor structure for a new basic block.
MachineBasicBlock * getSuccessMBB()
void resetPerBBState()
Reset state that changes when we handle different basic blocks.
void resetPerFunctionState()
Reset state that only changes when we switch functions.
MachineBasicBlock * getFailureMBB()
MachineBasicBlock * getParentMBB()
bool shouldEmitStackProtector() const
Returns true if all fields of the stack protector descriptor are initialized implying that we should/...
bool shouldEmitFunctionBasedCheckStackProtector() const
An instruction for storing to memory.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
TypeSize getElementOffset(unsigned Idx) const
Class to represent struct types.
bool createEntriesInEntryBlock(DebugLoc DbgLoc)
Create initial definitions of swifterror values in the entry block of the current function.
void setFunction(MachineFunction &MF)
Initialize data structures for specified new function.
void setCurrentVReg(const MachineBasicBlock *MBB, const Value *, Register)
Set the swifterror virtual register in the VRegDefMap for this basic block.
Register getOrCreateVRegUseAt(const Instruction *, const MachineBasicBlock *, const Value *)
Get or create the swifterror value virtual register for a use of a swifterror by an instruction.
Register getOrCreateVRegDefAt(const Instruction *, const MachineBasicBlock *, const Value *)
Get or create the swifterror value virtual register for a def of a swifterror by an instruction.
const Value * getFunctionArg() const
Get the (unique) function argument that was marked swifterror, or nullptr if this function has no swi...
void propagateVRegs()
Propagate assigned swifterror vregs through a function, synthesizing PHI nodes when needed to maintai...
Align getStackAlign() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
TargetInstrInfo - Interface to description of machine instruction set.
virtual bool isFMAFasterThanFMulAndFAdd(const MachineFunction &MF, EVT) const
Return true if an FMA operation is faster than a pair of fmul and fadd instructions.
virtual unsigned getVaListSizeInBits(const DataLayout &DL) const
Returns the size of the platform's va_list object.
EVT getValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const
Return the EVT corresponding to this LLVM type.
CallingConv::ID getLibcallCallingConv(RTLIB::Libcall Call) const
Get the CallingConv that should be used for the specified libcall.
virtual bool useStackGuardXorFP() const
If this function returns true, stack protection checks should XOR the frame pointer (or whichever poi...
const TargetMachine & getTargetMachine() const
virtual Value * getSDagStackGuard(const Module &M) const
Return the variable that's previously inserted by insertSSPDeclarations, if any, otherwise return nul...
bool isJumpExpensive() const
Return true if Flow Control is an expensive operation that should be avoided.
virtual Function * getSSPStackGuardCheck(const Module &M) const
If the target has a standard stack protection check function that performs validation and error handl...
MachineMemOperand::Flags getAtomicMemOperandFlags(const Instruction &AI, const DataLayout &DL) const
virtual bool getTgtMemIntrinsic(IntrinsicInfo &, const CallInst &, MachineFunction &, unsigned) const
Given an intrinsic, checks if on the target the intrinsic will need to map to a MemIntrinsicNode (tou...
MachineMemOperand::Flags getLoadMemOperandFlags(const LoadInst &LI, const DataLayout &DL, AssumptionCache *AC=nullptr, const TargetLibraryInfo *LibInfo=nullptr) const
MachineMemOperand::Flags getStoreMemOperandFlags(const StoreInst &SI, const DataLayout &DL) const
virtual bool fallBackToDAGISel(const Instruction &Inst) const
virtual Register getExceptionPointerRegister(const Constant *PersonalityFn) const
If a physical register, this returns the register that receives the exception address on entry to an ...
const char * getLibcallName(RTLIB::Libcall Call) const
Get the libcall routine name for the specified libcall.
virtual Register getExceptionSelectorRegister(const Constant *PersonalityFn) const
If a physical register, this returns the register that receives the exception typeid on entry to a la...
virtual MVT getPointerMemTy(const DataLayout &DL, uint32_t AS=0) const
Return the in-memory pointer type for the given address space, defaults to the pointer type from the ...
virtual unsigned getVectorIdxWidth(const DataLayout &DL) const
Returns the type to be used for the index operand vector operations.
virtual bool useLoadStackGuardNode(const Module &M) const
If this function returns true, SelectionDAGBuilder emits a LOAD_STACK_GUARD node when it is lowering ...
Primary interface to the complete machine description for the target machine.
CodeGenOptLevel getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
const Triple & getTargetTriple() const
unsigned NoTrapAfterNoreturn
Do not emit a trap instruction for 'unreachable' IR instructions behind noreturn calls,...
unsigned TrapUnreachable
Emit target-specific trap instruction for 'unreachable' IR instructions.
Target-Independent Code Generator Pass Configuration Options.
virtual std::unique_ptr< CSEConfigBase > getCSEConfig() const
Returns the CSEConfig object to use for the current optimization level.
virtual bool isGISelCSEEnabled() const
Check whether continuous CSE should be enabled in GISel passes.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const InlineAsmLowering * getInlineAsmLowering() const
virtual const CallLowering * getCallLowering() const
virtual const TargetFrameLowering * getFrameLowering() const
virtual const TargetInstrInfo * getInstrInfo() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
virtual const TargetLowering * getTargetLowering() const
bool isOSWindows() const
Tests whether the OS is Windows.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM_ABI bool isEmptyTy() const
Return true if this type is empty, that is, it has no elements or all of its elements are empty.
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
TypeID
Definitions of all of the base types for the Type system.
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
bool isAggregateType() const
Return true if the type is an aggregate type.
bool isTokenTy() const
Return true if this is 'token'.
bool isVoidTy() const
Return true if this is 'void'.
Value * getOperand(unsigned i) const
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
bool hasOneUse() const
Return true if there is exactly one use of this value.
LLVM_ABI const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
LLVM_ABI LLVMContext & getContext() const
All values hold a context through their type.
int getNumOccurrences() const
constexpr bool isZero() const
const ParentTy * getParent() const
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
A raw_ostream that writes to an std::string.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
@ C
The default llvm calling convention, compatible with C.
@ Libcall
The operation should be implemented as a call to some kind of runtime support library.
BinaryOp_match< SrcTy, SpecificConstantMatch, TargetOpcode::G_XOR, true > m_Not(const SrcTy &&Src)
Matches a register not-ed by a G_XOR.
OneUse_match< SubPat > m_OneUse(const SubPat &SP)
bool match(Val *V, const Pattern &P)
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
TwoOps_match< Val_t, Idx_t, Instruction::ExtractElement > m_ExtractElt(const Val_t &Val, const Idx_t &Idx)
Matches ExtractElementInst.
auto m_LogicalOr()
Matches L || R where L and R are arbitrary values.
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
auto m_LogicalAnd()
Matches L && R where L and R are arbitrary values.
@ Implicit
Not emitted register (e.g. carry, or temporary result).
@ Undef
Value of the register doesn't matter.
SmallVector< SwitchWorkListItem, 4 > SwitchWorkList
std::vector< CaseCluster > CaseClusterVector
void sortAndRangeify(CaseClusterVector &Clusters)
Sort Clusters and merge adjacent cases.
CaseClusterVector::iterator CaseClusterIt
@ CC_Range
A cluster of adjacent case labels with the same destination, or just one case.
@ CC_JumpTable
A cluster of cases suitable for jump table lowering.
@ CC_BitTests
A cluster of cases suitable for bit test lowering.
@ CE
Windows NT (Windows on ARM)
Reg
All possible values of the reg field in the ModR/M byte.
initializer< Ty > init(const Ty &Val)
ExceptionBehavior
Exception behavior used for floating point operations.
@ ebIgnore
This corresponds to "fpexcept.ignore".
DiagnosticInfoOptimizationBase::Argument NV
NodeAddr< PhiNode * > Phi
NodeAddr< CodeNode * > Code
BaseReg
Stack frame base register. Bit 0 of FREInfo.Info.
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
@ Low
Lower the current thread's priority such that it does not affect foreground tasks significantly.
int popcount(T Value) noexcept
Count the number of set bits in a value.
detail::scope_exit< std::decay_t< Callable > > make_scope_exit(Callable &&F)
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
int countr_one(T Value)
Count the number of ones from the least significant bit to the first zero bit.
LLVM_ABI void diagnoseDontCall(const CallInst &CI)
auto successors(const MachineBasicBlock *BB)
LLVM_ABI MVT getMVTForLLT(LLT Ty)
Get a rough equivalent of an MVT for a given LLT.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
constexpr bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
gep_type_iterator gep_type_end(const User *GEP)
MachineBasicBlock::iterator findSplitPointForStackProtector(MachineBasicBlock *BB, const TargetInstrInfo &TII)
Find the split point at which to splice the end of BB into its success stack protector check machine ...
LLVM_ABI LLT getLLTForMVT(MVT Ty)
Get a rough equivalent of an LLT for a given MVT.
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
Align getKnownAlignment(Value *V, const DataLayout &DL, const Instruction *CxtI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr)
Try to infer an alignment for the specified pointer.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI llvm::SmallVector< int, 16 > createStrideMask(unsigned Start, unsigned Stride, unsigned VF)
Create a stride shuffle mask.
auto reverse(ContainerTy &&C)
void computeValueLLTs(const DataLayout &DL, Type &Ty, SmallVectorImpl< LLT > &ValueTys, SmallVectorImpl< uint64_t > *Offsets=nullptr, uint64_t StartingOffset=0)
computeValueLLTs - Given an LLVM IR type, compute a sequence of LLTs that represent all the individua...
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
auto succ_size(const MachineBasicBlock *BB)
LLVM_ABI EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
CodeGenOptLevel
Code generation optimization level.
@ Success
The lock was released successfully.
@ Global
Append to llvm.global_dtors.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
LLVM_ABI void getSelectionDAGFallbackAnalysisUsage(AnalysisUsage &AU)
Modify analysis usage so it preserves passes required for the SelectionDAG fallback.
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
LLVM_ABI llvm::SmallVector< int, 16 > createInterleaveMask(unsigned VF, unsigned NumVecs)
Create an interleave shuffle mask.
@ Sub
Subtraction of integers.
bool isAsynchronousEHPersonality(EHPersonality Pers)
Returns true if this personality function catches asynchronous exceptions.
LLVM_ABI std::optional< RoundingMode > convertStrToRoundingMode(StringRef)
Returns a valid RoundingMode enumerator when given a string that is valid as input in constrained int...
gep_type_iterator gep_type_begin(const User *GEP)
GlobalValue * ExtractTypeInfo(Value *V)
ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V.
Align commonAlignment(Align A, uint64_t Offset)
Returns the alignment that satisfies both alignments.
LLVM_ABI LLT getLLTForType(Type &Ty, const DataLayout &DL)
Construct a low-level type based on an LLVM type.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
This struct is a compact representation of a valid (non-zero power of two) alignment.
uint64_t value() const
This is a hole in the type system and should not be abused.
Pair of physical register and lane mask.
This class contains a discriminated union of information about pointers in memory operands,...
static LLVM_ABI MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
MachineBasicBlock * Parent
This structure is used to communicate between SelectionDAGBuilder and SDISel for the code generation ...
BranchProbability TrueProb
MachineBasicBlock * ThisBB
struct PredInfoPair PredInfo
BranchProbability FalseProb
MachineBasicBlock * TrueBB
MachineBasicBlock * FalseBB