#include "AArch64InstrInfo.h"
#include "AArch64Subtarget.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/CodeGen/IndirectThunks.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineOperand.h"
#include "llvm/CodeGen/RegisterScavenging.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/Pass.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Target/TargetMachine.h"
#include <cassert>
#include <climits>
#include <tuple>
usingnamespacellvm;
#define DEBUG_TYPE …
#define AARCH64_SLS_HARDENING_NAME …
static constexpr StringRef CommonNamePrefix = …;
namespace {
struct ThunkKind { … };
class ThunksSet { … };
struct SLSHardeningInserter : ThunkInserter<SLSHardeningInserter, ThunksSet> { … };
}
const ThunkKind ThunkKind::BR = …;
const ThunkKind ThunkKind::BRAA = …;
const ThunkKind ThunkKind::BRAB = …;
const ThunkKind ThunkKind::BRAAZ = …;
const ThunkKind ThunkKind::BRABZ = …;
static const ThunkKind *getThunkKind(unsigned OriginalOpcode) { … }
static bool isBLR(const MachineInstr &MI) { … }
unsigned ThunksSet::indexOfXReg(Register Reg) { … }
Register ThunksSet::xRegByIndex(unsigned N) { … }
static void insertSpeculationBarrier(const AArch64Subtarget *ST,
MachineBasicBlock &MBB,
MachineBasicBlock::iterator MBBI,
DebugLoc DL,
bool AlwaysUseISBDSB = false) { … }
ThunksSet SLSHardeningInserter::insertThunks(MachineModuleInfo &MMI,
MachineFunction &MF,
ThunksSet ExistingThunks) { … }
bool SLSHardeningInserter::hardenReturnsAndBRs(MachineModuleInfo &MMI,
MachineBasicBlock &MBB) { … }
static SmallString<32> createThunkName(const ThunkKind &Kind, Register Xn,
Register Xm) { … }
static std::tuple<const ThunkKind &, Register, Register>
parseThunkName(StringRef ThunkName) { … }
void SLSHardeningInserter::populateThunk(MachineFunction &MF) { … }
void SLSHardeningInserter::convertBLRToBL(
MachineModuleInfo &MMI, MachineBasicBlock &MBB,
MachineBasicBlock::instr_iterator MBBI, ThunksSet &Thunks) { … }
bool SLSHardeningInserter::hardenBLRs(MachineModuleInfo &MMI,
MachineBasicBlock &MBB,
ThunksSet &Thunks) { … }
namespace {
class AArch64SLSHardening : public ThunkInserterPass<SLSHardeningInserter> { … };
}
char AArch64SLSHardening::ID = …;
INITIALIZE_PASS(…)
FunctionPass *llvm::createAArch64SLSHardeningPass() { … }