[llvm-commits] CVS: llvm-java/lib/Compiler/Support.h OperandStack.cpp Locals.cpp Compiler.cpp
Alkis Evlogimenos
alkis at cs.uiuc.edu
Fri Jan 21 05:53:38 PST 2005
Changes in directory llvm-java/lib/Compiler:
Support.h added (r1.1)
OperandStack.cpp updated: 1.7 -> 1.8
Locals.cpp updated: 1.6 -> 1.7
Compiler.cpp updated: 1.185 -> 1.186
---
Log message:
Pull some common functions in Support.h.
---
Diffs of the changes: (+75 -53)
Index: llvm-java/lib/Compiler/Support.h
diff -c /dev/null llvm-java/lib/Compiler/Support.h:1.1
*** /dev/null Fri Jan 21 07:53:37 2005
--- llvm-java/lib/Compiler/Support.h Fri Jan 21 07:53:27 2005
***************
*** 0 ****
--- 1,44 ----
+ //===-- Support.h - Support functions ---------------------------*- C++ -*-===//
+ //
+ // The LLVM Compiler Infrastructure
+ //
+ // This file was developed by the LLVM research group and is distributed under
+ // the University of Illinois Open Source License. See LICENSE.TXT for details.
+ //
+ //===----------------------------------------------------------------------===//
+ //
+ // This file contains support functions for the compiler.
+ //
+ //===----------------------------------------------------------------------===//
+
+ #ifndef LLVM_JAVA_SUPPORT_H
+ #define LLVM_JAVA_SUPPORT_H
+
+ #include <llvm/Type.h>
+ #include <llvm/Java/Compiler.h>
+
+ namespace llvm { namespace Java {
+
+ inline const Type* getStorageType(const Type* type) {
+ if (isa<PointerType>(type))
+ return ObjectBaseRefTy;
+ else if (type == Type::BoolTy ||
+ type == Type::SByteTy ||
+ type == Type::UShortTy ||
+ type == Type::ShortTy)
+ return Type::IntTy;
+ else
+ return type;
+ }
+
+ inline bool isTwoSlotType(const Type* type) {
+ return type == Type::LongTy || type == Type::DoubleTy;
+ }
+
+ inline bool isOneSlotType(const Type* type) {
+ return !isTwoSlotType(type);
+ }
+
+ } } // namespace llvm::Java
+
+ #endif//LLVM_JAVA_SUPPORT_H
Index: llvm-java/lib/Compiler/OperandStack.cpp
diff -u llvm-java/lib/Compiler/OperandStack.cpp:1.7 llvm-java/lib/Compiler/OperandStack.cpp:1.8
--- llvm-java/lib/Compiler/OperandStack.cpp:1.7 Mon Jan 17 12:21:03 2005
+++ llvm-java/lib/Compiler/OperandStack.cpp Fri Jan 21 07:53:27 2005
@@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//
#include "OperandStack.h"
+#include "Support.h"
#include <llvm/BasicBlock.h>
#include <llvm/DerivedTypes.h>
#include <llvm/Function.h>
@@ -27,33 +28,24 @@
assert(currentDepth < TheStack.size() && "Pushing to a full stack!");
const Type* valueTy = value->getType();
- // All pointer types are cast to a pointer to
- // llvm_java_lang_object_base.
- if (isa<PointerType>(valueTy))
- value = new CastInst(value, ObjectBaseRefTy,
- "to-object-base", insertAtEnd);
- // Values of jboolean, jbyte, jchar and jshort are extended to a
- // jint when pushed on the operand stack.
- else if (valueTy == Type::BoolTy ||
- valueTy == Type::SByteTy ||
- valueTy == Type::UShortTy ||
- valueTy == Type::ShortTy)
- value = new CastInst(value, Type::IntTy, "int-extend", insertAtEnd);
+ const Type* storageTy = getStorageType(valueTy);
+ if (valueTy != storageTy)
+ value = new CastInst(value, storageTy, "to-storage-type", insertAtEnd);
// If we don't have an alloca already for this slot create one
if (!TheStack[currentDepth] ||
- TheStack[currentDepth]->getAllocatedType() != value->getType()) {
+ TheStack[currentDepth]->getAllocatedType() != storageTy) {
// Insert the alloca at the beginning of the entry block.
BasicBlock* entry = &insertAtEnd->getParent()->getEntryBlock();
if (entry->empty())
TheStack[currentDepth] =
- new AllocaInst(value->getType(),
+ new AllocaInst(storageTy,
NULL,
"opStack" + utostr(currentDepth),
entry);
else
TheStack[currentDepth] =
- new AllocaInst(value->getType(),
+ new AllocaInst(storageTy,
NULL,
"opStack" + utostr(currentDepth),
&entry->front());
Index: llvm-java/lib/Compiler/Locals.cpp
diff -u llvm-java/lib/Compiler/Locals.cpp:1.6 llvm-java/lib/Compiler/Locals.cpp:1.7
--- llvm-java/lib/Compiler/Locals.cpp:1.6 Mon Jan 17 17:00:04 2005
+++ llvm-java/lib/Compiler/Locals.cpp Fri Jan 21 07:53:27 2005
@@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//
#include "Locals.h"
+#include "Support.h"
#include <llvm/BasicBlock.h>
#include <llvm/DerivedTypes.h>
#include <llvm/Function.h>
@@ -31,52 +32,44 @@
void Locals::store(unsigned i, Value* value, BasicBlock* insertAtEnd)
{
const Type* valueTy = value->getType();
- // All pointer types are cast to a pointer to
- // llvm_java_lang_object_base.
- if (isa<PointerType>(valueTy))
- value = new CastInst(value, ObjectBaseRefTy,
- "to-object-base", insertAtEnd);
-
- // Values of jboolean, jbyte, jchar and jshort are extended to a
- // jint when stored in a local slot.
- else if (valueTy == Type::BoolTy ||
- valueTy == Type::SByteTy ||
- valueTy == Type::UShortTy ||
- valueTy == Type::ShortTy)
- value = new CastInst(value, Type::IntTy, "int-extend", insertAtEnd);
-
- valueTy = value->getType();
+ const Type* storageTy = getStorageType(valueTy);
+ if (valueTy != storageTy)
+ value = new CastInst(value, storageTy, "to-storage-type", insertAtEnd);
SlotMap& slotMap = TheLocals[i];
- SlotMap::iterator it = slotMap.find(valueTy);
+ SlotMap::iterator it = slotMap.find(storageTy);
if (it == slotMap.end()) {
// Insert the alloca at the beginning of the entry block.
BasicBlock* entry = &insertAtEnd->getParent()->getEntryBlock();
AllocaInst* alloca;
if (entry->empty())
- alloca = new AllocaInst(
- value->getType(),
- NULL,
- "local" + utostr(i),
- entry);
+ alloca = new AllocaInst(storageTy,
+ NULL,
+ "local" + utostr(i),
+ entry);
else
- alloca = new AllocaInst(
- value->getType(),
- NULL,
- "local" + utostr(i),
- &entry->front());
- it = slotMap.insert(it, std::make_pair(valueTy, alloca));
+ alloca = new AllocaInst(storageTy,
+ NULL,
+ "local" + utostr(i),
+ &entry->front());
+ it = slotMap.insert(it, std::make_pair(storageTy, alloca));
}
new StoreInst(value, it->second, insertAtEnd);
}
-llvm::Value* Locals::load(unsigned i, const Type* type, BasicBlock* insertAtEnd)
+llvm::Value* Locals::load(unsigned i, const Type* valueTy,
+ BasicBlock* insertAtEnd)
{
+ const Type* storageTy = getStorageType(valueTy);
+
SlotMap& slotMap = TheLocals[i];
- SlotMap::iterator it = slotMap.find(type);
+ SlotMap::iterator it = slotMap.find(storageTy);
assert(it != slotMap.end() && "Attempt to load a non initialized global!");
- return new LoadInst(it->second, "load", insertAtEnd);
+ Value* value = new LoadInst(it->second, "load", insertAtEnd);
+ if (valueTy != storageTy)
+ value = new CastInst(value, valueTy, "from-storage-type", insertAtEnd);
+ return value;
}
Index: llvm-java/lib/Compiler/Compiler.cpp
diff -u llvm-java/lib/Compiler/Compiler.cpp:1.185 llvm-java/lib/Compiler/Compiler.cpp:1.186
--- llvm-java/lib/Compiler/Compiler.cpp:1.185 Mon Jan 17 17:00:04 2005
+++ llvm-java/lib/Compiler/Compiler.cpp Fri Jan 21 07:53:27 2005
@@ -17,6 +17,7 @@
#include "BasicBlockBuilder.h"
#include "Locals.h"
#include "OperandStack.h"
+#include "Support.h"
#include <llvm/Java/Bytecode.h>
#include <llvm/Java/BytecodeParser.h>
#include <llvm/Java/ClassFile.h>
@@ -55,18 +56,10 @@
const std::string TMP("tmp");
- inline bool isTwoSlotType(const Type* t) {
- return t == Type::LongTy | t == Type::DoubleTy;
- }
-
inline bool isTwoSlotValue(const Value* v) {
return isTwoSlotType(v->getType());
}
- inline bool isOneSlotType(const Type* t) {
- return !isTwoSlotType(t);
- }
-
inline bool isOneSlotValue(const Value* v) {
return isOneSlotType(v->getType());
}
More information about the llvm-commits
mailing list