Commit b17f61de by Jan Voung

Align function starts to target-specific bundle alignment.

BUG=none R=stichnot@chromium.org Review URL: https://codereview.chromium.org/515993002
parent ce581635
......@@ -314,6 +314,13 @@ void Cfg::emit() {
Str << "\t.globl\t" << MangledName << "\n";
Str << "\t.type\t" << MangledName << ",@function\n";
}
Str << "\t.p2align " << getTarget()->getBundleAlignLog2Bytes() << ",0x";
llvm::ArrayRef<uint8_t> Pad = getTarget()->getNonExecBundlePadding();
for (llvm::ArrayRef<uint8_t>::iterator I = Pad.begin(), E = Pad.end();
I != E; ++I) {
Str.write_hex(*I);
}
Str << "\n";
for (NodeList::const_iterator I = Nodes.begin(), E = Nodes.end(); I != E;
++I) {
(*I)->emit(this);
......
......@@ -27,6 +27,7 @@
#include <string>
#include <vector>
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/SmallBitVector.h"
#include "llvm/ADT/STLExtras.h"
......
......@@ -137,6 +137,8 @@ public:
virtual bool hasFramePointer() const { return false; }
virtual SizeT getFrameOrStackReg() const = 0;
virtual size_t typeWidthInBytesOnStack(Type Ty) const = 0;
virtual SizeT getBundleAlignLog2Bytes() const = 0;
virtual llvm::ArrayRef<uint8_t> getNonExecBundlePadding() const = 0;
bool hasComputedFrame() const { return HasComputedFrame; }
bool shouldDoNopInsertion() const;
int32_t getStackAdjustment() const { return StackAdjustment; }
......
......@@ -45,6 +45,11 @@ public:
// i8, and i16 are rounded up to 4 bytes.
return (typeWidthInBytes(Ty) + 3) & ~3;
}
virtual SizeT getBundleAlignLog2Bytes() const { return 5; }
virtual llvm::ArrayRef<uint8_t> getNonExecBundlePadding() const {
static const uint8_t Padding[] = { 0xF4 };
return llvm::ArrayRef<uint8_t>(Padding, 1);
}
virtual void emitVariable(const Variable *Var, const Cfg *Func) const;
virtual void lowerArguments();
virtual void addProlog(CfgNode *Node);
......
......@@ -42,8 +42,8 @@ config.substitutions.append(
config.substitutions.append(('%llvm2ice', llvm2icetool))
config.substitutions.append(('%szdiff', os.path.join(bin_root, 'szdiff.py')))
llvmbintools = [r"\bFileCheck\b", r"\bllvm-mc\b", r"\bnot\b",
r"\bpnacl-freeze\b"]
llvmbintools = [r"\bFileCheck\b", r"\bllvm-mc\b", r"\bllvm-objdump\b",
r"\bnot\b", r"\bpnacl-freeze\b"]
for tool in llvmbintools:
# The re.sub() line is adapted from one of LLVM's lit.cfg files.
......
; Test that functions are aligned to the NaCl bundle alignment.
; We could be smarter and only do this for indirect call targets
; but typically you want to align functions anyway.
; Also, we are currently using hlts for non-executable padding.
; RUN: %llvm2ice -O2 --verbose none %s \
; RUN: | llvm-mc -triple=i686-none-nacl -x86-asm-syntax=intel -filetype=obj \
; RUN: | llvm-objdump -d --symbolize -x86-asm-syntax=intel - | FileCheck %s
define void @foo() {
ret void
}
; CHECK-LABEL: foo
; CHECK-NEXT: 0: {{.*}} ret
; CHECK-NEXT: 1: {{.*}} hlt
define void @bar() {
ret void
}
; CHECK-LABEL: bar
; CHECK-NEXT: 20: {{.*}} ret
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