Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Unified Diff: src/llvm2ice.cpp

Issue 358013003: Subzero: Partial implementation of global initializers. (Closed) Base URL: https://gerrit.chromium.org/gerrit/p/native_client/pnacl-subzero.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/IceTargetLoweringX8632.cpp ('k') | szdiff.py » ('j') | szdiff.py » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/llvm2ice.cpp
diff --git a/src/llvm2ice.cpp b/src/llvm2ice.cpp
index c3a98dfed6b2d13a06f6dbeeb054d700990864ab..9b7e5ffda68bc7d72afc754fdf4763993bd86dd0 100644
--- a/src/llvm2ice.cpp
+++ b/src/llvm2ice.cpp
@@ -726,6 +726,55 @@ int main(int argc, char **argv) {
raw_os_ostream *Ls = new raw_os_ostream(LogFilename == "-" ? std::cout : Lfs);
Ls->SetUnbuffered();
+ Ice::GlobalContext Ctx(Ls, Os, VMask, TargetArch, OptLevel, TestPrefix);
+
+ Ice::TargetGlobalInitLowering *GlobalLowering =
+ Ice::TargetGlobalInitLowering::createLowering(TargetArch, &Ctx);
+ for (Module::const_global_iterator I = Mod->global_begin(),
+ E = Mod->global_end();
+ I != E; ++I) {
+ if (!I->hasInitializer())
+ continue;
+ const Constant *Initializer = I->getInitializer();
+ Ice::IceString Name = I->getName();
+ unsigned Align = I->getAlignment();
+ uint64_t NumElements = 0;
+ const char *Data = NULL;
+ bool DeleteData = false;
+ bool IsInternal = I->hasInternalLinkage();
+ bool IsConst = I->isConstant();
+ bool IsZeroInitializer = false;
+
+ if (const ConstantDataArray *CDA =
+ dyn_cast<ConstantDataArray>(Initializer)) {
+ NumElements = CDA->getNumElements();
+ assert(isa<IntegerType>(CDA->getElementType()) &&
+ cast<IntegerType>(CDA->getElementType())->getBitWidth() == 8);
+ Data = CDA->getRawDataValues().data();
+ } else if (isa<ConstantAggregateZero>(Initializer)) {
+ if (const ArrayType *AT = dyn_cast<ArrayType>(Initializer->getType())) {
+ assert(isa<IntegerType>(AT->getElementType()) &&
+ cast<IntegerType>(AT->getElementType())->getBitWidth() == 8);
+ NumElements = AT->getNumElements();
+ char *MyData = new char[NumElements];
+ memset(MyData, 0, NumElements);
+ Data = MyData;
+ DeleteData = true;
+ IsZeroInitializer = true;
+ } else {
+ llvm_unreachable("Unhandled constant aggregate zero type");
+ }
+ } else {
+ llvm_unreachable("Unhandled global initializer");
+ }
+
+ GlobalLowering->lower(Name, Align, IsInternal, IsConst, IsZeroInitializer,
+ NumElements, Data, DisableTranslation);
+ if (DeleteData)
+ delete Data;
+ }
+ delete GlobalLowering;
+
// Ideally, Func would be declared inside the loop and its object
// would be automatically deleted at the end of the loop iteration.
// However, emitting the constant pool requires a valid Cfg object,
@@ -735,7 +784,6 @@ int main(int argc, char **argv) {
// object, change all Ice::Constant related functions to use
// GlobalContext instead of Cfg, and then clean up this loop.
OwningPtr<Ice::Cfg> Func;
- Ice::GlobalContext Ctx(Ls, Os, VMask, TargetArch, OptLevel, TestPrefix);
for (Module::const_iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) {
if (I->empty())
« no previous file with comments | « src/IceTargetLoweringX8632.cpp ('k') | szdiff.py » ('j') | szdiff.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698