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;
28class Twine;
29
31private:
32 MCContext &Ctx;
33
34protected:
35 bool Enabled = true;
36 std::unique_ptr<MCInstrInfo> InstInfo;
37 std::unique_ptr<MCRegisterInfo> RegInfo;
38
39public:
40 MCLFIRewriter(MCContext &Ctx, std::unique_ptr<MCRegisterInfo> &&RI,
41 std::unique_ptr<MCInstrInfo> &&II)
42 : Ctx(Ctx), InstInfo(std::move(II)), RegInfo(std::move(RI)) {}
43
44 LLVM_ABI void error(const MCInst &Inst, const Twine &Msg);
45 LLVM_ABI void warning(const MCInst &Inst, const Twine &Msg);
46
47 void disable() { Enabled = false; }
48 void enable() { Enabled = true; }
49
50 LLVM_ABI bool isCall(const MCInst &Inst) const;
51 LLVM_ABI bool isBranch(const MCInst &Inst) const;
52 LLVM_ABI bool isIndirectBranch(const MCInst &Inst) const;
53 LLVM_ABI bool isReturn(const MCInst &Inst) const;
54
55 LLVM_ABI bool mayLoad(const MCInst &Inst) const;
56 LLVM_ABI bool mayStore(const MCInst &Inst) const;
57
58 LLVM_ABI bool mayModifyRegister(const MCInst &Inst, MCRegister Reg) const;
60 MCRegister Reg) const;
61
62 virtual ~MCLFIRewriter() = default;
63 virtual bool rewriteInst(const MCInst &Inst, MCStreamer &Out,
64 const MCSubtargetInfo &STI) = 0;
65
66 // Called when a label is emitted. Used for optimizations that require
67 // information about jump targets, such as guard elimination.
68 virtual void onLabel(const MCSymbol *Symbol) {}
69};
70
71} // namespace llvm
72#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
std::unique_ptr< MCInstrInfo > InstInfo
LLVM_ABI bool isIndirectBranch(const MCInst &Inst) const
LLVM_ABI void warning(const MCInst &Inst, const Twine &Msg)
LLVM_ABI bool isCall(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
LLVM_ABI bool mayStore(const MCInst &Inst) const
virtual void onLabel(const MCSymbol *Symbol)
virtual ~MCLFIRewriter()=default
LLVM_ABI bool explicitlyModifiesRegister(const MCInst &Inst, MCRegister Reg) 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: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
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
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:1916
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:874