Skip to content

Commit 227144c

Browse files
committed
Remove the MachineMove class.
It was just a less powerful and more confusing version of MCCFIInstruction. A side effect is that, since MCCFIInstruction uses dwarf register numbers, calls to getDwarfRegNum are pushed out, which should allow further simplifications. I left the MachineModuleInfo::addFrameMove interface unchanged since this patch was already fairly big. llvm-svn: 181680
1 parent c6e16af commit 227144c

38 files changed

+169
-177
lines changed

Diff for: llvm/include/llvm/CodeGen/AsmPrinter.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ namespace llvm {
3838
class MachineConstantPoolValue;
3939
class MachineJumpTableInfo;
4040
class MachineModuleInfo;
41-
class MachineMove;
4241
class MCAsmInfo;
42+
class MCCFIInstruction;
4343
class MCContext;
4444
class MCSection;
4545
class MCStreamer;
@@ -417,9 +417,8 @@ namespace llvm {
417417
// Dwarf Lowering Routines
418418
//===------------------------------------------------------------------===//
419419

420-
/// EmitCFIFrameMove - Emit frame instruction to describe the layout of the
421-
/// frame.
422-
void EmitCFIFrameMove(const MachineMove &Move) const;
420+
/// \brief Emit frame instruction to describe the layout of the frame.
421+
void emitCFIInstruction(const MCCFIInstruction &Inst) const;
423422

424423
//===------------------------------------------------------------------===//
425424
// Inline Asm Support

Diff for: llvm/include/llvm/CodeGen/MachineModuleInfo.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ class MachineModuleInfo : public ImmutablePass {
106106
/// want.
107107
MachineModuleInfoImpl *ObjFileMMI;
108108

109-
/// FrameMoves - List of moves done by a function's prolog. Used to construct
110-
/// frame maps by debug and exception handling consumers.
111-
std::vector<MachineMove> FrameMoves;
109+
/// List of moves done by a function's prolog. Used to construct frame maps
110+
/// by debug and exception handling consumers.
111+
std::vector<MCCFIInstruction> FrameInstructions;
112112

113113
/// CompactUnwindEncoding - If the target supports it, this is the compact
114114
/// unwind encoding. It replaces a function's CIE and FDE.
@@ -231,15 +231,15 @@ class MachineModuleInfo : public ImmutablePass {
231231
UsesVAFloatArgument = b;
232232
}
233233

234-
/// getFrameMoves - Returns a reference to a list of moves done in the current
234+
/// \brief Returns a reference to a list of cfi instructions in the current
235235
/// function's prologue. Used to construct frame maps for debug and exception
236236
/// handling comsumers.
237-
const std::vector<MachineMove> &getFrameMoves() { return FrameMoves; }
237+
const std::vector<MCCFIInstruction> &getFrameInstructions() {
238+
return FrameInstructions;
239+
}
238240

239241
void addFrameMove(MCSymbol *Label, const MachineLocation &Dst,
240-
const MachineLocation &Src) {
241-
FrameMoves.push_back(MachineMove(Label, Dst, Src));
242-
}
242+
const MachineLocation &Src);
243243

244244
/// getCompactUnwindEncoding - Returns the compact unwind encoding for a
245245
/// function if the target supports the encoding. This encoding replaces a

Diff for: llvm/include/llvm/MC/MCAsmInfo.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define LLVM_MC_MCASMINFO_H
1818

1919
#include "llvm/MC/MCDirectives.h"
20+
#include "llvm/MC/MCDwarf.h"
2021
#include "llvm/MC/MachineLocation.h"
2122
#include <cassert>
2223
#include <vector>
@@ -332,7 +333,7 @@ namespace llvm {
332333

333334
//===--- Prologue State ----------------------------------------------===//
334335

335-
std::vector<MachineMove> InitialFrameState;
336+
std::vector<MCCFIInstruction> InitialFrameState;
336337

337338
public:
338339
explicit MCAsmInfo();
@@ -567,11 +568,11 @@ namespace llvm {
567568
return DwarfRegNumForCFI;
568569
}
569570

570-
void addInitialFrameState(MCSymbol *label, const MachineLocation &D,
571-
const MachineLocation &S) {
572-
InitialFrameState.push_back(MachineMove(label, D, S));
571+
void addInitialFrameState(const MCCFIInstruction &Inst) {
572+
InitialFrameState.push_back(Inst);
573573
}
574-
const std::vector<MachineMove> &getInitialFrameState() const {
574+
575+
const std::vector<MCCFIInstruction> &getInitialFrameState() const {
575576
return InitialFrameState;
576577
}
577578
};

Diff for: llvm/include/llvm/MC/MachineLocation.h

-29
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
// frame. Locations will be one of two forms; a register or an address formed
1111
// from a base address plus an offset. Register indirection can be specified by
1212
// explicitly passing an offset to the constructor.
13-
//
14-
// The MachineMove class is used to represent abstract move operations in the
15-
// prolog/epilog of a compiled function. A collection of these objects can be
16-
// used by a debug consumer to track the location of values when unwinding stack
17-
// frames.
1813
//===----------------------------------------------------------------------===//
1914

2015

@@ -74,30 +69,6 @@ class MachineLocation {
7469
void dump();
7570
#endif
7671
};
77-
78-
/// MachineMove - This class represents the save or restore of a callee saved
79-
/// register that exception or debug info needs to know about.
80-
class MachineMove {
81-
private:
82-
/// Label - Symbol for post-instruction address when result of move takes
83-
/// effect.
84-
MCSymbol *Label;
85-
86-
// Move to & from location.
87-
MachineLocation Destination, Source;
88-
public:
89-
MachineMove() : Label(0) {}
90-
91-
MachineMove(MCSymbol *label, const MachineLocation &D,
92-
const MachineLocation &S)
93-
: Label(label), Destination(D), Source(S) {}
94-
95-
// Accessors
96-
MCSymbol *getLabel() const { return Label; }
97-
const MachineLocation &getDestination() const { return Destination; }
98-
const MachineLocation &getSource() const { return Source; }
99-
};
100-
10172
} // End llvm namespace
10273

10374
#endif

Diff for: llvm/include/llvm/Support/TargetRegistry.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ namespace llvm {
7070

7171
typedef unsigned (*TripleMatchQualityFnTy)(const std::string &TT);
7272

73-
typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(StringRef TT);
73+
typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const MCRegisterInfo &MRI,
74+
StringRef TT);
7475
typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT,
7576
Reloc::Model RM,
7677
CodeModel::Model CM,
@@ -265,10 +266,11 @@ namespace llvm {
265266
/// feature set; it should always be provided. Generally this should be
266267
/// either the target triple from the module, or the target triple of the
267268
/// host if that does not exist.
268-
MCAsmInfo *createMCAsmInfo(StringRef Triple) const {
269+
MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
270+
StringRef Triple) const {
269271
if (!MCAsmInfoCtorFn)
270272
return 0;
271-
return MCAsmInfoCtorFn(Triple);
273+
return MCAsmInfoCtorFn(MRI, Triple);
272274
}
273275

274276
/// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
@@ -803,7 +805,7 @@ namespace llvm {
803805
TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
804806
}
805807
private:
806-
static MCAsmInfo *Allocator(StringRef TT) {
808+
static MCAsmInfo *Allocator(const MCRegisterInfo &MRI, StringRef TT) {
807809
return new MCAsmInfoImpl(TT);
808810
}
809811

Diff for: llvm/include/llvm/Target/TargetMachine.h

+1
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ class LLVMTargetMachine : public TargetMachine {
292292
Reloc::Model RM, CodeModel::Model CM,
293293
CodeGenOpt::Level OL);
294294

295+
void initAsmInfo();
295296
public:
296297
/// \brief Register analysis passes for this target with a pass manager.
297298
///

Diff for: llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -636,14 +636,13 @@ void AsmPrinter::emitPrologLabel(const MachineInstr &MI) {
636636
OutStreamer.EmitCompactUnwindEncoding(MMI->getCompactUnwindEncoding());
637637

638638
MachineModuleInfo &MMI = MF->getMMI();
639-
const std::vector<MachineMove> &Moves = MMI.getFrameMoves();
639+
std::vector<MCCFIInstruction> Instructions = MMI.getFrameInstructions();
640640
bool FoundOne = false;
641641
(void)FoundOne;
642-
for (std::vector<MachineMove>::const_iterator I = Moves.begin(),
643-
E = Moves.end();
644-
I != E; ++I) {
642+
for (std::vector<MCCFIInstruction>::iterator I = Instructions.begin(),
643+
E = Instructions.end(); I != E; ++I) {
645644
if (I->getLabel() == Label) {
646-
EmitCFIFrameMove(*I);
645+
emitCFIInstruction(*I);
647646
FoundOne = true;
648647
}
649648
}

Diff for: llvm/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp

+16-23
Original file line numberDiff line numberDiff line change
@@ -169,28 +169,21 @@ void AsmPrinter::EmitSectionOffset(const MCSymbol *Label,
169169
// Dwarf Lowering Routines
170170
//===----------------------------------------------------------------------===//
171171

172-
/// EmitCFIFrameMove - Emit a frame instruction.
173-
void AsmPrinter::EmitCFIFrameMove(const MachineMove &Move) const {
174-
const TargetRegisterInfo *RI = TM.getRegisterInfo();
175-
176-
const MachineLocation &Dst = Move.getDestination();
177-
const MachineLocation &Src = Move.getSource();
178-
179-
// If advancing cfa.
180-
if (Dst.isReg() && Dst.getReg() == MachineLocation::VirtualFP) {
181-
if (Src.getReg() == MachineLocation::VirtualFP) {
182-
OutStreamer.EmitCFIDefCfaOffset(-Src.getOffset());
183-
} else {
184-
// Reg + Offset
185-
OutStreamer.EmitCFIDefCfa(RI->getDwarfRegNum(Src.getReg(), true),
186-
Src.getOffset());
187-
}
188-
} else if (Src.isReg() && Src.getReg() == MachineLocation::VirtualFP) {
189-
assert(Dst.isReg() && "Machine move not supported yet.");
190-
OutStreamer.EmitCFIDefCfaRegister(RI->getDwarfRegNum(Dst.getReg(), true));
191-
} else {
192-
assert(!Dst.isReg() && "Machine move not supported yet.");
193-
OutStreamer.EmitCFIOffset(RI->getDwarfRegNum(Src.getReg(), true),
194-
Dst.getOffset());
172+
void AsmPrinter::emitCFIInstruction(const MCCFIInstruction &Inst) const {
173+
switch (Inst.getOperation()) {
174+
default:
175+
llvm_unreachable("Unexpected instruction");
176+
case MCCFIInstruction::OpDefCfaOffset:
177+
OutStreamer.EmitCFIDefCfaOffset(Inst.getOffset());
178+
break;
179+
case MCCFIInstruction::OpDefCfa:
180+
OutStreamer.EmitCFIDefCfa(Inst.getRegister(), Inst.getOffset());
181+
break;
182+
case MCCFIInstruction::OpDefCfaRegister:
183+
OutStreamer.EmitCFIDefCfaRegister(Inst.getRegister());
184+
break;
185+
case MCCFIInstruction::OpOffset:
186+
OutStreamer.EmitCFIOffset(Inst.getRegister(), Inst.getOffset());
187+
break;
195188
}
196189
}

Diff for: llvm/lib/CodeGen/AsmPrinter/DwarfException.h

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ namespace llvm {
2323
template <typename T> class SmallVectorImpl;
2424
struct LandingPadInfo;
2525
class MachineModuleInfo;
26-
class MachineMove;
2726
class MachineInstr;
2827
class MachineFunction;
2928
class MCAsmInfo;

Diff for: llvm/lib/CodeGen/LLVMTargetMachine.cpp

+11-8
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,8 @@ static bool getVerboseAsm() {
6262
llvm_unreachable("Invalid verbose asm state");
6363
}
6464

65-
LLVMTargetMachine::LLVMTargetMachine(const Target &T, StringRef Triple,
66-
StringRef CPU, StringRef FS,
67-
TargetOptions Options,
68-
Reloc::Model RM, CodeModel::Model CM,
69-
CodeGenOpt::Level OL)
70-
: TargetMachine(T, Triple, CPU, FS, Options) {
71-
CodeGenInfo = T.createMCCodeGenInfo(Triple, RM, CM, OL);
72-
AsmInfo = T.createMCAsmInfo(Triple);
65+
void LLVMTargetMachine::initAsmInfo() {
66+
AsmInfo = TheTarget.createMCAsmInfo(*getRegisterInfo(), TargetTriple);
7367
// TargetSelect.h moved to a different directory between LLVM 2.9 and 3.0,
7468
// and if the old one gets included then MCAsmInfo will be NULL and
7569
// we'll crash later.
@@ -79,6 +73,15 @@ LLVMTargetMachine::LLVMTargetMachine(const Target &T, StringRef Triple,
7973
"and that InitializeAllTargetMCs() is being invoked!");
8074
}
8175

76+
LLVMTargetMachine::LLVMTargetMachine(const Target &T, StringRef Triple,
77+
StringRef CPU, StringRef FS,
78+
TargetOptions Options,
79+
Reloc::Model RM, CodeModel::Model CM,
80+
CodeGenOpt::Level OL)
81+
: TargetMachine(T, Triple, CPU, FS, Options) {
82+
CodeGenInfo = T.createMCCodeGenInfo(Triple, RM, CM, OL);
83+
}
84+
8285
void LLVMTargetMachine::addAnalysisPasses(PassManagerBase &PM) {
8386
PM.add(createBasicTargetTransformInfoPass(getTargetLowering()));
8487
}

Diff for: llvm/lib/CodeGen/MachineModuleInfo.cpp

+34-1
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,39 @@ MachineModuleInfo::MachineModuleInfo()
268268
MachineModuleInfo::~MachineModuleInfo() {
269269
}
270270

271+
static MCCFIInstruction convertMoveToCFI(const MCRegisterInfo &MRI,
272+
MCSymbol *Label,
273+
const MachineLocation &Dst,
274+
const MachineLocation &Src) {
275+
// If advancing cfa.
276+
if (Dst.isReg() && Dst.getReg() == MachineLocation::VirtualFP) {
277+
if (Src.getReg() == MachineLocation::VirtualFP)
278+
return MCCFIInstruction::createDefCfaOffset(Label, Src.getOffset());
279+
// Reg + Offset
280+
return MCCFIInstruction::createDefCfa(
281+
Label, MRI.getDwarfRegNum(Src.getReg(), true), -Src.getOffset());
282+
}
283+
284+
if (Src.isReg() && Src.getReg() == MachineLocation::VirtualFP) {
285+
assert(Dst.isReg() && "Machine move not supported yet.");
286+
return MCCFIInstruction::createDefCfaRegister(
287+
Label, MRI.getDwarfRegNum(Dst.getReg(), true));
288+
}
289+
290+
assert(!Dst.isReg() && "Machine move not supported yet.");
291+
return MCCFIInstruction::createOffset(
292+
Label, MRI.getDwarfRegNum(Src.getReg(), true), Dst.getOffset());
293+
}
294+
295+
296+
void MachineModuleInfo::addFrameMove(MCSymbol *Label,
297+
const MachineLocation &Dst,
298+
const MachineLocation &Src) {
299+
MCCFIInstruction I =
300+
convertMoveToCFI(Context.getRegisterInfo(), Label, Dst, Src);
301+
FrameInstructions.push_back(I);
302+
}
303+
271304
bool MachineModuleInfo::doInitialization(Module &M) {
272305

273306
ObjFileMMI = 0;
@@ -303,7 +336,7 @@ bool MachineModuleInfo::doFinalization(Module &M) {
303336
///
304337
void MachineModuleInfo::EndFunction() {
305338
// Clean up frame info.
306-
FrameMoves.clear();
339+
FrameInstructions.clear();
307340

308341
// Clean up exception info.
309342
LandingPads.clear();

Diff for: llvm/lib/MC/MCDisassembler/Disassembler.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,19 @@ LLVMDisasmContextRef LLVMCreateDisasmCPU(const char *Triple, const char *CPU,
4242
const Target *TheTarget = TargetRegistry::lookupTarget(Triple, Error);
4343
assert(TheTarget && "Unable to create target!");
4444

45+
const MCRegisterInfo *MRI = TheTarget->createMCRegInfo(Triple);
46+
if (!MRI)
47+
return 0;
48+
4549
// Get the assembler info needed to setup the MCContext.
46-
const MCAsmInfo *MAI = TheTarget->createMCAsmInfo(Triple);
50+
const MCAsmInfo *MAI = TheTarget->createMCAsmInfo(*MRI, Triple);
4751
if (!MAI)
4852
return 0;
4953

5054
const MCInstrInfo *MII = TheTarget->createMCInstrInfo();
5155
if (!MII)
5256
return 0;
5357

54-
const MCRegisterInfo *MRI = TheTarget->createMCRegInfo(Triple);
55-
if (!MRI)
56-
return 0;
57-
5858
// Package up features to be passed to target/subtarget
5959
std::string FeaturesStr;
6060

0 commit comments

Comments
 (0)