forked from OSchip/llvm-project
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. llvm-svn: 120253
This commit is contained in:
parent
3378d870d2
commit
235b66c40f
|
@ -1564,11 +1564,25 @@ void CppWriter::printFunctionUses(const Function* F) {
|
||||||
// If the operand references a GVal or Constant, make a note of it
|
// If the operand references a GVal or Constant, make a note of it
|
||||||
if (GlobalValue* GV = dyn_cast<GlobalValue>(operand)) {
|
if (GlobalValue* GV = dyn_cast<GlobalValue>(operand)) {
|
||||||
gvs.insert(GV);
|
gvs.insert(GV);
|
||||||
if (GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV))
|
if (GenerationType != GenFunction)
|
||||||
if (GVar->hasInitializer())
|
if (GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV))
|
||||||
consts.insert(GVar->getInitializer());
|
if (GVar->hasInitializer())
|
||||||
} else if (Constant* C = dyn_cast<Constant>(operand))
|
consts.insert(GVar->getInitializer());
|
||||||
|
} else if (Constant* C = dyn_cast<Constant>(operand)) {
|
||||||
consts.insert(C);
|
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);
|
printVariableHead(F);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print the constants found
|
// Print the constants found
|
||||||
nl(Out) << "// Constant Definitions"; nl(Out);
|
nl(Out) << "// Constant Definitions"; nl(Out);
|
||||||
for (SmallPtrSet<Constant*,64>::iterator I = consts.begin(),
|
for (SmallPtrSet<Constant*,64>::iterator I = consts.begin(),
|
||||||
E = consts.end(); I != E; ++I) {
|
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
|
// Process the global variables definitions now that all the constants have
|
||||||
// been emitted. These definitions just couple the gvars with their constant
|
// been emitted. These definitions just couple the gvars with their constant
|
||||||
// initializers.
|
// initializers.
|
||||||
nl(Out) << "// Global Variable Definitions"; nl(Out);
|
if (GenerationType != GenFunction) {
|
||||||
for (SmallPtrSet<GlobalValue*,64>::iterator I = gvs.begin(), E = gvs.end();
|
nl(Out) << "// Global Variable Definitions"; nl(Out);
|
||||||
I != E; ++I) {
|
for (SmallPtrSet<GlobalValue*,64>::iterator I = gvs.begin(), E = gvs.end();
|
||||||
if (GlobalVariable* GV = dyn_cast<GlobalVariable>(*I))
|
I != E; ++I) {
|
||||||
printVariableBody(GV);
|
if (GlobalVariable* GV = dyn_cast<GlobalVariable>(*I))
|
||||||
|
printVariableBody(GV);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue