36 #define DEBUG_TYPE "aarch64-stack-tagging-pre-ra" 44 "Unconditionally apply unchecked-ld-st optimization (even for large " 45 "stack frames, or in the presence of variable sized allocas)."),
50 "apply unchecked-ld-st when the target is definitely within range"),
71 bool mayUseUncheckedLoadStore();
72 void uncheckUsesOf(
unsigned TaggedReg,
int FI);
73 void uncheckLoadsAndStores();
77 return "AArch64 Stack Tagging PreRA";
90 "AArch64 Stack Tagging PreRA Pass",
false,
false)
95 return new AArch64StackTaggingPreRA();
100 case AArch64::LDRBBui:
101 case AArch64::LDRHHui:
102 case AArch64::LDRWui:
103 case AArch64::LDRXui:
105 case AArch64::LDRBui:
106 case AArch64::LDRHui:
107 case AArch64::LDRSui:
108 case AArch64::LDRDui:
109 case AArch64::LDRQui:
111 case AArch64::LDRSHWui:
112 case AArch64::LDRSHXui:
114 case AArch64::LDRSBWui:
115 case AArch64::LDRSBXui:
117 case AArch64::LDRSWui:
119 case AArch64::STRBBui:
120 case AArch64::STRHHui:
121 case AArch64::STRWui:
122 case AArch64::STRXui:
124 case AArch64::STRBui:
125 case AArch64::STRHui:
126 case AArch64::STRSui:
127 case AArch64::STRDui:
128 case AArch64::STRQui:
136 case AArch64::LDPSWi:
149 bool AArch64StackTaggingPreRA::mayUseUncheckedLoadStore() {
166 unsigned FrameSize = 0;
167 for (
unsigned i = 0,
e = MFI->getObjectIndexEnd(); i !=
e; ++i)
168 FrameSize += MFI->getObjectSize(i);
169 bool EntireFrameReachableFromSP = FrameSize < 0xf00;
170 return !MFI->hasVarSizedObjects() && EntireFrameReachableFromSP;
173 void AArch64StackTaggingPreRA::uncheckUsesOf(
unsigned TaggedReg,
int FI) {
174 for (
auto UI =
MRI->use_instr_begin(TaggedReg),
E =
MRI->use_instr_end();
179 unsigned OpIdx =
TII->getLoadStoreImmIdx(UseI->
getOpcode()) - 1;
185 }
else if (UseI->
isCopy() &&
192 void AArch64StackTaggingPreRA::uncheckLoadsAndStores() {
193 for (
auto *
I : ReTags) {
194 unsigned TaggedReg =
I->getOperand(0).getReg();
195 int FI =
I->getOperand(1).getIndex();
196 uncheckUsesOf(TaggedReg, FI);
200 bool AArch64StackTaggingPreRA::runOnMachineFunction(
MachineFunction &Func) {
202 MRI = &MF->getRegInfo();
206 MF->getSubtarget().getRegisterInfo());
207 MFI = &MF->getFrameInfo();
212 LLVM_DEBUG(
dbgs() <<
"********** AArch64 Stack Tagging PreRA **********\n" 213 <<
"********** Function: " << MF->getName() <<
'\n');
216 for (
auto &BB : *MF) {
218 if (
I.getOpcode() == AArch64::TAGPstack) {
219 ReTags.push_back(&
I);
220 int FI =
I.getOperand(1).getIndex();
221 TaggedSlots.insert(FI);
223 assert(
I.getOperand(2).getImm() == 0);
231 if (mayUseUncheckedLoadStore())
232 uncheckLoadsAndStores();
Pass interface - Implemented by all 'passes'.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
AArch64FunctionInfo - This class is derived from MachineFunctionInfo and contains private AArch64-spe...
This class represents lattice values for constants.
void setTargetFlags(unsigned F)
MO_TAGGED - With MO_PAGE, indicates that the page includes a memory tag in bits 56-63.
unsigned const TargetRegisterInfo * TRI
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
aarch64 stack tagging pre ra
void initializeAArch64StackTaggingPreRAPass(PassRegistry &)
cl::opt< UncheckedLdStMode > ClUncheckedLdSt("stack-tagging-unchecked-ld-st", cl::Hidden, cl::init(UncheckedSafe), cl::desc("Unconditionally apply unchecked-ld-st optimization (even for large " "stack frames, or in the presence of variable sized allocas)."), cl::values(clEnumValN(UncheckedNever, "never", "never apply unchecked-ld-st"), clEnumValN(UncheckedSafe, "safe", "apply unchecked-ld-st when the target is definitely within range"), clEnumValN(UncheckedAlways, "always", "always apply unchecked-ld-st")))
initializer< Ty > init(const Ty &Val)
unsigned const MachineRegisterInfo * MRI
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
Represent the analysis usage information of a pass.
FunctionPass * createAArch64StackTaggingPreRAPass()
FunctionPass class - This class is used to implement most global optimizations.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
A SetVector that performs no allocations if smaller than a certain size.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
void setPreservesCFG()
This function should be called by the pass, iff they do not:
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool isUncheckedLoadOrStoreOpcode(unsigned Opcode)
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
void ChangeToFrameIndex(int Idx)
Replace this operand with a frame index.
StringRef - Represent a constant reference to a string, i.e.
Register getReg() const
getReg - Returns the register number.
INITIALIZE_PASS_BEGIN(AArch64StackTaggingPreRA, "aarch64-stack-tagging-pre-ra", "AArch64 Stack Tagging PreRA Pass", false, false) INITIALIZE_PASS_END(AArch64StackTaggingPreRA
const MachineOperand & getOperand(unsigned i) const