diff options
author | Nicolas Geoffray <nicolas.geoffray@lip6.fr> | 2010-11-28 18:00:53 +0000 |
---|---|---|
committer | Nicolas Geoffray <nicolas.geoffray@lip6.fr> | 2010-11-28 18:00:53 +0000 |
commit | 7509ccda930156d44f83b4b40eef077e93313091 (patch) | |
tree | 5f3feb0be214ec3ddd418eac35bc191820912295 /lib/Target/CppBackend | |
parent | ea4afa91eb453323948588ad1e1706d842fb9007 (diff) | |
download | external_llvm-7509ccda930156d44f83b4b40eef077e93313091.zip external_llvm-7509ccda930156d44f83b4b40eef077e93313091.tar.gz external_llvm-7509ccda930156d44f83b4b40eef077e93313091.tar.bz2 |
When emitting a single function with cppgen=function, you don't want to emit
initializers of global variables used in the function.
Also make sure to emit the operands of a constant.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120253 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/CppBackend')
-rw-r--r-- | lib/Target/CppBackend/CPPBackend.cpp | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/lib/Target/CppBackend/CPPBackend.cpp b/lib/Target/CppBackend/CPPBackend.cpp index 2c2e8df..71d6049 100644 --- a/lib/Target/CppBackend/CPPBackend.cpp +++ b/lib/Target/CppBackend/CPPBackend.cpp @@ -1564,11 +1564,25 @@ void CppWriter::printFunctionUses(const Function* F) { // If the operand references a GVal or Constant, make a note of it if (GlobalValue* GV = dyn_cast<GlobalValue>(operand)) { gvs.insert(GV); - if (GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV)) - if (GVar->hasInitializer()) - consts.insert(GVar->getInitializer()); - } else if (Constant* C = dyn_cast<Constant>(operand)) + if (GenerationType != GenFunction) + if (GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV)) + if (GVar->hasInitializer()) + consts.insert(GVar->getInitializer()); + } else if (Constant* C = dyn_cast<Constant>(operand)) { consts.insert(C); + for (unsigned j = 0; j < C->getNumOperands(); ++j) { + // If the operand references a GVal or Constant, make a note of it + Value* operand = C->getOperand(j); + printType(operand->getType()); + if (GlobalValue* GV = dyn_cast<GlobalValue>(operand)) { + gvs.insert(GV); + if (GenerationType != GenFunction) + if (GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV)) + if (GVar->hasInitializer()) + consts.insert(GVar->getInitializer()); + } + } + } } } } @@ -1591,7 +1605,7 @@ void CppWriter::printFunctionUses(const Function* F) { printVariableHead(F); } -// Print the constants found + // Print the constants found nl(Out) << "// Constant Definitions"; nl(Out); for (SmallPtrSet<Constant*,64>::iterator I = consts.begin(), E = consts.end(); I != E; ++I) { @@ -1601,11 +1615,13 @@ void CppWriter::printFunctionUses(const Function* F) { // Process the global variables definitions now that all the constants have // been emitted. These definitions just couple the gvars with their constant // initializers. - nl(Out) << "// Global Variable Definitions"; nl(Out); - for (SmallPtrSet<GlobalValue*,64>::iterator I = gvs.begin(), E = gvs.end(); - I != E; ++I) { - if (GlobalVariable* GV = dyn_cast<GlobalVariable>(*I)) - printVariableBody(GV); + if (GenerationType != GenFunction) { + nl(Out) << "// Global Variable Definitions"; nl(Out); + for (SmallPtrSet<GlobalValue*,64>::iterator I = gvs.begin(), E = gvs.end(); + I != E; ++I) { + if (GlobalVariable* GV = dyn_cast<GlobalVariable>(*I)) + printVariableBody(GV); + } } } |