2012-12-11 21:25:42 +00:00
|
|
|
//===-- AMDGPUAsmBackend.cpp - AMDGPU Assembler Backend -------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
/// \file
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/MC/MCAsmBackend.h"
|
|
|
|
#include "llvm/MC/MCAssembler.h"
|
|
|
|
#include "llvm/MC/MCObjectWriter.h"
|
|
|
|
#include "llvm/MC/MCValue.h"
|
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class AMDGPUMCObjectWriter : public MCObjectWriter {
|
|
|
|
public:
|
|
|
|
AMDGPUMCObjectWriter(raw_ostream &OS) : MCObjectWriter(OS, true) { }
|
|
|
|
virtual void ExecutePostLayoutBinding(MCAssembler &Asm,
|
|
|
|
const MCAsmLayout &Layout) {
|
|
|
|
//XXX: Implement if necessary.
|
|
|
|
}
|
2014-03-29 06:26:49 +00:00
|
|
|
void RecordRelocation(const MCAssembler &Asm, const MCAsmLayout &Layout,
|
|
|
|
const MCFragment *Fragment, const MCFixup &Fixup,
|
|
|
|
MCValue Target, bool &IsPCRel,
|
|
|
|
uint64_t &FixedValue) override {
|
2012-12-11 21:25:42 +00:00
|
|
|
assert(!"Not implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void WriteObject(MCAssembler &Asm, const MCAsmLayout &Layout);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class AMDGPUAsmBackend : public MCAsmBackend {
|
|
|
|
public:
|
|
|
|
AMDGPUAsmBackend(const Target &T)
|
|
|
|
: MCAsmBackend() {}
|
|
|
|
|
|
|
|
virtual unsigned getNumFixupKinds() const { return 0; };
|
|
|
|
virtual void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
|
2014-03-29 06:26:49 +00:00
|
|
|
uint64_t Value, bool IsPCRel) const;
|
2012-12-11 21:25:42 +00:00
|
|
|
virtual bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
|
2013-01-08 00:22:56 +00:00
|
|
|
const MCRelaxableFragment *DF,
|
2012-12-11 21:25:42 +00:00
|
|
|
const MCAsmLayout &Layout) const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
virtual void relaxInstruction(const MCInst &Inst, MCInst &Res) const {
|
|
|
|
assert(!"Not implemented");
|
|
|
|
}
|
|
|
|
virtual bool mayNeedRelaxation(const MCInst &Inst) const { return false; }
|
|
|
|
virtual bool writeNopData(uint64_t Count, MCObjectWriter *OW) const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} //End anonymous namespace
|
|
|
|
|
|
|
|
void AMDGPUMCObjectWriter::WriteObject(MCAssembler &Asm,
|
|
|
|
const MCAsmLayout &Layout) {
|
|
|
|
for (MCAssembler::iterator I = Asm.begin(), E = Asm.end(); I != E; ++I) {
|
|
|
|
Asm.writeSectionData(I, Layout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-17 15:14:54 +00:00
|
|
|
void AMDGPUAsmBackend::applyFixup(const MCFixup &Fixup, char *Data,
|
2014-03-29 06:26:49 +00:00
|
|
|
unsigned DataSize, uint64_t Value,
|
|
|
|
bool IsPCRel) const {
|
2012-12-17 15:14:54 +00:00
|
|
|
|
|
|
|
uint16_t *Dst = (uint16_t*)(Data + Fixup.getOffset());
|
|
|
|
assert(Fixup.getKind() == FK_PCRel_4);
|
|
|
|
*Dst = (Value - 4) / 4;
|
|
|
|
}
|
2013-04-15 17:51:21 +00:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ELFAMDGPUAsmBackend class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-05-23 15:43:05 +00:00
|
|
|
namespace {
|
|
|
|
|
2013-04-15 17:51:21 +00:00
|
|
|
class ELFAMDGPUAsmBackend : public AMDGPUAsmBackend {
|
|
|
|
public:
|
|
|
|
ELFAMDGPUAsmBackend(const Target &T) : AMDGPUAsmBackend(T) { }
|
|
|
|
|
|
|
|
MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
|
|
|
|
return createAMDGPUELFObjectWriter(OS);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-05-23 15:43:05 +00:00
|
|
|
} // end anonymous namespace
|
|
|
|
|
2013-09-09 02:37:14 +00:00
|
|
|
MCAsmBackend *llvm::createAMDGPUAsmBackend(const Target &T,
|
|
|
|
const MCRegisterInfo &MRI,
|
|
|
|
StringRef TT,
|
2013-04-15 17:51:21 +00:00
|
|
|
StringRef CPU) {
|
|
|
|
return new ELFAMDGPUAsmBackend(T);
|
|
|
|
}
|