LLVM 23.0.0git
MCLFIRewriter.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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/// \file
10/// This file declares the MCLFIRewriter class, an abstract class that
11/// encapsulates the rewriting logic for MCInsts.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_MC_MCLFIREWRITER_H
16#define LLVM_MC_MCLFIREWRITER_H
17
18#include "llvm/MC/MCInstrInfo.h"
21
22namespace llvm {
23class MCContext;
24class MCInst;
25class MCSubtargetInfo;
26class MCStreamer;
27class MCSymbol;
28
30private:
31 MCContext &Ctx;
32
33protected:
34 bool Enabled = true;
35 std::unique_ptr<MCInstrInfo> InstInfo;
36 std::unique_ptr<MCRegisterInfo> RegInfo;
37
38public:
39 MCLFIRewriter(MCContext &Ctx, std::unique_ptr<MCRegisterInfo> &&RI,
40 std::unique_ptr<MCInstrInfo> &&II)
41 : Ctx(Ctx), InstInfo(std::move(II)), RegInfo(std::move(RI)) {}
42
43 LLVM_ABI void error(const MCInst &Inst, const char Msg[]);
44
45 void disable() { Enabled = false; }
46 void enable() { Enabled = true; }
47
48 LLVM_ABI bool isCall(const MCInst &Inst) const;
49 LLVM_ABI bool isBranch(const MCInst &Inst) const;
50 LLVM_ABI bool isIndirectBranch(const MCInst &Inst) const;
51 LLVM_ABI bool isReturn(const MCInst &Inst) const;
52
53 LLVM_ABI bool mayLoad(const MCInst &Inst) const;
54 LLVM_ABI bool mayStore(const MCInst &Inst) const;
55
56 LLVM_ABI bool mayModifyRegister(const MCInst &Inst, MCRegister Reg) const;
57
58 virtual ~MCLFIRewriter() = default;
59 virtual bool rewriteInst(const MCInst &Inst, MCStreamer &Out,
60 const MCSubtargetInfo &STI) = 0;
61
62 // Called when a label is emitted. Used for optimizations that require
63 // information about jump targets, such as guard elimination.
64 virtual void onLabel(const MCSymbol *Symbol) {}
65};
66
67} // namespace llvm
68#endif
#define LLVM_ABI
Definition Compiler.h:213
Register Reg
uint64_t IntrinsicInst * II
#define error(X)
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
LLVM_ABI bool mayModifyRegister(const MCInst &Inst, MCRegister Reg) const
LLVM_ABI bool mayLoad(const MCInst &Inst) const
LLVM_ABI bool isCall(const MCInst &Inst) const
std::unique_ptr< MCInstrInfo > InstInfo
LLVM_ABI bool mayStore(const MCInst &Inst) const
LLVM_ABI bool isReturn(const MCInst &Inst) const
std::unique_ptr< MCRegisterInfo > RegInfo
virtual bool rewriteInst(const MCInst &Inst, MCStreamer &Out, const MCSubtargetInfo &STI)=0
virtual void onLabel(const MCSymbol *Symbol)
virtual ~MCLFIRewriter()=default
LLVM_ABI bool isIndirectBranch(const MCInst &Inst) const
MCLFIRewriter(MCContext &Ctx, std::unique_ptr< MCRegisterInfo > &&RI, std::unique_ptr< MCInstrInfo > &&II)
LLVM_ABI bool isBranch(const MCInst &Inst) const
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
Streaming machine code generation interface.
Definition MCStreamer.h:221
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 an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
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:1917
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:870