blob: ed1d287646c6d0a83a076a23a3377e825041191b [file] [log] [blame]
Evan Cheng148b6a42007-07-05 21:15:40 +00001//===-- ARM/ARMCodeEmitter.cpp - Convert ARM code to machine code ---------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerc3dbe702007-07-17 05:56:43 +00005// This file was developed by the Raul Herbster and is distributed under the
6// University of Illinois Open Source License. See LICENSE.TXT for details.
Evan Cheng148b6a42007-07-05 21:15:40 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file contains the pass that transforms the ARM machine instructions into
11// relocatable machine code.
12//
13//===----------------------------------------------------------------------===//
14
15#define DEBUG_TYPE "arm-emitter"
16#include "ARMInstrInfo.h"
17#include "ARMSubtarget.h"
18#include "ARMTargetMachine.h"
19#include "ARM.h"
20#include "llvm/PassManager.h"
21#include "llvm/CodeGen/MachineCodeEmitter.h"
22#include "llvm/CodeGen/MachineFunctionPass.h"
23#include "llvm/CodeGen/MachineInstr.h"
24#include "llvm/CodeGen/Passes.h"
25#include "llvm/Function.h"
26#include "llvm/ADT/Statistic.h"
27#include "llvm/Support/Compiler.h"
28using namespace llvm;
29
30STATISTIC(NumEmitted, "Number of machine instructions emitted");
31
32namespace {
33 class VISIBILITY_HIDDEN Emitter : public MachineFunctionPass {
34 const ARMInstrInfo *II;
35 const TargetData *TD;
36 TargetMachine &TM;
37 MachineCodeEmitter &MCE;
38 public:
39 static char ID;
40 explicit Emitter(TargetMachine &tm, MachineCodeEmitter &mce)
41 : MachineFunctionPass((intptr_t)&ID), II(0), TD(0), TM(tm),
42 MCE(mce) {}
43 Emitter(TargetMachine &tm, MachineCodeEmitter &mce,
44 const ARMInstrInfo &ii, const TargetData &td)
45 : MachineFunctionPass((intptr_t)&ID), II(&ii), TD(&td), TM(tm),
46 MCE(mce) {}
47
48 bool runOnMachineFunction(MachineFunction &MF);
49
50 virtual const char *getPassName() const {
51 return "ARM Machine Code Emitter";
52 }
53
54 void emitInstruction(const MachineInstr &MI);
55
56 private:
57
58 };
59 char Emitter::ID = 0;
60}
61
62/// createARMCodeEmitterPass - Return a pass that emits the collected ARM code
63/// to the specified MCE object.
64FunctionPass *llvm::createARMCodeEmitterPass(ARMTargetMachine &TM,
65 MachineCodeEmitter &MCE) {
66 return new Emitter(TM, MCE);
67}
68
69bool Emitter::runOnMachineFunction(MachineFunction &MF) {
70 assert((MF.getTarget().getRelocationModel() != Reloc::Default ||
71 MF.getTarget().getRelocationModel() != Reloc::Static) &&
72 "JIT relocation model must be set to static or default!");
73 II = ((ARMTargetMachine&)MF.getTarget()).getInstrInfo();
74 TD = ((ARMTargetMachine&)MF.getTarget()).getTargetData();
75
76 do {
77 MCE.startFunction(MF);
78 for (MachineFunction::iterator MBB = MF.begin(), E = MF.end();
79 MBB != E; ++MBB) {
80 MCE.StartMachineBasicBlock(MBB);
81 for (MachineBasicBlock::const_iterator I = MBB->begin(), E = MBB->end();
82 I != E; ++I)
83 emitInstruction(*I);
84 }
85 } while (MCE.finishFunction(MF));
86
87 return false;
88}
89
90void Emitter::emitInstruction(const MachineInstr &MI) {
91 NumEmitted++; // Keep track of the # of mi's emitted
92}