blob: 97aa6b911aef7ae1d77a1363941324f84e9ab17e [file] [log] [blame]
Logan Chien8b977d32012-02-21 19:14:55 +08001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Brian Carlstrom641ce032013-01-31 15:21:37 -080017#include "llvm_compilation_unit.h"
Logan Chien8b977d32012-02-21 19:14:55 +080018
Elliott Hughes07ed66b2012-12-12 18:34:25 -080019#include "base/logging.h"
Logan Chien110bcba2012-04-16 19:11:28 +080020#include "compiled_method.h"
Logan Chien971bf3f2012-05-01 15:47:55 +080021#include "compiler_llvm.h"
Elliott Hughes0f3c5532012-03-30 14:51:51 -070022#include "instruction_set.h"
Logan Chien8b977d32012-02-21 19:14:55 +080023#include "ir_builder.h"
Shih-wei Liaod7726e42012-04-20 15:23:36 -070024#include "os.h"
Logan Chien8b977d32012-02-21 19:14:55 +080025
TDYa127d668a062012-04-13 12:36:57 -070026#include "runtime_support_builder_arm.h"
TDYa127b08ed122012-06-05 23:51:19 -070027#include "runtime_support_builder_thumb2.h"
TDYa127d668a062012-04-13 12:36:57 -070028#include "runtime_support_builder_x86.h"
29
Logan Chien8b977d32012-02-21 19:14:55 +080030#include <llvm/ADT/OwningPtr.h>
31#include <llvm/ADT/StringSet.h>
32#include <llvm/ADT/Triple.h>
33#include <llvm/Analysis/CallGraph.h>
34#include <llvm/Analysis/DebugInfo.h>
TDYa127f15b0ab2012-05-11 21:01:36 -070035#include <llvm/Analysis/Dominators.h>
36#include <llvm/Analysis/LoopInfo.h>
Logan Chien8b977d32012-02-21 19:14:55 +080037#include <llvm/Analysis/LoopPass.h>
38#include <llvm/Analysis/RegionPass.h>
TDYa127f15b0ab2012-05-11 21:01:36 -070039#include <llvm/Analysis/ScalarEvolution.h>
Logan Chien8b977d32012-02-21 19:14:55 +080040#include <llvm/Analysis/Verifier.h>
41#include <llvm/Assembly/PrintModulePass.h>
42#include <llvm/Bitcode/ReaderWriter.h>
43#include <llvm/CallGraphSCCPass.h>
Logan Chien110bcba2012-04-16 19:11:28 +080044#include <llvm/CodeGen/MachineFrameInfo.h>
45#include <llvm/CodeGen/MachineFunction.h>
46#include <llvm/CodeGen/MachineFunctionPass.h>
Logan Chien8b977d32012-02-21 19:14:55 +080047#include <llvm/DerivedTypes.h>
48#include <llvm/LLVMContext.h>
Logan Chien8b977d32012-02-21 19:14:55 +080049#include <llvm/Module.h>
Logan Chien971bf3f2012-05-01 15:47:55 +080050#include <llvm/Object/ObjectFile.h>
Logan Chien8b977d32012-02-21 19:14:55 +080051#include <llvm/PassManager.h>
52#include <llvm/Support/Debug.h>
Logan Chien971bf3f2012-05-01 15:47:55 +080053#include <llvm/Support/ELF.h>
Logan Chien8b977d32012-02-21 19:14:55 +080054#include <llvm/Support/FormattedStream.h>
55#include <llvm/Support/ManagedStatic.h>
Shih-wei Liaod7726e42012-04-20 15:23:36 -070056#include <llvm/Support/MemoryBuffer.h>
Logan Chien8b977d32012-02-21 19:14:55 +080057#include <llvm/Support/PassNameParser.h>
58#include <llvm/Support/PluginLoader.h>
59#include <llvm/Support/PrettyStackTrace.h>
60#include <llvm/Support/Signals.h>
61#include <llvm/Support/SystemUtils.h>
62#include <llvm/Support/TargetRegistry.h>
63#include <llvm/Support/TargetSelect.h>
64#include <llvm/Support/ToolOutputFile.h>
65#include <llvm/Support/raw_ostream.h>
Shih-wei Liaod7726e42012-04-20 15:23:36 -070066#include <llvm/Support/system_error.h>
Logan Chien8b977d32012-02-21 19:14:55 +080067#include <llvm/Target/TargetData.h>
68#include <llvm/Target/TargetLibraryInfo.h>
69#include <llvm/Target/TargetMachine.h>
Shih-wei Liaof1cb9a52012-04-20 01:49:18 -070070#include <llvm/Transforms/IPO.h>
Logan Chien8b977d32012-02-21 19:14:55 +080071#include <llvm/Transforms/IPO/PassManagerBuilder.h>
TDYa127f15b0ab2012-05-11 21:01:36 -070072#include <llvm/Transforms/Scalar.h>
Logan Chien8b977d32012-02-21 19:14:55 +080073
Shih-wei Liaod7726e42012-04-20 15:23:36 -070074#include <sys/types.h>
75#include <sys/wait.h>
76#include <unistd.h>
77
Logan Chien8b977d32012-02-21 19:14:55 +080078#include <string>
79
80namespace art {
81namespace compiler_llvm {
82
jeffhao40283122013-01-15 13:15:24 -080083#if defined(ART_USE_PORTABLE_COMPILER)
Shih-wei Liaobb33f2f2012-08-23 13:20:00 -070084llvm::FunctionPass*
85CreateGBCExpanderPass(const greenland::IntrinsicHelper& intrinsic_helper, IRBuilder& irb,
86 Compiler* compiler, OatCompilationUnit* oat_compilation_unit);
Shih-wei Liao21d28f52012-06-12 05:55:00 -070087#endif
88
Logan Chien8b977d32012-02-21 19:14:55 +080089llvm::Module* makeLLVMModuleContents(llvm::Module* module);
90
91
Brian Carlstrom641ce032013-01-31 15:21:37 -080092LlvmCompilationUnit::LlvmCompilationUnit(const CompilerLLVM* compiler_llvm,
Logan Chien971bf3f2012-05-01 15:47:55 +080093 size_t cunit_idx)
TDYa12755e5e6c2012-09-11 15:14:42 -070094: compiler_llvm_(compiler_llvm), cunit_idx_(cunit_idx) {
buzbeec531cef2012-10-18 07:09:20 -070095#if !defined(ART_USE_PORTABLE_COMPILER)
TDYa12755e5e6c2012-09-11 15:14:42 -070096 context_.reset(new llvm::LLVMContext());
Logan Chien8b977d32012-02-21 19:14:55 +080097 module_ = new llvm::Module("art", *context_);
TDYa12755e5e6c2012-09-11 15:14:42 -070098#else
Shih-wei Liaobb33f2f2012-08-23 13:20:00 -070099 compiler_ = NULL;
100 oat_compilation_unit_ = NULL;
buzbee4df2bbd2012-10-11 14:46:06 -0700101 llvm_info_.reset(new LLVMInfo());
102 context_.reset(llvm_info_->GetLLVMContext());
103 module_ = llvm_info_->GetLLVMModule();
TDYa12755e5e6c2012-09-11 15:14:42 -0700104#endif
105
106 // Include the runtime function declaration
107 makeLLVMModuleContents(module_);
108
Logan Chien8b977d32012-02-21 19:14:55 +0800109 // Create IRBuilder
110 irb_.reset(new IRBuilder(*context_, *module_));
TDYa127d668a062012-04-13 12:36:57 -0700111
112 // We always need a switch case, so just use a normal function.
Logan Chien971bf3f2012-05-01 15:47:55 +0800113 switch(GetInstructionSet()) {
TDYa127b08ed122012-06-05 23:51:19 -0700114 default:
115 runtime_support_.reset(new RuntimeSupportBuilder(*context_, *module_, *irb_));
116 break;
TDYa127d668a062012-04-13 12:36:57 -0700117 case kArm:
TDYa127d668a062012-04-13 12:36:57 -0700118 runtime_support_.reset(new RuntimeSupportBuilderARM(*context_, *module_, *irb_));
119 break;
TDYa127b08ed122012-06-05 23:51:19 -0700120 case kThumb2:
121 runtime_support_.reset(new RuntimeSupportBuilderThumb2(*context_, *module_, *irb_));
122 break;
TDYa127d668a062012-04-13 12:36:57 -0700123 case kX86:
124 runtime_support_.reset(new RuntimeSupportBuilderX86(*context_, *module_, *irb_));
125 break;
126 }
127
TDYa127d668a062012-04-13 12:36:57 -0700128 irb_->SetRuntimeSupport(runtime_support_.get());
Logan Chien8b977d32012-02-21 19:14:55 +0800129}
130
131
Brian Carlstrom641ce032013-01-31 15:21:37 -0800132LlvmCompilationUnit::~LlvmCompilationUnit() {
jeffhao40283122013-01-15 13:15:24 -0800133#if defined(ART_USE_PORTABLE_COMPILER)
buzbee4df2bbd2012-10-11 14:46:06 -0700134 llvm::LLVMContext* llvm_context = context_.release(); // Managed by llvm_info_
TDYa12755e5e6c2012-09-11 15:14:42 -0700135 CHECK(llvm_context != NULL);
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700136#endif
Logan Chien8b977d32012-02-21 19:14:55 +0800137}
138
139
Brian Carlstrom641ce032013-01-31 15:21:37 -0800140InstructionSet LlvmCompilationUnit::GetInstructionSet() const {
Logan Chien971bf3f2012-05-01 15:47:55 +0800141 return compiler_llvm_->GetInstructionSet();
Logan Chien8b977d32012-02-21 19:14:55 +0800142}
143
144
Brian Carlstrom641ce032013-01-31 15:21:37 -0800145bool LlvmCompilationUnit::Materialize() {
Logan Chien971bf3f2012-05-01 15:47:55 +0800146 std::string elf_image;
Logan Chien110bcba2012-04-16 19:11:28 +0800147
Logan Chien971bf3f2012-05-01 15:47:55 +0800148 // Compile and prelink llvm::Module
149 if (!MaterializeToString(elf_image)) {
150 LOG(ERROR) << "Failed to materialize compilation unit " << cunit_idx_;
Logan Chien971bf3f2012-05-01 15:47:55 +0800151 return false;
Logan Chien110bcba2012-04-16 19:11:28 +0800152 }
Logan Chien971bf3f2012-05-01 15:47:55 +0800153
154#if 0
155 // Dump the ELF image for debugging
156 std::string filename(StringPrintf("%s/Art%zu.elf",
157 GetArtCacheOrDie(GetAndroidData()).c_str(),
158 cunit_idx_));
159 UniquePtr<File> output(OS::OpenFile(filename.c_str(), true));
160 output->WriteFully(elf_image.data(), elf_image.size());
161#endif
162
163 // Extract the .text section and prelink the code
164 if (!ExtractCodeAndPrelink(elf_image)) {
165 LOG(ERROR) << "Failed to extract code from compilation unit " << cunit_idx_;
Logan Chien971bf3f2012-05-01 15:47:55 +0800166 return false;
167 }
168
Logan Chien971bf3f2012-05-01 15:47:55 +0800169 return true;
Logan Chien110bcba2012-04-16 19:11:28 +0800170}
171
Logan Chien971bf3f2012-05-01 15:47:55 +0800172
Brian Carlstrom641ce032013-01-31 15:21:37 -0800173bool LlvmCompilationUnit::MaterializeToString(std::string& str_buffer) {
Logan Chien971bf3f2012-05-01 15:47:55 +0800174 llvm::raw_string_ostream str_os(str_buffer);
175 return MaterializeToRawOStream(str_os);
176}
177
178
Brian Carlstrom641ce032013-01-31 15:21:37 -0800179bool LlvmCompilationUnit::MaterializeToRawOStream(llvm::raw_ostream& out_stream) {
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700180 // Lookup the LLVM target
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800181 std::string target_triple;
182 std::string target_cpu;
183 std::string target_attr;
184 Compiler::InstructionSetToLLVMTarget(GetInstructionSet(), target_triple, target_cpu, target_attr);
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700185
186 std::string errmsg;
Logan Chien12584172012-07-10 04:07:28 -0700187 const llvm::Target* target =
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700188 llvm::TargetRegistry::lookupTarget(target_triple, errmsg);
189
190 CHECK(target != NULL) << errmsg;
191
192 // Target options
193 llvm::TargetOptions target_options;
194 target_options.FloatABIType = llvm::FloatABI::Soft;
195 target_options.NoFramePointerElim = true;
196 target_options.NoFramePointerElimNonLeaf = true;
197 target_options.UseSoftFloat = false;
TDYa1273978da52012-05-19 07:45:39 -0700198 target_options.EnableFastISel = false;
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700199
200 // Create the llvm::TargetMachine
Logan Chienb6bed0b2012-05-04 15:03:56 +0800201 llvm::OwningPtr<llvm::TargetMachine> target_machine(
Shih-wei Liao53519bf2012-06-17 03:45:00 -0700202 target->createTargetMachine(target_triple, target_cpu, target_attr, target_options,
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700203 llvm::Reloc::Static, llvm::CodeModel::Small,
Shih-wei Liaodac5eb22012-06-03 14:06:04 -0700204 llvm::CodeGenOpt::Aggressive));
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700205
Logan Chienb6bed0b2012-05-04 15:03:56 +0800206 CHECK(target_machine.get() != NULL) << "Failed to create target machine";
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700207
208 // Add target data
Logan Chien12584172012-07-10 04:07:28 -0700209 const llvm::TargetData* target_data = target_machine->getTargetData();
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700210
211 // PassManager for code generation passes
212 llvm::PassManager pm;
213 pm.add(new llvm::TargetData(*target_data));
214
215 // FunctionPassManager for optimization pass
Logan Chien799ef4f2012-04-23 00:17:47 +0800216 llvm::FunctionPassManager fpm(module_);
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700217 fpm.add(new llvm::TargetData(*target_data));
218
TDYa127f15b0ab2012-05-11 21:01:36 -0700219 if (bitcode_filename_.empty()) {
220 // If we don't need write the bitcode to file, add the AddSuspendCheckToLoopLatchPass to the
221 // regular FunctionPass.
TDYa127ce4cc0d2012-11-18 16:59:53 -0800222#if defined(ART_USE_PORTABLE_COMPILER)
buzbee4df2bbd2012-10-11 14:46:06 -0700223 fpm.add(CreateGBCExpanderPass(*llvm_info_->GetIntrinsicHelper(), *irb_.get(),
Shih-wei Liaobb33f2f2012-08-23 13:20:00 -0700224 compiler_, oat_compilation_unit_));
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700225#endif
TDYa127f15b0ab2012-05-11 21:01:36 -0700226 } else {
TDYa127ce4cc0d2012-11-18 16:59:53 -0800227#if defined(ART_USE_PORTABLE_COMPILER)
TDYa127f15b0ab2012-05-11 21:01:36 -0700228 llvm::FunctionPassManager fpm2(module_);
buzbee4df2bbd2012-10-11 14:46:06 -0700229 fpm2.add(CreateGBCExpanderPass(*llvm_info_->GetIntrinsicHelper(), *irb_.get(),
Shih-wei Liaobb33f2f2012-08-23 13:20:00 -0700230 compiler_, oat_compilation_unit_));
TDYa127f15b0ab2012-05-11 21:01:36 -0700231 fpm2.doInitialization();
232 for (llvm::Module::iterator F = module_->begin(), E = module_->end();
233 F != E; ++F) {
234 fpm2.run(*F);
235 }
236 fpm2.doFinalization();
TDYa127ce4cc0d2012-11-18 16:59:53 -0800237#endif
TDYa127f15b0ab2012-05-11 21:01:36 -0700238
239 // Write bitcode to file
240 std::string errmsg;
241
242 llvm::OwningPtr<llvm::tool_output_file> out_file(
243 new llvm::tool_output_file(bitcode_filename_.c_str(), errmsg,
244 llvm::raw_fd_ostream::F_Binary));
245
246
247 if (!errmsg.empty()) {
248 LOG(ERROR) << "Failed to create bitcode output file: " << errmsg;
249 return false;
250 }
251
252 llvm::WriteBitcodeToFile(module_, out_file->os());
253 out_file->keep();
254 }
255
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700256 // Add optimization pass
257 llvm::PassManagerBuilder pm_builder;
TDYa1279a129452012-07-19 03:10:08 -0700258 // TODO: Use inliner after we can do IPO.
259 pm_builder.Inliner = NULL;
Shih-wei Liaoe0e40242012-05-08 01:04:03 -0700260 //pm_builder.Inliner = llvm::createFunctionInliningPass();
TDYa1279a129452012-07-19 03:10:08 -0700261 //pm_builder.Inliner = llvm::createAlwaysInlinerPass();
Shih-wei Liao415576b2012-04-23 15:28:53 -0700262 //pm_builder.Inliner = llvm::createPartialInliningPass();
263 pm_builder.OptLevel = 3;
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700264 pm_builder.DisableSimplifyLibCalls = 1;
TDYa127e4c2ccc2012-05-13 21:10:36 -0700265 pm_builder.DisableUnitAtATime = 1;
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700266 pm_builder.populateFunctionPassManager(fpm);
TDYa127ce9c3172012-05-15 06:09:27 -0700267 pm_builder.populateModulePassManager(pm);
268 pm.add(llvm::createStripDeadPrototypesPass());
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700269
270 // Add passes to emit ELF image
271 {
Logan Chien08e1ba32012-05-08 15:08:51 +0800272 llvm::formatted_raw_ostream formatted_os(out_stream, false);
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700273
274 // Ask the target to add backend passes as necessary.
275 if (target_machine->addPassesToEmitFile(pm,
276 formatted_os,
277 llvm::TargetMachine::CGFT_ObjectFile,
278 true)) {
279 LOG(FATAL) << "Unable to generate ELF for this target";
280 return false;
281 }
282
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700283 // Run the per-function optimization
284 fpm.doInitialization();
Logan Chien799ef4f2012-04-23 00:17:47 +0800285 for (llvm::Module::iterator F = module_->begin(), E = module_->end();
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700286 F != E; ++F) {
287 fpm.run(*F);
288 }
289 fpm.doFinalization();
290
291 // Run the code generation passes
Logan Chien799ef4f2012-04-23 00:17:47 +0800292 pm.run(*module_);
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700293 }
294
295 return true;
296}
Logan Chien110bcba2012-04-16 19:11:28 +0800297
Brian Carlstrom641ce032013-01-31 15:21:37 -0800298bool LlvmCompilationUnit::ExtractCodeAndPrelink(const std::string& elf_image) {
Shih-wei Liao02a1e352012-06-30 00:42:07 -0700299 if (GetInstructionSet() == kX86) {
300 compiled_code_.push_back(0xccU);
301 compiled_code_.push_back(0xccU);
302 compiled_code_.push_back(0xccU);
303 compiled_code_.push_back(0xccU);
304 return true;
305 }
306
Logan Chien971bf3f2012-05-01 15:47:55 +0800307 llvm::OwningPtr<llvm::MemoryBuffer> elf_image_buff(
308 llvm::MemoryBuffer::getMemBuffer(llvm::StringRef(elf_image.data(),
309 elf_image.size())));
310
311 llvm::OwningPtr<llvm::object::ObjectFile> elf_file(
312 llvm::object::ObjectFile::createELFObjectFile(elf_image_buff.take()));
313
314 llvm::error_code ec;
315
316 const ProcedureLinkageTable& plt = compiler_llvm_->GetProcedureLinkageTable();
317
318 for (llvm::object::section_iterator
319 sec_iter = elf_file->begin_sections(),
320 sec_end = elf_file->end_sections();
321 sec_iter != sec_end; sec_iter.increment(ec)) {
322
323 CHECK(ec == 0) << "Failed to read section because " << ec.message();
324
325 // Read the section information
326 llvm::StringRef name;
327 uint64_t alignment = 0u;
328 uint64_t size = 0u;
329
330 CHECK(sec_iter->getName(name) == 0);
331 CHECK(sec_iter->getSize(size) == 0);
332 CHECK(sec_iter->getAlignment(alignment) == 0);
333
334 if (name == ".data" || name == ".bss" || name == ".rodata") {
335 if (size > 0) {
336 LOG(FATAL) << "Compilation unit " << cunit_idx_ << " has non-empty "
337 << name.str() << " section";
338 }
339
340 } else if (name == "" || name == ".rel.text" ||
341 name == ".ARM.attributes" || name == ".symtab" ||
342 name == ".strtab" || name == ".shstrtab") {
343 // We can ignore these sections. We don't have to copy them into
344 // the result Oat file.
345
346 } else if (name == ".text") {
347 // Ensure the alignment requirement is less than or equal to
348 // kArchAlignment
349 CheckCodeAlign(alignment);
350
351 // Copy the compiled code
352 llvm::StringRef contents;
353 CHECK(sec_iter->getContents(contents) == 0);
354
355 copy(contents.data(),
356 contents.data() + contents.size(),
357 back_inserter(compiled_code_));
358
359 // Prelink the compiled code
360 for (llvm::object::relocation_iterator
361 rel_iter = sec_iter->begin_relocations(),
362 rel_end = sec_iter->end_relocations(); rel_iter != rel_end;
363 rel_iter.increment(ec)) {
364
365 CHECK(ec == 0) << "Failed to read relocation because " << ec.message();
366
367 // Read the relocation information
368 llvm::object::SymbolRef sym_ref;
369 uint64_t rel_offset = 0;
370 uint64_t rel_type = 0;
371 int64_t rel_addend = 0;
372
373 CHECK(rel_iter->getSymbol(sym_ref) == 0);
374 CHECK(rel_iter->getOffset(rel_offset) == 0);
375 CHECK(rel_iter->getType(rel_type) == 0);
376 CHECK(rel_iter->getAdditionalInfo(rel_addend) == 0);
377
378 // Read the symbol related to this relocation fixup
379 llvm::StringRef sym_name;
380 CHECK(sym_ref.getName(sym_name) == 0);
381
382 // Relocate the fixup.
383 // TODO: Support more relocation type.
384 CHECK(rel_type == llvm::ELF::R_ARM_ABS32);
385 CHECK_LE(rel_offset + 4, compiled_code_.size());
386
387 uintptr_t dest_addr = plt.GetEntryAddress(sym_name.str().c_str());
388 uintptr_t final_addr = dest_addr + rel_addend;
389 compiled_code_[rel_offset] = final_addr & 0xff;
390 compiled_code_[rel_offset + 1] = (final_addr >> 8) & 0xff;
391 compiled_code_[rel_offset + 2] = (final_addr >> 16) & 0xff;
392 compiled_code_[rel_offset + 3] = (final_addr >> 24) & 0xff;
393 }
394
395 } else {
396 LOG(WARNING) << "Unexpected section: " << name.str();
397 }
398 }
399
400 return true;
401}
402
403
404// Check whether the align is less than or equal to the code alignment of
405// that architecture. Since the Oat writer only guarantee that the compiled
406// method being aligned to kArchAlignment, we have no way to align the ELf
407// section if the section alignment is greater than kArchAlignment.
Brian Carlstrom641ce032013-01-31 15:21:37 -0800408void LlvmCompilationUnit::CheckCodeAlign(uint32_t align) const {
Logan Chien971bf3f2012-05-01 15:47:55 +0800409 InstructionSet insn_set = GetInstructionSet();
410 switch (insn_set) {
411 case kThumb2:
412 case kArm:
413 CHECK_LE(align, static_cast<uint32_t>(kArmAlignment));
414 break;
415
416 case kX86:
417 CHECK_LE(align, static_cast<uint32_t>(kX86Alignment));
418 break;
419
420 case kMips:
421 CHECK_LE(align, static_cast<uint32_t>(kMipsAlignment));
422 break;
423
424 default:
425 LOG(FATAL) << "Unknown instruction set: " << insn_set;
426 }
427}
428
429
Logan Chien8b977d32012-02-21 19:14:55 +0800430} // namespace compiler_llvm
431} // namespace art