[Lldb-commits] [lldb] r109317 - in /lldb/trunk: include/lldb/Expression/IRForTarget.h source/Expression/ClangExpressionDeclMap.cpp source/Expression/ClangResultSynthesizer.cpp source/Expression/IRForTarget.cpp

Sean Callanan scallanan at apple.com
Fri Jul 23 18:37:44 PDT 2010


Author: spyffe
Date: Fri Jul 23 20:37:44 2010
New Revision: 109317

URL: http://llvm.org/viewvc/llvm-project?rev=109317&view=rev
Log:
Updated the IR converter for the target to eliminate
spurious guard variables on expression statics.

Updated the AST result synthesizer to eliminate the
unneeded result pointer.

Very rudimentary expressions now evaluate correctly
in the target using the new JIT-based mechanism.

Modified:
    lldb/trunk/include/lldb/Expression/IRForTarget.h
    lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
    lldb/trunk/source/Expression/ClangResultSynthesizer.cpp
    lldb/trunk/source/Expression/IRForTarget.cpp

Modified: lldb/trunk/include/lldb/Expression/IRForTarget.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/IRForTarget.h?rev=109317&r1=109316&r2=109317&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/IRForTarget.h (original)
+++ lldb/trunk/include/lldb/Expression/IRForTarget.h Fri Jul 23 20:37:44 2010
@@ -42,6 +42,8 @@
                              bool Store);
     bool runOnBasicBlock(llvm::Module &M,
                          llvm::BasicBlock &BB);
+    bool removeGuards(llvm::Module &M,
+                      llvm::BasicBlock &BB);
     bool replaceVariables(llvm::Module &M,
                           llvm::Function *F);
     

Modified: lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp?rev=109317&r1=109316&r2=109317&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Fri Jul 23 20:37:44 2010
@@ -300,6 +300,12 @@
         return LLDB_INVALID_ADDRESS;
     }
     
+    if (!exe_ctx->frame)
+    {
+        err.SetErrorString("Received null execution frame");
+        return LLDB_INVALID_ADDRESS;
+    }
+    
     const SymbolContext &sym_ctx(exe_ctx->frame->GetSymbolContext(lldb::eSymbolContextEverything));
     
     if (!dematerialize)

Modified: lldb/trunk/source/Expression/ClangResultSynthesizer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangResultSynthesizer.cpp?rev=109317&r1=109316&r2=109317&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangResultSynthesizer.cpp (original)
+++ lldb/trunk/source/Expression/ClangResultSynthesizer.cpp Fri Jul 23 20:37:44 2010
@@ -147,9 +147,7 @@
     }
     
     IdentifierInfo &result_id = Ctx.Idents.get("___clang_expr_result");
-    
-    DeclContext *decl_context = function_decl->getDeclContext();
-    
+        
     clang::VarDecl *result_decl = VarDecl::Create(Ctx, 
                                                   function_decl, 
                                                   SourceLocation(), 
@@ -189,87 +187,11 @@
                                                                                        SourceLocation(),
                                                                                        SourceLocation()));
     
-    
-    ///////////////////////////////////////////////
-    // Synthesize external void pointer variable
-    //
-    
-    IdentifierInfo &result_ptr_id = Ctx.Idents.get("___clang_expr_result_ptr");
-    
-    clang::VarDecl *result_ptr_decl = VarDecl::Create(Ctx,
-                                                      decl_context,
-                                                      SourceLocation(),
-                                                      &result_ptr_id,
-                                                      Ctx.VoidPtrTy,
-                                                      NULL,
-                                                      VarDecl::Extern,
-                                                      VarDecl::Extern);
-    
-    /////////////////////////////////////////////
-    // Build a DeclRef for the result variable
-    //
-    
-    DeclRefExpr *result_decl_ref_expr = DeclRefExpr::Create(Ctx,
-                                                            NULL,
-                                                            SourceRange(),
-                                                            result_decl,
-                                                            SourceLocation(),
-                                                            expr_qual_type);
-    
-    ///////////////////////
-    // call ActOnUnaryOp
-    //
-    
-    Scope my_scope(NULL, (Scope::BlockScope | Scope::FnScope | Scope::DeclScope));
-    
-    Parser::DeclPtrTy result_ptr_decl_ptr;
-    result_ptr_decl_ptr.set(result_ptr_decl);
-        
-    Parser::OwningExprResult addressof_expr_result(m_action->ActOnUnaryOp(&my_scope,
-                                                                          SourceLocation(),
-                                                                          tok::amp,
-                                                                          Parser::ExprArg(*m_action, result_decl_ref_expr)));
-    
-    ////////////////////////////////////////////
-    // Build a DeclRef for the result pointer
-    //
-    
-    DeclRefExpr *result_ptr_decl_ref_expr = DeclRefExpr::Create(Ctx,
-                                                                NULL,
-                                                                SourceRange(),
-                                                                result_ptr_decl,
-                                                                SourceLocation(),
-                                                                Ctx.VoidPtrTy);
-    
-    ////////////////////////
-    // call ActOnBinaryOp
-    //
-    
-    Parser::OwningExprResult assignment_expr_result(m_action->ActOnBinOp(&my_scope,
-                                                                         SourceLocation(),
-                                                                         tok::equal,
-                                                                         Parser::ExprArg(*m_action, result_ptr_decl_ref_expr),
-                                                                         Parser::ExprArg(*m_action, addressof_expr_result.take())));
-    
-    ////////////////////////////
-    // call ActOnCompoundStmt
-    //
-    
-    void *stmts[2];
-    
-    stmts[0] = result_initialization_stmt_result.take();
-    stmts[1] = assignment_expr_result.take();
-    
-    Parser::OwningStmtResult compound_stmt_result(m_action->ActOnCompoundStmt(SourceLocation(), 
-                                                                              SourceLocation(), 
-                                                                              Parser::MultiStmtArg(*m_action, stmts, 2), 
-                                                                              false));
-    
     ////////////////////////////////////////////////
     // replace the old statement with the new one
     //
     
-    *last_stmt_ptr = reinterpret_cast<Stmt*>(compound_stmt_result.take());
+    *last_stmt_ptr = reinterpret_cast<Stmt*>(result_initialization_stmt_result.take());
 
     if (log)
     {

Modified: lldb/trunk/source/Expression/IRForTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRForTarget.cpp?rev=109317&r1=109316&r2=109317&view=diff
==============================================================================
--- lldb/trunk/source/Expression/IRForTarget.cpp (original)
+++ lldb/trunk/source/Expression/IRForTarget.cpp Fri Jul 23 20:37:44 2010
@@ -162,6 +162,85 @@
     return s;
 }
 
+static bool isGuardVariableRef(llvm::Value *V)
+{
+    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)
+        ui->replaceUsesOfWith(guard_load, zero);
+    
+    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.
+    //
+    
+    llvm::BasicBlock::iterator ii;
+    
+    typedef llvm::SmallVector <Instruction*, 2> InstrList;
+    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;
+}
+
 // 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 
@@ -363,6 +442,9 @@
     {
         if (!runOnBasicBlock(M, *bbi))
             return false;
+        
+        if (!removeGuards(M, *bbi))
+            return false;
     }
     
     if (!replaceVariables(M, function))





More information about the lldb-commits mailing list