| OLD | NEW |
| 1 //=== ARMMCNaCl.cpp - Expansion of NaCl pseudo-instructions --*- C++ -*-=// | 1 //=== ARMMCNaCl.cpp - Expansion of NaCl pseudo-instructions --*- C++ -*-=// |
| 2 // | 2 // |
| 3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 // | 9 // |
| 10 //===----------------------------------------------------------------------===// | 10 //===----------------------------------------------------------------------===// |
| 11 #define DEBUG_TYPE "arm-mc-nacl" | 11 #define DEBUG_TYPE "arm-mc-nacl" |
| 12 | 12 |
| 13 #include "ARMAddressingModes.h" |
| 13 #include "MCTargetDesc/ARMBaseInfo.h" | 14 #include "MCTargetDesc/ARMBaseInfo.h" |
| 14 #include "MCTargetDesc/ARMMCExpr.h" | 15 #include "MCTargetDesc/ARMMCExpr.h" |
| 15 #include "MCTargetDesc/ARMMCNaCl.h" | 16 #include "MCTargetDesc/ARMMCNaCl.h" |
| 16 #include "MCTargetDesc/ARMMCTargetDesc.h" | 17 #include "MCTargetDesc/ARMMCTargetDesc.h" |
| 17 #include "llvm/MC/MCInst.h" | 18 #include "llvm/MC/MCInst.h" |
| 18 #include "llvm/MC/MCStreamer.h" | 19 #include "llvm/MC/MCStreamer.h" |
| 19 #include "llvm/Support/CommandLine.h" | 20 #include "llvm/Support/CommandLine.h" |
| 20 #include "llvm/Support/Debug.h" | 21 #include "llvm/Support/Debug.h" |
| 21 | 22 |
| 22 using namespace llvm; | 23 using namespace llvm; |
| 23 | 24 |
| 24 /// Two helper functions for emitting the actual guard instructions | 25 /// Two helper functions for emitting the actual guard instructions |
| 25 | 26 |
| 26 static void EmitBICMask(const MCSubtargetInfo &STI, MCStreamer &Out, | 27 static void EmitBICMask(const MCSubtargetInfo &STI, MCStreamer &Out, |
| 27 unsigned Addr, int64_t Pred, unsigned Mask) { | 28 unsigned Addr, int64_t Pred, unsigned Mask) { |
| 28 // bic\Pred \Addr, \Addr, #Mask | 29 // bic\Pred \Addr, \Addr, #Mask |
| 29 MCInst BICInst; | 30 MCInst BICInst; |
| 31 const int32_t EncodedMask = ARM_AM::getSOImmVal(Mask); |
| 32 assert(EncodedMask != -1); |
| 30 BICInst.setOpcode(ARM::BICri); | 33 BICInst.setOpcode(ARM::BICri); |
| 31 BICInst.addOperand(MCOperand::CreateReg(Addr)); // rD | 34 BICInst.addOperand(MCOperand::CreateReg(Addr)); // rD |
| 32 BICInst.addOperand(MCOperand::CreateReg(Addr)); // rS | 35 BICInst.addOperand(MCOperand::CreateReg(Addr)); // rS |
| 33 BICInst.addOperand(MCOperand::CreateImm(Mask)); // imm | 36 BICInst.addOperand(MCOperand::CreateImm(EncodedMask)); // imm |
| 34 BICInst.addOperand(MCOperand::CreateImm(Pred)); // predicate | 37 BICInst.addOperand(MCOperand::CreateImm(Pred)); // predicate |
| 35 BICInst.addOperand(MCOperand::CreateReg(ARM::CPSR)); // CPSR | 38 BICInst.addOperand(MCOperand::CreateReg(ARM::CPSR)); // CPSR |
| 36 BICInst.addOperand(MCOperand::CreateReg(0)); // flag out | 39 BICInst.addOperand(MCOperand::CreateReg(0)); // flag out |
| 37 Out.EmitInstruction(BICInst, STI); | 40 Out.EmitInstruction(BICInst, STI); |
| 38 } | 41 } |
| 39 | 42 |
| 40 static void EmitTST(const MCSubtargetInfo &STI, MCStreamer &Out, unsigned Reg) { | 43 static void EmitTST(const MCSubtargetInfo &STI, MCStreamer &Out, unsigned Reg) { |
| 41 // tst \reg, #\MASK typically 0xc0000000 | 44 // tst \reg, #\MASK typically 0xc0000000 |
| 42 const unsigned Mask = 0xC0000000; | 45 const int32_t Mask = ARM_AM::getSOImmVal(0xC0000000U); |
| 46 assert(Mask != -1); |
| 43 MCInst TSTInst; | 47 MCInst TSTInst; |
| 44 TSTInst.setOpcode(ARM::TSTri); | 48 TSTInst.setOpcode(ARM::TSTri); |
| 45 TSTInst.addOperand(MCOperand::CreateReg(Reg)); // rS | 49 TSTInst.addOperand(MCOperand::CreateReg(Reg)); // rS |
| 46 TSTInst.addOperand(MCOperand::CreateImm(Mask)); // imm | 50 TSTInst.addOperand(MCOperand::CreateImm(Mask)); // imm |
| 47 TSTInst.addOperand(MCOperand::CreateImm((int64_t)ARMCC::AL)); // Always | 51 TSTInst.addOperand(MCOperand::CreateImm((int64_t)ARMCC::AL)); // Always |
| 48 TSTInst.addOperand(MCOperand::CreateImm(0)); // flag out | 52 TSTInst.addOperand(MCOperand::CreateImm(0)); // flag out |
| 49 Out.EmitInstruction(TSTInst, STI); | 53 Out.EmitInstruction(TSTInst, STI); |
| 50 } | 54 } |
| 51 | 55 |
| 52 | 56 |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 assert(State.RecursiveCall && "Illegal Depth"); | 314 assert(State.RecursiveCall && "Illegal Depth"); |
| 311 State.RecursiveCall = false; | 315 State.RecursiveCall = false; |
| 312 | 316 |
| 313 // We're done expanding a SFI guard. Reset state vars. | 317 // We're done expanding a SFI guard. Reset state vars. |
| 314 State.SaveCount = 0; | 318 State.SaveCount = 0; |
| 315 State.I = 0; | 319 State.I = 0; |
| 316 return true; | 320 return true; |
| 317 } | 321 } |
| 318 | 322 |
| 319 } // namespace llvm | 323 } // namespace llvm |
| OLD | NEW |