31 #define DEBUG_TYPE "mips-mc-nacl"
35 const unsigned IndirectBranchMaskReg = Mips::T6;
36 const unsigned LoadStoreStackMaskReg = Mips::T7;
47 ~MipsNaClELFStreamer()
override =
default;
52 bool PendingCall =
false;
54 bool isIndirectJump(
const MCInst &
MI) {
64 bool isStackPointerFirstOperand(
const MCInst &MI) {
69 bool isCall(
const MCInst &MI,
bool *IsIndirectCall) {
72 *IsIndirectCall =
false;
92 *IsIndirectCall =
true;
97 void emitMask(
unsigned AddrReg,
unsigned MaskReg,
112 EmitBundleLock(
false);
113 emitMask(AddrReg, IndirectBranchMaskReg, STI);
120 void sandboxLoadStoreStackChange(
const MCInst &MI,
unsigned AddrIdx,
123 EmitBundleLock(
false);
127 emitMask(BaseReg, LoadStoreStackMaskReg, STI);
133 assert((Mips::SP == SPReg) &&
"Unexpected stack-pointer register.");
134 emitMask(SPReg, LoadStoreStackMaskReg, STI);
145 if (isIndirectJump(Inst)) {
148 sandboxIndirectJump(Inst, STI);
157 bool IsSPFirstOperand = isStackPointerFirstOperand(Inst);
158 if (IsMemAccess || IsSPFirstOperand) {
159 bool MaskBefore = (IsMemAccess
162 bool MaskAfter = IsSPFirstOperand && !IsStore;
163 if (MaskBefore || MaskAfter) {
166 sandboxLoadStoreStackChange(Inst, AddrIdx, STI, MaskBefore, MaskAfter);
175 if (isCall(Inst, &IsIndirectCall)) {
180 EmitBundleLock(
true);
181 if (IsIndirectCall) {
183 emitMask(TargetReg, IndirectBranchMaskReg, STI);
255 return Reg != Mips::SP && Reg !=
Mips::T8;
262 MipsNaClELFStreamer *S =
new MipsNaClELFStreamer(Context, TAB, OS, Emitter);
264 S->getAssembler().setRelaxAll(
true);
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
bool isBasePlusOffsetMemoryAccess(unsigned Opcode, unsigned *AddrIdx, bool *IsStore=nullptr)
static MCOperand createReg(unsigned Reg)
Reg
All possible values of the reg field in the ModR/M byte.
bool baseRegNeedsLoadStoreMask(unsigned Reg)
Context object for machine code objects.
unsigned getReg() const
Returns the register number.
Instances of this class represent a single low-level machine instruction.
INITIALIZE_PASS(HexagonEarlyIfConversion,"hexagon-eif","Hexagon early if conversion", false, false) bool HexagonEarlyIfConversion MachineBasicBlock * SB
MCCodeEmitter - Generic instruction encoding interface.
MCELFStreamer * createMipsNaClELFStreamer(MCContext &Context, MCAsmBackend &TAB, raw_pwrite_stream &OS, MCCodeEmitter *Emitter, bool RelaxAll)
void setOpcode(unsigned Op)
CHAIN = SC CHAIN, Imm128 - System call.
unsigned getOpcode() const
static const unsigned MIPS_NACL_BUNDLE_ALIGN
Bitwise operators - logical and, logical or, logical xor.
unsigned getNumOperands() const
MCSubtargetInfo - Generic base class for all target subtargets.
An abstract base class for streams implementations that also support a pwrite operation.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
cl::opt< bool > RelaxAll("mc-relax-all", cl::desc("When used with filetype=obj, ""relax all fixups in the emitted object file"))
Generic interface to target specific assembler backends.
void addOperand(const MCOperand &Op)
const MCOperand & getOperand(unsigned i) const
void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, bool=false) override
Overriding this function allows us to add arbitrary behaviour before the Inst is actually emitted...