TBAA, separate different types of heap load/store.
Change-Id: I24dc2857db2985239e17d97fdd6463d7f2b54985
diff --git a/src/compiler_llvm/backend_types.h b/src/compiler_llvm/backend_types.h
index 7e7e2d3..f7449a5 100644
--- a/src/compiler_llvm/backend_types.h
+++ b/src/compiler_llvm/backend_types.h
@@ -35,6 +35,7 @@
kFloat,
kDouble,
kObject,
+ MAX_JTYPE
};
@@ -58,7 +59,9 @@
enum TBAASpecialType {
kTBAARegister,
kTBAAStackTemp,
- kTBAAMemory,
+ kTBAAHeapArray,
+ kTBAAHeapInstance,
+ kTBAAHeapStatic,
kTBAAJRuntime,
kTBAARuntimeInfo,
kTBAAConstJObject,
@@ -124,10 +127,11 @@
case kObject:
return kRegObject;
- }
- LOG(FATAL) << "Unknown java type: " << jty;
- return kRegUnknown;
+ default:
+ LOG(FATAL) << "Unknown java type: " << jty;
+ return kRegUnknown;
+ }
}
diff --git a/src/compiler_llvm/dalvik_reg.cc b/src/compiler_llvm/dalvik_reg.cc
index 3d87a43..6f7e908 100644
--- a/src/compiler_llvm/dalvik_reg.cc
+++ b/src/compiler_llvm/dalvik_reg.cc
@@ -157,6 +157,10 @@
case kDouble:
case kObject:
return irb_.CreateLoad(GetAddr(jty, space), kTBAARegister);
+
+ default:
+ LOG(FATAL) << "Unknown java type: " << jty;
+ return NULL;
}
}
@@ -203,6 +207,9 @@
case kObject:
irb_.CreateStore(value, GetAddr(jty, space), kTBAARegister);
break;
+
+ default:
+ LOG(FATAL) << "Unknown java type: " << jty;
}
}
}
diff --git a/src/compiler_llvm/ir_builder.cc b/src/compiler_llvm/ir_builder.cc
index 998ec04..8b2f0f7 100644
--- a/src/compiler_llvm/ir_builder.cc
+++ b/src/compiler_llvm/ir_builder.cc
@@ -82,10 +82,11 @@
case kObject:
return getJObjectTy();
- }
- LOG(FATAL) << "Unknown java type: " << jty;
- return NULL;
+ default:
+ LOG(FATAL) << "Unknown java type: " << jty;
+ return NULL;
+ }
}
@@ -142,10 +143,11 @@
case kObject:
return getJObjectTy();
- }
- LOG(FATAL) << "Unknown java type: " << jty;
- return NULL;
+ default:
+ LOG(FATAL) << "Unknown java type: " << jty;
+ return NULL;
+ }
}
diff --git a/src/compiler_llvm/ir_builder.h b/src/compiler_llvm/ir_builder.h
index 4dbc1b5..4b7642d 100644
--- a/src/compiler_llvm/ir_builder.h
+++ b/src/compiler_llvm/ir_builder.h
@@ -80,6 +80,16 @@
return CreateStore(val, ptr, tbaa_.GetSpecialType(special_ty));
}
+ llvm::LoadInst* CreateLoad(llvm::Value* ptr, TBAASpecialType special_ty, JType j_ty) {
+ return CreateLoad(ptr, tbaa_.GetMemoryJType(special_ty, j_ty));
+ }
+
+ llvm::StoreInst* CreateStore(llvm::Value* val, llvm::Value* ptr,
+ TBAASpecialType special_ty, JType j_ty) {
+ DCHECK_NE(special_ty, kTBAAConstJObject) << "ConstJObject is read only!";
+ return CreateStore(val, ptr, tbaa_.GetMemoryJType(special_ty, j_ty));
+ }
+
llvm::Value* LoadFromObjectOffset(llvm::Value* object_addr,
int64_t offset,
llvm::Type* type,
@@ -339,10 +349,11 @@
case kObject:
return getJNull();
- }
- LOG(FATAL) << "Unknown java type: " << jty;
- return NULL;
+ default:
+ LOG(FATAL) << "Unknown java type: " << jty;
+ return NULL;
+ }
}
diff --git a/src/compiler_llvm/method_compiler.cc b/src/compiler_llvm/method_compiler.cc
index 193f570..d61c913 100644
--- a/src/compiler_llvm/method_compiler.cc
+++ b/src/compiler_llvm/method_compiler.cc
@@ -1866,7 +1866,7 @@
reg_value = EmitLoadDalvikReg(reg_index, kObject, kAccurate);
}
- irb_.CreateStore(reg_value, data_field_addr, kTBAAMemory);
+ irb_.CreateStore(reg_value, data_field_addr, kTBAAHeapArray);
data_field_addr =
irb_.CreatePtrDisp(data_field_addr, elem_size, field_type);
@@ -2283,7 +2283,7 @@
llvm::Value* array_elem_addr =
EmitArrayGEP(array_addr, index_value, elem_type, elem_jty);
- llvm::Value* array_elem_value = irb_.CreateLoad(array_elem_addr, kTBAAMemory);
+ llvm::Value* array_elem_value = irb_.CreateLoad(array_elem_addr, kTBAAHeapArray, elem_jty);
EmitStoreDalvikReg(dec_insn.vA, elem_jty, kArray, array_elem_value);
@@ -2319,7 +2319,7 @@
EmitMarkGCCard(new_value, array_addr);
}
- irb_.CreateStore(new_value, array_elem_addr, kTBAAMemory);
+ irb_.CreateStore(new_value, array_elem_addr, kTBAAHeapArray, elem_jty);
irb_.CreateBr(GetNextBasicBlock(dex_pc));
}
@@ -2380,7 +2380,7 @@
// TODO: Check is_volatile. We need to generate atomic load instruction
// when is_volatile is true.
- field_value = irb_.CreateLoad(field_addr, kTBAAMemory);
+ field_value = irb_.CreateLoad(field_addr, kTBAAHeapInstance, field_jty);
}
EmitStoreDalvikReg(dec_insn.vA, field_jty, kField, field_value);
@@ -2444,7 +2444,7 @@
// TODO: Check is_volatile. We need to generate atomic store instruction
// when is_volatile is true.
- irb_.CreateStore(new_value, field_addr, kTBAAMemory);
+ irb_.CreateStore(new_value, field_addr, kTBAAHeapInstance, field_jty);
if (field_jty == kObject) { // If put an object, mark the GC card table.
EmitMarkGCCard(new_value, object_addr);
@@ -2581,7 +2581,7 @@
// TODO: Check is_volatile. We need to generate atomic load instruction
// when is_volatile is true.
- static_field_value = irb_.CreateLoad(static_field_addr, kTBAAMemory);
+ static_field_value = irb_.CreateLoad(static_field_addr, kTBAAHeapStatic, field_jty);
}
EmitStoreDalvikReg(dec_insn.vA, field_jty, kField, static_field_value);
@@ -2660,7 +2660,7 @@
// TODO: Check is_volatile. We need to generate atomic store instruction
// when is_volatile is true.
- irb_.CreateStore(new_value, static_field_addr, kTBAAMemory);
+ irb_.CreateStore(new_value, static_field_addr, kTBAAHeapStatic, field_jty);
if (field_jty == kObject) { // If put an object, mark the GC card table.
EmitMarkGCCard(new_value, static_storage_addr);
diff --git a/src/compiler_llvm/tbaa_info.cc b/src/compiler_llvm/tbaa_info.cc
index 01a1978..d1b351f 100644
--- a/src/compiler_llvm/tbaa_info.cc
+++ b/src/compiler_llvm/tbaa_info.cc
@@ -42,15 +42,14 @@
llvm::MDNode*& spec_ty = special_type_[sty_id];
if (spec_ty == NULL) {
switch (sty_id) {
- case kTBAARegister: spec_ty = GenTBAANode("Register", GetRootType()); break;
- case kTBAAStackTemp: spec_ty = GenTBAANode("StackTemp", GetRootType()); break;
- case kTBAAMemory: spec_ty = GenTBAANode("Memory", GetRootType()); break;
- case kTBAAMemoryArray: spec_ty = GenTBAANode("MemoryArray", GetRootType()); break;
- case kTBAAMemoryIdentified: spec_ty = GenTBAANode("MemoryIdentified", GetRootType()); break;
- case kTBAAMemoryStatic: spec_ty = GenTBAANode("MemoryStatic", GetRootType()); break;
- case kTBAAJRuntime: spec_ty = GenTBAANode("JRuntime", GetRootType()); break;
- case kTBAARuntimeInfo: spec_ty = GenTBAANode("RuntimeInfo", GetRootType()); break;
- case kTBAAConstJObject: spec_ty = GenTBAANode("ConstJObject", GetRootType(), true); break;
+ case kTBAARegister: spec_ty = GenTBAANode("Register", GetRootType()); break;
+ case kTBAAStackTemp: spec_ty = GenTBAANode("StackTemp", GetRootType()); break;
+ case kTBAAHeapArray: spec_ty = GenTBAANode("HeapArray", GetRootType()); break;
+ case kTBAAHeapInstance: spec_ty = GenTBAANode("HeapInstance", GetRootType()); break;
+ case kTBAAHeapStatic: spec_ty = GenTBAANode("HeapStatic", GetRootType()); break;
+ case kTBAAJRuntime: spec_ty = GenTBAANode("JRuntime", GetRootType()); break;
+ case kTBAARuntimeInfo: spec_ty = GenTBAANode("RuntimeInfo", GetRootType()); break;
+ case kTBAAConstJObject: spec_ty = GenTBAANode("ConstJObject", GetRootType(), true); break;
default:
LOG(FATAL) << "Unknown TBAA special type: " << sty_id;
break;
@@ -59,6 +58,50 @@
return spec_ty;
}
+llvm::MDNode* TBAAInfo::GetMemoryJType(TBAASpecialType sty_id, JType jty_id) {
+ DCHECK(sty_id == kTBAAHeapArray ||
+ sty_id == kTBAAHeapInstance ||
+ sty_id == kTBAAHeapStatic) << "SpecialType must be array, identified, or static";
+
+ DCHECK_GE(jty_id, 0) << "Unknown JType: " << jty_id;
+ DCHECK_LT(jty_id, MAX_JTYPE) << "Unknown JType: " << jty_id;
+ DCHECK_NE(jty_id, kVoid) << "Can't load/store Void type!";
+
+ std::string name;
+ size_t sty_mapped_index = 0;
+ switch (sty_id) {
+ case kTBAAHeapArray: sty_mapped_index = 0; name = "HeapArray "; break;
+ case kTBAAHeapInstance: sty_mapped_index = 1; name = "HeapInstance "; break;
+ case kTBAAHeapStatic: sty_mapped_index = 2; name = "HeapStatic "; break;
+ default:
+ LOG(FATAL) << "Unknown TBAA special type: " << sty_id;
+ break;
+ }
+
+ llvm::MDNode*& spec_ty = memory_jtype_[sty_mapped_index][jty_id];
+ if (spec_ty != NULL) {
+ return spec_ty;
+ }
+
+ switch (jty_id) {
+ case kBoolean: name += "Boolean"; break;
+ case kByte: name += "Byte"; break;
+ case kChar: name += "Char"; break;
+ case kShort: name += "Short"; break;
+ case kInt: name += "Int"; break;
+ case kLong: name += "Long"; break;
+ case kFloat: name += "Float"; break;
+ case kDouble: name += "Double"; break;
+ case kObject: name += "Object"; break;
+ default:
+ LOG(FATAL) << "Unknown JType: " << jty_id;
+ break;
+ }
+
+ spec_ty = GenTBAANode(name, GetSpecialType(sty_id));
+ return spec_ty;
+}
+
llvm::MDNode* TBAAInfo::GenTBAANode(llvm::StringRef name, llvm::MDNode* parent, bool read_only) {
llvm::SmallVector<llvm::Value*, 3> array_ref;
diff --git a/src/compiler_llvm/tbaa_info.h b/src/compiler_llvm/tbaa_info.h
index 0df732b..1fe9314 100644
--- a/src/compiler_llvm/tbaa_info.h
+++ b/src/compiler_llvm/tbaa_info.h
@@ -35,12 +35,15 @@
public:
TBAAInfo(llvm::LLVMContext& context) : context_(context), root_(NULL) {
std::memset(special_type_, 0, sizeof(special_type_));
+ std::memset(memory_jtype_, 0, sizeof(memory_jtype_));
}
llvm::MDNode* GetRootType();
llvm::MDNode* GetSpecialType(TBAASpecialType special_ty);
+ llvm::MDNode* GetMemoryJType(TBAASpecialType special_ty, JType j_ty);
+
llvm::MDNode* GenTBAANode(llvm::StringRef name,
llvm::MDNode* parent = NULL,
bool readonly = false);
@@ -49,6 +52,9 @@
llvm::LLVMContext& context_;
llvm::MDNode* root_;
llvm::MDNode* special_type_[MAX_TBAA_SPECIAL_TYPE];
+ // There are 3 categories of memory types will not alias: array element, identified field, and
+ // static field.
+ llvm::MDNode* memory_jtype_[3][MAX_JTYPE];
};