1 //===--------------------- llvm/Target/TargetRecip.h ------------*- 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 class is used to customize machine-specific reciprocal estimate code
11 // generation in a target-independent way.
12 // If a target does not support operations in this specification, then code
13 // generation will default to using supported operations.
14 //
15 //===----------------------------------------------------------------------===//
16 
17 #ifndef LLVM_TARGET_TARGETRECIP_H
18 #define LLVM_TARGET_TARGETRECIP_H
19 
20 #include "llvm/ADT/StringRef.h"
21 #include <vector>
22 #include <string>
23 #include <map>
24 
25 namespace llvm {
26 
27 struct TargetRecip {
28 public:
29   TargetRecip();
30 
31   /// Initialize all or part of the operations from command-line options or
32   /// a front end.
33   TargetRecip(const std::vector<std::string> &Args);
34 
35   /// Set whether a particular reciprocal operation is enabled and how many
36   /// refinement steps are needed when using it. Use "all" to set enablement
37   /// and refinement steps for all operations.
38   void setDefaults(StringRef Key, bool Enable, unsigned RefSteps);
39 
40   /// Return true if the reciprocal operation has been enabled by default or
41   /// from the command-line. Return false if the operation has been disabled
42   /// by default or from the command-line.
43   bool isEnabled(StringRef Key) const;
44 
45   /// Return the number of iterations necessary to refine the
46   /// the result of a machine instruction for the given reciprocal operation.
47   unsigned getRefinementSteps(StringRef Key) const;
48 
49   bool operator==(const TargetRecip &Other) const;
50 
51 private:
52   enum {
53     Uninitialized = -1
54   };
55 
56   struct RecipParams {
57     int8_t Enabled;
58     int8_t RefinementSteps;
59 
RecipParamsTargetRecip::RecipParams60     RecipParams() : Enabled(Uninitialized), RefinementSteps(Uninitialized) {}
61   };
62 
63   std::map<StringRef, RecipParams> RecipMap;
64   typedef std::map<StringRef, RecipParams>::iterator RecipIter;
65   typedef std::map<StringRef, RecipParams>::const_iterator ConstRecipIter;
66 
67   bool parseGlobalParams(const std::string &Arg);
68   void parseIndividualParams(const std::vector<std::string> &Args);
69 };
70 
71 } // End llvm namespace
72 
73 #endif
74