Index: src/llvm2ice.cpp |
diff --git a/src/llvm2ice.cpp b/src/llvm2ice.cpp |
index 08f90f8132727f84c8f9b271275da01f04b62f39..01c043fd491bea53ab9c7b872eb4c809edef75b6 100644 |
--- a/src/llvm2ice.cpp |
+++ b/src/llvm2ice.cpp |
@@ -19,6 +19,7 @@ |
#include "IceGlobalContext.h" |
#include "IceInst.h" |
#include "IceOperand.h" |
+#include "IceTargetLowering.h" |
#include "IceTypes.h" |
#include "llvm/IR/Constant.h" |
@@ -63,6 +64,7 @@ public: |
SubzeroPointerType = Ice::IceType_i32; |
} |
+ // Caller is expected to delete the returned Ice::Cfg object. |
Ice::Cfg *convertFunction(const Function *F) { |
VarMap.clear(); |
NodeMap.clear(); |
@@ -670,6 +672,7 @@ int main(int argc, char **argv) { |
raw_os_ostream *Ls = new raw_os_ostream(LogFilename == "-" ? std::cout : Lfs); |
Ls->SetUnbuffered(); |
+ Ice::Cfg *Func = NULL; |
Ice::GlobalContext Ctx(Ls, Os, VMask, TargetArch, OptLevel, TestPrefix); |
for (Module::const_iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) { |
@@ -677,8 +680,19 @@ int main(int argc, char **argv) { |
continue; |
LLVM2ICEConverter FunctionConverter(&Ctx); |
+ // Ideally, we would have deleted the Ice::Cfg object (Func) at |
+ // the end of the previous iteration. However, emitting the |
+ // constant pool requires a valid Cfg object, so we need to defer |
+ // deleting the last non-empty Cfg object until outside the loop |
+ // and after emitting the constant pool. TODO: Since all |
+ // constants are globally pooled in the Ice::GlobalContext object, |
+ // change all Ice::Constant related functions to use GlobalContext |
+ // instead of Cfg, and then clean up this loop. |
+ delete Func; |
JF
2014/05/22 21:39:47
A smart pointer be better here.
Jim Stichnoth
2014/05/22 23:48:28
Done.
|
+ Func = NULL; |
+ |
Ice::Timer TConvert; |
- Ice::Cfg *Func = FunctionConverter.convertFunction(I); |
+ Func = FunctionConverter.convertFunction(I); |
if (DisableInternal) |
Func->setInternal(false); |
@@ -713,5 +727,11 @@ int main(int argc, char **argv) { |
} |
} |
+ if (!DisableTranslation && Func) |
+ Func->getTarget()->emitConstants(); |
+ |
+ delete Func; |
+ Func = NULL; |
JF
2014/05/22 21:39:47
Same.
Jim Stichnoth
2014/05/22 23:48:28
Done.
|
+ |
return ExitStatus; |
} |