Commit 206833c6 by Jim Stichnoth

Subzero: A few fixes toward running larger programs.

1. Add 'llvm2ice -disable-globals' to disable Subzero translation of global initializers, since full support isn't yet implemented. 2. Change the names of intra-block branch target labels to avoid collisions with basic block labels. 3. Fix lowering of "br i1 <constant>, label ...", which was producing invalid instructions like "cmp 1, 0". 4. Fix the "make format-diff" operation, which was diffing against the wrong target. BUG= none R=wala@chromium.org Review URL: https://codereview.chromium.org/449093002
parent 7da431b5
...@@ -103,7 +103,7 @@ else ...@@ -103,7 +103,7 @@ else
CLANG_FORMAT_DIFF = /usr/lib/clang-format/clang-format-diff.py CLANG_FORMAT_DIFF = /usr/lib/clang-format/clang-format-diff.py
endif endif
format-diff: format-diff:
git diff -U0 HEAD^ | \ git diff -U0 `git merge-base HEAD master` | \
$(CLANG_FORMAT_DIFF) -p1 -style=LLVM -i $(CLANG_FORMAT_DIFF) -p1 -style=LLVM -i
clean: clean:
......
...@@ -20,10 +20,11 @@ class ClFlags { ...@@ -20,10 +20,11 @@ class ClFlags {
public: public:
ClFlags() ClFlags()
: DisableInternal(false), SubzeroTimingEnabled(false), : DisableInternal(false), SubzeroTimingEnabled(false),
DisableTranslation(false) {} DisableTranslation(false), DisableGlobals(false) {}
bool DisableInternal; bool DisableInternal;
bool SubzeroTimingEnabled; bool SubzeroTimingEnabled;
bool DisableTranslation; bool DisableTranslation;
bool DisableGlobals;
}; };
} }
......
...@@ -681,7 +681,8 @@ private: ...@@ -681,7 +681,8 @@ private:
namespace Ice { namespace Ice {
void Converter::convertToIce(Module *Mod) { void Converter::convertToIce(Module *Mod) {
convertGlobals(Mod); if (!Flags.DisableGlobals)
convertGlobals(Mod);
convertFunctions(Mod); convertFunctions(Mod);
} }
......
...@@ -122,7 +122,7 @@ InstX8632Label::InstX8632Label(Cfg *Func, TargetX8632 *Target) ...@@ -122,7 +122,7 @@ InstX8632Label::InstX8632Label(Cfg *Func, TargetX8632 *Target)
IceString InstX8632Label::getName(const Cfg *Func) const { IceString InstX8632Label::getName(const Cfg *Func) const {
char buf[30]; char buf[30];
snprintf(buf, llvm::array_lengthof(buf), "%u", Number); snprintf(buf, llvm::array_lengthof(buf), "%u", Number);
return ".L" + Func->getFunctionName() + "$__" + buf; return ".L" + Func->getFunctionName() + "$local$__" + buf;
} }
InstX8632Br::InstX8632Br(Cfg *Func, CfgNode *TargetTrue, CfgNode *TargetFalse, InstX8632Br::InstX8632Br(Cfg *Func, CfgNode *TargetTrue, CfgNode *TargetFalse,
......
...@@ -1584,7 +1584,7 @@ void TargetX8632::lowerBr(const InstBr *Inst) { ...@@ -1584,7 +1584,7 @@ void TargetX8632::lowerBr(const InstBr *Inst) {
if (Inst->isUnconditional()) { if (Inst->isUnconditional()) {
_br(Inst->getTargetUnconditional()); _br(Inst->getTargetUnconditional());
} else { } else {
Operand *Src0 = legalize(Inst->getCondition()); Operand *Src0 = legalize(Inst->getCondition(), Legal_Reg | Legal_Mem);
Constant *Zero = Ctx->getConstantZero(IceType_i32); Constant *Zero = Ctx->getConstantZero(IceType_i32);
_cmp(Src0, Zero); _cmp(Src0, Zero);
_br(InstX8632Br::Br_ne, Inst->getTargetTrue(), Inst->getTargetFalse()); _br(InstX8632Br::Br_ne, Inst->getTargetTrue(), Inst->getTargetFalse());
...@@ -2481,8 +2481,8 @@ void TargetX8632::lowerIcmp(const InstIcmp *Inst) { ...@@ -2481,8 +2481,8 @@ void TargetX8632::lowerIcmp(const InstIcmp *Inst) {
if (InstBr *NextBr = llvm::dyn_cast_or_null<InstBr>(Context.getNextInst())) { if (InstBr *NextBr = llvm::dyn_cast_or_null<InstBr>(Context.getNextInst())) {
if (Src0->getType() != IceType_i64 && !NextBr->isUnconditional() && if (Src0->getType() != IceType_i64 && !NextBr->isUnconditional() &&
Dest == NextBr->getSrc(0) && NextBr->isLastUse(Dest)) { Dest == NextBr->getSrc(0) && NextBr->isLastUse(Dest)) {
Operand *Src0New = Operand *Src0New = legalize(
legalize(Src0, IsSrc1ImmOrReg ? Legal_All : Legal_Reg, true); Src0, IsSrc1ImmOrReg ? (Legal_Reg | Legal_Mem) : Legal_Reg, true);
_cmp(Src0New, Src1); _cmp(Src0New, Src1);
_br(getIcmp32Mapping(Inst->getCondition()), NextBr->getTargetTrue(), _br(getIcmp32Mapping(Inst->getCondition()), NextBr->getTargetTrue(),
NextBr->getTargetFalse()); NextBr->getTargetFalse());
......
...@@ -88,6 +88,10 @@ DisableTranslation("notranslate", cl::desc("Disable Subzero translation")); ...@@ -88,6 +88,10 @@ DisableTranslation("notranslate", cl::desc("Disable Subzero translation"));
static cl::opt<bool> SubzeroTimingEnabled( static cl::opt<bool> SubzeroTimingEnabled(
"timing", cl::desc("Enable breakdown timing of Subzero translation")); "timing", cl::desc("Enable breakdown timing of Subzero translation"));
static cl::opt<bool>
DisableGlobals("disable-globals",
cl::desc("Disable global initializer translation"));
static cl::opt<NaClFileFormat> InputFileFormat( static cl::opt<NaClFileFormat> InputFileFormat(
"bitcode-format", cl::desc("Define format of input file:"), "bitcode-format", cl::desc("Define format of input file:"),
cl::values(clEnumValN(LLVMFormat, "llvm", "LLVM file (default)"), cl::values(clEnumValN(LLVMFormat, "llvm", "LLVM file (default)"),
...@@ -128,6 +132,7 @@ int main(int argc, char **argv) { ...@@ -128,6 +132,7 @@ int main(int argc, char **argv) {
Flags.DisableInternal = DisableInternal; Flags.DisableInternal = DisableInternal;
Flags.SubzeroTimingEnabled = SubzeroTimingEnabled; Flags.SubzeroTimingEnabled = SubzeroTimingEnabled;
Flags.DisableTranslation = DisableTranslation; Flags.DisableTranslation = DisableTranslation;
Flags.DisableGlobals = DisableGlobals;
if (BuildOnRead) { if (BuildOnRead) {
Ice::PNaClTranslator Translator(&Ctx, Flags); Ice::PNaClTranslator Translator(&Ctx, Flags);
......
; Trivial smoke test of compare and branch, with multiple basic ; 1. Trivial smoke test of compare and branch, with multiple basic
; blocks. ; blocks.
; 2. For a conditional branch on a constant boolean value, make sure
; we don't lower to a cmp instructions with an immediate as the first
; source operand.
; RUN: %llvm2ice %s --verbose inst | FileCheck %s ; RUN: %llvm2ice -O2 --verbose inst %s | FileCheck %s
; RUN: %llvm2ice -Om1 --verbose inst %s | FileCheck %s
; RUN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s ; RUN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s
; RUN: %llvm2iceinsts %s | %szdiff %s | FileCheck --check-prefix=DUMP %s ; RUN: %llvm2iceinsts %s | %szdiff %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts --pnacl %s | %szdiff %s \ ; RUN: %llvm2iceinsts --pnacl %s | %szdiff %s \
...@@ -15,6 +19,7 @@ Equal: ...@@ -15,6 +19,7 @@ Equal:
ret i32 %foo ret i32 %foo
Unequal: Unequal:
ret i32 %bar ret i32 %bar
; CHECK-LABEL: simple_cond_branch
; CHECK: br i1 %r1, label %Equal, label %Unequal ; CHECK: br i1 %r1, label %Equal, label %Unequal
; CHECK: Equal: ; CHECK: Equal:
; CHECK: ret i32 %foo ; CHECK: ret i32 %foo
...@@ -22,5 +27,16 @@ Unequal: ...@@ -22,5 +27,16 @@ Unequal:
; CHECK: ret i32 %bar ; CHECK: ret i32 %bar
} }
define internal i32 @test_br_const() {
__0:
br i1 1, label %__1, label %__2
__1:
ret i32 21
__2:
ret i32 43
}
; CHECK-LABEL: test_br_const
; CHECK-NOT: cmp {{[0-9]*}},
; ERRORS-NOT: ICE translation error ; ERRORS-NOT: ICE translation error
; DUMP-NOT: SZ ; DUMP-NOT: SZ
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment