aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2006-10-20 07:07:24 +0000
committerReid Spencer <rspencer@reidspencer.com>2006-10-20 07:07:24 +0000
commitb83eb6447ba155342598f0fabe1f08f5baa9164a (patch)
treea5822f5fdac89033b7b16ba8e5aaf1ae10833b1c
parent6e7dd9db6bf677c9161a6ecc12f90651cf1231e0 (diff)
For PR950:
This patch implements the first increment for the Signless Types feature. All changes pertain to removing the ConstantSInt and ConstantUInt classes in favor of just using ConstantInt. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31063 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--docs/ProgrammersManual.html19
-rw-r--r--docs/Stacker.html10
-rw-r--r--examples/Fibonacci/fibonacci.cpp4
-rw-r--r--examples/HowToUseJIT/HowToUseJIT.cpp4
-rw-r--r--examples/ModuleMaker/ModuleMaker.cpp4
-rw-r--r--examples/ParallelJIT/ParallelJIT.cpp6
-rw-r--r--include/llvm/Constants.h148
-rw-r--r--include/llvm/IntrinsicInst.h4
-rw-r--r--include/llvm/Value.h3
-rw-r--r--lib/Analysis/BasicAliasAnalysis.cpp15
-rw-r--r--lib/Analysis/ConstantFolding.cpp11
-rw-r--r--lib/Analysis/ConstantRange.cpp4
-rw-r--r--lib/Analysis/DataStructure/Local.cpp2
-rw-r--r--lib/Analysis/ScalarEvolution.cpp28
-rw-r--r--lib/Analysis/ScalarEvolutionExpander.cpp2
-rw-r--r--lib/AsmParser/Lexer.cpp.cvs269
-rw-r--r--lib/AsmParser/llvmAsmParser.cpp.cvs6397
-rw-r--r--lib/AsmParser/llvmAsmParser.h.cvs370
-rw-r--r--lib/AsmParser/llvmAsmParser.y28
-rw-r--r--lib/AsmParser/llvmAsmParser.y.cvs28
-rw-r--r--lib/Bytecode/Reader/Reader.cpp24
-rw-r--r--lib/Bytecode/Writer/Writer.cpp12
-rw-r--r--lib/CodeGen/AsmPrinter.cpp23
-rw-r--r--lib/CodeGen/IntrinsicLowering.cpp35
-rw-r--r--lib/CodeGen/MachineDebugInfo.cpp29
-rw-r--r--lib/CodeGen/SelectionDAG/LegalizeDAG.cpp6
-rw-r--r--lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp70
-rw-r--r--lib/Debugger/ProgramInfo.cpp8
-rw-r--r--lib/ExecutionEngine/ExecutionEngine.cpp26
-rw-r--r--lib/ExecutionEngine/Interpreter/Execution.cpp4
-rw-r--r--lib/ExecutionEngine/JIT/JIT.cpp24
-rw-r--r--lib/Support/ConstantRange.cpp4
-rw-r--r--lib/Target/ARM/ARMISelDAGToDAG.cpp3
-rw-r--r--lib/Target/Alpha/AlphaISelDAGToDAG.cpp3
-rw-r--r--lib/Target/CBackend/CBackend.cpp22
-rw-r--r--lib/Target/CBackend/Writer.cpp22
-rw-r--r--lib/Target/TargetData.cpp4
-rwxr-xr-xlib/Target/X86/X86IntelAsmPrinter.cpp2
-rw-r--r--lib/Transforms/IPO/ArgumentPromotion.cpp6
-rw-r--r--lib/Transforms/IPO/GlobalOpt.cpp39
-rw-r--r--lib/Transforms/IPO/LowerSetJmp.cpp4
-rw-r--r--lib/Transforms/IPO/SimplifyLibCalls.cpp138
-rw-r--r--lib/Transforms/Instrumentation/EmitFunctions.cpp2
-rw-r--r--lib/Transforms/Instrumentation/ProfilingUtils.cpp4
-rw-r--r--lib/Transforms/Instrumentation/RSProfiling.cpp22
-rw-r--r--lib/Transforms/Instrumentation/TraceBasicBlocks.cpp2
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp594
-rw-r--r--lib/Transforms/Scalar/LoopStrengthReduce.cpp6
-rw-r--r--lib/Transforms/Scalar/LoopUnroll.cpp4
-rw-r--r--lib/Transforms/Scalar/LowerGC.cpp12
-rw-r--r--lib/Transforms/Scalar/LowerPacked.cpp22
-rw-r--r--lib/Transforms/Scalar/Reassociate.cpp2
-rw-r--r--lib/Transforms/Scalar/ScalarReplAggregates.cpp24
-rw-r--r--lib/Transforms/TransformInternals.cpp9
-rw-r--r--lib/Transforms/TransformInternals.h2
-rw-r--r--lib/Transforms/Utils/CodeExtractor.cpp14
-rw-r--r--lib/Transforms/Utils/Local.cpp14
-rw-r--r--lib/Transforms/Utils/LowerAllocations.cpp4
-rw-r--r--lib/Transforms/Utils/LowerInvoke.cpp8
-rw-r--r--lib/Transforms/Utils/LowerSwitch.cpp11
-rw-r--r--lib/Transforms/Utils/SimplifyCFG.cpp2
-rw-r--r--lib/VMCore/AsmWriter.cpp9
-rw-r--r--lib/VMCore/ConstantFold.cpp309
-rw-r--r--lib/VMCore/Constants.cpp122
-rw-r--r--lib/VMCore/Instructions.cpp14
-rw-r--r--lib/VMCore/Type.cpp6
-rw-r--r--lib/VMCore/Verifier.cpp2
-rw-r--r--projects/Stacker/lib/compiler/StackerCompiler.cpp16
-rw-r--r--tools/bugpoint/ExtractFunction.cpp6
-rw-r--r--tools/llvm2cpp/CppWriter.cpp11
70 files changed, 5035 insertions, 4082 deletions
diff --git a/docs/ProgrammersManual.html b/docs/ProgrammersManual.html
index bd79747626..950c937824 100644
--- a/docs/ProgrammersManual.html
+++ b/docs/ProgrammersManual.html
@@ -2390,8 +2390,8 @@ provide a name for it (probably based on the name of the translation unit).</p>
<div class="doc_text">
<p>Constant represents a base class for different types of constants. It
-is subclassed by ConstantBool, ConstantInt, ConstantSInt, ConstantUInt,
-ConstantArray etc for representing the various types of Constants.</p>
+is subclassed by ConstantBool, ConstantInt, ConstantArray etc for representing
+the various types of Constants.</p>
</div>
@@ -2406,17 +2406,12 @@ ConstantArray etc for representing the various types of Constants.</p>
<div class="doc_subsubsection">Important Subclasses of Constant </div>
<div class="doc_text">
<ul>
- <li>ConstantSInt : This subclass of Constant represents a signed integer
- constant.
+ <li>ConstantInt : This subclass of Constant represents an integer constant.
<ul>
- <li><tt>int64_t getValue() const</tt>: Returns the underlying value of
- this constant. </li>
- </ul>
- </li>
- <li>ConstantUInt : This class represents an unsigned integer.
- <ul>
- <li><tt>uint64_t getValue() const</tt>: Returns the underlying value of
- this constant. </li>
+ <li><tt>int64_t getSExtValue() const</tt>: Returns the underlying value of
+ this constant as a sign extended signed integer value.</li>
+ <li><tt>uint64_t getZExtValue() const</tt>: Returns the underlying value
+ of this constant as a zero extended unsigned integer value.</li>
</ul>
</li>
<li>ConstantFP : This class represents a floating point constant.
diff --git a/docs/Stacker.html b/docs/Stacker.html
index 7656dc10c0..a49b56de86 100644
--- a/docs/Stacker.html
+++ b/docs/Stacker.html
@@ -139,7 +139,7 @@ this: </p>
Value*
expression(BasicBlock* bb, Value* a, Value* b, Value* x, Value* y )
{
- ConstantSInt* one = ConstantSInt::get(Type::IntTy, 1);
+ ConstantInt* one = ConstantInt::get(Type::IntTy, 1);
BinaryOperator* or1 = BinaryOperator::createOr(a, b, "", bb);
BinaryOperator* add1 = BinaryOperator::createAdd(x, one, "", bb);
BinaryOperator* add2 = BinaryOperator::createAdd(y, one, "", bb);
@@ -308,7 +308,7 @@ things, this leads to the idiom:
</p>
<pre>
std::vector&lt;Value*&gt; index_vector;
-index_vector.push_back( ConstantSInt::get( Type::LongTy, 0 );
+index_vector.push_back( ConstantInt::get( Type::LongTy, 0 );
// ... push other indices ...
GetElementPtrInst* gep = new GetElementPtrInst( ptr, index_vector );
</pre>
@@ -367,9 +367,9 @@ functions in the LLVM IR that make things easier. Here's what I learned: </p>
<ul>
<li>Constants are Values like anything else and can be operands of instructions</li>
<li>Integer constants, frequently needed, can be created using the static "get"
- methods of the ConstantInt, ConstantSInt, and ConstantUInt classes. The nice thing
- about these is that you can "get" any kind of integer quickly.</li>
- <li>There's a special method on Constant class which allows you to get the null
+ methods of the ConstantInt class. The nice thing about these is that you can
+ "get" any kind of integer quickly.</li>
+ <li>There's a special method on Constant class which allows you to get the null
constant for <em>any</em> type. This is really handy for initializing large
arrays or structures, etc.</li>
</ul>
diff --git a/examples/Fibonacci/fibonacci.cpp b/examples/Fibonacci/fibonacci.cpp
index cdc84ca212..6f775515fb 100644
--- a/examples/Fibonacci/fibonacci.cpp
+++ b/examples/Fibonacci/fibonacci.cpp
@@ -45,8 +45,8 @@ static Function *CreateFibFunction(Module *M) {
BasicBlock *BB = new BasicBlock("EntryBlock", FibF);
// Get pointers to the constants.
- Value *One = ConstantSInt::get(Type::IntTy, 1);
- Value *Two = ConstantSInt::get(Type::IntTy, 2);
+ Value *One = ConstantInt::get(Type::IntTy, 1);
+ Value *Two = ConstantInt::get(Type::IntTy, 2);
// Get pointer to the integer argument of the add1 function...
Argument *ArgX = FibF->arg_begin(); // Get the arg.
diff --git a/examples/HowToUseJIT/HowToUseJIT.cpp b/examples/HowToUseJIT/HowToUseJIT.cpp
index 8fb9e5659d..8023cc7a18 100644
--- a/examples/HowToUseJIT/HowToUseJIT.cpp
+++ b/examples/HowToUseJIT/HowToUseJIT.cpp
@@ -60,7 +60,7 @@ int main() {
BasicBlock *BB = new BasicBlock("EntryBlock", Add1F);
// Get pointers to the constant `1'.
- Value *One = ConstantSInt::get(Type::IntTy, 1);
+ Value *One = ConstantInt::get(Type::IntTy, 1);
// Get pointers to the integer argument of the add1 function...
assert(Add1F->arg_begin() != Add1F->arg_end()); // Make sure there's an arg
@@ -84,7 +84,7 @@ int main() {
BB = new BasicBlock("EntryBlock", FooF);
// Get pointers to the constant `10'.
- Value *Ten = ConstantSInt::get(Type::IntTy, 10);
+ Value *Ten = ConstantInt::get(Type::IntTy, 10);
// Pass Ten to the call call:
std::vector<Value*> Params;
diff --git a/examples/ModuleMaker/ModuleMaker.cpp b/examples/ModuleMaker/ModuleMaker.cpp
index 04c6a9f95b..2ec5437c36 100644
--- a/examples/ModuleMaker/ModuleMaker.cpp
+++ b/examples/ModuleMaker/ModuleMaker.cpp
@@ -40,8 +40,8 @@ int main() {
BasicBlock *BB = new BasicBlock("EntryBlock", F);
// Get pointers to the constant integers...
- Value *Two = ConstantSInt::get(Type::IntTy, 2);
- Value *Three = ConstantSInt::get(Type::IntTy, 3);
+ Value *Two = ConstantInt::get(Type::IntTy, 2);
+ Value *Three = ConstantInt::get(Type::IntTy, 3);
// Create the add instruction... does not insert...
Instruction *Add = BinaryOperator::create(Instruction::Add, Two, Three,
diff --git a/examples/ParallelJIT/ParallelJIT.cpp b/examples/ParallelJIT/ParallelJIT.cpp
index b70f3db5bb..dfda126378 100644
--- a/examples/ParallelJIT/ParallelJIT.cpp
+++ b/examples/ParallelJIT/ParallelJIT.cpp
@@ -42,7 +42,7 @@ static Function* createAdd1(Module* M)
BasicBlock *BB = new BasicBlock("EntryBlock", Add1F);
// Get pointers to the constant `1'.
- Value *One = ConstantSInt::get(Type::IntTy, 1);
+ Value *One = ConstantInt::get(Type::IntTy, 1);
// Get pointers to the integer argument of the add1 function...
assert(Add1F->arg_begin() != Add1F->arg_end()); // Make sure there's an arg
@@ -70,8 +70,8 @@ static Function *CreateFibFunction(Module *M)
BasicBlock *BB = new BasicBlock("EntryBlock", FibF);
// Get pointers to the constants.
- Value *One = ConstantSInt::get(Type::IntTy, 1);
- Value *Two = ConstantSInt::get(Type::IntTy, 2);
+ Value *One = ConstantInt::get(Type::IntTy, 1);
+ Value *Two = ConstantInt::get(Type::IntTy, 2);
// Get pointer to the integer argument of the add1 function...
Argument *ArgX = FibF->arg_begin(); // Get the arg.
diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h
index 6b8e91958b..bc76248c15 100644
--- a/include/llvm/Constants.h
+++ b/include/llvm/Constants.h
@@ -41,22 +41,14 @@ struct ConvertConstantType;
/// @brief An abstract class for integer constants.
class ConstantIntegral : public Constant {
protected:
- union {
- int64_t Signed;
- uint64_t Unsigned;
- } Val;
+ uint64_t Val;
ConstantIntegral(const Type *Ty, ValueTy VT, uint64_t V);
public:
-
- /// @brief Return the raw value of the constant as a 64-bit integer value.
- inline uint64_t getRawValue() const { return Val.Unsigned; }
-
/// Return the constant as a 64-bit unsigned integer value after it
/// has been zero extended as appropriate for the type of this constant.
/// @brief Return the zero extended value.
inline uint64_t getZExtValue() const {
- unsigned Size = getType()->getPrimitiveSizeInBits();
- return Val.Unsigned & (~uint64_t(0UL) >> (64-Size));
+ return Val;
}
/// Return the constant as a 64-bit integer value after it has been sign
@@ -64,7 +56,7 @@ public:
/// @brief Return the sign extended value.
inline int64_t getSExtValue() const {
unsigned Size = getType()->getPrimitiveSizeInBits();
- return (Val.Signed << (64-Size)) >> (64-Size);
+ return (int64_t(Val) << (64-Size)) >> (64-Size);
}
/// This function is implemented by subclasses and will return true iff this
@@ -111,8 +103,7 @@ public:
static inline bool classof(const ConstantIntegral *) { return true; }
static bool classof(const Value *V) {
return V->getValueType() == ConstantBoolVal ||
- V->getValueType() == ConstantSIntVal ||
- V->getValueType() == ConstantUIntVal;
+ V->getValueType() == ConstantIntVal;
}
};
@@ -147,7 +138,7 @@ public:
/// @returns the value of this ConstantBool
/// @brief return the boolean value of this constant.
- inline bool getValue() const { return static_cast<bool>(getRawValue()); }
+ inline bool getValue() const { return static_cast<bool>(getZExtValue()); }
/// @see ConstantIntegral for details
/// @brief Implement overrides
@@ -165,13 +156,15 @@ public:
//===----------------------------------------------------------------------===//
-/// This is the abstract superclass of ConstantSInt & ConstantUInt, to make
-/// dealing with integral constants easier when sign is irrelevant.
-/// @brief Abstract clas for constant integers.
+/// This is concrete integer subclass of ConstantIntegral that represents
+/// both signed and unsigned integral constants, other than boolean.
+/// @brief Class for constant integers.
class ConstantInt : public ConstantIntegral {
protected:
ConstantInt(const ConstantInt &); // DO NOT IMPLEMENT
- ConstantInt(const Type *Ty, ValueTy VT, uint64_t V);
+ ConstantInt(const Type *Ty, uint64_t V);
+ ConstantInt(const Type *Ty, int64_t V);
+ friend struct ConstantCreator<ConstantInt, Type, uint64_t>;
public:
/// A helper method that can be used to determine if the constant contained
/// within is equal to a constant. This only works for very small values,
@@ -180,48 +173,15 @@ public:
bool equalsInt(unsigned char V) const {
assert(V <= 127 &&
"equalsInt: Can only be used with very small positive constants!");
- return Val.Unsigned == V;
+ return Val == V;
}
/// Return a ConstantInt with the specified value for the specified type.
- /// This only works for very small values, because this is all that can be
- /// represented with all types integer types.
+ /// Overloads for ll the integer types are provided to ensure that implicit
+ /// conversions don't bite us and to get around compiler errors where the
+ /// compiler can't find a suitable overload for a given integer value.
/// @brief Get a ConstantInt for a specific value.
- static ConstantInt *get(const Type *Ty, unsigned char V);
-
- /// @returns true if this is the null integer value.
- /// @see ConstantIntegral for details
- /// @brief Implement override.
- virtual bool isNullValue() const { return Val.Unsigned == 0; }
-
- /// @brief Methods to support type inquiry through isa, cast, and dyn_cast.
- static inline bool classof(const ConstantInt *) { return true; }
- static bool classof(const Value *V) {
- return V->getValueType() == ConstantSIntVal ||
- V->getValueType() == ConstantUIntVal;
- }
-};
-
-
-//===----------------------------------------------------------------------===//
-/// A concrete class to represent constant signed integer values for the types
-/// sbyte, short, int, and long.
-/// @brief Constant Signed Integer Class.
-class ConstantSInt : public ConstantInt {
- ConstantSInt(const ConstantSInt &); // DO NOT IMPLEMENT
- friend struct ConstantCreator<ConstantSInt, Type, int64_t>;
-
-protected:
- ConstantSInt(const Type *Ty, int64_t V);
-public:
- /// This static factory methods returns objects of the specified value. Note
- /// that repeated calls with the same operands return the same object.
- /// @returns A ConstantSInt instant for the type and value requested.
- /// @brief Get a signed integer constant.
- static ConstantSInt *get(
- const Type *Ty, ///< The type of constant (SByteTy, IntTy, ShortTy, LongTy)
- int64_t V ///< The value for the constant integer.
- );
+ static ConstantInt *get(const Type *Ty, int64_t V);
/// This static method returns true if the type Ty is big enough to
/// represent the value V. This can be used to avoid having the get method
@@ -230,24 +190,28 @@ public:
/// @brief Determine if the value is in range for the given type.
static bool isValueValidForType(const Type *Ty, int64_t V);
- /// @returns the underlying value of this constant.
- /// @brief Get the constant value.
- inline int64_t getValue() const { return Val.Signed; }
+ /// @returns true if this is the null integer value.
+ /// @see ConstantIntegral for details
+ /// @brief Implement override.
+ virtual bool isNullValue() const { return Val == 0; }
/// @returns true iff this constant's bits are all set to true.
/// @see ConstantIntegral
/// @brief Override implementation
- virtual bool isAllOnesValue() const { return getValue() == -1; }
+ virtual bool isAllOnesValue() const { return getSExtValue() == -1; }
/// @returns true iff this is the largest value that may be represented
/// by this type.
/// @see ConstantIntegeral
/// @brief Override implementation
virtual bool isMaxValue() const {
- int64_t V = getValue();
- if (V < 0) return false; // Be careful about wrap-around on 'long's
- ++V;
- return !isValueValidForType(getType(), V) || V < 0;
+ if (getType()->isSigned()) {
+ int64_t V = getSExtValue();
+ if (V < 0) return false; // Be careful about wrap-around on 'long's
+ ++V;
+ return !isValueValidForType(getType(), V) || V < 0;
+ }
+ return isAllOnesValue();
}
/// @returns true if this is the smallest value that may be represented by
@@ -255,52 +219,19 @@ public:
/// @see ConstantIntegral
/// @brief Override implementation
virtual bool isMinValue() const {
- int64_t V = getValue();
- if (V > 0) return false; // Be careful about wrap-around on 'long's
- --V;
- return !isValueValidForType(getType(), V) || V > 0;
+ if (getType()->isSigned()) {
+ int64_t V = getSExtValue();
+ if (V > 0) return false; // Be careful about wrap-around on 'long's
+ --V;
+ return !isValueValidForType(getType(), V) || V > 0;
+ }
+ return getZExtValue() == 0;
}
- /// @brief Methods to support type inquiry through isa, cast, and dyn_cast:
- static inline bool classof(const ConstantSInt *) { return true; }
- static bool classof(const Value *V) {
- return V->getValueType() == ConstantSIntVal;
- }
-};
-
-//===----------------------------------------------------------------------===//
-/// A concrete class that represents constant unsigned integer values of type
-/// Type::UByteTy, Type::UShortTy, Type::UIntTy, or Type::ULongTy.
-/// @brief Constant Unsigned Integer Class
-class ConstantUInt : public ConstantInt {
- ConstantUInt(const ConstantUInt &); // DO NOT IMPLEMENT
- friend struct ConstantCreator<ConstantUInt, Type, uint64_t>;
-protected:
- ConstantUInt(const Type *Ty, uint64_t V);
-public:
- /// get() - Static factory methods - Return objects of the specified value
- ///
- static ConstantUInt *get(const Type *Ty, uint64_t V);
-
- /// isValueValidForType - return true if Ty is big enough to represent V.
- ///
- static bool isValueValidForType(const Type *Ty, uint64_t V);
-
- /// getValue - return the underlying value of this constant.
- ///
- inline uint64_t getValue() const { return Val.Unsigned; }
-
- /// isMaxValue - Return true if this is the largest value that may be
- /// represented by this type.
- ///
- virtual bool isAllOnesValue() const;
- virtual bool isMaxValue() const { return isAllOnesValue(); }
- virtual bool isMinValue() const { return getValue() == 0; }
-
- /// Methods for support type inquiry through isa, cast, and dyn_cast:
- static inline bool classof(const ConstantUInt *) { return true; }
+ /// @brief Methods to support type inquiry through isa, cast, and dyn_cast.
+ static inline bool classof(const ConstantInt *) { return true; }
static bool classof(const Value *V) {
- return V->getValueType() == ConstantUIntVal;
+ return V->getValueType() == ConstantIntVal;
}
};
@@ -591,8 +522,7 @@ public:
}
/// getSizeOf constant expr - computes the size of a type in a target
- /// independent way (Note: the return type is ULong but the object is not
- /// necessarily a ConstantUInt).
+ /// independent way (Note: the return type is a ULong).
///
static Constant *getSizeOf(const Type *Ty);
diff --git a/include/llvm/IntrinsicInst.h b/include/llvm/IntrinsicInst.h
index 996c83cb8e..4e4d47513d 100644
--- a/