diff options
author | Chris Lattner <sabre@nondot.org> | 2003-01-15 21:36:50 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-01-15 21:36:50 +0000 |
commit | dea36ca100bcd9ecd01192208e459db82143beb2 (patch) | |
tree | 765f6d27c45a78aa2468070c7ee34c086f73bbbf /llvm/lib/Target/Sparc/SparcInstrInfo.cpp | |
parent | 4f596d7a2cd73c384a7d01498209fa83289693d1 (diff) | |
download | bcm5719-llvm-dea36ca100bcd9ecd01192208e459db82143beb2.tar.gz bcm5719-llvm-dea36ca100bcd9ecd01192208e459db82143beb2.zip |
Move sparc specific code into the Sparc backend
llvm-svn: 5317
Diffstat (limited to 'llvm/lib/Target/Sparc/SparcInstrInfo.cpp')
-rw-r--r-- | llvm/lib/Target/Sparc/SparcInstrInfo.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/llvm/lib/Target/Sparc/SparcInstrInfo.cpp b/llvm/lib/Target/Sparc/SparcInstrInfo.cpp index 289e871c459..6df7617c93e 100644 --- a/llvm/lib/Target/Sparc/SparcInstrInfo.cpp +++ b/llvm/lib/Target/Sparc/SparcInstrInfo.cpp @@ -20,6 +20,53 @@ static const uint32_t MAXLO = (1 << 10) - 1; // set bits set by %lo(*) static const uint32_t MAXSIMM = (1 << 12) - 1; // set bits in simm13 field of OR +//--------------------------------------------------------------------------- +// Function GetConstantValueAsUnsignedInt +// Function GetConstantValueAsSignedInt +// +// Convenience functions to get the value of an integral constant, for an +// appropriate integer or non-integer type that can be held in a signed +// or unsigned integer respectively. The type of the argument must be +// the following: +// Signed or unsigned integer +// Boolean +// Pointer +// +// isValidConstant is set to true if a valid constant was found. +//--------------------------------------------------------------------------- + +static uint64_t +GetConstantValueAsUnsignedInt(const Value *V, + bool &isValidConstant) +{ + isValidConstant = true; + + if (isa<Constant>(V)) + if (const ConstantBool *CB = dyn_cast<ConstantBool>(V)) + return (int64_t)CB->getValue(); + else if (const ConstantSInt *CS = dyn_cast<ConstantSInt>(V)) + return (uint64_t)CS->getValue(); + else if (const ConstantUInt *CU = dyn_cast<ConstantUInt>(V)) + return CU->getValue(); + + isValidConstant = false; + return 0; +} + +int64_t +GetConstantValueAsSignedInt(const Value *V, bool &isValidConstant) +{ + uint64_t C = GetConstantValueAsUnsignedInt(V, isValidConstant); + if (isValidConstant) { + if (V->getType()->isSigned() || C < INT64_MAX) // safe to cast to signed + return (int64_t) C; + else + isValidConstant = false; + } + return 0; +} + + //---------------------------------------------------------------------------- // Function: CreateSETUWConst // |