#define DEBUG_TYPE "pic16-codegen"
#include "PIC16.h"
+#include "PIC16ABINames.h"
#include "PIC16InstrInfo.h"
-#include "PIC16TargetAsmInfo.h"
+#include "PIC16MCAsmInfo.h"
#include "PIC16TargetMachine.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/GlobalValue.h"
#include "llvm/DerivedTypes.h"
-#include "llvm/Support/Compiler.h"
using namespace llvm;
namespace {
- struct VISIBILITY_HIDDEN MemSelOpt : public MachineFunctionPass {
+ struct MemSelOpt : public MachineFunctionPass {
static char ID;
MemSelOpt() : MachineFunctionPass(&ID) {}
bool Changed = false;
unsigned NumOperands = MI->getNumOperands();
- // If this insn has only one operand, probably it is not going to
- // access any data memory.
- if (PIC16InstrInfo::hasNoMemOperand(*MI)) return Changed;
+ if (NumOperands == 0) return false;
+
+
+ // If this insn is not going to access any memory, return.
+ const TargetInstrDesc &TID = TII->get(MI->getOpcode());
+ if (!(TID.isBranch() || TID.isCall() || TID.mayLoad() || TID.mayStore()))
+ return false;
// Scan for the memory address operand.
// FIXME: Should we use standard interfaces like memoperands_iterator,
for (unsigned i = 0; i < NumOperands; i++) {
MachineOperand Op = MI->getOperand(i);
if (Op.getType() == MachineOperand::MO_GlobalAddress ||
- Op.getType() == MachineOperand::MO_ExternalSymbol) {
- // We found one mem operand. Next one should be BS.
+ Op.getType() == MachineOperand::MO_ExternalSymbol ||
+ Op.getType() == MachineOperand::MO_MachineBasicBlock) {
+ // We found one mem operand. Next one may be BS.
MemOpPos = i;
break;
}
MachineOperand &Op = MI->getOperand(MemOpPos);
// If this is a pagesel material, handle it first.
- if (MI->getOpcode() == PIC16::CALL) {
+ if (MI->getOpcode() == PIC16::CALL ||
+ MI->getOpcode() == PIC16::br_uncond) {
DebugLoc dl = MI->getDebugLoc();
BuildMI(*MBB, MI, dl, TII->get(PIC16::pagesel)).
addOperand(Op);
}
// Get the section name(NewBank) for MemOp.
+ // This assumes that the section names for globals are already set by
+ // AsmPrinter->doInitialization.
std::string NewBank = CurBank;
if (Op.getType() == MachineOperand::MO_GlobalAddress &&
Op.getGlobal()->getType()->getAddressSpace() == PIC16ISD::RAM_SPACE) {
// External Symbol is generated for temp data and arguments. They are
// in fpdata.<functionname>.# section.
std::string Sym = Op.getSymbolName();
- NewBank = getSectionNameForSym(Sym);
+ NewBank = PAN::getSectionNameForSym(Sym);
}
-
+
+ // If the section is shared section, do not emit banksel.
+ if (NewBank == PAN::getSharedUDataSectionName())
+ return Changed;
+
// If the previous and new section names are same, we don't need to
// emit banksel.
if (NewBank.compare(CurBank) != 0 ) {