19 #ifndef LLVM_CODEGEN_GLOBALISEL_IRTRANSLATOR_H 20 #define LLVM_CODEGEN_GLOBALISEL_IRTRANSLATOR_H 41 class MachineBasicBlock;
42 class MachineFunction;
44 class MachineRegisterInfo;
45 class OptimizationRemarkEmitter;
47 class TargetPassConfig;
68 class ValueToVRegInfo {
70 ValueToVRegInfo() =
default;
75 using const_vreg_iterator =
77 using const_offset_iterator =
80 inline const_vreg_iterator vregs_end()
const {
return ValToVRegs.end(); }
82 VRegListT *getVRegs(
const Value &V) {
83 auto It = ValToVRegs.find(&V);
84 if (It != ValToVRegs.end())
87 return insertVRegs(V);
90 OffsetListT *getOffsets(
const Value &V) {
91 auto It = TypeToOffsets.find(V.
getType());
92 if (It != TypeToOffsets.end())
95 return insertOffsets(V);
98 const_vreg_iterator findVRegs(
const Value &V)
const {
99 return ValToVRegs.find(&V);
103 return ValToVRegs.find(&V) != ValToVRegs.end();
108 TypeToOffsets.clear();
109 VRegAlloc.DestroyAll();
110 OffsetAlloc.DestroyAll();
114 VRegListT *insertVRegs(
const Value &V) {
115 assert(ValToVRegs.find(&V) == ValToVRegs.end() &&
"Value already exists");
119 auto *VRegList =
new (VRegAlloc.Allocate()) VRegListT();
120 ValToVRegs[&V] = VRegList;
124 OffsetListT *insertOffsets(
const Value &V) {
125 assert(TypeToOffsets.find(V.
getType()) == TypeToOffsets.end() &&
126 "Type already exists");
128 auto *OffsetList =
new (OffsetAlloc.Allocate()) OffsetListT();
129 TypeToOffsets[V.
getType()] = OffsetList;
143 ValueToVRegInfo VMap;
155 using CFGEdge = std::pair<const BasicBlock *, const BasicBlock *>;
217 bool translateOverflowIntrinsic(
const CallInst &CI,
unsigned Op,
236 bool valueIsSplit(
const Value &V,
249 bool translateCast(
unsigned Opcode,
const User &U,
260 return translateCompare(U, MIRBuilder);
265 return translateCompare(U, MIRBuilder);
270 void finishPendingPhis();
274 bool translateBinaryOp(
unsigned Opcode,
const User &U,
306 return translateBinaryOp(TargetOpcode::G_ADD, U, MIRBuilder);
309 return translateBinaryOp(TargetOpcode::G_SUB, U, MIRBuilder);
312 return translateBinaryOp(TargetOpcode::G_AND, U, MIRBuilder);
315 return translateBinaryOp(TargetOpcode::G_MUL, U, MIRBuilder);
318 return translateBinaryOp(TargetOpcode::G_OR, U, MIRBuilder);
321 return translateBinaryOp(TargetOpcode::G_XOR, U, MIRBuilder);
325 return translateBinaryOp(TargetOpcode::G_UDIV, U, MIRBuilder);
328 return translateBinaryOp(TargetOpcode::G_SDIV, U, MIRBuilder);
331 return translateBinaryOp(TargetOpcode::G_UREM, U, MIRBuilder);
334 return translateBinaryOp(TargetOpcode::G_SREM, U, MIRBuilder);
337 return translateCast(TargetOpcode::G_INTTOPTR, U, MIRBuilder);
340 return translateCast(TargetOpcode::G_PTRTOINT, U, MIRBuilder);
343 return translateCast(TargetOpcode::G_TRUNC, U, MIRBuilder);
346 return translateCast(TargetOpcode::G_FPTRUNC, U, MIRBuilder);
349 return translateCast(TargetOpcode::G_FPEXT, U, MIRBuilder);
352 return translateCast(TargetOpcode::G_FPTOUI, U, MIRBuilder);
355 return translateCast(TargetOpcode::G_FPTOSI, U, MIRBuilder);
358 return translateCast(TargetOpcode::G_UITOFP, U, MIRBuilder);
361 return translateCast(TargetOpcode::G_SITOFP, U, MIRBuilder);
367 return translateCast(TargetOpcode::G_SEXT, U, MIRBuilder);
371 return translateCast(TargetOpcode::G_ZEXT, U, MIRBuilder);
375 return translateBinaryOp(TargetOpcode::G_SHL, U, MIRBuilder);
378 return translateBinaryOp(TargetOpcode::G_LSHR, U, MIRBuilder);
381 return translateBinaryOp(TargetOpcode::G_ASHR, U, MIRBuilder);
385 return translateBinaryOp(TargetOpcode::G_FADD, U, MIRBuilder);
388 return translateBinaryOp(TargetOpcode::G_FMUL, U, MIRBuilder);
391 return translateBinaryOp(TargetOpcode::G_FDIV, U, MIRBuilder);
394 return translateBinaryOp(TargetOpcode::G_FREM, U, MIRBuilder);
426 return translateCast(TargetOpcode::G_ADDRSPACE_CAST, U, MIRBuilder);
448 std::unique_ptr<MachineIRBuilder> CurBuilder;
453 std::unique_ptr<MachineIRBuilder> EntryBuilder;
467 std::unique_ptr<OptimizationRemarkEmitter> ORE;
473 void finalizeFunction();
481 unsigned getOrCreateVReg(
const Value &Val) {
482 auto Regs = getOrCreateVRegs(Val);
485 assert(Regs.size() == 1 &&
486 "attempt to get single VReg for aggregate or void");
496 int getOrCreateFrameIndex(
const AllocaInst &AI);
519 auto RemappedEdge = MachinePreds.
find(Edge);
520 if (RemappedEdge != MachinePreds.
end())
521 return RemappedEdge->second;
550 #endif // LLVM_CODEGEN_GLOBALISEL_IRTRANSLATOR_H
A parsed version of the target data layout string in and methods for querying it. ...
This class represents lattice values for constants.
This class represents a function call, abstracting a target machine's calling convention.
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
return AArch64::GPR64RegClass contains(Reg)
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Target-Independent Code Generator Pass Configuration Options.
Type * getType() const
All values are typed, get the type of this value.
iterator find(const_arg_type_t< KeyT > Val)
unsigned const MachineRegisterInfo * MRI
LLVM Basic Block Representation.
This is an important base class in LLVM.
This file implements a version of MachineIRBuilder which CSEs insts within a MachineBasicBlock.
Helper class to build MachineInstr.
Represent the analysis usage information of a pass.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
A BumpPtrAllocator that allows only elements of a specific type to be allocated.
This file describes high level types that are used by several passes or APIs involved in the GlobalIS...
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
StringRef - Represent a constant reference to a string, i.e.
an instruction to allocate memory on the stack