[llvm-commits] [llvm-gcc-4.2] r40057 - in /llvm-gcc-4.2/trunk/gcc: llvm-backend.cpp llvm-convert.cpp llvm-internal.h
Duncan Sands
baldrick at free.fr
Thu Jul 19 07:21:22 PDT 2007
Author: baldrick
Date: Thu Jul 19 09:21:22 2007
New Revision: 40057
URL: http://llvm.org/viewvc/llvm-project?rev=40057&view=rev
Log:
The code for a function body is no longer a
STATEMENT_LIST, so factor some code so that
ignored values (such a function call results)
get placed in a temporary. EmitSTATEMENT_LIST
used to take care of this.
Modified:
llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp
llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
llvm-gcc-4.2/trunk/gcc/llvm-internal.h
Modified: llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp?rev=40057&r1=40056&r2=40057&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp Thu Jul 19 09:21:22 2007
@@ -64,7 +64,6 @@
#include "timevar.h"
#include "tm.h"
#include "function.h"
-#include "tree-flow.h"
#include "tree-inline.h"
#include "langhooks.h"
#include "cgraph.h"
@@ -556,21 +555,7 @@
{
TreeToLLVM Emitter(fndecl);
- // Set up parameters and prepare for return, for the function.
- Emitter.StartFunctionBody();
-
- // Drop all fallthru edges, make explicit jumps
- disband_implicit_edges();
-
- // Emit the body of the function iterating over all BBs
- basic_block bb;
- FOR_EACH_BB (bb)
- for (block_stmt_iterator bsi = bsi_start (bb);
- !bsi_end_p (bsi); bsi_next (&bsi))
- Emitter.Emit(bsi_stmt (bsi), 0);
-
- // Wrap things up.
- Fn = Emitter.FinishFunctionBody();
+ Fn = Emitter.EmitFunction();
}
#if 0
Modified: llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp?rev=40057&r1=40056&r2=40057&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Thu Jul 19 09:21:22 2007
@@ -61,6 +61,7 @@
#include "hard-reg-set.h"
#include "except.h"
#include "rtl.h"
+#include "tree-flow.h"
extern bool tree_could_throw_p(tree); // tree-flow.h uses non-C++ C constructs.
extern int get_pointer_alignment (tree exp, unsigned int max_align);
extern enum machine_mode reg_raw_mode[FIRST_PSEUDO_REGISTER];
@@ -752,6 +753,23 @@
return Fn;
}
+Function *TreeToLLVM::EmitFunction() {
+ // Set up parameters and prepare for return, for the function.
+ StartFunctionBody();
+
+ // Drop all fallthru edges, make explicit jumps
+ disband_implicit_edges();
+
+ // Emit the body of the function iterating over all BBs
+ basic_block bb;
+ FOR_EACH_BB (bb)
+ for (block_stmt_iterator bsi = bsi_start (bb); !bsi_end_p (bsi);
+ bsi_next (&bsi))
+ EmitStatement(bsi_stmt (bsi));
+
+ // Wrap things up.
+ return FinishFunctionBody();
+}
Value *TreeToLLVM::Emit(tree exp, Value *DestLoc) {
assert((isAggregateTreeType(TREE_TYPE(exp)) == (DestLoc != 0) ||
@@ -1613,22 +1631,25 @@
return Result;
}
+void TreeToLLVM::EmitStatement(tree stmt) {
+ Value *DestLoc = 0;
+
+ // If this stmt returns an aggregate value (e.g. a call whose result is
+ // ignored), create a temporary to receive the value. Note that we don't
+ // do this for MODIFY_EXPRs as an efficiency hack.
+ if (isAggregateTreeType(TREE_TYPE(stmt)) && TREE_CODE(stmt) != MODIFY_EXPR)
+ DestLoc = CreateTemporary(ConvertType(TREE_TYPE(stmt)));
+
+ Emit(stmt, DestLoc);
+}
+
Value *TreeToLLVM::EmitSTATEMENT_LIST(tree exp, Value *DestLoc) {
assert(DestLoc == 0 && "Does not return a value!");
// Convert each statement.
- for (tree_stmt_iterator I = tsi_start(exp); !tsi_end_p(I); tsi_next(&I)) {
- tree stmt = tsi_stmt(I);
- Value *DestLoc = 0;
-
- // If this stmt returns an aggregate value (e.g. a call whose result is
- // ignored), create a temporary to receive the value. Note that we don't
- // do this for MODIFY_EXPRs as an efficiency hack.
- if (isAggregateTreeType(TREE_TYPE(stmt)) && TREE_CODE(stmt) != MODIFY_EXPR)
- DestLoc = CreateTemporary(ConvertType(TREE_TYPE(stmt)));
+ for (tree_stmt_iterator I = tsi_start(exp); !tsi_end_p(I); tsi_next(&I))
+ EmitStatement(tsi_stmt(I));
- Emit(stmt, DestLoc);
- }
return 0;
}
Modified: llvm-gcc-4.2/trunk/gcc/llvm-internal.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-internal.h?rev=40057&r1=40056&r2=40057&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-internal.h (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-internal.h Thu Jul 19 09:21:22 2007
@@ -380,24 +380,13 @@
/// being compiled.
tree_node *getFUNCTION_DECL() const { return FnDecl; }
- /// StartFunctionBody - Start the emission of 'fndecl', outputing all
- /// declarations for parameters and setting things up.
- void StartFunctionBody();
-
- /// Emit - Convert the specified tree node to LLVM code. If the node is an
- /// expression that fits into an LLVM scalar value, the result is returned. If
- /// the result is an aggregate, it is stored into the location specified by
- /// DestLoc.
- Value *Emit(tree_node *exp, Value *DestLoc);
+ /// EmitFunction - Convert 'fndecl' to LLVM code.
+ Function *EmitFunction();
/// EmitLV - Convert the specified l-value tree node to LLVM code, returning
/// the address of the result.
LValue EmitLV(tree_node *exp);
- /// FinishFunctionBody - Once the body of the function has been emitted, this
- /// cleans up and returns the result function.
- Function *FinishFunctionBody();
-
/// getIndirectGotoBlockNumber - Return the unique ID of the specified basic
/// block for uses that take the address of it.
Constant *getIndirectGotoBlockNumber(BasicBlock *BB);
@@ -445,6 +434,23 @@
private: // Helper functions.
+ /// StartFunctionBody - Start the emission of 'fndecl', outputing all
+ /// declarations for parameters and setting things up.
+ void StartFunctionBody();
+
+ /// FinishFunctionBody - Once the body of the function has been emitted, this
+ /// cleans up and returns the result function.
+ Function *FinishFunctionBody();
+
+ /// Emit - Convert the specified tree node to LLVM code. If the node is an
+ /// expression that fits into an LLVM scalar value, the result is returned. If
+ /// the result is an aggregate, it is stored into the location specified by
+ /// DestLoc.
+ Value *Emit(tree_node *exp, Value *DestLoc);
+
+ /// EmitStatement - Convert the specified statement to LLVM code.
+ void EmitStatement(tree_node *stmt);
+
/// EmitBlock - Add the specified basic block to the end of the function. If
/// the previous block falls through into it, add an explicit branch. Also,
/// manage fixups for EH info.
@@ -498,7 +504,7 @@
///
void CreateExceptionValues();
- // Emit* - These are delgates from Emit, and have the same parameter
+ // Emit* - These are delegates from Emit, and have the same parameter
// characteristics.
// Basic lists and binding scopes.
More information about the llvm-commits
mailing list