LLVM: lib/Target/RISCV/RISCVIndirectBranchTracking.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

23

24#define DEBUG_TYPE "riscv-indirect-branch-tracking"

25#define PASS_NAME "RISC-V Indirect Branch Tracking"

26

27using namespace llvm;

28

31 cl::desc("Use preferred fixed label for all labels"));

32

33namespace {

35public:

36 static char ID;

38

39 StringRef getPassName() const override { return PASS_NAME; }

40

41 bool runOnMachineFunction(MachineFunction &MF) override;

42

43private:

45};

46

47}

48

50 false)

51

52char RISCVIndirectBranchTracking::ID = 0;

53

55 return new RISCVIndirectBranchTracking();

56}

57

58static void

61 if (I.isValid())

62 I = MBB.begin();

63 BuildMI(MBB, I, MBB.findDebugLoc(I), TII->get(RISCV::AUIPC), RISCV::X0)

65}

66

69 return false;

71 if (!CalleeFn)

72 return false;

73 AttributeList Attrs = CalleeFn->getAttributes();

74 return Attrs.hasFnAttr(Attribute::ReturnsTwice);

75}

76

77bool RISCVIndirectBranchTracking::runOnMachineFunction(MachineFunction &MF) {

78 const auto &Subtarget = MF.getSubtarget();

79 const RISCVInstrInfo *TII = Subtarget.getInstrInfo();

80 if (!Subtarget.hasStdExtZicfilp())

81 return false;

82

83 uint32_t FixedLabel = 0;

86 report_fatal_error("riscv-landing-pad-label=, needs to fit in "

87 "unsigned 20-bits");

89 }

90

92 for (MachineBasicBlock &MBB : MF) {

95

96 if (F.hasFnAttribute("interrupt"))

97 continue;

98

99 if (F.hasAddressTaken() || F.hasLocalLinkage()) {

101 if (MF.getAlignment() < LpadAlign)

102 MF.setAlignment(LpadAlign);

104 }

105 continue;

106 }

107

113 }

114 }

115

116

117

118 for (MachineBasicBlock &MBB : MF) {

120 if (I->isCall() && I->getNumOperands() > 0 &&

122 auto NextI = std::next(I);

125 }

126 }

127 }

128

130}

const TargetInstrInfo & TII

#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)

static bool isCallReturnTwice(const MachineOperand &MOp)

Definition RISCVIndirectBranchTracking.cpp:67

cl::opt< uint32_t > PreferredLandingPadLabel("riscv-landing-pad-label", cl::ReallyHidden, cl::desc("Use preferred fixed label for all labels"))

static void emitLpad(MachineBasicBlock &MBB, const RISCVInstrInfo *TII, uint32_t Label, MachineBasicBlock::iterator I=MachineBasicBlock::iterator{})

Definition RISCVIndirectBranchTracking.cpp:59

#define PASS_NAME

Definition RISCVIndirectBranchTracking.cpp:25

This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...

FunctionPass class - This class is used to implement most global optimizations.

bool hasAddressTaken() const

Test whether this block is used as something other than the target of a terminator,...

void setAlignment(Align A)

Set alignment of the basic block.

Align getAlignment() const

Return alignment of the basic block.

MachineInstrBundleIterator< MachineInstr > iterator

MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...

const TargetSubtargetInfo & getSubtarget() const

getSubtarget - Return the subtarget for which this machine code is being compiled.

const MachineInstrBuilder & addImm(int64_t Val) const

Add a new immediate operand.

MachineOperand class - Representation of each machine instruction operand.

const GlobalValue * getGlobal() const

bool isGlobal() const

isGlobal - Tests if this is a MO_GlobalAddress operand.

constexpr char Align[]

Key for Kernel::Arg::Metadata::mAlign.

unsigned ID

LLVM IR allows to use arbitrary numbers as calling convention identifiers.

This is an optimization pass for GlobalISel generic memory operations.

MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)

Builder interface. Specify how to create the initial instruction itself.

decltype(auto) dyn_cast(const From &Val)

dyn_cast - Return the argument parameter cast to the specified type.

LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)

constexpr bool isUInt(uint64_t x)

Checks if an unsigned integer fits into the given bit width.

FunctionPass * createRISCVIndirectBranchTrackingPass()