2009-10-20 04:20:46 +08:00
|
|
|
//===-- ARMAsmPrinter.cpp - Print machine code to an ARM .s file ----------===//
|
|
|
|
//
|
2006-05-15 06:18:28 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
2006-05-15 06:18:28 +08:00
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains a printer that converts from our internal representation
|
|
|
|
// of machine-dependent LLVM code to GAS-format ARM assembly language.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-01-12 05:46:47 +08:00
|
|
|
#include "ARMAsmPrinter.h"
|
2012-03-17 15:33:42 +08:00
|
|
|
#include "ARM.h"
|
2007-01-19 15:51:42 +08:00
|
|
|
#include "ARMConstantPoolValue.h"
|
2009-10-20 04:20:46 +08:00
|
|
|
#include "ARMMachineFunctionInfo.h"
|
|
|
|
#include "ARMTargetMachine.h"
|
2010-10-12 07:01:44 +08:00
|
|
|
#include "ARMTargetObjectFile.h"
|
2011-01-12 05:46:47 +08:00
|
|
|
#include "InstPrinter/ARMInstPrinter.h"
|
2011-07-21 07:34:39 +08:00
|
|
|
#include "MCTargetDesc/ARMAddressingModes.h"
|
|
|
|
#include "MCTargetDesc/ARMMCExpr.h"
|
2012-10-05 05:33:24 +08:00
|
|
|
#include "llvm/ADT/SetVector.h"
|
|
|
|
#include "llvm/ADT/SmallString.h"
|
2017-06-07 11:48:56 +08:00
|
|
|
#include "llvm/BinaryFormat/COFF.h"
|
2006-05-15 06:18:28 +08:00
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
2007-01-19 15:51:42 +08:00
|
|
|
#include "llvm/CodeGen/MachineJumpTableInfo.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/CodeGen/MachineModuleInfoImpls.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Constants.h"
|
|
|
|
#include "llvm/IR/DataLayout.h"
|
2014-01-08 05:19:40 +08:00
|
|
|
#include "llvm/IR/Mangler.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Module.h"
|
|
|
|
#include "llvm/IR/Type.h"
|
2009-10-20 02:38:33 +08:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2010-10-26 01:50:35 +08:00
|
|
|
#include "llvm/MC/MCAssembler.h"
|
2009-10-20 02:38:33 +08:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2013-01-30 10:24:33 +08:00
|
|
|
#include "llvm/MC/MCELFStreamer.h"
|
2009-10-20 04:20:46 +08:00
|
|
|
#include "llvm/MC/MCInst.h"
|
2012-11-26 21:34:22 +08:00
|
|
|
#include "llvm/MC/MCInstBuilder.h"
|
2010-10-26 01:50:35 +08:00
|
|
|
#include "llvm/MC/MCObjectStreamer.h"
|
2009-08-19 13:49:37 +08:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2009-09-14 01:14:04 +08:00
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2014-01-19 16:25:27 +08:00
|
|
|
#include "llvm/Support/ARMBuildAttributes.h"
|
2010-08-05 06:39:39 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2009-07-09 04:55:50 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2016-04-18 17:17:29 +08:00
|
|
|
#include "llvm/Support/TargetParser.h"
|
2011-08-25 02:08:43 +08:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2010-04-04 16:18:47 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2006-05-15 06:18:28 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 10:41:26 +08:00
|
|
|
#define DEBUG_TYPE "asm-printer"
|
|
|
|
|
2015-01-19 04:29:04 +08:00
|
|
|
ARMAsmPrinter::ARMAsmPrinter(TargetMachine &TM,
|
|
|
|
std::unique_ptr<MCStreamer> Streamer)
|
|
|
|
: AsmPrinter(TM, std::move(Streamer)), AFI(nullptr), MCP(nullptr),
|
2015-12-07 22:22:39 +08:00
|
|
|
InConstantPool(false), OptimizationGoals(-1) {}
|
2015-01-19 04:29:04 +08:00
|
|
|
|
2012-05-19 03:12:01 +08:00
|
|
|
void ARMAsmPrinter::EmitFunctionBodyEnd() {
|
|
|
|
// Make sure to terminate any constant pools that were at the end
|
|
|
|
// of the function.
|
|
|
|
if (!InConstantPool)
|
|
|
|
return;
|
|
|
|
InConstantPool = false;
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitDataRegion(MCDR_DataRegionEnd);
|
2012-05-19 03:12:01 +08:00
|
|
|
}
|
2011-10-05 07:26:17 +08:00
|
|
|
|
2012-05-19 03:12:01 +08:00
|
|
|
void ARMAsmPrinter::EmitFunctionEntryLabel() {
|
2010-01-28 07:58:11 +08:00
|
|
|
if (AFI->isThumbFunction()) {
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitAssemblerFlag(MCAF_Code16);
|
|
|
|
OutStreamer->EmitThumbFunc(CurrentFnSym);
|
2016-09-13 20:18:15 +08:00
|
|
|
} else {
|
|
|
|
OutStreamer->EmitAssemblerFlag(MCAF_Code32);
|
2010-01-28 07:58:11 +08:00
|
|
|
}
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitLabel(CurrentFnSym);
|
2010-01-28 07:58:11 +08:00
|
|
|
}
|
|
|
|
|
2015-07-16 14:11:10 +08:00
|
|
|
void ARMAsmPrinter::EmitXXStructor(const DataLayout &DL, const Constant *CV) {
|
|
|
|
uint64_t Size = getDataLayout().getTypeAllocSize(CV->getType());
|
2012-01-26 17:25:43 +08:00
|
|
|
assert(Size && "C++ constructor pointer had zero size!");
|
|
|
|
|
2012-02-15 17:14:08 +08:00
|
|
|
const GlobalValue *GV = dyn_cast<GlobalValue>(CV->stripPointerCasts());
|
2012-01-26 17:25:43 +08:00
|
|
|
assert(GV && "C++ constructor pointer was not a GlobalValue!");
|
|
|
|
|
2015-05-30 09:25:56 +08:00
|
|
|
const MCExpr *E = MCSymbolRefExpr::create(GetARMGVSymbol(GV,
|
2014-07-07 13:18:22 +08:00
|
|
|
ARMII::MO_NO_FLAG),
|
2014-01-06 22:28:05 +08:00
|
|
|
(Subtarget->isTargetELF()
|
|
|
|
? MCSymbolRefExpr::VK_ARM_TARGET1
|
|
|
|
: MCSymbolRefExpr::VK_None),
|
2012-01-26 17:25:43 +08:00
|
|
|
OutContext);
|
2014-04-04 07:43:18 +08:00
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitValue(E, Size);
|
2012-01-26 17:25:43 +08:00
|
|
|
}
|
|
|
|
|
2016-09-26 15:26:24 +08:00
|
|
|
void ARMAsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) {
|
|
|
|
if (PromotedGlobals.count(GV))
|
|
|
|
// The global was promoted into a constant pool. It should not be emitted.
|
|
|
|
return;
|
|
|
|
AsmPrinter::EmitGlobalVariable(GV);
|
|
|
|
}
|
|
|
|
|
2010-09-30 09:57:53 +08:00
|
|
|
/// runOnMachineFunction - This uses the EmitInstruction()
|
2006-05-15 06:18:28 +08:00
|
|
|
/// method to print assembly for each instruction.
|
|
|
|
///
|
|
|
|
bool ARMAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
2007-01-19 15:51:42 +08:00
|
|
|
AFI = MF.getInfo<ARMFunctionInfo>();
|
2008-09-18 15:27:23 +08:00
|
|
|
MCP = MF.getConstantPool();
|
2015-02-18 04:02:32 +08:00
|
|
|
Subtarget = &MF.getSubtarget<ARMSubtarget>();
|
2007-01-19 15:51:42 +08:00
|
|
|
|
2014-04-30 14:14:25 +08:00
|
|
|
SetupMachineFunction(MF);
|
2017-12-16 06:22:58 +08:00
|
|
|
const Function &F = MF.getFunction();
|
2015-12-07 22:22:39 +08:00
|
|
|
const TargetMachine& TM = MF.getTarget();
|
|
|
|
|
2016-09-26 15:26:24 +08:00
|
|
|
// Collect all globals that had their storage promoted to a constant pool.
|
|
|
|
// Functions are emitted before variables, so this accumulates promoted
|
|
|
|
// globals from all functions in PromotedGlobals.
|
|
|
|
for (auto *GV : AFI->getGlobalsPromotedToConstantPool())
|
|
|
|
PromotedGlobals.insert(GV);
|
|
|
|
|
2015-12-07 22:22:39 +08:00
|
|
|
// Calculate this function's optimization goal.
|
|
|
|
unsigned OptimizationGoal;
|
2017-12-16 06:22:58 +08:00
|
|
|
if (F.hasFnAttribute(Attribute::OptimizeNone))
|
2015-12-07 22:22:39 +08:00
|
|
|
// For best debugging illusion, speed and small size sacrificed
|
|
|
|
OptimizationGoal = 6;
|
2017-12-16 06:22:58 +08:00
|
|
|
else if (F.optForMinSize())
|
2015-12-07 22:22:39 +08:00
|
|
|
// Aggressively for small size, speed and debug illusion sacrificed
|
|
|
|
OptimizationGoal = 4;
|
2017-12-16 06:22:58 +08:00
|
|
|
else if (F.optForSize())
|
2015-12-07 22:22:39 +08:00
|
|
|
// For small size, but speed and debugging illusion preserved
|
|
|
|
OptimizationGoal = 3;
|
|
|
|
else if (TM.getOptLevel() == CodeGenOpt::Aggressive)
|
|
|
|
// Aggressively for speed, small size and debug illusion sacrificed
|
|
|
|
OptimizationGoal = 2;
|
|
|
|
else if (TM.getOptLevel() > CodeGenOpt::None)
|
|
|
|
// For speed, but small size and good debug illusion preserved
|
|
|
|
OptimizationGoal = 1;
|
|
|
|
else // TM.getOptLevel() == CodeGenOpt::None
|
|
|
|
// For good debugging, but speed and small size preserved
|
|
|
|
OptimizationGoal = 5;
|
|
|
|
|
|
|
|
// Combine a new optimization goal with existing ones.
|
|
|
|
if (OptimizationGoals == -1) // uninitialized goals
|
|
|
|
OptimizationGoals = OptimizationGoal;
|
|
|
|
else if (OptimizationGoals != (int)OptimizationGoal) // conflicting goals
|
|
|
|
OptimizationGoals = 0;
|
2014-04-30 14:14:25 +08:00
|
|
|
|
|
|
|
if (Subtarget->isTargetCOFF()) {
|
2017-12-16 06:22:58 +08:00
|
|
|
bool Internal = F.hasInternalLinkage();
|
2014-04-30 14:14:25 +08:00
|
|
|
COFF::SymbolStorageClass Scl = Internal ? COFF::IMAGE_SYM_CLASS_STATIC
|
|
|
|
: COFF::IMAGE_SYM_CLASS_EXTERNAL;
|
|
|
|
int Type = COFF::IMAGE_SYM_DTYPE_FUNCTION << COFF::SCT_COMPLEX_TYPE_SHIFT;
|
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->BeginCOFFSymbolDef(CurrentFnSym);
|
|
|
|
OutStreamer->EmitCOFFSymbolStorageClass(Scl);
|
|
|
|
OutStreamer->EmitCOFFSymbolType(Type);
|
|
|
|
OutStreamer->EndCOFFSymbolDef();
|
2014-04-30 14:14:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Emit the rest of the function body.
|
|
|
|
EmitFunctionBody();
|
|
|
|
|
2017-01-20 04:24:23 +08:00
|
|
|
// Emit the XRay table for this function.
|
|
|
|
emitXRayTable();
|
|
|
|
|
2014-12-05 03:34:50 +08:00
|
|
|
// If we need V4T thumb mode Register Indirect Jump pads, emit them.
|
|
|
|
// These are created per function, rather than per TU, since it's
|
|
|
|
// relatively easy to exceed the thumb branch range within a TU.
|
|
|
|
if (! ThumbIndirectPads.empty()) {
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitAssemblerFlag(MCAF_Code16);
|
2014-12-05 03:34:50 +08:00
|
|
|
EmitAlignment(1);
|
2017-08-29 18:04:18 +08:00
|
|
|
for (std::pair<unsigned, MCSymbol *> &TIP : ThumbIndirectPads) {
|
|
|
|
OutStreamer->EmitLabel(TIP.second);
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tBX)
|
2017-08-29 18:04:18 +08:00
|
|
|
.addReg(TIP.first)
|
2014-12-05 03:34:50 +08:00
|
|
|
// Add predicate operands.
|
|
|
|
.addImm(ARMCC::AL)
|
|
|
|
.addReg(0));
|
|
|
|
}
|
|
|
|
ThumbIndirectPads.clear();
|
|
|
|
}
|
|
|
|
|
2014-04-30 14:14:25 +08:00
|
|
|
// We didn't modify anything.
|
|
|
|
return false;
|
2006-10-18 02:04:53 +08:00
|
|
|
}
|
|
|
|
|
2009-06-29 15:51:04 +08:00
|
|
|
void ARMAsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
|
2015-05-14 04:28:41 +08:00
|
|
|
raw_ostream &O) {
|
2009-06-29 15:51:04 +08:00
|
|
|
const MachineOperand &MO = MI->getOperand(OpNum);
|
2009-11-24 08:44:37 +08:00
|
|
|
unsigned TF = MO.getTargetFlags();
|
|
|
|
|
2006-05-25 20:57:06 +08:00
|
|
|
switch (MO.getType()) {
|
2012-02-07 10:50:20 +08:00
|
|
|
default: llvm_unreachable("<unknown operand type>");
|
2009-06-23 07:27:02 +08:00
|
|
|
case MachineOperand::MO_Register: {
|
|
|
|
unsigned Reg = MO.getReg();
|
2009-10-20 04:59:55 +08:00
|
|
|
assert(TargetRegisterInfo::isPhysicalRegister(Reg));
|
2010-10-07 05:22:32 +08:00
|
|
|
assert(!MO.getSubReg() && "Subregs should be eliminated!");
|
2013-02-15 02:10:21 +08:00
|
|
|
if(ARM::GPRPairRegClass.contains(Reg)) {
|
|
|
|
const MachineFunction &MF = *MI->getParent()->getParent();
|
2014-08-05 10:39:49 +08:00
|
|
|
const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
|
2013-02-15 02:10:21 +08:00
|
|
|
Reg = TRI->getSubReg(Reg, ARM::gsub_0);
|
|
|
|
}
|
2010-10-07 05:22:32 +08:00
|
|
|
O << ARMInstPrinter::getRegisterName(Reg);
|
2006-05-25 20:57:06 +08:00
|
|
|
break;
|
2009-06-23 07:27:02 +08:00
|
|
|
}
|
2007-01-19 15:51:42 +08:00
|
|
|
case MachineOperand::MO_Immediate: {
|
2009-09-28 17:14:39 +08:00
|
|
|
int64_t Imm = MO.getImm();
|
2009-10-09 04:43:22 +08:00
|
|
|
O << '#';
|
2015-05-14 04:28:41 +08:00
|
|
|
if (TF == ARMII::MO_LO16)
|
2009-11-24 08:44:37 +08:00
|
|
|
O << ":lower16:";
|
2015-05-14 04:28:41 +08:00
|
|
|
else if (TF == ARMII::MO_HI16)
|
2009-11-24 08:44:37 +08:00
|
|
|
O << ":upper16:";
|
2009-10-09 04:43:22 +08:00
|
|
|
O << Imm;
|
2006-05-25 20:57:06 +08:00
|
|
|
break;
|
2007-01-19 15:51:42 +08:00
|
|
|
}
|
2006-05-25 20:57:06 +08:00
|
|
|
case MachineOperand::MO_MachineBasicBlock:
|
2015-06-09 08:31:39 +08:00
|
|
|
MO.getMBB()->getSymbol()->print(O, MAI);
|
2006-05-25 20:57:06 +08:00
|
|
|
return;
|
2006-07-16 09:02:57 +08:00
|
|
|
case MachineOperand::MO_GlobalAddress: {
|
2010-04-15 09:51:59 +08:00
|
|
|
const GlobalValue *GV = MO.getGlobal();
|
2015-05-14 04:28:41 +08:00
|
|
|
if (TF & ARMII::MO_LO16)
|
2009-11-24 08:44:37 +08:00
|
|
|
O << ":lower16:";
|
2015-05-14 04:28:41 +08:00
|
|
|
else if (TF & ARMII::MO_HI16)
|
2009-11-24 08:44:37 +08:00
|
|
|
O << ":upper16:";
|
2015-06-09 08:31:39 +08:00
|
|
|
GetARMGVSymbol(GV, TF)->print(O, MAI);
|
2008-11-23 00:15:34 +08:00
|
|
|
|
2010-04-04 06:28:33 +08:00
|
|
|
printOffset(MO.getOffset(), O);
|
2006-05-25 20:57:06 +08:00
|
|
|
break;
|
2007-01-19 15:51:42 +08:00
|
|
|
}
|
2006-05-25 20:57:06 +08:00
|
|
|
case MachineOperand::MO_ConstantPoolIndex:
|
2016-12-15 15:59:08 +08:00
|
|
|
if (Subtarget->genExecuteOnly())
|
|
|
|
llvm_unreachable("execute-only should not generate constant pools");
|
2015-06-09 08:31:39 +08:00
|
|
|
GetCPISymbol(MO.getIndex())->print(O, MAI);
|
2006-05-25 20:57:06 +08:00
|
|
|
break;
|
|
|
|
}
|
2006-05-15 06:18:28 +08:00
|
|
|
}
|
|
|
|
|
2009-06-29 15:51:04 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
2010-01-26 03:51:38 +08:00
|
|
|
MCSymbol *ARMAsmPrinter::
|
2015-05-14 04:28:38 +08:00
|
|
|
GetARMJTIPICJumpTableLabel(unsigned uid) const {
|
2015-07-16 14:11:10 +08:00
|
|
|
const DataLayout &DL = getDataLayout();
|
2010-01-26 03:51:38 +08:00
|
|
|
SmallString<60> Name;
|
2015-07-16 14:11:10 +08:00
|
|
|
raw_svector_ostream(Name) << DL.getPrivateGlobalPrefix() << "JTI"
|
2015-05-14 04:28:38 +08:00
|
|
|
<< getFunctionNumber() << '_' << uid;
|
2015-05-19 02:43:14 +08:00
|
|
|
return OutContext.getOrCreateSymbol(Name);
|
2010-01-26 03:39:52 +08:00
|
|
|
}
|
|
|
|
|
2009-06-29 15:51:04 +08:00
|
|
|
bool ARMAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
|
2010-04-04 13:29:35 +08:00
|
|
|
unsigned AsmVariant, const char *ExtraCode,
|
|
|
|
raw_ostream &O) {
|
2007-01-19 15:51:42 +08:00
|
|
|
// Does this asm operand have a single letter operand modifier?
|
|
|
|
if (ExtraCode && ExtraCode[0]) {
|
|
|
|
if (ExtraCode[1] != 0) return true; // Unknown modifier.
|
2009-08-09 07:10:41 +08:00
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
switch (ExtraCode[0]) {
|
2012-06-26 21:49:27 +08:00
|
|
|
default:
|
|
|
|
// See if this is a generic print operand
|
|
|
|
return AsmPrinter::PrintAsmOperand(MI, OpNum, AsmVariant, ExtraCode, O);
|
2009-07-10 07:54:51 +08:00
|
|
|
case 'a': // Print as a memory address.
|
|
|
|
if (MI->getOperand(OpNum).isReg()) {
|
2010-09-30 23:25:22 +08:00
|
|
|
O << "["
|
|
|
|
<< ARMInstPrinter::getRegisterName(MI->getOperand(OpNum).getReg())
|
|
|
|
<< "]";
|
2009-07-10 07:54:51 +08:00
|
|
|
return false;
|
|
|
|
}
|
2016-08-17 13:10:15 +08:00
|
|
|
LLVM_FALLTHROUGH;
|
2009-07-10 07:54:51 +08:00
|
|
|
case 'c': // Don't print "#" before an immediate operand.
|
2009-08-22 05:58:55 +08:00
|
|
|
if (!MI->getOperand(OpNum).isImm())
|
|
|
|
return true;
|
2010-09-30 09:57:53 +08:00
|
|
|
O << MI->getOperand(OpNum).getImm();
|
2009-04-07 05:46:51 +08:00
|
|
|
return false;
|
2007-04-04 08:13:29 +08:00
|
|
|
case 'P': // Print a VFP double precision register.
|
2009-12-09 07:06:22 +08:00
|
|
|
case 'q': // Print a NEON quad precision register.
|
2010-04-04 12:47:45 +08:00
|
|
|
printOperand(MI, OpNum, O);
|
2007-03-09 06:42:46 +08:00
|
|
|
return false;
|
2011-05-25 06:10:34 +08:00
|
|
|
case 'y': // Print a VFP single precision register as indexed double.
|
|
|
|
if (MI->getOperand(OpNum).isReg()) {
|
|
|
|
unsigned Reg = MI->getOperand(OpNum).getReg();
|
2014-08-05 10:39:49 +08:00
|
|
|
const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
|
2012-05-31 07:00:43 +08:00
|
|
|
// Find the 'd' register that has this 's' register as a sub-register,
|
|
|
|
// and determine the lane number.
|
|
|
|
for (MCSuperRegIterator SR(Reg, TRI); SR.isValid(); ++SR) {
|
|
|
|
if (!ARM::DPRRegClass.contains(*SR))
|
|
|
|
continue;
|
|
|
|
bool Lane0 = TRI->getSubReg(*SR, ARM::ssub_0) == Reg;
|
|
|
|
O << ARMInstPrinter::getRegisterName(*SR) << (Lane0 ? "[0]" : "[1]");
|
|
|
|
return false;
|
|
|
|
}
|
2011-05-25 06:10:34 +08:00
|
|
|
}
|
2011-05-25 07:27:13 +08:00
|
|
|
return true;
|
2011-05-25 06:27:43 +08:00
|
|
|
case 'B': // Bitwise inverse of integer or symbol without a preceding #.
|
2011-05-25 07:15:43 +08:00
|
|
|
if (!MI->getOperand(OpNum).isImm())
|
|
|
|
return true;
|
|
|
|
O << ~(MI->getOperand(OpNum).getImm());
|
|
|
|
return false;
|
2011-05-25 06:27:43 +08:00
|
|
|
case 'L': // The low 16 bits of an immediate constant.
|
2011-05-25 07:27:13 +08:00
|
|
|
if (!MI->getOperand(OpNum).isImm())
|
|
|
|
return true;
|
|
|
|
O << (MI->getOperand(OpNum).getImm() & 0xffff);
|
|
|
|
return false;
|
2011-05-28 09:40:44 +08:00
|
|
|
case 'M': { // A register range suitable for LDM/STM.
|
|
|
|
if (!MI->getOperand(OpNum).isReg())
|
|
|
|
return true;
|
|
|
|
const MachineOperand &MO = MI->getOperand(OpNum);
|
|
|
|
unsigned RegBegin = MO.getReg();
|
|
|
|
// This takes advantage of the 2 operand-ness of ldm/stm and that we've
|
|
|
|
// already got the operands in registers that are operands to the
|
|
|
|
// inline asm statement.
|
2013-06-29 01:26:02 +08:00
|
|
|
O << "{";
|
|
|
|
if (ARM::GPRPairRegClass.contains(RegBegin)) {
|
2014-08-05 10:39:49 +08:00
|
|
|
const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
|
2013-06-29 01:26:02 +08:00
|
|
|
unsigned Reg0 = TRI->getSubReg(RegBegin, ARM::gsub_0);
|
2014-04-20 07:56:35 +08:00
|
|
|
O << ARMInstPrinter::getRegisterName(Reg0) << ", ";
|
2013-06-29 01:26:02 +08:00
|
|
|
RegBegin = TRI->getSubReg(RegBegin, ARM::gsub_1);
|
|
|
|
}
|
|
|
|
O << ARMInstPrinter::getRegisterName(RegBegin);
|
2011-09-03 02:46:15 +08:00
|
|
|
|
2011-05-28 09:40:44 +08:00
|
|
|
// FIXME: The register allocator not only may not have given us the
|
|
|
|
// registers in sequence, but may not be in ascending registers. This
|
|
|
|
// will require changes in the register allocator that'll need to be
|
|
|
|
// propagated down here if the operands change.
|
|
|
|
unsigned RegOps = OpNum + 1;
|
|
|
|
while (MI->getOperand(RegOps).isReg()) {
|
2011-09-03 02:46:15 +08:00
|
|
|
O << ", "
|
2011-05-28 09:40:44 +08:00
|
|
|
<< ARMInstPrinter::getRegisterName(MI->getOperand(RegOps).getReg());
|
|
|
|
RegOps++;
|
|
|
|
}
|
|
|
|
|
|
|
|
O << "}";
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2011-08-11 00:26:42 +08:00
|
|
|
case 'R': // The most significant register of a pair.
|
|
|
|
case 'Q': { // The least significant register of a pair.
|
|
|
|
if (OpNum == 0)
|
|
|
|
return true;
|
|
|
|
const MachineOperand &FlagsOP = MI->getOperand(OpNum - 1);
|
|
|
|
if (!FlagsOP.isImm())
|
|
|
|
return true;
|
|
|
|
unsigned Flags = FlagsOP.getImm();
|
2013-08-22 14:51:04 +08:00
|
|
|
|
|
|
|
// This operand may not be the one that actually provides the register. If
|
|
|
|
// it's tied to a previous one then we should refer instead to that one
|
|
|
|
// for registers and their classes.
|
|
|
|
unsigned TiedIdx;
|
|
|
|
if (InlineAsm::isUseOperandTiedToDef(Flags, TiedIdx)) {
|
|
|
|
for (OpNum = InlineAsm::MIOp_FirstOperand; TiedIdx; --TiedIdx) {
|
|
|
|
unsigned OpFlags = MI->getOperand(OpNum).getImm();
|
|
|
|
OpNum += InlineAsm::getNumOperandRegisters(OpFlags) + 1;
|
|
|
|
}
|
|
|
|
Flags = MI->getOperand(OpNum).getImm();
|
|
|
|
|
|
|
|
// Later code expects OpNum to be pointing at the register rather than
|
|
|
|
// the flags.
|
|
|
|
OpNum += 1;
|
|
|
|
}
|
|
|
|
|
2011-08-11 00:26:42 +08:00
|
|
|
unsigned NumVals = InlineAsm::getNumOperandRegisters(Flags);
|
2013-06-29 01:26:02 +08:00
|
|
|
unsigned RC;
|
|
|
|
InlineAsm::hasRegClassConstraint(Flags, RC);
|
|
|
|
if (RC == ARM::GPRPairRegClassID) {
|
|
|
|
if (NumVals != 1)
|
|
|
|
return true;
|
|
|
|
const MachineOperand &MO = MI->getOperand(OpNum);
|
|
|
|
if (!MO.isReg())
|
|
|
|
return true;
|
2014-08-05 10:39:49 +08:00
|
|
|
const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
|
2013-06-29 01:26:02 +08:00
|
|
|
unsigned Reg = TRI->getSubReg(MO.getReg(), ExtraCode[0] == 'Q' ?
|
|
|
|
ARM::gsub_0 : ARM::gsub_1);
|
|
|
|
O << ARMInstPrinter::getRegisterName(Reg);
|
|
|
|
return false;
|
|
|
|
}
|
2011-08-11 00:26:42 +08:00
|
|
|
if (NumVals != 2)
|
|
|
|
return true;
|
|
|
|
unsigned RegOp = ExtraCode[0] == 'Q' ? OpNum : OpNum + 1;
|
|
|
|
if (RegOp >= MI->getNumOperands())
|
|
|
|
return true;
|
|
|
|
const MachineOperand &MO = MI->getOperand(RegOp);
|
|
|
|
if (!MO.isReg())
|
|
|
|
return true;
|
|
|
|
unsigned Reg = MO.getReg();
|
|
|
|
O << ARMInstPrinter::getRegisterName(Reg);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-05-25 06:27:43 +08:00
|
|
|
case 'e': // The low doubleword register of a NEON quad register.
|
2011-12-13 05:45:15 +08:00
|
|
|
case 'f': { // The high doubleword register of a NEON quad register.
|
|
|
|
if (!MI->getOperand(OpNum).isReg())
|
|
|
|
return true;
|
|
|
|
unsigned Reg = MI->getOperand(OpNum).getReg();
|
|
|
|
if (!ARM::QPRRegClass.contains(Reg))
|
|
|
|
return true;
|
2014-08-05 10:39:49 +08:00
|
|
|
const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
|
2011-12-13 05:45:15 +08:00
|
|
|
unsigned SubReg = TRI->getSubReg(Reg, ExtraCode[0] == 'e' ?
|
|
|
|
ARM::dsub_0 : ARM::dsub_1);
|
|
|
|
O << ARMInstPrinter::getRegisterName(SubReg);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-14 02:18:52 +08:00
|
|
|
// This modifier is not yet supported.
|
2011-05-25 06:27:43 +08:00
|
|
|
case 'h': // A range of VFP/NEON registers suitable for VLD1/VST1.
|
2010-05-28 04:23:42 +08:00
|
|
|
return true;
|
2012-08-15 07:32:15 +08:00
|
|
|
case 'H': { // The highest-numbered register of a pair.
|
2012-08-14 02:18:52 +08:00
|
|
|
const MachineOperand &MO = MI->getOperand(OpNum);
|
|
|
|
if (!MO.isReg())
|
|
|
|
return true;
|
|
|
|
const MachineFunction &MF = *MI->getParent()->getParent();
|
2014-08-05 10:39:49 +08:00
|
|
|
const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
|
2013-02-15 02:10:21 +08:00
|
|
|
unsigned Reg = MO.getReg();
|
|
|
|
if(!ARM::GPRPairRegClass.contains(Reg))
|
|
|
|
return false;
|
|
|
|
Reg = TRI->getSubReg(Reg, ARM::gsub_1);
|
2012-08-14 02:18:52 +08:00
|
|
|
O << ARMInstPrinter::getRegisterName(Reg);
|
|
|
|
return false;
|
2010-05-28 06:08:38 +08:00
|
|
|
}
|
2012-08-15 07:32:15 +08:00
|
|
|
}
|
2007-01-19 15:51:42 +08:00
|
|
|
}
|
2009-09-04 09:38:51 +08:00
|
|
|
|
2010-04-04 12:47:45 +08:00
|
|
|
printOperand(MI, OpNum, O);
|
2007-01-19 15:51:42 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-05-19 13:53:42 +08:00
|
|
|
bool ARMAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
|
2009-06-29 15:51:04 +08:00
|
|
|
unsigned OpNum, unsigned AsmVariant,
|
2010-04-04 13:29:35 +08:00
|
|
|
const char *ExtraCode,
|
|
|
|
raw_ostream &O) {
|
2011-05-26 04:51:58 +08:00
|
|
|
// Does this asm operand have a single letter operand modifier?
|
|
|
|
if (ExtraCode && ExtraCode[0]) {
|
|
|
|
if (ExtraCode[1] != 0) return true; // Unknown modifier.
|
2011-09-03 02:46:15 +08:00
|
|
|
|
2011-05-26 04:51:58 +08:00
|
|
|
switch (ExtraCode[0]) {
|
2011-05-27 02:22:26 +08:00
|
|
|
case 'A': // A memory operand for a VLD1/VST1 instruction.
|
2011-05-26 04:51:58 +08:00
|
|
|
default: return true; // Unknown modifier.
|
|
|
|
case 'm': // The base register of a memory operand.
|
|
|
|
if (!MI->getOperand(OpNum).isReg())
|
|
|
|
return true;
|
|
|
|
O << ARMInstPrinter::getRegisterName(MI->getOperand(OpNum).getReg());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2011-09-03 02:46:15 +08:00
|
|
|
|
2009-10-14 04:50:28 +08:00
|
|
|
const MachineOperand &MO = MI->getOperand(OpNum);
|
|
|
|
assert(MO.isReg() && "unexpected inline asm memory operand");
|
2010-09-30 09:57:53 +08:00
|
|
|
O << "[" << ARMInstPrinter::getRegisterName(MO.getReg()) << "]";
|
2009-05-19 13:53:42 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-24 23:47:54 +08:00
|
|
|
static bool isThumb(const MCSubtargetInfo& STI) {
|
2015-05-26 18:47:10 +08:00
|
|
|
return STI.getFeatureBits()[ARM::ModeThumb];
|
2014-01-24 23:47:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARMAsmPrinter::emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
|
2014-02-07 02:19:40 +08:00
|
|
|
const MCSubtargetInfo *EndInfo) const {
|
2014-01-24 23:47:54 +08:00
|
|
|
// If either end mode is unknown (EndInfo == NULL) or different than
|
|
|
|
// the start mode, then restore the start mode.
|
|
|
|
const bool WasThumb = isThumb(StartInfo);
|
2014-04-25 13:30:21 +08:00
|
|
|
if (!EndInfo || WasThumb != isThumb(*EndInfo)) {
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitAssemblerFlag(WasThumb ? MCAF_Code16 : MCAF_Code32);
|
2014-01-24 23:47:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-01 06:06:26 +08:00
|
|
|
void ARMAsmPrinter::EmitStartOfAsmFile(Module &M) {
|
2015-06-16 23:44:21 +08:00
|
|
|
const Triple &TT = TM.getTargetTriple();
|
2009-11-09 08:11:35 +08:00
|
|
|
// Use unified assembler syntax.
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitAssemblerFlag(MCAF_SyntaxUnified);
|
2009-06-18 07:43:18 +08:00
|
|
|
|
2009-05-24 03:51:20 +08:00
|
|
|
// Emit ARM Build Attributes
|
2016-09-03 03:51:34 +08:00
|
|
|
if (TT.isOSBinFormatELF())
|
2010-10-07 06:36:46 +08:00
|
|
|
emitAttributes();
|
2014-07-25 13:12:49 +08:00
|
|
|
|
2015-02-18 04:02:32 +08:00
|
|
|
// Use the triple's architecture and subarchitecture to determine
|
|
|
|
// if we're thumb for the purposes of the top level code16 assembler
|
|
|
|
// flag.
|
2017-08-13 01:40:18 +08:00
|
|
|
if (!M.getModuleInlineAsm().empty() && TT.isThumb())
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitAssemblerFlag(MCAF_Code16);
|
2006-05-15 06:18:28 +08:00
|
|
|
}
|
|
|
|
|
2014-04-29 18:06:05 +08:00
|
|
|
static void
|
|
|
|
emitNonLazySymbolPointer(MCStreamer &OutStreamer, MCSymbol *StubLabel,
|
|
|
|
MachineModuleInfoImpl::StubValueTy &MCSym) {
|
|
|
|
// L_foo$stub:
|
|
|
|
OutStreamer.EmitLabel(StubLabel);
|
|
|
|
// .indirect_symbol _foo
|
|
|
|
OutStreamer.EmitSymbolAttribute(MCSym.getPointer(), MCSA_IndirectSymbol);
|
|
|
|
|
|
|
|
if (MCSym.getInt())
|
|
|
|
// External to current translation unit.
|
|
|
|
OutStreamer.EmitIntValue(0, 4/*size*/);
|
|
|
|
else
|
|
|
|
// Internal to current translation unit.
|
|
|
|
//
|
|
|
|
// When we place the LSDA into the TEXT section, the type info
|
|
|
|
// pointers need to be indirect and pc-rel. We accomplish this by
|
|
|
|
// using NLPs; however, sometimes the types are local to the file.
|
|
|
|
// We need to fill in the value for the NLP in those cases.
|
|
|
|
OutStreamer.EmitValue(
|
2015-05-30 09:25:56 +08:00
|
|
|
MCSymbolRefExpr::create(MCSym.getPointer(), OutStreamer.getContext()),
|
2014-04-29 18:06:05 +08:00
|
|
|
4 /*size*/);
|
|
|
|
}
|
|
|
|
|
2008-08-07 17:54:23 +08:00
|
|
|
|
2009-10-20 01:59:19 +08:00
|
|
|
void ARMAsmPrinter::EmitEndOfAsmFile(Module &M) {
|
2015-06-16 23:44:21 +08:00
|
|
|
const Triple &TT = TM.getTargetTriple();
|
2015-02-18 04:02:32 +08:00
|
|
|
if (TT.isOSBinFormatMachO()) {
|
2009-08-04 06:18:15 +08:00
|
|
|
// All darwin targets use mach-o.
|
2010-04-18 00:44:48 +08:00
|
|
|
const TargetLoweringObjectFileMachO &TLOFMacho =
|
|
|
|
static_cast<const TargetLoweringObjectFileMachO &>(getObjFileLowering());
|
2009-10-20 02:38:33 +08:00
|
|
|
MachineModuleInfoMachO &MMIMacho =
|
|
|
|
MMI->getObjFileInfo<MachineModuleInfoMachO>();
|
2009-09-04 09:38:51 +08:00
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
// Output non-lazy-pointers for external and common global variables.
|
2009-10-20 02:38:33 +08:00
|
|
|
MachineModuleInfoMachO::SymbolListTy Stubs = MMIMacho.GetGVStubList();
|
2010-03-11 06:34:10 +08:00
|
|
|
|
2009-10-20 02:38:33 +08:00
|
|
|
if (!Stubs.empty()) {
|
2009-08-10 09:39:42 +08:00
|
|
|
// Switch with ".non_lazy_symbol_pointer" directive.
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->SwitchSection(TLOFMacho.getNonLazySymbolPointerSection());
|
2009-08-11 02:01:34 +08:00
|
|
|
EmitAlignment(2);
|
2014-04-29 18:06:05 +08:00
|
|
|
|
|
|
|
for (auto &Stub : Stubs)
|
2015-04-25 03:11:51 +08:00
|
|
|
emitNonLazySymbolPointer(*OutStreamer, Stub.first, Stub.second);
|
2010-03-09 08:40:17 +08:00
|
|
|
|
|
|
|
Stubs.clear();
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->AddBlankLine();
|
2007-01-19 15:51:42 +08:00
|
|
|
}
|
|
|
|
|
2016-04-26 05:12:04 +08:00
|
|
|
Stubs = MMIMacho.GetThreadLocalGVStubList();
|
|
|
|
if (!Stubs.empty()) {
|
|
|
|
// Switch with ".non_lazy_symbol_pointer" directive.
|
|
|
|
OutStreamer->SwitchSection(TLOFMacho.getThreadLocalPointerSection());
|
|
|
|
EmitAlignment(2);
|
|
|
|
|
|
|
|
for (auto &Stub : Stubs)
|
|
|
|
emitNonLazySymbolPointer(*OutStreamer, Stub.first, Stub.second);
|
|
|
|
|
|
|
|
Stubs.clear();
|
|
|
|
OutStreamer->AddBlankLine();
|
|
|
|
}
|
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
// Funny Darwin hack: This flag tells the linker that no global symbols
|
|
|
|
// contain code that falls through to other global symbols (e.g. the obvious
|
|
|
|
// implementation of multiple entry points). If this doesn't occur, the
|
|
|
|
// linker can safely perform dead code stripping. Since LLVM never
|
|
|
|
// generates code that does this, it is always safe to set.
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitAssemblerFlag(MCAF_SubsectionsViaSymbols);
|
2006-07-27 19:38:51 +08:00
|
|
|
}
|
2015-12-07 22:22:39 +08:00
|
|
|
|
|
|
|
// The last attribute to be emitted is ABI_optimization_goals
|
|
|
|
MCTargetStreamer &TS = *OutStreamer->getTargetStreamer();
|
|
|
|
ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
|
|
|
|
|
2015-12-13 13:27:45 +08:00
|
|
|
if (OptimizationGoals > 0 &&
|
2016-06-25 05:14:33 +08:00
|
|
|
(Subtarget->isTargetAEABI() || Subtarget->isTargetGNUAEABI() ||
|
|
|
|
Subtarget->isTargetMuslAEABI()))
|
2015-12-07 22:22:39 +08:00
|
|
|
ATS.emitAttribute(ARMBuildAttrs::ABI_optimization_goals, OptimizationGoals);
|
|
|
|
OptimizationGoals = -1;
|
|
|
|
|
|
|
|
ATS.finishAttributeSection();
|
2006-05-15 06:18:28 +08:00
|
|
|
}
|
2008-08-17 21:55:10 +08:00
|
|
|
|
2010-10-07 06:36:46 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Helper routines for EmitStartOfAsmFile() and EmitEndOfAsmFile()
|
|
|
|
// FIXME:
|
|
|
|
// The following seem like one-off assembler flags, but they actually need
|
2010-10-07 06:46:47 +08:00
|
|
|
// to appear in the .ARM.attributes section in ELF.
|
2010-10-07 06:36:46 +08:00
|
|
|
// Instead of subclassing the MCELFStreamer, we do the work here.
|
|
|
|
|
2016-10-19 21:43:02 +08:00
|
|
|
// Returns true if all functions have the same function attribute value.
|
|
|
|
// It also returns true when the module has no functions.
|
|
|
|
static bool checkFunctionsAttributeConsistency(const Module &M, StringRef Attr,
|
|
|
|
StringRef Value) {
|
|
|
|
return !any_of(M, [&](const Function &F) {
|
|
|
|
return F.getFnAttribute(Attr).getValueAsString() != Value;
|
|
|
|
});
|
2016-09-03 03:51:34 +08:00
|
|
|
}
|
|
|
|
|
2010-10-07 06:36:46 +08:00
|
|
|
void ARMAsmPrinter::emitAttributes() {
|
2015-04-25 03:11:51 +08:00
|
|
|
MCTargetStreamer &TS = *OutStreamer->getTargetStreamer();
|
[arm] Implement eabi_attribute, cpu, and fpu directives.
This commit allows the ARM integrated assembler to parse
and assemble the code with .eabi_attribute, .cpu, and
.fpu directives.
To implement the feature, this commit moves the code from
AttrEmitter to ARMTargetStreamers, and several new test
cases related to cortex-m4, cortex-r5, and cortex-a15 are
added.
Besides, this commit also change the Subtarget->isFPOnlySP()
to Subtarget->hasD16() to match the usage of .fpu directive.
This commit changes the test cases:
* Several .eabi_attribute directives in
2010-09-29-mc-asm-header-test.ll are removed because the .fpu
directive already cover the functionality.
* In the Cortex-A15 test case, the value for
Tag_Advanced_SIMD_arch has be changed from 1 to 2,
which is more precise.
llvm-svn: 193524
2013-10-29 01:51:12 +08:00
|
|
|
ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
|
2010-10-07 06:46:47 +08:00
|
|
|
|
2015-01-05 21:12:17 +08:00
|
|
|
ATS.emitTextAttribute(ARMBuildAttrs::conformance, "2.09");
|
|
|
|
|
[arm] Implement eabi_attribute, cpu, and fpu directives.
This commit allows the ARM integrated assembler to parse
and assemble the code with .eabi_attribute, .cpu, and
.fpu directives.
To implement the feature, this commit moves the code from
AttrEmitter to ARMTargetStreamers, and several new test
cases related to cortex-m4, cortex-r5, and cortex-a15 are
added.
Besides, this commit also change the Subtarget->isFPOnlySP()
to Subtarget->hasD16() to match the usage of .fpu directive.
This commit changes the test cases:
* Several .eabi_attribute directives in
2010-09-29-mc-asm-header-test.ll are removed because the .fpu
directive already cover the functionality.
* In the Cortex-A15 test case, the value for
Tag_Advanced_SIMD_arch has be changed from 1 to 2,
which is more precise.
llvm-svn: 193524
2013-10-29 01:51:12 +08:00
|
|
|
ATS.switchVendor("aeabi");
|
2010-10-26 01:50:35 +08:00
|
|
|
|
2015-02-18 04:02:32 +08:00
|
|
|
// Compute ARM ELF Attributes based on the default subtarget that
|
|
|
|
// we'd have constructed. The existing ARM behavior isn't LTO clean
|
|
|
|
// anyhow.
|
|
|
|
// FIXME: For ifunc related functions we could iterate over and look
|
|
|
|
// for a feature string that doesn't match the default one.
|
2015-06-16 23:44:21 +08:00
|
|
|
const Triple &TT = TM.getTargetTriple();
|
2015-02-18 04:02:32 +08:00
|
|
|
StringRef CPU = TM.getTargetCPU();
|
|
|
|
StringRef FS = TM.getTargetFeatureString();
|
2015-09-16 00:17:27 +08:00
|
|
|
std::string ArchFS = ARM_MC::ParseARMTriple(TT, CPU);
|
2015-02-18 04:02:32 +08:00
|
|
|
if (!FS.empty()) {
|
|
|
|
if (!ArchFS.empty())
|
2015-03-30 23:42:36 +08:00
|
|
|
ArchFS = (Twine(ArchFS) + "," + FS).str();
|
2015-02-18 04:02:32 +08:00
|
|
|
else
|
|
|
|
ArchFS = FS;
|
|
|
|
}
|
|
|
|
const ARMBaseTargetMachine &ATM =
|
|
|
|
static_cast<const ARMBaseTargetMachine &>(TM);
|
|
|
|
const ARMSubtarget STI(TT, CPU, ArchFS, ATM, ATM.isLittleEndian());
|
|
|
|
|
[ARM] Add hardware build attributes in assembler
In the assembler, we should emit build attributes based on the target
selected with command-line options. This matches the GNU assembler's
behaviour. We only do this for build attributes which describe the
hardware that is expected to be available, not the ones that describe
ABI compatibility.
This is done by moving some of the attribute emission code to
ARMTargetStreamer, so that it can be shared between the assembly and
code-generation code paths. Since the assembler only creates a
MCSubtargetInfo, not an ARMSubtarget, the code had to be changed to
check raw features, and not use the convenience functions in
ARMSubtarget.
If different attributes are later specified using the .eabi_attribute
directive, then they will take precedence, as happens when the same
.eabi_attribute is specified twice.
This must be enabled by an option, because we don't want to do this when
parsing inline assembly. The attributes would match the ones emitted at
the start of the file, so wouldn't actually change the emitted object
file, but the extra directives would be added to every inline assembly
block when emitting assembly, which we'd like to avoid.
The majority of the changes in the build-attributes.ll test are just
re-ordering the directives, because the hardware attributes are now
emitted before the ABI ones. However, I did fix one bug which I spotted:
Tag_CPU_arch_profile was not being emitted for v6M.
Differential revision: https://reviews.llvm.org/D31812
llvm-svn: 300547
2017-04-18 20:52:35 +08:00
|
|
|
// Emit build attributes for the available hardware.
|
|
|
|
ATS.emitTargetAttributes(STI);
|
2010-10-07 06:36:46 +08:00
|
|
|
|
2016-08-08 23:28:31 +08:00
|
|
|
// RW data addressing.
|
2016-06-21 22:21:53 +08:00
|
|
|
if (isPositionIndependent()) {
|
2014-05-27 21:30:21 +08:00
|
|
|
ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_RW_data,
|
|
|
|
ARMBuildAttrs::AddressRWPCRel);
|
2016-08-08 23:28:31 +08:00
|
|
|
} else if (STI.isRWPI()) {
|
|
|
|
// RWPI specific attributes.
|
|
|
|
ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_RW_data,
|
|
|
|
ARMBuildAttrs::AddressRWSBRel);
|
|
|
|
}
|
|
|
|
|
|
|
|
// RO data addressing.
|
|
|
|
if (isPositionIndependent() || STI.isROPI()) {
|
2014-05-27 21:30:21 +08:00
|
|
|
ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_RO_data,
|
|
|
|
ARMBuildAttrs::AddressROPCRel);
|
2016-08-08 23:28:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// GOT use.
|
|
|
|
if (isPositionIndependent()) {
|
2014-05-27 21:30:21 +08:00
|
|
|
ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_GOT_use,
|
|
|
|
ARMBuildAttrs::AddressGOT);
|
|
|
|
} else {
|
|
|
|
ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_GOT_use,
|
|
|
|
ARMBuildAttrs::AddressDirect);
|
|
|
|
}
|
|
|
|
|
2016-08-31 22:17:38 +08:00
|
|
|
// Set FP Denormals.
|
2016-10-19 21:43:02 +08:00
|
|
|
if (checkFunctionsAttributeConsistency(*MMI->getModule(),
|
|
|
|
"denormal-fp-math",
|
|
|
|
"preserve-sign") ||
|
2016-10-04 16:03:36 +08:00
|
|
|
TM.Options.FPDenormalMode == FPDenormal::PreserveSign)
|
2016-09-03 03:51:34 +08:00
|
|
|
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,
|
|
|
|
ARMBuildAttrs::PreserveFPSign);
|
2016-10-19 21:43:02 +08:00
|
|
|
else if (checkFunctionsAttributeConsistency(*MMI->getModule(),
|
|
|
|
"denormal-fp-math",
|
|
|
|
"positive-zero") ||
|
2016-10-04 16:03:36 +08:00
|
|
|
TM.Options.FPDenormalMode == FPDenormal::PositiveZero)
|
2016-09-03 03:51:34 +08:00
|
|
|
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,
|
|
|
|
ARMBuildAttrs::PositiveZero);
|
2016-08-31 22:17:38 +08:00
|
|
|
else if (!TM.Options.UnsafeFPMath)
|
2014-12-02 16:22:29 +08:00
|
|
|
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,
|
|
|
|
ARMBuildAttrs::IEEEDenormals);
|
2016-08-31 22:17:38 +08:00
|
|
|
else {
|
2015-02-18 04:02:32 +08:00
|
|
|
if (!STI.hasVFP2()) {
|
2014-12-02 16:22:29 +08:00
|
|
|
// When the target doesn't have an FPU (by design or
|
|
|
|
// intention), the assumptions made on the software support
|
|
|
|
// mirror that of the equivalent hardware support *if it
|
|
|
|
// existed*. For v7 and better we indicate that denormals are
|
|
|
|
// flushed preserving sign, and for V6 we indicate that
|
|
|
|
// denormals are flushed to positive zero.
|
2015-02-18 04:02:32 +08:00
|
|
|
if (STI.hasV7Ops())
|
2014-12-02 16:22:29 +08:00
|
|
|
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,
|
|
|
|
ARMBuildAttrs::PreserveFPSign);
|
2015-02-18 04:02:32 +08:00
|
|
|
} else if (STI.hasVFP3()) {
|
2014-12-02 16:22:29 +08:00
|
|
|
// In VFPv4, VFPv4U, VFPv3, or VFPv3U, it is preserved. That is,
|
|
|
|
// the sign bit of the zero matches the sign bit of the input or
|
|
|
|
// result that is being flushed to zero.
|
|
|
|
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,
|
|
|
|
ARMBuildAttrs::PreserveFPSign);
|
|
|
|
}
|
|
|
|
// For VFPv2 implementations it is implementation defined as
|
|
|
|
// to whether denormals are flushed to positive zero or to
|
|
|
|
// whatever the sign of zero is (ARM v7AR ARM 2.7.5). Historically
|
|
|
|
// LLVM has chosen to flush this to positive zero (most likely for
|
|
|
|
// GCC compatibility), so that's the chosen value here (the
|
|
|
|
// absence of its emission implies zero).
|
2013-10-08 00:55:23 +08:00
|
|
|
}
|
2010-10-07 06:36:46 +08:00
|
|
|
|
2016-08-31 22:17:38 +08:00
|
|
|
// Set FP exceptions and rounding
|
2016-10-19 21:43:02 +08:00
|
|
|
if (checkFunctionsAttributeConsistency(*MMI->getModule(),
|
|
|
|
"no-trapping-math", "true") ||
|
2016-09-03 03:51:34 +08:00
|
|
|
TM.Options.NoTrappingFPMath)
|
2016-08-31 22:17:38 +08:00
|
|
|
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_exceptions,
|
|
|
|
ARMBuildAttrs::Not_Allowed);
|
|
|
|
else if (!TM.Options.UnsafeFPMath) {
|
|
|
|
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_exceptions, ARMBuildAttrs::Allowed);
|
|
|
|
|
|
|
|
// If the user has permitted this code to choose the IEEE 754
|
|
|
|
// rounding at run-time, emit the rounding attribute.
|
|
|
|
if (TM.Options.HonorSignDependentRoundingFPMathOption)
|
|
|
|
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_rounding, ARMBuildAttrs::Allowed);
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:22:47 +08:00
|
|
|
// TM.Options.NoInfsFPMath && TM.Options.NoNaNsFPMath is the
|
|
|
|
// equivalent of GCC's -ffinite-math-only flag.
|
2013-10-12 00:03:43 +08:00
|
|
|
if (TM.Options.NoInfsFPMath && TM.Options.NoNaNsFPMath)
|
[arm] Implement eabi_attribute, cpu, and fpu directives.
This commit allows the ARM integrated assembler to parse
and assemble the code with .eabi_attribute, .cpu, and
.fpu directives.
To implement the feature, this commit moves the code from
AttrEmitter to ARMTargetStreamers, and several new test
cases related to cortex-m4, cortex-r5, and cortex-a15 are
added.
Besides, this commit also change the Subtarget->isFPOnlySP()
to Subtarget->hasD16() to match the usage of .fpu directive.
This commit changes the test cases:
* Several .eabi_attribute directives in
2010-09-29-mc-asm-header-test.ll are removed because the .fpu
directive already cover the functionality.
* In the Cortex-A15 test case, the value for
Tag_Advanced_SIMD_arch has be changed from 1 to 2,
which is more precise.
llvm-svn: 193524
2013-10-29 01:51:12 +08:00
|
|
|
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_number_model,
|
|
|
|
ARMBuildAttrs::Allowed);
|
2013-10-12 00:03:43 +08:00
|
|
|
else
|
[arm] Implement eabi_attribute, cpu, and fpu directives.
This commit allows the ARM integrated assembler to parse
and assemble the code with .eabi_attribute, .cpu, and
.fpu directives.
To implement the feature, this commit moves the code from
AttrEmitter to ARMTargetStreamers, and several new test
cases related to cortex-m4, cortex-r5, and cortex-a15 are
added.
Besides, this commit also change the Subtarget->isFPOnlySP()
to Subtarget->hasD16() to match the usage of .fpu directive.
This commit changes the test cases:
* Several .eabi_attribute directives in
2010-09-29-mc-asm-header-test.ll are removed because the .fpu
directive already cover the functionality.
* In the Cortex-A15 test case, the value for
Tag_Advanced_SIMD_arch has be changed from 1 to 2,
which is more precise.
llvm-svn: 193524
2013-10-29 01:51:12 +08:00
|
|
|
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_number_model,
|
2017-01-18 21:52:12 +08:00
|
|
|
ARMBuildAttrs::AllowIEEE754);
|
2013-10-12 00:03:43 +08:00
|
|
|
|
2014-01-19 16:25:27 +08:00
|
|
|
// FIXME: add more flags to ARMBuildAttributes.h
|
2010-10-07 06:36:46 +08:00
|
|
|
// 8-bytes alignment stuff.
|
2014-01-19 16:25:35 +08:00
|
|
|
ATS.emitAttribute(ARMBuildAttrs::ABI_align_needed, 1);
|
|
|
|
ATS.emitAttribute(ARMBuildAttrs::ABI_align_preserved, 1);
|
2010-10-07 06:36:46 +08:00
|
|
|
|
|
|
|
// Hard float. Use both S and D registers and conform to AAPCS-VFP.
|
2015-02-18 04:02:32 +08:00
|
|
|
if (STI.isAAPCS_ABI() && TM.Options.FloatABIType == FloatABI::Hard)
|
2013-11-01 19:21:16 +08:00
|
|
|
ATS.emitAttribute(ARMBuildAttrs::ABI_VFP_args, ARMBuildAttrs::HardFPAAPCS);
|
|
|
|
|
2014-12-12 19:59:18 +08:00
|
|
|
// FIXME: To support emitting this build attribute as GCC does, the
|
|
|
|
// -mfp16-format option and associated plumbing must be
|
|
|
|
// supported. For now the __fp16 type is exposed by default, so this
|
|
|
|
// attribute should be emitted with value 1.
|
|
|
|
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_16bit_format,
|
|
|
|
ARMBuildAttrs::FP16FormatIEEE);
|
|
|
|
|
2014-06-20 18:08:11 +08:00
|
|
|
if (MMI) {
|
|
|
|
if (const Module *SourceModule = MMI->getModule()) {
|
|
|
|
// ABI_PCS_wchar_t to indicate wchar_t width
|
|
|
|
// FIXME: There is no way to emit value 0 (wchar_t prohibited).
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
if (auto WCharWidthValue = mdconst::extract_or_null<ConstantInt>(
|
2014-06-20 18:08:11 +08:00
|
|
|
SourceModule->getModuleFlag("wchar_size"))) {
|
|
|
|
int WCharWidth = WCharWidthValue->getZExtValue();
|
|
|
|
assert((WCharWidth == 2 || WCharWidth == 4) &&
|
|
|
|
"wchar_t width must be 2 or 4 bytes");
|
|
|
|
ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_wchar_t, WCharWidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ABI_enum_size to indicate enum width
|
|
|
|
// FIXME: There is no way to emit value 0 (enums prohibited) or value 3
|
|
|
|
// (all enums contain a value needing 32 bits to encode).
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
if (auto EnumWidthValue = mdconst::extract_or_null<ConstantInt>(
|
2014-06-20 18:08:11 +08:00
|
|
|
SourceModule->getModuleFlag("min_enum_size"))) {
|
|
|
|
int EnumWidth = EnumWidthValue->getZExtValue();
|
|
|
|
assert((EnumWidth == 1 || EnumWidth == 4) &&
|
|
|
|
"Minimum enum width must be 1 or 4 bytes");
|
|
|
|
int EnumBuildAttr = EnumWidth == 1 ? 1 : 2;
|
|
|
|
ATS.emitAttribute(ARMBuildAttrs::ABI_enum_size, EnumBuildAttr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-08 23:28:31 +08:00
|
|
|
// We currently do not support using R9 as the TLS pointer.
|
|
|
|
if (STI.isRWPI())
|
|
|
|
ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_R9_use,
|
|
|
|
ARMBuildAttrs::R9IsSB);
|
|
|
|
else if (STI.isR9Reserved())
|
|
|
|
ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_R9_use,
|
|
|
|
ARMBuildAttrs::R9Reserved);
|
2014-07-25 22:03:14 +08:00
|
|
|
else
|
2016-08-08 23:28:31 +08:00
|
|
|
ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_R9_use,
|
|
|
|
ARMBuildAttrs::R9IsGPR);
|
2010-10-07 06:36:46 +08:00
|
|
|
}
|
|
|
|
|
2009-10-20 04:20:46 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-10-01 13:57:55 +08:00
|
|
|
static MCSymbol *getPICLabel(StringRef Prefix, unsigned FunctionNumber,
|
2010-09-18 08:05:05 +08:00
|
|
|
unsigned LabelId, MCContext &Ctx) {
|
|
|
|
|
2015-05-19 02:43:14 +08:00
|
|
|
MCSymbol *Label = Ctx.getOrCreateSymbol(Twine(Prefix)
|
2010-09-18 08:05:05 +08:00
|
|
|
+ "PC" + Twine(FunctionNumber) + "_" + Twine(LabelId));
|
|
|
|
return Label;
|
|
|
|
}
|
|
|
|
|
2010-11-10 11:26:07 +08:00
|
|
|
static MCSymbolRefExpr::VariantKind
|
|
|
|
getModifierVariantKind(ARMCP::ARMCPModifier Modifier) {
|
|
|
|
switch (Modifier) {
|
2016-06-07 11:15:01 +08:00
|
|
|
case ARMCP::no_modifier:
|
|
|
|
return MCSymbolRefExpr::VK_None;
|
|
|
|
case ARMCP::TLSGD:
|
|
|
|
return MCSymbolRefExpr::VK_TLSGD;
|
|
|
|
case ARMCP::TPOFF:
|
|
|
|
return MCSymbolRefExpr::VK_TPOFF;
|
|
|
|
case ARMCP::GOTTPOFF:
|
|
|
|
return MCSymbolRefExpr::VK_GOTTPOFF;
|
2016-08-08 23:28:31 +08:00
|
|
|
case ARMCP::SBREL:
|
|
|
|
return MCSymbolRefExpr::VK_ARM_SBREL;
|
2016-06-07 11:15:01 +08:00
|
|
|
case ARMCP::GOT_PREL:
|
|
|
|
return MCSymbolRefExpr::VK_ARM_GOT_PREL;
|
2016-06-07 11:15:07 +08:00
|
|
|
case ARMCP::SECREL:
|
|
|
|
return MCSymbolRefExpr::VK_SECREL;
|
2010-11-10 11:26:07 +08:00
|
|
|
}
|
2012-01-21 05:51:11 +08:00
|
|
|
llvm_unreachable("Invalid ARMCPModifier!");
|
2010-11-10 11:26:07 +08:00
|
|
|
}
|
|
|
|
|
2013-11-26 00:24:52 +08:00
|
|
|
MCSymbol *ARMAsmPrinter::GetARMGVSymbol(const GlobalValue *GV,
|
|
|
|
unsigned char TargetFlags) {
|
2014-07-07 13:18:30 +08:00
|
|
|
if (Subtarget->isTargetMachO()) {
|
2016-06-28 23:38:13 +08:00
|
|
|
bool IsIndirect =
|
|
|
|
(TargetFlags & ARMII::MO_NONLAZY) && Subtarget->isGVIndirectSymbol(GV);
|
2014-07-07 13:18:30 +08:00
|
|
|
|
|
|
|
if (!IsIndirect)
|
|
|
|
return getSymbol(GV);
|
2011-01-17 16:03:18 +08:00
|
|
|
|
2014-07-07 13:18:30 +08:00
|
|
|
// FIXME: Remove this when Darwin transition to @GOT like syntax.
|
|
|
|
MCSymbol *MCSym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
|
|
|
|
MachineModuleInfoMachO &MMIMachO =
|
|
|
|
MMI->getObjFileInfo<MachineModuleInfoMachO>();
|
|
|
|
MachineModuleInfoImpl::StubValueTy &StubSym =
|
2016-05-18 00:01:32 +08:00
|
|
|
GV->isThreadLocal() ? MMIMachO.getThreadLocalGVStubEntry(MCSym)
|
|
|
|
: MMIMachO.getGVStubEntry(MCSym);
|
2016-04-26 05:12:04 +08:00
|
|
|
|
2014-07-07 13:18:30 +08:00
|
|
|
if (!StubSym.getPointer())
|
|
|
|
StubSym = MachineModuleInfoImpl::StubValueTy(getSymbol(GV),
|
|
|
|
!GV->hasInternalLinkage());
|
|
|
|
return MCSym;
|
|
|
|
} else if (Subtarget->isTargetCOFF()) {
|
|
|
|
assert(Subtarget->isTargetWindows() &&
|
|
|
|
"Windows is the only supported COFF target");
|
2015-06-11 09:31:48 +08:00
|
|
|
|
|
|
|
bool IsIndirect = (TargetFlags & ARMII::MO_DLLIMPORT);
|
|
|
|
if (!IsIndirect)
|
|
|
|
return getSymbol(GV);
|
|
|
|
|
|
|
|
SmallString<128> Name;
|
|
|
|
Name = "__imp_";
|
|
|
|
getNameWithPrefix(Name, GV);
|
|
|
|
|
|
|
|
return OutContext.getOrCreateSymbol(Name);
|
2014-07-07 13:18:30 +08:00
|
|
|
} else if (Subtarget->isTargetELF()) {
|
|
|
|
return getSymbol(GV);
|
|
|
|
}
|
|
|
|
llvm_unreachable("unexpected target");
|
2011-01-17 16:03:18 +08:00
|
|
|
}
|
|
|
|
|
2010-11-10 02:45:04 +08:00
|
|
|
void ARMAsmPrinter::
|
|
|
|
EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) {
|
2015-07-16 14:11:10 +08:00
|
|
|
const DataLayout &DL = getDataLayout();
|
|
|
|
int Size = DL.getTypeAllocSize(MCPV->getType());
|
2010-11-10 02:45:04 +08:00
|
|
|
|
|
|
|
ARMConstantPoolValue *ACPV = static_cast<ARMConstantPoolValue*>(MCPV);
|
|
|
|
|
2016-09-26 15:26:24 +08:00
|
|
|
if (ACPV->isPromotedGlobal()) {
|
|
|
|
// This constant pool entry is actually a global whose storage has been
|
|
|
|
// promoted into the constant pool. This global may be referenced still
|
|
|
|
// by debug information, and due to the way AsmPrinter is set up, the debug
|
|
|
|
// info is immutable by the time we decide to promote globals to constant
|
|
|
|
// pools. Because of this, we need to ensure we emit a symbol for the global
|
|
|
|
// with private linkage (the default) so debug info can refer to it.
|
|
|
|
//
|
|
|
|
// However, if this global is promoted into several functions we must ensure
|
|
|
|
// we don't try and emit duplicate symbols!
|
|
|
|
auto *ACPC = cast<ARMConstantPoolConstant>(ACPV);
|
2017-09-07 12:00:13 +08:00
|
|
|
for (const auto *GV : ACPC->promotedGlobals()) {
|
|
|
|
if (!EmittedPromotedGlobalLabels.count(GV)) {
|
|
|
|
MCSymbol *GVSym = getSymbol(GV);
|
|
|
|
OutStreamer->EmitLabel(GVSym);
|
|
|
|
EmittedPromotedGlobalLabels.insert(GV);
|
|
|
|
}
|
2016-09-26 15:26:24 +08:00
|
|
|
}
|
|
|
|
return EmitGlobalConstant(DL, ACPC->getPromotedGlobalInit());
|
|
|
|
}
|
|
|
|
|
2010-11-11 01:59:10 +08:00
|
|
|
MCSymbol *MCSym;
|
2010-11-10 02:45:04 +08:00
|
|
|
if (ACPV->isLSDA()) {
|
2015-03-17 21:57:48 +08:00
|
|
|
MCSym = getCurExceptionSym();
|
2010-11-10 02:45:04 +08:00
|
|
|
} else if (ACPV->isBlockAddress()) {
|
2011-10-01 16:00:54 +08:00
|
|
|
const BlockAddress *BA =
|
|
|
|
cast<ARMConstantPoolConstant>(ACPV)->getBlockAddress();
|
|
|
|
MCSym = GetBlockAddressSymbol(BA);
|
2010-11-10 02:45:04 +08:00
|
|
|
} else if (ACPV->isGlobalValue()) {
|
2011-10-01 16:00:54 +08:00
|
|
|
const GlobalValue *GV = cast<ARMConstantPoolConstant>(ACPV)->getGV();
|
2013-11-26 00:24:52 +08:00
|
|
|
|
|
|
|
// On Darwin, const-pool entries may get the "FOO$non_lazy_ptr" mangling, so
|
|
|
|
// flag the global as MO_NONLAZY.
|
2014-01-06 22:28:05 +08:00
|
|
|
unsigned char TF = Subtarget->isTargetMachO() ? ARMII::MO_NONLAZY : 0;
|
2013-11-26 01:04:35 +08:00
|
|
|
MCSym = GetARMGVSymbol(GV, TF);
|
2011-09-30 07:50:42 +08:00
|
|
|
} else if (ACPV->isMachineBasicBlock()) {
|
2011-10-01 17:30:42 +08:00
|
|
|
const MachineBasicBlock *MBB = cast<ARMConstantPoolMBB>(ACPV)->getMBB();
|
2011-09-30 07:50:42 +08:00
|
|
|
MCSym = MBB->getSymbol();
|
2010-11-10 02:45:04 +08:00
|
|
|
} else {
|
|
|
|
assert(ACPV->isExtSymbol() && "unrecognized constant pool value");
|
2016-10-05 09:41:06 +08:00
|
|
|
auto Sym = cast<ARMConstantPoolSymbol>(ACPV)->getSymbol();
|
2011-10-01 16:58:29 +08:00
|
|
|
MCSym = GetExternalSymbolSymbol(Sym);
|
2010-11-10 02:45:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create an MCSymbol for the reference.
|
2010-11-10 11:26:07 +08:00
|
|
|
const MCExpr *Expr =
|
2015-05-30 09:25:56 +08:00
|
|
|
MCSymbolRefExpr::create(MCSym, getModifierVariantKind(ACPV->getModifier()),
|
2010-11-10 11:26:07 +08:00
|
|
|
OutContext);
|
|
|
|
|
|
|
|
if (ACPV->getPCAdjustment()) {
|
2015-07-16 14:11:10 +08:00
|
|
|
MCSymbol *PCLabel =
|
|
|
|
getPICLabel(DL.getPrivateGlobalPrefix(), getFunctionNumber(),
|
|
|
|
ACPV->getLabelId(), OutContext);
|
2015-05-30 09:25:56 +08:00
|
|
|
const MCExpr *PCRelExpr = MCSymbolRefExpr::create(PCLabel, OutContext);
|
2010-11-10 11:26:07 +08:00
|
|
|
PCRelExpr =
|
2015-05-30 09:25:56 +08:00
|
|
|
MCBinaryExpr::createAdd(PCRelExpr,
|
|
|
|
MCConstantExpr::create(ACPV->getPCAdjustment(),
|
2010-11-10 11:26:07 +08:00
|
|
|
OutContext),
|
|
|
|
OutContext);
|
|
|
|
if (ACPV->mustAddCurrentAddress()) {
|
|
|
|
// We want "(<expr> - .)", but MC doesn't have a concept of the '.'
|
|
|
|
// label, so just emit a local label end reference that instead.
|
2015-05-19 02:43:14 +08:00
|
|
|
MCSymbol *DotSym = OutContext.createTempSymbol();
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitLabel(DotSym);
|
2015-05-30 09:25:56 +08:00
|
|
|
const MCExpr *DotExpr = MCSymbolRefExpr::create(DotSym, OutContext);
|
|
|
|
PCRelExpr = MCBinaryExpr::createSub(PCRelExpr, DotExpr, OutContext);
|
2010-11-10 02:45:04 +08:00
|
|
|
}
|
2015-05-30 09:25:56 +08:00
|
|
|
Expr = MCBinaryExpr::createSub(Expr, PCRelExpr, OutContext);
|
2010-11-10 02:45:04 +08:00
|
|
|
}
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitValue(Expr, Size);
|
2010-11-10 02:45:04 +08:00
|
|
|
}
|
|
|
|
|
2015-06-01 03:22:07 +08:00
|
|
|
void ARMAsmPrinter::EmitJumpTableAddrs(const MachineInstr *MI) {
|
|
|
|
const MachineOperand &MO1 = MI->getOperand(1);
|
2010-09-23 01:39:48 +08:00
|
|
|
unsigned JTI = MO1.getIndex();
|
|
|
|
|
2015-06-01 03:22:07 +08:00
|
|
|
// Make sure the Thumb jump table is 4-byte aligned. This will be a nop for
|
|
|
|
// ARM mode tables.
|
|
|
|
EmitAlignment(2);
|
|
|
|
|
2010-09-23 01:39:48 +08:00
|
|
|
// Emit a label for the jump table.
|
2015-05-14 04:28:38 +08:00
|
|
|
MCSymbol *JTISymbol = GetARMJTIPICJumpTableLabel(JTI);
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitLabel(JTISymbol);
|
2010-09-23 01:39:48 +08:00
|
|
|
|
2012-05-19 03:12:01 +08:00
|
|
|
// Mark the jump table as data-in-code.
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitDataRegion(MCDR_DataRegionJT32);
|
2012-05-19 03:12:01 +08:00
|
|
|
|
2010-09-23 01:39:48 +08:00
|
|
|
// Emit each entry of the table.
|
|
|
|
const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo();
|
|
|
|
const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
|
|
|
|
const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs;
|
|
|
|
|
2017-08-29 18:04:18 +08:00
|
|
|
for (MachineBasicBlock *MBB : JTBBs) {
|
2010-09-23 01:39:48 +08:00
|
|
|
// Construct an MCExpr for the entry. We want a value of the form:
|
|
|
|
// (BasicBlockAddr - TableBeginAddr)
|
|
|
|
//
|
|
|
|
// For example, a table with entries jumping to basic blocks BB0 and BB1
|
|
|
|
// would look like:
|
|
|
|
// LJTI_0_0:
|
|
|
|
// .word (LBB0 - LJTI_0_0)
|
|
|
|
// .word (LBB1 - LJTI_0_0)
|
2015-05-30 09:25:56 +08:00
|
|
|
const MCExpr *Expr = MCSymbolRefExpr::create(MBB->getSymbol(), OutContext);
|
2010-09-23 01:39:48 +08:00
|
|
|
|
2016-08-08 23:28:31 +08:00
|
|
|
if (isPositionIndependent() || Subtarget->isROPI())
|
2015-05-30 09:25:56 +08:00
|
|
|
Expr = MCBinaryExpr::createSub(Expr, MCSymbolRefExpr::create(JTISymbol,
|
2010-09-23 01:39:48 +08:00
|
|
|
OutContext),
|
|
|
|
OutContext);
|
2011-09-01 06:23:09 +08:00
|
|
|
// If we're generating a table of Thumb addresses in static relocation
|
|
|
|
// model, we need to add one to keep interworking correctly.
|
|
|
|
else if (AFI->isThumbFunction())
|
2015-05-30 09:25:56 +08:00
|
|
|
Expr = MCBinaryExpr::createAdd(Expr, MCConstantExpr::create(1,OutContext),
|
2011-09-01 06:23:09 +08:00
|
|
|
OutContext);
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitValue(Expr, 4);
|
2010-09-23 01:39:48 +08:00
|
|
|
}
|
2012-05-19 03:12:01 +08:00
|
|
|
// Mark the end of jump table data-in-code region.
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitDataRegion(MCDR_DataRegionEnd);
|
2010-09-23 01:39:48 +08:00
|
|
|
}
|
|
|
|
|
2015-06-01 03:22:07 +08:00
|
|
|
void ARMAsmPrinter::EmitJumpTableInsts(const MachineInstr *MI) {
|
|
|
|
const MachineOperand &MO1 = MI->getOperand(1);
|
2010-09-22 07:28:16 +08:00
|
|
|
unsigned JTI = MO1.getIndex();
|
|
|
|
|
2017-02-13 22:07:45 +08:00
|
|
|
// Make sure the Thumb jump table is 4-byte aligned. This will be a nop for
|
|
|
|
// ARM mode tables.
|
|
|
|
EmitAlignment(2);
|
|
|
|
|
|
|
|
// Emit a label for the jump table.
|
2015-05-14 04:28:38 +08:00
|
|
|
MCSymbol *JTISymbol = GetARMJTIPICJumpTableLabel(JTI);
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitLabel(JTISymbol);
|
2010-09-22 07:28:16 +08:00
|
|
|
|
|
|
|
// Emit each entry of the table.
|
|
|
|
const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo();
|
|
|
|
const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
|
|
|
|
const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs;
|
|
|
|
|
2017-08-29 18:04:18 +08:00
|
|
|
for (MachineBasicBlock *MBB : JTBBs) {
|
2015-05-30 09:25:56 +08:00
|
|
|
const MCExpr *MBBSymbolExpr = MCSymbolRefExpr::create(MBB->getSymbol(),
|
2014-07-07 13:18:22 +08:00
|
|
|
OutContext);
|
2010-09-22 07:28:16 +08:00
|
|
|
// If this isn't a TBB or TBH, the entries are direct branch instructions.
|
2015-06-01 03:22:07 +08:00
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::t2B)
|
2012-11-26 21:34:22 +08:00
|
|
|
.addExpr(MBBSymbolExpr)
|
|
|
|
.addImm(ARMCC::AL)
|
2012-11-27 02:05:52 +08:00
|
|
|
.addReg(0));
|
2015-06-01 03:22:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARMAsmPrinter::EmitJumpTableTBInst(const MachineInstr *MI,
|
|
|
|
unsigned OffsetWidth) {
|
|
|
|
assert((OffsetWidth == 1 || OffsetWidth == 2) && "invalid tbb/tbh width");
|
|
|
|
const MachineOperand &MO1 = MI->getOperand(1);
|
|
|
|
unsigned JTI = MO1.getIndex();
|
|
|
|
|
[Thumb-1] Synthesize TBB/TBH instructions to make use of compressed jump tables
[Reapplying r284580 and r285917 with fix and testing to ensure emitted jump tables for Thumb-1 have 4-byte alignment]
The TBB and TBH instructions in Thumb-2 allow jump tables to be compressed into sequences of bytes or shorts respectively. These instructions do not exist in Thumb-1, however it is possible to synthesize them out of a sequence of other instructions.
It turns out this sequence is so short that it's almost never a lose for performance and is ALWAYS a significant win for code size.
TBB example:
Before: lsls r0, r0, #2 After: add r0, pc
adr r1, .LJTI0_0 ldrb r0, [r0, #6]
ldr r0, [r0, r1] lsls r0, r0, #1
mov pc, r0 add pc, r0
=> No change in prologue code size or dynamic instruction count. Jump table shrunk by a factor of 4.
The only case that can increase dynamic instruction count is the TBH case:
Before: lsls r0, r4, #2 After: lsls r4, r4, #1
adr r1, .LJTI0_0 add r4, pc
ldr r0, [r0, r1] ldrh r4, [r4, #6]
mov pc, r0 lsls r4, r4, #1
add pc, r4
=> 1 more instruction in prologue. Jump table shrunk by a factor of 2.
So there is an argument that this should be disabled when optimizing for performance (and a TBH needs to be generated). I'm not so sure about that in practice, because on small cores with Thumb-1 performance is often tied to code size. But I'm willing to turn it off when optimizing for performance if people want (also note that TBHs are fairly rare in practice!)
llvm-svn: 285690
2016-11-01 21:37:41 +08:00
|
|
|
if (Subtarget->isThumb1Only())
|
|
|
|
EmitAlignment(2);
|
|
|
|
|
2015-06-01 03:22:07 +08:00
|
|
|
MCSymbol *JTISymbol = GetARMJTIPICJumpTableLabel(JTI);
|
|
|
|
OutStreamer->EmitLabel(JTISymbol);
|
|
|
|
|
|
|
|
// Emit each entry of the table.
|
|
|
|
const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo();
|
|
|
|
const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
|
|
|
|
const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs;
|
|
|
|
|
|
|
|
// Mark the jump table as data-in-code.
|
|
|
|
OutStreamer->EmitDataRegion(OffsetWidth == 1 ? MCDR_DataRegionJT8
|
|
|
|
: MCDR_DataRegionJT16);
|
|
|
|
|
|
|
|
for (auto MBB : JTBBs) {
|
|
|
|
const MCExpr *MBBSymbolExpr = MCSymbolRefExpr::create(MBB->getSymbol(),
|
|
|
|
OutContext);
|
2010-09-22 07:28:16 +08:00
|
|
|
// Otherwise it's an offset from the dispatch instruction. Construct an
|
2010-09-23 01:15:35 +08:00
|
|
|
// MCExpr for the entry. We want a value of the form:
|
2015-06-01 03:22:07 +08:00
|
|
|
// (BasicBlockAddr - TBBInstAddr + 4) / 2
|
2010-09-23 01:15:35 +08:00
|
|
|
//
|
|
|
|
// For example, a TBB table with entries jumping to basic blocks BB0 and BB1
|
|
|
|
// would look like:
|
|
|
|
// LJTI_0_0:
|
2015-06-01 03:22:07 +08:00
|
|
|
// .byte (LBB0 - (LCPI0_0 + 4)) / 2
|
|
|
|
// .byte (LBB1 - (LCPI0_0 + 4)) / 2
|
|
|
|
// where LCPI0_0 is a label defined just before the TBB instruction using
|
|
|
|
// this table.
|
|
|
|
MCSymbol *TBInstPC = GetCPISymbol(MI->getOperand(0).getImm());
|
|
|
|
const MCExpr *Expr = MCBinaryExpr::createAdd(
|
|
|
|
MCSymbolRefExpr::create(TBInstPC, OutContext),
|
|
|
|
MCConstantExpr::create(4, OutContext), OutContext);
|
|
|
|
Expr = MCBinaryExpr::createSub(MBBSymbolExpr, Expr, OutContext);
|
2015-05-30 09:25:56 +08:00
|
|
|
Expr = MCBinaryExpr::createDiv(Expr, MCConstantExpr::create(2, OutContext),
|
2010-09-23 01:15:35 +08:00
|
|
|
OutContext);
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitValue(Expr, OffsetWidth);
|
2010-09-22 07:28:16 +08:00
|
|
|
}
|
2012-05-22 07:34:42 +08:00
|
|
|
// Mark the end of jump table data-in-code region. 32-bit offsets use
|
|
|
|
// actual branch instructions here, so we don't mark those as a data-region
|
|
|
|
// at all.
|
2015-06-01 03:22:07 +08:00
|
|
|
OutStreamer->EmitDataRegion(MCDR_DataRegionEnd);
|
|
|
|
|
|
|
|
// Make sure the next instruction is 2-byte aligned.
|
|
|
|
EmitAlignment(1);
|
2010-09-22 07:28:16 +08:00
|
|
|
}
|
|
|
|
|
2011-03-06 02:43:32 +08:00
|
|
|
void ARMAsmPrinter::EmitUnwindingInstruction(const MachineInstr *MI) {
|
|
|
|
assert(MI->getFlag(MachineInstr::FrameSetup) &&
|
|
|
|
"Only instruction which are involved into frame setup code are allowed");
|
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
MCTargetStreamer &TS = *OutStreamer->getTargetStreamer();
|
2013-10-08 21:08:17 +08:00
|
|
|
ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
|
2011-03-06 02:43:32 +08:00
|
|
|
const MachineFunction &MF = *MI->getParent()->getParent();
|
2014-08-05 10:39:49 +08:00
|
|
|
const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo();
|
2011-03-06 02:43:55 +08:00
|
|
|
const ARMFunctionInfo &AFI = *MF.getInfo<ARMFunctionInfo>();
|
2011-03-06 02:43:32 +08:00
|
|
|
|
|
|
|
unsigned FramePtr = RegInfo->getFrameRegister(MF);
|
|
|
|
unsigned Opc = MI->getOpcode();
|
2011-03-06 02:43:43 +08:00
|
|
|
unsigned SrcReg, DstReg;
|
|
|
|
|
2011-03-06 02:43:50 +08:00
|
|
|
if (Opc == ARM::tPUSH || Opc == ARM::tLDRpci) {
|
|
|
|
// Two special cases:
|
|
|
|
// 1) tPUSH does not have src/dst regs.
|
|
|
|
// 2) for Thumb1 code we sometimes materialize the constant via constpool
|
|
|
|
// load. Yes, this is pretty fragile, but for now I don't see better
|
|
|
|
// way... :(
|
2011-03-06 02:43:43 +08:00
|
|
|
SrcReg = DstReg = ARM::SP;
|
|
|
|
} else {
|
2011-03-06 02:43:50 +08:00
|
|
|
SrcReg = MI->getOperand(1).getReg();
|
2011-03-06 02:43:43 +08:00
|
|
|
DstReg = MI->getOperand(0).getReg();
|
|
|
|
}
|
2011-03-06 02:43:32 +08:00
|
|
|
|
|
|
|
// Try to figure out the unwinding opcode out of src / dst regs.
|
2011-12-07 15:15:52 +08:00
|
|
|
if (MI->mayStore()) {
|
2011-03-06 02:43:32 +08:00
|
|
|
// Register saves.
|
|
|
|
assert(DstReg == ARM::SP &&
|
|
|
|
"Only stack pointer as a destination reg is supported");
|
|
|
|
|
|
|
|
SmallVector<unsigned, 4> RegList;
|
2011-03-06 02:43:43 +08:00
|
|
|
// Skip src & dst reg, and pred ops.
|
|
|
|
unsigned StartOp = 2 + 2;
|
|
|
|
// Use all the operands.
|
|
|
|
unsigned NumOffset = 0;
|
2018-01-08 22:47:19 +08:00
|
|
|
// Amount of SP adjustment folded into a push.
|
|
|
|
unsigned Pad = 0;
|
2011-03-06 02:43:43 +08:00
|
|
|
|
2011-03-06 02:43:32 +08:00
|
|
|
switch (Opc) {
|
|
|
|
default:
|
2017-01-28 10:02:38 +08:00
|
|
|
MI->print(errs());
|
2012-02-07 10:50:20 +08:00
|
|
|
llvm_unreachable("Unsupported opcode for unwinding information");
|
2011-03-06 02:43:43 +08:00
|
|
|
case ARM::tPUSH:
|
|
|
|
// Special case here: no src & dst reg, but two extra imp ops.
|
|
|
|
StartOp = 2; NumOffset = 2;
|
2017-07-09 02:42:04 +08:00
|
|
|
LLVM_FALLTHROUGH;
|
2011-03-06 02:43:32 +08:00
|
|
|
case ARM::STMDB_UPD:
|
2011-03-06 02:43:43 +08:00
|
|
|
case ARM::t2STMDB_UPD:
|
2011-03-06 02:43:32 +08:00
|
|
|
case ARM::VSTMDDB_UPD:
|
|
|
|
assert(SrcReg == ARM::SP &&
|
|
|
|
"Only stack pointer as a source reg is supported");
|
2011-03-06 02:43:43 +08:00
|
|
|
for (unsigned i = StartOp, NumOps = MI->getNumOperands() - NumOffset;
|
2012-08-04 21:25:58 +08:00
|
|
|
i != NumOps; ++i) {
|
|
|
|
const MachineOperand &MO = MI->getOperand(i);
|
|
|
|
// Actually, there should never be any impdef stuff here. Skip it
|
|
|
|
// temporary to workaround PR11902.
|
|
|
|
if (MO.isImplicit())
|
|
|
|
continue;
|
2018-01-08 22:47:19 +08:00
|
|
|
// Registers, pushed as a part of folding an SP update into the
|
|
|
|
// push instruction are marked as undef and should not be
|
|
|
|
// restored when unwinding, because the function can modify the
|
|
|
|
// corresponding stack slots.
|
|
|
|
if (MO.isUndef()) {
|
|
|
|
assert(RegList.empty() &&
|
|
|
|
"Pad registers must come before restored ones");
|
|
|
|
Pad += 4;
|
|
|
|
continue;
|
|
|
|
}
|
2012-08-04 21:25:58 +08:00
|
|
|
RegList.push_back(MO.getReg());
|
|
|
|
}
|
2011-03-06 02:43:32 +08:00
|
|
|
break;
|
2011-07-27 04:54:26 +08:00
|
|
|
case ARM::STR_PRE_IMM:
|
|
|
|
case ARM::STR_PRE_REG:
|
2012-01-19 20:53:06 +08:00
|
|
|
case ARM::t2STR_PRE:
|
2011-03-06 02:43:32 +08:00
|
|
|
assert(MI->getOperand(2).getReg() == ARM::SP &&
|
|
|
|
"Only stack pointer as a source reg is supported");
|
|
|
|
RegList.push_back(SrcReg);
|
|
|
|
break;
|
|
|
|
}
|
2018-01-08 22:47:19 +08:00
|
|
|
if (MAI->getExceptionHandlingType() == ExceptionHandling::ARM) {
|
2014-05-01 06:43:13 +08:00
|
|
|
ATS.emitRegSave(RegList, Opc == ARM::VSTMDDB_UPD);
|
2018-01-08 22:47:19 +08:00
|
|
|
// Account for the SP adjustment, folded into the push.
|
|
|
|
if (Pad)
|
|
|
|
ATS.emitPad(Pad);
|
|
|
|
}
|
2011-03-06 02:43:32 +08:00
|
|
|
} else {
|
|
|
|
// Changes of stack / frame pointer.
|
|
|
|
if (SrcReg == ARM::SP) {
|
|
|
|
int64_t Offset = 0;
|
|
|
|
switch (Opc) {
|
|
|
|
default:
|
2017-01-28 10:02:38 +08:00
|
|
|
MI->print(errs());
|
2012-02-07 10:50:20 +08:00
|
|
|
llvm_unreachable("Unsupported opcode for unwinding information");
|
2011-03-06 02:43:32 +08:00
|
|
|
case ARM::MOVr:
|
2012-01-19 20:53:06 +08:00
|
|
|
case ARM::tMOVr:
|
2011-03-06 02:43:32 +08:00
|
|
|
Offset = 0;
|
|
|
|
break;
|
|
|
|
case ARM::ADDri:
|
2015-11-10 08:10:41 +08:00
|
|
|
case ARM::t2ADDri:
|
2011-03-06 02:43:32 +08:00
|
|
|
Offset = -MI->getOperand(2).getImm();
|
|
|
|
break;
|
|
|
|
case ARM::SUBri:
|
2012-01-19 20:53:06 +08:00
|
|
|
case ARM::t2SUBri:
|
2011-06-30 07:25:04 +08:00
|
|
|
Offset = MI->getOperand(2).getImm();
|
2011-03-06 02:43:32 +08:00
|
|
|
break;
|
2011-03-06 02:43:43 +08:00
|
|
|
case ARM::tSUBspi:
|
2011-06-30 07:25:04 +08:00
|
|
|
Offset = MI->getOperand(2).getImm()*4;
|
2011-03-06 02:43:43 +08:00
|
|
|
break;
|
|
|
|
case ARM::tADDspi:
|
|
|
|
case ARM::tADDrSPi:
|
|
|
|
Offset = -MI->getOperand(2).getImm()*4;
|
|
|
|
break;
|
2011-03-06 02:43:55 +08:00
|
|
|
case ARM::tLDRpci: {
|
|
|
|
// Grab the constpool index and check, whether it corresponds to
|
|
|
|
// original or cloned constpool entry.
|
|
|
|
unsigned CPI = MI->getOperand(1).getIndex();
|
|
|
|
const MachineConstantPool *MCP = MF.getConstantPool();
|
|
|
|
if (CPI >= MCP->getConstants().size())
|
|
|
|
CPI = AFI.getOriginalCPIdx(CPI);
|
|
|
|
assert(CPI != -1U && "Invalid constpool index");
|
|
|
|
|
|
|
|
// Derive the actual offset.
|
|
|
|
const MachineConstantPoolEntry &CPE = MCP->getConstants()[CPI];
|
|
|
|
assert(!CPE.isMachineConstantPoolEntry() && "Invalid constpool entry");
|
|
|
|
// FIXME: Check for user, it should be "add" instruction!
|
|
|
|
Offset = -cast<ConstantInt>(CPE.Val.ConstVal)->getSExtValue();
|
2011-03-06 02:43:50 +08:00
|
|
|
break;
|
2011-03-06 02:43:32 +08:00
|
|
|
}
|
2011-03-06 02:43:55 +08:00
|
|
|
}
|
2011-03-06 02:43:32 +08:00
|
|
|
|
2014-05-01 06:43:13 +08:00
|
|
|
if (MAI->getExceptionHandlingType() == ExceptionHandling::ARM) {
|
|
|
|
if (DstReg == FramePtr && FramePtr != ARM::SP)
|
|
|
|
// Set-up of the frame pointer. Positive values correspond to "add"
|
|
|
|
// instruction.
|
|
|
|
ATS.emitSetFP(FramePtr, ARM::SP, -Offset);
|
|
|
|
else if (DstReg == ARM::SP) {
|
|
|
|
// Change of SP by an offset. Positive values correspond to "sub"
|
|
|
|
// instruction.
|
|
|
|
ATS.emitPad(Offset);
|
|
|
|
} else {
|
|
|
|
// Move of SP to a register. Positive values correspond to an "add"
|
|
|
|
// instruction.
|
|
|
|
ATS.emitMovSP(DstReg, -Offset);
|
|
|
|
}
|
2011-03-06 02:43:32 +08:00
|
|
|
}
|
|
|
|
} else if (DstReg == ARM::SP) {
|
2017-01-28 10:02:38 +08:00
|
|
|
MI->print(errs());
|
2012-02-07 10:50:20 +08:00
|
|
|
llvm_unreachable("Unsupported opcode for unwinding information");
|
2011-03-06 02:43:32 +08:00
|
|
|
}
|
|
|
|
else {
|
2017-01-28 10:02:38 +08:00
|
|
|
MI->print(errs());
|
2012-02-07 10:50:20 +08:00
|
|
|
llvm_unreachable("Unsupported opcode for unwinding information");
|
2011-03-06 02:43:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-09 01:40:42 +08:00
|
|
|
// Simple pseudo-instructions have their lowering (with expansion to real
|
|
|
|
// instructions) auto-generated.
|
|
|
|
#include "ARMGenMCPseudoLowering.inc"
|
|
|
|
|
2010-09-29 23:23:40 +08:00
|
|
|
void ARMAsmPrinter::EmitInstruction(const MachineInstr *MI) {
|
2015-07-16 14:11:10 +08:00
|
|
|
const DataLayout &DL = getDataLayout();
|
2016-01-29 18:23:32 +08:00
|
|
|
MCTargetStreamer &TS = *OutStreamer->getTargetStreamer();
|
|
|
|
ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
|
2014-01-04 03:21:54 +08:00
|
|
|
|
[ARM] Restore the right frame pointer register in Int_eh_sjlj_longjmp
In setupEntryBlockAndCallSites in CodeGen/SjLjEHPrepare.cpp,
we fetch and store the actual frame pointer, but on return via
the longjmp intrinsic, it always was restored into the r7 variable.
On windows, the frame pointer should be restored into r11 instead of r7.
On Darwin (where sjlj exception handling is used by default), the frame
pointer is always r7, both in arm and thumb mode, and likewise, on
windows, the frame pointer always is r11.
On linux however, if sjlj exception handling is enabled (which it isn't
by default), libcxxabi and the user code can be built in differing modes
using different registers as frame pointer. Therefore, when restoring
registers on a platform where we don't always use the same register
depending on code mode, restore both r7 and r11.
Differential Revision: https://reviews.llvm.org/D38253
llvm-svn: 314451
2017-09-29 03:04:30 +08:00
|
|
|
const MachineFunction &MF = *MI->getParent()->getParent();
|
|
|
|
const ARMSubtarget &STI = MF.getSubtarget<ARMSubtarget>();
|
|
|
|
unsigned FramePtr = STI.useR7AsFramePointer() ? ARM::R7 : ARM::R11;
|
|
|
|
|
2012-05-19 03:12:01 +08:00
|
|
|
// If we just ended a constant pool, mark it as such.
|
|
|
|
if (InConstantPool && MI->getOpcode() != ARM::CONSTPOOL_ENTRY) {
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitDataRegion(MCDR_DataRegionEnd);
|
2012-05-19 03:12:01 +08:00
|
|
|
InConstantPool = false;
|
|
|
|
}
|
2011-10-05 07:26:17 +08:00
|
|
|
|
2011-08-24 05:32:34 +08:00
|
|
|
// Emit unwinding stuff for frame-related instructions
|
2014-02-08 04:12:49 +08:00
|
|
|
if (Subtarget->isTargetEHABICompatible() &&
|
2014-01-29 19:50:56 +08:00
|
|
|
MI->getFlag(MachineInstr::FrameSetup))
|
2011-08-24 05:32:34 +08:00
|
|
|
EmitUnwindingInstruction(MI);
|
|
|
|
|
2011-07-09 01:40:42 +08:00
|
|
|
// Do any auto-generated pseudo lowerings.
|
2015-04-25 03:11:51 +08:00
|
|
|
if (emitPseudoExpansionLowering(*OutStreamer, MI))
|
2011-07-01 02:25:42 +08:00
|
|
|
return;
|
2010-12-09 09:22:19 +08:00
|
|
|
|
2011-09-21 10:20:46 +08:00
|
|
|
assert(!convertAddSubFlagsOpcode(MI->getOpcode()) &&
|
|
|
|
"Pseudo flag setting opcode should be expanded early");
|
|
|
|
|
2011-07-09 01:40:42 +08:00
|
|
|
// Check for manual lowerings.
|
|
|
|
unsigned Opc = MI->getOpcode();
|
|
|
|
switch (Opc) {
|
2012-02-07 10:50:20 +08:00
|
|
|
case ARM::t2MOVi32imm: llvm_unreachable("Should be lowered by thumb2it pass");
|
2013-06-17 04:34:27 +08:00
|
|
|
case ARM::DBG_VALUE: llvm_unreachable("Should be handled by generic printing");
|
2010-12-15 05:10:47 +08:00
|
|
|
case ARM::LEApcrel:
|
2010-12-15 06:28:03 +08:00
|
|
|
case ARM::tLEApcrel:
|
2010-12-15 05:10:47 +08:00
|
|
|
case ARM::t2LEApcrel: {
|
2010-12-02 08:28:45 +08:00
|
|
|
// FIXME: Need to also handle globals and externals
|
2012-11-26 21:34:22 +08:00
|
|
|
MCSymbol *CPISymbol = GetCPISymbol(MI->getOperand(1).getIndex());
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(MI->getOpcode() ==
|
|
|
|
ARM::t2LEApcrel ? ARM::t2ADR
|
2012-11-26 21:34:22 +08:00
|
|
|
: (MI->getOpcode() == ARM::tLEApcrel ? ARM::tADR
|
|
|
|
: ARM::ADR))
|
|
|
|
.addReg(MI->getOperand(0).getReg())
|
2015-05-30 09:25:56 +08:00
|
|
|
.addExpr(MCSymbolRefExpr::create(CPISymbol, OutContext))
|
2012-11-26 21:34:22 +08:00
|
|
|
// Add predicate operands.
|
|
|
|
.addImm(MI->getOperand(2).getImm())
|
2012-11-27 02:05:52 +08:00
|
|
|
.addReg(MI->getOperand(3).getReg()));
|
2010-12-02 08:28:45 +08:00
|
|
|
return;
|
|
|
|
}
|
2010-12-15 06:28:03 +08:00
|
|
|
case ARM::LEApcrelJT:
|
|
|
|
case ARM::tLEApcrelJT:
|
|
|
|
case ARM::t2LEApcrelJT: {
|
2012-11-26 21:34:22 +08:00
|
|
|
MCSymbol *JTIPICSymbol =
|
2015-05-14 04:28:38 +08:00
|
|
|
GetARMJTIPICJumpTableLabel(MI->getOperand(1).getIndex());
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(MI->getOpcode() ==
|
|
|
|
ARM::t2LEApcrelJT ? ARM::t2ADR
|
2012-11-26 21:34:22 +08:00
|
|
|
: (MI->getOpcode() == ARM::tLEApcrelJT ? ARM::tADR
|
|
|
|
: ARM::ADR))
|
|
|
|
.addReg(MI->getOperand(0).getReg())
|
2015-05-30 09:25:56 +08:00
|
|
|
.addExpr(MCSymbolRefExpr::create(JTIPICSymbol, OutContext))
|
2012-11-26 21:34:22 +08:00
|
|
|
// Add predicate operands.
|
2015-05-14 04:28:38 +08:00
|
|
|
.addImm(MI->getOperand(2).getImm())
|
|
|
|
.addReg(MI->getOperand(3).getReg()));
|
2010-12-02 03:47:31 +08:00
|
|
|
return;
|
|
|
|
}
|
2011-03-12 08:45:26 +08:00
|
|
|
// Darwin call instructions are just normal call instructions with different
|
|
|
|
// clobber semantics (they clobber R9).
|
2010-12-01 02:30:19 +08:00
|
|
|
case ARM::BX_CALL: {
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::MOVr)
|
2012-11-26 21:34:22 +08:00
|
|
|
.addReg(ARM::LR)
|
|
|
|
.addReg(ARM::PC)
|
2010-12-01 02:30:19 +08:00
|
|
|
// Add predicate operands.
|
2012-11-26 21:34:22 +08:00
|
|
|
.addImm(ARMCC::AL)
|
|
|
|
.addReg(0)
|
2010-12-01 02:30:19 +08:00
|
|
|
// Add 's' bit operand (always reg0 for this)
|
2012-11-27 02:05:52 +08:00
|
|
|
.addReg(0));
|
2012-11-26 21:34:22 +08:00
|
|
|
|
2017-08-29 04:20:47 +08:00
|
|
|
assert(Subtarget->hasV4TOps());
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::BX)
|
2012-11-27 02:05:52 +08:00
|
|
|
.addReg(MI->getOperand(0).getReg()));
|
2010-12-01 02:30:19 +08:00
|
|
|
return;
|
|
|
|
}
|
2011-05-26 05:53:50 +08:00
|
|
|
case ARM::tBX_CALL: {
|
2014-12-05 03:34:50 +08:00
|
|
|
if (Subtarget->hasV5TOps())
|
|
|
|
llvm_unreachable("Expected BLX to be selected for v5t+");
|
|
|
|
|
|
|
|
// On ARM v4t, when doing a call from thumb mode, we need to ensure
|
|
|
|
// that the saved lr has its LSB set correctly (the arch doesn't
|
|
|
|
// have blx).
|
|
|
|
// So here we generate a bl to a small jump pad that does bx rN.
|
|
|
|
// The jump pads are emitted after the function body.
|
|
|
|
|
|
|
|
unsigned TReg = MI->getOperand(0).getReg();
|
|
|
|
MCSymbol *TRegSym = nullptr;
|
2017-08-29 18:04:18 +08:00
|
|
|
for (std::pair<unsigned, MCSymbol *> &TIP : ThumbIndirectPads) {
|
|
|
|
if (TIP.first == TReg) {
|
|
|
|
TRegSym = TIP.second;
|
2014-12-05 03:34:50 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-26 21:34:22 +08:00
|
|
|
|
2014-12-05 03:34:50 +08:00
|
|
|
if (!TRegSym) {
|
2015-05-19 02:43:14 +08:00
|
|
|
TRegSym = OutContext.createTempSymbol();
|
2014-12-05 03:34:50 +08:00
|
|
|
ThumbIndirectPads.push_back(std::make_pair(TReg, TRegSym));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a link-saving branch to the Reg Indirect Jump Pad.
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tBL)
|
2014-12-05 03:34:50 +08:00
|
|
|
// Predicate comes first here.
|
|
|
|
.addImm(ARMCC::AL).addReg(0)
|
2015-05-30 09:25:56 +08:00
|
|
|
.addExpr(MCSymbolRefExpr::create(TRegSym, OutContext)));
|
2011-05-26 05:53:50 +08:00
|
|
|
return;
|
|
|
|
}
|
2010-12-01 02:30:19 +08:00
|
|
|
case ARM::BMOVPCRX_CALL: {
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::MOVr)
|
2012-11-26 21:34:22 +08:00
|
|
|
.addReg(ARM::LR)
|
|
|
|
.addReg(ARM::PC)
|
2010-12-01 02:30:19 +08:00
|
|
|
// Add predicate operands.
|
2012-11-26 21:34:22 +08:00
|
|
|
.addImm(ARMCC::AL)
|
|
|
|
.addReg(0)
|
2010-12-01 02:30:19 +08:00
|
|
|
// Add 's' bit operand (always reg0 for this)
|
2012-11-27 02:05:52 +08:00
|
|
|
.addReg(0));
|
2012-11-26 21:34:22 +08:00
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::MOVr)
|
2012-11-26 21:34:22 +08:00
|
|
|
.addReg(ARM::PC)
|
2013-03-16 01:27:39 +08:00
|
|
|
.addReg(MI->getOperand(0).getReg())
|
2010-12-01 02:30:19 +08:00
|
|
|
// Add predicate operands.
|
2012-11-26 21:34:22 +08:00
|
|
|
.addImm(ARMCC::AL)
|
|
|
|
.addReg(0)
|
2010-12-01 02:30:19 +08:00
|
|
|
// Add 's' bit operand (always reg0 for this)
|
2012-11-27 02:05:52 +08:00
|
|
|
.addReg(0));
|
2010-12-01 02:30:19 +08:00
|
|
|
return;
|
|
|
|
}
|
2012-02-29 02:51:51 +08:00
|
|
|
case ARM::BMOVPCB_CALL: {
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::MOVr)
|
2012-11-26 21:34:22 +08:00
|
|
|
.addReg(ARM::LR)
|
|
|
|
.addReg(ARM::PC)
|
2012-02-29 02:51:51 +08:00
|
|
|
// Add predicate operands.
|
2012-11-26 21:34:22 +08:00
|
|
|
.addImm(ARMCC::AL)
|
|
|
|
.addReg(0)
|
2012-02-29 02:51:51 +08:00
|
|
|
// Add 's' bit operand (always reg0 for this)
|
2012-11-27 02:05:52 +08:00
|
|
|
.addReg(0));
|
2012-11-26 21:34:22 +08:00
|
|
|
|
2014-07-07 13:18:22 +08:00
|
|
|
const MachineOperand &Op = MI->getOperand(0);
|
|
|
|
const GlobalValue *GV = Op.getGlobal();
|
|
|
|
const unsigned TF = Op.getTargetFlags();
|
|
|
|
MCSymbol *GVSym = GetARMGVSymbol(GV, TF);
|
2015-05-30 09:25:56 +08:00
|
|
|
const MCExpr *GVSymExpr = MCSymbolRefExpr::create(GVSym, OutContext);
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::Bcc)
|
2012-11-26 21:34:22 +08:00
|
|
|
.addExpr(GVSymExpr)
|
2012-02-29 02:51:51 +08:00
|
|
|
// Add predicate operands.
|
2012-11-26 21:34:22 +08:00
|
|
|
.addImm(ARMCC::AL)
|
2012-11-27 02:05:52 +08:00
|
|
|
.addReg(0));
|
2012-02-29 02:51:51 +08:00
|
|
|
return;
|
|
|
|
}
|
2011-01-22 02:55:51 +08:00
|
|
|
case ARM::MOVi16_ga_pcrel:
|
|
|
|
case ARM::t2MOVi16_ga_pcrel: {
|
2011-01-17 16:03:18 +08:00
|
|
|
MCInst TmpInst;
|
2011-01-22 02:55:51 +08:00
|
|
|
TmpInst.setOpcode(Opc == ARM::MOVi16_ga_pcrel? ARM::MOVi16 : ARM::t2MOVi16);
|
2015-05-14 02:37:00 +08:00
|
|
|
TmpInst.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));
|
2011-01-17 16:03:18 +08:00
|
|
|
|
2011-01-22 02:55:51 +08:00
|
|
|
unsigned TF = MI->getOperand(1).getTargetFlags();
|
2011-01-17 16:03:18 +08:00
|
|
|
const GlobalValue *GV = MI->getOperand(1).getGlobal();
|
2013-11-26 00:24:52 +08:00
|
|
|
MCSymbol *GVSym = GetARMGVSymbol(GV, TF);
|
2015-05-30 09:25:56 +08:00
|
|
|
const MCExpr *GVSymExpr = MCSymbolRefExpr::create(GVSym, OutContext);
|
2013-11-26 00:24:52 +08:00
|
|
|
|
2015-07-16 14:11:10 +08:00
|
|
|
MCSymbol *LabelSym =
|
|
|
|
getPICLabel(DL.getPrivateGlobalPrefix(), getFunctionNumber(),
|
|
|
|
MI->getOperand(2).getImm(), OutContext);
|
2015-05-30 09:25:56 +08:00
|
|
|
const MCExpr *LabelSymExpr= MCSymbolRefExpr::create(LabelSym, OutContext);
|
2013-11-26 00:24:52 +08:00
|
|
|
unsigned PCAdj = (Opc == ARM::MOVi16_ga_pcrel) ? 8 : 4;
|
|
|
|
const MCExpr *PCRelExpr =
|
2015-05-30 09:25:56 +08:00
|
|
|
ARMMCExpr::createLower16(MCBinaryExpr::createSub(GVSymExpr,
|
|
|
|
MCBinaryExpr::createAdd(LabelSymExpr,
|
|
|
|
MCConstantExpr::create(PCAdj, OutContext),
|
2013-11-26 00:24:52 +08:00
|
|
|
OutContext), OutContext), OutContext);
|
2015-05-14 02:37:00 +08:00
|
|
|
TmpInst.addOperand(MCOperand::createExpr(PCRelExpr));
|
2011-01-22 02:55:51 +08:00
|
|
|
|
2011-01-17 16:03:18 +08:00
|
|
|
// Add predicate operands.
|
2015-05-14 02:37:00 +08:00
|
|
|
TmpInst.addOperand(MCOperand::createImm(ARMCC::AL));
|
|
|
|
TmpInst.addOperand(MCOperand::createReg(0));
|
2011-01-17 16:03:18 +08:00
|
|
|
// Add 's' bit operand (always reg0 for this)
|
2015-05-14 02:37:00 +08:00
|
|
|
TmpInst.addOperand(MCOperand::createReg(0));
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, TmpInst);
|
2011-01-17 16:03:18 +08:00
|
|
|
return;
|
|
|
|
}
|
2011-01-22 02:55:51 +08:00
|
|
|
case ARM::MOVTi16_ga_pcrel:
|
|
|
|
case ARM::t2MOVTi16_ga_pcrel: {
|
2011-01-17 16:03:18 +08:00
|
|
|
MCInst TmpInst;
|
2011-01-22 02:55:51 +08:00
|
|
|
TmpInst.setOpcode(Opc == ARM::MOVTi16_ga_pcrel
|
|
|
|
? ARM::MOVTi16 : ARM::t2MOVTi16);
|
2015-05-14 02:37:00 +08:00
|
|
|
TmpInst.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));
|
|
|
|
TmpInst.addOperand(MCOperand::createReg(MI->getOperand(1).getReg()));
|
2011-01-17 16:03:18 +08:00
|
|
|
|
2011-01-22 02:55:51 +08:00
|
|
|
unsigned TF = MI->getOperand(2).getTargetFlags();
|
2011-01-17 16:03:18 +08:00
|
|
|
const GlobalValue *GV = MI->getOperand(2).getGlobal();
|
2013-11-26 00:24:52 +08:00
|
|
|
MCSymbol *GVSym = GetARMGVSymbol(GV, TF);
|
2015-05-30 09:25:56 +08:00
|
|
|
const MCExpr *GVSymExpr = MCSymbolRefExpr::create(GVSym, OutContext);
|
2013-11-26 00:24:52 +08:00
|
|
|
|
2015-07-16 14:11:10 +08:00
|
|
|
MCSymbol *LabelSym =
|
|
|
|
getPICLabel(DL.getPrivateGlobalPrefix(), getFunctionNumber(),
|
|
|
|
MI->getOperand(3).getImm(), OutContext);
|
2015-05-30 09:25:56 +08:00
|
|
|
const MCExpr *LabelSymExpr= MCSymbolRefExpr::create(LabelSym, OutContext);
|
2013-11-26 00:24:52 +08:00
|
|
|
unsigned PCAdj = (Opc == ARM::MOVTi16_ga_pcrel) ? 8 : 4;
|
|
|
|
const MCExpr *PCRelExpr =
|
2015-05-30 09:25:56 +08:00
|
|
|
ARMMCExpr::createUpper16(MCBinaryExpr::createSub(GVSymExpr,
|
|
|
|
MCBinaryExpr::createAdd(LabelSymExpr,
|
|
|
|
MCConstantExpr::create(PCAdj, OutContext),
|
2011-01-17 16:03:18 +08:00
|
|
|
OutContext), OutContext), OutContext);
|
2015-05-14 02:37:00 +08:00
|
|
|
TmpInst.addOperand(MCOperand::createExpr(PCRelExpr));
|
2011-01-17 16:03:18 +08:00
|
|
|
// Add predicate operands.
|
2015-05-14 02:37:00 +08:00
|
|
|
TmpInst.addOperand(MCOperand::createImm(ARMCC::AL));
|
|
|
|
TmpInst.addOperand(MCOperand::createReg(0));
|
2011-01-17 16:03:18 +08:00
|
|
|
// Add 's' bit operand (always reg0 for this)
|
2015-05-14 02:37:00 +08:00
|
|
|
TmpInst.addOperand(MCOperand::createReg(0));
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, TmpInst);
|
2011-01-17 16:03:18 +08:00
|
|
|
return;
|
|
|
|
}
|
2010-09-18 07:41:53 +08:00
|
|
|
case ARM::tPICADD: {
|
|
|
|
// This is a pseudo op for a label + instruction sequence, which looks like:
|
|
|
|
// LPC0:
|
|
|
|
// add r0, pc
|
|
|
|
// This adds the address of LPC0 to r0.
|
|
|
|
|
|
|
|
// Emit the label.
|
2015-07-16 14:11:10 +08:00
|
|
|
OutStreamer->EmitLabel(getPICLabel(DL.getPrivateGlobalPrefix(),
|
2015-04-25 03:11:51 +08:00
|
|
|
getFunctionNumber(),
|
2015-07-16 14:11:10 +08:00
|
|
|
MI->getOperand(2).getImm(), OutContext));
|
2010-09-18 07:41:53 +08:00
|
|
|
|
|
|
|
// Form and emit the add.
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tADDhirr)
|
2012-11-26 21:34:22 +08:00
|
|
|
.addReg(MI->getOperand(0).getReg())
|
|
|
|
.addReg(MI->getOperand(0).getReg())
|
|
|
|
.addReg(ARM::PC)
|
|
|
|
// Add predicate operands.
|
|
|
|
.addImm(ARMCC::AL)
|
2012-11-27 02:05:52 +08:00
|
|
|
.addReg(0));
|
2010-09-18 07:41:53 +08:00
|
|
|
return;
|
|
|
|
}
|
2010-10-01 03:53:58 +08:00
|
|
|
case ARM::PICADD: {
|
2009-10-20 06:23:04 +08:00
|
|
|
// This is a pseudo op for a label + instruction sequence, which looks like:
|
|
|
|
// LPC0:
|
|
|
|
// add r0, pc, r0
|
|
|
|
// This adds the address of LPC0 to r0.
|
2010-09-02 09:02:06 +08:00
|
|
|
|
2009-10-20 06:23:04 +08:00
|
|
|
// Emit the label.
|
2015-07-16 14:11:10 +08:00
|
|
|
OutStreamer->EmitLabel(getPICLabel(DL.getPrivateGlobalPrefix(),
|
2015-04-25 03:11:51 +08:00
|
|
|
getFunctionNumber(),
|
2015-07-16 14:11:10 +08:00
|
|
|
MI->getOperand(2).getImm(), OutContext));
|
2010-09-02 09:02:06 +08:00
|
|
|
|
2010-09-15 05:05:34 +08:00
|
|
|
// Form and emit the add.
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::ADDrr)
|
2012-11-26 21:34:22 +08:00
|
|
|
.addReg(MI->getOperand(0).getReg())
|
|
|
|
.addReg(ARM::PC)
|
|
|
|
.addReg(MI->getOperand(1).getReg())
|
|
|
|
// Add predicate operands.
|
|
|
|
.addImm(MI->getOperand(3).getImm())
|
|
|
|
.addReg(MI->getOperand(4).getReg())
|
|
|
|
// Add 's' bit operand (always reg0 for this)
|
2012-11-27 02:05:52 +08:00
|
|
|
.addReg(0));
|
2009-10-20 06:23:04 +08:00
|
|
|
return;
|
2010-09-17 01:43:25 +08:00
|
|
|
}
|
2010-09-18 00:25:52 +08:00
|
|
|
case ARM::PICSTR:
|
|
|
|
case ARM::PICSTRB:
|
|
|
|
case ARM::PICSTRH:
|
|
|
|
case ARM::PICLDR:
|
|
|
|
case ARM::PICLDRB:
|
|
|
|
case ARM::PICLDRH:
|
|
|
|
case ARM::PICLDRSB:
|
|
|
|
case ARM::PICLDRSH: {
|
2010-09-17 01:43:25 +08:00
|
|
|
// This is a pseudo op for a label + instruction sequence, which looks like:
|
|
|
|
// LPC0:
|
2010-09-18 00:25:52 +08:00
|
|
|
// OP r0, [pc, r0]
|
2010-09-17 01:43:25 +08:00
|
|
|
// The LCP0 label is referenced by a constant pool entry in order to get
|
|
|
|
// a PC-relative address at the ldr instruction.
|
|
|
|
|
|
|
|
// Emit the label.
|
2015-07-16 14:11:10 +08:00
|
|
|
OutStreamer->EmitLabel(getPICLabel(DL.getPrivateGlobalPrefix(),
|
2015-04-25 03:11:51 +08:00
|
|
|
getFunctionNumber(),
|
2015-07-16 14:11:10 +08:00
|
|
|
MI->getOperand(2).getImm(), OutContext));
|
2010-09-17 01:43:25 +08:00
|
|
|
|
|
|
|
// Form and emit the load
|
2010-09-18 00:25:52 +08:00
|
|
|
unsigned Opcode;
|
|
|
|
switch (MI->getOpcode()) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unexpected opcode!");
|
2010-10-28 07:12:14 +08:00
|
|
|
case ARM::PICSTR: Opcode = ARM::STRrs; break;
|
|
|
|
case ARM::PICSTRB: Opcode = ARM::STRBrs; break;
|
2010-09-18 00:25:52 +08:00
|
|
|
case ARM::PICSTRH: Opcode = ARM::STRH; break;
|
2010-10-27 06:37:02 +08:00
|
|
|
case ARM::PICLDR: Opcode = ARM::LDRrs; break;
|
2010-10-27 08:19:44 +08:00
|
|
|
case ARM::PICLDRB: Opcode = ARM::LDRBrs; break;
|
2010-09-18 00:25:52 +08:00
|
|
|
case ARM::PICLDRH: Opcode = ARM::LDRH; break;
|
|
|
|
case ARM::PICLDRSB: Opcode = ARM::LDRSB; break;
|
|
|
|
case ARM::PICLDRSH: Opcode = ARM::LDRSH; break;
|
|
|
|
}
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(Opcode)
|
2012-11-26 21:34:22 +08:00
|
|
|
.addReg(MI->getOperand(0).getReg())
|
|
|
|
.addReg(ARM::PC)
|
|
|
|
.addReg(MI->getOperand(1).getReg())
|
|
|
|
.addImm(0)
|
|
|
|
// Add predicate operands.
|
|
|
|
.addImm(MI->getOperand(3).getImm())
|
2012-11-27 02:05:52 +08:00
|
|
|
.addReg(MI->getOperand(4).getReg()));
|
2010-09-17 01:43:25 +08:00
|
|
|
|
|
|
|
return;
|
2009-10-20 06:23:04 +08:00
|
|
|
}
|
2010-10-01 03:53:58 +08:00
|
|
|
case ARM::CONSTPOOL_ENTRY: {
|
2017-06-20 15:20:52 +08:00
|
|
|
if (Subtarget->genExecuteOnly())
|
|
|
|
llvm_unreachable("execute-only should not generate constant pools");
|
|
|
|
|
2009-10-20 06:33:05 +08:00
|
|
|
/// CONSTPOOL_ENTRY - This instruction represents a floating constant pool
|
|
|
|
/// in the function. The first operand is the ID# for this instruction, the
|
|
|
|
/// second is the index into the MachineConstantPool that this is, the third
|
|
|
|
/// is the size in bytes of this constant pool entry.
|
2011-12-06 09:43:02 +08:00
|
|
|
/// The required alignment is specified on the basic block holding this MI.
|
2009-10-20 06:33:05 +08:00
|
|
|
unsigned LabelId = (unsigned)MI->getOperand(0).getImm();
|
|
|
|
unsigned CPIdx = (unsigned)MI->getOperand(1).getIndex();
|
|
|
|
|
2012-05-19 03:12:01 +08:00
|
|
|
// If this is the first entry of the pool, mark it.
|
|
|
|
if (!InConstantPool) {
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitDataRegion(MCDR_DataRegion);
|
2012-05-19 03:12:01 +08:00
|
|
|
InConstantPool = true;
|
|
|
|
}
|
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitLabel(GetCPISymbol(LabelId));
|
2009-10-20 06:33:05 +08:00
|
|
|
|
|
|
|
const MachineConstantPoolEntry &MCPE = MCP->getConstants()[CPIdx];
|
|
|
|
if (MCPE.isMachineConstantPoolEntry())
|
|
|
|
EmitMachineConstantPoolValue(MCPE.Val.MachineCPVal);
|
|
|
|
else
|
2015-07-16 14:11:10 +08:00
|
|
|
EmitGlobalConstant(DL, MCPE.Val.ConstVal);
|
2009-10-20 06:33:05 +08:00
|
|
|
return;
|
|
|
|
}
|
2015-06-01 03:22:07 +08:00
|
|
|
case ARM::JUMPTABLE_ADDRS:
|
|
|
|
EmitJumpTableAddrs(MI);
|
|
|
|
return;
|
|
|
|
case ARM::JUMPTABLE_INSTS:
|
|
|
|
EmitJumpTableInsts(MI);
|
|
|
|
return;
|
|
|
|
case ARM::JUMPTABLE_TBB:
|
|
|
|
case ARM::JUMPTABLE_TBH:
|
|
|
|
EmitJumpTableTBInst(MI, MI->getOpcode() == ARM::JUMPTABLE_TBB ? 1 : 2);
|
|
|
|
return;
|
2010-09-22 07:28:16 +08:00
|
|
|
case ARM::t2BR_JT: {
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tMOVr)
|
2012-11-26 21:34:22 +08:00
|
|
|
.addReg(ARM::PC)
|
|
|
|
.addReg(MI->getOperand(0).getReg())
|
|
|
|
// Add predicate operands.
|
|
|
|
.addImm(ARMCC::AL)
|
2012-11-27 02:05:52 +08:00
|
|
|
.addReg(0));
|
2010-11-30 06:37:40 +08:00
|
|
|
return;
|
|
|
|
}
|
2015-06-01 03:22:07 +08:00
|
|
|
case ARM::t2TBB_JT:
|
2010-11-30 06:37:40 +08:00
|
|
|
case ARM::t2TBH_JT: {
|
2015-06-01 03:22:07 +08:00
|
|
|
unsigned Opc = MI->getOpcode() == ARM::t2TBB_JT ? ARM::t2TBB : ARM::t2TBH;
|
|
|
|
// Lower and emit the PC label, then the instruction itself.
|
|
|
|
OutStreamer->EmitLabel(GetCPISymbol(MI->getOperand(3).getImm()));
|
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(Opc)
|
|
|
|
.addReg(MI->getOperand(0).getReg())
|
|
|
|
.addReg(MI->getOperand(1).getReg())
|
|
|
|
// Add predicate operands.
|
|
|
|
.addImm(ARMCC::AL)
|
|
|
|
.addReg(0));
|
2010-09-22 07:28:16 +08:00
|
|
|
return;
|
|
|
|
}
|
[Thumb-1] Synthesize TBB/TBH instructions to make use of compressed jump tables
[Reapplying r284580 and r285917 with fix and testing to ensure emitted jump tables for Thumb-1 have 4-byte alignment]
The TBB and TBH instructions in Thumb-2 allow jump tables to be compressed into sequences of bytes or shorts respectively. These instructions do not exist in Thumb-1, however it is possible to synthesize them out of a sequence of other instructions.
It turns out this sequence is so short that it's almost never a lose for performance and is ALWAYS a significant win for code size.
TBB example:
Before: lsls r0, r0, #2 After: add r0, pc
adr r1, .LJTI0_0 ldrb r0, [r0, #6]
ldr r0, [r0, r1] lsls r0, r0, #1
mov pc, r0 add pc, r0
=> No change in prologue code size or dynamic instruction count. Jump table shrunk by a factor of 4.
The only case that can increase dynamic instruction count is the TBH case:
Before: lsls r0, r4, #2 After: lsls r4, r4, #1
adr r1, .LJTI0_0 add r4, pc
ldr r0, [r0, r1] ldrh r4, [r4, #6]
mov pc, r0 lsls r4, r4, #1
add pc, r4
=> 1 more instruction in prologue. Jump table shrunk by a factor of 2.
So there is an argument that this should be disabled when optimizing for performance (and a TBH needs to be generated). I'm not so sure about that in practice, because on small cores with Thumb-1 performance is often tied to code size. But I'm willing to turn it off when optimizing for performance if people want (also note that TBHs are fairly rare in practice!)
llvm-svn: 285690
2016-11-01 21:37:41 +08:00
|
|
|
case ARM::tTBB_JT:
|
|
|
|
case ARM::tTBH_JT: {
|
|
|
|
|
|
|
|
bool Is8Bit = MI->getOpcode() == ARM::tTBB_JT;
|
|
|
|
unsigned Base = MI->getOperand(0).getReg();
|
|
|
|
unsigned Idx = MI->getOperand(1).getReg();
|
|
|
|
assert(MI->getOperand(1).isKill() && "We need the index register as scratch!");
|
|
|
|
|
|
|
|
// Multiply up idx if necessary.
|
|
|
|
if (!Is8Bit)
|
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tLSLri)
|
|
|
|
.addReg(Idx)
|
|
|
|
.addReg(ARM::CPSR)
|
|
|
|
.addReg(Idx)
|
|
|
|
.addImm(1)
|
|
|
|
// Add predicate operands.
|
|
|
|
.addImm(ARMCC::AL)
|
|
|
|
.addReg(0));
|
|
|
|
|
|
|
|
if (Base == ARM::PC) {
|
|
|
|
// TBB [base, idx] =
|
|
|
|
// ADDS idx, idx, base
|
|
|
|
// LDRB idx, [idx, #4] ; or LDRH if TBH
|
|
|
|
// LSLS idx, #1
|
|
|
|
// ADDS pc, pc, idx
|
|
|
|
|
2016-11-07 21:38:21 +08:00
|
|
|
// When using PC as the base, it's important that there is no padding
|
|
|
|
// between the last ADDS and the start of the jump table. The jump table
|
|
|
|
// is 4-byte aligned, so we ensure we're 4 byte aligned here too.
|
|
|
|
//
|
|
|
|
// FIXME: Ideally we could vary the LDRB index based on the padding
|
|
|
|
// between the sequence and jump table, however that relies on MCExprs
|
|
|
|
// for load indexes which are currently not supported.
|
|
|
|
OutStreamer->EmitCodeAlignment(4);
|
[Thumb-1] Synthesize TBB/TBH instructions to make use of compressed jump tables
[Reapplying r284580 and r285917 with fix and testing to ensure emitted jump tables for Thumb-1 have 4-byte alignment]
The TBB and TBH instructions in Thumb-2 allow jump tables to be compressed into sequences of bytes or shorts respectively. These instructions do not exist in Thumb-1, however it is possible to synthesize them out of a sequence of other instructions.
It turns out this sequence is so short that it's almost never a lose for performance and is ALWAYS a significant win for code size.
TBB example:
Before: lsls r0, r0, #2 After: add r0, pc
adr r1, .LJTI0_0 ldrb r0, [r0, #6]
ldr r0, [r0, r1] lsls r0, r0, #1
mov pc, r0 add pc, r0
=> No change in prologue code size or dynamic instruction count. Jump table shrunk by a factor of 4.
The only case that can increase dynamic instruction count is the TBH case:
Before: lsls r0, r4, #2 After: lsls r4, r4, #1
adr r1, .LJTI0_0 add r4, pc
ldr r0, [r0, r1] ldrh r4, [r4, #6]
mov pc, r0 lsls r4, r4, #1
add pc, r4
=> 1 more instruction in prologue. Jump table shrunk by a factor of 2.
So there is an argument that this should be disabled when optimizing for performance (and a TBH needs to be generated). I'm not so sure about that in practice, because on small cores with Thumb-1 performance is often tied to code size. But I'm willing to turn it off when optimizing for performance if people want (also note that TBHs are fairly rare in practice!)
llvm-svn: 285690
2016-11-01 21:37:41 +08:00
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tADDhirr)
|
|
|
|
.addReg(Idx)
|
|
|
|
.addReg(Idx)
|
|
|
|
.addReg(Base)
|
|
|
|
// Add predicate operands.
|
|
|
|
.addImm(ARMCC::AL)
|
|
|
|
.addReg(0));
|
|
|
|
|
|
|
|
unsigned Opc = Is8Bit ? ARM::tLDRBi : ARM::tLDRHi;
|
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(Opc)
|
|
|
|
.addReg(Idx)
|
|
|
|
.addReg(Idx)
|
|
|
|
.addImm(Is8Bit ? 4 : 2)
|
|
|
|
// Add predicate operands.
|
|
|
|
.addImm(ARMCC::AL)
|
|
|
|
.addReg(0));
|
|
|
|
} else {
|
|
|
|
// TBB [base, idx] =
|
|
|
|
// LDRB idx, [base, idx] ; or LDRH if TBH
|
|
|
|
// LSLS idx, #1
|
|
|
|
// ADDS pc, pc, idx
|
|
|
|
|
|
|
|
unsigned Opc = Is8Bit ? ARM::tLDRBr : ARM::tLDRHr;
|
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(Opc)
|
|
|
|
.addReg(Idx)
|
|
|
|
.addReg(Base)
|
|
|
|
.addReg(Idx)
|
|
|
|
// Add predicate operands.
|
|
|
|
.addImm(ARMCC::AL)
|
|
|
|
.addReg(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tLSLri)
|
|
|
|
.addReg(Idx)
|
|
|
|
.addReg(ARM::CPSR)
|
|
|
|
.addReg(Idx)
|
|
|
|
.addImm(1)
|
|
|
|
// Add predicate operands.
|
|
|
|
.addImm(ARMCC::AL)
|
|
|
|
.addReg(0));
|
|
|
|
|
|
|
|
OutStreamer->EmitLabel(GetCPISymbol(MI->getOperand(3).getImm()));
|
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tADDhirr)
|
|
|
|
.addReg(ARM::PC)
|
|
|
|
.addReg(ARM::PC)
|
|
|
|
.addReg(Idx)
|
|
|
|
// Add predicate operands.
|
|
|
|
.addImm(ARMCC::AL)
|
|
|
|
.addReg(0));
|
|
|
|
return;
|
|
|
|
}
|
2010-11-30 03:32:47 +08:00
|
|
|
case ARM::tBR_JTr:
|
2010-11-30 02:37:44 +08:00
|
|
|
case ARM::BR_JTr: {
|
|
|
|
// mov pc, target
|
|
|
|
MCInst TmpInst;
|
2010-11-30 06:37:40 +08:00
|
|
|
unsigned Opc = MI->getOpcode() == ARM::BR_JTr ?
|
2011-07-01 07:38:17 +08:00
|
|
|
ARM::MOVr : ARM::tMOVr;
|
2010-11-30 03:32:47 +08:00
|
|
|
TmpInst.setOpcode(Opc);
|
2015-05-14 02:37:00 +08:00
|
|
|
TmpInst.addOperand(MCOperand::createReg(ARM::PC));
|
|
|
|
TmpInst.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));
|
2010-11-30 02:37:44 +08:00
|
|
|
// Add predicate operands.
|
2015-05-14 02:37:00 +08:00
|
|
|
TmpInst.addOperand(MCOperand::createImm(ARMCC::AL));
|
|
|
|
TmpInst.addOperand(MCOperand::createReg(0));
|
2010-12-01 02:30:19 +08:00
|
|
|
// Add 's' bit operand (always reg0 for this)
|
|
|
|
if (Opc == ARM::MOVr)
|
2015-05-14 02:37:00 +08:00
|
|
|
TmpInst.addOperand(MCOperand::createReg(0));
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, TmpInst);
|
2010-11-30 02:37:44 +08:00
|
|
|
return;
|
|
|
|
}
|
2017-11-15 20:02:55 +08:00
|
|
|
case ARM::BR_JTm_i12: {
|
2010-11-30 02:37:44 +08:00
|
|
|
// ldr pc, target
|
|
|
|
MCInst TmpInst;
|
2017-11-15 20:02:55 +08:00
|
|
|
TmpInst.setOpcode(ARM::LDRi12);
|
|
|
|
TmpInst.addOperand(MCOperand::createReg(ARM::PC));
|
|
|
|
TmpInst.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));
|
|
|
|
TmpInst.addOperand(MCOperand::createImm(MI->getOperand(2).getImm()));
|
|
|
|
// Add predicate operands.
|
|
|
|
TmpInst.addOperand(MCOperand::createImm(ARMCC::AL));
|
|
|
|
TmpInst.addOperand(MCOperand::createReg(0));
|
|
|
|
EmitToStreamer(*OutStreamer, TmpInst);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case ARM::BR_JTm_rs: {
|
|
|
|
// ldr pc, target
|
|
|
|
MCInst TmpInst;
|
|
|
|
TmpInst.setOpcode(ARM::LDRrs);
|
|
|
|
TmpInst.addOperand(MCOperand::createReg(ARM::PC));
|
|
|
|
TmpInst.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));
|
|
|
|
TmpInst.addOperand(MCOperand::createReg(MI->getOperand(1).getReg()));
|
|
|
|
TmpInst.addOperand(MCOperand::createImm(MI->getOperand(2).getImm()));
|
2010-11-30 02:37:44 +08:00
|
|
|
// Add predicate operands.
|
2015-05-14 02:37:00 +08:00
|
|
|
TmpInst.addOperand(MCOperand::createImm(ARMCC::AL));
|
|
|
|
TmpInst.addOperand(MCOperand::createReg(0));
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, TmpInst);
|
2010-09-23 01:39:48 +08:00
|
|
|
return;
|
|
|
|
}
|
2010-11-18 05:05:55 +08:00
|
|
|
case ARM::BR_JTadd: {
|
|
|
|
// add pc, target, idx
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::ADDrr)
|
2012-11-26 21:34:22 +08:00
|
|
|
.addReg(ARM::PC)
|
|
|
|
.addReg(MI->getOperand(0).getReg())
|
|
|
|
.addReg(MI->getOperand(1).getReg())
|
|
|
|
// Add predicate operands.
|
|
|
|
.addImm(ARMCC::AL)
|
|
|
|
.addReg(0)
|
|
|
|
// Add 's' bit operand (always reg0 for this)
|
2012-11-27 02:05:52 +08:00
|
|
|
.addReg(0));
|
2010-11-18 05:05:55 +08:00
|
|
|
return;
|
|
|
|
}
|
2014-11-14 01:58:48 +08:00
|
|
|
case ARM::SPACE:
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitZeros(MI->getOperand(1).getImm());
|
2014-11-14 01:58:48 +08:00
|
|
|
return;
|
2010-09-24 02:05:37 +08:00
|
|
|
case ARM::TRAP: {
|
|
|
|
// Non-Darwin binutils don't yet support the "trap" mnemonic.
|
|
|
|
// FIXME: Remove this special case when they do.
|
2014-01-06 22:28:05 +08:00
|
|
|
if (!Subtarget->isTargetMachO()) {
|
2010-09-24 03:42:17 +08:00
|
|
|
uint32_t Val = 0xe7ffdefeUL;
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->AddComment("trap");
|
2016-01-29 18:23:32 +08:00
|
|
|
ATS.emitInst(Val);
|
2010-09-24 02:05:37 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-01-31 00:30:19 +08:00
|
|
|
case ARM::TRAPNaCl: {
|
|
|
|
uint32_t Val = 0xe7fedef0UL;
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->AddComment("trap");
|
2016-01-29 18:23:32 +08:00
|
|
|
ATS.emitInst(Val);
|
2013-01-31 00:30:19 +08:00
|
|
|
return;
|
|
|
|
}
|
2010-09-24 02:05:37 +08:00
|
|
|
case ARM::tTRAP: {
|
|
|
|
// Non-Darwin binutils don't yet support the "trap" mnemonic.
|
|
|
|
// FIXME: Remove this special case when they do.
|
2014-01-06 22:28:05 +08:00
|
|
|
if (!Subtarget->isTargetMachO()) {
|
2010-09-24 02:57:26 +08:00
|
|
|
uint16_t Val = 0xdefe;
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->AddComment("trap");
|
2016-01-29 18:23:32 +08:00
|
|
|
ATS.emitInst(Val, 'n');
|
2010-09-24 02:05:37 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2010-09-25 04:47:58 +08:00
|
|
|
case ARM::t2Int_eh_sjlj_setjmp:
|
|
|
|
case ARM::t2Int_eh_sjlj_setjmp_nofp:
|
2010-10-01 03:53:58 +08:00
|
|
|
case ARM::tInt_eh_sjlj_setjmp: {
|
2010-09-25 04:47:58 +08:00
|
|
|
// Two incoming args: GPR:$src, GPR:$val
|
|
|
|
// mov $val, pc
|
|
|
|
// adds $val, #7
|
|
|
|
// str $val, [$src, #4]
|
|
|
|
// movs r0, #0
|
2015-07-17 06:34:20 +08:00
|
|
|
// b LSJLJEH
|
2010-09-25 04:47:58 +08:00
|
|
|
// movs r0, #1
|
2015-07-17 06:34:20 +08:00
|
|
|
// LSJLJEH:
|
2010-09-25 04:47:58 +08:00
|
|
|
unsigned SrcReg = MI->getOperand(0).getReg();
|
|
|
|
unsigned ValReg = MI->getOperand(1).getReg();
|
2015-07-17 06:34:20 +08:00
|
|
|
MCSymbol *Label = OutContext.createTempSymbol("SJLJEH", false, true);
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->AddComment("eh_setjmp begin");
|
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tMOVr)
|
2012-11-26 21:34:22 +08:00
|
|
|
.addReg(ValReg)
|
|
|
|
.addReg(ARM::PC)
|
2011-07-01 06:10:46 +08:00
|
|
|
// Predicate.
|
2012-11-26 21:34:22 +08:00
|
|
|
.addImm(ARMCC::AL)
|
2012-11-27 02:05:52 +08:00
|
|
|
.addReg(0));
|
2012-11-26 21:34:22 +08:00
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tADDi3)
|
2012-11-26 21:34:22 +08:00
|
|
|
.addReg(ValReg)
|
2010-09-25 04:47:58 +08:00
|
|
|
// 's' bit operand
|
2012-11-26 21:34:22 +08:00
|
|
|
.addReg(ARM::CPSR)
|
|
|
|
.addReg(ValReg)
|
|
|
|
.addImm(7)
|
2010-09-25 04:47:58 +08:00
|
|
|
// Predicate.
|
2012-11-26 21:34:22 +08:00
|
|
|
.addImm(ARMCC::AL)
|
2012-11-27 02:05:52 +08:00
|
|
|
.addReg(0));
|
2012-11-26 21:34:22 +08:00
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tSTRi)
|
2012-11-26 21:34:22 +08:00
|
|
|
.addReg(ValReg)
|
|
|
|
.addReg(SrcReg)
|
2010-09-25 04:47:58 +08:00
|
|
|
// The offset immediate is #4. The operand value is scaled by 4 for the
|
|
|
|
// tSTR instruction.
|
2012-11-26 21:34:22 +08:00
|
|
|
.addImm(1)
|
2010-09-25 04:47:58 +08:00
|
|
|
// Predicate.
|
2012-11-26 21:34:22 +08:00
|
|
|
.addImm(ARMCC::AL)
|
2012-11-27 02:05:52 +08:00
|
|
|
.addReg(0));
|
2012-11-26 21:34:22 +08:00
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tMOVi8)
|
2012-11-26 21:34:22 +08:00
|
|
|
.addReg(ARM::R0)
|
|
|
|
.addReg(ARM::CPSR)
|
|
|
|
.addImm(0)
|
2010-09-25 04:47:58 +08:00
|
|
|
// Predicate.
|
2012-11-26 21:34:22 +08:00
|
|
|
.addImm(ARMCC::AL)
|
2012-11-27 02:05:52 +08:00
|
|
|
.addReg(0));
|
2012-11-26 21:34:22 +08:00
|
|
|
|
2015-05-30 09:25:56 +08:00
|
|
|
const MCExpr *SymbolExpr = MCSymbolRefExpr::create(Label, OutContext);
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tB)
|
2012-11-26 21:34:22 +08:00
|
|
|
.addExpr(SymbolExpr)
|
|
|
|
.addImm(ARMCC::AL)
|
2012-11-27 02:05:52 +08:00
|
|
|
.addReg(0));
|
2012-11-26 21:34:22 +08:00
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->AddComment("eh_setjmp end");
|
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tMOVi8)
|
2012-11-26 21:34:22 +08:00
|
|
|
.addReg(ARM::R0)
|
|
|
|
.addReg(ARM::CPSR)
|
|
|
|
.addImm(1)
|
2010-09-25 04:47:58 +08:00
|
|
|
// Predicate.
|
2012-11-26 21:34:22 +08:00
|
|
|
.addImm(ARMCC::AL)
|
2012-11-27 02:05:52 +08:00
|
|
|
.addReg(0));
|
2012-11-26 21:34:22 +08:00
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitLabel(Label);
|
2010-09-25 04:47:58 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-24 07:33:56 +08:00
|
|
|
case ARM::Int_eh_sjlj_setjmp_nofp:
|
2010-10-01 03:53:58 +08:00
|
|
|
case ARM::Int_eh_sjlj_setjmp: {
|
2010-09-24 07:33:56 +08:00
|
|
|
// Two incoming args: GPR:$src, GPR:$val
|
|
|
|
// add $val, pc, #8
|
|
|
|
// str $val, [$src, #+4]
|
|
|
|
// mov r0, #0
|
|
|
|
// add pc, pc, #0
|
|
|
|
// mov r0, #1
|
|
|
|
unsigned SrcReg = MI->getOperand(0).getReg();
|
|
|
|
unsigned ValReg = MI->getOperand(1).getReg();
|
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->AddComment("eh_setjmp begin");
|
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::ADDri)
|
2012-11-26 21:34:22 +08:00
|
|
|
.addReg(ValReg)
|
|
|
|
.addReg(ARM::PC)
|
|
|
|
.addImm(8)
|
2010-09-24 07:33:56 +08:00
|
|
|
// Predicate.
|
2012-11-26 21:34:22 +08:00
|
|
|
.addImm(ARMCC::AL)
|
|
|
|
.addReg(0)
|
2010-09-24 07:33:56 +08:00
|
|
|
// 's' bit operand (always reg0 for this).
|
2012-11-27 02:05:52 +08:00
|
|
|
.addReg(0));
|
2012-11-26 21:34:22 +08:00
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::STRi12)
|
2012-11-26 21:34:22 +08:00
|
|
|
.addReg(ValReg)
|
|
|
|
.addReg(SrcReg)
|
|
|
|
.addImm(4)
|
2010-09-24 07:33:56 +08:00
|
|
|
// Predicate.
|
2012-11-26 21:34:22 +08:00
|
|
|
.addImm(ARMCC::AL)
|
2012-11-27 02:05:52 +08:00
|
|
|
.addReg(0));
|
2012-11-26 21:34:22 +08:00
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::MOVi)
|
2012-11-26 21:34:22 +08:00
|
|
|
.addReg(ARM::R0)
|
|
|
|
.addImm(0)
|
2010-09-24 07:33:56 +08:00
|
|
|
// Predicate.
|
2012-11-26 21:34:22 +08:00
|
|
|
.addImm(ARMCC::AL)
|
|
|
|
.addReg(0)
|
2010-09-24 07:33:56 +08:00
|
|
|
// 's' bit operand (always reg0 for this).
|
2012-11-27 02:05:52 +08:00
|
|
|
.addReg(0));
|
2012-11-26 21:34:22 +08:00
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::ADDri)
|
2012-11-26 21:34:22 +08:00
|
|
|
.addReg(ARM::PC)
|
|
|
|
.addReg(ARM::PC)
|
|
|
|
.addImm(0)
|
2010-09-24 07:33:56 +08:00
|
|
|
// Predicate.
|
2012-11-26 21:34:22 +08:00
|
|
|
.addImm(ARMCC::AL)
|
|
|
|
.addReg(0)
|
2010-09-24 07:33:56 +08:00
|
|
|
// 's' bit operand (always reg0 for this).
|
2012-11-27 02:05:52 +08:00
|
|
|
.addReg(0));
|
2012-11-26 21:34:22 +08:00
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->AddComment("eh_setjmp end");
|
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::MOVi)
|
2012-11-26 21:34:22 +08:00
|
|
|
.addReg(ARM::R0)
|
|
|
|
.addImm(1)
|
2010-09-24 07:33:56 +08:00
|
|
|
// Predicate.
|
2012-11-26 21:34:22 +08:00
|
|
|
.addImm(ARMCC::AL)
|
|
|
|
.addReg(0)
|
2010-09-24 07:33:56 +08:00
|
|
|
// 's' bit operand (always reg0 for this).
|
2012-11-27 02:05:52 +08:00
|
|
|
.addReg(0));
|
2010-09-24 07:33:56 +08:00
|
|
|
return;
|
|
|
|
}
|
2010-09-28 05:47:04 +08:00
|
|
|
case ARM::Int_eh_sjlj_longjmp: {
|
|
|
|
// ldr sp, [$src, #8]
|
|
|
|
// ldr $scratch, [$src, #4]
|
|
|
|
// ldr r7, [$src]
|
|
|
|
// bx $scratch
|
|
|
|
unsigned SrcReg = MI->getOperand(0).getReg();
|
|
|
|
unsigned ScratchReg = MI->getOperand(1).getReg();
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::LDRi12)
|
2012-11-26 21:34:22 +08:00
|
|
|
.addReg(ARM::SP)
|
|
|
|
.addReg(SrcReg)
|
|
|
|
.addImm(8)
|
2010-09-28 05:47:04 +08:00
|
|
|
// Predicate.
|
2012-11-26 21:34:22 +08:00
|
|
|
.addImm(ARMCC::AL)
|
2012-11-27 02:05:52 +08:00
|
|
|
.addReg(0));
|
2012-11-26 21:34:22 +08:00
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::LDRi12)
|
2012-11-26 21:34:22 +08:00
|
|
|
.addReg(ScratchReg)
|
|
|
|
.addReg(SrcReg)
|
|
|
|
.addImm(4)
|
2010-09-28 05:47:04 +08:00
|
|
|
// Predicate.
|
2012-11-26 21:34:22 +08:00
|
|
|
.addImm(ARMCC::AL)
|
2012-11-27 02:05:52 +08:00
|
|
|
.addReg(0));
|
2012-11-26 21:34:22 +08:00
|
|
|
|
[ARM] Restore the right frame pointer register in Int_eh_sjlj_longjmp
In setupEntryBlockAndCallSites in CodeGen/SjLjEHPrepare.cpp,
we fetch and store the actual frame pointer, but on return via
the longjmp intrinsic, it always was restored into the r7 variable.
On windows, the frame pointer should be restored into r11 instead of r7.
On Darwin (where sjlj exception handling is used by default), the frame
pointer is always r7, both in arm and thumb mode, and likewise, on
windows, the frame pointer always is r11.
On linux however, if sjlj exception handling is enabled (which it isn't
by default), libcxxabi and the user code can be built in differing modes
using different registers as frame pointer. Therefore, when restoring
registers on a platform where we don't always use the same register
depending on code mode, restore both r7 and r11.
Differential Revision: https://reviews.llvm.org/D38253
llvm-svn: 314451
2017-09-29 03:04:30 +08:00
|
|
|
if (STI.isTargetDarwin() || STI.isTargetWindows()) {
|
|
|
|
// These platforms always use the same frame register
|
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::LDRi12)
|
|
|
|
.addReg(FramePtr)
|
|
|
|
.addReg(SrcReg)
|
|
|
|
.addImm(0)
|
|
|
|
// Predicate.
|
|
|
|
.addImm(ARMCC::AL)
|
|
|
|
.addReg(0));
|
|
|
|
} else {
|
|
|
|
// If the calling code might use either R7 or R11 as
|
|
|
|
// frame pointer register, restore it into both.
|
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::LDRi12)
|
|
|
|
.addReg(ARM::R7)
|
|
|
|
.addReg(SrcReg)
|
|
|
|
.addImm(0)
|
|
|
|
// Predicate.
|
|
|
|
.addImm(ARMCC::AL)
|
|
|
|
.addReg(0));
|
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::LDRi12)
|
|
|
|
.addReg(ARM::R11)
|
|
|
|
.addReg(SrcReg)
|
|
|
|
.addImm(0)
|
|
|
|
// Predicate.
|
|
|
|
.addImm(ARMCC::AL)
|
|
|
|
.addReg(0));
|
|
|
|
}
|
2012-11-26 21:34:22 +08:00
|
|
|
|
2017-08-29 04:20:47 +08:00
|
|
|
assert(Subtarget->hasV4TOps());
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::BX)
|
2012-11-26 21:34:22 +08:00
|
|
|
.addReg(ScratchReg)
|
2010-09-28 05:47:04 +08:00
|
|
|
// Predicate.
|
2012-11-26 21:34:22 +08:00
|
|
|
.addImm(ARMCC::AL)
|
2012-11-27 02:05:52 +08:00
|
|
|
.addReg(0));
|
2010-09-28 06:28:11 +08:00
|
|
|
return;
|
|
|
|
}
|
2016-07-08 08:48:22 +08:00
|
|
|
case ARM::tInt_eh_sjlj_longjmp: {
|
2010-09-28 06:28:11 +08:00
|
|
|
// ldr $scratch, [$src, #8]
|
|
|
|
// mov sp, $scratch
|
|
|
|
// ldr $scratch, [$src, #4]
|
|
|
|
// ldr r7, [$src]
|
|
|
|
// bx $scratch
|
|
|
|
unsigned SrcReg = MI->getOperand(0).getReg();
|
|
|
|
unsigned ScratchReg = MI->getOperand(1).getReg();
|
2016-03-10 23:11:09 +08:00
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tLDRi)
|
2012-11-26 21:34:22 +08:00
|
|
|
.addReg(ScratchReg)
|
|
|
|
.addReg(SrcReg)
|
2010-09-28 06:28:11 +08:00
|
|
|
// The offset immediate is #8. The operand value is scaled by 4 for the
|
2010-12-14 11:36:38 +08:00
|
|
|
// tLDR instruction.
|
2012-11-26 21:34:22 +08:00
|
|
|
.addImm(2)
|
2010-09-28 06:28:11 +08:00
|
|
|
// Predicate.
|
2012-11-26 21:34:22 +08:00
|
|
|
.addImm(ARMCC::AL)
|
2012-11-27 02:05:52 +08:00
|
|
|
.addReg(0));
|
2012-11-26 21:34:22 +08:00
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tMOVr)
|
2012-11-26 21:34:22 +08:00
|
|
|
.addReg(ARM::SP)
|
|
|
|
.addReg(ScratchReg)
|
2010-09-28 06:28:11 +08:00
|
|
|
// Predicate.
|
2012-11-26 21:34:22 +08:00
|
|
|
.addImm(ARMCC::AL)
|
2012-11-27 02:05:52 +08:00
|
|
|
.addReg(0));
|
2012-11-26 21:34:22 +08:00
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tLDRi)
|
2012-11-26 21:34:22 +08:00
|
|
|
.addReg(ScratchReg)
|
|
|
|
.addReg(SrcReg)
|
|
|
|
.addImm(1)
|
2010-09-28 06:28:11 +08:00
|
|
|
// Predicate.
|
2012-11-26 21:34:22 +08:00
|
|
|
.addImm(ARMCC::AL)
|
2012-11-27 02:05:52 +08:00
|
|
|
.addReg(0));
|
2012-11-26 21:34:22 +08:00
|
|
|
|
[ARM] Restore the right frame pointer register in Int_eh_sjlj_longjmp
In setupEntryBlockAndCallSites in CodeGen/SjLjEHPrepare.cpp,
we fetch and store the actual frame pointer, but on return via
the longjmp intrinsic, it always was restored into the r7 variable.
On windows, the frame pointer should be restored into r11 instead of r7.
On Darwin (where sjlj exception handling is used by default), the frame
pointer is always r7, both in arm and thumb mode, and likewise, on
windows, the frame pointer always is r11.
On linux however, if sjlj exception handling is enabled (which it isn't
by default), libcxxabi and the user code can be built in differing modes
using different registers as frame pointer. Therefore, when restoring
registers on a platform where we don't always use the same register
depending on code mode, restore both r7 and r11.
Differential Revision: https://reviews.llvm.org/D38253
llvm-svn: 314451
2017-09-29 03:04:30 +08:00
|
|
|
if (STI.isTargetDarwin() || STI.isTargetWindows()) {
|
|
|
|
// These platforms always use the same frame register
|
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tLDRi)
|
|
|
|
.addReg(FramePtr)
|
|
|
|
.addReg(SrcReg)
|
|
|
|
.addImm(0)
|
|
|
|
// Predicate.
|
|
|
|
.addImm(ARMCC::AL)
|
|
|
|
.addReg(0));
|
|
|
|
} else {
|
|
|
|
// If the calling code might use either R7 or R11 as
|
|
|
|
// frame pointer register, restore it into both.
|
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tLDRi)
|
|
|
|
.addReg(ARM::R7)
|
|
|
|
.addReg(SrcReg)
|
|
|
|
.addImm(0)
|
|
|
|
// Predicate.
|
|
|
|
.addImm(ARMCC::AL)
|
|
|
|
.addReg(0));
|
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tLDRi)
|
|
|
|
.addReg(ARM::R11)
|
|
|
|
.addReg(SrcReg)
|
|
|
|
.addImm(0)
|
|
|
|
// Predicate.
|
|
|
|
.addImm(ARMCC::AL)
|
|
|
|
.addReg(0));
|
|
|
|
}
|
2012-11-26 21:34:22 +08:00
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tBX)
|
2012-11-26 21:34:22 +08:00
|
|
|
.addReg(ScratchReg)
|
2010-09-28 06:28:11 +08:00
|
|
|
// Predicate.
|
2012-11-26 21:34:22 +08:00
|
|
|
.addImm(ARMCC::AL)
|
2012-11-27 02:05:52 +08:00
|
|
|
.addReg(0));
|
2010-09-28 05:47:04 +08:00
|
|
|
return;
|
|
|
|
}
|
2016-07-08 08:48:22 +08:00
|
|
|
case ARM::tInt_WIN_eh_sjlj_longjmp: {
|
|
|
|
// ldr.w r11, [$src, #0]
|
|
|
|
// ldr.w sp, [$src, #8]
|
|
|
|
// ldr.w pc, [$src, #4]
|
|
|
|
|
|
|
|
unsigned SrcReg = MI->getOperand(0).getReg();
|
|
|
|
|
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::t2LDRi12)
|
|
|
|
.addReg(ARM::R11)
|
|
|
|
.addReg(SrcReg)
|
|
|
|
.addImm(0)
|
|
|
|
// Predicate
|
|
|
|
.addImm(ARMCC::AL)
|
|
|
|
.addReg(0));
|
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::t2LDRi12)
|
|
|
|
.addReg(ARM::SP)
|
|
|
|
.addReg(SrcReg)
|
|
|
|
.addImm(8)
|
|
|
|
// Predicate
|
|
|
|
.addImm(ARMCC::AL)
|
|
|
|
.addReg(0));
|
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::t2LDRi12)
|
|
|
|
.addReg(ARM::PC)
|
|
|
|
.addReg(SrcReg)
|
|
|
|
.addImm(4)
|
|
|
|
// Predicate
|
|
|
|
.addImm(ARMCC::AL)
|
|
|
|
.addReg(0));
|
|
|
|
return;
|
|
|
|
}
|
2016-09-19 08:54:35 +08:00
|
|
|
case ARM::PATCHABLE_FUNCTION_ENTER:
|
|
|
|
LowerPATCHABLE_FUNCTION_ENTER(*MI);
|
|
|
|
return;
|
|
|
|
case ARM::PATCHABLE_FUNCTION_EXIT:
|
|
|
|
LowerPATCHABLE_FUNCTION_EXIT(*MI);
|
|
|
|
return;
|
2016-10-18 13:54:15 +08:00
|
|
|
case ARM::PATCHABLE_TAIL_CALL:
|
|
|
|
LowerPATCHABLE_TAIL_CALL(*MI);
|
|
|
|
return;
|
2009-10-20 04:20:46 +08:00
|
|
|
}
|
2010-09-02 09:02:06 +08:00
|
|
|
|
2009-10-20 04:20:46 +08:00
|
|
|
MCInst TmpInst;
|
2010-11-15 05:00:02 +08:00
|
|
|
LowerARMMachineInstrToMCInst(MI, TmpInst, *this);
|
2011-03-06 02:43:32 +08:00
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, TmpInst);
|
2009-10-20 04:20:46 +08:00
|
|
|
}
|
2009-10-20 13:15:36 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Target Registry Stuff
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// Force static initialization.
|
|
|
|
extern "C" void LLVMInitializeARMAsmPrinter() {
|
2016-10-10 07:00:34 +08:00
|
|
|
RegisterAsmPrinter<ARMAsmPrinter> X(getTheARMLETarget());
|
|
|
|
RegisterAsmPrinter<ARMAsmPrinter> Y(getTheARMBETarget());
|
|
|
|
RegisterAsmPrinter<ARMAsmPrinter> A(getTheThumbLETarget());
|
|
|
|
RegisterAsmPrinter<ARMAsmPrinter> B(getTheThumbBETarget());
|
2009-10-20 13:15:36 +08:00
|
|
|
}
|