LLVM 24.0.0git
AArch64SLSHardening.cpp
Go to the documentation of this file.
1//===- AArch64SLSHardening.cpp - Harden Straight Line Missspeculation -----===//
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//
9// This file contains a pass to insert code to mitigate against side channel
10// vulnerabilities that may happen under straight line miss-speculation.
11//
12//===----------------------------------------------------------------------===//
13
14#include "AArch64.h"
15#include "AArch64InstrInfo.h"
16#include "AArch64Subtarget.h"
26#include "llvm/IR/DebugLoc.h"
27#include "llvm/Pass.h"
31#include <cassert>
32#include <climits>
33#include <tuple>
34
35using namespace llvm;
36
37#define DEBUG_TYPE "aarch64-sls-hardening"
38
39#define AARCH64_SLS_HARDENING_NAME "AArch64 sls hardening pass"
40
41// Common name prefix of all thunks generated by this pass.
42//
43// The generic form is
44// __llvm_slsblr_thunk_xN for BLR thunks
45// __llvm_slsblr_thunk_(aaz|abz)_xN for BLRAAZ and BLRABZ thunks
46// __llvm_slsblr_thunk_(aa|ab)_xN_xM for BLRAA and BLRAB thunks
47static constexpr StringRef CommonNamePrefix = "__llvm_slsblr_thunk_";
48
49namespace {
50
51struct ThunkKind {
52 enum ThunkKindId {
53 ThunkBR,
54 ThunkBRAA,
55 ThunkBRAB,
56 ThunkBRAAZ,
57 ThunkBRABZ,
58 };
59
60 ThunkKindId Id;
61 StringRef NameInfix;
62 bool HasXmOperand;
63 bool NeedsPAuth;
64
65 // Opcode to perform indirect jump from inside the thunk.
66 unsigned BROpcode;
67
68 static const ThunkKind BR;
69 static const ThunkKind BRAA;
70 static const ThunkKind BRAB;
71 static const ThunkKind BRAAZ;
72 static const ThunkKind BRABZ;
73};
74
75// Set of inserted thunks.
76class ThunksSet {
77public:
78 static constexpr unsigned NumXRegisters = 32;
79
80 // Given Xn register, returns n.
81 static unsigned indexOfXReg(Register Xn);
82 // Given n, returns Xn register.
83 static Register xRegByIndex(unsigned N);
84
85 ThunksSet &operator|=(const ThunksSet &Other) {
86 BLRThunks |= Other.BLRThunks;
87 BLRAAZThunks |= Other.BLRAAZThunks;
88 BLRABZThunks |= Other.BLRABZThunks;
89 for (unsigned I = 0; I < NumXRegisters; ++I)
90 BLRAAThunks[I] |= Other.BLRAAThunks[I];
91 for (unsigned I = 0; I < NumXRegisters; ++I)
92 BLRABThunks[I] |= Other.BLRABThunks[I];
93
94 return *this;
95 }
96
97 bool get(ThunkKind::ThunkKindId Kind, Register Xn, Register Xm) {
98 reg_bitmask_t XnBit = reg_bitmask_t(1) << indexOfXReg(Xn);
99 return getBitmask(Kind, Xm) & XnBit;
100 }
101
102 void set(ThunkKind::ThunkKindId Kind, Register Xn, Register Xm) {
103 reg_bitmask_t XnBit = reg_bitmask_t(1) << indexOfXReg(Xn);
104 getBitmask(Kind, Xm) |= XnBit;
105 }
106
107private:
108 typedef uint32_t reg_bitmask_t;
109 static_assert(NumXRegisters <= sizeof(reg_bitmask_t) * CHAR_BIT,
110 "Bitmask is not wide enough to hold all Xn registers");
111
112 // Bitmasks representing operands used, with n-th bit corresponding to Xn
113 // register operand. If the instruction has a second operand (Xm), an array
114 // of bitmasks is used, indexed by m.
115 // Indexes corresponding to the forbidden x16, x17 and x30 registers are
116 // always unset, for simplicity there are no holes.
117 reg_bitmask_t BLRThunks = 0;
118 reg_bitmask_t BLRAAZThunks = 0;
119 reg_bitmask_t BLRABZThunks = 0;
120 reg_bitmask_t BLRAAThunks[NumXRegisters] = {};
121 reg_bitmask_t BLRABThunks[NumXRegisters] = {};
122
123 reg_bitmask_t &getBitmask(ThunkKind::ThunkKindId Kind, Register Xm) {
124 switch (Kind) {
125 case ThunkKind::ThunkBR:
126 return BLRThunks;
127 case ThunkKind::ThunkBRAAZ:
128 return BLRAAZThunks;
129 case ThunkKind::ThunkBRABZ:
130 return BLRABZThunks;
131 case ThunkKind::ThunkBRAA:
132 return BLRAAThunks[indexOfXReg(Xm)];
133 case ThunkKind::ThunkBRAB:
134 return BLRABThunks[indexOfXReg(Xm)];
135 }
136 llvm_unreachable("Unknown ThunkKindId enum");
137 }
138};
139
140} // end anonymous namespace
141
142struct SLSHardeningInserter : ThunkInserter<SLSHardeningInserter, ThunksSet> {
143public:
144 const char *getThunkPrefix() { return CommonNamePrefix.data(); }
145 bool mayUseThunk(const MachineFunction &MF) {
146 ComdatThunks &= !MF.getSubtarget<AArch64Subtarget>().hardenSlsNoComdat();
147 // We are inserting barriers aside from thunk calls, so
148 // check hardenSlsRetBr() as well.
149 return MF.getSubtarget<AArch64Subtarget>().hardenSlsBlr() ||
150 MF.getSubtarget<AArch64Subtarget>().hardenSlsRetBr();
151 }
153 ThunksSet ExistingThunks);
155
156private:
157 bool ComdatThunks = true;
158
159 bool hardenReturnsAndBRs(MachineModuleInfo &MMI, MachineBasicBlock &MBB);
160 bool hardenBLRs(MachineModuleInfo &MMI, MachineBasicBlock &MBB,
161 ThunksSet &Thunks);
162
163 void convertBLRToBL(MachineModuleInfo &MMI, MachineBasicBlock &MBB,
165 ThunksSet &Thunks);
166};
167
168const ThunkKind ThunkKind::BR = {ThunkBR, "", /*HasXmOperand=*/false,
169 /*NeedsPAuth=*/false, AArch64::BR};
170const ThunkKind ThunkKind::BRAA = {ThunkBRAA, "aa_", /*HasXmOperand=*/true,
171 /*NeedsPAuth=*/true, AArch64::BRAA};
172const ThunkKind ThunkKind::BRAB = {ThunkBRAB, "ab_", /*HasXmOperand=*/true,
173 /*NeedsPAuth=*/true, AArch64::BRAB};
174const ThunkKind ThunkKind::BRAAZ = {ThunkBRAAZ, "aaz_", /*HasXmOperand=*/false,
175 /*NeedsPAuth=*/true, AArch64::BRAAZ};
176const ThunkKind ThunkKind::BRABZ = {ThunkBRABZ, "abz_", /*HasXmOperand=*/false,
177 /*NeedsPAuth=*/true, AArch64::BRABZ};
178
179// Returns thunk kind to emit, or nullptr if not a BLR* instruction.
180static const ThunkKind *getThunkKind(unsigned OriginalOpcode) {
181 switch (OriginalOpcode) {
182 case AArch64::BLR:
183 case AArch64::BLRNoIP:
184 return &ThunkKind::BR;
185 case AArch64::BLRAA:
186 return &ThunkKind::BRAA;
187 case AArch64::BLRAB:
188 return &ThunkKind::BRAB;
189 case AArch64::BLRAAZ:
190 return &ThunkKind::BRAAZ;
191 case AArch64::BLRABZ:
192 return &ThunkKind::BRABZ;
193 }
194 return nullptr;
195}
196
197static bool isBLR(const MachineInstr &MI) {
198 return getThunkKind(MI.getOpcode()) != nullptr;
199}
200
201unsigned ThunksSet::indexOfXReg(Register Reg) {
202 assert(AArch64::GPR64RegClass.contains(Reg));
203 assert(Reg != AArch64::X16 && Reg != AArch64::X17 && Reg != AArch64::LR);
204
205 // Most Xn registers have consecutive ids, except for FP and XZR.
206 unsigned Result = (unsigned)Reg - (unsigned)AArch64::X0;
207 if (Reg == AArch64::FP)
208 Result = 29;
209 else if (Reg == AArch64::XZR)
210 Result = 31;
211
212 assert(Result < NumXRegisters && "Internal register numbering changed");
213 assert(AArch64::GPR64RegClass.getRegister(Result).id() == Reg &&
214 "Internal register numbering changed");
215
216 return Result;
217}
218
219Register ThunksSet::xRegByIndex(unsigned N) {
220 return AArch64::GPR64RegClass.getRegister(N);
221}
222
226 DebugLoc DL,
227 bool AlwaysUseISBDSB = false) {
228 assert(MBBI != MBB.begin() &&
229 "Must not insert SpeculationBarrierEndBB as only instruction in MBB.");
230 assert(std::prev(MBBI)->isBarrier() &&
231 "SpeculationBarrierEndBB must only follow unconditional control flow "
232 "instructions.");
233 assert(std::prev(MBBI)->isTerminator() &&
234 "SpeculationBarrierEndBB must only follow terminators.");
235 const TargetInstrInfo *TII = ST->getInstrInfo();
236 unsigned BarrierOpc = ST->hasSB() && !AlwaysUseISBDSB
237 ? AArch64::SpeculationBarrierSBEndBB
238 : AArch64::SpeculationBarrierISBDSBEndBB;
239 if (MBBI == MBB.end() ||
240 (MBBI->getOpcode() != AArch64::SpeculationBarrierSBEndBB &&
241 MBBI->getOpcode() != AArch64::SpeculationBarrierISBDSBEndBB))
242 BuildMI(MBB, MBBI, DL, TII->get(BarrierOpc));
243}
244
246 MachineFunction &MF,
247 ThunksSet ExistingThunks) {
249
250 for (auto &MBB : MF) {
251 if (ST->hardenSlsRetBr())
252 hardenReturnsAndBRs(MMI, MBB);
253 if (ST->hardenSlsBlr())
254 hardenBLRs(MMI, MBB, ExistingThunks);
255 }
256 return ExistingThunks;
257}
258
259bool SLSHardeningInserter::hardenReturnsAndBRs(MachineModuleInfo &MMI,
261 const AArch64Subtarget *ST =
262 &MBB.getParent()->getSubtarget<AArch64Subtarget>();
263 bool Modified = false;
264 MachineBasicBlock::iterator MBBI = MBB.getFirstTerminator(), E = MBB.end();
266 for (; MBBI != E; MBBI = NextMBBI) {
267 MachineInstr &MI = *MBBI;
268 NextMBBI = std::next(MBBI);
269 if (MI.isReturn() || isIndirectBranchOpcode(MI.getOpcode())) {
270 assert(MI.isTerminator());
271 insertSpeculationBarrier(ST, MBB, std::next(MBBI), MI.getDebugLoc());
272 Modified = true;
273 }
274 }
275 return Modified;
276}
277
278// Currently, the longest possible thunk name is
279// __llvm_slsblr_thunk_aa_xNN_xMM
280// which is 31 characters (without the '\0' character).
281static SmallString<32> createThunkName(const ThunkKind &Kind, Register Xn,
282 Register Xm) {
283 unsigned N = ThunksSet::indexOfXReg(Xn);
284 if (!Kind.HasXmOperand)
285 return formatv("{0}{1}x{2}", CommonNamePrefix, Kind.NameInfix, N);
286
287 unsigned M = ThunksSet::indexOfXReg(Xm);
288 return formatv("{0}{1}x{2}_x{3}", CommonNamePrefix, Kind.NameInfix, N, M);
289}
290
291static std::tuple<const ThunkKind &, Register, Register>
294 "Should be filtered out by ThunkInserter");
295 // Thunk name suffix, such as "x1" or "aa_x2_x3".
296 StringRef NameSuffix = ThunkName.drop_front(CommonNamePrefix.size());
297
298 // Parse thunk kind based on thunk name infix.
299 const ThunkKind &Kind = *StringSwitch<const ThunkKind *>(NameSuffix)
300 .StartsWith("aa_", &ThunkKind::BRAA)
301 .StartsWith("ab_", &ThunkKind::BRAB)
302 .StartsWith("aaz_", &ThunkKind::BRAAZ)
303 .StartsWith("abz_", &ThunkKind::BRABZ)
304 .Default(&ThunkKind::BR);
305
306 auto ParseRegName = [](StringRef Name) {
307 unsigned N;
308
309 assert(Name.starts_with("x") && "xN register name expected");
310 bool Fail = Name.drop_front(1).getAsInteger(/*Radix=*/10, N);
311 assert(!Fail && N < ThunksSet::NumXRegisters && "Unexpected register");
312 (void)Fail;
313
314 return ThunksSet::xRegByIndex(N);
315 };
316
317 // For example, "x1" or "x2_x3".
318 StringRef RegsStr = NameSuffix.drop_front(Kind.NameInfix.size());
319 StringRef XnStr, XmStr;
320 std::tie(XnStr, XmStr) = RegsStr.split('_');
321
322 // Parse register operands.
323 Register Xn = ParseRegName(XnStr);
324 Register Xm = Kind.HasXmOperand ? ParseRegName(XmStr) : Register();
325
326 return std::make_tuple(std::ref(Kind), Xn, Xm);
327}
328
330 assert(MF.getFunction().hasComdat() == ComdatThunks &&
331 "ComdatThunks value changed since MF creation");
332 Register Xn, Xm;
333 auto KindAndRegs = parseThunkName(MF.getName());
334 const ThunkKind &Kind = std::get<0>(KindAndRegs);
335 std::tie(std::ignore, Xn, Xm) = KindAndRegs;
336
337 const TargetInstrInfo *TII =
338 MF.getSubtarget<AArch64Subtarget>().getInstrInfo();
339
340 // Depending on whether this pass is in the same FunctionPassManager as the
341 // IR->MIR conversion, the thunk may be completely empty, or contain a single
342 // basic block with a single return instruction. Normalise it to contain a
343 // single empty basic block.
344 if (MF.size() == 1) {
345 assert(MF.front().size() == 1);
346 assert(MF.front().front().getOpcode() == AArch64::RET);
347 MF.front().erase(MF.front().begin());
348 } else {
349 assert(MF.size() == 0);
351 }
352
353 MachineBasicBlock *Entry = &MF.front();
354 Entry->clear();
355
356 // These thunks need to consist of the following instructions:
357 // __llvm_slsblr_thunk_...:
358 // MOV x16, xN ; BR* instructions are not compatible with "BTI c"
359 // ; branch target unless xN is x16 or x17.
360 // BR* ... ; One of: BR x16
361 // ; BRA(A|B) x16, xM
362 // ; BRA(A|B)Z x16
363 // barrierInsts
364 Entry->addLiveIn(Xn);
365 // MOV X16, Reg == ORR X16, XZR, Reg, LSL #0
366 BuildMI(Entry, DebugLoc(), TII->get(AArch64::ORRXrs), AArch64::X16)
367 .addReg(AArch64::XZR)
368 .addReg(Xn)
369 .addImm(0);
370 MachineInstrBuilder Builder =
371 BuildMI(Entry, DebugLoc(), TII->get(Kind.BROpcode)).addReg(AArch64::X16);
372 if (Xm.isValid()) {
373 Entry->addLiveIn(Xm);
374 Builder.addReg(Xm);
375 }
376
377 // Make sure the thunks do not make use of the SB extension in case there is
378 // a function somewhere that will call to it that for some reason disabled
379 // the SB extension locally on that function, even though it's enabled for
380 // the module otherwise. Therefore set AlwaysUseISBSDB to true.
382 Entry->end(), DebugLoc(), true /*AlwaysUseISBDSB*/);
383}
384
385void SLSHardeningInserter::convertBLRToBL(
387 MachineBasicBlock::instr_iterator MBBI, ThunksSet &Thunks) {
388 // Transform a BLR* instruction (one of BLR, BLRAA/BLRAB or BLRAAZ/BLRABZ) to
389 // a BL to the thunk containing BR, BRAA/BRAB or BRAAZ/BRABZ, respectively.
390 //
391 // Before:
392 // |-----------------------------|
393 // | ... |
394 // | instI |
395 // | BLR* xN or BLR* xN, xM |
396 // | instJ |
397 // | ... |
398 // |-----------------------------|
399 //
400 // After:
401 // |-----------------------------|
402 // | ... |
403 // | instI |
404 // | BL __llvm_slsblr_thunk_... |
405 // | instJ |
406 // | ... |
407 // |-----------------------------|
408 //
409 // __llvm_slsblr_thunk_...:
410 // |-----------------------------|
411 // | MOV x16, xN |
412 // | BR* x16 or BR* x16, xM |
413 // | barrierInsts |
414 // |-----------------------------|
415 //
416 // This function needs to transform BLR* instruction into BL with the correct
417 // thunk name and lazily create the thunk if it does not exist yet.
418 //
419 // Since linkers are allowed to clobber X16 and X17 on function calls, the
420 // above mitigation only works if the original BLR* instruction had neither
421 // X16 nor X17 as one of its operands. Code generation before must make sure
422 // that no such BLR* instruction was produced if the mitigation is enabled.
423
424 MachineInstr &BLR = *MBBI;
425 assert(isBLR(BLR));
426 const ThunkKind &Kind = *getThunkKind(BLR.getOpcode());
427
428 unsigned NumRegOperands = Kind.HasXmOperand ? 2 : 1;
429 assert(BLR.getNumExplicitOperands() == NumRegOperands &&
430 "Expected one or two register inputs");
431 Register Xn = BLR.getOperand(0).getReg();
432 Register Xm = Kind.HasXmOperand ? BLR.getOperand(1).getReg() : Register();
433
434 DebugLoc DL = BLR.getDebugLoc();
435
436 MachineFunction &MF = *MBBI->getMF();
437 MCContext &Context = MBB.getParent()->getContext();
439
440 auto ThunkName = createThunkName(Kind, Xn, Xm);
441 MCSymbol *Sym = Context.getOrCreateSymbol(ThunkName);
442
443 if (!Thunks.get(Kind.Id, Xn, Xm)) {
444 StringRef TargetAttrs = Kind.NeedsPAuth ? "+pauth" : "";
445 Thunks.set(Kind.Id, Xn, Xm);
446 createThunkFunction(MMI, ThunkName, ComdatThunks, TargetAttrs);
447 }
448
449 MachineInstr *BL = BuildMI(MBB, MBBI, DL, TII->get(AArch64::BL)).addSym(Sym);
450
451 // Now copy the implicit operands from BLR to BL and copy other necessary
452 // info.
453 // However, both BLR and BL instructions implicitly use SP and implicitly
454 // define LR. Blindly copying implicit operands would result in SP and LR
455 // operands to be present multiple times. While this may not be too much of
456 // an issue, let's avoid that for cleanliness, by removing those implicit
457 // operands from the BL created above before we copy over all implicit
458 // operands from the BLR.
459 int ImpLROpIdx = -1;
460 int ImpSPOpIdx = -1;
461 for (unsigned OpIdx = BL->getNumExplicitOperands();
462 OpIdx < BL->getNumOperands(); OpIdx++) {
463 MachineOperand Op = BL->getOperand(OpIdx);
464 if (!Op.isReg())
465 continue;
466 if (Op.getReg() == AArch64::LR && Op.isDef())
467 ImpLROpIdx = OpIdx;
468 if (Op.getReg() == AArch64::SP && !Op.isDef())
469 ImpSPOpIdx = OpIdx;
470 }
471 assert(ImpLROpIdx != -1);
472 assert(ImpSPOpIdx != -1);
473 int FirstOpIdxToRemove = std::max(ImpLROpIdx, ImpSPOpIdx);
474 int SecondOpIdxToRemove = std::min(ImpLROpIdx, ImpSPOpIdx);
475 BL->removeOperand(FirstOpIdxToRemove);
476 BL->removeOperand(SecondOpIdxToRemove);
477 // Now copy over the implicit operands from the original BLR
478 BL->copyImplicitOps(MF, BLR);
479 MF.moveAdditionalCallInfo(&BLR, BL);
480 // Also add the register operands of the original BLR* instruction
481 // as being used in the called thunk.
482 for (unsigned OpIdx = 0; OpIdx < NumRegOperands; ++OpIdx) {
483 MachineOperand &Op = BLR.getOperand(OpIdx);
484 BL->addOperand(MachineOperand::CreateReg(Op.getReg(), /*isDef=*/false,
485 /*isImp=*/true, Op.isKill()));
486 }
487 // Remove BLR instruction
488 MBB.erase(MBBI);
489}
490
491bool SLSHardeningInserter::hardenBLRs(MachineModuleInfo &MMI,
492 MachineBasicBlock &MBB,
493 ThunksSet &Thunks) {
494 bool Modified = false;
496 E = MBB.instr_end();
498 for (; MBBI != E; MBBI = NextMBBI) {
499 MachineInstr &MI = *MBBI;
500 NextMBBI = std::next(MBBI);
501 if (isBLR(MI)) {
502 convertBLRToBL(MMI, MBB, MBBI, Thunks);
503 Modified = true;
504 }
505 }
506 return Modified;
507}
508
509namespace {
510class AArch64SLSHardeningLegacy
511 : public ThunkInserterPass<SLSHardeningInserter> {
512public:
513 static char ID;
514
515 AArch64SLSHardeningLegacy() : ThunkInserterPass(ID) {}
516
517 StringRef getPassName() const override { return AARCH64_SLS_HARDENING_NAME; }
518};
519
520} // end anonymous namespace
521
522char AArch64SLSHardeningLegacy::ID = 0;
523
524INITIALIZE_PASS(AArch64SLSHardeningLegacy, "aarch64-sls-hardening",
525 AARCH64_SLS_HARDENING_NAME, false, false)
526
528 return new AArch64SLSHardeningLegacy();
529}
530
533
535 default;
537
543 .getCachedResult<MachineModuleAnalysis>(
544 *MF.getFunction().getParent());
545 assert(MMI && "MachineModuleAnalysis must be available");
546
547 if (Inserter->run(MMI->getMMI(), MF)) {
550 return PA;
551 }
552 return PreservedAnalyses::all();
553}
#define Fail
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define AARCH64_SLS_HARDENING_NAME
static void insertSpeculationBarrier(const AArch64Subtarget *ST, MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, DebugLoc DL, bool AlwaysUseISBDSB=false)
static constexpr StringRef CommonNamePrefix
static SmallString< 32 > createThunkName(const ThunkKind &Kind, Register Xn, Register Xm)
static std::tuple< const ThunkKind &, Register, Register > parseThunkName(StringRef ThunkName)
static const ThunkKind * getThunkKind(unsigned OriginalOpcode)
static bool isBLR(const MachineInstr &MI)
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc bool AlwaysUseISBDSB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
Contains a base ThunkInserter class that simplifies injection of MI thunks as well as a default imple...
#define I(x, y, z)
Definition MD5.cpp:57
Register Reg
Promote Memory to Register
Definition Mem2Reg.cpp:110
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
This file declares the machine register scavenger class.
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition Value.cpp:479
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represents analyses that only rely on functions' control flow.
Definition Analysis.h:73
A debug info location.
Definition DebugLoc.h:126
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:312
bool hasComdat() const
Module * getParent()
Get the module that this global value is contained inside of...
Context object for machine code objects.
Definition MCContext.h:83
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
Instructions::iterator instr_iterator
LLVM_ABI instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
MachineInstrBundleIterator< MachineInstr > iterator
void moveAdditionalCallInfo(const MachineInstr *Old, const MachineInstr *New)
Move the call site info from Old to \New call site info.
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.
void push_back(MachineBasicBlock *MBB)
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineBasicBlock & front() const
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *BB=nullptr, std::optional< UniqueBBID > BBID=std::nullopt)
CreateMachineInstr - Allocate a new MachineInstr.
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addSym(MCSymbol *Sym, unsigned char TargetFlags=0) const
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
LLVM_ABI void addOperand(MachineFunction &MF, const MachineOperand &Op)
Add the specified operand to the instruction.
LLVM_ABI unsigned getNumExplicitOperands() const
Returns the number of non-implicit operands.
LLVM_ABI void copyImplicitOps(MachineFunction &MF, const MachineInstr &MI)
Copy implicit register operands from specified instruction to this instruction.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
LLVM_ABI void removeOperand(unsigned OpNo)
Erase an operand from an instruction, leaving it with one fewer operand than it started with.
const MachineOperand & getOperand(unsigned i) const
This class contains meta information specific to a module.
Register getReg() const
getReg - Returns the register number.
static MachineOperand CreateReg(Register Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isEarlyClobber=false, unsigned SubReg=0, bool isDebug=false, bool isInternalRead=false, bool isRenamable=false)
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
Definition Analysis.h:151
Wrapper class representing virtual and physical registers.
Definition Register.h:20
constexpr bool isValid() const
Definition Register.h:112
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition StringRef.h:736
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition StringRef.h:258
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
Definition StringRef.h:635
A switch()-like statement whose cases are string literals.
StringSwitch & StartsWith(StringLiteral S, T Value)
TargetInstrInfo - Interface to description of machine instruction set.
virtual const TargetInstrInfo * getInstrInfo() const
This class assists in inserting MI thunk functions into the module and rewriting the existing machine...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
OuterAnalysisManagerProxy< ModuleAnalysisManager, MachineFunction > ModuleAnalysisManagerMachineFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
static bool isIndirectBranchOpcode(int Opc)
FunctionPass * createAArch64SLSHardeningLegacyPass()
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
@ Other
Any other memory.
Definition ModRef.h:68
DWARFExpression::Operation Op
bool operator|=(SparseBitVector< ElementSize > &LHS, const SparseBitVector< ElementSize > *RHS)
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:878
#define N
void populateThunk(MachineFunction &MF)
ThunksSet insertThunks(MachineModuleInfo &MMI, MachineFunction &MF, ThunksSet ExistingThunks)
bool mayUseThunk(const MachineFunction &MF)