2010-07-03 01:35:46 +00:00
|
|
|
//===-- IRForTarget.cpp -------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Expression/IRForTarget.h"
|
|
|
|
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include "llvm/InstrTypes.h"
|
2010-07-13 21:41:46 +00:00
|
|
|
#include "llvm/Instructions.h"
|
2010-07-03 01:35:46 +00:00
|
|
|
#include "llvm/Module.h"
|
2010-07-13 21:41:46 +00:00
|
|
|
#include "llvm/Target/TargetData.h"
|
|
|
|
|
|
|
|
#include "clang/AST/ASTContext.h"
|
2010-07-03 01:35:46 +00:00
|
|
|
|
|
|
|
#include "lldb/Core/dwarf.h"
|
|
|
|
#include "lldb/Core/Log.h"
|
|
|
|
#include "lldb/Core/Scalar.h"
|
|
|
|
#include "lldb/Core/StreamString.h"
|
|
|
|
#include "lldb/Expression/ClangExpressionDeclMap.h"
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
IRForTarget::IRForTarget(const void *pid,
|
2010-07-13 21:41:46 +00:00
|
|
|
lldb_private::ClangExpressionDeclMap *decl_map,
|
2010-07-27 21:39:39 +00:00
|
|
|
const TargetData *target_data) :
|
2010-07-03 01:35:46 +00:00
|
|
|
ModulePass(pid),
|
2010-07-13 21:41:46 +00:00
|
|
|
m_decl_map(decl_map),
|
|
|
|
m_target_data(target_data)
|
2010-07-03 01:35:46 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
IRForTarget::~IRForTarget()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-07-13 21:41:46 +00:00
|
|
|
static clang::NamedDecl *
|
2010-07-27 21:39:39 +00:00
|
|
|
DeclForGlobalValue(Module &module,
|
|
|
|
GlobalValue *global_value)
|
2010-07-13 21:41:46 +00:00
|
|
|
{
|
|
|
|
NamedMDNode *named_metadata = module.getNamedMetadata("clang.global.decl.ptrs");
|
|
|
|
|
|
|
|
if (!named_metadata)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
unsigned num_nodes = named_metadata->getNumOperands();
|
|
|
|
unsigned node_index;
|
|
|
|
|
|
|
|
for (node_index = 0;
|
|
|
|
node_index < num_nodes;
|
|
|
|
++node_index)
|
|
|
|
{
|
|
|
|
MDNode *metadata_node = named_metadata->getOperand(node_index);
|
|
|
|
|
|
|
|
if (!metadata_node)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (metadata_node->getNumOperands() != 2)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (metadata_node->getOperand(0) != global_value)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ConstantInt *constant_int = dyn_cast<ConstantInt>(metadata_node->getOperand(1));
|
|
|
|
|
|
|
|
if (!constant_int)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
uintptr_t ptr = constant_int->getZExtValue();
|
|
|
|
|
|
|
|
return reinterpret_cast<clang::NamedDecl *>(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IRForTarget::MaybeHandleVariable(Module &M,
|
2010-07-27 21:39:39 +00:00
|
|
|
Value *V,
|
2010-07-13 21:41:46 +00:00
|
|
|
bool Store)
|
2010-07-03 01:35:46 +00:00
|
|
|
{
|
2010-07-13 21:41:46 +00:00
|
|
|
if (GlobalVariable *global_variable = dyn_cast<GlobalVariable>(V))
|
|
|
|
{
|
|
|
|
clang::NamedDecl *named_decl = DeclForGlobalValue(M, global_variable);
|
|
|
|
|
2010-07-16 00:09:46 +00:00
|
|
|
std::string name = named_decl->getName().str();
|
|
|
|
|
|
|
|
void *qual_type = NULL;
|
2010-07-20 23:31:16 +00:00
|
|
|
clang::ASTContext *ast_context = NULL;
|
2010-07-16 00:09:46 +00:00
|
|
|
|
|
|
|
if (clang::ValueDecl *value_decl = dyn_cast<clang::ValueDecl>(named_decl))
|
2010-07-20 23:31:16 +00:00
|
|
|
{
|
2010-07-16 00:09:46 +00:00
|
|
|
qual_type = value_decl->getType().getAsOpaquePtr();
|
2010-07-20 23:31:16 +00:00
|
|
|
ast_context = &value_decl->getASTContext();
|
|
|
|
}
|
2010-07-16 00:09:46 +00:00
|
|
|
else
|
2010-07-20 23:31:16 +00:00
|
|
|
{
|
2010-07-16 00:09:46 +00:00
|
|
|
return false;
|
2010-07-20 23:31:16 +00:00
|
|
|
}
|
|
|
|
|
2010-07-27 21:39:39 +00:00
|
|
|
const Type *value_type = global_variable->getType();
|
2010-07-03 01:35:46 +00:00
|
|
|
|
2010-07-13 21:41:46 +00:00
|
|
|
size_t value_size = m_target_data->getTypeStoreSize(value_type);
|
|
|
|
off_t value_alignment = m_target_data->getPrefTypeAlignment(value_type);
|
|
|
|
|
2010-07-27 02:07:53 +00:00
|
|
|
if (named_decl && !m_decl_map->AddValueToStruct(V,
|
|
|
|
named_decl,
|
|
|
|
name,
|
|
|
|
qual_type,
|
|
|
|
ast_context,
|
|
|
|
value_size,
|
|
|
|
value_alignment))
|
2010-07-13 21:41:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-07-27 02:07:53 +00:00
|
|
|
bool
|
|
|
|
IRForTarget::MaybeHandleCall(Module &M,
|
|
|
|
CallInst *C)
|
|
|
|
{
|
|
|
|
lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
|
|
|
|
|
2010-07-27 21:39:39 +00:00
|
|
|
Function *fun = C->getCalledFunction();
|
2010-07-27 02:07:53 +00:00
|
|
|
|
|
|
|
if (fun == NULL)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
clang::NamedDecl *fun_decl = DeclForGlobalValue(M, fun);
|
|
|
|
|
|
|
|
if (!fun_decl)
|
|
|
|
{
|
|
|
|
if (log)
|
|
|
|
log->Printf("Function %s wasn't in the metadata", fun->getName().str().c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-07-27 21:39:39 +00:00
|
|
|
uint64_t fun_addr;
|
|
|
|
Value **fun_value_ptr;
|
2010-07-27 02:07:53 +00:00
|
|
|
|
2010-07-27 21:39:39 +00:00
|
|
|
if (!m_decl_map->GetFunctionInfo(fun_decl, fun_value_ptr, fun_addr))
|
2010-07-27 02:07:53 +00:00
|
|
|
{
|
|
|
|
if (log)
|
|
|
|
log->Printf("Function %s had no address", fun_decl->getNameAsCString());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (log)
|
|
|
|
log->Printf("Found %s at %llx", fun_decl->getNameAsCString(), fun_addr);
|
|
|
|
|
2010-07-27 21:39:39 +00:00
|
|
|
if (!*fun_value_ptr)
|
|
|
|
{
|
|
|
|
std::vector<const Type*> params;
|
|
|
|
|
|
|
|
const IntegerType *intptr_ty = Type::getIntNTy(M.getContext(),
|
|
|
|
(M.getPointerSize() == Module::Pointer64) ? 64 : 32);
|
|
|
|
|
|
|
|
FunctionType *fun_ty = FunctionType::get(intptr_ty, params, true);
|
|
|
|
PointerType *fun_ptr_ty = PointerType::getUnqual(fun_ty);
|
|
|
|
Constant *fun_addr_int = ConstantInt::get(intptr_ty, fun_addr, false);
|
|
|
|
Constant *fun_addr_ptr = ConstantExpr::getIntToPtr(fun_addr_int, fun_ptr_ty);
|
|
|
|
*fun_value_ptr = fun_addr_ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
C->setCalledFunction(*fun_value_ptr);
|
|
|
|
|
2010-07-27 02:07:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-07-13 21:41:46 +00:00
|
|
|
bool
|
|
|
|
IRForTarget::runOnBasicBlock(Module &M, BasicBlock &BB)
|
|
|
|
{
|
2010-07-03 01:35:46 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
// Prepare the current basic block for execution in the remote process
|
|
|
|
//
|
|
|
|
|
2010-07-27 21:39:39 +00:00
|
|
|
BasicBlock::iterator ii;
|
2010-07-13 21:41:46 +00:00
|
|
|
|
|
|
|
for (ii = BB.begin();
|
|
|
|
ii != BB.end();
|
|
|
|
++ii)
|
|
|
|
{
|
|
|
|
Instruction &inst = *ii;
|
|
|
|
|
|
|
|
if (LoadInst *load = dyn_cast<LoadInst>(&inst))
|
2010-07-27 02:07:53 +00:00
|
|
|
if (!MaybeHandleVariable(M, load->getPointerOperand(), false))
|
2010-07-13 21:41:46 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (StoreInst *store = dyn_cast<StoreInst>(&inst))
|
2010-07-27 02:07:53 +00:00
|
|
|
if (!MaybeHandleVariable(M, store->getPointerOperand(), true))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (CallInst *call = dyn_cast<CallInst>(&inst))
|
|
|
|
if (!MaybeHandleCall(M, call))
|
2010-07-13 21:41:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-07-14 23:40:29 +00:00
|
|
|
static std::string
|
2010-07-27 21:39:39 +00:00
|
|
|
PrintValue(Value *V, bool truncate = false)
|
2010-07-13 21:41:46 +00:00
|
|
|
{
|
|
|
|
std::string s;
|
|
|
|
raw_string_ostream rso(s);
|
|
|
|
V->print(rso);
|
|
|
|
rso.flush();
|
|
|
|
if (truncate)
|
|
|
|
s.resize(s.length() - 1);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2010-07-27 21:39:39 +00:00
|
|
|
static bool isGuardVariableRef(Value *V)
|
2010-07-24 01:37:44 +00:00
|
|
|
{
|
|
|
|
ConstantExpr *C = dyn_cast<ConstantExpr>(V);
|
|
|
|
|
|
|
|
if (!C || C->getOpcode() != Instruction::BitCast)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
GlobalVariable *GV = dyn_cast<GlobalVariable>(C->getOperand(0));
|
|
|
|
|
|
|
|
if (!GV || !GV->hasName() || !GV->getName().startswith("_ZGV"))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void TurnGuardLoadIntoZero(Instruction* guard_load, Module &M)
|
|
|
|
{
|
|
|
|
Constant* zero(ConstantInt::get(Type::getInt8Ty(M.getContext()), 0, true));
|
|
|
|
|
|
|
|
Value::use_iterator ui;
|
|
|
|
|
|
|
|
for (ui = guard_load->use_begin();
|
|
|
|
ui != guard_load->use_end();
|
|
|
|
++ui)
|
2010-07-27 01:17:28 +00:00
|
|
|
{
|
2010-07-30 20:30:44 +00:00
|
|
|
if (isa<Constant>(*ui))
|
2010-07-27 01:17:28 +00:00
|
|
|
{
|
|
|
|
// do nothing for the moment
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->replaceUsesOfWith(guard_load, zero);
|
|
|
|
}
|
|
|
|
}
|
2010-07-24 01:37:44 +00:00
|
|
|
|
|
|
|
guard_load->eraseFromParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ExciseGuardStore(Instruction* guard_store)
|
|
|
|
{
|
|
|
|
guard_store->eraseFromParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IRForTarget::removeGuards(Module &M, BasicBlock &BB)
|
|
|
|
{
|
|
|
|
///////////////////////////////////////////////////////
|
|
|
|
// Eliminate any reference to guard variables found.
|
|
|
|
//
|
|
|
|
|
2010-07-27 21:39:39 +00:00
|
|
|
BasicBlock::iterator ii;
|
2010-07-24 01:37:44 +00:00
|
|
|
|
2010-07-27 21:39:39 +00:00
|
|
|
typedef SmallVector <Instruction*, 2> InstrList;
|
2010-07-24 01:37:44 +00:00
|
|
|
typedef InstrList::iterator InstrIterator;
|
|
|
|
|
|
|
|
InstrList guard_loads;
|
|
|
|
InstrList guard_stores;
|
|
|
|
|
|
|
|
for (ii = BB.begin();
|
|
|
|
ii != BB.end();
|
|
|
|
++ii)
|
|
|
|
{
|
|
|
|
Instruction &inst = *ii;
|
|
|
|
|
|
|
|
if (LoadInst *load = dyn_cast<LoadInst>(&inst))
|
|
|
|
if (isGuardVariableRef(load->getPointerOperand()))
|
|
|
|
guard_loads.push_back(&inst);
|
|
|
|
|
|
|
|
if (StoreInst *store = dyn_cast<StoreInst>(&inst))
|
|
|
|
if (isGuardVariableRef(store->getPointerOperand()))
|
|
|
|
guard_stores.push_back(&inst);
|
|
|
|
}
|
|
|
|
|
|
|
|
InstrIterator iter;
|
|
|
|
|
|
|
|
for (iter = guard_loads.begin();
|
|
|
|
iter != guard_loads.end();
|
|
|
|
++iter)
|
|
|
|
TurnGuardLoadIntoZero(*iter, M);
|
|
|
|
|
|
|
|
for (iter = guard_stores.begin();
|
|
|
|
iter != guard_stores.end();
|
|
|
|
++iter)
|
|
|
|
ExciseGuardStore(*iter);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-07-14 23:40:29 +00:00
|
|
|
// UnfoldConstant operates on a constant [C] which has just been replaced with a value
|
|
|
|
// [new_value]. We assume that new_value has been properly placed early in the function,
|
|
|
|
// most likely somewhere in front of the first instruction in the entry basic block
|
|
|
|
// [first_entry_instruction].
|
|
|
|
//
|
|
|
|
// UnfoldConstant reads through the uses of C and replaces C in those uses with new_value.
|
|
|
|
// Where those uses are constants, the function generates new instructions to compute the
|
|
|
|
// result of the new, non-constant expression and places them before first_entry_instruction.
|
|
|
|
// These instructions replace the constant uses, so UnfoldConstant calls itself recursively
|
|
|
|
// for those.
|
|
|
|
|
|
|
|
static bool
|
2010-07-27 21:39:39 +00:00
|
|
|
UnfoldConstant(Constant *C, Value *new_value, Instruction *first_entry_instruction)
|
2010-07-14 23:40:29 +00:00
|
|
|
{
|
|
|
|
lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
|
|
|
|
|
|
|
|
Value::use_iterator ui;
|
|
|
|
|
|
|
|
for (ui = C->use_begin();
|
|
|
|
ui != C->use_end();
|
|
|
|
++ui)
|
|
|
|
{
|
|
|
|
User *user = *ui;
|
|
|
|
|
|
|
|
if (Constant *constant = dyn_cast<Constant>(user))
|
|
|
|
{
|
|
|
|
// synthesize a new non-constant equivalent of the constant
|
|
|
|
|
|
|
|
if (ConstantExpr *constant_expr = dyn_cast<ConstantExpr>(constant))
|
|
|
|
{
|
|
|
|
switch (constant_expr->getOpcode())
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
if (log)
|
|
|
|
log->Printf("Unhandled constant expression type: %s", PrintValue(constant_expr).c_str());
|
|
|
|
return false;
|
|
|
|
case Instruction::BitCast:
|
|
|
|
{
|
|
|
|
// UnaryExpr
|
|
|
|
// OperandList[0] is value
|
|
|
|
|
|
|
|
Value *s = constant_expr->getOperand(0);
|
|
|
|
|
|
|
|
if (s == C)
|
|
|
|
s = new_value;
|
|
|
|
|
|
|
|
BitCastInst *bit_cast(new BitCastInst(s, C->getType(), "", first_entry_instruction));
|
|
|
|
|
|
|
|
UnfoldConstant(constant_expr, bit_cast, first_entry_instruction);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Instruction::GetElementPtr:
|
|
|
|
{
|
|
|
|
// GetElementPtrConstantExpr
|
|
|
|
// OperandList[0] is base
|
|
|
|
// OperandList[1]... are indices
|
|
|
|
|
|
|
|
Value *ptr = constant_expr->getOperand(0);
|
|
|
|
|
|
|
|
if (ptr == C)
|
|
|
|
ptr = new_value;
|
|
|
|
|
|
|
|
SmallVector<Value*, 16> indices;
|
|
|
|
|
|
|
|
unsigned operand_index;
|
|
|
|
unsigned num_operands = constant_expr->getNumOperands();
|
|
|
|
|
|
|
|
for (operand_index = 1;
|
|
|
|
operand_index < num_operands;
|
|
|
|
++operand_index)
|
|
|
|
{
|
|
|
|
Value *operand = constant_expr->getOperand(operand_index);
|
|
|
|
|
|
|
|
if (operand == C)
|
|
|
|
operand = new_value;
|
|
|
|
|
|
|
|
indices.push_back(operand);
|
|
|
|
}
|
|
|
|
|
|
|
|
GetElementPtrInst *get_element_ptr(GetElementPtrInst::Create(ptr, indices.begin(), indices.end(), "", first_entry_instruction));
|
|
|
|
|
|
|
|
UnfoldConstant(constant_expr, get_element_ptr, first_entry_instruction);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (log)
|
|
|
|
log->Printf("Unhandled constant type: %s", PrintValue(constant).c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// simple fall-through case for non-constants
|
|
|
|
user->replaceUsesOfWith(C, new_value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-07-13 21:41:46 +00:00
|
|
|
bool
|
|
|
|
IRForTarget::replaceVariables(Module &M, Function *F)
|
|
|
|
{
|
|
|
|
lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
|
|
|
|
|
|
|
|
m_decl_map->DoStructLayout();
|
|
|
|
|
|
|
|
if (log)
|
|
|
|
log->Printf("Element arrangement:");
|
|
|
|
|
|
|
|
uint32_t num_elements;
|
|
|
|
uint32_t element_index;
|
|
|
|
|
|
|
|
size_t size;
|
|
|
|
off_t alignment;
|
|
|
|
|
|
|
|
if (!m_decl_map->GetStructInfo (num_elements, size, alignment))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Function::arg_iterator iter(F->getArgumentList().begin());
|
|
|
|
|
|
|
|
if (iter == F->getArgumentList().end())
|
|
|
|
return false;
|
|
|
|
|
2010-07-27 21:39:39 +00:00
|
|
|
Argument *argument = iter;
|
2010-07-13 21:41:46 +00:00
|
|
|
|
|
|
|
if (!argument->getName().equals("___clang_arg"))
|
|
|
|
return false;
|
|
|
|
|
2010-07-03 01:35:46 +00:00
|
|
|
if (log)
|
2010-07-13 21:41:46 +00:00
|
|
|
log->Printf("Arg: %s", PrintValue(argument).c_str());
|
|
|
|
|
2010-07-27 21:39:39 +00:00
|
|
|
BasicBlock &entry_block(F->getEntryBlock());
|
|
|
|
Instruction *first_entry_instruction(entry_block.getFirstNonPHIOrDbg());
|
2010-07-13 21:41:46 +00:00
|
|
|
|
|
|
|
if (!first_entry_instruction)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
LLVMContext &context(M.getContext());
|
|
|
|
const IntegerType *offset_type(Type::getInt32Ty(context));
|
|
|
|
|
|
|
|
if (!offset_type)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (element_index = 0; element_index < num_elements; ++element_index)
|
2010-07-03 01:35:46 +00:00
|
|
|
{
|
2010-07-13 21:41:46 +00:00
|
|
|
const clang::NamedDecl *decl;
|
2010-07-27 21:39:39 +00:00
|
|
|
Value *value;
|
2010-07-13 21:41:46 +00:00
|
|
|
off_t offset;
|
2010-07-03 01:35:46 +00:00
|
|
|
|
2010-07-13 21:41:46 +00:00
|
|
|
if (!m_decl_map->GetStructElement (decl, value, offset, element_index))
|
|
|
|
return false;
|
2010-07-03 01:35:46 +00:00
|
|
|
|
2010-07-13 21:41:46 +00:00
|
|
|
if (log)
|
|
|
|
log->Printf(" %s (%s) placed at %d",
|
|
|
|
decl->getIdentifier()->getNameStart(),
|
|
|
|
PrintValue(value, true).c_str(),
|
|
|
|
offset);
|
|
|
|
|
|
|
|
ConstantInt *offset_int(ConstantInt::getSigned(offset_type, offset));
|
|
|
|
GetElementPtrInst *get_element_ptr = GetElementPtrInst::Create(argument, offset_int, "", first_entry_instruction);
|
|
|
|
BitCastInst *bit_cast = new BitCastInst(get_element_ptr, value->getType(), "", first_entry_instruction);
|
|
|
|
|
2010-07-14 23:40:29 +00:00
|
|
|
if (Constant *constant = dyn_cast<Constant>(value))
|
|
|
|
UnfoldConstant(constant, bit_cast, first_entry_instruction);
|
|
|
|
else
|
|
|
|
value->replaceAllUsesWith(bit_cast);
|
2010-07-03 01:35:46 +00:00
|
|
|
}
|
|
|
|
|
2010-07-13 21:41:46 +00:00
|
|
|
if (log)
|
|
|
|
log->Printf("Total structure [align %d, size %d]", alignment, size);
|
|
|
|
|
2010-07-03 01:35:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IRForTarget::runOnModule(Module &M)
|
|
|
|
{
|
|
|
|
lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
|
|
|
|
|
2010-07-27 21:39:39 +00:00
|
|
|
Function* function = M.getFunction(StringRef("___clang_expr"));
|
2010-07-03 01:35:46 +00:00
|
|
|
|
|
|
|
if (!function)
|
|
|
|
{
|
|
|
|
if (log)
|
|
|
|
log->Printf("Couldn't find ___clang_expr() in the module");
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-07-27 21:39:39 +00:00
|
|
|
Function::iterator bbi;
|
2010-07-03 01:35:46 +00:00
|
|
|
|
|
|
|
for (bbi = function->begin();
|
|
|
|
bbi != function->end();
|
|
|
|
++bbi)
|
|
|
|
{
|
2010-07-13 21:41:46 +00:00
|
|
|
if (!runOnBasicBlock(M, *bbi))
|
|
|
|
return false;
|
2010-07-24 01:37:44 +00:00
|
|
|
|
|
|
|
if (!removeGuards(M, *bbi))
|
|
|
|
return false;
|
2010-07-13 21:41:46 +00:00
|
|
|
}
|
|
|
|
|
2010-07-28 01:00:59 +00:00
|
|
|
// TEMPORARY FOR DEBUGGING
|
|
|
|
M.dump();
|
|
|
|
|
2010-07-13 21:41:46 +00:00
|
|
|
if (!replaceVariables(M, function))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (log)
|
|
|
|
{
|
2010-07-28 01:00:59 +00:00
|
|
|
std::string s;
|
|
|
|
raw_string_ostream oss(s);
|
|
|
|
|
|
|
|
M.print(oss, NULL);
|
|
|
|
|
|
|
|
oss.flush();
|
2010-07-13 21:41:46 +00:00
|
|
|
|
2010-07-28 01:00:59 +00:00
|
|
|
log->Printf("Module after preparing for execution: \n%s", s.c_str());
|
2010-07-03 01:35:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IRForTarget::assignPassManager(PMStack &PMS,
|
2010-07-13 21:41:46 +00:00
|
|
|
PassManagerType T)
|
2010-07-03 01:35:46 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
PassManagerType
|
|
|
|
IRForTarget::getPotentialPassManagerType() const
|
|
|
|
{
|
|
|
|
return PMT_ModulePassManager;
|
|
|
|
}
|