Skip to content
This repository was archived by the owner on Sep 2, 2018. It is now read-only.

Commit f308c01

Browse files
author
Dylan McKay
committed
[AVR] Updated to LLVM master
1 parent 08f6111 commit f308c01

12 files changed

+127
-29
lines changed

lib/Target/AVR/AVRBranchSelector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static bool isCondBranch(int Opcode)
7474
bool AVRBSel::runOnMachineFunction(MachineFunction &Fn)
7575
{
7676
const AVRInstrInfo *TII =
77-
static_cast<const AVRInstrInfo *>(Fn.getTarget().getSubtargetImpl()->getInstrInfo());
77+
static_cast<const AVRTargetMachine&>(Fn.getTarget()).getSubtargetImpl()->getInstrInfo();
7878

7979
// Give the blocks of the function a dense, in-order, numbering.
8080
Fn.RenumberBlocks();

lib/Target/AVR/AVRISelDAGToDAG.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ class AVRDAGToDAGISel : public SelectionDAGISel
3333
{
3434
public:
3535
explicit AVRDAGToDAGISel(AVRTargetMachine &tm, CodeGenOpt::Level OptLevel) :
36-
SelectionDAGISel(tm, OptLevel), Subtarget(&tm.getSubtarget<AVRSubtarget>()) {}
36+
SelectionDAGISel(tm, OptLevel), Subtarget(nullptr) {}
3737

3838
const char *getPassName() const
3939
{
4040
return "AVR DAG->DAG Instruction Selection";
4141
}
4242

43+
bool runOnMachineFunction(MachineFunction &MF) override;
44+
4345
// Address Selection.
4446
bool SelectAddr(SDNode *Op, SDValue N, SDValue &Base, SDValue &Disp);
4547
// Indexed load (postinc and predec) matching code.
@@ -61,6 +63,15 @@ class AVRDAGToDAGISel : public SelectionDAGISel
6163

6264
} // end of anonymous namespace
6365

66+
bool
67+
AVRDAGToDAGISel::runOnMachineFunction(MachineFunction &MF) {
68+
69+
Subtarget = &static_cast<const AVRSubtarget &>(MF.getSubtarget());
70+
bool Ret = SelectionDAGISel::runOnMachineFunction(MF);
71+
72+
return Ret;
73+
}
74+
6475
bool
6576
AVRDAGToDAGISel::SelectAddr(SDNode *Op, SDValue N, SDValue &Base, SDValue &Disp)
6677
{

lib/Target/AVR/AVRISelLowering.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,7 @@ AVRTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
11331133
// Add a register mask operand representing the call-preserved registers.
11341134
const AVRTargetMachine& TM = (const AVRTargetMachine&)getTargetMachine();
11351135
const TargetRegisterInfo *TRI = TM.getSubtargetImpl()->getRegisterInfo();
1136-
const uint32_t *Mask = TRI->getCallPreservedMask(CallConv);
1136+
const uint32_t *Mask = TRI->getCallPreservedMask(DAG.getMachineFunction(), CallConv);
11371137
assert(Mask && "Missing call preserved mask for calling convention");
11381138
Ops.push_back(DAG.getRegisterMask(Mask));
11391139

@@ -1644,7 +1644,10 @@ std::pair<unsigned, const TargetRegisterClass *>
16441644
AVRTargetLowering::getRegForInlineAsmConstraint(const std::string &Constraint,
16451645
MVT VT) const
16461646
{
1647+
auto STI = static_cast<const AVRTargetMachine&>(this->getTargetMachine()).getSubtargetImpl();
1648+
16471649
// We only support i8 and i16.
1650+
//
16481651
//:FIXME: remove this assert for now since it gets sometimes executed
16491652
//assert((VT == MVT::i16 || VT == MVT::i8) && "Wrong operand type.");
16501653

@@ -1688,7 +1691,7 @@ AVRTargetLowering::getRegForInlineAsmConstraint(const std::string &Constraint,
16881691
}
16891692
}
16901693

1691-
return TargetLowering::getRegForInlineAsmConstraint(getTargetMachine().getSubtargetImpl()->getRegisterInfo(), Constraint, VT);
1694+
return TargetLowering::getRegForInlineAsmConstraint(STI->getRegisterInfo(), Constraint, VT);
16921695
}
16931696

16941697
void AVRTargetLowering::LowerAsmOperandForConstraint(SDValue Op,

lib/Target/AVR/AVRTargetMachine.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ AVRTargetMachine::AVRTargetMachine(const Target &T, StringRef TT, StringRef CPU,
3131
StringRef FS, const TargetOptions &Options,
3232
Reloc::Model RM, CodeModel::Model CM,
3333
CodeGenOpt::Level OL) :
34-
LLVMTargetMachine(T, TT, CPU.empty() ? DefaultCPU : CPU, FS, Options, RM, CM, OL),
35-
SubTarget(TT, CPU, FS, *this),
36-
DL("e-p:16:8:8-i8:8:8-i16:8:8-i32:8:8-i64:8:8-f32:8:8-f64:8:8-n8")
34+
LLVMTargetMachine(T, "e-p:16:8:8-i8:8:8-i16:8:8-i32:8:8-i64:8:8-f32:8:8-f64:8:8-n8",
35+
TT, CPU.empty() ? DefaultCPU : CPU, FS, Options, RM, CM, OL),
36+
SubTarget(TT, CPU, FS, *this)
3737
{
3838
this->TLOF = make_unique<AVRTargetObjectFile>();
3939
initAsmInfo();
@@ -75,6 +75,11 @@ const AVRSubtarget *AVRTargetMachine::getSubtargetImpl() const
7575
return &SubTarget;
7676
}
7777

78+
const AVRSubtarget *AVRTargetMachine::getSubtargetImpl(const Function&) const
79+
{
80+
return &SubTarget;
81+
}
82+
7883
//===----------------------------------------------------------------------===//
7984
// Pass Pipeline Configuration
8085
//===----------------------------------------------------------------------===//

lib/Target/AVR/AVRTargetMachine.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class AVRTargetMachine : public LLVMTargetMachine
3434
CodeModel::Model CM, CodeGenOpt::Level OL);
3535
public: // TargetMachine
3636

37-
const AVRSubtarget *getSubtargetImpl() const override;
38-
const DataLayout *getDataLayout() const override { return &DL; }
37+
const AVRSubtarget *getSubtargetImpl() const;
38+
const AVRSubtarget *getSubtargetImpl(const Function &) const override;
3939

4040
TargetLoweringObjectFile *getObjFileLowering() const override { return this->TLOF.get(); }
4141

@@ -47,7 +47,6 @@ class AVRTargetMachine : public LLVMTargetMachine
4747
private:
4848
std::unique_ptr<TargetLoweringObjectFile> TLOF;
4949
AVRSubtarget SubTarget;
50-
const DataLayout DL;
5150
};
5251

5352
} // end namespace llvm

lib/Target/AVR/AVRTargetStreamer.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//===-- AVRTargetStreamer.h - AVR Target Streamer ----------*- C++ -*--===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef LLVM_LIB_TARGET_AVR_SPARCTARGETSTREAMER_H
11+
#define LLVM_LIB_TARGET_AVR_SPARCTARGETSTREAMER_H
12+
13+
#include "llvm/MC/MCELFStreamer.h"
14+
#include "llvm/MC/MCStreamer.h"
15+
16+
namespace llvm {
17+
class AVRTargetStreamer : public MCTargetStreamer {
18+
virtual void anchor();
19+
20+
public:
21+
AVRTargetStreamer(MCStreamer &S);
22+
};
23+
24+
// This part is for ascii assembly output
25+
class AVRTargetAsmStreamer : public AVRTargetStreamer {
26+
formatted_raw_ostream &OS;
27+
28+
public:
29+
AVRTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);
30+
};
31+
32+
// This part is for ELF object output
33+
class AVRTargetELFStreamer : public AVRTargetStreamer {
34+
public:
35+
AVRTargetELFStreamer(MCStreamer &S);
36+
MCELFStreamer &getStreamer();
37+
};
38+
} // end namespace llvm
39+
40+
#endif

lib/Target/AVR/MCTargetDesc/AVRMCCodeEmitter.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434

3535
MCCodeEmitter *llvm::createAVRMCCodeEmitter(const MCInstrInfo &MCII,
3636
const MCRegisterInfo &MRI,
37-
const MCSubtargetInfo &STI,
3837
MCContext &Ctx) {
3938
return new AVRMCCodeEmitter(MCII, Ctx, false);
4039
}

lib/Target/AVR/MCTargetDesc/AVRMCExpr.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "AVRMCExpr.h"
1111
#include "llvm/MC/MCAssembler.h"
1212
#include "llvm/MC/MCContext.h"
13+
#include "llvm/MC/MCStreamer.h"
1314

1415
using namespace llvm;
1516

lib/Target/AVR/MCTargetDesc/AVRMCTargetDesc.cpp

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "AVRMCTargetDesc.h"
1515
#include "AVRMCAsmInfo.h"
16+
#include "AVRTargetStreamer.h"
1617
#include "InstPrinter/AVRInstPrinter.h"
1718
#include "llvm/MC/MCCodeGenInfo.h"
1819
#include "llvm/MC/MCInstrInfo.h"
@@ -82,22 +83,23 @@ static MCInstPrinter *createAVRMCInstPrinter(const Target &T,
8283
return 0;
8384
}
8485

85-
static MCStreamer *createMCStreamer(const Target &T, StringRef TT,
86-
MCContext &Context, MCAsmBackend &MAB,
87-
raw_ostream &OS, MCCodeEmitter *Emitter,
88-
const MCSubtargetInfo &STI,
89-
bool RelaxAll) {
86+
static MCStreamer *createMCStreamer(const Triple &T, MCContext &Context,
87+
MCAsmBackend &MAB, raw_ostream &OS,
88+
MCCodeEmitter *Emitter, bool RelaxAll) {
9089
return createELFStreamer(Context, MAB, OS, Emitter, RelaxAll);
9190
}
9291

93-
static MCStreamer *
94-
createMCAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
95-
bool isVerboseAsm,
96-
bool useDwarfDirectory, MCInstPrinter *InstPrint,
97-
MCCodeEmitter *CE, MCAsmBackend *TAB, bool ShowInst) {
98-
return llvm::createAsmStreamer(Ctx, OS, isVerboseAsm,
99-
useDwarfDirectory, InstPrint, CE, TAB,
100-
ShowInst);
92+
static MCTargetStreamer *
93+
createAVRObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) {
94+
95+
return new AVRTargetELFStreamer(S);
96+
}
97+
98+
static MCTargetStreamer *createMCAsmTargetStreamer(MCStreamer &S,
99+
formatted_raw_ostream &OS,
100+
MCInstPrinter *InstPrint,
101+
bool isVerboseAsm) {
102+
return new AVRTargetAsmStreamer(S, OS);
101103
}
102104

103105
extern "C" void LLVMInitializeAVRTargetMC()
@@ -124,12 +126,14 @@ extern "C" void LLVMInitializeAVRTargetMC()
124126
// Register the MC Code Emitter
125127
TargetRegistry::RegisterMCCodeEmitter(TheAVRTarget,
126128
createAVRMCCodeEmitter);
129+
// Register the ELF streamer
130+
TargetRegistry::RegisterELFStreamer(TheAVRTarget, createMCStreamer);
127131

128-
// Register the object streamer.
129-
TargetRegistry::RegisterMCObjectStreamer(TheAVRTarget, createMCStreamer);
132+
// Register the obj target streamer.
133+
TargetRegistry::RegisterObjectTargetStreamer(TheAVRTarget, createAVRObjectTargetStreamer);
130134

131-
// Register the asm streamer.
132-
TargetRegistry::RegisterAsmStreamer(TheAVRTarget, createMCAsmStreamer);
135+
// Register the asm target streamer.
136+
TargetRegistry::RegisterAsmTargetStreamer(TheAVRTarget, createMCAsmTargetStreamer);
133137

134138
// Register the asm backend (as little endian).
135139
TargetRegistry::RegisterMCAsmBackend(TheAVRTarget,

lib/Target/AVR/MCTargetDesc/AVRMCTargetDesc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ namespace llvm
2727
class MCContext;
2828
class StringRef;
2929
class Target;
30+
class MCStreamer;
31+
class MCTargetStreamer;
3032
class raw_ostream;
3133

3234
extern Target TheAVRTarget;
3335

3436

3537
MCCodeEmitter *createAVRMCCodeEmitter(const MCInstrInfo &MCII,
3638
const MCRegisterInfo &MRI,
37-
const MCSubtargetInfo &STI,
3839
MCContext &Ctx);
3940
/*!
4041
* \brief Creates a little endian AVR assembly backend.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//===-- AVRTargetStreamer.cpp - AVR Target Streamer Methods -----------===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
//
10+
// This file provides AVR specific target streamer methods.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#include "AVRTargetStreamer.h"
15+
#include "InstPrinter/AVRInstPrinter.h"
16+
#include "llvm/Support/FormattedStream.h"
17+
18+
using namespace llvm;
19+
20+
// pin vtable to this file
21+
AVRTargetStreamer::AVRTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {}
22+
23+
void AVRTargetStreamer::anchor() {}
24+
25+
AVRTargetAsmStreamer::AVRTargetAsmStreamer(MCStreamer &S,
26+
formatted_raw_ostream &OS)
27+
: AVRTargetStreamer(S), OS(OS) {}
28+
29+
AVRTargetELFStreamer::AVRTargetELFStreamer(MCStreamer &S)
30+
: AVRTargetStreamer(S) {}
31+
32+
MCELFStreamer &AVRTargetELFStreamer::getStreamer() {
33+
return static_cast<MCELFStreamer &>(Streamer);
34+
}

lib/Target/AVR/MCTargetDesc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ add_llvm_library(LLVMAVRDesc
55
AVRAsmBackend.cpp
66
AVRELFObjectWriter.cpp
77
AVRMCCodeEmitter.cpp
8+
AVRTargetStreamer.cpp
89
)
910

1011
add_dependencies(LLVMAVRDesc AVRCommonTableGen)

0 commit comments

Comments
 (0)