~louis/ubuntu/trusty/clamav/lp799623_fix_logrotate

« back to all changes in this revision

Viewing changes to libclamav/c++/llvm/utils/TableGen/CodeGenDAGPatterns.h

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-03-12 11:30:04 UTC
  • mfrom: (0.41.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100312113004-b0fop4bkycszdd0z
Tags: 0.96~rc1+dfsg-0ubuntu1
* New upstream RC - FFE (LP: #537636):
  - Add OfficialDatabaseOnly option to clamav-base.postinst.in
  - Add LocalSocketGroup option to clamav-base.postinst.in
  - Add LocalSocketMode option to clamav-base.postinst.in
  - Add CrossFilesystems option to clamav-base.postinst.in
  - Add ClamukoScannerCount option to clamav-base.postinst.in
  - Add BytecodeSecurity opiton to clamav-base.postinst.in
  - Add DetectionStatsHostID option to clamav-freshclam.postinst.in
  - Add Bytecode option to clamav-freshclam.postinst.in
  - Add MilterSocketGroup option to clamav-milter.postinst.in
  - Add MilterSocketMode option to clamav-milter.postinst.in
  - Add ReportHostname option to clamav-milter.postinst.in
  - Bump libclamav SO version to 6.1.0 in libclamav6.install
  - Drop clamdmon from clamav.examples (no longer shipped by upstream)
  - Drop libclamav.a from libclamav-dev.install (not built by upstream)
  - Update SO version for lintian override for libclamav6
  - Add new Bytecode Testing Tool, usr/bin/clambc, to clamav.install
  - Add build-depends on python and python-setuptools for new test suite
  - Update debian/copyright for the embedded copy of llvm (using the system
    llvm is not currently feasible)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//===- CodeGenDAGPatterns.h - Read DAG patterns from .td file ---*- 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
// This file declares the CodeGenDAGPatterns class, which is used to read and
 
11
// represent the patterns present in a .td file for instructions.
 
12
//
 
13
//===----------------------------------------------------------------------===//
 
14
 
 
15
#ifndef CODEGEN_DAGPATTERNS_H
 
16
#define CODEGEN_DAGPATTERNS_H
 
17
 
 
18
#include <set>
 
19
#include <algorithm>
 
20
#include <vector>
 
21
 
 
22
#include "CodeGenTarget.h"
 
23
#include "CodeGenIntrinsics.h"
 
24
 
 
25
namespace llvm {
 
26
  class Record;
 
27
  struct Init;
 
28
  class ListInit;
 
29
  class DagInit;
 
30
  class SDNodeInfo;
 
31
  class TreePattern;
 
32
  class TreePatternNode;
 
33
  class CodeGenDAGPatterns;
 
34
  class ComplexPattern;
 
35
 
 
36
/// EEVT::DAGISelGenValueType - These are some extended forms of
 
37
/// MVT::SimpleValueType that we use as lattice values during type inference.
 
38
/// The existing MVT iAny, fAny and vAny types suffice to represent
 
39
/// arbitrary integer, floating-point, and vector types, so only an unknown
 
40
/// value is needed.
 
41
namespace EEVT {
 
42
  enum DAGISelGenValueType {
 
43
    isUnknown  = MVT::LAST_VALUETYPE
 
44
  };
 
45
 
 
46
  /// isExtIntegerInVTs - Return true if the specified extended value type
 
47
  /// vector contains iAny or an integer value type.
 
48
  bool isExtIntegerInVTs(const std::vector<unsigned char> &EVTs);
 
49
 
 
50
  /// isExtFloatingPointInVTs - Return true if the specified extended value
 
51
  /// type vector contains fAny or a FP value type.
 
52
  bool isExtFloatingPointInVTs(const std::vector<unsigned char> &EVTs);
 
53
 
 
54
  /// isExtVectorinVTs - Return true if the specified extended value type 
 
55
  /// vector contains vAny or a vector value type.
 
56
  bool isExtVectorInVTs(const std::vector<unsigned char> &EVTs);
 
57
}
 
58
 
 
59
/// Set type used to track multiply used variables in patterns
 
60
typedef std::set<std::string> MultipleUseVarSet;
 
61
 
 
62
/// SDTypeConstraint - This is a discriminated union of constraints,
 
63
/// corresponding to the SDTypeConstraint tablegen class in Target.td.
 
64
struct SDTypeConstraint {
 
65
  SDTypeConstraint(Record *R);
 
66
  
 
67
  unsigned OperandNo;   // The operand # this constraint applies to.
 
68
  enum { 
 
69
    SDTCisVT, SDTCisPtrTy, SDTCisInt, SDTCisFP, SDTCisVec, SDTCisSameAs, 
 
70
    SDTCisVTSmallerThanOp, SDTCisOpSmallerThanOp, SDTCisEltOfVec
 
71
  } ConstraintType;
 
72
  
 
73
  union {   // The discriminated union.
 
74
    struct {
 
75
      unsigned char VT;
 
76
    } SDTCisVT_Info;
 
77
    struct {
 
78
      unsigned OtherOperandNum;
 
79
    } SDTCisSameAs_Info;
 
80
    struct {
 
81
      unsigned OtherOperandNum;
 
82
    } SDTCisVTSmallerThanOp_Info;
 
83
    struct {
 
84
      unsigned BigOperandNum;
 
85
    } SDTCisOpSmallerThanOp_Info;
 
86
    struct {
 
87
      unsigned OtherOperandNum;
 
88
    } SDTCisEltOfVec_Info;
 
89
  } x;
 
90
 
 
91
  /// ApplyTypeConstraint - Given a node in a pattern, apply this type
 
92
  /// constraint to the nodes operands.  This returns true if it makes a
 
93
  /// change, false otherwise.  If a type contradiction is found, throw an
 
94
  /// exception.
 
95
  bool ApplyTypeConstraint(TreePatternNode *N, const SDNodeInfo &NodeInfo,
 
96
                           TreePattern &TP) const;
 
97
  
 
98
  /// getOperandNum - Return the node corresponding to operand #OpNo in tree
 
99
  /// N, which has NumResults results.
 
100
  TreePatternNode *getOperandNum(unsigned OpNo, TreePatternNode *N,
 
101
                                 unsigned NumResults) const;
 
102
};
 
103
 
 
104
/// SDNodeInfo - One of these records is created for each SDNode instance in
 
105
/// the target .td file.  This represents the various dag nodes we will be
 
106
/// processing.
 
107
class SDNodeInfo {
 
108
  Record *Def;
 
109
  std::string EnumName;
 
110
  std::string SDClassName;
 
111
  unsigned Properties;
 
112
  unsigned NumResults;
 
113
  int NumOperands;
 
114
  std::vector<SDTypeConstraint> TypeConstraints;
 
115
public:
 
116
  SDNodeInfo(Record *R);  // Parse the specified record.
 
117
  
 
118
  unsigned getNumResults() const { return NumResults; }
 
119
  int getNumOperands() const { return NumOperands; }
 
120
  Record *getRecord() const { return Def; }
 
121
  const std::string &getEnumName() const { return EnumName; }
 
122
  const std::string &getSDClassName() const { return SDClassName; }
 
123
  
 
124
  const std::vector<SDTypeConstraint> &getTypeConstraints() const {
 
125
    return TypeConstraints;
 
126
  }
 
127
  
 
128
  /// getKnownType - If the type constraints on this node imply a fixed type
 
129
  /// (e.g. all stores return void, etc), then return it as an
 
130
  /// MVT::SimpleValueType.  Otherwise, return EEVT::isUnknown.
 
131
  unsigned getKnownType() const;
 
132
  
 
133
  /// hasProperty - Return true if this node has the specified property.
 
134
  ///
 
135
  bool hasProperty(enum SDNP Prop) const { return Properties & (1 << Prop); }
 
136
 
 
137
  /// ApplyTypeConstraints - Given a node in a pattern, apply the type
 
138
  /// constraints for this node to the operands of the node.  This returns
 
139
  /// true if it makes a change, false otherwise.  If a type contradiction is
 
140
  /// found, throw an exception.
 
141
  bool ApplyTypeConstraints(TreePatternNode *N, TreePattern &TP) const {
 
142
    bool MadeChange = false;
 
143
    for (unsigned i = 0, e = TypeConstraints.size(); i != e; ++i)
 
144
      MadeChange |= TypeConstraints[i].ApplyTypeConstraint(N, *this, TP);
 
145
    return MadeChange;
 
146
  }
 
147
};
 
148
 
 
149
/// FIXME: TreePatternNode's can be shared in some cases (due to dag-shaped
 
150
/// patterns), and as such should be ref counted.  We currently just leak all
 
151
/// TreePatternNode objects!
 
152
class TreePatternNode {
 
153
  /// The inferred type for this node, or EEVT::isUnknown if it hasn't
 
154
  /// been determined yet. This is a std::vector because during inference
 
155
  /// there may be multiple possible types.
 
156
  std::vector<unsigned char> Types;
 
157
  
 
158
  /// Operator - The Record for the operator if this is an interior node (not
 
159
  /// a leaf).
 
160
  Record *Operator;
 
161
  
 
162
  /// Val - The init value (e.g. the "GPRC" record, or "7") for a leaf.
 
163
  ///
 
164
  Init *Val;
 
165
  
 
166
  /// Name - The name given to this node with the :$foo notation.
 
167
  ///
 
168
  std::string Name;
 
169
  
 
170
  /// PredicateFns - The predicate functions to execute on this node to check
 
171
  /// for a match.  If this list is empty, no predicate is involved.
 
172
  std::vector<std::string> PredicateFns;
 
173
  
 
174
  /// TransformFn - The transformation function to execute on this node before
 
175
  /// it can be substituted into the resulting instruction on a pattern match.
 
176
  Record *TransformFn;
 
177
  
 
178
  std::vector<TreePatternNode*> Children;
 
179
public:
 
180
  TreePatternNode(Record *Op, const std::vector<TreePatternNode*> &Ch) 
 
181
    : Types(), Operator(Op), Val(0), TransformFn(0),
 
182
    Children(Ch) { Types.push_back(EEVT::isUnknown); }
 
183
  TreePatternNode(Init *val)    // leaf ctor
 
184
    : Types(), Operator(0), Val(val), TransformFn(0) {
 
185
    Types.push_back(EEVT::isUnknown);
 
186
  }
 
187
  ~TreePatternNode();
 
188
  
 
189
  const std::string &getName() const { return Name; }
 
190
  void setName(const std::string &N) { Name = N; }
 
191
  
 
192
  bool isLeaf() const { return Val != 0; }
 
193
  bool hasTypeSet() const {
 
194
    return (Types[0] < MVT::LAST_VALUETYPE) || (Types[0] == MVT::iPTR) || 
 
195
          (Types[0] == MVT::iPTRAny);
 
196
  }
 
197
  bool isTypeCompletelyUnknown() const {
 
198
    return Types[0] == EEVT::isUnknown;
 
199
  }
 
200
  bool isTypeDynamicallyResolved() const {
 
201
    return (Types[0] == MVT::iPTR) || (Types[0] == MVT::iPTRAny);
 
202
  }
 
203
  MVT::SimpleValueType getTypeNum(unsigned Num) const {
 
204
    assert(hasTypeSet() && "Doesn't have a type yet!");
 
205
    assert(Types.size() > Num && "Type num out of range!");
 
206
    return (MVT::SimpleValueType)Types[Num];
 
207
  }
 
208
  unsigned char getExtTypeNum(unsigned Num) const { 
 
209
    assert(Types.size() > Num && "Extended type num out of range!");
 
210
    return Types[Num]; 
 
211
  }
 
212
  const std::vector<unsigned char> &getExtTypes() const { return Types; }
 
213
  void setTypes(const std::vector<unsigned char> &T) { Types = T; }
 
214
  void removeTypes() { Types = std::vector<unsigned char>(1, EEVT::isUnknown); }
 
215
  
 
216
  Init *getLeafValue() const { assert(isLeaf()); return Val; }
 
217
  Record *getOperator() const { assert(!isLeaf()); return Operator; }
 
218
  
 
219
  unsigned getNumChildren() const { return Children.size(); }
 
220
  TreePatternNode *getChild(unsigned N) const { return Children[N]; }
 
221
  void setChild(unsigned i, TreePatternNode *N) {
 
222
    Children[i] = N;
 
223
  }
 
224
  
 
225
  /// hasChild - Return true if N is any of our children.
 
226
  bool hasChild(const TreePatternNode *N) const {
 
227
    for (unsigned i = 0, e = Children.size(); i != e; ++i)
 
228
      if (Children[i] == N) return true;
 
229
    return false;
 
230
  }
 
231
 
 
232
  const std::vector<std::string> &getPredicateFns() const {return PredicateFns;}
 
233
  void clearPredicateFns() { PredicateFns.clear(); }
 
234
  void setPredicateFns(const std::vector<std::string> &Fns) {
 
235
    assert(PredicateFns.empty() && "Overwriting non-empty predicate list!");
 
236
    PredicateFns = Fns;
 
237
  }
 
238
  void addPredicateFn(const std::string &Fn) { 
 
239
    assert(!Fn.empty() && "Empty predicate string!");
 
240
    if (std::find(PredicateFns.begin(), PredicateFns.end(), Fn) ==
 
241
          PredicateFns.end())
 
242
      PredicateFns.push_back(Fn);
 
243
  }
 
244
 
 
245
  Record *getTransformFn() const { return TransformFn; }
 
246
  void setTransformFn(Record *Fn) { TransformFn = Fn; }
 
247
  
 
248
  /// getIntrinsicInfo - If this node corresponds to an intrinsic, return the
 
249
  /// CodeGenIntrinsic information for it, otherwise return a null pointer.
 
250
  const CodeGenIntrinsic *getIntrinsicInfo(const CodeGenDAGPatterns &CDP) const;
 
251
 
 
252
  /// getComplexPatternInfo - If this node corresponds to a ComplexPattern,
 
253
  /// return the ComplexPattern information, otherwise return null.
 
254
  const ComplexPattern *
 
255
  getComplexPatternInfo(const CodeGenDAGPatterns &CGP) const;
 
256
 
 
257
  /// NodeHasProperty - Return true if this node has the specified property.
 
258
  bool NodeHasProperty(SDNP Property, const CodeGenDAGPatterns &CGP) const;
 
259
  
 
260
  /// TreeHasProperty - Return true if any node in this tree has the specified
 
261
  /// property.
 
262
  bool TreeHasProperty(SDNP Property, const CodeGenDAGPatterns &CGP) const;
 
263
  
 
264
  /// isCommutativeIntrinsic - Return true if the node is an intrinsic which is
 
265
  /// marked isCommutative.
 
266
  bool isCommutativeIntrinsic(const CodeGenDAGPatterns &CDP) const;
 
267
  
 
268
  void print(raw_ostream &OS) const;
 
269
  void dump() const;
 
270
  
 
271
public:   // Higher level manipulation routines.
 
272
 
 
273
  /// clone - Return a new copy of this tree.
 
274
  ///
 
275
  TreePatternNode *clone() const;
 
276
 
 
277
  /// RemoveAllTypes - Recursively strip all the types of this tree.
 
278
  void RemoveAllTypes();
 
279
  
 
280
  /// isIsomorphicTo - Return true if this node is recursively isomorphic to
 
281
  /// the specified node.  For this comparison, all of the state of the node
 
282
  /// is considered, except for the assigned name.  Nodes with differing names
 
283
  /// that are otherwise identical are considered isomorphic.
 
284
  bool isIsomorphicTo(const TreePatternNode *N,
 
285
                      const MultipleUseVarSet &DepVars) const;
 
286
  
 
287
  /// SubstituteFormalArguments - Replace the formal arguments in this tree
 
288
  /// with actual values specified by ArgMap.
 
289
  void SubstituteFormalArguments(std::map<std::string,
 
290
                                          TreePatternNode*> &ArgMap);
 
291
 
 
292
  /// InlinePatternFragments - If this pattern refers to any pattern
 
293
  /// fragments, inline them into place, giving us a pattern without any
 
294
  /// PatFrag references.
 
295
  TreePatternNode *InlinePatternFragments(TreePattern &TP);
 
296
  
 
297
  /// ApplyTypeConstraints - Apply all of the type constraints relevant to
 
298
  /// this node and its children in the tree.  This returns true if it makes a
 
299
  /// change, false otherwise.  If a type contradiction is found, throw an
 
300
  /// exception.
 
301
  bool ApplyTypeConstraints(TreePattern &TP, bool NotRegisters);
 
302
  
 
303
  /// UpdateNodeType - Set the node type of N to VT if VT contains
 
304
  /// information.  If N already contains a conflicting type, then throw an
 
305
  /// exception.  This returns true if any information was updated.
 
306
  ///
 
307
  bool UpdateNodeType(const std::vector<unsigned char> &ExtVTs,
 
308
                      TreePattern &TP);
 
309
  bool UpdateNodeType(unsigned char ExtVT, TreePattern &TP) {
 
310
    std::vector<unsigned char> ExtVTs(1, ExtVT);
 
311
    return UpdateNodeType(ExtVTs, TP);
 
312
  }
 
313
  
 
314
  /// ContainsUnresolvedType - Return true if this tree contains any
 
315
  /// unresolved types.
 
316
  bool ContainsUnresolvedType() const {
 
317
    if (!hasTypeSet() && !isTypeDynamicallyResolved()) return true;
 
318
    for (unsigned i = 0, e = getNumChildren(); i != e; ++i)
 
319
      if (getChild(i)->ContainsUnresolvedType()) return true;
 
320
    return false;
 
321
  }
 
322
  
 
323
  /// canPatternMatch - If it is impossible for this pattern to match on this
 
324
  /// target, fill in Reason and return false.  Otherwise, return true.
 
325
  bool canPatternMatch(std::string &Reason, const CodeGenDAGPatterns &CDP);
 
326
};
 
327
 
 
328
inline raw_ostream &operator<<(raw_ostream &OS, const TreePatternNode &TPN) {
 
329
  TPN.print(OS);
 
330
  return OS;
 
331
}
 
332
  
 
333
 
 
334
/// TreePattern - Represent a pattern, used for instructions, pattern
 
335
/// fragments, etc.
 
336
///
 
337
class TreePattern {
 
338
  /// Trees - The list of pattern trees which corresponds to this pattern.
 
339
  /// Note that PatFrag's only have a single tree.
 
340
  ///
 
341
  std::vector<TreePatternNode*> Trees;
 
342
  
 
343
  /// TheRecord - The actual TableGen record corresponding to this pattern.
 
344
  ///
 
345
  Record *TheRecord;
 
346
    
 
347
  /// Args - This is a list of all of the arguments to this pattern (for
 
348
  /// PatFrag patterns), which are the 'node' markers in this pattern.
 
349
  std::vector<std::string> Args;
 
350
  
 
351
  /// CDP - the top-level object coordinating this madness.
 
352
  ///
 
353
  CodeGenDAGPatterns &CDP;
 
354
 
 
355
  /// isInputPattern - True if this is an input pattern, something to match.
 
356
  /// False if this is an output pattern, something to emit.
 
357
  bool isInputPattern;
 
358
public:
 
359
    
 
360
  /// TreePattern constructor - Parse the specified DagInits into the
 
361
  /// current record.
 
362
  TreePattern(Record *TheRec, ListInit *RawPat, bool isInput,
 
363
              CodeGenDAGPatterns &ise);
 
364
  TreePattern(Record *TheRec, DagInit *Pat, bool isInput,
 
365
              CodeGenDAGPatterns &ise);
 
366
  TreePattern(Record *TheRec, TreePatternNode *Pat, bool isInput,
 
367
              CodeGenDAGPatterns &ise);
 
368
      
 
369
  /// getTrees - Return the tree patterns which corresponds to this pattern.
 
370
  ///
 
371
  const std::vector<TreePatternNode*> &getTrees() const { return Trees; }
 
372
  unsigned getNumTrees() const { return Trees.size(); }
 
373
  TreePatternNode *getTree(unsigned i) const { return Trees[i]; }
 
374
  TreePatternNode *getOnlyTree() const {
 
375
    assert(Trees.size() == 1 && "Doesn't have exactly one pattern!");
 
376
    return Trees[0];
 
377
  }
 
378
      
 
379
  /// getRecord - Return the actual TableGen record corresponding to this
 
380
  /// pattern.
 
381
  ///
 
382
  Record *getRecord() const { return TheRecord; }
 
383
  
 
384
  unsigned getNumArgs() const { return Args.size(); }
 
385
  const std::string &getArgName(unsigned i) const {
 
386
    assert(i < Args.size() && "Argument reference out of range!");
 
387
    return Args[i];
 
388
  }
 
389
  std::vector<std::string> &getArgList() { return Args; }
 
390
  
 
391
  CodeGenDAGPatterns &getDAGPatterns() const { return CDP; }
 
392
 
 
393
  /// InlinePatternFragments - If this pattern refers to any pattern
 
394
  /// fragments, inline them into place, giving us a pattern without any
 
395
  /// PatFrag references.
 
396
  void InlinePatternFragments() {
 
397
    for (unsigned i = 0, e = Trees.size(); i != e; ++i)
 
398
      Trees[i] = Trees[i]->InlinePatternFragments(*this);
 
399
  }
 
400
  
 
401
  /// InferAllTypes - Infer/propagate as many types throughout the expression
 
402
  /// patterns as possible.  Return true if all types are inferred, false
 
403
  /// otherwise.  Throw an exception if a type contradiction is found.
 
404
  bool InferAllTypes();
 
405
  
 
406
  /// error - Throw an exception, prefixing it with information about this
 
407
  /// pattern.
 
408
  void error(const std::string &Msg) const;
 
409
  
 
410
  void print(raw_ostream &OS) const;
 
411
  void dump() const;
 
412
  
 
413
private:
 
414
  TreePatternNode *ParseTreePattern(DagInit *DI);
 
415
};
 
416
 
 
417
/// DAGDefaultOperand - One of these is created for each PredicateOperand
 
418
/// or OptionalDefOperand that has a set ExecuteAlways / DefaultOps field.
 
419
struct DAGDefaultOperand {
 
420
  std::vector<TreePatternNode*> DefaultOps;
 
421
};
 
422
 
 
423
class DAGInstruction {
 
424
  TreePattern *Pattern;
 
425
  std::vector<Record*> Results;
 
426
  std::vector<Record*> Operands;
 
427
  std::vector<Record*> ImpResults;
 
428
  std::vector<Record*> ImpOperands;
 
429
  TreePatternNode *ResultPattern;
 
430
public:
 
431
  DAGInstruction(TreePattern *TP,
 
432
                 const std::vector<Record*> &results,
 
433
                 const std::vector<Record*> &operands,
 
434
                 const std::vector<Record*> &impresults,
 
435
                 const std::vector<Record*> &impoperands)
 
436
    : Pattern(TP), Results(results), Operands(operands), 
 
437
      ImpResults(impresults), ImpOperands(impoperands),
 
438
      ResultPattern(0) {}
 
439
 
 
440
  const TreePattern *getPattern() const { return Pattern; }
 
441
  unsigned getNumResults() const { return Results.size(); }
 
442
  unsigned getNumOperands() const { return Operands.size(); }
 
443
  unsigned getNumImpResults() const { return ImpResults.size(); }
 
444
  unsigned getNumImpOperands() const { return ImpOperands.size(); }
 
445
  const std::vector<Record*>& getImpResults() const { return ImpResults; }
 
446
  
 
447
  void setResultPattern(TreePatternNode *R) { ResultPattern = R; }
 
448
  
 
449
  Record *getResult(unsigned RN) const {
 
450
    assert(RN < Results.size());
 
451
    return Results[RN];
 
452
  }
 
453
  
 
454
  Record *getOperand(unsigned ON) const {
 
455
    assert(ON < Operands.size());
 
456
    return Operands[ON];
 
457
  }
 
458
 
 
459
  Record *getImpResult(unsigned RN) const {
 
460
    assert(RN < ImpResults.size());
 
461
    return ImpResults[RN];
 
462
  }
 
463
  
 
464
  Record *getImpOperand(unsigned ON) const {
 
465
    assert(ON < ImpOperands.size());
 
466
    return ImpOperands[ON];
 
467
  }
 
468
 
 
469
  TreePatternNode *getResultPattern() const { return ResultPattern; }
 
470
};
 
471
  
 
472
/// PatternToMatch - Used by CodeGenDAGPatterns to keep tab of patterns
 
473
/// processed to produce isel.
 
474
class PatternToMatch {
 
475
public:
 
476
  PatternToMatch(ListInit *preds,
 
477
                 TreePatternNode *src, TreePatternNode *dst,
 
478
                 const std::vector<Record*> &dstregs,
 
479
                 unsigned complexity, unsigned uid)
 
480
    : Predicates(preds), SrcPattern(src), DstPattern(dst),
 
481
      Dstregs(dstregs), AddedComplexity(complexity), ID(uid) {}
 
482
 
 
483
  ListInit        *Predicates;  // Top level predicate conditions to match.
 
484
  TreePatternNode *SrcPattern;  // Source pattern to match.
 
485
  TreePatternNode *DstPattern;  // Resulting pattern.
 
486
  std::vector<Record*> Dstregs; // Physical register defs being matched.
 
487
  unsigned         AddedComplexity; // Add to matching pattern complexity.
 
488
  unsigned         ID;          // Unique ID for the record.
 
489
 
 
490
  ListInit        *getPredicates() const { return Predicates; }
 
491
  TreePatternNode *getSrcPattern() const { return SrcPattern; }
 
492
  TreePatternNode *getDstPattern() const { return DstPattern; }
 
493
  const std::vector<Record*> &getDstRegs() const { return Dstregs; }
 
494
  unsigned         getAddedComplexity() const { return AddedComplexity; }
 
495
 
 
496
  std::string getPredicateCheck() const;
 
497
};
 
498
 
 
499
// Deterministic comparison of Record*.
 
500
struct RecordPtrCmp {
 
501
  bool operator()(const Record *LHS, const Record *RHS) const;
 
502
};
 
503
  
 
504
class CodeGenDAGPatterns {
 
505
  RecordKeeper &Records;
 
506
  CodeGenTarget Target;
 
507
  std::vector<CodeGenIntrinsic> Intrinsics;
 
508
  std::vector<CodeGenIntrinsic> TgtIntrinsics;
 
509
  
 
510
  std::map<Record*, SDNodeInfo, RecordPtrCmp> SDNodes;
 
511
  std::map<Record*, std::pair<Record*, std::string>, RecordPtrCmp> SDNodeXForms;
 
512
  std::map<Record*, ComplexPattern, RecordPtrCmp> ComplexPatterns;
 
513
  std::map<Record*, TreePattern*, RecordPtrCmp> PatternFragments;
 
514
  std::map<Record*, DAGDefaultOperand, RecordPtrCmp> DefaultOperands;
 
515
  std::map<Record*, DAGInstruction, RecordPtrCmp> Instructions;
 
516
  
 
517
  // Specific SDNode definitions:
 
518
  Record *intrinsic_void_sdnode;
 
519
  Record *intrinsic_w_chain_sdnode, *intrinsic_wo_chain_sdnode;
 
520
  
 
521
  /// PatternsToMatch - All of the things we are matching on the DAG.  The first
 
522
  /// value is the pattern to match, the second pattern is the result to
 
523
  /// emit.
 
524
  std::vector<PatternToMatch> PatternsToMatch;
 
525
public:
 
526
  CodeGenDAGPatterns(RecordKeeper &R); 
 
527
  ~CodeGenDAGPatterns();
 
528
  
 
529
  CodeGenTarget &getTargetInfo() { return Target; }
 
530
  const CodeGenTarget &getTargetInfo() const { return Target; }
 
531
  
 
532
  Record *getSDNodeNamed(const std::string &Name) const;
 
533
  
 
534
  const SDNodeInfo &getSDNodeInfo(Record *R) const {
 
535
    assert(SDNodes.count(R) && "Unknown node!");
 
536
    return SDNodes.find(R)->second;
 
537
  }
 
538
  
 
539
  // Node transformation lookups.
 
540
  typedef std::pair<Record*, std::string> NodeXForm;
 
541
  const NodeXForm &getSDNodeTransform(Record *R) const {
 
542
    assert(SDNodeXForms.count(R) && "Invalid transform!");
 
543
    return SDNodeXForms.find(R)->second;
 
544
  }
 
545
  
 
546
  typedef std::map<Record*, NodeXForm, RecordPtrCmp>::const_iterator
 
547
          nx_iterator;
 
548
  nx_iterator nx_begin() const { return SDNodeXForms.begin(); }
 
549
  nx_iterator nx_end() const { return SDNodeXForms.end(); }
 
550
 
 
551
  
 
552
  const ComplexPattern &getComplexPattern(Record *R) const {
 
553
    assert(ComplexPatterns.count(R) && "Unknown addressing mode!");
 
554
    return ComplexPatterns.find(R)->second;
 
555
  }
 
556
  
 
557
  const CodeGenIntrinsic &getIntrinsic(Record *R) const {
 
558
    for (unsigned i = 0, e = Intrinsics.size(); i != e; ++i)
 
559
      if (Intrinsics[i].TheDef == R) return Intrinsics[i];
 
560
    for (unsigned i = 0, e = TgtIntrinsics.size(); i != e; ++i)
 
561
      if (TgtIntrinsics[i].TheDef == R) return TgtIntrinsics[i];
 
562
    assert(0 && "Unknown intrinsic!");
 
563
    abort();
 
564
  }
 
565
  
 
566
  const CodeGenIntrinsic &getIntrinsicInfo(unsigned IID) const {
 
567
    if (IID-1 < Intrinsics.size())
 
568
      return Intrinsics[IID-1];
 
569
    if (IID-Intrinsics.size()-1 < TgtIntrinsics.size())
 
570
      return TgtIntrinsics[IID-Intrinsics.size()-1];
 
571
    assert(0 && "Bad intrinsic ID!");
 
572
    abort();
 
573
  }
 
574
  
 
575
  unsigned getIntrinsicID(Record *R) const {
 
576
    for (unsigned i = 0, e = Intrinsics.size(); i != e; ++i)
 
577
      if (Intrinsics[i].TheDef == R) return i;
 
578
    for (unsigned i = 0, e = TgtIntrinsics.size(); i != e; ++i)
 
579
      if (TgtIntrinsics[i].TheDef == R) return i + Intrinsics.size();
 
580
    assert(0 && "Unknown intrinsic!");
 
581
    abort();
 
582
  }
 
583
  
 
584
  const DAGDefaultOperand &getDefaultOperand(Record *R) const {
 
585
    assert(DefaultOperands.count(R) &&"Isn't an analyzed default operand!");
 
586
    return DefaultOperands.find(R)->second;
 
587
  }
 
588
  
 
589
  // Pattern Fragment information.
 
590
  TreePattern *getPatternFragment(Record *R) const {
 
591
    assert(PatternFragments.count(R) && "Invalid pattern fragment request!");
 
592
    return PatternFragments.find(R)->second;
 
593
  }
 
594
  typedef std::map<Record*, TreePattern*, RecordPtrCmp>::const_iterator
 
595
          pf_iterator;
 
596
  pf_iterator pf_begin() const { return PatternFragments.begin(); }
 
597
  pf_iterator pf_end() const { return PatternFragments.end(); }
 
598
 
 
599
  // Patterns to match information.
 
600
  typedef std::vector<PatternToMatch>::const_iterator ptm_iterator;
 
601
  ptm_iterator ptm_begin() const { return PatternsToMatch.begin(); }
 
602
  ptm_iterator ptm_end() const { return PatternsToMatch.end(); }
 
603
  
 
604
  
 
605
  
 
606
  const DAGInstruction &getInstruction(Record *R) const {
 
607
    assert(Instructions.count(R) && "Unknown instruction!");
 
608
    return Instructions.find(R)->second;
 
609
  }
 
610
  
 
611
  Record *get_intrinsic_void_sdnode() const {
 
612
    return intrinsic_void_sdnode;
 
613
  }
 
614
  Record *get_intrinsic_w_chain_sdnode() const {
 
615
    return intrinsic_w_chain_sdnode;
 
616
  }
 
617
  Record *get_intrinsic_wo_chain_sdnode() const {
 
618
    return intrinsic_wo_chain_sdnode;
 
619
  }
 
620
  
 
621
  bool hasTargetIntrinsics() { return !TgtIntrinsics.empty(); }
 
622
 
 
623
private:
 
624
  void ParseNodeInfo();
 
625
  void ParseNodeTransforms();
 
626
  void ParseComplexPatterns();
 
627
  void ParsePatternFragments();
 
628
  void ParseDefaultOperands();
 
629
  void ParseInstructions();
 
630
  void ParsePatterns();
 
631
  void InferInstructionFlags();
 
632
  void GenerateVariants();
 
633
  
 
634
  void AddPatternToMatch(const TreePattern *Pattern, const PatternToMatch &PTM);
 
635
  void FindPatternInputsAndOutputs(TreePattern *I, TreePatternNode *Pat,
 
636
                                   std::map<std::string,
 
637
                                   TreePatternNode*> &InstInputs,
 
638
                                   std::map<std::string,
 
639
                                   TreePatternNode*> &InstResults,
 
640
                                   std::vector<Record*> &InstImpInputs,
 
641
                                   std::vector<Record*> &InstImpResults);
 
642
};
 
643
} // end namespace llvm
 
644
 
 
645
#endif