Updated our IR processing to reflect best practices
for making pointer-valued constants.
llvm-svn: 197829
diff --git a/lldb/source/Expression/IRForTarget.cpp b/lldb/source/Expression/IRForTarget.cpp
index 1d9faa6..a998896 100644
--- a/lldb/source/Expression/IRForTarget.cpp
+++ b/lldb/source/Expression/IRForTarget.cpp
@@ -105,6 +105,7 @@
m_data_allocator(execution_unit),
m_CFStringCreateWithBytes(NULL),
m_sel_registerName(NULL),
+ m_intptr_ty(NULL),
m_error_stream(error_stream),
m_result_store(NULL),
m_result_is_pointer(false),
@@ -285,9 +286,8 @@
IRForTarget::BuildFunctionPointer (llvm::Type *type,
uint64_t ptr)
{
- IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(), 64);
PointerType *fun_ptr_ty = PointerType::getUnqual(type);
- Constant *fun_addr_int = ConstantInt::get(intptr_ty, ptr, false);
+ Constant *fun_addr_int = ConstantInt::get(m_intptr_ty, ptr, false);
return ConstantExpr::getIntToPtr(fun_addr_int, fun_ptr_ty);
}
@@ -725,7 +725,6 @@
Type *ns_str_ty = ns_str->getType();
Type *i8_ptr_ty = Type::getInt8PtrTy(m_module->getContext());
- IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(), 64);
Type *i32_ty = Type::getInt32Ty(m_module->getContext());
Type *i8_ty = Type::getInt8Ty(m_module->getContext());
@@ -772,7 +771,7 @@
arg_type_array[0] = i8_ptr_ty;
arg_type_array[1] = i8_ptr_ty;
- arg_type_array[2] = intptr_ty;
+ arg_type_array[2] = m_intptr_ty;
arg_type_array[3] = i32_ty;
arg_type_array[4] = i8_ty;
@@ -782,7 +781,7 @@
// Build the constant containing the pointer to the function
PointerType *CFSCWB_ptr_ty = PointerType::getUnqual(CFSCWB_ty);
- Constant *CFSCWB_addr_int = ConstantInt::get(intptr_ty, CFStringCreateWithBytes_addr, false);
+ Constant *CFSCWB_addr_int = ConstantInt::get(m_intptr_ty, CFStringCreateWithBytes_addr, false);
m_CFStringCreateWithBytes = ConstantExpr::getIntToPtr(CFSCWB_addr_int, CFSCWB_ptr_ty);
}
@@ -793,7 +792,7 @@
Constant *alloc_arg = Constant::getNullValue(i8_ptr_ty);
Constant *bytes_arg = cstr ? ConstantExpr::getBitCast(cstr, i8_ptr_ty) : Constant::getNullValue(i8_ptr_ty);
- Constant *numBytes_arg = ConstantInt::get(intptr_ty, cstr ? string_array->getNumElements() - 1 : 0, false);
+ Constant *numBytes_arg = ConstantInt::get(m_intptr_ty, cstr ? string_array->getNumElements() - 1 : 0, false);
Constant *encoding_arg = ConstantInt::get(i32_ty, 0x0600, false); /* 0x0600 is kCFStringEncodingASCII */
Constant *isExternal_arg = ConstantInt::get(i8_ty, 0x0, false); /* 0x0 is false */
@@ -1146,9 +1145,8 @@
llvm::Type *srN_type = FunctionType::get(sel_ptr_type, srN_arg_types, false);
// Build the constant containing the pointer to the function
- IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(), 64);
PointerType *srN_ptr_ty = PointerType::getUnqual(srN_type);
- Constant *srN_addr_int = ConstantInt::get(intptr_ty, sel_registerName_addr, false);
+ Constant *srN_addr_int = ConstantInt::get(m_intptr_ty, sel_registerName_addr, false);
m_sel_registerName = ConstantExpr::getIntToPtr(srN_addr_int, srN_ptr_ty);
}
@@ -1595,9 +1593,8 @@
log->Printf("Found \"%s\" at 0x%" PRIx64, name.GetCString(), symbol_addr);
Type *symbol_type = symbol->getType();
- IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(), 64);
- Constant *symbol_addr_int = ConstantInt::get(intptr_ty, symbol_addr, false);
+ Constant *symbol_addr_int = ConstantInt::get(m_intptr_ty, symbol_addr, false);
Value *symbol_addr_ptr = ConstantExpr::getIntToPtr(symbol_addr_int, symbol_type);
@@ -1675,9 +1672,7 @@
if (load_instructions.empty())
return false;
- IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(), 64);
-
- Constant *class_addr = ConstantInt::get(intptr_ty, (uint64_t)class_ptr);
+ Constant *class_addr = ConstantInt::get(m_intptr_ty, (uint64_t)class_ptr);
for (LoadInst *load_instruction : load_instructions)
{
@@ -2492,9 +2487,7 @@
llvm::Constant *
IRForTarget::BuildRelocation(llvm::Type *type, uint64_t offset)
{
- IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(), 64);
-
- llvm::Constant *offset_int = ConstantInt::get(intptr_ty, offset);
+ llvm::Constant *offset_int = ConstantInt::get(m_intptr_ty, offset);
llvm::Constant *offset_array[1];
@@ -2529,9 +2522,7 @@
if (!allocation || allocation == LLDB_INVALID_ADDRESS)
return false;
- IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(), 64);
-
- Constant *relocated_addr = ConstantInt::get(intptr_ty, (uint64_t)allocation);
+ Constant *relocated_addr = ConstantInt::get(m_intptr_ty, (uint64_t)allocation);
Constant *relocated_bitcast = ConstantExpr::getIntToPtr(relocated_addr, llvm::Type::getInt8PtrTy(m_module->getContext()));
m_reloc_placeholder->replaceAllUsesWith(relocated_bitcast);
@@ -2598,6 +2589,7 @@
m_module = &llvm_module;
m_target_data.reset(new DataLayout(m_module));
+ m_intptr_ty = llvm::Type::getIntNTy(m_module->getContext(), m_target_data->getPointerSizeInBits());
if (log)
{
@@ -2632,13 +2624,13 @@
return false;
}
- llvm::Type *intptr_ty = Type::getInt8Ty(m_module->getContext());
+ llvm::Type *int8_ty = Type::getInt8Ty(m_module->getContext());
m_reloc_placeholder = new llvm::GlobalVariable((*m_module),
- intptr_ty,
+ int8_ty,
false /* IsConstant */,
GlobalVariable::InternalLinkage,
- Constant::getNullValue(intptr_ty),
+ Constant::getNullValue(int8_ty),
"reloc_placeholder",
NULL /* InsertBefore */,
GlobalVariable::NotThreadLocal /* ThreadLocal */,