diff options
author | Sean Callanan <scallanan@apple.com> | 2013-12-20 19:55:02 +0000 |
---|---|---|
committer | Sean Callanan <scallanan@apple.com> | 2013-12-20 19:55:02 +0000 |
commit | 439dcae4a22bea594e8298515faee7183e0598aa (patch) | |
tree | 531192865517281befc78810246d06e06ee1cce7 | |
parent | f75e5bbefc3a38d8cc479784ae4187584fbed9e8 (diff) | |
download | bcm5719-llvm-439dcae4a22bea594e8298515faee7183e0598aa.tar.gz bcm5719-llvm-439dcae4a22bea594e8298515faee7183e0598aa.zip |
Updated our IR processing to reflect best practices
for making pointer-valued constants.
llvm-svn: 197829
-rw-r--r-- | lldb/include/lldb/Expression/IRForTarget.h | 2 | ||||
-rw-r--r-- | lldb/source/Expression/IRDynamicChecks.cpp | 25 | ||||
-rw-r--r-- | lldb/source/Expression/IRForTarget.cpp | 36 |
3 files changed, 34 insertions, 29 deletions
diff --git a/lldb/include/lldb/Expression/IRForTarget.h b/lldb/include/lldb/Expression/IRForTarget.h index 56632877250..502f796d15a 100644 --- a/lldb/include/lldb/Expression/IRForTarget.h +++ b/lldb/include/lldb/Expression/IRForTarget.h @@ -30,6 +30,7 @@ namespace llvm { class GlobalValue; class GlobalVariable; class Instruction; + class IntegerType; class Module; class StoreInst; class DataLayout; @@ -650,6 +651,7 @@ private: StaticDataAllocator m_data_allocator; ///< The allocator to use for constant strings llvm::Constant *m_CFStringCreateWithBytes; ///< The address of the function CFStringCreateWithBytes, cast to the appropriate function pointer type llvm::Constant *m_sel_registerName; ///< The address of the function sel_registerName, cast to the appropriate function pointer type + llvm::IntegerType *m_intptr_ty; ///< The type of an integer large enough to hold a pointer. lldb_private::Stream *m_error_stream; ///< If non-NULL, the stream on which errors should be printed llvm::StoreInst *m_result_store; ///< If non-NULL, the store instruction that writes to the result variable. If m_has_side_effects is true, this is NULL. diff --git a/lldb/source/Expression/IRDynamicChecks.cpp b/lldb/source/Expression/IRDynamicChecks.cpp index ed47fe31a45..a75a0fca9c6 100644 --- a/lldb/source/Expression/IRDynamicChecks.cpp +++ b/lldb/source/Expression/IRDynamicChecks.cpp @@ -19,6 +19,7 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/IR/Constants.h" +#include "llvm/IR/DataLayout.h" #include "llvm/IR/Function.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/Module.h" @@ -145,7 +146,8 @@ public: DynamicCheckerFunctions &checker_functions) : m_module(module), m_checker_functions(checker_functions), - m_i8ptr_ty(NULL) + m_i8ptr_ty(NULL), + m_intptr_ty(NULL) { } @@ -279,8 +281,6 @@ protected: //------------------------------------------------------------------ llvm::Value *BuildPointerValidatorFunc(lldb::addr_t start_address) { - IntegerType *intptr_ty = llvm::Type::getIntNTy(m_module.getContext(), 64); - llvm::Type *param_array[1]; param_array[0] = const_cast<llvm::PointerType*>(GetI8PtrTy()); @@ -289,7 +289,7 @@ protected: FunctionType *fun_ty = FunctionType::get(llvm::Type::getVoidTy(m_module.getContext()), params, true); PointerType *fun_ptr_ty = PointerType::getUnqual(fun_ty); - Constant *fun_addr_int = ConstantInt::get(intptr_ty, start_address, false); + Constant *fun_addr_int = ConstantInt::get(GetIntptrTy(), start_address, false); return ConstantExpr::getIntToPtr(fun_addr_int, fun_ptr_ty); } @@ -305,8 +305,6 @@ protected: //------------------------------------------------------------------ llvm::Value *BuildObjectCheckerFunc(lldb::addr_t start_address) { - IntegerType *intptr_ty = llvm::Type::getIntNTy(m_module.getContext(), 64); - llvm::Type *param_array[2]; param_array[0] = const_cast<llvm::PointerType*>(GetI8PtrTy()); @@ -316,7 +314,7 @@ protected: FunctionType *fun_ty = FunctionType::get(llvm::Type::getVoidTy(m_module.getContext()), params, true); PointerType *fun_ptr_ty = PointerType::getUnqual(fun_ty); - Constant *fun_addr_int = ConstantInt::get(intptr_ty, start_address, false); + Constant *fun_addr_int = ConstantInt::get(GetIntptrTy(), start_address, false); return ConstantExpr::getIntToPtr(fun_addr_int, fun_ptr_ty); } @@ -328,6 +326,18 @@ protected: return m_i8ptr_ty; } + IntegerType *GetIntptrTy() + { + if (!m_intptr_ty) + { + llvm::DataLayout data_layout(&m_module); + + m_intptr_ty = llvm::Type::getIntNTy(m_module.getContext(), data_layout.getPointerSizeInBits()); + } + + return m_intptr_ty; + } + typedef std::vector <llvm::Instruction *> InstVector; typedef InstVector::iterator InstIterator; @@ -336,6 +346,7 @@ protected: DynamicCheckerFunctions &m_checker_functions; ///< The dynamic checker functions for the process private: PointerType *m_i8ptr_ty; + IntegerType *m_intptr_ty; }; class ValidPointerChecker : public Instrumenter diff --git a/lldb/source/Expression/IRForTarget.cpp b/lldb/source/Expression/IRForTarget.cpp index 1d9faa690dc..a998896a98f 100644 --- a/lldb/source/Expression/IRForTarget.cpp +++ b/lldb/source/Expression/IRForTarget.cpp @@ -105,6 +105,7 @@ IRForTarget::IRForTarget (lldb_private::ClangExpressionDeclMap *decl_map, 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 @@ llvm::Constant * 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 @@ IRForTarget::RewriteObjCConstString (llvm::GlobalVariable *ns_str, 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 @@ IRForTarget::RewriteObjCConstString (llvm::GlobalVariable *ns_str, 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 @@ IRForTarget::RewriteObjCConstString (llvm::GlobalVariable *ns_str, // 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 @@ IRForTarget::RewriteObjCConstString (llvm::GlobalVariable *ns_str, 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 @@ IRForTarget::RewriteObjCSelector (Instruction* selector_load) 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 @@ IRForTarget::HandleSymbol (Value *symbol) 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 @@ IRForTarget::HandleObjCClass(Value *classlist_reference) 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 @@ IRForTarget::ReplaceVariables (Function &llvm_function) 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 @@ IRForTarget::CompleteDataAllocation () 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 @@ IRForTarget::runOnModule (Module &llvm_module) 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 @@ IRForTarget::runOnModule (Module &llvm_module) 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 */, |