71 #define DEBUG_TYPE "irtranslator"
91 if (!R.getLocation().isValid() || TPC.isGlobalISelAbortEnabled())
92 R << (
" (in function: " + MF.getName() +
")").str();
94 if (TPC.isGlobalISelAbortEnabled())
109 unsigned IRTranslator::getOrCreateVReg(
const Value &Val) {
110 unsigned &ValReg = ValToVReg[&Val];
118 "Don't know how to create an empty vreg");
123 if (
auto CV = dyn_cast<Constant>(&Val)) {
124 bool Success = translate(*CV, VReg);
129 R <<
"unable to translate constant: " <<
ore::NV(
"Type", Val.
getType());
138 int IRTranslator::getOrCreateFrameIndex(
const AllocaInst &AI) {
139 if (FrameIndices.find(&AI) != FrameIndices.end())
140 return FrameIndices[&AI];
144 ElementSize * cast<ConstantInt>(AI.
getArraySize())->getZExtValue();
153 int &FI = FrameIndices[&AI];
158 unsigned IRTranslator::getMemOpAlignment(
const Instruction &
I) {
159 unsigned Alignment = 0;
160 Type *ValTy =
nullptr;
161 if (
const StoreInst *SI = dyn_cast<StoreInst>(&I)) {
162 Alignment =
SI->getAlignment();
163 ValTy =
SI->getValueOperand()->getType();
164 }
else if (
const LoadInst *LI = dyn_cast<LoadInst>(&I)) {
165 Alignment = LI->getAlignment();
166 ValTy = LI->getType();
169 R <<
"unable to translate memop: " <<
ore::NV(
"Opcode", &I);
179 assert(MBB &&
"BasicBlock was not encountered before");
184 assert(NewPred &&
"new predecessor must be a real MachineBasicBlock");
185 MachinePreds[Edge].push_back(NewPred);
188 bool IRTranslator::translateBinaryOp(
unsigned Opcode,
const User &U,
196 unsigned Op0 = getOrCreateVReg(*U.
getOperand(0));
197 unsigned Op1 = getOrCreateVReg(*U.
getOperand(1));
198 unsigned Res = getOrCreateVReg(U);
208 .
addDef(getOrCreateVReg(U))
212 return translateBinaryOp(TargetOpcode::G_FSUB, U, MIRBuilder);
215 bool IRTranslator::translateCompare(
const User &U,
218 unsigned Op0 = getOrCreateVReg(*U.
getOperand(0));
219 unsigned Op1 = getOrCreateVReg(*U.
getOperand(1));
220 unsigned Res = getOrCreateVReg(U);
223 cast<ConstantExpr>(U).getPredicate());
225 MIRBuilder.
buildICmp(Pred, Res, Op0, Op1);
233 MIRBuilder.
buildFCmp(Pred, Res, Op0, Op1);
244 return CLI->
lowerReturn(MIRBuilder, Ret, !Ret ? 0 : getOrCreateVReg(*Ret));
248 const BranchInst &BrInst = cast<BranchInst>(U);
272 bool IRTranslator::translateSwitch(
const User &U,
281 const SwitchInst &SwInst = cast<SwitchInst>(U);
282 const unsigned SwCondValue = getOrCreateVReg(*SwInst.
getCondition());
286 for (
auto &CaseIt : SwInst.
cases()) {
287 const unsigned CaseValueReg = getOrCreateVReg(*CaseIt.getCaseValue());
291 const BasicBlock *TrueBB = CaseIt.getCaseSuccessor();
296 addMachineCFGPred({OrigBB, TrueBB}, &CurMBB);
305 MIRBuilder.
setMBB(*FalseMBB);
310 MIRBuilder.
buildBr(DefaultMBB);
313 addMachineCFGPred({OrigBB, DefaultBB}, &CurMBB);
318 bool IRTranslator::translateIndirectBr(
const User &U,
322 const unsigned Tgt = getOrCreateVReg(*BrInst.
getAddress());
334 const LoadInst &LI = cast<LoadInst>(U);
340 unsigned Res = getOrCreateVReg(LI);
347 getMemOpAlignment(LI),
AAMDNodes(),
nullptr,
371 bool IRTranslator::translateExtractValue(
const User &U,
379 if (
auto CS = dyn_cast<ConstantStruct>(Src))
380 if (
CS->getNumOperands() == 1) {
381 unsigned Res = getOrCreateVReg(*
CS->getOperand(0));
391 for (
auto Idx : EVI->indices())
400 unsigned Res = getOrCreateVReg(U);
401 MIRBuilder.
buildExtract(Res, getOrCreateVReg(*Src), Offset);
406 bool IRTranslator::translateInsertValue(
const User &U,
417 for (
auto Idx : IVI->indices())
426 unsigned Res = getOrCreateVReg(U);
427 unsigned Inserted = getOrCreateVReg(*U.
getOperand(1));
428 MIRBuilder.
buildInsert(Res, getOrCreateVReg(*Src), Inserted, Offset);
433 bool IRTranslator::translateSelect(
const User &U,
435 unsigned Res = getOrCreateVReg(U);
436 unsigned Tst = getOrCreateVReg(*U.
getOperand(0));
437 unsigned Op0 = getOrCreateVReg(*U.
getOperand(1));
438 unsigned Op1 = getOrCreateVReg(*U.
getOperand(2));
443 bool IRTranslator::translateBitCast(
const User &U,
449 unsigned SrcReg = getOrCreateVReg(*U.
getOperand(0));
450 unsigned &
Reg = ValToVReg[&U];
459 return translateCast(TargetOpcode::G_BITCAST, U, MIRBuilder);
462 bool IRTranslator::translateCast(
unsigned Opcode,
const User &U,
465 unsigned Res = getOrCreateVReg(U);
470 bool IRTranslator::translateGetElementPtr(
const User &U,
477 unsigned BaseReg = getOrCreateVReg(Op0);
486 const Value *Idx = GTI.getOperand();
487 if (
StructType *StTy = GTI.getStructTypeOrNull()) {
488 unsigned Field = cast<Constant>(Idx)->getUniqueInteger().getZExtValue();
496 if (
const auto *CI = dyn_cast<ConstantInt>(Idx)) {
497 Offset += ElementSize * CI->getSExtValue();
505 MIRBuilder.
buildGEP(NewBaseReg, BaseReg, OffsetReg);
507 BaseReg = NewBaseReg;
512 unsigned ElementSizeReg =
515 unsigned IdxReg = getOrCreateVReg(*Idx);
516 if (MRI->
getType(IdxReg) != OffsetTy) {
523 MIRBuilder.
buildMul(OffsetReg, ElementSizeReg, IdxReg);
526 MIRBuilder.
buildGEP(NewBaseReg, BaseReg, OffsetReg);
527 BaseReg = NewBaseReg;
532 unsigned OffsetReg = getOrCreateVReg(*
ConstantInt::get(OffsetIRTy, Offset));
533 MIRBuilder.
buildGEP(getOrCreateVReg(U), BaseReg, OffsetReg);
537 MIRBuilder.
buildCopy(getOrCreateVReg(U), BaseReg);
541 bool IRTranslator::translateMemfunc(
const CallInst &CI,
546 if (cast<PointerType>(DstTy)->getAddressSpace() != 0 ||
551 for (
int i = 0; i < 3; ++i) {
553 Args.
emplace_back(getOrCreateVReg(*Arg), Arg->getType());
558 case Intrinsic::memmove:
559 case Intrinsic::memcpy: {
561 if(cast<PointerType>(SrcTy)->getAddressSpace() != 0)
563 Callee = ID == Intrinsic::memcpy ?
"memcpy" :
"memmove";
566 case Intrinsic::memset:
578 void IRTranslator::getStackGuard(
unsigned DstReg,
582 auto MIB = MIRBuilder.
buildInstr(TargetOpcode::LOAD_STACK_GUARD);
597 MIB.setMemRefs(MemRefs, MemRefs + 1);
600 bool IRTranslator::translateOverflowIntrinsic(
const CallInst &CI,
unsigned Op,
613 if (Op == TargetOpcode::G_UADDE || Op == TargetOpcode::G_USUBE) {
614 unsigned Zero = getOrCreateVReg(
619 MIRBuilder.
buildSequence(getOrCreateVReg(CI), {Res, Overflow}, {0, Width});
628 case Intrinsic::lifetime_start:
629 case Intrinsic::lifetime_end:
636 case Intrinsic::dbg_declare: {
641 if (!Address || isa<UndefValue>(Address)) {
642 DEBUG(
dbgs() <<
"Dropping debug info for " << DI <<
"\n");
648 "Expected inlined-at fields to agree");
660 case Intrinsic::vaend:
664 case Intrinsic::vastart: {
667 unsigned ListSize = TLI.getVaListSizeInBits(*DL) / 8;
669 MIRBuilder.
buildInstr(TargetOpcode::G_VASTART)
670 .
addUse(getOrCreateVReg(*Ptr))
675 case Intrinsic::dbg_value: {
681 "Expected inlined-at fields to agree");
687 }
else if (
const auto *CI = dyn_cast<Constant>(V)) {
691 unsigned Reg = getOrCreateVReg(*V);
705 case Intrinsic::uadd_with_overflow:
706 return translateOverflowIntrinsic(CI, TargetOpcode::G_UADDE, MIRBuilder);
707 case Intrinsic::sadd_with_overflow:
708 return translateOverflowIntrinsic(CI, TargetOpcode::G_SADDO, MIRBuilder);
709 case Intrinsic::usub_with_overflow:
710 return translateOverflowIntrinsic(CI, TargetOpcode::G_USUBE, MIRBuilder);
711 case Intrinsic::ssub_with_overflow:
712 return translateOverflowIntrinsic(CI, TargetOpcode::G_SSUBO, MIRBuilder);
713 case Intrinsic::umul_with_overflow:
714 return translateOverflowIntrinsic(CI, TargetOpcode::G_UMULO, MIRBuilder);
715 case Intrinsic::smul_with_overflow:
716 return translateOverflowIntrinsic(CI, TargetOpcode::G_SMULO, MIRBuilder);
719 .
addDef(getOrCreateVReg(CI))
725 .
addDef(getOrCreateVReg(CI))
728 case Intrinsic::exp2:
730 .
addDef(getOrCreateVReg(CI))
735 .
addDef(getOrCreateVReg(CI))
738 case Intrinsic::log2:
740 .
addDef(getOrCreateVReg(CI))
745 .
addDef(getOrCreateVReg(CI))
750 case Intrinsic::memcpy:
751 case Intrinsic::memmove:
752 case Intrinsic::memset:
753 return translateMemfunc(CI, MIRBuilder, ID);
754 case Intrinsic::eh_typeid_for: {
756 unsigned Reg = getOrCreateVReg(CI);
761 case Intrinsic::objectsize: {
768 case Intrinsic::stackguard:
769 getStackGuard(getOrCreateVReg(CI), MIRBuilder);
771 case Intrinsic::stackprotector: {
774 getStackGuard(GuardVal, MIRBuilder);
778 GuardVal, getOrCreateVReg(*Slot),
781 getOrCreateFrameIndex(*Slot)),
790 bool IRTranslator::translateInlineAsm(
const CallInst &CI,
796 unsigned ExtraInfo = 0;
810 const CallInst &CI = cast<CallInst>(U);
815 return translateInlineAsm(CI, MIRBuilder);
824 return CLI->
lowerCall(MIRBuilder, &CI, Res, Args, [&]() {
835 if (translateKnownIntrinsic(CI, ID, MIRBuilder))
844 if (isa<MetadataAsValue>(Arg))
846 MIB.
addUse(getOrCreateVReg(*Arg));
851 TargetLowering::IntrinsicInfo Info;
858 uint64_t Size = Info.memVT.getSizeInBits() >> 3;
860 Flags, Size, Info.align));
866 bool IRTranslator::translateInvoke(
const User &U,
876 if (isa<InlineAsm>(Callee))
888 if (!isa<LandingPadInst>(EHPadBB->
front()))
893 MCSymbol *BeginSymbol = Context.createTempSymbol();
901 if (!CLI->
lowerCall(MIRBuilder, &I, Res, Args,
905 MCSymbol *EndSymbol = Context.createTempSymbol();
910 &ReturnMBB = getMBB(*ReturnBB);
911 MF->addInvoke(&EHPadMBB, BeginSymbol, EndSymbol);
919 bool IRTranslator::translateLandingPad(
const User &U,
953 for (
Type *Ty : cast<StructType>(LP.
getType())->elements())
955 assert(Tys.
size() == 2 &&
"Only two-valued landingpads are supported");
962 MBB.addLiveIn(ExceptionReg);
965 MIRBuilder.
buildCopy(VReg, ExceptionReg);
972 MBB.addLiveIn(SelectorReg);
978 MIRBuilder.
buildCopy(PtrVReg, SelectorReg);
982 MIRBuilder.
buildInsert(getOrCreateVReg(LP), Tmp, VReg,
987 bool IRTranslator::translateAlloca(
const User &U,
989 auto &AI = cast<AllocaInst>(U);
992 unsigned Res = getOrCreateVReg(AI);
993 int FI = getOrCreateFrameIndex(AI);
1003 unsigned NumElts = getOrCreateVReg(*AI.
getArraySize());
1007 if (MRI->
getType(NumElts) != IntPtrTy) {
1016 MIRBuilder.
buildMul(AllocSize, NumElts, TySize);
1026 MIRBuilder.
buildGEP(AllocTmp, SPTmp, AllocSize);
1031 unsigned StackAlign =
1033 Align =
std::max(Align, StackAlign);
1040 AllocTmp = AlignedAlloc;
1044 MIRBuilder.
buildCopy(getOrCreateVReg(AI), AllocTmp);
1057 .
addDef(getOrCreateVReg(U))
1063 bool IRTranslator::translateInsertElement(
const User &U,
1068 unsigned Elt = getOrCreateVReg(*U.
getOperand(1));
1069 ValToVReg[&U] = Elt;
1072 unsigned Res = getOrCreateVReg(U);
1073 unsigned Val = getOrCreateVReg(*U.
getOperand(0));
1074 unsigned Elt = getOrCreateVReg(*U.
getOperand(1));
1075 unsigned Idx = getOrCreateVReg(*U.
getOperand(2));
1080 bool IRTranslator::translateExtractElement(
const User &U,
1085 unsigned Elt = getOrCreateVReg(*U.
getOperand(0));
1086 ValToVReg[&U] = Elt;
1089 unsigned Res = getOrCreateVReg(U);
1090 unsigned Val = getOrCreateVReg(*U.
getOperand(0));
1091 unsigned Idx = getOrCreateVReg(*U.
getOperand(1));
1096 bool IRTranslator::translateShuffleVector(
const User &U,
1098 MIRBuilder.
buildInstr(TargetOpcode::G_SHUFFLE_VECTOR)
1099 .
addDef(getOrCreateVReg(U))
1107 const PHINode &PI = cast<PHINode>(U);
1108 auto MIB = MIRBuilder.
buildInstr(TargetOpcode::PHI);
1109 MIB.
addDef(getOrCreateVReg(PI));
1111 PendingPHIs.emplace_back(&PI, MIB.getInstr());
1115 void IRTranslator::finishPendingPhis() {
1116 for (std::pair<const PHINode *, MachineInstr *> &Phi : PendingPHIs) {
1117 const PHINode *PI = Phi.first;
1128 if (HandledPreds.
count(IRPred))
1131 HandledPreds.
insert(IRPred);
1133 for (
auto Pred : getMachinePredBBs({IRPred, PI->
getParent()})) {
1134 assert(Pred->isSuccessor(MIB->getParent()) &&
1135 "incorrect CFG at MachineBasicBlock level");
1143 bool IRTranslator::translate(
const Instruction &Inst) {
1146 #define HANDLE_INST(NUM, OPCODE, CLASS) \
1147 case Instruction::OPCODE: return translate##OPCODE(Inst, CurBuilder);
1148 #include "llvm/IR/Instruction.def"
1154 bool IRTranslator::translate(
const Constant &
C,
unsigned Reg) {
1155 if (
auto CI = dyn_cast<ConstantInt>(&C))
1157 else if (
auto CF = dyn_cast<ConstantFP>(&C))
1159 else if (isa<UndefValue>(C))
1161 else if (isa<ConstantPointerNull>(C))
1163 else if (
auto GV = dyn_cast<GlobalValue>(&C))
1165 else if (
auto CAZ = dyn_cast<ConstantAggregateZero>(&C)) {
1166 if (!CAZ->getType()->isVectorTy())
1169 if (CAZ->getNumElements() == 1)
1170 return translate(*CAZ->getElementValue(0u),
Reg);
1171 std::vector<unsigned> Ops;
1172 for (
unsigned i = 0; i < CAZ->getNumElements(); ++i) {
1173 Constant &Elt = *CAZ->getElementValue(i);
1174 Ops.push_back(getOrCreateVReg(Elt));
1177 }
else if (
auto CV = dyn_cast<ConstantDataVector>(&C)) {
1179 if (CV->getNumElements() == 1)
1180 return translate(*CV->getElementAsConstant(0),
Reg);
1181 std::vector<unsigned> Ops;
1182 for (
unsigned i = 0; i < CV->getNumElements(); ++i) {
1183 Constant &Elt = *CV->getElementAsConstant(i);
1184 Ops.push_back(getOrCreateVReg(Elt));
1187 }
else if (
auto CE = dyn_cast<ConstantExpr>(&C)) {
1188 switch(
CE->getOpcode()) {
1189 #define HANDLE_INST(NUM, OPCODE, CLASS) \
1190 case Instruction::OPCODE: return translate##OPCODE(*CE, EntryBuilder);
1191 #include "llvm/IR/Instruction.def"
1195 }
else if (
auto CS = dyn_cast<ConstantStruct>(&C)) {
1197 if (
CS->getNumOperands() == 1) {
1198 unsigned EltReg = getOrCreateVReg(*
CS->getOperand(0));
1204 uint64_t Offset = 0;
1205 for (
unsigned i = 0; i <
CS->getNumOperands(); ++i) {
1206 unsigned OpReg = getOrCreateVReg(*
CS->getOperand(i));
1212 }
else if (
auto CV = dyn_cast<ConstantVector>(&C)) {
1213 if (CV->getNumOperands() == 1)
1214 return translate(*CV->getOperand(0),
Reg);
1216 for (
unsigned i = 0; i < CV->getNumOperands(); ++i) {
1217 Ops.
push_back(getOrCreateVReg(*CV->getOperand(i)));
1226 void IRTranslator::finalizeFunction() {
1229 PendingPHIs.clear();
1231 FrameIndices.clear();
1232 MachinePreds.clear();
1246 CurBuilder.
setMF(*MF);
1247 EntryBuilder.
setMF(*MF);
1250 TPC = &getAnalysis<TargetPassConfig>();
1251 ORE = llvm::make_unique<OptimizationRemarkEmitter>(&
F);
1253 assert(PendingPHIs.empty() &&
"stale PHIs");
1256 auto FinalizeOnReturn =
make_scope_exit([
this]() { finalizeFunction(); });
1261 EntryBuilder.
setMBB(*EntryBB);
1265 auto *&MBB = BBToMBB[&BB];
1270 if (BB.hasAddressTaken())
1271 MBB->setHasAddressTaken();
1275 EntryBB->addSuccessor(&getMBB(F.front()));
1279 for (
const Argument &Arg: F.args())
1280 VRegArgs.
push_back(getOrCreateVReg(Arg));
1285 R <<
"unable to lower arguments: " <<
ore::NV(
"Prototype", F.getType());
1298 if (translate(Inst))
1301 std::string InstStrStorage;
1306 Inst.getDebugLoc(), &BB);
1307 R <<
"unable to translate instruction: " <<
ore::NV(
"Opcode", &Inst)
1308 <<
": '" << InstStr.
str() <<
"'";
1314 finishPendingPhis();
1319 assert(EntryBB->succ_size() == 1 &&
1320 "Custom BB used for lowering should have only one successor");
1323 assert(NewEntryBB.pred_size() == 1 &&
1324 "LLVM-IR entry block has a predecessor!?");
1327 NewEntryBB.splice(NewEntryBB.begin(), EntryBB, EntryBB->begin(),
1332 NewEntryBB.addLiveIn(LiveIn);
1333 NewEntryBB.sortUniqueLiveIns();
1336 EntryBB->removeSuccessor(&NewEntryBB);
1341 "New entry wasn't next in the list of basic block!");
virtual bool lowerReturn(MachineIRBuilder &MIRBuilder, const Value *Val, unsigned VReg) const
This hook must be implemented to lower outgoing return values, described by Val, into the specified v...
MachineBasicBlock & getMBB()
Getter for the basic block we currently build.
unsigned getStackAlignment() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
void initializeIRTranslatorPass(PassRegistry &)
BasicBlock * getSuccessor(unsigned i) const
Return a value (possibly void), from a function.
Value * getValueOperand()
const Value * getCalledValue() const
Get a pointer to the function that is invoked by this instruction.
void push_back(const T &Elt)
AsmDialect getDialect() const
This class is the base class for the comparison instructions.
static IntegerType * getInt1Ty(LLVMContext &C)
void setVariableDbgInfo(const DILocalVariable *Var, const DIExpression *Expr, unsigned Slot, const DILocation *Loc)
Collect information used to emit debugging information of a variable.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
iterator_range< CaseIt > cases()
Iteration adapter for range-for loops.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
This class represents an incoming formal argument to a Function.
MachineInstrBuilder buildGEP(unsigned Res, unsigned Op0, unsigned Op1)
Build and insert Res<def> = G_GEP Op0, Op1.
LLT getType(unsigned VReg) const
Get the low-level type of VReg or LLT{} if VReg is not a generic (target independent) virtual registe...
DiagnosticInfoOptimizationBase::Argument NV
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
bool isVolatile() const
Return true if this is a store to a volatile memory location.
MCSymbol * addLandingPad(MachineBasicBlock *LandingPad)
Add a new panding pad. Returns the label ID for the landing pad entry.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
MachineInstrBuilder buildZExtOrTrunc(unsigned Res, unsigned Op)
Build and insert Res<def> = G_ZEXT Op, Res = G_TRUNC Op, or Res = COPY Op depending on the differing ...
void addLandingPadInfo(const LandingPadInst &I, MachineBasicBlock &MBB)
Extract the exception handling information from the landingpad instruction and add them to the specif...
unsigned getNumOperands() const
unsigned getPrefTypeAlignment(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
IRTranslator LLVM IR static false void reportTranslationError(MachineFunction &MF, const TargetPassConfig &TPC, OptimizationRemarkEmitter &ORE, OptimizationRemarkMissed &R)
This class represents a function call, abstracting a target machine's calling convention.
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
const std::string & getAsmString() const
void setDebugLoc(const DebugLoc &DL)
Set the debug location to DL for all the next build instructions.
gep_type_iterator gep_type_end(const User *GEP)
LLVM_NODISCARD detail::scope_exit< typename std::decay< Callable >::type > make_scope_exit(Callable &&F)
iterator_range< op_iterator > arg_operands()
Iteration adapter for range-for loops.
bool isTokenTy() const
Return true if this is 'token'.
const std::string & getConstraintString() const
const Instruction & front() const
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
An instruction for reading from memory.
virtual const CallLowering * getCallLowering() const
unsigned getTypeIDFor(const GlobalValue *TI)
Return the type id for the specified typeinfo. This is function wide.
unsigned createGenericVirtualRegister(LLT Ty)
Create and return a new generic virtual register with low-level type Ty.
virtual unsigned getExceptionPointerRegister(const Constant *PersonalityFn) const
If a physical register, this returns the register that receives the exception address on entry to an ...
MachineInstrBuilder buildExtract(unsigned Res, unsigned Src, uint64_t Index)
Build and insert `Res0<def>, ...
GlobalValue * ExtractTypeInfo(Value *V)
ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V.
void DeleteMachineBasicBlock(MachineBasicBlock *MBB)
DeleteMachineBasicBlock - Delete the given MachineBasicBlock.
const MachineInstrBuilder & addDef(unsigned RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register definition operand.
uint64_t getOffset() const
MachineInstrBuilder buildSelect(unsigned Res, unsigned Tst, unsigned Op0, unsigned Op1)
Build and insert a Res = G_SELECT Tst, Op0, Op1.
MachineInstrBuilder buildFCmp(CmpInst::Predicate Pred, unsigned Res, unsigned Op0, unsigned Op1)
Build and insert a Res = G_FCMP PredOp0, Op1.
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
Value * getAddress() const
MachineInstrBuilder buildStore(unsigned Val, unsigned Addr, MachineMemOperand &MMO)
Build and insert G_STORE Val, Addr, MMO.
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
bool isUnconditional() const
A description of a memory reference used in the backend.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Value * getReturnValue() const
Convenience accessor. Returns null if there is no return value.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID of this store instruction.
unsigned getPointerABIAlignment(unsigned AS=0) const
Layout pointer alignment FIXME: The defaults need to be removed once all of the backends/clients are ...
Class to represent struct types.
const Value * getCalledValue() const
Get a pointer to the function that is invoked by this instruction.
MachineInstrBuilder buildFConstant(unsigned Res, const ConstantFP &Val)
Build and insert Res = G_FCONSTANT Val.
Constant * getPersonalityFn() const
Get the personality function associated with this function.
Reg
All possible values of the reg field in the ModR/M byte.
TypeID
Definitions of all of the base types for the Type system.
The memory access is dereferenceable (i.e., doesn't trap).
MachineInstrBuilder buildExtractVectorElement(unsigned Res, unsigned Val, unsigned Idx)
Build and insert Res<def> = G_EXTRACT_VECTOR_ELT Val, Idx.
Windows NT (Windows on ARM)
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s, unsigned 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.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
Target-Independent Code Generator Pass Configuration Options.
INLINEASM - Represents an inline asm block.
MachineInstrBuilder buildInsertVectorElement(unsigned Res, unsigned Val, unsigned Elt, unsigned Idx)
Build and insert Res<def> = G_INSERT_VECTOR_ELT Val, Elt, Idx.
Context object for machine code objects.
const MachineBasicBlock & front() const
virtual bool lowerCall(MachineIRBuilder &MIRBuilder, CallingConv::ID CallConv, const MachineOperand &Callee, const ArgInfo &OrigRet, ArrayRef< ArgInfo > OrigArgs) const
This hook must be implemented to lower the given call instruction, including argument and return valu...
BasicBlock * getSuccessor(unsigned i) const
An instruction for storing to memory.
MachineInstrBuilder buildConstDbgValue(const Constant &C, unsigned Offset, const MDNode *Variable, const MDNode *Expr)
Build and insert a DBG_VALUE instructions specifying that Variable is given by C (suitably modified b...
CodeGenOpt::Level getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
static LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
MCContext & getContext() const
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *bb=nullptr)
CreateMachineBasicBlock - Allocate a new MachineBasicBlock.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
uint64_t getElementOffset(unsigned Idx) const
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
The memory access is volatile.
MachineInstrBuilder buildBr(MachineBasicBlock &BB)
Build and insert G_BR Dest.
The landingpad instruction holds all of the information necessary to generate correct exception handl...
IRTranslator LLVM IR false
bool hasSideEffects() const
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
DIExpression * getExpression() const
Conditional or Unconditional Branch instruction.
MachineInstrBuilder buildInstr(unsigned Opcode)
Build and insert <empty> = Opcode <empty>.
bool isVectorTy() const
True if this is an instance of VectorType.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
static unsigned getSizeInBits(unsigned Reg, const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI)
Get the size in bits of Reg.
This is an important base class in LLVM.
PointerType * getType() const
Overload to return most specific pointer type.
MachineInstrBuilder buildPtrMask(unsigned Res, unsigned Op0, uint32_t NumBits)
Build and insert Res<def> = G_PTR_MASK Op0, NumBits.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Indirect Branch Instruction.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
unsigned getAlignment() const
Return the alignment of the memory that is being allocated by the instruction.
MachineInstrBuilder buildIntrinsic(Intrinsic::ID ID, unsigned Res, bool HasSideEffects)
Build and insert either a G_INTRINSIC (if HasSideEffects is false) or G_INTRINSIC_W_SIDE_EFFECTS inst...
Helper class to build MachineInstr.
bool isIntPredicate() const
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
Represent the analysis usage information of a pass.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
MachineInstrBuilder buildICmp(CmpInst::Predicate Pred, unsigned Res, unsigned Op0, unsigned Op1)
Build and insert a Res = G_ICMP Pred, Op0, Op1.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
MachineInstrBuilder buildInsert(unsigned Res, unsigned Src, unsigned Op, unsigned Index)
bool doesNotAccessMemory() const
Determine if the call does not access memory.
MachineInstrBuilder buildIndirectDbgValue(unsigned Reg, unsigned Offset, const MDNode *Variable, const MDNode *Expr)
Build and insert a DBG_VALUE instruction expressing the fact that the associated Variable lives in me...
Value * getOperand(unsigned i) const
int64_t getIndexedOffsetInType(Type *ElemTy, ArrayRef< Value * > Indices) const
Returns the offset from the beginning of the type for the specified indices.
Value * getPointerOperand()
void remove(iterator MBBI)
self_iterator getIterator()
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
Predicate getPredicate() const
Return the predicate for this instruction.
void setMF(MachineFunction &)
static Constant * getAllOnesValue(Type *Ty)
Get the all ones value.
1 1 1 1 Always true (always folded)
MachineInstrBuilder buildBrIndirect(unsigned Tgt)
Build and insert G_BRINDIRECT Tgt.
unsigned getStackPointerRegisterToSaveRestore() const
If a physical register, this specifies the register that llvm.savestack/llvm.restorestack should save...
succ_iterator succ_begin()
MachineInstrBuilder buildSExtOrTrunc(unsigned Res, unsigned Op)
Build and insert Res<def> = G_SEXT Op, Res = G_TRUNC Op, or Res = COPY Op depending on the differing ...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
LLVMContext & getContext() const
All values hold a context through their type.
This class contains a discriminated union of information about pointers in memory operands...
std::string & str()
Flushes the stream contents to the target string and returns the string's reference.
EH_LABEL - Represents a label in mid basic block used to track locations needed for debug and excepti...
MachineInstrBuilder buildFrameIndex(unsigned Res, int Idx)
Build and insert Res<def> = G_FRAME_INDEX Idx.
LLT getLLTForType(Type &Ty, const DataLayout &DL)
Construct a low-level type based on an LLVM type.
The memory access writes data.
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
Returns an integer type with size at least as big as that of a pointer in the given address space...
virtual const TargetFrameLowering * getFrameLowering() const
unsigned getABITypeAlignment(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
DIExpression * getExpression() const
AtomicOrdering getOrdering() const
Returns the ordering constraint of this store instruction.
void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
This is the shared class of boolean and integer constants.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
void buildSequence(unsigned Res, ArrayRef< unsigned > Ops, ArrayRef< uint64_t > Indices)
Build and insert instructions to put Ops together at the specified p Indices to form a larger registe...
INITIALIZE_PASS_BEGIN(IRTranslator, DEBUG_TYPE,"IRTranslator LLVM IR -> MI", false, false) INITIALIZE_PASS_END(IRTranslator
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
bool isStaticAlloca() const
Return true if this alloca is in the entry block of the function and is a constant size...
Type * getType() const
All values are typed, get the type of this value.
MachineInstrBuilder buildCopy(unsigned Res, unsigned Op)
Build and insert Res<def> = COPY Op.
virtual const TargetLowering * getTargetLowering() const
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID of this load instruction.
bool isVolatile() const
Return true if this is a load from a volatile memory location.
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
DebugLoc getDebugLoc()
Get the current instruction's debug location.
Function * getCalledFunction() const
Return the function called, or null if this is an indirect function invocation.
AtomicOrdering getOrdering() const
Returns the ordering constraint of this load instruction.
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
const BasicBlock & getEntryBlock() const
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
const MachineInstrBuilder & addSym(MCSymbol *Sym, unsigned char TargetFlags=0) const
DISubprogram * getSubprogram() const
Get the attached subprogram.
static MachineOperand CreateES(const char *SymName, unsigned char TargetFlags=0)
unsigned getVectorNumElements() const
Value * getCondition() const
bool isInlineAsm() const
Check if this call is an inline asm statement.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
Flags
Flags values. These may be or'd together.
The memory access reads data.
static MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
static std::vector< std::string > Flags
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
MachineInstrBuilder buildUndef(unsigned Dst)
Build and insert Res = IMPLICIT_DEF.
Value * getCondition() const
MachineInstrBuilder buildDirectDbgValue(unsigned Reg, const MDNode *Variable, const MDNode *Expr)
Build and insert a DBG_VALUE instruction expressing the fact that the associated Variable lives in Re...
void emplace_back(ArgTypes &&...Args)
BasicBlock * getDefaultDest() const
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
static IntegerType * getInt32Ty(LLVMContext &C)
virtual const TargetIntrinsicInfo * getIntrinsicInfo() const
If intrinsic information is available, return it. If not, return null.
This represents the llvm.dbg.value instruction.
const MachineInstrBuilder & addExternalSymbol(const char *FnName, unsigned char TargetFlags=0) const
virtual bool lowerFormalArguments(MachineIRBuilder &MIRBuilder, const Function &F, ArrayRef< unsigned > VRegs) const
This hook must be implemented to lower the incoming (formal) arguments, described by Args...
void setMBB(MachineBasicBlock &MBB)
Set the insertion point to the end of MBB.
MachineInstrBuilder buildConstant(unsigned Res, const ConstantInt &Val)
Build and insert Res = G_CONSTANT Val.
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
static Constant * getZeroValueForNegation(Type *Ty)
Floating point negation must be implemented with f(x) = -0.0 - x.
MachineInstrBuilder buildMul(unsigned Res, unsigned Op0, unsigned Op1)
Build and insert Res<def> = G_MUL Op0, Op1.
unsigned getPointerSizeInBits(unsigned AS=0) const
Layout pointer size, in bits FIXME: The defaults need to be removed once all of the backends/clients ...
Pair of physical register and lane mask.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
The memory access always returns the same value (or traps).
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
uint64_t getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
int CreateStackObject(uint64_t Size, unsigned Alignment, bool isSS, const AllocaInst *Alloca=nullptr)
Create a new statically sized stack object, returning a nonnegative identifier to represent it...
iterator_range< op_iterator > arg_operands()
Iteration adapter for range-for loops.
This file declares the IRTranslator pass.
DILocalVariable * getVariable() const
virtual bool getTgtMemIntrinsic(IntrinsicInfo &, const CallInst &, unsigned) const
Given an intrinsic, checks if on the target the intrinsic will need to map to a MemIntrinsicNode (tou...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void insert(iterator MBBI, MachineBasicBlock *MBB)
MachineInstrBuilder buildCast(unsigned Dst, unsigned Src)
Build and insert an appropriate cast between two registers of equal size.
const MachineInstrBuilder & addUse(unsigned RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register use operand.
A raw_ostream that writes to an std::string.
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
DILocalVariable * getVariable() const
This file describes how to lower LLVM calls to machine code calls.
void push_back(MachineBasicBlock *MBB)
MachineInstrBuilder buildLoad(unsigned Res, unsigned Addr, MachineMemOperand &MMO)
Build and insert Res<def> = G_LOAD Addr, MMO.
const Value * getArraySize() const
Get the number of elements allocated.
bool isValidLocationForIntrinsic(const DILocation *DL) const
Check that a location is valid for this variable.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
void setRegClass(unsigned Reg, const TargetRegisterClass *RC)
setRegClass - Set the register class of the specified virtual register.
unsigned getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
CallingConv::ID getCallingConv() const
getCallingConv/setCallingConv - Get or set the calling convention of this function call...
unsigned countOperandBundlesOfType(StringRef Name) const
Return the number of operand bundles with the tag Name attached to this instruction.
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
MachineInstrBuilder buildGlobalValue(unsigned Res, const GlobalValue *GV)
Build and insert Res<def> = G_GLOBAL_VALUE GV.
bool isLayoutSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB will be emitted immediately after this block, such that if this bloc...
MachineInstrBuilder buildMerge(unsigned Res, ArrayRef< unsigned > Ops)
Build and insert Res<def> = G_MERGE_VALUES Op0, ...
int CreateVariableSizedObject(unsigned Alignment, const AllocaInst *Alloca)
Notify the MachineFrameInfo object that a variable sized object has been created. ...
This represents the llvm.dbg.declare instruction.
virtual unsigned getExceptionSelectorRegister(const Constant *PersonalityFn) const
If a physical register, this returns the register that receives the exception typeid on entry to a la...
Value * getPointerOperand()
MachineInstr::mmo_iterator allocateMemRefsArray(unsigned long Num)
allocateMemRefsArray - Allocate an array to hold MachineMemOperand pointers.
virtual const TargetRegisterClass * getPointerRegClass(const MachineFunction &MF, unsigned Kind=0) const
Returns a TargetRegisterClass used for pointer values.
Statically lint checks LLVM IR
const BasicBlock * getParent() const
0 0 0 0 Always false (always folded)
This file describes how to lower LLVM code to machine code.
bool isVoidTy() const
Return true if this is 'void'.
an instruction to allocate memory on the stack
This instruction inserts a struct field of array element value into an aggregate value.
gep_type_iterator gep_type_begin(const User *GEP)
MachineInstrBuilder buildBrCond(unsigned Tst, MachineBasicBlock &BB)
Build and insert G_BRCOND Tst, Dest.