LLVM 20.0.0git
AMDGPUGlobalISelUtils.cpp
Go to the documentation of this file.
1//===- AMDGPUGlobalISelUtils.cpp ---------------------------------*- C++ -*-==//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
13#include "llvm/IR/Constants.h"
14
15using namespace llvm;
16using namespace MIPatternMatch;
17
18std::pair<Register, unsigned>
20 GISelKnownBits *KnownBits, bool CheckNUW) {
22 if (Def->getOpcode() == TargetOpcode::G_CONSTANT) {
23 unsigned Offset;
24 const MachineOperand &Op = Def->getOperand(1);
25 if (Op.isImm())
26 Offset = Op.getImm();
27 else
28 Offset = Op.getCImm()->getZExtValue();
29
30 return std::pair(Register(), Offset);
31 }
32
33 int64_t Offset;
34 if (Def->getOpcode() == TargetOpcode::G_ADD) {
35 // A 32-bit (address + offset) should not cause unsigned 32-bit integer
36 // wraparound, because s_load instructions perform the addition in 64 bits.
37 if (CheckNUW && !Def->getFlag(MachineInstr::NoUWrap)) {
38 assert(MRI.getType(Reg).getScalarSizeInBits() == 32);
39 return std::pair(Reg, 0);
40 }
41 // TODO: Handle G_OR used for add case
42 if (mi_match(Def->getOperand(2).getReg(), MRI, m_ICst(Offset)))
43 return std::pair(Def->getOperand(1).getReg(), Offset);
44
45 // FIXME: matcher should ignore copies
46 if (mi_match(Def->getOperand(2).getReg(), MRI, m_Copy(m_ICst(Offset))))
47 return std::pair(Def->getOperand(1).getReg(), Offset);
48 }
49
51 if (KnownBits && mi_match(Reg, MRI, m_GOr(m_Reg(Base), m_ICst(Offset))) &&
52 KnownBits->maskedValueIsZero(Base, APInt(32, Offset)))
53 return std::pair(Base, Offset);
54
55 // Handle G_PTRTOINT (G_PTR_ADD base, const) case
56 if (Def->getOpcode() == TargetOpcode::G_PTRTOINT) {
58 if (mi_match(Def->getOperand(1).getReg(), MRI,
60 // If Base was int converted to pointer, simply return int and offset.
61 if (Base->getOpcode() == TargetOpcode::G_INTTOPTR)
62 return std::pair(Base->getOperand(1).getReg(), Offset);
63
64 // Register returned here will be of pointer type.
65 return std::pair(Base->getOperand(0).getReg(), Offset);
66 }
67 }
68
69 return std::pair(Reg, 0);
70}
unsigned const MachineRegisterInfo * MRI
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Provides analysis for querying information about KnownBits during GISel passes.
Implement a low-level type suitable for MachineInstr level instruction selection.
Contains matchers for matching SSA Machine Instructions.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Class for arbitrary precision integers.
Definition: APInt.h:78
This class represents an Operation in the Expression.
Representation of each machine instruction.
Definition: MachineInstr.h:69
MachineOperand class - Representation of each machine instruction operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
std::pair< Register, unsigned > getBaseWithConstantOffset(MachineRegisterInfo &MRI, Register Reg, GISelKnownBits *KnownBits=nullptr, bool CheckNUW=false)
Returns base register and constant offset.
operand_type_match m_Reg()
UnaryOp_match< SrcTy, TargetOpcode::COPY > m_Copy(SrcTy &&Src)
ConstantMatch< APInt > m_ICst(APInt &Cst)
BinaryOp_match< LHS, RHS, TargetOpcode::G_OR, true > m_GOr(const LHS &L, const RHS &R)
bool mi_match(Reg R, const MachineRegisterInfo &MRI, Pattern &&P)
BinaryOp_match< LHS, RHS, TargetOpcode::G_PTR_ADD, false > m_GPtrAdd(const LHS &L, const RHS &R)
bind_ty< MachineInstr * > m_MInstr(MachineInstr *&MI)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
MachineInstr * getDefIgnoringCopies(Register Reg, const MachineRegisterInfo &MRI)
Find the def instruction for Reg, folding away any trivial copies.
Definition: Utils.cpp:471