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

Unified Diff: src/llvm2ice.cpp

Issue 300563003: Subzero: Initial O2 lowering (Closed) Base URL: https://gerrit.chromium.org/gerrit/p/native_client/pnacl-subzero.git@master
Patch Set: Jan's third-round comments 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') | tests_lit/llvm2ice_tests/64bit.pnacl.ll » ('j') | no next file with comments »
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 e29637dea85e5aa54449088e57985a57263627d8..374d753769eff6b00403fb787bd52ce49430a428 100644
--- a/src/llvm2ice.cpp
+++ b/src/llvm2ice.cpp
@@ -100,6 +100,29 @@ public:
return Func;
}
+ // convertConstant() does not use Func or require it to be a valid
+ // Ice::Cfg pointer. As such, it's suitable for e.g. constructing
+ // global initializers.
+ Ice::Constant *convertConstant(const Constant *Const) {
+ if (const GlobalValue *GV = dyn_cast<GlobalValue>(Const)) {
+ return Ctx->getConstantSym(convertType(GV->getType()), 0, GV->getName());
+ } else if (const ConstantInt *CI = dyn_cast<ConstantInt>(Const)) {
+ return Ctx->getConstantInt(convertIntegerType(CI->getType()),
+ CI->getZExtValue());
+ } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(Const)) {
+ Ice::Type Type = convertType(CFP->getType());
+ if (Type == Ice::IceType_f32)
+ return Ctx->getConstantFloat(CFP->getValueAPF().convertToFloat());
+ else if (Type == Ice::IceType_f64)
+ return Ctx->getConstantDouble(CFP->getValueAPF().convertToDouble());
+ llvm_unreachable("Unexpected floating point type");
+ return NULL;
+ } else {
+ llvm_unreachable("Unhandled constant type");
+ return NULL;
+ }
+ }
+
private:
// LLVM values (instructions, etc.) are mapped directly to ICE variables.
// mapValueToIceVar has a version that forces an ICE type on the variable,
@@ -180,24 +203,7 @@ private:
Ice::Operand *convertValue(const Value *Op) {
if (const Constant *Const = dyn_cast<Constant>(Op)) {
- if (const GlobalValue *GV = dyn_cast<GlobalValue>(Const)) {
- return Ctx->getConstantSym(convertType(GV->getType()), 0,
- GV->getName());
- } else if (const ConstantInt *CI = dyn_cast<ConstantInt>(Const)) {
- return Ctx->getConstantInt(convertIntegerType(CI->getType()),
- CI->getZExtValue());
- } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(Const)) {
- Ice::Type Type = convertType(CFP->getType());
- if (Type == Ice::IceType_f32)
- return Ctx->getConstantFloat(CFP->getValueAPF().convertToFloat());
- else if (Type == Ice::IceType_f64)
- return Ctx->getConstantDouble(CFP->getValueAPF().convertToDouble());
- llvm_unreachable("Unexpected floating point type");
- return NULL;
- } else {
- llvm_unreachable("Unhandled constant type");
- return NULL;
- }
+ return convertConstant(Const);
} else {
return mapValueToIceVar(Op);
}
« no previous file with comments | « src/IceTargetLoweringX8632.cpp ('k') | tests_lit/llvm2ice_tests/64bit.pnacl.ll » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698