blob: 56c6b414d70317b90990afd4ac24e05cc939f78e [file] [log] [blame]
Shalini Salomi Bodapatidd121f62018-10-26 15:03:53 +05301/* Copyright (C) 2018 The Android Open Source Project
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#include "instruction_simplifier_x86_64.h"
17#include "instruction_simplifier_x86_shared.h"
18#include "code_generator_x86_64.h"
19
Vladimir Marko0a516052019-10-14 13:00:44 +000020namespace art {
Shalini Salomi Bodapatidd121f62018-10-26 15:03:53 +053021
22namespace x86_64 {
23
24class InstructionSimplifierX86_64Visitor : public HGraphVisitor {
25 public:
26 InstructionSimplifierX86_64Visitor(HGraph* graph,
27 CodeGenerator* codegen,
28 OptimizingCompilerStats* stats)
29 : HGraphVisitor(graph),
30 codegen_(down_cast<CodeGeneratorX86_64*>(codegen)),
31 stats_(stats) {}
32
33 void RecordSimplification() {
34 MaybeRecordStat(stats_, MethodCompilationStat::kInstructionSimplificationsArch);
35 }
36
37 bool HasAVX2() {
38 return codegen_->GetInstructionSetFeatures().HasAVX2();
39 }
40
41 void VisitBasicBlock(HBasicBlock* block) override {
42 for (HInstructionIterator it(block->GetInstructions()); !it.Done(); it.Advance()) {
43 HInstruction* instruction = it.Current();
44 if (instruction->IsInBlock()) {
45 instruction->Accept(this);
46 }
47 }
48 }
49
50 void VisitAnd(HAnd* instruction) override;
51 void VisitXor(HXor* instruction) override;
52
53 private:
54 CodeGeneratorX86_64* codegen_;
55 OptimizingCompilerStats* stats_;
56};
57
58void InstructionSimplifierX86_64Visitor::VisitAnd(HAnd* instruction) {
59 if (TryCombineAndNot(instruction)) {
60 RecordSimplification();
61 } else if (TryGenerateResetLeastSetBit(instruction)) {
62 RecordSimplification();
63 }
64}
65
66
67void InstructionSimplifierX86_64Visitor::VisitXor(HXor* instruction) {
68 if (TryGenerateMaskUptoLeastSetBit(instruction)) {
69 RecordSimplification();
70 }
71}
72
73bool InstructionSimplifierX86_64::Run() {
74 InstructionSimplifierX86_64Visitor visitor(graph_, codegen_, stats_);
75 if (visitor.HasAVX2()) {
76 visitor.VisitReversePostOrder();
77 return true;
78 }
79 return false;
80}
81} // namespace x86_64
82} // namespace art