aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm/CodeGen/InstrSelection.h
blob: 91bc8f2a8cf616f50b3f1df07d67963700062dd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// $Id$ -*-c++-*-
//***************************************************************************
// File:
//	InstrSelection.h
// 
// Purpose:
//	External interface to instruction selection.
// 
// History:
//	7/02/01	 -  Vikram Adve  -  Created
//**************************************************************************/

#ifndef LLVM_CODEGEN_INSTR_SELECTION_H
#define LLVM_CODEGEN_INSTR_SELECTION_H

#include "llvm/Instruction.h"
class Function;
class InstrForest;
class MachineInstr;
class InstructionNode;
class TargetMachine;

/************************* Required Functions *******************************
 * Target-dependent functions that MUST be implemented for each target.
 ***************************************************************************/

const unsigned MAX_INSTR_PER_VMINSTR = 8;

extern void	GetInstructionsByRule	(InstructionNode* subtreeRoot,
					 int ruleForNode,
					 short* nts,
					 TargetMachine &Target,
                                         vector<MachineInstr*>& mvec);

extern unsigned	GetInstructionsForProlog(BasicBlock* entryBB,
					 TargetMachine &Target,
					 MachineInstr** minstrVec);

extern unsigned	GetInstructionsForEpilog(BasicBlock* anExitBB,
					 TargetMachine &Target,
					 MachineInstr** minstrVec);

extern bool	ThisIsAChainRule	(int eruleno);


//************************ Exported Functions ******************************/


//---------------------------------------------------------------------------
// Function: SelectInstructionsForMethod
// 
// Purpose:
//   Entry point for instruction selection using BURG.
//   Returns true if instruction selection failed, false otherwise.
//   Implemented in machine-specific instruction selection file.
//---------------------------------------------------------------------------

bool		SelectInstructionsForMethod	(Function* function,
						 TargetMachine &Target);


//************************ Exported Data Types *****************************/


//---------------------------------------------------------------------------
// class TmpInstruction
//
//   This class represents temporary intermediate values
//   used within the machine code for a VM instruction
//---------------------------------------------------------------------------

class TmpInstruction : public Instruction {
  TmpInstruction(const TmpInstruction &TI)
    : Instruction(TI.getType(), TI.getOpcode()) {
    if (!TI.Operands.empty()) {
      Operands.push_back(Use(TI.Operands[0], this));
      if (TI.Operands.size() == 2)
        Operands.push_back(Use(TI.Operands[1], this));
      else
        assert(0 && "Bad # operands to TmpInstruction!");
    }
  }
public:
  // Constructor that uses the type of S1 as the type of the temporary.
  // s1 must be a valid value.  s2 may be NULL.
  TmpInstruction(Value *s1, Value *s2 = 0, const std::string &name = "")
    : Instruction(s1->getType(), Instruction::UserOp1, name) {
    Operands.push_back(Use(s1, this));  // s1 must be nonnull
    if (s2) {
      Operands.push_back(Use(s2, this));
    }
  }
  
  // Constructor that requires the type of the temporary to be specified.
  // Both S1 and S2 may be NULL.
  TmpInstruction(const Type *Ty, Value *s1 = 0, Value* s2 = 0,
                 const std::string &name = "")
    : Instruction(Ty, Instruction::UserOp1, name) {
    if (s1) { Operands.push_back(Use(s1, this)); }
    if (s2) { Operands.push_back(Use(s2, this)); }
  }
  
  virtual Instruction *clone() const { return new TmpInstruction(*this); }
  virtual const char *getOpcodeName() const {
    return "TempValueForMachineInstr";
  }
  
  // Methods for support type inquiry through isa, cast, and dyn_cast:
  static inline bool classof(const TmpInstruction *) { return true; }
  static inline bool classof(const Instruction *I) {
    return (I->getOpcode() == Instruction::UserOp1);
  }
  static inline bool classof(const Value *V) {
    return isa<Instruction>(V) && classof(cast<Instruction>(V));
  }
};

#endif