LLVM 24.0.0git
X86MCLFIRewriter.h
Go to the documentation of this file.
1//===- X86MCLFIRewriter.h ---------------------------------------*- 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//
9// This file declares the X86MCLFIRewriter class, the X86 specific
10// subclass of MCLFIRewriter.
11//
12//===----------------------------------------------------------------------===//
13#ifndef LLVM_LIB_TARGET_X86_MCTARGETDESC_X86MCLFIREWRITER_H
14#define LLVM_LIB_TARGET_X86_MCTARGETDESC_X86MCLFIREWRITER_H
15
17#include "llvm/MC/MCInst.h"
18#include "llvm/MC/MCInstrInfo.h"
21
22namespace llvm {
23class MCContext;
24class MCStreamer;
25class MCSubtargetInfo;
26
27namespace X86 {
28
29constexpr unsigned LFIBundleSize = 32;
30
32public:
33 X86MCLFIRewriter(MCContext &Ctx, std::unique_ptr<MCRegisterInfo> &&RI,
34 std::unique_ptr<MCInstrInfo> &&II)
35 : MCLFIRewriter(Ctx, std::move(RI), std::move(II)) {}
36
37 bool rewriteInst(const MCInst &Inst, MCStreamer &Out,
38 const MCSubtargetInfo &STI) override;
39
40 void onLabel(const MCSymbol *Symbol, MCStreamer &Out) override;
41 void finish(MCStreamer &Out) override;
42
43private:
44 /// Recursion guard to prevent infinite loops when emitting instructions.
45 bool Guard = false;
46
47 /// Prefixes written on their own line, held back so that they can be emitted
48 /// immediately before the instruction they apply to.
50
51 void doRewriteInst(const MCInst &Inst, MCStreamer &Out,
52 const MCSubtargetInfo &STI);
53
54 /// Emit the prefixes that were held back, followed by Inst.
55 void emitWithPrefixes(const MCInst &Inst, MCStreamer &Out,
56 const MCSubtargetInfo &STI);
57
58 /// Report and drop the prefixes that were held back, for when the
59 /// instruction they would apply to does not take them.
60 void discardPrefixes();
61
62 /// Return the 32-bit subregister of Reg, or Reg itself if it already
63 /// is a 32-bit register.
64 MCRegister getReg32(MCRegister Reg) const;
65
66 void rewriteSyscall(const MCInst &Inst, MCStreamer &Out,
67 const MCSubtargetInfo &STI);
68
69 /// Emit the mask sequence that turns an arbitrary value in Reg into a
70 /// bundle-aligned address inside the sandbox.
71 void emitSandboxBranchReg(MCRegister Reg, MCStreamer &Out,
72 const MCSubtargetInfo &STI);
73
74 void rewriteIndirectBranch(const MCInst &Inst, MCStreamer &Out,
75 const MCSubtargetInfo &STI);
76 void rewriteDirectCall(const MCInst &Inst, MCStreamer &Out,
77 const MCSubtargetInfo &STI);
78 void rewriteReturn(const MCInst &Inst, MCStreamer &Out,
79 const MCSubtargetInfo &STI);
80
81 bool isFSAccess(const MCInst &Inst);
82 void rewriteFSAccess(const MCInst &Inst, MCStreamer &Out,
83 const MCSubtargetInfo &STI);
84
85 /// Rewrite the addressing mode of the memory operand at MemIdx so that
86 /// the access it performs stays inside the sandbox.
87 void sandboxMemOperand(MCInst &Inst, int MemIdx) const;
88
89 /// Apply sandboxMemOperand to the memory operand of Inst, if it has one
90 /// that it dereferences.
91 void sandboxMemAccess(MCInst &Inst) const;
92
93 void rewriteMemAccess(const MCInst &Inst, MCStreamer &Out,
94 const MCSubtargetInfo &STI);
95 void rewriteStringOperation(const MCInst &Inst, MCStreamer &Out,
96 const MCSubtargetInfo &STI);
97
98 /// Return the stack pointer register that Inst writes as an explicit
99 /// operand, or NoRegister if it does not write one.
100 MCRegister getWrittenStackReg(const MCInst &Inst) const;
101
102 void rewriteStackModification(MCRegister StackReg, const MCInst &Inst,
103 MCStreamer &Out, const MCSubtargetInfo &STI);
104 void rewriteLeave(const MCInst &Inst, MCStreamer &Out,
105 const MCSubtargetInfo &STI);
106};
107
108} // namespace X86
109} // namespace llvm
110#endif // LLVM_LIB_TARGET_X86_MCTARGETDESC_X86MCLFIREWRITER_H
This file declares the MCLFIRewriter class, an abstract class that encapsulates the rewriting logic f...
Register Reg
uint64_t IntrinsicInst * II
This file defines the SmallVector class.
Context object for machine code objects.
Definition MCContext.h:83
Instances of this class represent a single low-level machine instruction.
Definition MCInst.h:188
MCLFIRewriter(MCContext &Ctx, std::unique_ptr< MCRegisterInfo > &&RI, std::unique_ptr< MCInstrInfo > &&II)
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
Streaming machine code generation interface.
Definition MCStreamer.h:222
Generic base class for all target subtargets.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
void finish(MCStreamer &Out) override
X86MCLFIRewriter(MCContext &Ctx, std::unique_ptr< MCRegisterInfo > &&RI, std::unique_ptr< MCInstrInfo > &&II)
bool rewriteInst(const MCInst &Inst, MCStreamer &Out, const MCSubtargetInfo &STI) override
void onLabel(const MCSymbol *Symbol, MCStreamer &Out) override
Define some predicates that are used for node matching.
constexpr unsigned LFIBundleSize
This is an optimization pass for GlobalISel generic memory operations.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1933
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:879