aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ExecutionEngine/ExecutionEngine.cpp
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2006-11-27 01:05:10 +0000
committerReid Spencer <rspencer@reidspencer.com>2006-11-27 01:05:10 +0000
commit3da59db637a887474c1b1346c1f3ccf53b6c4663 (patch)
treeb061e2133efdb9ea9bb334c1b15ceea881bb88f8 /lib/ExecutionEngine/ExecutionEngine.cpp
parent5fed9b90447a9a95a1f670ccd9c23aea8c937451 (diff)
downloadexternal_llvm-3da59db637a887474c1b1346c1f3ccf53b6c4663.zip
external_llvm-3da59db637a887474c1b1346c1f3ccf53b6c4663.tar.gz
external_llvm-3da59db637a887474c1b1346c1f3ccf53b6c4663.tar.bz2
For PR950:
The long awaited CAST patch. This introduces 12 new instructions into LLVM to replace the cast instruction. Corresponding changes throughout LLVM are provided. This passes llvm-test, llvm/test, and SPEC CPUINT2000 with the exception of 175.vpr which fails only on a slight floating point output difference. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31931 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine/ExecutionEngine.cpp')
-rw-r--r--lib/ExecutionEngine/ExecutionEngine.cpp56
1 files changed, 36 insertions, 20 deletions
diff --git a/lib/ExecutionEngine/ExecutionEngine.cpp b/lib/ExecutionEngine/ExecutionEngine.cpp
index 9b50669..3c4d9d5 100644
--- a/lib/ExecutionEngine/ExecutionEngine.cpp
+++ b/lib/ExecutionEngine/ExecutionEngine.cpp
@@ -213,7 +213,7 @@ void ExecutionEngine::runStaticConstructorsDestructors(bool isDtors) {
break; // Found a null terminator, exit.
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(FP))
- if (CE->getOpcode() == Instruction::Cast)
+ if (CE->isCast())
FP = CE->getOperand(0);
if (Function *F = dyn_cast<Function>(FP)) {
// Execute the ctor/dtor function!
@@ -299,15 +299,21 @@ void *ExecutionEngine::getPointerToGlobal(const GlobalValue *GV) {
return state.getGlobalAddressMap(locked)[GV];
}
-/// FIXME: document
-///
+/// This function converts a Constant* into a GenericValue. The interesting
+/// part is if C is a ConstantExpr.
+/// @brief Get a GenericValue for a Constnat*
GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
+ // Declare the result as garbage.
GenericValue Result;
+
+ // If its undefined, return the garbage.
if (isa<UndefValue>(C)) return Result;
- if (ConstantExpr *CE = const_cast<ConstantExpr*>(dyn_cast<ConstantExpr>(C))) {
+ // If the value is a ConstantExpr
+ if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
switch (CE->getOpcode()) {
case Instruction::GetElementPtr: {
+ // Compute the index
Result = getConstantValue(CE->getOperand(0));
std::vector<Value*> Indexes(CE->op_begin()+1, CE->op_end());
uint64_t Offset =
@@ -319,24 +325,35 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
Result.LongVal += Offset;
return Result;
}
- case Instruction::Cast: {
- // We only need to handle a few cases here. Almost all casts will
- // automatically fold, just the ones involving pointers won't.
- //
+ case Instruction::Trunc:
+ case Instruction::ZExt:
+ case Instruction::SExt:
+ case Instruction::FPTrunc:
+ case Instruction::FPExt:
+ case Instruction::UIToFP:
+ case Instruction::SIToFP:
+ case Instruction::FPToUI:
+ case Instruction::FPToSI:
+ break;
+ case Instruction::PtrToInt: {
+ Constant *Op = CE->getOperand(0);
+ GenericValue GV = getConstantValue(Op);
+ return GV;
+ }
+ case Instruction::BitCast: {
+ // Bit casts are no-ops but we can only return the GV of the operand if
+ // they are the same basic type (pointer->pointer, packed->packed, etc.)
Constant *Op = CE->getOperand(0);
GenericValue GV = getConstantValue(Op);
-
- // Handle cast of pointer to pointer...
if (Op->getType()->getTypeID() == C->getType()->getTypeID())
return GV;
-
- // Handle a cast of pointer to any integral type...
- if (isa<PointerType>(Op->getType()) && C->getType()->isIntegral())
- return GV;
-
- // Handle cast of integer to a pointer...
- if (isa<PointerType>(C->getType()) && Op->getType()->isIntegral())
- switch (Op->getType()->getTypeID()) {
+ break;
+ }
+ case Instruction::IntToPtr: {
+ // IntToPtr casts are just so special. Cast to intptr_t first.
+ Constant *Op = CE->getOperand(0);
+ GenericValue GV = getConstantValue(Op);
+ switch (Op->getType()->getTypeID()) {
case Type::BoolTyID: return PTOGV((void*)(uintptr_t)GV.BoolVal);
case Type::SByteTyID: return PTOGV((void*)( intptr_t)GV.SByteVal);
case Type::UByteTyID: return PTOGV((void*)(uintptr_t)GV.UByteVal);
@@ -347,10 +364,9 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
case Type::LongTyID: return PTOGV((void*)( intptr_t)GV.LongVal);
case Type::ULongTyID: return PTOGV((void*)(uintptr_t)GV.ULongVal);
default: assert(0 && "Unknown integral type!");
- }
+ }
break;
}
-
case Instruction::Add:
switch (CE->getOperand(0)->getType()->getTypeID()) {
default: assert(0 && "Bad add type!"); abort();