diff options
Diffstat (limited to 'include/clang/Basic/TargetInfo.h')
-rw-r--r-- | include/clang/Basic/TargetInfo.h | 141 |
1 files changed, 83 insertions, 58 deletions
diff --git a/include/clang/Basic/TargetInfo.h b/include/clang/Basic/TargetInfo.h index 39f575f..f1d8338 100644 --- a/include/clang/Basic/TargetInfo.h +++ b/include/clang/Basic/TargetInfo.h @@ -22,6 +22,8 @@ #include "clang/Basic/TargetOptions.h" #include "clang/Basic/VersionTuple.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" +#include "llvm/ADT/APInt.h" +#include "llvm/ADT/SmallSet.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSwitch.h" @@ -72,7 +74,7 @@ protected: unsigned short MaxVectorAlign; unsigned short MaxTLSAlign; unsigned short SimdDefaultAlign; - const char *DescriptionString; + const char *DataLayoutString; const char *UserLabelPrefix; const char *MCountName; const llvm::fltSemantics *HalfFormat, *FloatFormat, *DoubleFormat, @@ -88,6 +90,8 @@ protected: unsigned RealTypeUsesObjCFPRet : 3; unsigned ComplexLongDoubleUsesFP2Ret : 1; + unsigned HasBuiltinMSVaList : 1; + // TargetInfo Constructor. Default initializes all fields. TargetInfo(const llvm::Triple &T); @@ -104,9 +108,9 @@ public: virtual ~TargetInfo(); /// \brief Retrieve the target options. - TargetOptions &getTargetOpts() const { + TargetOptions &getTargetOpts() const { assert(TargetOpts && "Missing target options"); - return *TargetOpts; + return *TargetOpts; } ///===---- Target Data Type Query Methods -------------------------------===// @@ -253,10 +257,11 @@ public: unsigned getTypeWidth(IntType T) const; /// \brief Return integer type with specified width. - IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const; + virtual IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const; /// \brief Return the smallest integer type with at least the specified width. - IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const; + virtual IntType getLeastIntTypeByWidth(unsigned BitWidth, + bool IsSigned) const; /// \brief Return floating point type with specified width. RealType getRealTypeByWidth(unsigned BitWidth) const; @@ -311,7 +316,9 @@ public: unsigned getLongLongAlign() const { return LongLongAlign; } /// \brief Determine whether the __int128 type is supported on this target. - virtual bool hasInt128Type() const { return getPointerWidth(0) >= 64; } // FIXME + virtual bool hasInt128Type() const { + return getPointerWidth(0) >= 64; + } // FIXME /// \brief Return the alignment that is suitable for storing any /// object with a fundamental alignment requirement. @@ -509,8 +516,7 @@ public: /// Return information about target-specific builtins for /// the current primary target, and info about which builtins are non-portable /// across the current set of primary and secondary targets. - virtual void getTargetBuiltins(const Builtin::Info *&Records, - unsigned &NumRecords) const = 0; + virtual ArrayRef<Builtin::Info> getTargetBuiltins() const = 0; /// The __builtin_clz* and __builtin_ctz* built-in /// functions are specified to have undefined results for zero inputs, but @@ -523,6 +529,10 @@ public: /// with this target. virtual BuiltinVaListKind getBuiltinVaListKind() const = 0; + /// Returns whether or not type \c __builtin_ms_va_list type is + /// available on this target. + bool hasBuiltinMSVaList() const { return HasBuiltinMSVaList; } + /// \brief Returns whether the passed in string is a valid clobber in an /// inline asm statement. /// @@ -556,6 +566,7 @@ public: int Min; int Max; } ImmRange; + llvm::SmallSet<int, 4> ImmSet; std::string ConstraintStr; // constraint: "=rm" std::string Name; // Operand name: [foo] with no []'s. @@ -591,8 +602,10 @@ public: bool requiresImmediateConstant() const { return (Flags & CI_ImmediateConstant) != 0; } - int getImmConstantMin() const { return ImmRange.Min; } - int getImmConstantMax() const { return ImmRange.Max; } + bool isValidAsmImmediate(const llvm::APInt &Value) const { + return (Value.sge(ImmRange.Min) && Value.sle(ImmRange.Max)) || + ImmSet.count(Value.getZExtValue()) != 0; + } void setIsReadWrite() { Flags |= CI_ReadWrite; } void setEarlyClobber() { Flags |= CI_EarlyClobber; } @@ -604,9 +617,23 @@ public: ImmRange.Min = Min; ImmRange.Max = Max; } + void setRequiresImmediate(llvm::ArrayRef<int> Exacts) { + Flags |= CI_ImmediateConstant; + for (int Exact : Exacts) + ImmSet.insert(Exact); + } + void setRequiresImmediate(int Exact) { + Flags |= CI_ImmediateConstant; + ImmSet.insert(Exact); + } + void setRequiresImmediate() { + Flags |= CI_ImmediateConstant; + ImmRange.Min = INT_MIN; + ImmRange.Max = INT_MAX; + } /// \brief Indicate that this is an input operand that is tied to - /// the specified output operand. + /// the specified output operand. /// /// Copy over the various constraint information from the output. void setTiedOperand(unsigned N, ConstraintInfo &Output) { @@ -617,15 +644,24 @@ public: } }; - // Validate the contents of the __builtin_cpu_supports(const char*) argument. - virtual bool validateCpuSupports(StringRef Name) const { return false; } + /// \brief Validate register name used for global register variables. + /// + /// This function returns true if the register passed in RegName can be used + /// for global register variables on this target. In addition, it returns + /// true in HasSizeMismatch if the size of the register doesn't match the + /// variable size passed in RegSize. + virtual bool validateGlobalRegisterVariable(StringRef RegName, + unsigned RegSize, + bool &HasSizeMismatch) const { + HasSizeMismatch = false; + return true; + } // validateOutputConstraint, validateInputConstraint - Checks that // a constraint is valid and provides information about it. // FIXME: These should return a real error instead of just true/false. bool validateOutputConstraint(ConstraintInfo &Info) const; - bool validateInputConstraint(ConstraintInfo *OutputConstraints, - unsigned NumOutputs, + bool validateInputConstraint(MutableArrayRef<ConstraintInfo> OutputConstraints, ConstraintInfo &info) const; virtual bool validateOutputSize(StringRef /*Constraint*/, @@ -644,9 +680,13 @@ public: std::string &/*SuggestedModifier*/) const { return true; } + virtual bool + validateAsmConstraint(const char *&Name, + TargetInfo::ConstraintInfo &info) const = 0; + bool resolveSymbolicName(const char *&Name, - ConstraintInfo *OutputConstraints, - unsigned NumOutputs, unsigned &Index) const; + ArrayRef<ConstraintInfo> OutputConstraints, + unsigned &Index) const; // Constraint parm will be left pointing at the last character of // the constraint. In practice, it won't be changed unless the @@ -658,24 +698,23 @@ public: return std::string(1, *Constraint); } + /// \brief Returns a string of target-specific clobbers, in LLVM format. + virtual const char *getClobbers() const = 0; + /// \brief Returns true if NaN encoding is IEEE 754-2008. /// Only MIPS allows a different encoding. virtual bool isNan2008() const { return true; } - /// \brief Returns a string of target-specific clobbers, in LLVM format. - virtual const char *getClobbers() const = 0; - - /// \brief Returns the target triple of the primary target. const llvm::Triple &getTriple() const { return Triple; } - const char *getTargetDescription() const { - assert(DescriptionString); - return DescriptionString; + const char *getDataLayoutString() const { + assert(DataLayoutString && "Uninitialized DataLayoutString!"); + return DataLayoutString; } struct GCCRegAlias { @@ -721,10 +760,13 @@ public: /// language options which change the target configuration. virtual void adjust(const LangOptions &Opts); - /// \brief Get the default set of target features for the CPU; - /// this should include all legal feature strings on the target. - virtual void getDefaultFeatures(llvm::StringMap<bool> &Features) const { - } + /// \brief Initialize the map with the default set of target features for the + /// CPU this should include all legal feature strings on the target. + /// + /// \return False on error (invalid features). + virtual bool initFeatureMap(llvm::StringMap<bool> &Features, + DiagnosticsEngine &Diags, StringRef CPU, + const std::vector<std::string> &FeatureVec) const; /// \brief Get the ABI currently in use. virtual StringRef getABI() const { return StringRef(); } @@ -755,23 +797,6 @@ public: return false; } - /// \brief Use this specified C++ ABI. - /// - /// \return False on error (invalid C++ ABI name). - bool setCXXABI(llvm::StringRef name) { - TargetCXXABI ABI; - if (!ABI.tryParse(name)) return false; - return setCXXABI(ABI); - } - - /// \brief Set the C++ ABI to be used by this implementation. - /// - /// \return False on error (ABI not valid on this target) - virtual bool setCXXABI(TargetCXXABI ABI) { - TheCXXABI = ABI; - return true; - } - /// \brief Enable or disable a specific target feature; /// the feature name must be valid. virtual void setFeatureEnabled(llvm::StringMap<bool> &Features, @@ -787,6 +812,8 @@ public: /// /// The target may modify the features list, to change which options are /// passed onwards to the backend. + /// FIXME: This part should be fixed so that we can change handleTargetFeatures + /// to merely a TargetInfo initialization routine. /// /// \return False on error. virtual bool handleTargetFeatures(std::vector<std::string> &Features, @@ -798,7 +825,11 @@ public: virtual bool hasFeature(StringRef Feature) const { return false; } - + + // \brief Validate the contents of the __builtin_cpu_supports(const char*) + // argument. + virtual bool validateCpuSupports(StringRef Name) const { return false; } + // \brief Returns maximal number of args passed in registers. unsigned getRegParmMax() const { assert(RegParmMax < 7 && "RegParmMax value is larger than AST can handle"); @@ -882,7 +913,7 @@ public: }; /// \brief Determines whether a given calling convention is valid for the - /// target. A calling convention can either be accepted, produce a warning + /// target. A calling convention can either be accepted, produce a warning /// and be substituted with the default calling convention, or (someday) /// produce an error (such as using thiscall on a non-instance function). virtual CallingConvCheckResult checkCallingConvention(CallingConv CC) const { @@ -910,17 +941,11 @@ protected: virtual enum IntType getPtrDiffTypeV(unsigned AddrSpace) const { return PtrDiffType; } - virtual void getGCCRegNames(const char * const *&Names, - unsigned &NumNames) const = 0; - virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, - unsigned &NumAliases) const = 0; - virtual void getGCCAddlRegNames(const AddlRegName *&Addl, - unsigned &NumAddl) const { - Addl = nullptr; - NumAddl = 0; - } - virtual bool validateAsmConstraint(const char *&Name, - TargetInfo::ConstraintInfo &info) const= 0; + virtual ArrayRef<const char *> getGCCRegNames() const = 0; + virtual ArrayRef<GCCRegAlias> getGCCRegAliases() const = 0; + virtual ArrayRef<AddlRegName> getGCCAddlRegNames() const { + return None; + } }; } // end namespace clang |