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

Side by Side Diff: src/IceInstX8632.cpp

Issue 1435363002: Merge fixed alloca stack adjustments into the prolog (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Fix rebase issues. Created 5 years, 1 month 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 unified diff | Download patch
OLDNEW
1 //===- subzero/src/IceInstX8632.cpp - X86-32 instruction implementation ---===// 1 //===- subzero/src/IceInstX8632.cpp - X86-32 instruction implementation ---===//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 /// 9 ///
10 /// \file 10 /// \file
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 Vars = Func->allocateArrayOf<Variable *>(NumVars); 91 Vars = Func->allocateArrayOf<Variable *>(NumVars);
92 SizeT I = 0; 92 SizeT I = 0;
93 if (Base) 93 if (Base)
94 Vars[I++] = Base; 94 Vars[I++] = Base;
95 if (Index) 95 if (Index)
96 Vars[I++] = Index; 96 Vars[I++] = Index;
97 assert(I == NumVars); 97 assert(I == NumVars);
98 } 98 }
99 } 99 }
100 100
101 namespace {
102 static int32_t GetRematerializableOffset(Variable *Var, bool IgnoreStackAdjust,
103 const Ice::TargetLowering *Target) {
John 2015/11/16 14:00:02 const Ice::TargetX8632 *? I would hope llvm would
sehr 2015/11/16 18:42:24 Done.
104 int32_t Disp = 0;
105 Disp += Var->getStackOffset();
106 if (static_cast<SizeT>(Var->getRegNum()) == Target->getStackReg()) {
Jim Stichnoth 2015/11/16 14:47:57 Pull "static_cast<SizeT>(Var->getRegNum())" out of
sehr 2015/11/16 18:42:24 Done.
107 if (!IgnoreStackAdjust)
108 Disp += Target->getStackAdjustment();
109 } else if (static_cast<SizeT>(Var->getRegNum()) == Target->getFrameReg()) {
110 Disp += Target->getFrameFixedAllocaOffset();
111 } else {
112 llvm_unreachable("Unexpected rematerializable register type");
Jim Stichnoth 2015/11/16 14:47:57 llvm::report_fatal_error
sehr 2015/11/16 18:42:24 Done.
113 }
114 return Disp;
115 }
116 } // end namespace
Jim Stichnoth 2015/11/16 14:47:57 end of anonymous namespace
sehr 2015/11/16 18:42:24 Done.
117
101 void MachineTraits<TargetX8632>::X86OperandMem::emit(const Cfg *Func) const { 118 void MachineTraits<TargetX8632>::X86OperandMem::emit(const Cfg *Func) const {
102 if (!BuildDefs::dump()) 119 if (!BuildDefs::dump())
103 return; 120 return;
104 const ::Ice::TargetLowering *Target = Func->getTarget(); 121 Ice::TargetLowering *Target = Func->getTarget();
Jim Stichnoth 2015/11/16 14:47:57 Retain the const?
sehr 2015/11/16 18:42:24 Done.
105 // If the base is rematerializable, we need to replace it with the correct 122 // If the base is rematerializable, we need to replace it with the correct
106 // physical register (esp or ebp), and update the Offset. 123 // physical register (esp or ebp), and update the Offset.
107 int32_t Disp = 0; 124 int32_t Disp = 0;
108 if (getBase() && getBase()->isRematerializable()) { 125 if (getBase() && getBase()->isRematerializable()) {
109 Disp += getBase()->getStackOffset(); 126 Disp += GetRematerializableOffset(getBase(), getIgnoreStackAdjust(),
110 if (!getIgnoreStackAdjust()) 127 Target);
111 Disp += Target->getStackAdjustment();
112 } 128 }
113 // The index should never be rematerializable. But if we ever allow it, then 129 // The index should never be rematerializable. But if we ever allow it, then
114 // we should make sure the rematerialization offset is shifted by the Shift 130 // we should make sure the rematerialization offset is shifted by the Shift
115 // value. 131 // value.
116 if (getIndex()) 132 if (getIndex())
117 assert(!getIndex()->isRematerializable()); 133 assert(!getIndex()->isRematerializable());
118 Ostream &Str = Func->getContext()->getStrEmit(); 134 Ostream &Str = Func->getContext()->getStrEmit();
119 if (SegmentReg != DefaultSegment) { 135 if (SegmentReg != DefaultSegment) {
120 assert(SegmentReg >= 0 && SegmentReg < SegReg_NUM); 136 assert(SegmentReg >= 0 && SegmentReg < SegReg_NUM);
121 Str << "%" << X8632::Traits::InstSegmentRegNames[SegmentReg] << ":"; 137 Str << "%" << X8632::Traits::InstSegmentRegNames[SegmentReg] << ":";
122 } 138 }
123 // Emit as Offset(Base,Index,1<<Shift). Offset is emitted without the leading 139 // Emit as Offset(Base,Index,1<<Shift). Offset is emitted without the leading
124 // '$'. Omit the (Base,Index,1<<Shift) part if Base==nullptr. 140 // '$'. Omit the (Base,Index,1<<Shift) part if Base==nullptr.
125 if (getOffset() == 0 && Disp == 0) { 141 if (getOffset() == 0 && Disp == 0) {
126 // No offset, emit nothing. 142 // No offset, emit nothing.
127 } else if (getOffset() == 0 && Disp != 0) { 143 } else if (getOffset() == 0 && Disp != 0) {
128 Str << Disp; 144 Str << Disp;
129 } else if (const auto *CI = llvm::dyn_cast<ConstantInteger32>(getOffset())) { 145 } else if (const auto *CI = llvm::dyn_cast<ConstantInteger32>(getOffset())) {
130 if (getBase() == nullptr || CI->getValue() || Disp != 0) 146 if (getBase() == nullptr || CI->getValue() || Disp != 0)
131 // Emit a non-zero offset without a leading '$'. 147 // Emit a non-zero offset without a leading '$'.
132 Str << CI->getValue() + Disp; 148 Str << CI->getValue() + Disp;
133 } else if (const auto *CR = 149 } else if (const auto *CR =
134 llvm::dyn_cast<ConstantRelocatable>(getOffset())) { 150 llvm::dyn_cast<ConstantRelocatable>(getOffset())) {
135 // TODO(sehr): ConstantRelocatable still needs updating for 151 // TODO(sehr): ConstantRelocatable still needs updating for
136 // rematerializable base/index and Disp. 152 // rematerializable base/index and Disp.
137 assert(Disp == 0); 153 assert(Disp == 0);
138 CR->emitWithoutPrefix(Func->getTarget()); 154 CR->emitWithoutPrefix(Target);
139 } else { 155 } else {
140 llvm_unreachable("Invalid offset type for x86 mem operand"); 156 llvm_unreachable("Invalid offset type for x86 mem operand");
141 } 157 }
142 158
143 if (getBase() || getIndex()) { 159 if (getBase() || getIndex()) {
144 Str << "("; 160 Str << "(";
145 if (getBase()) 161 if (getBase())
146 getBase()->emit(Func); 162 getBase()->emit(Func);
147 if (getIndex()) { 163 if (getIndex()) {
148 Str << ","; 164 Str << ",";
(...skipping 10 matching lines...) Expand all
159 if (!BuildDefs::dump()) 175 if (!BuildDefs::dump())
160 return; 176 return;
161 if (SegmentReg != DefaultSegment) { 177 if (SegmentReg != DefaultSegment) {
162 assert(SegmentReg >= 0 && SegmentReg < SegReg_NUM); 178 assert(SegmentReg >= 0 && SegmentReg < SegReg_NUM);
163 Str << X8632::Traits::InstSegmentRegNames[SegmentReg] << ":"; 179 Str << X8632::Traits::InstSegmentRegNames[SegmentReg] << ":";
164 } 180 }
165 bool Dumped = false; 181 bool Dumped = false;
166 Str << "["; 182 Str << "[";
167 int32_t Disp = 0; 183 int32_t Disp = 0;
168 if (getBase() && getBase()->isRematerializable()) { 184 if (getBase() && getBase()->isRematerializable()) {
169 Disp += getBase()->getStackOffset(); 185 Disp += GetRematerializableOffset(getBase(), getIgnoreStackAdjust(),
170 if (!getIgnoreStackAdjust()) 186 Func->getTarget());
171 Disp += Func->getTarget()->getStackAdjustment();
172 } 187 }
173 if (getBase()) { 188 if (getBase()) {
174 if (Func) 189 if (Func)
175 getBase()->dump(Func); 190 getBase()->dump(Func);
176 else 191 else
177 getBase()->dump(Str); 192 getBase()->dump(Str);
178 Dumped = true; 193 Dumped = true;
179 } 194 }
180 if (getIndex()) { 195 if (getIndex()) {
181 assert(!getIndex()->isRematerializable()); 196 assert(!getIndex()->isRematerializable());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 Asm->emitSegmentOverride(X8632::Traits::InstSegmentPrefixes[SegmentReg]); 241 Asm->emitSegmentOverride(X8632::Traits::InstSegmentPrefixes[SegmentReg]);
227 } 242 }
228 } 243 }
229 244
230 MachineTraits<TargetX8632>::Address 245 MachineTraits<TargetX8632>::Address
231 MachineTraits<TargetX8632>::X86OperandMem::toAsmAddress( 246 MachineTraits<TargetX8632>::X86OperandMem::toAsmAddress(
232 MachineTraits<TargetX8632>::Assembler *Asm, 247 MachineTraits<TargetX8632>::Assembler *Asm,
233 const Ice::TargetLowering *Target) const { 248 const Ice::TargetLowering *Target) const {
234 int32_t Disp = 0; 249 int32_t Disp = 0;
235 if (getBase() && getBase()->isRematerializable()) { 250 if (getBase() && getBase()->isRematerializable()) {
236 Disp += getBase()->getStackOffset(); 251 Disp += GetRematerializableOffset(getBase(), getIgnoreStackAdjust(),
237 if (!getIgnoreStackAdjust()) { 252 Target);
238 Disp += Target->getStackAdjustment();
239 }
240 } 253 }
241 // The index should never be rematerializable. But if we ever allow it, then 254 // The index should never be rematerializable. But if we ever allow it, then
242 // we should make sure the rematerialization offset is shifted by the Shift 255 // we should make sure the rematerialization offset is shifted by the Shift
243 // value. 256 // value.
244 if (getIndex()) 257 if (getIndex())
245 assert(!getIndex()->isRematerializable()); 258 assert(!getIndex()->isRematerializable());
246 AssemblerFixup *Fixup = nullptr; 259 AssemblerFixup *Fixup = nullptr;
247 // Determine the offset (is it relocatable?) 260 // Determine the offset (is it relocatable?)
248 if (getOffset()) { 261 if (getOffset()) {
249 if (const auto *CI = llvm::dyn_cast<ConstantInteger32>(getOffset())) { 262 if (const auto *CI = llvm::dyn_cast<ConstantInteger32>(getOffset())) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 Var->dump(Func); 330 Var->dump(Func);
318 else 331 else
319 Var->dump(Str); 332 Var->dump(Str);
320 Str << ")"; 333 Str << ")";
321 } 334 }
322 335
323 } // namespace X86Internal 336 } // namespace X86Internal
324 } // end of namespace Ice 337 } // end of namespace Ice
325 338
326 X86INSTS_DEFINE_STATIC_DATA(TargetX8632) 339 X86INSTS_DEFINE_STATIC_DATA(TargetX8632)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698