[llvm-commits] [dragonegg] r152919 - in /dragonegg/trunk: include/dragonegg/Internals.h src/Convert.cpp
Duncan Sands
baldrick at free.fr
Fri Mar 16 05:54:38 PDT 2012
Author: baldrick
Date: Fri Mar 16 07:54:38 2012
New Revision: 152919
URL: http://llvm.org/viewvc/llvm-project?rev=152919&view=rev
Log:
Output stack variables in the order that they are declared in, in
order to make the IR less surprising.
Modified:
dragonegg/trunk/include/dragonegg/Internals.h
dragonegg/trunk/src/Convert.cpp
Modified: dragonegg/trunk/include/dragonegg/Internals.h
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/include/dragonegg/Internals.h?rev=152919&r1=152918&r2=152919&view=diff
==============================================================================
--- dragonegg/trunk/include/dragonegg/Internals.h (original)
+++ dragonegg/trunk/include/dragonegg/Internals.h Fri Mar 16 07:54:38 2012
@@ -391,6 +391,10 @@
/// cleans up and returns the result function.
Function *FinishFunctionBody();
+ /// EmitVariablesInScope - Output a declaration for every variable in the
+ /// given scope.
+ void EmitVariablesInScope(tree_node *scope);
+
/// PopulatePhiNodes - Populate generated phi nodes with their operands.
void PopulatePhiNodes();
Modified: dragonegg/trunk/src/Convert.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Convert.cpp?rev=152919&r1=152918&r2=152919&view=diff
==============================================================================
--- dragonegg/trunk/src/Convert.cpp (original)
+++ dragonegg/trunk/src/Convert.cpp Fri Mar 16 07:54:38 2012
@@ -561,6 +561,7 @@
(!DECL_CONTEXT(decl) && TREE_CODE(decl) == RESULT_DECL) ||
// Usual case.
(DECL_CONTEXT(decl) == current_function_decl &&
+ !DECL_EXTERNAL(decl) && // External variables are not local.
!TREE_STATIC(decl) && // Static variables not considered local.
TREE_CODE(decl) != FUNCTION_DECL); // Nested functions not considered local.
}
@@ -1100,10 +1101,29 @@
if (EmitDebugInfo())
TheDebugInfo->EmitStopPoint(Builder.GetInsertBlock(), Builder);
+ // Ensure that local variables are output in the order that they were declared
+ // rather than in the order we come across them. This is only done to make the
+ // IR more readable and is not needed for correctness.
+ EmitVariablesInScope(DECL_INITIAL(FnDecl));
+
// Create a new block for the return node, but don't insert it yet.
ReturnBB = BasicBlock::Create(Context, "return");
}
+/// EmitVariablesInScope - Output a declaration for every variable in the
+/// given scope.
+void TreeToLLVM::EmitVariablesInScope(tree scope) {
+ for (tree t = BLOCK_VARS(scope); t; t = DECL_CHAIN (t))
+ if (TREE_CODE(t) == VAR_DECL)
+ // If this is just the rotten husk of a variable that the gimplifier
+ // eliminated all uses of, but is preserving for debug info, ignore it.
+ if (!DECL_HAS_VALUE_EXPR_P(t))
+ make_decl_local(t);
+ // Declare variables in contained scopes.
+ for (tree t = BLOCK_SUBBLOCKS (scope); t ; t = BLOCK_CHAIN (t))
+ EmitVariablesInScope(t);
+}
+
/// DefineSSAName - Use the given value as the definition of the given SSA name.
/// Returns the provided value as a convenience.
Value *TreeToLLVM::DefineSSAName(tree reg, Value *Val) {
@@ -2167,7 +2187,7 @@
void TreeToLLVM::EmitAutomaticVariableDecl(tree decl) {
// If this is just the rotten husk of a variable that the gimplifier
// eliminated all uses of, but is preserving for debug info, ignore it.
- if (TREE_CODE(decl) == VAR_DECL && DECL_VALUE_EXPR(decl))
+ if (TREE_CODE(decl) == VAR_DECL && DECL_HAS_VALUE_EXPR_P(decl))
return;
tree type = TREE_TYPE(decl);
More information about the llvm-commits
mailing list